コード例 #1
0
ファイル: template.php プロジェクト: ekandreas/papi
/**
 * Load a template array file and merge values with it.
 *
 * @param  string $file
 * @param  array $values
 * @param  bool $convert_to_object
 *
 * @return array
 */
function papi_template($file, $values = [], $convert_to_object = false)
{
    if (!is_string($file) || empty($file)) {
        return [];
    }
    $filepath = papi_get_file_path($file);
    if (empty($filepath) && is_file($file)) {
        $filepath = $file;
    }
    if (empty($filepath) || !file_exists($filepath) || is_dir($filepath)) {
        return [];
    }
    $template = (require $filepath);
    if (papi_is_property($template)) {
        foreach ($values as $key => $value) {
            $template->set_option($key, $value);
        }
        $result = $template;
    } else {
        $result = array_merge((array) $template, $values);
    }
    if ($convert_to_object) {
        return (object) $result;
    }
    return $result;
}
コード例 #2
0
 /**
  * The constructor.
  *
  * Load a entry type by the file.
  *
  * @param string $file_path
  */
 public function __construct($file_path = '')
 {
     // Try to load the file if the file path is empty.
     if (empty($file_path)) {
         $page_type = papi_get_entry_type_id();
         $file_path = papi_get_file_path($page_type);
     }
     parent::__construct($file_path);
 }
コード例 #3
0
 /**
  * The constructor.
  *
  * Load a page type by the file.
  *
  * @param string $file_path
  */
 public function __construct($file_path)
 {
     // Try to load the file if the file path is empty.
     if (empty($file_path)) {
         $page_type = papi_get_page_type_id();
         $file_path = papi_get_file_path($page_type);
     }
     if (is_file($file_path)) {
         $this->setup_file($file_path);
         $this->setup_meta_data();
     }
 }
コード例 #4
0
ファイル: page.php プロジェクト: KristoferN/papi
/**
 * Get page type by identifier.
 *
 * @param  string $id
 *
 * @return Papi_Page_Type
 */
function papi_get_page_type_by_id($id)
{
    if (!is_string($id) || empty($id)) {
        return;
    }
    $result = null;
    $page_types = papi_get_all_page_types(true);
    foreach ($page_types as $page_type) {
        if ($page_type->match_id($id)) {
            $result = $page_type;
            break;
        }
    }
    if (is_null($result)) {
        $path = papi_get_file_path($id);
        $result = papi_get_page_type($path);
    }
    return $result;
}
コード例 #5
0
ファイル: entry.php プロジェクト: nlemoine/papi
/**
 * Get entry type by identifier.
 *
 * @param  string $id
 *
 * @return Papi_Entry_Type
 */
function papi_get_entry_type_by_id($id)
{
    if (!is_string($id) || empty($id)) {
        return;
    }
    if (papi()->exists($id)) {
        return papi()->make($id);
    }
    $result = null;
    $entry_types = papi_get_all_entry_types();
    foreach ($entry_types as $entry_type) {
        if ($entry_type->match_id($id)) {
            $result = $entry_type;
            break;
        }
    }
    if (is_null($result)) {
        $path = papi_get_file_path($id);
        $result = papi_get_entry_type($path);
    }
    return $result;
}