Пример #1
0
 /**
  * Execute the search for the given SearchCommand
  *
  * @param  SearchCommand $search
  * @return SearchResult
  */
 public function fire(SearchCommand $search)
 {
     $search_result = new SearchResult();
     $fields = array('name', 'content');
     $sql_query = ' SELECT      id,
                                 name
                     FROM        ' . Watson::getTable('template') . '
                     WHERE       ' . $search->getSqlWhere($fields) . '
                     ORDER BY    name
                     LIMIT       20';
     $results = $this->getDatabaseResults($sql_query);
     if (count($results)) {
         foreach ($results as $result) {
             $url = Watson::getUrl(array('page' => 'template', 'template_id' => $result['id'], 'function' => 'edit'));
             $entry = new SearchResultEntry();
             $entry->setValue($result['name']);
             $entry->setDescription(Watson::translate('watson_open_template'));
             $entry->setIcon('icon_template.png');
             $entry->setUrl($url);
             $entry->setQuickLookUrl($url);
             $search_result->addEntry($entry);
         }
     }
     return $search_result;
 }
Пример #2
0
 /**
  * render all result entries
  */
 public function render($displayKey)
 {
     $entries = $this->entries;
     $returns = array();
     if (count($entries) > 0) {
         foreach ($entries as $entry) {
             $return = array();
             $classes = array();
             $styles = array();
             $value = $entry->getValue();
             $return['value_name'] = $entry->getValue();
             $return['description'] = '';
             if ($entry->hasValueSuffix()) {
                 // Suffix anhängen, da sonst nur ein Ergebnis erscheint
                 // Bspl. gleicher Artikelname in 2 Sprachen
                 $value .= ' ' . $entry->getValueSuffix();
                 $classes[] = 'watson-has-value-suffix';
                 $return['value_suffix'] = $entry->getValueSuffix();
             }
             if ($entry->hasIcon()) {
                 $classes[] = 'watson-has-icon';
                 $styles[] = 'background-image: url(' . Watson::getMediaDir() . $entry->getIcon() . ');';
             }
             if ($entry->hasDescription()) {
                 $classes[] = 'watson-has-description';
                 $return['description'] = $entry->getDescription();
             }
             if ($entry->hasUrl()) {
                 $return['url'] = $entry->getUrl();
                 $return['url_open_window'] = $entry->getUrlOpenWindow();
             }
             if ($entry->hasQuickLookUrl()) {
                 $classes[] = 'watson-has-quick-look';
                 $return['quick_look_url'] = $entry->getQuickLookUrl();
             }
             if ($entry->hasHtmlFields()) {
                 $classes[] = 'watson-has-quick-look';
                 $return['html_fields'] = $entry->getHtmlFields();
             }
             $return['value'] = $value;
             $return['tokens'] = array($value);
             $return['displayKey'] = $displayKey;
             $class = count($classes) > 0 ? ' ' . implode(' ', $classes) : '';
             $style = count($styles) > 0 ? implode(' ', $styles) : '';
             $return['class'] = $class;
             $return['style'] = $style;
             $returns[] = $return;
         }
     }
     return $returns;
 }
Пример #3
0
 protected function getDatabaseResults($query)
 {
     $query = str_replace(array("\r\n", "\r", "\n"), '', $query);
     $limit = strpos(strtoupper($query), ' LIMIT ');
     if ($limit !== false) {
         $query = substr($query, 0, $limit);
     }
     $query .= ' LIMIT ' . Watson::getSearchResultLimit();
     $sql = \rex_sql::factory();
     //        $sql->debugsql = true;
     $sql->setQuery($query);
     //exit();
     return $sql->getArray();
 }
