function testFunctionsPHP()
 {
     $context = Timber::get_context();
     $this->assertEquals('StarterSite', get_class($context['site']));
     $this->assertTrue(current_theme_supports('post-thumbnails'));
     $this->assertEquals('bar', $context['foo']);
 }
Exemplo n.º 2
0
 /**
  * Custom implementation for get_context method.
  */
 public function get_context()
 {
     global $content_width;
     if (class_exists('Easy_Digital_Downloads')) {
         global $edd_options;
     }
     $context = Timber::get_context();
     $sidebar_primary = Timber::get_widgets('sidebar_primary');
     $sidebar_footer = Timber::get_widgets('sidebar_footer');
     $context['theme_mods'] = get_theme_mods();
     $context['site_options'] = wp_load_alloptions();
     $context['teaser_mode'] = apply_filters('maera/teaser/mode', 'excerpt');
     $context['thumbnail']['width'] = apply_filters('maera/image/width', 600);
     $context['thumbnail']['height'] = apply_filters('maera/image/height', 371);
     $context['menu']['primary'] = has_nav_menu('primary_navigation') ? new TimberMenu('primary_navigation') : null;
     $context['sidebar']['primary'] = apply_filters('maera/sidebar/primary', $sidebar_primary);
     $context['sidebar']['footer'] = apply_filters('maera/sidebar/footer', $sidebar_footer);
     $context['pagination'] = Timber::get_pagination();
     $context['comment_form'] = TimberHelper::get_comment_form();
     $context['comments_args'] = array('style' => 'ul', 'reply_text' => __('Reply', 'maera'), 'short_ping' => true, 'avatar_size' => 60);
     $context['site_logo'] = get_option('site_logo', false);
     $context['content_width'] = $content_width;
     $context['sidebar_template'] = maera_templates_sidebar();
     if (class_exists('Easy_Digital_Downloads')) {
         $data['edd_options'] = $edd_options;
         $data['download_categories'] = Timber::get_terms('download_category');
         $data['download_tags'] = Timber::get_terms('download_tag');
         $data['default_image'] = new TimberImage(get_template_directory_uri() . '/assets/images/default.png');
     }
     return apply_filters('maera/timber/context', $context);
 }
 public function form($instance)
 {
     $context = \Timber::get_context();
     $context['title'] = !empty($instance['title']) ? $instance['title'] : __('Test', self::I18N_DOMAIN);
     $context['widget'] = $this;
     \Timber::render('timber-test-widget-form.twig', $context);
 }
Exemplo n.º 4
0
 public function load_view()
 {
     $context = Timber::get_context();
     $context['data'] = $this->data;
     $context['constants'] = get_slate_constants();
     Timber::render(theme_views . '/single.twig', $context);
 }
Exemplo n.º 5
0
 function testLinkOnSubdirectoryInstall()
 {
     update_option('siteurl', 'http://example.org/wordpress', true);
     $context = Timber::get_context();
     $theme = $context['site']->theme;
     $output = Timber::compile_string('{{site.theme.link}}', $context);
     $this->assertEquals('http://example.org/wp-content/themes/' . $theme->slug, $output);
 }
Exemplo n.º 6
0
 function testGetData()
 {
     $_GET['foo'] = 'bar';
     $template = '{{request.get.foo}}';
     $context = Timber::get_context();
     $str = Timber::compile_string($template, $context);
     $this->assertEquals('bar', $str);
 }
Exemplo n.º 7
0
 /**
  *
  * {$inheritdoc}
  *
  */
 public function getCallback()
 {
     $context = \Timber::get_context();
     $context['options'] = $this->getOptions();
     $context['field_name'] = self::META_NAME_PAGE_TYPE;
     $context['current_value'] = $this->getCurrentValue();
     \Timber::render($this->dic['CMS']->getViewPath('meta_boxes/page-type.html.twig'), $context);
 }
