/** * 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; }
private function get_snippet($object_path) { try { $snippet = new midgard_snippet(); $snippet->get_by_path(str_replace('.php', '', $object_path)); } catch (midgard_error_exception $e) { return false; } $this->snippet = $snippet; return true; }
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(); } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }