|
Jquery Dialog Load and External Script File |
|
|
|
|
Written by Joe
|
|
Tuesday, 23 November 2010 19:13 |
|
Internet Explorer 7/8 had problems loading content through the load() method into a Jquery UI dialog window. The load ajax request was failing frequently (not all of the time). This was caused by the external file being called via load() containg script tags including another external file.
For example:
$dialog = $( '<div></div>' ) .load( '/external_page.php' ) .dialog();
If external_page.php contained the following:
<script type="text/javascript" src="/js/jquery/another_external_file.js"></script>
Then an ajax error was being thrown intermittently in IE (not seen in Firefox/Opera). Wrapping this include in a getScript call avoided it:
<script type="text/javascript">
$(document).ready(function() { $.getScript( '/js/jquery/another_external_file.js' ); });
</script>
|
|
Last Updated on Tuesday, 23 November 2010 19:27 |
|
|
Written by Joe
|
|
Monday, 03 May 2010 23:24 |
|
Implementing HTML purifier and Zend Form together is pretty straight forward. Download the most recent version from http://htmlpurifier.org and then place all code located in the 'library' folder somewhere in your application accessible from your include paths.
For example: 'ZF/library/My/HtmlPurifier/'
Now in the Form class add the filter path and the filter property to the form element.
$this->addElementPrefixPath( 'Form_Filters', 'Form/Filters/', 'filter' );
$content_text->setAttrib( 'class', 'text_editor' ) ->addFilter( 'HTMLBody' ) ->setAllowEmpty( false ) ->addValidator( 'NotEmpty', true, array( 'messages' => 'You must supply some <b>Content</b> for your article.' ) );
Then create the HTML purifier filter itself.
class Form_Filters_HTMLBody implements Zend_Filter_Interface { protected $_htmlPurifier = null; public function __construct() { require_once 'My/HtmlPurifier/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); $config->set( 'HTML.Allowed', 'p,em,h1,h2,h3,h4,h5,strong,a[href],ul,ol,li,code,pre,' .'blockquote,img[src|alt|height|width],sub,sup' ); $config->set( 'AutoFormat.Linkify', 'true' ); $config->set( 'AutoFormat.AutoParagraph', 'true' ); $this->_htmlPurifier = new HTMLPurifier( $config ); }
public function filter( $value ) { return $this->_htmlPurifier->purify( $value ); }
}
Config options can probably be added via a single array and there are plenty of additional config options to consider - this is just a simple up and running method. Your character encoding and document type require additional consideration, as does the html white list you wish to incorporate and additional behavioural tweaks. |
|
Last Updated on Monday, 03 May 2010 23:41 |
|
Written by Joe
|
|
Friday, 30 April 2010 14:21 |
|
Using a static route in conjunction with zend paginator prohibits the pagination links (prev/next etc) from passing the 'page' parameter to the url. Instead use a standard route or regexp, for example: http://some-domain.com/index/users To map this url with a custom route do not use:
$route = new Zend_Controller_Router_Route_Static( 'users', array( 'controller' => 'index', 'action' => 'users' ) ); $router->addRoute( 'users', $route );
but instead:
$route_users = new Zend_Controller_Router_Route( 'users/:page', array( 'controller' => 'index', 'action' => 'users', 'page' => 1 ) ); $router->addRoute( 'targets', $route_users );
This will map requests correctly for: http://some-domain.com/users http://some-domain.com/users/1 http://some-domain.com/users/2 etc and keeps the pagination links working correctly. Omitting the 'page' value from the array means a request for 'http://some-domain.com/users' would throw an error. |
|
Last Updated on Friday, 30 April 2010 20:46 |
|
Written by Joe
|
|
Friday, 30 April 2010 14:17 |
|
Changing character encoding types requires a change in php string function families used with php. Changing your database to utf-8 format, html page declarations to utf-8 and ensuring your application works strictly with utf-8 data negates the usage of the functions:
- strlen
- strtolower
- substr
- etc...
And requires you to use the multi byte verions:
- mb_strlen
- mb_strtolower
- mb_substr
- etc...
It is also advisable when taking such an approach to manually forcing that php is working internally with your desired multibyte character set. Useful functions for doing this include:
// SET mb_internal_encoding( 'UTF-8' );
// GET echo mb_internal_encoding();
Php multibyte string functions for more information. |
|
Last Updated on Friday, 30 April 2010 18:08 |
|
Written by Joe
|
|
Wednesday, 17 March 2010 18:17 |
|
When working with Zend Framework it is important to match the character set used internally with that of the mysql DB. Otherwise, inserted data may not match the working character set and result in those weird "browser is confused shapes" that appear.
Previously, this could be set once when defining the db adapter using the now deprecated:
db.params.driver_options.1002 = "SET NAMES utf8"
Now simplified to:
db.params.charset = utf8;
|
|
Last Updated on Friday, 30 April 2010 18:32 |
|
|
|
|