Zend_Validate_StringEquals
Jan0
If you ever wonder where that 'StringEquals' validator rule taken as example from the Zend_Filter_Input documentation page results in an error like below, well read again. It was clearly stated as 'hypothetical'.
Plugin by name 'StringEquals' was not found in the registry; used paths: Zend_Validate_: Zend/Validate/
Given such validator would be useful on a number of situations i.e. confirming passwords, emails, etc. I present to you my own version of the class.
<?php class Zend_Validate_StringEquals extends Zend_Validate_Abstract { const NOT_EQUAL = 'stringNotEqual'; const MISSING = 'stringMissing'; /** * @var array */ self::NOT_EQUAL => "%field1% and %field2% are not equal.", self::MISSING => "One or both strings are missing." ); /** * @var array */ 'field1' => '_field1', 'field2' => '_field2' ); protected $_case = false; protected $_field1 = null; protected $_field2 = null; /** * Sets validator options * * @param boolean $case * @return void */ public function __construct($case = false) { $this->_case = $case; } /** * Defined by Zend_Validate_Interface * * Returns true if and only if the the 2 strings are equal * * @param array $value * @return boolean */ public function isValid($value) { $this->_error(self::MISSING); } if($this->_case === true) $function = 'strcmp'; else $function = 'strcasecmp'; if(0 !== $function($this->_field1,$this->_field2)) $this->_error(self::NOT_EQUAL); return false; } else { return true; } } }
Here is a sample test case. Validate password and confirm password elements represented by 'password' and 'cpassword' element names respectively.
'presence' => 'required', 'fields' => 'password', 'messages' => "Passwords must be between 5 and 15 characters in length."), Zend_Validate_StringEquals::NOT_EQUAL => "Passwords does not match.", Zend_Validate_StringEquals::MISSING => "Both password fields must be filled.")))); $inputdata = new Zend_Filter_Input($filter,$validators,$_POST,$options);
Fetch Smarty Templates From MySQL Database
Mar0
I was recently working on a mailing application. With the nature of the bulk mailing routine, it was designed to store templates made by its users and email designers. Since most of them have been exposed to Smarty templating before we decided to base our email template parsing to Smarty.
Smarty does not come with the ability to parse templates from database natively, but it is easy to extend it to do just that.
DISCLAIMER: This is a quick and dirty hack I provided with my colleagues. Improvement required!
This approach should work on both PHP 4 and PHP 5, since Smarty.class.php is written on PHP 4.
What we will need to do is extend Smarty.class.php on a new class and override function _fetch_resource_info and replace the if clause demonstrated below to use our code that actually fetches database stored templates.
class Smarty
{
function _fetch_resource_info(&$params) {
....
if ($this->_parse_resource_name($_params)) {
.....
}
....
}
}
Our resulting class would look something like:
require_once 'Smarty.class.php';
class Smarty_Db extends Smarty
{
function _fetch_resource_info(&$params) {
....
$_resource_type = $_params['resource_type'];
$_resource_name = $_params['resource_name'];
$db = new Template_Db;
if ($params['get_source']) {
$params['source_content'] = $db->fetchTemplate($myTemplateId);
}
$params['resource_timestamp'] = now();
$_return = true;
....
}
}
So you would then use your Smarty extended class like:
$smarty = new Smarty_Db; $smarty->compile_dir = '/path/to/my/compile/dir'; $compiledTemplateFromDb = $smarty->fetch($myTemplateId);
That is all there is to it actually. I haven't went through all the Smarty pre and post processing, but this should suffice the requirements for now.
Hope this helps.
CSS Gradient Text Effect
Jan0
This is a very useful and cool CSS design approach, saves time and effort and still SEO friendly. Hit the link for more.
Do you want to create fancy headings without rendering each heading with Photoshop? Here is a simple CSS trick to show you how to create gradient text effect with a PNG image (pure CSS, no Javascript or Flash). All you need is an empty tag in the heading and apply the background image overlay using the CSS position:absolute property. This trick has been tested on most browsers: Firefox, Safari, Opera, and even Internet Explorer 6. Continue to read this article to find out how.
http://www.webdesignerwall.com/tutorials/css-gradient-text-effect/