Пример #4
0
 /**
  * Execute the search for the given SearchCommand
  *
  * @param  SearchCommand $search
  * @return SearchResult
  */
 public function fire(SearchCommand $search)
 {
     $search_result = new SearchResult();
     $fields = array('filename', 'title');
     $s = \rex_sql::factory();
     $s->setQuery('SELECT * FROM ' . Watson::getTable('file') . ' LIMIT 0');
     $fieldnames = $s->getFieldnames();
     foreach ($fieldnames as $fieldname) {
         if (substr($fieldname, 0, 4) == 'med_') {
             $fields[] = $fieldname;
         }
     }
     $sql_query = ' SELECT      filename,
                                 title
                     FROM        ' . Watson::getTable('file') . '
                     WHERE       ' . $search->getSqlWhere($fields) . '
                     ORDER BY    filename';
     $results = $this->getDatabaseResults($sql_query);
     if (count($results)) {
         foreach ($results as $result) {
             $title = $result['title'] != '' ? ' (' . Watson::translate('watson_media_title') . ': ' . $result['title'] . ')' : '';
             $entry = new SearchResultEntry();
             $entry->setValue($result['filename']);
             $entry->setDescription(Watson::translate('watson_open_media') . $title);
             $entry->setIcon('icon_media.png');
             $entry->setUrl('javascript:newPoolWindow(\'' . Watson::getUrl(array('page' => 'mediapool', 'subpage' => 'detail', 'file_name' => $result['filename'])) . '\')');
             $m = \OOMedia::getMediaByFileName($result['filename']);
             if ($m instanceof \OOMedia) {
                 if ($m->isImage()) {
                     $entry->setQuickLookUrl(Watson::getUrl(array('rex_img_type' => 'rex_mediapool_maximized', 'rex_img_file' => $result['filename'])));
                 }
             }
             $search_result->addEntry($entry);
         }
     }
     return $search_result;
 }
Пример #5
0
 /**
  * Returns whether a icon is set
  *
  * @return bool
  */
 public function hasIcon()
 {
     return !empty($this->icon) && file_exists(Watson::getMediaDir() . $this->icon);
 }
