コード例 #1
0
ファイル: misc.php プロジェクト: nemein/openpsa
 /**
  * This helper function searches for a snippet either in the Filesystem
  * or in the database and returns its content or code-field, respectively.
  *
  * Prefix the snippet Path with 'file:' for retrieval of a file relative to
  * MIDCOM_ROOT; omit it to get the code field of a Snippet.
  *
  * Any error (files not found) will return null. If you want to trigger an error,
  * look for midcom_helper_misc::get_snippet_content.
  *
  * @param string $path  The URL to the snippet.
  * @return string       The content of the snippet/file.
  */
 public static function get_snippet_content_graceful($path)
 {
     static $cached_snippets = array();
     if (array_key_exists($path, $cached_snippets)) {
         return $cached_snippets[$path];
     }
     if (substr($path, 0, 5) == 'file:') {
         $filename = MIDCOM_ROOT . substr($path, 5);
         if (!file_exists($filename)) {
             $cached_snippets[$path] = null;
             return null;
         }
         $data = file_get_contents($filename);
     } else {
         $snippet = new midgard_snippet();
         try {
             $snippet->get_by_path($path);
         } catch (Exception $e) {
             $cached_snippets[$path] = null;
             return null;
         }
         midcom::get('cache')->content->register($snippet->guid);
         $data = $snippet->code;
     }
     $cached_snippets[$path] = $data;
     return $data;
 }
コード例 #2
0
ファイル: yaml.php プロジェクト: abbra/midcom
 private function load_locals()
 {
     $snippetname = "/local-configuration/{$this->component}/configuration";
     try {
         $snippet = new midgard_snippet();
         $snippet->get_by_path($snippetname);
     } catch (Exception $e) {
         return;
     }
     $this->locals = $this->unserialize($snippet->code);
     if (!is_array($this->locals)) {
         // Safety
         $this->locals = array();
     }
 }
コード例 #3
0
ファイル: snippet.php プロジェクト: abbra/midcom
 /**
  * This helper function searches for a snippet either in the Filesystem
  * or in the database and returns its content or code-field, respectively.
  *
  * Prefix the snippet Path with 'file:' for retrieval of a file relative to
  * MIDCOM_ROOT; omit it to get the code field of a Snippet.
  *
  * @param string $path    The URL to the snippet.
  * @return string        The content of the snippet/file.
  */
 static function get_contents_graceful($path)
 {
     if (substr($path, 0, 5) == 'file:') {
         $filename = MIDCOM_ROOT . substr($path, 5);
         if (!file_exists($filename)) {
             return '';
         }
         $data = file_get_contents($filename);
     } else {
         try {
             $snippet = new midgard_snippet();
             $snippet->get_by_path($path);
         } catch (Exception $e) {
             return '';
         }
         $data = $snippet->code;
     }
     return $data;
 }
コード例 #4
0
ファイル: yaml.php プロジェクト: piotras/midgardmvc_core
 /**
  * Internal helper of loading configuration array from a snippet
  *
  * @param string $snippet_path
  * @return array
  */
 private function load_snippet($snippet_path)
 {
     if (is_null($this->midgardmvc)) {
         $this->midgardmvc = midgardmvc_core::get_instance();
     }
     if (!$this->midgardmvc->dispatcher->get_midgard_connection()) {
         return array();
     }
     try {
         $snippet = new midgard_snippet();
         $snippet->get_by_path($snippet_path);
     } catch (Exception $e) {
         return array();
     }
     $configuration = $this->unserialize($snippet->code);
     if (!is_array($configuration)) {
         return array();
     }
     return $configuration;
 }
コード例 #5
0
ファイル: snippets.php プロジェクト: piotras/midgardmvc_core
 private function handle_copy($route_id, &$data)
 {
     $destination = $this->check_destination($data['dest']);
     if (!$this->get_snippetdir($this->object_path)) {
         // Possibly copying snippets instead
         if (!$this->get_snippet($this->object_path)) {
             throw new midgardmvc_exception_notfound("Snippetdir {$this->object_path} not found");
         }
         $new_snippet = new midgard_snippet();
         $new_snippet->up = $destination['snippetdir']->id;
         $new_snippet->name = str_replace('.php', '', $destination['name']);
         $new_snippet->code = $this->snippet->code;
         $new_snippet->create();
         return;
     }
     $new_snippetdir = new midgard_snippetdir();
     $new_snippetdir->up = $destination['snippetdir']->id;
     $new_snippetdir->name = $destination['name'];
     $new_snippetdir->create();
 }
コード例 #6
0
ファイル: main.php プロジェクト: nemein/openpsa
 /**
  * Loads the language database.
  */
 private function _load_language_db()
 {
     $path = $GLOBALS['midcom_config']['i18n_language_db_path'];
     if (substr($path, 0, 5) == 'file:') {
         $filename = MIDCOM_ROOT . substr($path, 5);
         if (!file_exists($filename)) {
             $cached_snippets[$path] = null;
             return null;
         }
         $data = file_get_contents($filename);
     } else {
         $snippet = new midgard_snippet();
         try {
             $snippet->get_by_path($path);
         } catch (Exception $e) {
             $cached_snippets[$path] = null;
             return null;
         }
         if (isset(midcom::get('cache')->content)) {
             midcom::get('cache')->content->register($snippet->guid);
         }
         $data = $snippet->code;
     }
     eval("\$layout = Array(\n{$data}\n);");
     $this->_language_db = $layout;
     return true;
 }
コード例 #7
0
ファイル: schema.php プロジェクト: nemein/openpsa
 /**
  * Get snippet link. A small helper for generating link for the requested schemadb
  *
  * @param String $schemadb
  * @return String Link tag to the loaded object
  */
 private function _get_snippet_link($path)
 {
     if (!is_string($path)) {
         return false;
     }
     $snippet = new midgard_snippet();
     try {
         $snippet->get_by_path($path);
         if ($snippet->guid) {
             return "<a href=\"" . midcom_connection::get_url('self') . "__mfa/asgard/object/edit/{$snippet->guid}/\">{$path}</a>";
         }
     } catch (Exception $e) {
     }
     return $path;
 }