Пример #1
0
 /**
  * Build HTML component.
  *
  * @param array $post Contains all data such as Wordpress asks
  * @param array $args Contains all data such as Wordpress asks
  *
  * @return int|null
  *
  * @since 3.0.0
  */
 public function hookFieldBuild($post, $args)
 {
     //If autosave...
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return isset($post->ID) ? $post->ID : null;
     }
     //Get contents
     $content = isset($args['args']['contents']) ? $args['args']['contents'] : array();
     $field = isset($args['args']['field']) ? $args['args']['field'] : '';
     //Check if a type is defined
     if (empty($content) || empty($field) || !isset($args['args']['type'])) {
         TeaThemeOptions::notify('error', TeaThemeOptions::__('A field is missing because no type is defined.'));
         return null;
     }
     //Get values
     //$type = $args['args']['type'];
     //$id = isset($content['id']) ? $content['id'] : '';
     //Display field content
     $tpl = $field->prepareField($content, array('post' => $post));
     TeaThemeOptions::getRender($tpl['template'], $tpl['vars']);
     //Return post if it is asked
     return isset($post->ID) ? $post->ID : null;
 }
Пример #2
0
 /**
  * Hook building custom fields.
  *
  * @param string|object $term Contain term used by function
  * @uses add_meta_box()
  *
  * @since 3.3.0
  */
 public function hookFieldsDisplay($term)
 {
     //Get all authorized fields
     $unauthorized = Field::getUnauthorizedFields();
     $contents = array();
     $ids = array();
     //Get current
     $isobject = is_object($term);
     $slug = $isobject ? $term->taxonomy : $term;
     $termid = $isobject ? $term->term_id : 0;
     /**
      * Build term contents.
      *
      * @var string $slug
      * @param array $contents
      * @return array $contents
      *
      * @since 3.3.0
      */
     $contents = apply_filters('tto_term_' . $slug . '_contents', $contents);
     //Check contents
     if (empty($contents)) {
         return;
     }
     //Get contents
     foreach ($contents as $ctn) {
         //Check fields
         if (empty($ctn)) {
             continue;
         }
         //Get type and id
         $type = isset($ctn['type']) ? $ctn['type'] : '';
         $id = isset($ctn['id']) ? $ctn['id'] : '';
         //Check if we are authorized to use this field in CPTs
         if (empty($type) || in_array($type, $unauthorized)) {
             continue;
         }
         //Get field instance
         $field = Field::getField($type, $id, array(), $ids);
         //Get template
         $tpl = $field->prepareField($ctn, array('prefix' => $slug, 'term_id' => $termid, 'structure' => Engine::getPrefix()));
         //Display it
         TeaThemeOptions::getRender($tpl['template'], $tpl['vars']);
     }
 }
Пример #3
0
 /**
  * Hook on search.
  *
  * @since 3.0.0
  */
 public function hookSearchTemplate()
 {
     //Check page
     if (TTO_IS_ADMIN || !is_search() || !$this->template) {
         return;
     }
     //Display template
     TeaThemeOptions::getRender('fields/search_results.html.twig', array('results' => $this->getEngine()->searchContents(), 't_see_all' => TeaThemeOptions::__('See all'), 't_read_more' => TeaThemeOptions::__('Read more'), 't_date' => TeaThemeOptions::__('By <a href="%s" itemprop="author">%s</a> on 
             <time datetime="%s" itemprop="datePublished">%s</time>'), 't_apologies' => TeaThemeOptions::__('Apologies, but no results were found for the requested archive. 
             Perhaps searching will help find a related post.')));
     exit;
 }
Пример #4
0
 /**
  * Build header layout.
  *
  * @since 3.3.0
  */
 protected function initialize()
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //Get current infos
     $currentpage = empty($this->currentPage) ? $this->identifier : $this->currentPage;
     $currentsection = empty($this->currentSection) ? '' : $this->currentSection;
     $slug = $this->pages[$currentpage]['id'];
     $contents = array();
     //Check sections
     if (!empty($this->pages[$currentpage]['sections'])) {
         $stns = array();
         //Get all datas
         foreach ($this->pages[$currentpage]['sections'] as $k => $section) {
             $stns[$k] = array();
             //Update section
             if (empty($this->currentSection)) {
                 $this->currentSection = $k;
                 $this->breadcrumb['currentSection'] = $section['title'];
             } else {
                 if ($this->currentSection === $k) {
                     $this->breadcrumb['currentSection'] = $section['title'];
                 }
             }
             /**
              * Build section page contents.
              *
              * @var string $slug
              * @var string $section
              * @param array $stns[$section]
              * @return array $stns[$section]
              *
              * @since 3.3.0
              */
             $stns[$k] = apply_filters('tto_menu_' . $slug . '-' . $k . '_contents', $stns[$k]);
         }
         //Update sections' contents
         $contents['sections'] = $stns;
     } else {
         if ($currentpage == $this->identifier) {
             //Main page special case
             $contents = $this->pages[$currentpage]['contents'];
         } else {
             $contents = array();
             /**
              * Build page contents.
              *
              * @var string $slug
              * @param array $contents
              * @return array $contents
              *
              * @since 3.3.0
              */
             $contents = apply_filters('tto_menu_' . $slug . '_contents', $contents);
         }
     }
     //Check if contents are not empty
     if (empty($contents)) {
         TeaThemeOptions::notify('error', TeaThemeOptions::__('Something went wrong in your parameters
             definition: your contents are empty. See README.md for
             more explanations.'));
     }
     //Get all template variables to inject in Twig template
     $tplvars = $this->tplVars();
     //Build contents relatively to the type
     $fields = $this->tplFields($contents);
     //Merge all
     $vars = array_merge($tplvars, array('fields' => $fields));
     //Display template
     TeaThemeOptions::getRender('layouts/base.html.twig', $vars);
 }
Пример #5
0
 /**
  * Hook to display input value on Permalink settings page.
  *
  * @param array $vars Contains all usefull data
  *
  * @since 3.0.0
  */
 public function hookPermalinkSet($vars)
 {
     if (empty($vars)) {
         return;
     }
     $vars['t_description'] = TeaThemeOptions::__('The following structure uses the same rules 
         than post\'s permalink structure that you can built with <code>%year%</code>, <code>%monthnum%</code>, 
         <code>%day%</code>, <code>%hour%</code>, <code>%minute%</code>, <code>%second%</code>, 
         <code>%post_id%</code>, <code>%category%</code>, <code>%author%</code> and <code>%pagename%</code>. 
         If you need to display the <code>%postname%</code>, simply use the custom post type\'s slug instead.');
     $vars['t_home'] = TTO_HOME;
     //Render template
     TeaThemeOptions::getRender('layouts/permalinks.html.twig', $vars);
 }