Exemplo n.º 8
0
 function testTimberContext()
 {
     add_filter('timber/context', function ($context) {
         $context['person'] = "Nathan Hass";
         return $context;
     });
     $context = Timber::get_context();
     $this->assertEquals('Nathan Hass', $context['person']);
 }
Exemplo n.º 9
0
 /**
  * Get the twig file and pass the replacement to it.
  * This function is just a helper for the do_twig_replacements function.
  */
 public function twig_replacements($replacement = false)
 {
     // If no replacement has been defined, exit.
     if (!$replacement) {
         return;
     }
     $context = Timber::get_context();
     $context['element'] = $replacement;
     Timber::render(array('twig-str_replace.twig'), $context, Maera()->cache->cache_duration());
 }
Exemplo n.º 10
0
 /**
  *
  * Callback methods for the options page
  *
  * @author Tim Perry
  *
  */
 public function menuPageCallback()
 {
     $args = array('public' => true);
     $context = \Timber::get_context();
     $context['postTypes'] = get_post_types($args, 'names');
     $context['settingsGroupName'] = self::SETTINGS_GROUP_NAME;
     $context['fieldName'] = self::OPTION_NAME_SHOW_ON;
     $context['currentValue'] = get_option(self::OPTION_NAME_SHOW_ON);
     \Timber::render($this->getPath() . '/views/options-page.twig', $context);
 }
Exemplo n.º 11
0
 /**
  * This throws an infite loop if memorization isn't working
  */
 function testContextLoop()
 {
     add_filter('timber_context', function ($context) {
         $context = Timber::get_context();
         $context['zebra'] = 'silly horse';
         return $context;
     });
     $context = Timber::get_context();
     $this->assertEquals('http://example.org', $context['http_host']);
 }
Exemplo n.º 12
0
 function testPHPSidebar()
 {
     add_filter('timber_context', function ($context) {
         $context['sidebar'] = Timber::get_sidebar('assets/my-sidebar.php');
         return $context;
     });
     $context = Timber::get_context();
     $result = Timber::compile('assets/main-w-sidebar-php.twig', $context);
     $this->assertEquals("A Fever You Can't Sweat Out by Panic! at the Disco from 2005", trim($result));
 }
Exemplo n.º 13
0
 function testFunctionsPHP()
 {
     self::_setupStarterTheme();
     require_once get_template_directory() . '/functions.php';
     $context = Timber::get_context();
     $this->assertEquals('StarterSite', get_class($context['site']));
     $this->assertTrue(current_theme_supports('post-thumbnails'));
     $this->assertEquals('bar', $context['foo']);
     switch_theme('twentythirteen');
 }
Exemplo n.º 14
0
 function testTwigSidebar()
 {
     $context = Timber::get_context();
     $sidebar_post = $this->factory->post->create(array('post_title' => 'Sidebar post content'));
     $sidebar_context = array();
     $sidebar_context['post'] = new TimberPost($sidebar_post);
     $context['sidebar'] = Timber::get_sidebar('assets/sidebar.twig', $sidebar_context);
     $result = Timber::compile('assets/main-w-sidebar.twig', $context);
     $this->assertEquals('I am the main stuff <h4>Sidebar post content</h4>', trim($result));
 }
Exemplo n.º 15
0
 /**
  * Returns filtered Timber Context
  *
  * @param array $args Elements to be filtered.
  * @param bool  $override_with_empty Whether to override default when empty is provided.
  * @return array
  */
 public function get_filtered_context($args = false, $override_with_empty = true)
 {
     if (!$override_with_empty) {
         $args = $this->remove_empty($args);
     }
     $this->setup_filters($args);
     $context = Timber::get_context();
     $context = $this->add_context_elements($context);
     $this->remove_filters($args);
     return $context;
 }
