From: <lph...@us...> - 2008-10-28 17:12:43
|
Revision: 15361 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=15361&view=rev Author: lphuberdeau Date: 2008-10-28 17:12:38 +0000 (Tue, 28 Oct 2008) Log Message: ----------- [MOD] Add precise filters to tiki-editpage.php Modified Paths: -------------- branches/experimental/jitfilter/categorize.php branches/experimental/jitfilter/lib/core/lib/JitFilter.php branches/experimental/jitfilter/lib/core/test/JitFilter/AccessTest.php branches/experimental/jitfilter/lib/core/test/JitFilter/FilterTest.php branches/experimental/jitfilter/tiki-editpage.php Modified: branches/experimental/jitfilter/categorize.php =================================================================== --- branches/experimental/jitfilter/categorize.php 2008-10-28 16:15:08 UTC (rev 15360) +++ branches/experimental/jitfilter/categorize.php 2008-10-28 17:12:38 UTC (rev 15361) @@ -25,23 +25,28 @@ $_REQUEST["cat_categorize"] = 'on'; } + if( isset($_REQUEST['cat_categories']) ) + $categorize_cats = $_REQUEST['cat_categories']->asArray(); + else + $categorize_cats = array(); + if ( isset($_REQUEST["cat_categorize"]) && $_REQUEST["cat_categorize"] == 'on' && ! (isset($_REQUEST["cat_clearall"]) && $_REQUEST["cat_clearall"] == 'on') ) { $smarty->assign('cat_categorize', 'y'); } else { - $_REQUEST['cat_categories'] = NULL; + $categorize_cats = NULL; } if ($prefs["feature_wikiapproval"] == 'y' && $cat_type == 'wiki page' && substr($cat_objid, 0, strlen($prefs['wikiapproval_prefix'])) == $prefs['wikiapproval_prefix']) { - if ($prefs['wikiapproval_approved_category'] > 0 && in_array($prefs['wikiapproval_approved_category'], $_REQUEST['cat_categories'])) { - $_REQUEST['cat_categories'] = array_diff($_REQUEST['cat_categories'],Array($prefs['wikiapproval_approved_category'])); + if ($prefs['wikiapproval_approved_category'] > 0 && in_array($prefs['wikiapproval_approved_category'], $categorize_cats)) { + $categorize_cats = array_diff($categorize_cats,Array($prefs['wikiapproval_approved_category'])); } - if ($prefs['wikiapproval_staging_category'] > 0 && !in_array($prefs['wikiapproval_staging_category'], $_REQUEST['cat_categories'])) { - $_REQUEST['cat_categories'][] = $prefs['wikiapproval_staging_category']; + if ($prefs['wikiapproval_staging_category'] > 0 && !in_array($prefs['wikiapproval_staging_category'], $categorize_cats)) { + $categorize_cats[] = $prefs['wikiapproval_staging_category']; } - if ($prefs['wikiapproval_outofsync_category'] > 0 && !in_array($prefs['wikiapproval_outofsync_category'], $_REQUEST['cat_categories'])) { - $_REQUEST['cat_categories'][] = $prefs['wikiapproval_outofsync_category']; + if ($prefs['wikiapproval_outofsync_category'] > 0 && !in_array($prefs['wikiapproval_outofsync_category'], $categorize_cats)) { + $categorize_cats[] = $prefs['wikiapproval_outofsync_category']; } } - $categlib->update_object_categories($_REQUEST['cat_categories'], $cat_objid, $cat_type, $cat_desc, $cat_name, $cat_href); + $categlib->update_object_categories($categorize_cats, $cat_objid, $cat_type, $cat_desc, $cat_name, $cat_href); $cats = $categlib->get_object_categories($cat_type, $cat_objid); if (isset($section) && $section == 'wiki' && $prefs['feature_wiki_mandatory_category'] > 0) Modified: branches/experimental/jitfilter/lib/core/lib/JitFilter.php =================================================================== --- branches/experimental/jitfilter/lib/core/lib/JitFilter.php 2008-10-28 16:15:08 UTC (rev 15360) +++ branches/experimental/jitfilter/lib/core/lib/JitFilter.php 2008-10-28 17:12:38 UTC (rev 15361) @@ -26,7 +26,9 @@ { if( is_array( $this->stored[$key] ) ) { $this->stored[$key] = new self( $this->stored[$key] ); - if( $this->defaultFilter ) + if( isset( $this->filters[$key] ) ) + $this->stored[$key]->setDefaultFilter( $this->filters[$key] ); + elseif( $this->defaultFilter ) $this->stored[$key]->setDefaultFilter( $this->defaultFilter ); } @@ -70,6 +72,18 @@ return (string) $this->stored; } + function asArray() + { + $ret = array(); + foreach( array_keys( $this->stored ) as $k ) { + $ret[$k] = $this->offsetGet($k); + if( $ret[$k] instanceof self ) + $ret[$k] = $ret[$k]->asArray(); + } + + return $ret; + } + function setDefaultFilter( $filter ) { if( ! $filter instanceof Zend_Filter_Interface ) @@ -84,6 +98,10 @@ $filter = $this->mapFilter( $filter ); $this->filters[$key] = $filter; + + if( isset($this->stored[$key]) && $this->stored[$key] instanceof self ) { + $this->stored[$key]->setDefaultFilter( $filter ); + } } function replaceFilters( $filters ) Modified: branches/experimental/jitfilter/lib/core/test/JitFilter/AccessTest.php =================================================================== --- branches/experimental/jitfilter/lib/core/test/JitFilter/AccessTest.php 2008-10-28 16:15:08 UTC (rev 15360) +++ branches/experimental/jitfilter/lib/core/test/JitFilter/AccessTest.php 2008-10-28 17:12:38 UTC (rev 15361) @@ -40,6 +40,11 @@ $this->assertTrue( isset( $this->array['baz'] ) ); $this->assertFalse( isset( $this->array['hello'] ) ); } + + function testDirectArray() + { + $this->assertEquals( array(), array_diff( array( 'hello', 'world' ), $this->array['baz']->asArray() ) ); + } } ?> Modified: branches/experimental/jitfilter/lib/core/test/JitFilter/FilterTest.php =================================================================== --- branches/experimental/jitfilter/lib/core/test/JitFilter/FilterTest.php 2008-10-28 16:15:08 UTC (rev 15360) +++ branches/experimental/jitfilter/lib/core/test/JitFilter/FilterTest.php 2008-10-28 17:12:38 UTC (rev 15361) @@ -58,6 +58,31 @@ $this->assertEquals( '10 5 ', $this->array['content'] ); $this->assertEquals( 'WORLD !', $this->array['baz'][1] ); } + + function testNestedDefault() + { + $this->array->replaceFilters( array( + 'foo' => new Zend_Filter_Digits, + 'content' => new Zend_Filter_StripTags, + 'baz' => new Zend_Filter_StringToUpper, + ) ); + + $this->assertEquals( '123', $this->array['foo'] ); + $this->assertEquals( '10 5 ', $this->array['content'] ); + $this->assertEquals( 'WORLD !', $this->array['baz'][1] ); + + $this->array->replaceFilter( 'baz', new Zend_Filter_Alpha ); + $this->assertEquals( 'world', $this->array['baz'][1] ); + + $this->array->replaceFilters( array( + 'baz' => array( + 1 => new Zend_Filter_Digits, + ), + ) ); + + $this->assertEquals( 'hello', $this->array['baz'][0] ); + $this->assertEquals( '', $this->array['baz'][1] ); + } } ?> Modified: branches/experimental/jitfilter/tiki-editpage.php =================================================================== --- branches/experimental/jitfilter/tiki-editpage.php 2008-10-28 16:15:08 UTC (rev 15360) +++ branches/experimental/jitfilter/tiki-editpage.php 2008-10-28 17:12:38 UTC (rev 15361) @@ -8,6 +8,48 @@ $section = "wiki page"; require_once ('tiki-setup.php'); +require_once 'Zend/Filter/PregReplace.php'; +/* +$_REQUEST->replaceFilters( array( + // TODO : ??? 'attach_comment' => 'striptags', + 'cell' => 'digits', + // TODO : ??? 'contributions' => 'digits', + 'cat_categories' => 'digits', + 'cat_categorize' => 'alpha', + 'categId' => new Zend_Filter_PregReplace( '/[^\d\+]+/', '' ), + // TODO : ??? 'comment' => 'striptags', + 'copyrightAuthors' => 'striptags', + 'copyrightTitle' => 'striptags', + 'copyrightYear' => new Zend_Filter_PregReplace( '/[^\d\-]+/', '' ), + 'current_page_id' => 'digits', + 'description' => 'striptags', + // TODO : ??? 'edit' => 'wiki', + // TODO : ??? 'footnote' => 'striptags', + 'freetag_string' => 'striptags', + 'hdr' => 'digits', + 'isminor' => 'alpha', + 'lang' => new Zend_Filter_PregReplace( '/[^a-z\-]+/', '' ), + 'lock_it' => 'alpha', + 'newver' => 'digits', + 'oldver' => 'digits', + 'page' => 'striptags', + 'page_ref_id' => 'digits', + 'parse_html' => 'alpha', + 'poll_template' => 'striptags', + // TODO : ??? 'poll_template' => 'striptags', + 'poll_title' => 'striptags', + 'pos' => 'digits', + 'source_page' => 'striptags', + 'spellcheck' => 'alpha', + // TODO : ??? 'such_url' => 'striptags', + 'templateId' => 'digits', + 'translationOf' => 'striptags', + 'ratingId' => 'digits', + // TODO : ??? 'wiki_authors_style' => 'word', + 'wiki_cache' => 'digits', + 'wysiwyg' => 'alpha', +) ); +*/ include_once ('lib/wiki/wikilib.php'); include_once ('lib/structures/structlib.php'); include_once ('lib/notifications/notificationlib.php'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |