/** * Parse the indexable content for an entry * * @param int $entry * @param int $section */ public function indexEntry($entry, $section, $check_filters = TRUE) { self::assert(); if (is_object($entry)) { $entry = $entry->get('id'); } if (is_object($section)) { $section = $section->get('id'); } // get a list of sections that have indexing enabled $indexed_sections = self::getIndexes(); // go no further if this section isn't being indexed if (!isset($indexed_sections[$section])) { return; } // delete existing index for this entry self::deleteIndexByEntry($entry); // get the current section index config $section_index = $indexed_sections[$section]; // only pass entries through filters if we need to. If entry is being sent // from the Re-Index AJAX it has already gone through filtering, so no need here if ($check_filters === TRUE) { if (self::$_where == NULL || self::$_joins == NULL) { // modified from class.datasource.php // create filters and build SQL required for each if (is_array($section_index['filters']) && !empty($section_index['filters'])) { foreach ($section_index['filters'] as $field_id => $filter) { if (is_array($filter) && empty($filter) || trim($filter) == '') { continue; } if (!is_array($filter)) { $filter_type = DataSource::__determineFilterType($filter); $value = preg_split('/' . ($filter_type == DS_FILTER_AND ? '\\+' : ',') . '\\s*/', $filter, -1, PREG_SPLIT_NO_EMPTY); $value = array_map('trim', $value); } else { $value = $filter; } $field = self::$_entry_manager->fieldManager->fetch($field_id); $field->buildDSRetrivalSQL($value, $joins, $where, $filter_type == DS_FILTER_AND ? TRUE : FALSE); } } self::$_where = $where; self::$_joins = $joins; } // run entry though filters $entry_prefilter = self::$_entry_manager->fetch($entry, $section, 1, 0, self::$_where, self::$_joins, FALSE, FALSE); // if no entry found, it didn't pass the pre-filtering if (empty($entry_prefilter)) { return; } // if entry passes filtering, pass entry_id as a DS filter to the EntryXMLDataSource DS $entry = reset($entry_prefilter); $entry = $entry['id']; } if (!is_array($entry)) { $entry = array($entry); } // create a DS and filter on System ID of the current entry to build the entry's XML #$ds = new EntryXMLDataSource(Administration::instance(), NULL, FALSE); self::$_entry_xml_datasource->dsParamINCLUDEDELEMENTS = $indexed_sections[$section]['fields']; self::$_entry_xml_datasource->dsParamFILTERS['id'] = implode(',', $entry); self::$_entry_xml_datasource->dsSource = (string) $section; $param_pool = array(); $entry_xml = self::$_entry_xml_datasource->grab($param_pool); require_once TOOLKIT . '/class.xsltprocess.php'; $xml = simplexml_load_string($entry_xml->generate()); /* MULTILANGUAGE SUPPORT: */ require_once TOOLKIT . '/class.extensionmanager.php'; require_once TOOLKIT . '/class.fieldmanager.php'; $fieldManager = new FieldManager($this); $extensionManager = new ExtensionManager($this); $status = $extensionManager->fetchStatus('multilanguage'); $multilingualFields = array(); $languages = array(); if ($status == EXTENSION_ENABLED) { // Check if this section has multilingual fields: $results = Symphony::Database()->fetch('SELECT `element_name` FROM `tbl_fields` WHERE `parent_section` = ' . $section . ' AND `multilanguage` = 1;'); foreach ($results as $result) { $multilingualFields[] = $result['element_name']; } $languages = explode(',', file_get_contents(MANIFEST . '/multilanguage-languages')); } foreach ($xml->xpath("//entry") as $entry_xml) { // get text value of the entry (default behaviour) $proc = new XsltProcess(); $data = $proc->process($entry_xml->asXML(), file_get_contents(EXTENSIONS . '/search_index/lib/parse-entry.xsl')); $dataLanguages = array(); foreach ($languages as $language) { foreach ($entry_xml->children() as $child) { $name = $child->getName(); if (in_array($name, $multilingualFields)) { // Bingo! // Get the correct value for this item: $field_id = $fieldManager->fetchFieldIDFromElementName($name); $entry_id = $entry_xml->attributes()->id; $values = Symphony::Database()->fetch('SELECT * FROM `tbl_multilanguage_values` WHERE `id_entry` = ' . $entry_id . ' AND `id_field` = ' . $field_id . ' AND `language` = \'' . $language . '\';'); if (count($values) >= 1) { // Value found: foreach ($values as $value) { switch ($value['field_name']) { case 'value': $entry_xml->{$name} = $value['value']; break; } } } } } // Store it: $proc = new XsltProcess(); $dataLanguages[$language] = $proc->process($entry_xml->asXML(), file_get_contents(EXTENSIONS . '/search_index/lib/parse-entry.xsl')); } self::saveEntryIndex((int) $entry_xml->attributes()->id, $section, $data, $dataLanguages); /* END MULTILANGUAGE SUPPORT */ } }
/** * Parse the indexable content for an entry * * @param int $entry * @param int $section */ public function indexEntry($entry, $section, $check_filters = TRUE) { self::assert(); if (is_object($entry)) { $entry = $entry->get('id'); } if (is_object($section)) { $section = $section->get('id'); } // get a list of sections that have indexing enabled $indexed_sections = self::getIndexes(); // go no further if this section isn't being indexed if (!isset($indexed_sections[$section])) { return; } // get the current section index config $section_index = $indexed_sections[$section]; // only pass entries through filters if we need to. If entry is being sent // from the Re-Index AJAX it has already gone through filtering, so no need here if ($check_filters === TRUE) { if (self::$_where == NULL || self::$_joins == NULL) { // modified from the core's class.datasource.php // create filters and build SQL required for each if (is_array($section_index['filters']) && !empty($section_index['filters'])) { foreach ($section_index['filters'] as $field_id => $filter) { if (is_array($filter) && empty($filter) || trim($filter) == '') { continue; } if (!is_array($filter)) { $filter_type = DataSource::__determineFilterType($filter); $value = preg_split('/' . ($filter_type == DS_FILTER_AND ? '\\+' : '(?<!\\\\),') . '\\s*/', $filter, -1, PREG_SPLIT_NO_EMPTY); $value = array_map('trim', $value); $value = array_map(array('Datasource', 'removeEscapedCommas'), $value); } else { $value = $filter; } if (!isset($fieldPool[$field_id]) || !is_object($fieldPool[$field_id])) { $fieldPool[$field_id] =& FieldManager::fetch($field_id); } if ($field_id != 'id' && !$fieldPool[$field_id] instanceof Field) { throw new Exception(__('Error creating field object with id %1$d, for filtering in data source "%2$s". Check this field exists.', array($field_id, $this->dsParamROOTELEMENT))); } if ($field_id == 'id') { $where = " AND `e`.id IN ('" . @implode("', '", $value) . "') "; } else { if (!$fieldPool[$field_id]->buildDSRetrievalSQL($value, $joins, $where, $filter_type == DS_FILTER_AND ? true : false)) { $this->_force_empty_result = true; return; } if (!$group) { $group = $fieldPool[$field_id]->requiresSQLGrouping(); } } } } self::$_where = $where; self::$_joins = $joins; } // run entry though filters $entry_prefilter = EntryManager::fetch($entry, $section, 1, 0, self::$_where, self::$_joins, FALSE, FALSE); // if no entry found, it didn't pass the pre-filtering if (empty($entry_prefilter)) { return; } // if entry passes filtering, pass entry_id as a DS filter to the EntryXMLDataSource DS $entry = reset($entry_prefilter); $entry = $entry['id']; } if (!is_array($entry)) { $entry = array($entry); } // create a DS and filter on System ID of the current entry to build the entry's XML self::$_entry_xml_datasource->dsParamINCLUDEDELEMENTS = $indexed_sections[$section]['fields']; self::$_entry_xml_datasource->dsParamFILTERS['id'] = implode(',', $entry); self::$_entry_xml_datasource->dsSource = (string) $section; $param_pool = array(); $entry_xml = self::$_entry_xml_datasource->grab($param_pool); require_once TOOLKIT . '/class.xsltprocess.php'; $xml = simplexml_load_string($entry_xml->generate()); foreach ($xml->xpath("//entry") as $entry_xml) { $entry_id = (int) $entry_xml->attributes()->id; // delete existing index for this entry self::deleteIndexByEntry($entry_id); // get text value of the entry $proc = new XsltProcess(); $data = $proc->process($entry_xml->asXML(), file_get_contents(EXTENSIONS . '/search_index/lib/parse-entry.xsl')); $data = trim($data); self::saveEntryIndex($entry_id, $section, $data); } }