Exemplo n.º 16
0
 /**
  *
  *  Callback for the options page
  *
  * @author Tim Perry
  *
  */
 public function optionsPageCallback()
 {
     if (!class_exists('Timber')) {
         echo '<p>Please install and enable timber.</p>';
         return;
     }
     $context = \Timber::get_context();
     $context['settingsGroupName'] = self::SETTINGS_GROUP_NAME;
     $context['fieldNames'] = array('expiryDays' => self::OPTION_NAME_PASSWORD_EXPIRY_DAYS, 'disablePasswordResets' => self::OPTION_NAME_DISABLE_PASSWORD_RESETS);
     $context['currentValues'] = array('expiryDays' => get_option(self::OPTION_NAME_PASSWORD_EXPIRY_DAYS, 90), 'disablePasswordResets' => get_option(self::OPTION_NAME_DISABLE_PASSWORD_RESETS));
     \Timber::render($this->dic['securityPlugin']->getPath() . '/views/options-page.twig', $context);
 }
Exemplo n.º 17
0
 /** FUNCTION getContext
  * processes context from options
  **/
 public static function getContext()
 {
     if (self::$spark_options['context']) {
         $context = self::$spark_options['context'];
     } else {
         $context = Timber::get_context();
         $context['nav'] = new TimberMenu(self::$spark_options['nav']);
         $context['' . self::$class_id . '_right'] = Timber::compile(self::$spark_options['headerRight']);
         $context['logo'] = get_header_image();
     }
     return $context;
 }
 public function embed($slug)
 {
     $post = get_posts("name={$slug}&post_type=poll");
     if (!$post || count($post) == 0) {
         throw new \RuntimeException('Poll doesn\'t exist with this slug');
     }
     $context = \Timber::get_context();
     $context['poll'] = new \TimberPost($post[0]);
     $this->inline_css();
     $views = trailingslashit(Helper::get('views')['AgreablePollPlugin']);
     \Timber::render("{$views}/widgets/poll_plugin/template.twig", $context);
     $this->inline_js();
 }
Exemplo n.º 19
0
 function options_page()
 {
     if (!current_user_can('manage_options')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $ctx = \Timber::get_context();
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         $ctx['form'] = Option::get_instance()->get();
     } else {
         $ctx['form'] = $_POST;
         Option::get_instance()->update($_POST);
     }
     \Timber::render('Admin.html', $ctx);
 }
 function testMenuTwigWithClasses()
 {
     $this->setPermalinkStructure();
     $this->_createTestMenu();
     $this->go_to(home_url('/home'));
     $context = Timber::get_context();
     $context['menu'] = new TimberMenu();
     $str = Timber::compile('assets/menu-classes.twig', $context);
     $str = trim($str);
     $this->assertContains('current_page_item', $str);
     $this->assertContains('current-menu-item', $str);
     $this->assertContains('menu-item-object-page', $str);
     $this->assertNotContains('foobar', $str);
 }
Exemplo n.º 21
0
 function testMenuTwigWithClasses()
 {
     $struc = '/%postname%/';
     global $wp_rewrite;
     $wp_rewrite->set_permalink_structure($struc);
     $wp_rewrite->flush_rules();
     update_option('permalink_structure', $struc);
     $this->_createTestMenu();
     $this->go_to(home_url('/home'));
     $context = Timber::get_context();
     $context['menu'] = new TimberMenu();
     $str = Timber::compile('assets/menu-classes.twig', $context);
     $str = trim($str);
     $this->assertContains('current_page_item', $str);
     $this->assertContains('current-menu-item', $str);
     $this->assertContains('menu-item-object-page', $str);
     $this->assertNotContains('foobar', $str);
 }
Exemplo n.º 22
0
 /**
  * Returns the callback for the shortcode
  *
  * @throws \RuntimeException
  * @return mixed
  */
 public function getCallback()
 {
     if (!function_exists('get_field')) {
         return false;
     }
     if ($accordions = get_field(self::ACF_FIELD_NAME_ACCORDION)) {
         $markup = '<div class="accordion-block">';
         foreach ($accordions as $accordion) {
             $context = \Timber::get_context();
             $context["accordion"] = $accordion;
             $template = apply_filters('fpshortcode_timber_template', $this->dic['accordionPlugin']->getPath() . "/views/accordion.twig");
             $markup .= \Timber::compile($template, $context);
         }
         $markup .= '</div>';
         return $markup;
     }
     return false;
 }
