function testTimers() { $start = TimberHelper::start_timer(); sleep(1); $end = TimberHelper::stop_timer($start); $this->assertContains(' seconds.', $end); $time = str_replace(' seconds.', '', $end); $this->assertGreaterThan(1, $time); }
<?php /** * The main template file. */ // set up page data $template = false; $start = TimberHelper::start_timer(); $data = Timber::get_context(); $data['latest_news'] = get_fg_latest_posts(); if (is_singular()) { $data['post'] = new TimberPost(); } else { $data['posts'] = Timber::get_posts(); } $data['config'] = $get_config(); $data['menu'] = new TimberMenu('main-menu'); if (is_single()) { $template = 'single'; $data['slideshow'] = $get_slideshow(); } elseif (is_page()) { $matches = null; $template = 'page'; // for custom templates $returnValue = preg_match('/.*\\/(.*?)\\./', get_page_template(), $matches); if ($returnValue) { $template = 'page-' . $matches[1]; } $data['slideshow'] = $get_slideshow(); } elseif (is_home()) { $template = 'index';
public static function handle_post_results($results, $PostClass = 'TimberPost') { $start = TimberHelper::start_timer(); $posts = array(); foreach ($results as $rid) { $PostClassUse = $PostClass; if (is_array($PostClass)) { $post_type = get_post_type($rid); $PostClassUse = 'TimberPost'; if (isset($PostClass[$post_type])) { $PostClassUse = $PostClass[$post_type]; } else { if (is_array($PostClass)) { TimberHelper::error_log($post_type . ' of ' . $rid . ' not found in ' . print_r($PostClass, true)); } else { TimberHelper::error_log($post_type . ' not found in ' . $PostClass); } } } $post = new $PostClassUse($rid); if (isset($post->ID)) { $posts[] = $post; } } return $posts; }