Ejemplo n.º 1
0
 public function addPluginExternally($pluginName, $fileName, $pluginPath, $pluginConfig)
 {
     // for use of array based config
     //         if($pluginConfig instanceof Zend_Config){
     //             $pluginConfig = $pluginConfig->toArray();
     //         }
     //         $pluginConfig['pluginPath'] = $pluginPath;
     //         if(!isset($pluginConfig['enabled'])){
     //             $pluginConfig['enabled'] = false;
     //         }
     //         $enabled = $pluginConfig['enabled'];
     //
     //        // keep track of loaded plug-ins
     //        if (!array_key_exists($pluginName, $this->_plugins)) {
     //            $this->_plugins[$pluginName] = $pluginConfig;
     //        }
     //
     //        if ($enabled && isset($pluginConfig['events']) && is_array($pluginConfig['events'])) {
     //            foreach ($pluginConfig['events'] as $event) {
     //                if (is_array($event)) {
     //                    // TODO: allow trigger method that differs from event name
     //                } else if (is_string($event)) {
     //                    $pluginSpec = array(
     //                        'class_name'   => ucfirst($pluginName) . self::PLUGIN_CLASS_POSTFIX,
     //                        'file_name'    => $fileName,
     //                        'include_path' => $pluginPath,
     //                        'config'       => isset($pluginPrivateConfig) ? $pluginPrivateConfig : null
     //                    );
     //
     //                    $priority = isset($event['priority']) ? (int) $event['priority'] : 10;
     //
     //                    // register plugin events with event dispatcher
     //                    $this->_eventDispatcher->register($event, $pluginSpec, $priority);
     //                }
     //            }
     //        }
     $pluginConfig->pluginPath = $pluginPath;
     if (!isset($pluginConfig->enabled)) {
         $pluginConfig->enabled = false;
     }
     $enabled = $pluginConfig->enabled;
     // keep track of loaded plug-ins
     if (!array_key_exists($pluginName, $this->_plugins)) {
         $this->_plugins[$pluginName] = $pluginConfig;
     }
     if ($enabled && isset($pluginConfig->events) && $pluginConfig->events instanceof Zend_Config) {
         foreach ($pluginConfig->events->toArray() as $event) {
             if (is_array($event)) {
                 // TODO: allow trigger method that differs from event name
             } else {
                 if (is_string($event)) {
                     $pluginSpec = array('class_name' => ucfirst($pluginName) . self::PLUGIN_CLASS_POSTFIX, 'file_name' => $fileName, 'include_path' => $pluginPath, 'config' => $pluginConfig->private);
                     $priority = isset($event->priority) ? (int) $event->priority : 10;
                     // register plugin events with event dispatcher
                     $this->_eventDispatcher->register($event, $pluginSpec, $priority);
                 }
             }
         }
     }
 }
 public function setUpExtensionIntegrationTest()
 {
     $this->setUpIntegrationTest();
     if (null !== $this->_extensionName) {
         $extensionManager = OntoWiki::getInstance()->extensionManager;
         if (!$extensionManager->isExtensionActive($this->_extensionName)) {
             Erfurt_Event_Dispatcher::reset();
             $this->markTestSkipped('extension is not active');
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Enables or disables versioning.
  *
  * When first called registers with Erfurt_Event_Dispatcher
  * and adds triggers for operations on statements (add/del)
  *
  * @param bool $versioningEnabled True, if versioning is enabled, false otherwise
  */
 public function enableVersioning($versioningEnabled = true)
 {
     $this->_versioningEnabled = (bool) $versioningEnabled;
     if (!$this->_eventsRegistered) {
         $eventDispatcher = Erfurt_Event_Dispatcher::getInstance();
         $eventDispatcher->register('onAddStatement', $this);
         $eventDispatcher->register('onAddMultipleStatements', $this);
         $eventDispatcher->register('onDeleteMatchingStatements', $this);
         $eventDispatcher->register('onDeleteMultipleStatements', $this);
         $this->_eventsRegistered = true;
     }
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  */
 public function __construct(Erfurt_Store $store, Erfurt_Rdf_Model $graph)
 {
     // system variables
     $this->_store = $store;
     $this->_config = OntoWiki::getInstance()->config;
     $this->_logger = OntoWiki::getInstance()->logger;
     $this->_eventDispatcher = Erfurt_Event_Dispatcher::getInstance();
     if (isset($this->_config->system->inference) && !(bool) $this->_config->system->inference) {
         $this->_inference = false;
     }
     // data variables
     $this->_graph = $graph->getModelIri();
     $this->_model = $graph;
     $this->_titleHelper = new OntoWiki_Model_TitleHelper($this->_model, $store);
     // $this->_titleProperties = array_flip($this->_config->properties->title->toArray());
     $this->_titleProperties = array_flip($graph->getTitleProperties());
 }
Ejemplo n.º 5
0
 /**
  * Returns the event dispatcher instance.
  *
  * @return Erfurt_Event_Dispatcher
  */
 public function getEventDispatcher()
 {
     require_once 'Erfurt/Event/Dispatcher.php';
     $ed = Erfurt_Event_Dispatcher::getInstance();
     return $ed;
 }
Ejemplo n.º 6
0
    /**
     * Deletes all statements that match the triple pattern specified.
     *
     * @param string $graphUri  URI of the model
     * @param mixed  $subject   mixed triple pattern (string or null)
     * @param mixed  $predicate mixed triple pattern (string or null)
     * @param mixed  $object    mixed triple pattern (string or null)
     * @param array  $options   An array containing two keys
     *     'subject_type' and 'object_type'. The value of each is one of the
     *     defined constants of Erfurt_Store: TYPE_IRI, TYPE_BLANKNODE and
     *     TYPE_LITERAL. In addtion to this two keys the options array can contain
     *     two keys 'literal_language' and 'literal_datatype'.
     *
     * @throws Erfurt_Exception
     *
     * @return number of affected statements
     */
    public function deleteMatchingStatements($graphUri, $subject, $predicate, $object, $options = array())
    {
        if (!isset($options['use_ac'])) {
            $options['use_ac'] = true;
        }
        if ($this->_checkAc($graphUri, 'edit', $options['use_ac'])) {
            try {
                $filter = '';
                if (null !== $subject) {
                    $filter .= "FILTER (?s = <{$subject}>) .\n";
                }
                if (null !== $predicate) {
                    $filter .= "FILTER (?p = <{$predicate}>) .\n";
                }
                if (null !== $object) {
                    if ($object['type'] == 'uri') {
                        $o = $object['value'];
                        $filter .= "FILTER (?o = <{$o}>) .\n";
                    } else {
                        $o = $object['value'];
                        if (isset($object['datatype'])) {
                            $dt = $object['datatype'];
                            $filter .= "FILTER ((?o = \"{$o}\") && (datatype(?o) = <{$dt}>) .\n";
                        } else {
                            if (isset($object['lang'])) {
                                $lang = $object['lang'];
                                $filter .= "FILTER ((?o = \"{$o}\") && (lang(?o) = \"{$lang}\") .\n";
                            } else {
                                $filter .= "FILTER (?o = \"{$o}\") .\n";
                            }
                        }
                    }
                }
                $sparql = <<<EOF
SELECT ?s ?p ?o
FROM <{$graphUri}>
WHERE {
    ?s ?p ?o .
    {$filter}
}
EOF;
                $result = $this->sparqlQuery($sparql, array(Erfurt_Store::RESULTFORMAT => Erfurt_Store::RESULTFORMAT_EXTENDED, Erfurt_Store::USE_AC => $options['use_ac']));
                $ret = count($result['results']['bindings']);
                $stmts = array();
                foreach ($result['results']['bindings'] as $row) {
                    $s = $row['s']['value'];
                    $p = $row['p']['value'];
                    $o = $row['o']['value'];
                    if (!isset($stmts[$s])) {
                        $stmts[$s] = array();
                    }
                    if (!isset($stmts[$s][$p])) {
                        $stmts[$s][$p] = array();
                    }
                    $oSpec = array('type' => $row['o']['type'], 'value' => $o);
                    if (isset($row['o']['xml:lang'])) {
                        $oSpec['lang'] = $row['o']['xml:lang'];
                    }
                    if (isset($row['o']['datatype'])) {
                        $oSpec['datatype'] = $row['o']['datatype'];
                    }
                    $stmts[$s][$p][] = $oSpec;
                }
                $this->_backendAdapter->deleteMatchingStatements($graphUri, $subject, $predicate, $object, $options);
                $queryCache = Erfurt_App::getInstance()->getQueryCache();
                $queryCache->invalidate($graphUri, $subject, $predicate, $object);
                $event = new Erfurt_Event('onDeleteMatchingStatements');
                $event->graphUri = $graphUri;
                $event->resource = $subject;
                $event->statements = $stmts;
                $event->affectedStatements = $ret;
                // just trigger if really data operations were performed
                if ((int) $ret > 0) {
                    $event->trigger();
                }
                return $ret;
            } catch (Erfurt_Store_Adapter_Exception $e) {
                // TODO: Create a exception for too many matching values
                // In this case we log without storing the payload.
                // No rollback supported for such actions.
                $event = new Erfurt_Event('onDeleteMatchingStatements');
                $event->graphUri = $graphUri;
                $event->resource = $subject;
                Erfurt_Event_Dispatcher::getInstance()->trigger($event);
            }
        }
    }
Ejemplo n.º 7
0
 /**
  * load helpers for a component
  *
  * @param $componentName
  * @param $config
  *
  * @return mixed
  * @throws OntoWiki_Component_Exception
  */
 protected function _loadHelper($componentName, $config)
 {
     if (!isset($this->_helpers[$componentName])) {
         throw new OntoWiki_Component_Exception("No helper defined for component '{$componentName}'.");
     }
     $helperSpec = $this->_helpers[$componentName];
     // load helper class
     require_once $helperSpec['path'];
     if (class_exists($helperSpec['class'])) {
         // instantiate helper object
         $helperInstance = new $helperSpec['class']($config);
     } else {
         throw new OntoWiki_Component_Exception("required helper class '" . $helperSpec['class'] . "' could not be found for component '{$componentName}'.");
     }
     // register helper events
     if (isset($helperSpec['events'])) {
         $dispatcher = Erfurt_Event_Dispatcher::getInstance();
         foreach ($helperSpec['events'] as $currentEvent) {
             if (substr($currentEvent, 0, strlen(self::EVENT_NS)) == self::EVENT_NS) {
                 //currently we only accept events from the ontowiki event namespace
                 $currentEvent = substr($currentEvent, strlen(self::EVENT_NS));
             }
             $dispatcher->register($currentEvent, $helperInstance);
         }
     }
     $this->_helpers[$componentName]['instance'] = $helperInstance;
     return $helperInstance;
 }
Ejemplo n.º 8
0
 /**
  * Initializes the event dispatcher
  *
  * @since 0.9.5
  */
 public function _initEventDispatcher()
 {
     // load event dispatcher for Erfurt and OntoWiki events
     $eventDispatcher = Erfurt_Event_Dispatcher::getInstance();
     return $eventDispatcher;
 }
Ejemplo n.º 9
0
 /**
  * Triggers this event.
  *
  * @return mixed Event handler return value
  */
 public function trigger()
 {
     return $this->_eventDispatcher->trigger($this);
 }
Ejemplo n.º 10
0
 public static function reset()
 {
     self::$_instance = null;
 }
Ejemplo n.º 11
0
 /**
  * Constructor
  */
 public function init()
 {
     /**
      * @trigger onBeforeInitController
      * Triggered before a controller of class OntoWiki_Controller_Base (or derived)
      * is initialized.
      */
     $event = new Erfurt_Event('onBeforeInitController');
     $eventResult = $event->trigger();
     // init controller variables
     $this->_owApp = OntoWiki::getInstance();
     $this->_config = $this->_owApp->config;
     $this->_session = $this->_owApp->session;
     $this->_erfurt = $this->_owApp->erfurt;
     $this->_eventDispatcher = Erfurt_Event_Dispatcher::getInstance();
     // set important script variables
     $this->view->themeUrlBase = $this->_config->themeUrlBase;
     $this->view->urlBase = $this->_config->urlBase;
     $this->view->staticUrlBase = $this->_config->staticUrlBase;
     $this->view->libraryUrlBase = $this->_config->staticUrlBase . 'libraries/';
     $graph = $this->_owApp->selectedModel;
     if ($graph instanceof Erfurt_Rdf_Model) {
         if ($graph->isEditable()) {
             $this->view->placeholder('update')->set(array('defaultGraph' => $graph->getModelIri(), 'queryEndpoint' => $this->_config->urlBase . 'sparql/', 'updateEndpoint' => $this->_config->urlBase . 'update/'));
         }
     }
     // check config for additional styles
     if ($stylesExtra = $this->_config->themes->styles) {
         $this->view->themeExtraStyles = $stylesExtra->toArray();
     } else {
         $this->view->themeExtraStyles = array();
     }
     // disable layout for Ajax requests
     if ($this->_request->isXmlHttpRequest()) {
         $this->_helper->layout()->disableLayout();
     }
     // initialize view helpers
     $this->view->headTitle($this->_config->title->prefix, 'SET');
     $this->view->headTitle()->setSeparator($this->_config->title->separator);
     $this->view->headMeta()->setHttpEquiv('Content-Type', 'text/html; charset=' . $this->_config->encoding);
     $this->view->headMeta()->setName('generator', 'OntoWiki — Collaborative Knowledge Engineering');
     // RDFauthor view configuration
     $viewMode = isset($this->_config->rdfauthor->viewmode) ? $this->_config->rdfauthor->viewmode : 'inline';
     // inject JSON variables into view
     $this->view->jsonVars = '
         var urlBase = "' . $this->_config->urlBase . '";
         var themeUrlBase = "' . $this->_config->themeUrlBase . '";
         var _OWSESSION = "' . _OWSESSION . '";
         var RDFAUTHOR_BASE = "' . $this->_config->staticUrlBase . 'libraries/RDFauthor/";
         var RDFAUTHOR_VIEW_MODE = "' . $viewMode . '";' . PHP_EOL;
     if (defined('_OWDEBUG')) {
         $this->view->jsonVars .= '            var RDFAUTHOR_DEBUG = 1;';
     }
     if ($this->_owApp->selectedModel) {
         $this->view->jsonVars .= '
         var selectedGraph = {
             URI: "' . (string) $this->_owApp->selectedModel . '",
             title: ' . json_encode((string) $this->_owApp->selectedModel->getTitle()) . ',
             editable: ' . ($this->_owApp->selectedModel->isEditable() ? 'true' : 'false') . '
         };
         var RDFAUTHOR_DEFAULT_GRAPH = "' . (string) $this->_owApp->selectedModel . '";' . PHP_EOL;
     }
     if ($this->_owApp->selectedResource) {
         $this->view->jsonVars .= '
         var selectedResource = {
             URI: "' . (string) $this->_owApp->selectedResource . '",
             title: ' . json_encode((string) $this->_owApp->selectedResource->getTitle()) . ',
             graphURI: "' . (string) $this->_owApp->selectedModel . '"
         };
         var RDFAUTHOR_DEFAULT_SUBJECT = "' . (string) $this->_owApp->selectedResource . '";' . PHP_EOL;
     }
     // set ratio between left bar and main window
     if (isset($this->_session->sectionRation)) {
         $this->view->headScript()->appendScript('var sectionRatio = ' . $this->_session->sectionRation . ';');
     }
     if (isset($this->_config->meta)) {
         if (isset($this->_config->meta->Keywords)) {
             $this->view->metaKeywords = $this->_config->meta->Keywords;
         }
         if (isset($this->_config->meta->Description)) {
             $this->view->metaDescription = $this->_config->meta->Description;
         }
     }
     /**
      * @trigger onAfterInitController
      * Triggered after a controller from class OntoWiki_Controller_Base (or derived)
      * has been initialized.
      */
     $event = new Erfurt_Event('onAfterInitController');
     $event->response = $this->_response;
     $eventResult = $event->trigger();
 }