Exemplo n.º 23
0
 public static function newsletter_create()
 {
     $post_id = $_POST['id'];
     if (!empty($post_id)) {
         $post = new TimberPost($post_id);
         $data = Timber::get_context();
         $data['post'] = $post;
         $html = Timber::compile('newsletter/newsletter.twig', $data);
         $args = array('type' => 'regular', 'recipients' => array('list_id' => get_field('mailchimp_list_id', 'option')), 'settings' => array('subject_line' => $post->post_title, 'from_name' => 'The Food Rush', 'reply_to' => '*****@*****.**', 'authenticate' => false, 'auto_footer' => false), 'tracking' => array('opens' => true, 'html_clicks' => true, 'text_clicks' => false));
         $campaign = self::$mailchimp->post('campaigns', $args);
         $campaign_id = $campaign['id'];
         $args = array('html' => $html);
         $campaign_content = self::$mailchimp->put('campaigns/' . $campaign_id . '/content', $args);
         if (!empty($campaign_content)) {
             echo "Successfully created new campaign!";
         } else {
             echo "Error creating new campaign.";
         }
         die;
     }
 }
Exemplo n.º 24
0
 /** FUNCTION getRoll 
  * returns string of HTML Slides
  **/
 public static function getRoll($temp = null, $args = null, $posts = null)
 {
     $context = Timber::get_context();
     if ($posts) {
         foreach ($posts as $post) {
             $post->post_excerpt = $post->post_excerpt ? $post->post_excerpt : wp_trim_words($post->post_content, 55);
             $post->post_thumbnail = get_the_post_thumbnail($post->ID, 'medium');
             $newPosts[] = $post;
         }
         $posts = $newPosts;
         $context['content'] = $posts;
     } else {
         if ($args) {
             $context['content'] = Timber::get_posts($args);
         } else {
             $context['content'] = new TimberPost();
         }
     }
     $template = $temp ? $temp : 'content';
     return self::getView($context, $template);
 }
