diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-10-18 01:08:58 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-10-18 01:08:58 +0000 |
commit | 3326f742fe2a1745dc1ebdd060d023263af299b9 (patch) | |
tree | b5ec4cadf5e37a39e83e978af1bd8da9d1c2dea9 | |
parent | 90be9fbb84623095a360cfa6e9c1955a891eeba5 (diff) |
merge rev 2771,2772 from branch 2.0
- 2771 event tracer improvement: option to show all registered event handlers for every page
- 2772 php optims (small): remove/replace preg_xxx with faster simple string functions
git-svn-id: http://piwigo.org/svn/trunk@2773 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | include/functions_html.inc.php | 7 | ||||
-rw-r--r-- | include/functions_url.inc.php | 38 | ||||
-rw-r--r-- | include/section_init.inc.php | 11 | ||||
-rw-r--r-- | plugins/event_tracer/main.inc.php | 42 | ||||
-rw-r--r-- | plugins/event_tracer/tracer_admin.php | 2 | ||||
-rw-r--r-- | plugins/event_tracer/tracer_admin.tpl | 10 |
6 files changed, 75 insertions, 35 deletions
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index 0a09ab31a..cb530749a 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -81,7 +81,7 @@ function create_navigation_bar( $pages_around = $conf['paginate_pages_around']; $start_str = $clean_url ? '/start-' : - ( ( strstr($url, '?')===false ? '?':'&') . 'start=' ); + ( ( strpos($url, '?')===false ? '?':'&') . 'start=' ); $navbar = ''; @@ -781,8 +781,7 @@ function set_status_header($code, $text='') function render_category_description($desc) { global $conf; - if ( !( $conf['allow_html_descriptions'] and - preg_match('/<(div|br|img|script).*>/i', $desc) ) ) + if ( !$conf['allow_html_descriptions'] ) { $desc = nl2br($desc); } @@ -827,4 +826,4 @@ function register_default_menubar_blocks( $menu_ref_arr ) $menu->register_block( new RegisteredBlock( 'mbIdentification', 'identification', 'piwigo') ); } -?> +?>
\ No newline at end of file diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index 9921237a6..d58e94590 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -99,7 +99,7 @@ function add_url_params($url, $params) if ($is_first) { $is_first = false; - $url .= ( strstr($url, '?')===false ) ? '?' :'&'; + $url .= ( strpos($url, '?')===false ) ? '?' :'&'; } else { @@ -245,7 +245,7 @@ function make_picture_url($params) if ( isset($params['image_file']) ) { $fname_wo_ext = get_filename_wo_extension($params['image_file']); - if (! preg_match('/^\d+(-|$)/', $fname_wo_ext) ) + if ( ord($fname_wo_ext)>ord('9') or !preg_match('/^\d+(-|$)/', $fname_wo_ext) ) { $url .= $fname_wo_ext; break; @@ -440,7 +440,7 @@ function make_section_in_url($params) function parse_section_url( $tokens, &$next_token) { $page=array(); - if (0 === strpos(@$tokens[$next_token], 'categor')) + if (strncmp(@$tokens[$next_token], 'categor', 7)==0 ) { $page['section'] = 'categories'; $next_token++; @@ -505,7 +505,7 @@ function parse_section_url( $tokens, &$next_token) $page['category']=$result; } } - else if (0 === strpos(@$tokens[$next_token], 'tag')) + elseif ( 'tags' == @$tokens[$next_token] ) { $page['section'] = 'tags'; $page['tags'] = array(); @@ -518,7 +518,9 @@ function parse_section_url( $tokens, &$next_token) while (isset($tokens[$i])) { - if ( preg_match('/^(created-|posted-|start-(\d)+)/', $tokens[$i]) ) + if (strpos($tokens[$i], 'created-')===0 + or strpos($tokens[$i], 'posted-')===0 + or strpos($tokens[$i], 'start-')===0 ) break; if ( preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches) ) @@ -544,32 +546,32 @@ function parse_section_url( $tokens, &$next_token) page_not_found('Requested tag does not exist', get_root_url().'tags.php' ); } } - else if (0 === strpos(@$tokens[$next_token], 'fav')) + elseif ( 'favorites' == @$tokens[$next_token] ) { $page['section'] = 'favorites'; $next_token++; } - else if ('most_visited' == @$tokens[$next_token]) + elseif ('most_visited' == @$tokens[$next_token]) { $page['section'] = 'most_visited'; $next_token++; } - else if ('best_rated' == @$tokens[$next_token]) + elseif ('best_rated' == @$tokens[$next_token]) { $page['section'] = 'best_rated'; $next_token++; } - else if ('recent_pics' == @$tokens[$next_token]) + elseif ('recent_pics' == @$tokens[$next_token]) { $page['section'] = 'recent_pics'; $next_token++; } - else if ('recent_cats' == @$tokens[$next_token]) + elseif ('recent_cats' == @$tokens[$next_token]) { $page['section'] = 'recent_cats'; $next_token++; } - else if ('search' == @$tokens[$next_token]) + elseif ('search' == @$tokens[$next_token]) { $page['section'] = 'search'; $next_token++; @@ -582,7 +584,7 @@ function parse_section_url( $tokens, &$next_token) $page['search'] = $matches[1]; $next_token++; } - else if ('list' == @$tokens[$next_token]) + elseif ('list' == @$tokens[$next_token]) { $page['section'] = 'list'; $next_token++; @@ -621,18 +623,12 @@ function parse_well_known_params_url($tokens, &$i) $page = array(); while (isset($tokens[$i])) { - if (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) - { - $page['start'] = $matches[1]; - } - if ( 'flat' == $tokens[$i] ) { // indicate a special list of images $page['flat'] = true; } - - if (preg_match('/^(posted|created)/', $tokens[$i] )) + elseif (strpos($tokens[$i], 'created-')===0 or strpos($tokens[$i], 'posted-')===0) { $chronology_tokens = explode('-', $tokens[$i] ); @@ -653,6 +649,10 @@ function parse_well_known_params_url($tokens, &$i) $page['chronology_date'] = $chronology_tokens; } } + elseif (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) + { + $page['start'] = $matches[1]; + } $i++; } return $page; diff --git a/include/section_init.inc.php b/include/section_init.inc.php index 97f2f0a42..0d8659113 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -65,10 +65,7 @@ else } // deleting first "/" if displayed -$tokens = explode( - '/', - preg_replace('#^/#', '', $rewritten) - ); +$tokens = explode('/', ltrim($rewritten, '/') ); // $tokens = array( // 0 => category, // 1 => 12-foo, @@ -183,7 +180,7 @@ if ('categories' == $page['section'] and !isset($page['flat'])) if (pwg_get_session_var('image_order',0) > 0) { $image_order_id = pwg_get_session_var('image_order'); - + $orders = get_category_preferred_image_orders(); // the current session stored image_order might be not compatible with @@ -339,12 +336,10 @@ SELECT DISTINCT image_id $items = array_from_query($query, 'image_id'); } - $title = get_tags_content_title(); - $page = array_merge( $page, array( - 'title' => $title, + 'title' => get_tags_content_title(), 'items' => $items, ) ); diff --git a/plugins/event_tracer/main.inc.php b/plugins/event_tracer/main.inc.php index e80d29238..742bfd0ae 100644 --- a/plugins/event_tracer/main.inc.php +++ b/plugins/event_tracer/main.inc.php @@ -34,12 +34,11 @@ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); class EventTracer { - var $me_working; var $my_config; + var $trigger_counts = array(); function EventTracer() { - $this->me_working=0; } function get_config_file_dir() @@ -67,6 +66,7 @@ class EventTracer { $this->my_config['filters'] = array( '.*' ); $this->my_config['show_args'] = false; + $this->my_config['show_registered'] = true; $this->save_config(); } } @@ -82,6 +82,7 @@ class EventTracer function on_pre_trigger_event($event_info) { + @$this->trigger_counts[$event_info['event']]++; $this->dump('pre_trigger_event', $event_info); } function on_post_trigger_event($event_info) @@ -91,9 +92,43 @@ class EventTracer function on_trigger_action($event_info) { + @$this->trigger_counts[$event_info['event']]++; $this->dump('trigger_action', $event_info); } + function on_page_tail() + { + if (1 || @$this->my_config['show_registered']) + { + global $debug, $pwg_event_handlers; + $out = ''; + foreach ($pwg_event_handlers as $event => $prio_array) + { + $out .= $event.' '.intval(@$this->trigger_counts[$event])." calls\n"; + foreach ($prio_array as $prio => $handlers) + { + foreach ($handlers as $handler) + { + $out .= "\t$prio "; + if ( is_array($handler['function']) ) + { + if ( is_string($handler['function'][0]) ) + $out .= $handler['function'][0].'::'; + else + $out .= @get_class($handler['function'][0]).'->'; + $out .= $handler['function'][1]; + } + else + $out .= $handler['function']; + $out .= "\n"; + } + } + $out .= "\n"; + } + $debug .= '<pre>'.$out.'</pre>'; + } + } + function dump($event, $event_info) { foreach( $this->my_config['filters'] as $filter) @@ -108,7 +143,7 @@ class EventTracer } else $s = ''; - pwg_debug($event.' "'.$event_info['event'].'" '.($s) ); + pwg_debug($event.' "'.$event_info['event'].'" '.($this->trigger_counts[$event_info['event']]).' calls '.($s) ); break; } } @@ -132,6 +167,7 @@ $obj->load_config(); add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') ); add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') ); +add_event_handler('loc_begin_page_tail', array(&$obj, 'on_page_tail') ); add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') ); set_plugin_data($plugin['id'], $obj); ?> diff --git a/plugins/event_tracer/tracer_admin.php b/plugins/event_tracer/tracer_admin.php index b17f2a301..6e5b864e0 100644 --- a/plugins/event_tracer/tracer_admin.php +++ b/plugins/event_tracer/tracer_admin.php @@ -17,6 +17,7 @@ if ( isset($_POST['eventTracer_filters']) ) else $me->my_config['filters'] = array(); $me->my_config['show_args'] = isset($_POST['eventTracer_show_args']); + $me->my_config['show_registered'] = isset($_POST['eventTracer_show_registered']); $me->save_config(); global $page; array_push($page['infos'], 'event tracer options saved'); @@ -24,6 +25,7 @@ if ( isset($_POST['eventTracer_filters']) ) $template->assign('EVENT_TRACER_FILTERS', implode("\n", $me->my_config['filters'] ) ); $template->assign('EVENT_TRACER_SHOW_ARGS', $me->my_config['show_args'] ? 'checked="checked"' : '' ); $template->assign('U_LIST_EVENTS', get_admin_plugin_menu_link(dirname(__FILE__).'/event_list.php')); +$template->assign('EVENT_TRACER_SHOW_REGISTERED', $me->my_config['show_registered'] ? 'checked="checked"' : '' ); //$template->assign_var('EVENT_TRACER_F_ACTION', $my_url); diff --git a/plugins/event_tracer/tracer_admin.tpl b/plugins/event_tracer/tracer_admin.tpl index 17d7e2b01..560459915 100644 --- a/plugins/event_tracer/tracer_admin.tpl +++ b/plugins/event_tracer/tracer_admin.tpl @@ -12,15 +12,23 @@ You can use this plugin to see what events is Piwigo calling. <fieldset> <legend>Event Tracer</legend> -<label>Show event argument +<label>Show event arguments <input type="checkbox" name="eventTracer_show_args" {$EVENT_TRACER_SHOW_ARGS} /> </label> + <br/> + <label>Fill below a list of regular expressions (one per line). An event will be logged if its name matches at least one expression in the list. <textarea name="eventTracer_filters" id="eventTracer_filters"rows="10" cols="80">{$EVENT_TRACER_FILTERS}</textarea> </label> +<br/> + +<label>Show all registered handlers + <input type="checkbox" name="eventTracer_show_registered" {$EVENT_TRACER_SHOW_REGISTERED} /> +</label> + </fieldset> <p><input class="submit" type="submit" value="Submit" /></p> |