[fw-general] Imageoutput problems with Zend_Cache

2008-09-22 Thread Kai Meder

Hello,

I am trying to create an Image-proxy which caches image-urls on disk and 
outputs these jpegs to the browser.
The following code wont work. On the first Cache Miss, the image is 
properly shown. On each following Cache Hit, the image is not displayed 
(invalid data). The cache file on disk contains the proper jpeg-image, 
at least irfanview recognizes it being jpeg...

Any hint? Thanks!
Kai

$frontend = 'Output';
$frontendOpts = array(
'caching' => true,
'cache_id_prefix' => 'ImageServiceProxy_',
'lifetime' => NULL,
'ignore_user_abort' => true
);

$backend  = 'File';
$backendOpts = array(
'cache_dir' => CACHEDIR,
'read_control' => false,
'hashed_directory_level' => 3,
);

$cache = Zend_Cache::factory($frontend, $backend, $frontendOpts, 
$backendOpts);


header('Content-Type: image/jpeg');

if (!$cache->load($cacheID)) {

$http = new Zend_Http_Client($url);
$http->setHeaders('User-Agent', $_SERVER['HTTP_USER_AGENT']);
	$http->setHeaders('Referer','http://' . $http->getUri()->getHost() 
. '/');

$res = $http->request('GET');
$img = $res->getRawBody();

imagejpeg(imagecreatefromstring($img));

$cache->end();
}
exit;


[fw-general] Imageoutput problems with Zend_Cache

2008-09-22 Thread Kai Meder

Hello,

I am trying to create an Image-proxy which caches image-urls on disk and 
outputs these jpegs to the browser.
The following code wont work. On the first Cache Miss, the image is 
properly shown. On each following Cache Hit, the image is not displayed 
(invalid data). The cache file on disk contains the proper jpeg-image, 
at least irfanview recognizes it being jpeg...

Any hint? Thanks!
Kai

$frontend = 'Output';
$frontendOpts = array(
'caching' => true,
'cache_id_prefix' => 'ImageServiceProxy_',
'lifetime' => NULL,
'ignore_user_abort' => true
);

$backend  = 'File';
$backendOpts = array(
'cache_dir' => CACHEDIR,
'read_control' => false,
'hashed_directory_level' => 3,
);

$cache = Zend_Cache::factory($frontend, $backend, $frontendOpts, 
$backendOpts);


header('Content-Type: image/jpeg');

if (!$cache->load($cacheID)) {

$http = new Zend_Http_Client($url);
$http->setHeaders('User-Agent', $_SERVER['HTTP_USER_AGENT']);
$http->setHeaders('Referer','http://' . 
$http->getUri()->getHost() . '/');

$res = $http->request('GET');
$img = $res->getRawBody();

imagejpeg(imagecreatefromstring($img));

$cache->end();
}
exit;





[fw-general] Header-Problems with Zend_Controller_Response_Abstract

2008-04-14 Thread Kai Meder

Hello,

I do want an ImageService to get cached by the client.

$ETag = md5($h);
$this->res
->setHeader('Cache-Control', 'public', true)
->setHeader('Pragma', 'public', true)
->setHeader('Expires', gmdate("D, d M Y H:i:s",
time()+3600*24*365).' GMT', true)
->setHeader('ETag', $ETag, true);

if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
$_SERVER['HTTP_IF_NONE_MATCH'] == $ETag) {

//header('HTTP/1.1 304 Not Modified');
//$this->res->setHttpResponseCode(304);
$this->res->setRawHeader('HTTP/1.1 304 Not Modified');
return true;
}

This does not work. I think the Cache-Control, Pragma and Expires 
headers, which seem to have been manually set by the Zend-Framework, do 
affect the Cache-Behavior.
I can`t remove them, so is my overwriting OK to enforce the Browser to 
cache?
Secondly, I can`t properly set the Header 304, the client does not cache 
the images...


Any Hints?

Thanks,
Kai


[fw-general] Header-Problems with Zend_Controller_Response_Abstract

2008-04-12 Thread Kai Meder

Hello,