Пример #6
0
 /**
  * Execute the search for the given SearchCommand
  *
  * @param  SearchCommand $search
  * @return SearchResult
  */
 public function fire(SearchCommand $search)
 {
     global $REX;
     $search_result = new SearchResult();
     $searchResults = array();
     $command_parts = $search->getCommandParts();
     // Artikelnamen in der Struktur durchsuchen
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     $fields = array('a.name');
     $where = $search->getSqlWhere($fields);
     if (count($command_parts) == 1 && (int) $command_parts[0] >= 1) {
         $where = 'a.id = "' . (int) $command_parts[0] . '"';
     }
     $sql_query = ' SELECT      a.id,
                                 a.clang,
                                 CONCAT(a.id, "|", a.clang) as bulldog
                     FROM        ' . Watson::getTable('article') . ' AS a
                     WHERE       ' . $where . '
                     GROUP BY    bulldog
                     ';
     $results = $this->getDatabaseResults($sql_query);
     if (count($results)) {
         foreach ($results as $result) {
             $searchResults[$result['bulldog']] = $result;
         }
     }
     // Slices der Artikel durchsuchen
     // Werden Slices gefunden, dann die Strukturartikel überschreiben
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     $fields = array('s.value' => range('1', '20'), 's.file' => range('1', '10'), 's.filelist' => range('1', '10'));
     $searchFields = array();
     foreach ($fields as $field => $numbers) {
         foreach ($numbers as $number) {
             $searchFields[] = $field . $number;
         }
     }
     $fields = $searchFields;
     $sql_query = ' SELECT      s.article_id AS id,
                                 s.clang,
                                 s.ctype,
                                 CONCAT(s.article_id, "|", s.clang) as bulldog
                     FROM        ' . Watson::getTable('article_slice') . ' AS s
                         LEFT JOIN
                                 ' . Watson::getTable('article') . ' AS a
                             ON  (s.article_id = a.id AND s.clang = a.clang)
                     WHERE       ' . $search->getSqlWhere($fields) . '
                     GROUP BY    bulldog';
     $results = $this->getDatabaseResults($sql_query);
     if (count($results)) {
         foreach ($results as $result) {
             $searchResults[$result['bulldog']] = $result;
         }
     }
     // Ergebnisse auf Rechte prüfen und bereitstellen
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     if (count($searchResults)) {
         foreach ($searchResults as $result) {
             $clang = $result['clang'];
             $article = \OOArticle::getArticleById($result['id'], $clang);
             $category_id = $article->getCategoryId();
             // Rechte prüfen
             if (in_array($clang, $REX['USER']->getClangPerm()) && $REX['USER']->hasCategoryPerm($category_id)) {
                 $path = array();
                 $tree = $article->getParentTree();
                 foreach ($tree as $o) {
                     $path[] = $o->getName();
                 }
                 if (!$article->isStartArticle()) {
                     $path[] = $article->getName();
                 }
                 $path = '/' . implode('/', $path);
                 $url = Watson::getUrl(array('page' => 'structure', 'category_id' => $article->getCategoryId(), 'clang' => $clang));
                 if (isset($result['ctype'])) {
                     $url = Watson::getUrl(array('page' => 'content', 'article_id' => $article->getId(), 'mode' => 'edit', 'clang' => $clang, 'ctype' => $result['ctype']));
                 }
                 $suffix = array();
                 if ($REX['USER']->hasPerm('advancedMode[]')) {
                     $suffix[] = $article->getId();
                 }
                 if (count($REX['CLANG']) > 1) {
                     $suffix[] = $REX['CLANG'][$clang];
                 }
                 $suffix = implode(', ', $suffix);
                 $suffix = $suffix != '' ? '(' . $suffix . ')' : '';
                 $entry = new SearchResultEntry();
                 $entry->setValue($article->getName(), $suffix);
                 $entry->setDescription($path);
                 $entry->setIcon('icon_article.png');
                 $entry->setUrl($url);
                 $entry->setQuickLookUrl('../index.php?article_id=' . $article->getId() . '&clang=' . $clang);
                 $search_result->addEntry($entry);
             }
         }
     }
     return $search_result;
 }
Пример #7
0
 public static function searchRun($params)
 {
     global $REX, $I18N;
     $searchers = $params['searchers'];
     // registrierte Page Params speichern
     //watson::saveRegisteredPageParams($searchers);
     //watson::setPageRequest();
     // Phase 2
     // User Eingabe parsen in $input
     $userInput = rex_request('watson_search', 'string');
     //\Package\Package::console($userInput);
     if ($userInput != '') {
         $searchCommand = new SearchCommand($userInput);
         // Eingabe auf Keywords überprüfen
         $saveSearchers = array();
         foreach ($searchers as $searcher) {
             if (in_array($searchCommand->getCommand(), $searcher->commands())) {
                 $saveSearchers[] = $searcher;
             }
         }
         // registriertes Command gefunden
         if (count($saveSearchers) > 0) {
             $searchers = $saveSearchers;
             $searchCommand->deleteCommandFromCommandParts();
         }
         // Eingabe an vorher registrierte Search übergeben und Ergebnisse einsammeln
         /** @var $searchResults SearchResult */
         $searchResults = array();
         foreach ($searchers as $searcher) {
             $searchResults[] = $searcher->fire($searchCommand);
         }
         // Ergebnis rendern
         $renderedResults = array();
         foreach ($searchResults as $searchResult) {
             $renderedResults[] = $searchResult->render($userInput);
         }
         $json = array();
         foreach ($renderedResults as $values) {
             foreach ($values as $value) {
                 $json[] = $value;
             }
         }
         if (count($json) == 0) {
             $json[] = array('value_name' => $I18N->msg('b_no_results'), 'value' => Watson::translate('b_no_results'), 'tokens' => array(Watson::translate('b_no_results')));
         }
         ob_clean();
         header('Content-type: application/json');
         echo json_encode($json);
         exit;
     }
 }
