/** * 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 (array_key_exists('name', $this->_defaults) && $this->_defaults['name'] == 'index') { // Store this to article directly in case name field is not editable in schema $this->_article->name = 'index'; } 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')) { midcom_helper_misc::include_snippet_php($this->_config->get('callback_snippet')); } $callback = $this->_config->get('callback_function'); $callback($this->_article, $this->_content_topic); } return $this->_article; }
/** * Loads the file/snippet necessary for a given plugin, according to its configuration. * * @param string $namespace The plugin namespace to use. * @param string $plugin The plugin to load from the namespace. */ public function _load_plugin_class($namespace, $plugin) { $plugin_config = self::$_plugin_namespace_config[$namespace][$plugin]; // Sanity check, we return directly if the configured class name is already // available (dynamic_load could trigger this). if (class_exists($plugin_config['class'])) { return; } $i = strpos($plugin_config['src'], ':'); if ($i == false) { $method = 'snippet'; $src = $plugin_config['src']; } else { $method = substr($plugin_config['src'], 0, $i); $src = substr($plugin_config['src'], $i + 1); } switch ($method) { case 'file': require_once MIDCOM_ROOT . $src; break; case 'component': midcom::get('componentloader')->load($src); break; case 'snippet': midcom_helper_misc::include_snippet_php($src); break; default: throw new midcom_error("The plugin loader method {$method} is unknown, cannot continue."); } if (!class_exists($plugin_config['class'])) { throw new midcom_error("Failed to load the plugin {$namespace}/{$plugin}, implementation class not available."); } }
/** * Creates an instance of the renderer set in the system configuration. * * This is called during the initialize code and will make the renderer * available immediately after startup. */ function _create_default_renderer() { $default = $this->_config->get('default_renderer'); if ($default == 'none') { $this->renderer = 'none'; return; } $src = $this->_config->get('default_renderer_src'); if ($src) { // Ensure that the snippet is only loaded once. if (!class_exists($default)) { midcom_helper_misc::include_snippet_php($src); if (!class_exists($default)) { throw new midcom_error("The renderer class set in the DM2 configuration does not exist."); } } $this->renderer = new $default($this->namespace); } else { $this->create_renderer($default); } }