コード例 #1
0
ファイル: Templates.php プロジェクト: erkmen/wpstartersetup
 /**
  * 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;
 }
コード例 #2
0
ファイル: Templates.php プロジェクト: centaurustech/chipin
 /**
  * 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;
 }