Пример #8
0
 protected function createTemplate($params)
 {
     global $REX, $I18N;
     $function = 'add';
     $active = Watson::arrayCastVar($params, 'active', 'int', 0);
     $templatename = Watson::arrayCastVar($params, 'templatename', 'string', '');
     $content = Watson::arrayCastVar($params, 'content', 'string', '');
     $ctypes = Watson::arrayCastVar($params, 'ctype', 'array', array());
     $categories = Watson::arrayCastVar($params, 'categories', 'array', array());
     $modules = Watson::arrayCastVar($params, 'modules', 'array', array());
     /*
      * following Code is from REDAXO
      * include/pages/template.inc.php
      * 
      * change rex_sql > \rex_sql
      */
     $num_ctypes = count($ctypes);
     if ($ctypes[$num_ctypes] == "") {
         unset($ctypes[$num_ctypes]);
         if (isset($ctypes[$num_ctypes - 1]) && $ctypes[$num_ctypes - 1] == '') {
             unset($ctypes[$num_ctypes - 1]);
         }
     }
     // Daten wieder in den Rohzustand versetzen, da für serialize()/unserialize()
     // keine Zeichen escaped werden dürfen
     for ($i = 1; $i < count($ctypes) + 1; $i++) {
         $ctypes[$i] = stripslashes($ctypes[$i]);
     }
     // leerer eintrag = 0
     if (count($categories) == 0 || !isset($categories["all"]) || $categories["all"] != 1) {
         $categories["all"] = 0;
     }
     // leerer eintrag = 0
     if (count($modules) == 0) {
         $modules[1]["all"] = 0;
     }
     foreach ($modules as $k => $module) {
         if (!isset($module["all"]) || $module["all"] != 1) {
             $modules[$k]["all"] = 0;
         }
     }
     $TPL = \rex_sql::factory();
     $TPL->setTable($REX['TABLE_PREFIX'] . "template");
     $TPL->setValue("name", $templatename);
     $TPL->setValue("active", $active);
     $TPL->setValue("content", $content);
     $attributes = rex_setAttributes("ctype", $ctypes, "");
     $attributes = rex_setAttributes("modules", $modules, "");
     $attributes = rex_setAttributes("categories", $categories, "");
     $TPL->setValue("attributes", addslashes($attributes));
     $TPL->addGlobalCreateFields();
     if ($function == "add") {
         $attributes = rex_setAttributes("ctype", $ctypes, "");
         $attributes = rex_setAttributes("modules", $modules, $attributes);
         $attributes = rex_setAttributes("categories", $categories, $attributes);
         $TPL->setValue("attributes", addslashes($attributes));
         $TPL->addGlobalCreateFields();
         if ($TPL->insert()) {
             $template_id = $TPL->getLastId();
             $info = $I18N->msg("template_added");
         } else {
             $warning = $TPL->getError();
         }
     } else {
         $attributes = rex_setAttributes("ctype", $ctypes, $attributes);
         $attributes = rex_setAttributes("modules", $modules, $attributes);
         $attributes = rex_setAttributes("categories", $categories, $attributes);
         $TPL->setWhere("id='{$template_id}'");
         $TPL->setValue("attributes", addslashes($attributes));
         $TPL->addGlobalUpdateFields();
         if ($TPL->update()) {
             $info = $I18N->msg("template_updated");
         } else {
             $warning = $TPL->getError();
         }
     }
     // werte werden direkt wieder ausgegeben
     $templatename = stripslashes($templatename);
     $content = stripslashes($content);
     rex_deleteDir($REX['GENERATED_PATH'] . "/templates", 0);
     if ($goon != "") {
         $function = "edit";
         $save = "nein";
     } else {
         $function = "";
     }
     return array('success' => $info, 'error' => $warning);
 }