Пример #1
0
 /**
  * Display the page template
  *
  * @see Pods_Templates::template
  *
  * @param string $template The template name
  * @param string $code Custom template code to use instead
  * @param bool $deprecated Whether to use deprecated functionality based on old function usage
  *
  * @return mixed Template output
  *
  * @since 2.0
  * @link http://pods.io/docs/template/
  */
 public function template($template_name, $code = null, $deprecated = false)
 {
     $out = null;
     $obj =& $this;
     if (!empty($code)) {
         $code = str_replace('$this->', '$obj->', $code);
         // backwards compatibility
         $code = apply_filters('pods_templates_pre_template', $code, $template_name, $this);
         $code = apply_filters("pods_templates_pre_template_{$template_name}", $code, $template_name, $this);
         ob_start();
         if (!empty($code)) {
             // Only detail templates need $this->id
             if (empty($this->id)) {
                 while ($this->fetch()) {
                     echo $this->do_magic_tags($code);
                 }
             } else {
                 echo $this->do_magic_tags($code);
             }
         }
         $out = ob_get_clean();
         $out = apply_filters('pods_templates_post_template', $out, $code, $template_name, $this);
         $out = apply_filters("pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this);
     } elseif (class_exists('Pods_Templates')) {
         $out = Pods_Templates::template($template_name, $code, $this, $deprecated);
     } elseif ($template_name == trim(preg_replace('/[^a-zA-Z0-9_\\-\\/]/', '', $template_name), ' /-')) {
         ob_start();
         $default_templates = array('pods/' . $template_name, 'pods-' . $template_name, $template_name);
         $default_templates = apply_filters('pods_template_default_templates', $default_templates);
         // Only detail templates need $this->id
         if (empty($this->id)) {
             while ($this->fetch()) {
                 pods_template_part($default_templates, compact(array_keys(get_defined_vars())));
             }
         } else {
             pods_template_part($default_templates, compact(array_keys(get_defined_vars())));
         }
         $out = ob_get_clean();
         $out = apply_filters('pods_templates_post_template', $out, $code, $template_name, $this);
         $out = apply_filters("pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this);
     }
     return $out;
 }
Пример #2
0
 /**
  * Display the page template
  *
  * @param string $template The template name
  * @param string $code Custom template code to use instead
  * @param object $obj The Pods object
  * @param bool $deprecated Whether to use deprecated functionality based on old function usage
  *
  * @return mixed|string|void
  * @since 2.0
  */
 public static function template($template, $code = null, $obj = null, $deprecated = false)
 {
     if (!empty($obj)) {
         self::$obj =& $obj;
     } else {
         $obj =& self::$obj;
     }
     self::$deprecated = $deprecated;
     if (empty($obj) || !is_object($obj)) {
         return '';
     }
     if (empty($code) && !empty($template)) {
         $template = $obj->api->load_template(array('name' => $template));
         if (!empty($template)) {
             if (!empty($template['code'])) {
                 $code = $template['code'];
             }
             $permission = pods_permission($template['options']);
             $permission = (bool) apply_filters('pods_templates_permission', $permission, $code, $template, $obj);
             if (!$permission) {
                 return apply_filters('pods_templates_permission_denied', __('You do not have access to view this content.', 'pods'), $code, $template, $obj);
             }
         }
     }
     $code = apply_filters('pods_templates_pre_template', $code, $template, $obj);
     $code = apply_filters('pods_templates_pre_template_' . $template['slug'], $code, $template, $obj);
     ob_start();
     if (!empty($code)) {
         // Only detail templates need $this->id
         if (empty($obj->id)) {
             while ($obj->fetch()) {
                 echo self::do_template($code, $obj);
             }
         } else {
             echo self::do_template($code, $obj);
         }
     }
     $out = ob_get_clean();
     $out = apply_filters('pods_templates_post_template', $out, $code, $template, $obj);
     $out = apply_filters('pods_templates_post_template_' . $template['slug'], $out, $code, $template, $obj);
     return $out;
 }
Пример #3
0
 /**
  * Display the page template
  *
  * @param string $template_name The template name
  * @param string $code Custom template code to use instead
  * @param object $obj The Pods object
  * @param bool $deprecated Whether to use deprecated functionality based on old function usage
  *
  * @return mixed|string|void
  * @since 2.0
  */
 public static function template($template_name, $code = null, $obj = null, $deprecated = false)
 {
     if (!empty($obj)) {
         self::$obj =& $obj;
     } else {
         $obj =& self::$obj;
     }
     self::$deprecated = $deprecated;
     if (empty($obj) || !is_object($obj)) {
         return '';
     }
     $template = array('id' => 0, 'slug' => $template_name, 'code' => $code, 'options' => array());
     if (empty($code) && !empty($template_name)) {
         $template_obj = $obj->api->load_template(array('name' => $template_name));
         if (!empty($template_obj)) {
             $template = $template_obj;
             if (!empty($template['code'])) {
                 $code = $template['code'];
             }
             $permission = pods_permission($template['options']);
             $permission = (bool) apply_filters('pods_templates_permission', $permission, $code, $template, $obj);
             if (!$permission) {
                 return apply_filters('pods_templates_permission_denied', __('You do not have access to view this content.', 'pods'), $code, $template, $obj);
             }
         }
     }
     $code = apply_filters('pods_templates_pre_template', $code, $template, $obj);
     $code = apply_filters('pods_templates_pre_template_' . $template['slug'], $code, $template, $obj);
     ob_start();
     if (!empty($code)) {
         // Only detail templates need $this->id
         if (empty($obj->id)) {
             while ($obj->fetch()) {
                 echo self::do_template($code, $obj);
             }
         } else {
             echo self::do_template($code, $obj);
         }
     } elseif ($template_name == trim(preg_replace('/[^a-zA-Z0-9_\\-\\/]/', '', $template_name), ' /-')) {
         $default_templates = array('pods/' . $template_name, 'pods-' . $template_name, $template_name);
         $default_templates = apply_filters('pods_template_default_templates', $default_templates);
         if (empty($obj->id)) {
             while ($obj->fetch()) {
                 pods_template_part($default_templates, compact(array_keys(get_defined_vars())));
             }
         } else {
             pods_template_part($default_templates, compact(array_keys(get_defined_vars())));
         }
     }
     $out = ob_get_clean();
     $out = apply_filters('pods_templates_post_template', $out, $code, $template, $obj);
     $out = apply_filters('pods_templates_post_template_' . $template['slug'], $out, $code, $template, $obj);
     return $out;
 }
Пример #4
0
 /**
  * Display the page template
  *
  * @see Pods_Templates::template
  *
  * @param string $template The template name
  * @param string $code Custom template code to use instead
  * @param bool $deprecated Whether to use deprecated functionality based on old function usage
  *
  * @return mixed Template output
  *
  * @since 2.0
  * @link http://pods.io/docs/template/
  */
 public function template($template, $code = null, $deprecated = false)
 {
     if (!empty($code)) {
         $code = apply_filters('pods_templates_pre_template', $code, $template, $this);
         $code = apply_filters("pods_templates_pre_template_{$template}", $code, $template, $this);
         ob_start();
         if (!empty($code)) {
             // Only detail templates need $this->id
             if (empty($this->id)) {
                 while ($this->fetch()) {
                     echo $this->do_magic_tags($code);
                 }
             } else {
                 echo $this->do_magic_tags($code);
             }
         }
         $out = ob_get_clean();
         $out = apply_filters('pods_templates_post_template', $out, $code, $template, $this);
         $out = apply_filters("pods_templates_post_template_{$template}", $out, $code, $template, $this);
         return $out;
     } elseif (class_exists('Pods_Templates')) {
         return Pods_Templates::template($template, $code, $this, $deprecated);
     }
 }