Exemplo n.º 25
0
 public static function do_load_more_posts()
 {
     $args = $_GET['args'];
     $template = $_GET['template'];
     if (preg_match('/,/', $args['post_type'])) {
         $post_types = explode(',', $args['post_type']);
         $args['post_type'] = $post_types;
     }
     $data = Timber::get_context();
     $posts = Timber::get_posts($args);
     if (empty($posts)) {
         echo 0;
         die;
     }
     $i = 1;
     foreach ($posts as $post) {
         $data['post'] = $post;
         $data['loop']['index'] = $i;
         Timber::render('partials/' . $template . '.twig', $data);
         $i = $i + 1;
     }
     die;
 }
 public function render($venue = null)
 {
     $css_string = @file_get_contents(Helper::path('/resources/assets/styles.css'));
     $js_string = @file_get_contents(Helper::path('/resources/assets/app.js'));
     $webpack_port = null;
     $environment = getenv('WP_ENV');
     if ($environment === 'development') {
         try {
             $webpack_port = $this->get_webpack_port(Helper::path(''));
         } catch (\Exception $e) {
             // If exception the developer hasn't run webpack so may not be
             // 'developing' this particular plugin, force 'production'
             $environment = 'production';
         }
     }
     $views = trailingslashit(Helper::get('views')['template']);
     $context = \Timber::get_context();
     $context['body_class'] = $context['body_class'] . ' agreable-venues-plugin';
     $context['env'] = $environment;
     // $context['common_css_path'] = Helper::asset('styles.css');
     $context['js_string'] = $js_string;
     $context['css_string'] = $css_string;
     $context['css_path'] = '/resources/assets/styles.css';
     $context['js_path'] = '/resources/assets/app.js';
     $context['webpack_plugin_port'] = $webpack_port;
     $brand_str = strtolower(get_field('venues_brand', 'option'));
     $brands = !empty($brand_str) ? array_map('trim', explode(',', $brand_str)) : array();
     $context['initial_state'] = array('app' => array('site' => array('sitename' => get_bloginfo('name'), 'env' => $environment, 'terms' => get_field('venues_promo_terms', 'option')), 'firebase' => array('api_key' => get_field('venues_firebase_api_key', 'option'), 'auth_domain' => get_field('venues_firebase_auth_domain', 'option'), 'db_url' => get_field('venues_firebase_db_url', 'option'), 'storage_bucket' => get_field('venues_firebase_storage_bucket', 'option'), 'brands' => $brands), 'map' => array('mapboxToken' => get_field('venues_map_mapbox_token', 'option'), 'mapboxMapId' => get_field('venues_map_mapbox_mapid', 'option'), 'slug' => get_field('agreable_venues_plugin_map_slug', 'option'), 'tileUrl' => get_field('venues_map_tiles_url', 'option'), 'locationDetails' => get_field('map_initial_locations', 'option')), 'display_vouchers' => get_field('field_578dff0210320', 'option')));
     $context['calais_domain'] = 'https://calaisapi.com';
     if (isset($venue)) {
         // If on single venue page we set all meta data accordingly.
         $context['wp_title'] = htmlentities($venue->get('name'));
         $context['post'] = $this->get_post_meta_data($venue);
     }
     \Timber::render("{$views}template.twig", $context);
 }
Exemplo n.º 27
0
<?php

/*
* Third party plugins that hijack the theme will call wp_head() to get the header template.
* We use this to start our output buffer and render into the view/page-plugin.twig template in footer.php
*/
$GLOBALS['timberContext'] = Timber::get_context();
ob_start();
<?php

/**
 * The Template for displaying all single posts
 *
 * Methods for TimberHelper can be found in the /functions sub-directory
 *
 * @package  WordPress
 * @subpackage  Timber
 * @since    Timber 0.1
 */
$context = Timber::get_context();
$query = array('orderby' => 'meta_value_num', 'order' => 'asc', 'posts_per_page' => 12, 'post_type' => 'avaliacao', 'meta_query' => array(array('key' => 'ordem')));
$context['posts'] = Timber::get_posts($query);
$category_slug = get_query_var('category_name');
$obj_category = get_category_by_slug($category_slug);
$context['step_avaliacao'] = 'step_selected';
$context['show_step_2'] = true;
$context['nome_projeto'] = $obj_category->name;
$context['id_projeto'] = $obj_category->term_id;
$context['slug_projeto'] = $obj_category->slug;
$context['cor_projeto'] = get_tax_meta($obj_category->term_id, 'cda_color_field_id');
$context['username'] = get_query_var('username');
if (get_query_var('username')) {
    $current_user = get_user_by('login', get_query_var('username'));
    $context['profile'] = $current_user;
    $context['compartilhar_imagem'] = get_stylesheet_directory_uri() . '/assets/images/avaliacao_share_facebook_geral.jpg';
} else {
    global $current_user;
    get_currentuserinfo();
    $context['profile'] = $current_user;
Exemplo n.º 29
0
<?php

$data = Timber::get_context();
//$data['post'] = PostMaster::get_post_info(2611);
Timber::render('404.twig', $data);
Exemplo n.º 30
0
 /**
  * @see AbstractTheme::render()
  */
 public function render($file, array $context = [])
 {
     static $timberContext;
     if (!isset($timberContext)) {
         $timberContext = \Timber::get_context();
     }
     // Include Gantry specific things to the context.
     $context = array_replace($timberContext, $context);
     return $this->renderer()->render($file, $context);
 }