I do want an ImageService to get cached by the client.

$ETag = md5($h);
$this->res
->setHeader('Cache-Control', 'public', true)
->setHeader('Pragma', 'public', true)
->setHeader('Expires', gmdate("D, d M Y H:i:s",
time()+3600*24*365).' GMT', true)
->setHeader('ETag', $ETag, true);

if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
$_SERVER['HTTP_IF_NONE_MATCH'] == $ETag) {

//header('HTTP/1.1 304 Not Modified');
//$this->res->setHttpResponseCode(304);
$this->res->setRawHeader('HTTP/1.1 304 Not Modified');
return true;
}

This does not work. I think the Cache-Control, Pragma and Expires
headers, which seem to have been manually set by the Zend-Framework, do
affect the Cache-Behavior.
I can`t remove them, so is my overwriting OK to enforce the Browser to
cache?
Secondly, I can`t properly set the Header 304, the client does not cache
the images...

Any Hints?

Thanks,
Kai



Re: [fw-general] Difference between Zend_Db_Table and Zend_Db_Table_Abstract

2008-04-12 Thread Kai Meder

xing93111 wrote:

What's the difference between Zend_Db_Table and Zend_Db_Table_Abstract? My
code can extend either one and it works.


I think the only reason is the Namespace-style.
The class a_b_c is stored in the filesystem like a/b/c.
So Zend_Db_Table_Abstract is the main class containing the base logic.
Zend_Db_Table merely initiates the Namespace...

So long,
Kai


Re: [fw-general] Zend_PDF: creating a template PDF and replacing placeholders

2008-03-20 Thread Kai Meder

Willie Alberty wrote:
Although you can open a PDF file in a text editor and more or less 
follow its structure, it is not a text file. PDF documents are binary 
files. You can irreparably damage a PDF by doing string replacement 
operations.


The reason for this is the document trailer which appears at the end of 
every PDF file. This is an array of byte offsets to the various objects 
contained within the document. If you do a string replacement that 
changes the byte length of the string, you've wrecked this offsets 
table, and the PDF viewer will be unable to read the document.


If you're very careful to maintain the byte length of the strings you're 
replacing, you can actually change existing PDF content in this way, but 
you're treading on thin ice. If you keep the byte offsets in document 
trailer updated, you can change string lengths too, but this gets to be 
rather difficult.


thanks for that thorough explanation and thanks for the fop-link, 
thomas. will take a look at it.


thanks,
kai


[fw-general] Zend_PDF: creating a template PDF and replacing placeholders

2008-03-20 Thread Kai Meder

Hello,

does anyone know a good solution to:
- create a fully designed PDF template (e.g. from MS Publisher)
- replace embedded placeholders in this PDF to bulk-create PDFs.

It seems any PDF I create contains a binary data-stream and no raw-text 
whatsoever. So whats the best way to create such Template-PDFs?

Is there any official Variable/Placeholder Syntax for PDFs?

Thanks!
Kai


Re: [fw-general] view auto quoting

2007-07-11 Thread Kai Meder

it works when directly outputting in the view-script
*without* the helper like:


var SNAME = "";
var SID   = "";

var ROLES = roles); ?>;


yours,
kai


Re: [fw-general] view auto quoting

2007-07-11 Thread Kai Meder

Matthew Weier O'Phinney wrote:

Not happening in Zend_View, unless you're registering any filters with
the Zend_View object. It may be happening in Zend_Json::encode(), but it
should only be occurring if the value is a string.
no filters registered at all. double-checked via 
var_dump($this->getFilters());



How are you calling the helper? simply as:

$this->roles is array from db-select
json() is kindof shortcut to Zend_Json::encode

jsVar('ROLES', json($this->roles)); ?>

which results in:
var ROLES = 
"{\"Writer\":{\"role\":\"Writer\"}}";


full helper-source:
';
echo 'var ' . $name . ' = ';
echo json($value);
echo ';';
echo '';
echo "\n";
}
}

the whole thing is quoted twice and it seems to be the view's fault.
i have several ajax-controller which have no views and directly output 
the json-objects in the actionAction()-methods like so:

