/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_article = new midcom_db_article(); $this->_article->topic = $this->_content_topic->id; if (!$this->_article->create()) { debug_print_r('We operated on this object:', $this->_article); throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string()); } // Callback possibility if ($this->_config->get('callback_function')) { if ($this->_config->get('callback_snippet')) { // mgd_include_snippet($this->_config->get('callback_snippet')); $eval = midcom_helper_misc::get_snippet_content($this->_config->get('callback_snippet')); if ($eval) { eval($eval); } } $callback = $this->_config->get('callback_function'); $callback($this->_article, $this->_content_topic); } return $this->_article; }
/** * Helper function which transforms a raw schema database (either already parsed or * based on a URL to a schemadb) into a list of schema class instances. * * @param mixed $raw_db Either an already created raw schema array, or a midcom_helper_misc::get_snippet_content * compatible URL to a snippet / file from which the db should be loaded or schemadb contents as a string. * @return Array An array of midcom_helper_datamanager2_schema class instances. * @see midcom_helper_misc::get_snippet_content() */ public static function load_database($raw_db) { static $loaded_dbs = array(); $path = null; if (is_string($raw_db)) { // Determine if the given string is a path - assume that a path // doesn't have line breaks if (preg_match('/\\n/', $raw_db)) { $raw_db = midcom_helper_misc::parse_config($raw_db); } else { $path = $raw_db; if (!array_key_exists($path, $loaded_dbs)) { $data = midcom_helper_misc::get_snippet_content($raw_db); $loaded_dbs[$path] = midcom_helper_misc::parse_config($data); } $raw_db = $loaded_dbs[$path]; } } if (!is_array($raw_db)) { throw new midcom_error("Provided DM2 schema is not in Array format."); } $schemadb = array(); foreach ($raw_db as $name => $raw_schema) { $schemadb[$name] = new midcom_helper_datamanager2_schema($raw_db, $name, $path); } return $schemadb; }