echo json($db-selected-stuff);
it works as expected.

in the view-script the output is messed/quoted up and i have *no* idea 
where to look for this strange behaviour.


any ideas?
kai



[fw-general] view auto quoting


does the view/view-helper do quoting automatically?

view-helper.php
echo 'var ' . $name . ' = ' . 
Zend_Json::encode($value).';' . "\n";

}
}

the value is printed with quotes and the json-quotes are escaped.
any idea who does this quoting and where to turn it off?

thanks,
kai


Re: [fw-general] Form Filtering & Validation using Zend-Framework Components


Darby Felton wrote:

You might also take a look at the Zend_Filter_Input redesign proposal,
which is very much related to the functionality you describe:

http://framework.zend.com/wiki/x/D2k

looks pretty promising, thanks.

on the other hand i do not like the zend-style array-configuration,
i prefer coding-over-configuration..
furthermore i think the form-centric approach is missing in all 
proposals (or deliberatly refactored out into other components?)


thanks,
kai


[fw-general] Form Filtering & Validation using Zend-Framework Components


hello,

i am currently in the need of a form-library to process form-data 
without the ever going hassle of boring input sanitization and 
validation. i read thru the Zend-Form proposal and it seems that its 
going to be a *big* form-creation quick-form pendant.


i coded a component to do filtering and validation only and transporting 
values and errors over session-namespaces to redirect between 
processing<->view.


the usage is like this:

// FORM-PROCESSING
$F = new Form('edit');

// common form-data
$F->register('type')->isTableKey('mediatype', 'mediatype_id');
$F->register('collection')->isBool();
$F->register('parts')->isOptional()->isArray()->isTableKey('media', 
'media_id');

$F->register('lang')->isTableKey('locale', 'locale_id');
$F->register('country')->isTableKey('locale', 'locale_id');
$F->register('title')->isString();
$F->register('origtitle')->isString();
$F->register('comment')->isString();
$F->register('rating')->isInt(0, 5);

// optional checklists (kind of )
$F->register('genres')->isOptional()->isArray()->isTableKey('genre', 
'genre_id');

$F->register('genres_new')->isOptional()->isArray()->isString();
$F->register('persons')->isOptional()
->isArray()
->isTableKey('person', 'person_id')
->requires('person_roles');
$F->register('person_roles')->isOptional()
->isArray()
->isString();

$F->register('persons_new')->isOptional()
->isArray()
->isString()
->requires('person_roles_new');

$F->register('person_roles_new')->isOptional()
->isArray()
->isString();
[...]

// working with Zend-Validators, -Filters and Function-Delegates

function fooDelegate($elementName, $elementValue, $formData) {
  return true;
}

$F->register('foo')->validate(new Zend_Validate_xxx())
   ->filter(new Zend_Filter_yyy())
   ->delegate('fooDelegate');


try {
  $this->db->beginTransaction();
  $F->validate($_POST);

  $title = $F->value('title');
  ...

  if (($persons= $F->value('persons')) {
foreach ($persons as $personID) {
  ...
}
  }

  //or
  $persons = $F->value('persons', array());
  foreach ($persons as $personID) {
...
  }

} catch (FormException $e) {
$this->db->rollBack();
print_r($F->getErrors());
$this->redirect('back to edit-form-view');
}


// VIEW
$F = new Form('edit');
if ($F->hasErrors())
  print_r($F->getErrors());

if (!($title = $F->value('title')))
  $title = '';





any interest, opinions or hints?

yours,
kai


Re: [fw-general] Zend_Log


new release, i know... sorry ;)


[fw-general] Zend_Log


hello,

it seems that the whole Zend_Log-docs are messed up:


> $logger = new Zend_Log();
> $writer = new Zend_Log_Writer_Stream('php://output');
private constructor

> $logger->log('Informational message', Zend_Log::INFO);
Zend_Log::LEVEL_INFO
btw, why the LEVEL_ in the constant? just more typing-overhead...

btw2, the java logging facility has convenience methods like
Zend_Log::info(...
Zend_Log::warn(...
Zend_Log::debug(...


yours,
kai


Re: [fw-general] Action-Rewriting


Nico Edtinger wrote:

I just extended  Zend_Controller_Action to change dispatch():

public function dispatch($action)
{
$method = !empty($_SERVER['REQUEST_METHOD']) ? 
strtolower($_SERVER['REQUEST_METHOD']) : 'get';

if (method_exists($this, $action . $method)) {
parent::dispatch($action . $method);
} else {
parent::dispatch($action);
}
}

If I have a method called indexActionGet() or indexActionPost() it gets 
called if the request method matches. If not indexAction() is called (or 
__call() if it doesn't exist).

very smart, thanks alot.

yours,
kai


Re: [fw-general] Action-Rewriting


frederic wolf wrote:
everybody knows the form-POSTing problem if you hit the back- or 
refresh-button: "the page has expired bla bla"...


i want to implement two methods:
editAction():  display form
_editAction(): process form and http-redirect back to editAction()

however, it seems that the routing-process kills the underscore in 
"_editAction" and calls "editAction" instead.


any best-practice for the POST-problem?



you should this recent thread, it's well explained I think :
"Forwarding - Redirecting" initiated by Ian Warner

i know about the differences and it does not answer my question.

nevertheless thanks for the reply,
kai


[fw-general] Action-Rewriting


Hello,

everybody knows the form-POSTing problem if you hit the back- or 
refresh-button: "the page has expired bla bla"...


i want to implement two methods:
editAction():  display form
_editAction(): process form and http-redirect back to editAction()

however, it seems that the routing-process kills the underscore in 
"_editAction" and calls "editAction" instead.


any best-practice for the POST-problem?

thanks,
kai


[fw-general] Ajax.... How/Where to start?


Hello,

first of all, 0.9.1 is a very nice release, congratulations.

i searched the mailinglist-archives but cant find a proper 
way-to-do-the-ajax-thing-TM.
im looking for a small library which helps me firing ajax-calls to a 
zend-fwk controller, getting its actions results and embedding these 
into a html-table. i doesnt care (at the moment) whether the ajax-data 
is transported as plain-html or json.


could you please give me some suggestions regarding a
- stable, non-bloated java-script ajax-library
- to manipulate dom easily
- and send ajax-calls by using neat predefined functions

are there any other things to pay attention to on the ZFW-side?
session-management with ajax-calls?
any intentions to write something like a "Generic Ajax-Introduction for 
ZFK"?


looking forward for your advice,
kai


[fw-general] Zend_View Best-Practice Composite-View


hello,

has anybody information/ressources about a nice composite-view 
implementation?

i need this for multiple nested templates, e.g.:
- main-layout
- controller-layout
- view-layout
- helper-layout
etc...

how do you solve this?

thanks,
kai


Re: [fw-general] Zend_View, reference inside helpers


 > Any problem to use

$this->myHelperNeedView($this)?
it's not convenient, the view should provide this reference 
out-of-the-box...

but for the time being, this seems to be a reasonable solution.

thanks,
kai


Re: [fw-general] Zend_View, reference inside helpers


Michał Minicki wrote:

Kai Meder <[EMAIL PROTECTED]> napisał(a):
is there any way that the a view-helper may access the view, in which it 
was executed?


I was discussing this problem with Matthew some time ago and he agreed to 
do it eventually.

http://framework.zend.com/issues/browse/ZF-936
I have no idea when this will be implemented though.


thanks for your fast answer.
without the view-reference, how do you others implement view-helpers??
currently i have patched the source myself to get that reference...

yours,
kai



[fw-general] Zend_View, reference inside helpers

is there any way that the a view-helper may access the view, in which it 
was executed?

e.g. $view->escape
this would be extremely helpful to outsource common view-code into 
helpers...


thanks,
kai


[fw-general] Zend_View, reference inside helpers

is there any way that the a view-helper may access the view, in which it 
was executed?

e.g. $view->escape
this would be extremely helpful to outsource common view-code into 
helpers...


thanks,
kai