static function findNode($parentNode, $id, $asObject = false, $remoteID = false)
 {
     if (!isset($parentNode) || $parentNode == NULL) {
         $parentNode = 2;
     }
     $propertiesOverride = array("parent_node_id" => $parentNode = (int) $parentNode);
     $db = eZDB::instance();
     if ($asObject) {
         if ($remoteID) {
             $objectIDFilter = "ezcontentobject.remote_id = '" . $db->escapeString($id) . "'";
             $propertiesOverride["object_remote_id"] = $id;
         } else {
             $objectIDFilter = 'contentobject_id = ' . (int) $id;
             $propertiesOverride["id"] = $id;
         }
         $retNodeArray = eZContentObjectTreeNode::makeObjectsArray($db->arrayQuery("SELECT " . "ezcontentobject.contentclass_id, ezcontentobject.current_version, " . (!isset($propertiesOverride["id"]) ? "ezcontentobject.id, " : "") . "ezcontentobject.initial_language_id, ezcontentobject.language_mask, ezcontentobject.modified, " . "ezcontentobject.name, ezcontentobject.owner_id, ezcontentobject.published, " . (!isset($propertiesOverride["object_remote_id"]) ? "ezcontentobject.remote_id AS object_remote_id, " : "") . "ezcontentobject.section_id, ezcontentobject.status, " . "ezcontentobject_tree.contentobject_is_published, ezcontentobject_tree.contentobject_version, ezcontentobject_tree.depth, ezcontentobject_tree.is_hidden, " . "ezcontentobject_tree.is_invisible, ezcontentobject_tree.main_node_id, ezcontentobject_tree.modified_subnode, ezcontentobject_tree.node_id, " . "ezcontentobject_tree.path_identification_string, ezcontentobject_tree.path_string, ezcontentobject_tree.priority, ezcontentobject_tree.remote_id, ezcontentobject_tree.sort_field, " . "ezcontentobject_tree.sort_order, ezcontentclass.serialized_name_list as class_serialized_name_list, ezcontentclass.identifier as class_identifier, ezcontentclass.is_container " . "FROM ezcontentobject_tree " . "INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id) " . "INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id AND ezcontentclass.version = 0) " . "WHERE parent_node_id = {$parentNode} AND " . $objectIDFilter), true, $propertiesOverride);
         if (!empty($retNodeArray)) {
             return $retNodeArray[0];
         } else {
             return null;
         }
     } else {
         $id = (int) $id;
         $getNodeQuery = "SELECT node_id\n                           FROM ezcontentobject_tree\n                           WHERE\n                                parent_node_id={$parentNode} AND\n                                contentobject_id = {$id} ";
         $nodeArr = $db->arrayQuery($getNodeQuery);
         if (isset($nodeArr[0])) {
             return $nodeArr[0]['node_id'];
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 2
0
 public function search($searchText, $params = array(), $searchTypes = array())
 {
     if (count($searchTypes) == 0) {
         $searchTypes['general'] = array();
         $searchTypes['subtype'] = array();
         $searchTypes['and'] = array();
     } else {
         if (!isset($searchTypes['general'])) {
             $searchTypes['general'] = array();
         }
     }
     $allowSearch = true;
     if (trim($searchText) == '') {
         $ini = eZINI::instance();
         if ($ini->variable('SearchSettings', 'AllowEmptySearch') != 'enabled') {
             $allowSearch = false;
         }
         if (isset($params['AllowEmptySearch'])) {
             $allowSearch = $params['AllowEmptySearch'];
         }
     }
     if ($allowSearch) {
         $searchText = $this->normalizeText($searchText, false);
         $db = eZDB::instance();
         $nonExistingWordArray = array();
         $searchTypeMap = array('class' => 'SearchContentClassID', 'publishdate' => 'SearchDate', 'subtree' => 'SearchSubTreeArray');
         foreach ($searchTypes['general'] as $searchType) {
             $params[$searchTypeMap[$searchType['subtype']]] = $searchType['value'];
         }
         if (isset($params['SearchOffset'])) {
             $searchOffset = $params['SearchOffset'];
         } else {
             $searchOffset = 0;
         }
         if (isset($params['SearchLimit'])) {
             $searchLimit = $params['SearchLimit'];
         } else {
             $searchLimit = 10;
         }
         if (isset($params['SearchContentClassID'])) {
             $searchContentClassID = $params['SearchContentClassID'];
         } else {
             $searchContentClassID = -1;
         }
         if (isset($params['SearchSectionID'])) {
             $searchSectionID = $params['SearchSectionID'];
         } else {
             $searchSectionID = -1;
         }
         if (isset($params['SearchDate'])) {
             $searchDate = $params['SearchDate'];
         } else {
             $searchDate = -1;
         }
         if (isset($params['SearchTimestamp'])) {
             $searchTimestamp = $params['SearchTimestamp'];
         } else {
             $searchTimestamp = false;
         }
         if (isset($params['SearchContentClassAttributeID'])) {
             $searchContentClassAttributeID = $params['SearchContentClassAttributeID'];
         } else {
             $searchContentClassAttributeID = -1;
         }
         if (isset($params['SearchSubTreeArray'])) {
             $subTreeArray = $params['SearchSubTreeArray'];
         } else {
             $subTreeArray = array();
         }
         if (isset($params['SortArray'])) {
             $sortArray = $params['SortArray'];
         } else {
             $sortArray = array();
         }
         $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false;
         // strip multiple spaces
         $searchText = preg_replace("(\\s+)", " ", $searchText);
         // find the phrases
         /*            $numQuotes = substr_count( $searchText, "\"" );
         
                     $phraseTextArray = array();
                     $fullText = $searchText;
                     $nonPhraseText ='';
         //            $fullText = '';
                     $postPhraseText = $fullText;
                     $pos = 0;
                     if ( ( $numQuotes > 0 ) and ( ( $numQuotes % 2 ) == 0 ) )
                     {
                         for ( $i = 0; $i < ( $numQuotes / 2 ); $i ++ )
                         {
                             $quotePosStart = strpos( $searchText, '"',  $pos );
                             $quotePosEnd = strpos( $searchText, '"',  $quotePosStart + 1 );
         
                             $prePhraseText = substr( $searchText, $pos, $quotePosStart - $pos );
                             $postPhraseText = substr( $searchText, $quotePosEnd +1 );
                             $phraseText = substr( $searchText, $quotePosStart + 1, $quotePosEnd - $quotePosStart - 1 );
         
                             $phraseTextArray[] = $phraseText;
         //                    $fullText .= $prePhraseText;
                             $nonPhraseText .= $prePhraseText;
                             $pos = $quotePosEnd + 1;
                         }
                     }
                     $nonPhraseText .= $postPhraseText;
         */
         $phrasesResult = $this->getPhrases($searchText);
         $phraseTextArray = $phrasesResult['phrases'];
         $nonPhraseText = $phrasesResult['nonPhraseText'];
         $fullText = $phrasesResult['fullText'];
         $sectionQuery = '';
         if (is_numeric($searchSectionID) and $searchSectionID > 0) {
             $sectionQuery = "ezsearch_object_word_link.section_id = '{$searchSectionID}' AND ";
         } else {
             if (is_array($searchSectionID)) {
                 // Build query for searching in an array of sections
                 $sectionQuery = $db->generateSQLINStatement($searchSectionID, 'ezsearch_object_word_link.section_id', false, false, 'int') . " AND ";
             }
         }
         $searchDateQuery = '';
         if (is_numeric($searchDate) and $searchDate > 0 or $searchTimestamp) {
             $date = new eZDateTime();
             $timestamp = $date->timeStamp();
             $day = $date->attribute('day');
             $month = $date->attribute('month');
             $year = $date->attribute('year');
             $publishedDateStop = false;
             if ($searchTimestamp) {
                 if (is_array($searchTimestamp)) {
                     $publishedDate = (int) $searchTimestamp[0];
                     $publishedDateStop = (int) $searchTimestamp[1];
                 } else {
                     $publishedDate = (int) $searchTimestamp;
                 }
             } else {
                 switch ($searchDate) {
                     case 1:
                         $adjustment = 24 * 60 * 60;
                         //seconds for one day
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 2:
                         $adjustment = 7 * 24 * 60 * 60;
                         //seconds for one week
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 3:
                         $adjustment = 31 * 24 * 60 * 60;
                         //seconds for one month
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 4:
                         $adjustment = 3 * 31 * 24 * 60 * 60;
                         //seconds for three months
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 5:
                         $adjustment = 365 * 24 * 60 * 60;
                         //seconds for one year
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     default:
                         $publishedDate = $date->timeStamp();
                 }
             }
             $searchDateQuery = "ezsearch_object_word_link.published >= '{$publishedDate}' AND ";
             if ($publishedDateStop) {
                 $searchDateQuery .= "ezsearch_object_word_link.published <= '{$publishedDateStop}' AND ";
             }
             $this->GeneralFilter['searchDateQuery'] = $searchDateQuery;
         }
         $classQuery = "";
         if (is_numeric($searchContentClassID) and $searchContentClassID > 0) {
             // Build query for searching in one class
             $classQuery = "ezsearch_object_word_link.contentclass_id = '{$searchContentClassID}' AND ";
             $this->GeneralFilter['classAttributeQuery'] = $classQuery;
         } else {
             if (is_array($searchContentClassID)) {
                 // Build query for searching in a number of classes
                 $classString = $db->generateSQLINStatement($searchContentClassID, 'ezsearch_object_word_link.contentclass_id', false, false, 'int');
                 $classQuery = "{$classString} AND ";
                 $this->GeneralFilter['classAttributeQuery'] = $classQuery;
             }
         }
         $classAttributeQuery = "";
         if (is_numeric($searchContentClassAttributeID) and $searchContentClassAttributeID > 0) {
             $classAttributeQuery = "ezsearch_object_word_link.contentclass_attribute_id = '{$searchContentClassAttributeID}' AND ";
         } else {
             if (is_array($searchContentClassAttributeID)) {
                 // Build query for searching in a number of attributes
                 $classAttributeQuery = $db->generateSQLINStatement($searchContentClassAttributeID, 'ezsearch_object_word_link.contentclass_attribute_id', false, false, 'int') . ' AND ';
             }
         }
         // Get the total number of objects
         $totalObjectCount = $this->fetchTotalObjectCount();
         $searchPartsArray = array();
         $wordIDHash = array();
         $wildCardCount = 0;
         if (trim($searchText) != '') {
             $wordIDArrays = $this->prepareWordIDArrays($searchText);
             $wordIDArray = $wordIDArrays['wordIDArray'];
             $wordIDHash = $wordIDArrays['wordIDHash'];
             $wildIDArray = $wordIDArrays['wildIDArray'];
             $wildCardCount = $wordIDArrays['wildCardCount'];
             $searchPartsArray = $this->buildSearchPartArray($phraseTextArray, $nonPhraseText, $wordIDHash, $wildIDArray);
         }
         /// OR search, not used in this version
         $doOrSearch = false;
         if ($doOrSearch == true) {
             // build fulltext search SQL part
             $searchWordArray = $this->splitString($fullText);
             $fullTextSQL = "";
             if (count($searchWordArray) > 0) {
                 $i = 0;
                 // Build the word query string
                 foreach ($searchWordArray as $searchWord) {
                     $wordID = null;
                     if (isset($wordIDHash[$searchWord])) {
                         $wordID = $wordIDHash[$searchWord]['id'];
                     }
                     if (is_numeric($wordID) and $wordID > 0) {
                         if ($i == 0) {
                             $fullTextSQL .= "ezsearch_object_word_link.word_id='{$wordID}' ";
                         } else {
                             $fullTextSQL .= " OR ezsearch_object_word_link.word_id='{$wordID}' ";
                         }
                     } else {
                         $nonExistingWordArray[] = $searchWord;
                     }
                     $i++;
                 }
                 $fullTextSQL = " ( {$fullTextSQL} ) AND ";
             }
         }
         // Search only in specific sub trees
         $subTreeSQL = "";
         $subTreeTable = "";
         if (count($subTreeArray) > 0) {
             // Fetch path_string value to use when searching subtrees
             $i = 0;
             $doSubTreeSearch = false;
             $subTreeNodeSQL = '';
             foreach ($subTreeArray as $nodeID) {
                 if (is_numeric($nodeID) and $nodeID > 0) {
                     $subTreeNodeSQL .= " {$nodeID}";
                     if (isset($subTreeArray[$i + 1]) and is_numeric($subTreeArray[$i + 1])) {
                         $subTreeNodeSQL .= ", ";
                     }
                     $doSubTreeSearch = true;
                 }
                 $i++;
             }
             if ($doSubTreeSearch == true) {
                 $subTreeNodeSQL = "( " . $subTreeNodeSQL;
                 //                    $subTreeTable = ", ezcontentobject_tree ";
                 $subTreeTable = '';
                 $subTreeNodeSQL .= " ) ";
                 $nodeQuery = "SELECT node_id, path_string FROM ezcontentobject_tree WHERE node_id IN {$subTreeNodeSQL}";
                 // Build SQL subtre search query
                 $subTreeSQL = " ( ";
                 $nodeArray = $db->arrayQuery($nodeQuery);
                 $i = 0;
                 foreach ($nodeArray as $node) {
                     $pathString = $node['path_string'];
                     $subTreeSQL .= " ezcontentobject_tree.path_string like '{$pathString}%' ";
                     if ($i < count($nodeArray) - 1) {
                         $subTreeSQL .= " OR ";
                     }
                     $i++;
                 }
                 $subTreeSQL .= " ) AND ";
                 $this->GeneralFilter['subTreeTable'] = $subTreeTable;
                 $this->GeneralFilter['subTreeSQL'] = $subTreeSQL;
             }
         }
         $limitation = false;
         if (isset($params['Limitation'])) {
             $limitation = $params['Limitation'];
         }
         $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
         $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
         $this->GeneralFilter['sqlPermissionChecking'] = $sqlPermissionChecking;
         $versionNameJoins = " AND " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject');
         /// Only support AND search at this time
         // build fulltext search SQL part
         $searchWordArray = $this->splitString($fullText);
         $searchWordCount = count($searchWordArray);
         $fullTextSQL = "";
         $stopWordArray = array();
         $ini = eZINI::instance();
         $tmpTableCount = 0;
         $i = 0;
         foreach ($searchTypes['and'] as $searchType) {
             $methodName = $this->constructMethodName($searchType);
             $intermediateResult = $this->callMethod($methodName, array($searchType));
             if ($intermediateResult == false) {
                 // cleanup temp tables
                 $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
                 return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array());
             }
         }
         // Do not execute search if site.ini:[SearchSettings]->AllowEmptySearch is enabled, but no conditions are set.
         if (!$searchDateQuery && !$sectionQuery && !$classQuery && !$classAttributeQuery && !$searchPartsArray && !$subTreeSQL) {
             // cleanup temp tables
             $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
             return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array());
         }
         $i = $this->TempTablesCount;
         // Loop every word and insert result in temporary table
         // Determine whether we should search invisible nodes.
         $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
         foreach ($searchPartsArray as $searchPart) {
             $stopWordThresholdValue = 100;
             if ($ini->hasVariable('SearchSettings', 'StopWordThresholdValue')) {
                 $stopWordThresholdValue = $ini->variable('SearchSettings', 'StopWordThresholdValue');
             }
             $stopWordThresholdPercent = 60;
             if ($ini->hasVariable('SearchSettings', 'StopWordThresholdPercent')) {
                 $stopWordThresholdPercent = $ini->variable('SearchSettings', 'StopWordThresholdPercent');
             }
             $searchThresholdValue = $totalObjectCount;
             if ($totalObjectCount > $stopWordThresholdValue) {
                 $searchThresholdValue = (int) ($totalObjectCount * ($stopWordThresholdPercent / 100));
             }
             // do not search words that are too frequent
             if ($searchPart['object_count'] < $searchThresholdValue) {
                 $tmpTableCount++;
                 $searchPartText = $searchPart['sql_part'];
                 if ($i == 0) {
                     $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', 0);
                     $this->saveCreatedTempTableName(0, $table);
                     $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )");
                     $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n                                         FROM ezcontentobject\n                                              INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n                                              {$subTreeTable}\n                                              INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                                              INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                                              {$sqlPermissionChecking['from']}\n                                         WHERE\n                                               {$searchDateQuery}\n                                               {$sectionQuery}\n                                               {$classQuery}\n                                               {$classAttributeQuery}\n                                               {$searchPartText}\n                                               {$subTreeSQL}\n                                         ezcontentclass.version = '0' AND\n                                         ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                                         {$showInvisibleNodesCond}\n                                         {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE);
                 } else {
                     $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', $i);
                     $this->saveCreatedTempTableName($i, $table);
                     $tmpTable0 = $this->getSavedTempTableName(0);
                     $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )");
                     $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n                                         FROM\n                                             ezcontentobject\n                                             INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n                                             {$subTreeTable}\n                                             INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                                             INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                                             INNER JOIN {$tmpTable0} ON ({$tmpTable0}.contentobject_id = ezsearch_object_word_link.contentobject_id)\n                                             {$sqlPermissionChecking['from']}\n                                          WHERE\n                                          {$searchDateQuery}\n                                          {$sectionQuery}\n                                          {$classQuery}\n                                          {$classAttributeQuery}\n                                          {$searchPartText}\n                                          {$subTreeSQL}\n                                          ezcontentclass.version = '0' AND\n                                          ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                                          {$showInvisibleNodesCond}\n                                          {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE);
                 }
                 $i++;
             } else {
                 $stopWordArray[] = array('word' => $searchPart['text']);
             }
         }
         if (count($searchPartsArray) === 0 && $this->TempTablesCount == 0) {
             $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', 0);
             $this->saveCreatedTempTableName(0, $table);
             $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )");
             $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n                                     FROM ezcontentobject\n                                          INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n                                          {$subTreeTable}\n                                          INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                                          INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                                          {$sqlPermissionChecking['from']}\n                                     WHERE\n                                          {$searchDateQuery}\n                                          {$sectionQuery}\n                                          {$classQuery}\n                                          {$classAttributeQuery}\n                                          {$subTreeSQL}\n                                          ezcontentclass.version = '0' AND\n                                          ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                                          {$showInvisibleNodesCond}\n                                          {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE);
             $this->TempTablesCount = 1;
             $i = $this->TempTablesCount;
         }
         $nonExistingWordCount = count(array_unique($searchWordArray)) - count($wordIDHash) - $wildCardCount;
         $excludeWordCount = $searchWordCount - count($stopWordArray);
         if (count($stopWordArray) + $nonExistingWordCount == $searchWordCount && $this->TempTablesCount == 0) {
             // No words to search for, return empty result
             // cleanup temp tables
             $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
             $db->dropTempTableList($this->getSavedTempTablesList());
             return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => $stopWordArray);
         }
         $tmpTablesFrom = "";
         $tmpTablesWhere = "";
         /// tmp tables
         $tmpTableCount = $i;
         for ($i = 0; $i < $tmpTableCount; $i++) {
             $tmpTablesFrom .= $this->getSavedTempTableName($i);
             if ($i < $tmpTableCount - 1) {
                 $tmpTablesFrom .= ", ";
             }
         }
         $tmpTablesSeparator = '';
         if ($tmpTableCount > 0) {
             $tmpTablesSeparator = ', ';
         }
         $tmpTable0 = $this->getSavedTempTableName(0);
         for ($i = 1; $i < $tmpTableCount; $i++) {
             $tmpTableI = $this->getSavedTempTableName($i);
             $tmpTablesWhere .= " {$tmpTable0}.contentobject_id={$tmpTableI}.contentobject_id  ";
             if ($i < $tmpTableCount - 1) {
                 $tmpTablesWhere .= " AND ";
             }
         }
         $tmpTablesWhereExtra = '';
         if ($tmpTableCount > 0) {
             $tmpTablesWhereExtra = "ezcontentobject.id={$tmpTable0}.contentobject_id AND";
         }
         $and = "";
         if ($tmpTableCount > 1) {
             $and = " AND ";
         }
         // Generate ORDER BY SQL
         $orderBySQLArray = $this->buildSortSQL($sortArray);
         $orderByFieldsSQL = $orderBySQLArray['sortingFields'];
         $sortWhereSQL = $orderBySQLArray['whereSQL'];
         $sortFromSQL = $orderBySQLArray['fromSQL'];
         $sortSelectSQL = $orderBySQLArray['selectSQL'];
         // Fetch data from table
         $searchQuery = '';
         $searchQuery = "SELECT DISTINCT ezcontentobject.*, ezcontentclass.serialized_name_list as class_serialized_name_list,\n                ezcontentobject_tree.*, ezcontentobject_name.name as name,\n                ezcontentobject_name.real_translation {$sortSelectSQL}\n                FROM\n                   {$tmpTablesFrom} {$tmpTablesSeparator}\n                   ezcontentobject\n                   INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id )\n                   INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                   INNER JOIN ezcontentobject_name ON (\n                       ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n                       ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n                   )\n                   {$sortFromSQL}\n                WHERE\n                {$tmpTablesWhere} {$and}\n                {$tmpTablesWhereExtra}\n                ezcontentclass.version = '0' AND\n                ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id AND\n                " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n                {$showInvisibleNodesCond}\n                {$sortWhereSQL}\n                ORDER BY {$orderByFieldsSQL}";
         // Count query
         $languageCond = eZContentLanguage::languagesSQLFilter('ezcontentobject');
         if ($tmpTableCount == 0) {
             $searchCountQuery = "SELECT count( DISTINCT ezcontentobject.id ) AS count\n                        FROM\n                           ezcontentobject,\n                           ezcontentobject_tree\n                        WHERE\n                        ezcontentobject.id = ezcontentobject_tree.contentobject_id and\n                        ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                        AND {$languageCond}\n                        {$showInvisibleNodesCond}";
         } else {
             $searchCountQuery = "SELECT count( DISTINCT ezcontentobject.id ) AS count\n                        FROM {$tmpTablesFrom} {$tmpTablesSeparator}\n                             ezcontentobject\n                        WHERE {$tmpTablesWhere} {$and}\n                            {$tmpTablesWhereExtra}\n                            {$languageCond}";
         }
         $objectRes = array();
         $searchCount = 0;
         if ($nonExistingWordCount <= 0) {
             // execute search query
             $objectResArray = $db->arrayQuery($searchQuery, array("limit" => $searchLimit, "offset" => $searchOffset), eZDBInterface::SERVER_SLAVE);
             // execute search count query
             $objectCountRes = $db->arrayQuery($searchCountQuery, array(), eZDBInterface::SERVER_SLAVE);
             $objectRes = eZContentObjectTreeNode::makeObjectsArray($objectResArray);
             $searchCount = $objectCountRes[0]['count'];
         } else {
             $objectRes = array();
         }
         // Drop tmp tables
         $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
         $db->dropTempTableList($this->getSavedTempTablesList());
         return array("SearchResult" => $objectRes, "SearchCount" => $searchCount, "StopWordArray" => $stopWordArray);
     } else {
         return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array());
     }
 }
Ejemplo n.º 3
0
 static function findNode($parentNode, $id, $asObject = false, $remoteID = false)
 {
     if (!isset($parentNode) || $parentNode == NULL) {
         $parentNode = 2;
     }
     $parentNode = (int) $parentNode;
     $db = eZDB::instance();
     if ($asObject) {
         if ($remoteID) {
             $objectIDFilter = 'ezcontentobject.remote_id = ' . (string) $id;
         } else {
             $objectIDFilter = 'contentobject_id = ' . (int) $id;
         }
         $query = "SELECT ezcontentobject.*,\n                       ezcontentobject_tree.*,\n                       ezcontentclass.serialized_name_list as class_serialized_name_list,\n                       ezcontentclass.identifier as class_identifier,\n                       ezcontentclass.is_container as is_container\n                FROM ezcontentobject_tree,\n                     ezcontentobject,\n                     ezcontentclass\n                WHERE parent_node_id = {$parentNode} AND\n                      {$objectIDFilter} AND\n                      ezcontentobject_tree.contentobject_id=ezcontentobject.id AND\n                      ezcontentclass.version=0  AND\n                      ezcontentclass.id = ezcontentobject.contentclass_id ";
         $nodeListArray = $db->arrayQuery($query);
         $retNodeArray = eZContentObjectTreeNode::makeObjectsArray($nodeListArray);
         if (count($retNodeArray) > 0) {
             return $retNodeArray[0];
         } else {
             return null;
         }
     } else {
         $id = (int) $id;
         $getNodeQuery = "SELECT node_id\n                           FROM ezcontentobject_tree\n                           WHERE\n                                parent_node_id={$parentNode} AND\n                                contentobject_id = {$id} ";
         $nodeArr = $db->arrayQuery($getNodeQuery);
         if (isset($nodeArr[0])) {
             return $nodeArr[0]['node_id'];
         } else {
             return false;
         }
     }
 }
 /**
  * Returns the node assignments for the current object.
  *
  * @param boolean $asObject
  * @param boolean $checkVisibility if true, the visibility and the setting
  * site.ini/[SiteAccessSettings]/ShowHiddenNodes are taken into account.
  * @return eZContentObjectTreeNode[]|array[]
  */
 function assignedNodes( $asObject = true, $checkVisibility = false )
 {
     $contentobjectID = $this->attribute( 'id' );
     if ( $contentobjectID == null )
     {
         return array();
     }
     $visibilitySQL = '';
     if (
         $checkVisibility === true
         && eZINI::instance()->variable( 'SiteAccessSettings', 'ShowHiddenNodes' ) !== 'true'
     )
     {
         $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 ";
     }
     $nodesListArray = eZDB::instance()->arrayQuery(
         "SELECT " .
         "ezcontentobject.contentclass_id, ezcontentobject.current_version, ezcontentobject.initial_language_id, ezcontentobject.language_mask, " .
         "ezcontentobject.modified, ezcontentobject.name, ezcontentobject.owner_id, ezcontentobject.published, ezcontentobject.remote_id AS object_remote_id, ezcontentobject.section_id, " .
         "ezcontentobject.status, ezcontentobject_tree.contentobject_is_published, ezcontentobject_tree.contentobject_version, ezcontentobject_tree.depth, " .
         "ezcontentobject_tree.is_hidden, ezcontentobject_tree.is_invisible, ezcontentobject_tree.main_node_id, ezcontentobject_tree.modified_subnode, ezcontentobject_tree.node_id, " .
         "ezcontentobject_tree.parent_node_id, ezcontentobject_tree.path_identification_string, ezcontentobject_tree.path_string, ezcontentobject_tree.priority, ezcontentobject_tree.remote_id, " .
         "ezcontentobject_tree.sort_field, ezcontentobject_tree.sort_order, ezcontentclass.serialized_name_list as class_serialized_name_list, " .
         "ezcontentclass.identifier as class_identifier, " .
         "ezcontentclass.is_container as is_container " .
         "FROM ezcontentobject_tree " .
         "INNER JOIN ezcontentobject ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id) " .
         "INNER JOIN ezcontentclass ON (ezcontentclass.version = 0 AND ezcontentclass.id = ezcontentobject.contentclass_id) " .
         "WHERE contentobject_id = $contentobjectID " .
         $visibilitySQL .
         "ORDER BY path_string"
     );
     if ( $asObject == true )
     {
         return eZContentObjectTreeNode::makeObjectsArray( $nodesListArray, true, array( "id" => $contentobjectID ) );
     }
     else
         return $nodesListArray;
 }
Ejemplo n.º 5
0
 function assignedNodes( $asObject = true )
 {
     $contentobjectID = $this->attribute( 'id' );
     if ( $contentobjectID == null )
     {
         $retValue = array();
         return $retValue;
     }
     $query = "SELECT ezcontentobject.*,
          ezcontentobject_tree.*,
          ezcontentclass.serialized_name_list as class_serialized_name_list,
          ezcontentclass.identifier as class_identifier,
          ezcontentclass.is_container as is_container
       FROM   ezcontentobject_tree,
          ezcontentobject,
          ezcontentclass
       WHERE  contentobject_id=$contentobjectID AND
          ezcontentobject_tree.contentobject_id=ezcontentobject.id  AND
          ezcontentclass.version=0 AND
          ezcontentclass.id = ezcontentobject.contentclass_id
       ORDER BY path_string";
     $db = eZDB::instance();
     $nodesListArray = $db->arrayQuery( $query );
     if ( $asObject == true )
     {
         $nodes = eZContentObjectTreeNode::makeObjectsArray( $nodesListArray );
         return $nodes;
     }
     else
         return $nodesListArray;
 }
    /**
     * Returns the nodes for the current object.
     *
     * @param boolean $asObject
     * @param boolean $checkVisibility if true, the visibility and the setting
     * site.ini/[SiteAccessSettings]/ShowHiddenNodes are taken into account.
     * @return eZContentObjectTreeNode[]|array[]
     */
    function assignedNodes( $asObject = true, $checkVisibility = false )
    {
        $contentobjectID = $this->attribute( 'id' );
        if ( $contentobjectID == null )
        {
            $retValue = array();
            return $retValue;
        }

        $visibilitySQL = '';
        if (
            $checkVisibility === true
            && eZINI::instance()->variable( 'SiteAccessSettings', 'ShowHiddenNodes' ) !== 'true'
        )
        {
            $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 ";
        }

        $query = "SELECT ezcontentobject.*,
             ezcontentobject_tree.*,
             ezcontentclass.serialized_name_list as class_serialized_name_list,
             ezcontentclass.identifier as class_identifier,
             ezcontentclass.is_container as is_container
          FROM   ezcontentobject_tree,
             ezcontentobject,
             ezcontentclass
          WHERE  contentobject_id=$contentobjectID AND
             ezcontentobject_tree.contentobject_id=ezcontentobject.id  AND
             ezcontentclass.version=0 AND
             ezcontentclass.id = ezcontentobject.contentclass_id
             $visibilitySQL
          ORDER BY path_string";
        $db = eZDB::instance();
        $nodesListArray = $db->arrayQuery( $query );

        if ( $asObject == true )
        {
            $nodes = eZContentObjectTreeNode::makeObjectsArray( $nodesListArray );
            return $nodes;
        }
        else
            return $nodesListArray;
    }
 /**
  * @param $tpl eZTemplate
  * @param $operatorName array
  * @param $operatorParameters array
  * @param $rootNamespace string
  * @param $currentNamespace string
  * @param $operatorValue mixed
  * @param $namedParameters array
  *
  * @return mixed
  */
 function modify(&$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     $ini = eZINI::instance('ocoperatorscollection.ini');
     $appini = eZINI::instance('app.ini');
     switch ($operatorName) {
         case 'related_attribute_objects':
             $object = $operatorValue;
             $identifier = $namedParameters['identifier'];
             $dataMap = $object instanceof eZContentObject || $object instanceof eZContentObjectTreeNode ? $object->attribute('data_map') : array();
             $data = array();
             if (isset($dataMap[$identifier])) {
                 $ids = $dataMap[$identifier] instanceof eZContentObjectAttribute ? explode('-', $dataMap[$identifier]->toString()) : array();
                 if (!empty($ids)) {
                     $data = eZContentObject::fetchList(true, array("id" => array($ids)));
                 }
             }
             $operatorValue = $data;
             break;
         case 'smart_override':
             $identifier = $namedParameters['identifier'];
             $view = $namedParameters['view'];
             $node = $operatorValue;
             $operatorValue = $this->findSmartTemplate($identifier, $view, $node);
             break;
         case 'parse_link_href':
             $href = $operatorValue;
             $hrefParts = explode(':', $href);
             $hrefFirst = array_shift($hrefParts);
             if (!in_array($hrefFirst, array('http', 'https', 'file', 'mailto', 'ftp'))) {
                 if (!empty($hrefFirst)) {
                     $nodeID = eZURLAliasML::fetchNodeIDByPath('/' . $hrefFirst);
                     if ($nodeID) {
                         $contentNode = eZContentObjectTreeNode::fetch($nodeID);
                         if ($contentNode instanceof eZContentObjectTreeNode) {
                             $keyArray = array(array('node', $contentNode->attribute('node_id')), array('object', $contentNode->attribute('contentobject_id')), array('class_identifier', $contentNode->attribute('class_identifier')), array('class_group', $contentNode->attribute('object')->attribute('content_class')->attribute('match_ingroup_id_list')));
                             $tpl = new eZTemplate();
                             $ini = eZINI::instance();
                             $autoLoadPathList = $ini->variable('TemplateSettings', 'AutoloadPathList');
                             $extensionAutoloadPath = $ini->variable('TemplateSettings', 'ExtensionAutoloadPath');
                             $extensionPathList = eZExtension::expandedPathList($extensionAutoloadPath, 'autoloads/');
                             $autoLoadPathList = array_unique(array_merge($autoLoadPathList, $extensionPathList));
                             $tpl->setAutoloadPathList($autoLoadPathList);
                             $tpl->autoload();
                             $tpl->setVariable('node', $contentNode);
                             $tpl->setVariable('object', $contentNode->attribute('object'));
                             $tpl->setVariable('original_href', $href);
                             $res = new eZTemplateDesignResource();
                             $res->setKeys($keyArray);
                             $tpl->registerResource($res);
                             $result = trim($tpl->fetch('design:link/href.tpl'));
                             if (!empty($result)) {
                                 $href = $result;
                             }
                         }
                     }
                 }
             }
             return $operatorValue = $href;
             break;
         case 'gmap_static_image':
             try {
                 $cacheFileNames = array();
                 //@todo
                 $operatorValue = OCOperatorsCollectionsTools::gmapStaticImage($namedParameters['parameters'], $namedParameters['attribute'], $cacheFileNames);
             } catch (Exception $e) {
                 eZDebug::writeError($e->getMessage(), 'gmap_static_image');
             }
             break;
         case 'fa_class_icon':
             $faIconIni = eZINI::instance('fa_icons.ini');
             $node = $operatorValue;
             $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : $faIconIni->variable('ClassIcons', '_fallback');
             if ($node instanceof eZContentObjectTreeNode) {
                 if ($faIconIni->hasVariable('ClassIcons', $node->attribute('class_identifier'))) {
                     $data = $faIconIni->variable('ClassIcons', $node->attribute('class_identifier'));
                 }
             }
             $operatorValue = $data;
             break;
         case 'fa_object_icon':
             $faIconIni = eZINI::instance('fa_icons.ini');
             $object = $operatorValue;
             $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : '';
             if ($object instanceof eZContentObject) {
                 if ($faIconIni->hasVariable('ObjectIcons', $object->attribute('id'))) {
                     $data = $faIconIni->variable('ObjectIcons', $object->attribute('id'));
                 }
             } else {
                 if ($faIconIni->hasVariable('ObjectIcons', $node)) {
                     $data = $faIconIni->variable('ObjectIcons', $node);
                 }
             }
             $operatorValue = $data;
             break;
         case 'fa_node_icon':
             $faIconIni = eZINI::instance('fa_icons.ini');
             $node = $operatorValue;
             $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : '';
             if ($node instanceof eZContentObjectTreeNode) {
                 if ($faIconIni->hasVariable('NodeIcons', $node->attribute('node_id'))) {
                     $data = $faIconIni->variable('NodeIcons', $node->attribute('node_id'));
                 }
             } else {
                 if ($faIconIni->hasVariable('NodeIcons', $node)) {
                     $data = $faIconIni->variable('NodeIcons', $node);
                 }
             }
             $operatorValue = $data;
             break;
         case 'children_class_identifiers':
             $node = $operatorValue;
             $data = array();
             if ($node instanceof eZContentObjectTreeNode) {
                 $search = eZFunctionHandler::execute('ezfind', 'search', array('subtree_array' => array($node->attribute('node_id')), 'limit' => 1, 'as_objects' => false, 'filter' => array('-meta_id_si:' . $node->attribute('contentobject_id')), 'facet' => array(array('field' => 'meta_class_identifier_ms', 'name' => 'class_identifier', 'limit' => 200))));
                 if (isset($search['SearchExtras'])) {
                     $facets = $search['SearchExtras']->attribute('facet_fields');
                     $data = array_diff(array_values($facets[0]['nameList']), $namedParameters['exclude']);
                 }
             }
             //eZDebug::writeNotice( $data, 'children_class_identifiers'  );
             $operatorValue = $data;
             break;
         case 'json_encode':
             $operatorValue = json_encode($operatorValue);
             break;
         case 'browse_template':
             $identifiers = array('image', 'image2', 'galleria', 'gallery', 'immagini');
             if ($ini->hasVariable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers')) {
                 $identifiers = $ini->variable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers');
             }
             if ($operatorValue instanceof eZContentBrowse && $operatorValue->hasAttribute('type') && $operatorValue->attribute('type') == 'AddRelatedObjectListToDataType' && $operatorValue->hasAttribute('action_name')) {
                 $currentAttributeId = str_replace('AddRelatedObject_', '', $operatorValue->attribute('action_name'));
                 $currentAttribute = eZPersistentObject::fetchObject(eZContentObjectAttribute::definition(), null, array("id" => $currentAttributeId), false);
                 if (isset($currentAttribute['contentclassattribute_id'])) {
                     $contentClassAttribute = eZContentClassAttribute::fetch($currentAttribute['contentclassattribute_id']);
                     if ($contentClassAttribute instanceof eZContentClassAttribute && ($contentClassAttribute->attribute('data_type_string') == 'mugoobjectrelationlist' || $contentClassAttribute->attribute('data_type_string') == 'ezobjectrelationlist') && in_array($contentClassAttribute->attribute('identifier'), $identifiers)) {
                         return $operatorValue = 'multiupload.tpl';
                     }
                 }
             } elseif ($operatorValue instanceof eZContentBrowse && $operatorValue->hasAttribute('action_name') && $operatorValue->attribute('action_name') == 'MultiUploadBrowse') {
                 return $operatorValue = 'multiupload.tpl';
             }
             $operatorValue = 'default.tpl';
             break;
         case 'multiupload_file_types_string':
             $availableFileTypes = array();
             $availableFileTypesString = '';
             if (eZINI::instance('ezmultiupload.ini')->hasGroup('FileTypeSettings_' . $operatorValue)) {
                 $availableFileTypes = eZINI::instance('ezmultiupload.ini')->variable('FileTypeSettings_' . $operatorValue, 'FileType');
             }
             if (!empty($availableFileTypes)) {
                 $availableFileTypesString = implode(';', $availableFileTypes);
             }
             $operatorValue = $availableFileTypesString;
             break;
         case 'multiupload_file_types_string_from_attribute':
             $availableFileTypesString = '';
             $attribute = $operatorValue;
             if ($attribute instanceof eZContentObjectAttribute) {
                 $identifiers = array();
                 if ($ini->hasVariable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers')) {
                     $identifier = $attribute->attribute('contentclass_attribute_identifier');
                     $identifiers = $ini->variable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers');
                     if (in_array($identifier, $identifiers)) {
                         $availableFileTypes = array();
                         $groups = $ini->group('ObjectRelationsMultiuploadFileTypesGroups');
                         foreach ($groups as $groupName => $fileType) {
                             $groupIdentifiers = $ini->variable('ObjectRelationsMultiuploadFileTypes_' . $groupName, 'Identifiers');
                             if (in_array($identifier, $groupIdentifiers)) {
                                 $availableFileTypesString = $fileType;
                             }
                         }
                     }
                 }
             }
             $operatorValue = $availableFileTypesString;
             break;
         case 'session_id':
             $operatorValue = session_id();
             break;
         case 'session_name':
             $operatorValue = session_name();
             break;
         case 'user_session_hash':
             $operatorValue = '';
             break;
         case 'developer_warning':
             $res = false;
             $user = eZUser::currentUser();
             if ($user->attribute('login') == 'admin') {
                 $templates = $tpl->templateFetchList();
                 $data = array_pop($templates);
                 $res = '<div class="developer-warning alert alert-danger"><strong>Avviso per lo sviluppatore</strong>:<br /><code>' . $data . '</code><br />' . $namedParameters['text'] . '</div>';
             }
             $operatorValue = $res;
             break;
         case 'editor_warning':
             $res = false;
             $user = eZUser::currentUser();
             if ($user->hasAccessTo('content', 'dashboard')) {
                 $res = '<div class="editor-warning alert alert-warning"><strong>Avviso per l\'editor</strong>: ' . $namedParameters['text'] . '</div>';
             }
             $operatorValue = $res;
             break;
         case 'appini':
             if ($appini->hasVariable($namedParameters['block'], $namedParameters['setting'])) {
                 $rs = $appini->variable($namedParameters['block'], $namedParameters['setting']);
             } else {
                 $rs = $namedParameters['default'];
             }
             $operatorValue = $rs;
             break;
         case 'has_attribute':
         case 'attribute':
             if ($operatorName == 'attribute' && $namedParameters['show_values'] == 'show') {
                 $legacy = new eZTemplateAttributeOperator();
                 $parameters = $legacy->namedParameterList();
                 if (isset($parameters['attribute'])) {
                     $parameters = $parameters['attribute'];
                 }
                 $legacyParameters = array();
                 foreach (array_keys($parameters) as $key) {
                     switch ($key) {
                         case "as_html":
                             $legacyParameters[$key] = true;
                             break;
                         default:
                             $legacyParameters[$key] = isset($namedParameters[$key]) ? $namedParameters[$key] : false;
                     }
                 }
                 $legacy->modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, $operatorValue, $legacyParameters, null);
                 return $operatorValue;
             }
             return $operatorValue = $this->hasContentObjectAttribute($operatorValue, $namedParameters['show_values']);
             break;
         case 'set_defaults':
             if (is_array($namedParameters['variables'])) {
                 foreach ($namedParameters['variables'] as $key => $value) {
                     if (!$tpl->hasVariable($key, $currentNamespace)) {
                         $tpl->setLocalVariable($key, $value, $currentNamespace);
                     }
                 }
             }
             break;
         case 'unset_defaults':
             foreach ($namedParameters['variables'] as $key) {
                 $tpl->unsetLocalVariable($key, $currentNamespace);
                 //                    if ( isset( $tpl->Variables[$rootNamespace] ) &&
                 //                         array_key_exists( $key, $tpl->Variables[$rootNamespace] ) )
                 //                    {
                 //                        $tpl->unsetVariable( $key, $rootNamespace );
                 //                    }
             }
             break;
             //@todo add cache!
         //@todo add cache!
         case 'include_cache':
             $tpl = eZTemplate::factory();
             foreach ($namedParameters['variables'] as $key => $value) {
                 $tpl->setVariable($key, $value);
             }
             $operatorValue = $tpl->fetch('design:' . $namedParameters['template']);
             break;
         case 'find_global_layout':
             $result = false;
             $node = $operatorValue;
             if (is_numeric($node)) {
                 $node = eZContentObjectTreeNode::fetch($node);
             }
             if (!$node) {
                 return $operatorValue = $result;
             }
             $pathArray = $node->attribute('path_array');
             $nodesParams = array();
             foreach ($pathArray as $pathNodeID) {
                 if ($pathNodeID < eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode') || $pathNodeID == $node->attribute('node_id')) {
                     continue;
                 } else {
                     $nodesParams[] = array('ParentNodeID' => $pathNodeID, 'ResultID' => 'ezcontentobject_tree.node_id', 'ClassFilterType' => 'include', 'ClassFilterArray' => $ini->variable('GlobalLayout', 'Classes'), 'Depth' => 1, 'DepthOperator' => 'eq', 'AsObject' => false);
                 }
             }
             //eZDebug::writeWarning( var_export($nodesParams,1), __METHOD__);
             $findNodes = eZContentObjectTreeNode::subTreeMultiPaths($nodesParams, array('SortBy' => array('node_id', false)));
             $sortByParentNodeID = array();
             if (!empty($findNodes)) {
                 foreach ($findNodes as $findNode) {
                     $sortByParentNodeID[$findNode['parent_node_id']] = $findNode;
                 }
                 krsort($sortByParentNodeID);
                 $result = array_shift($sortByParentNodeID);
                 $result = eZContentObjectTreeNode::makeObjectsArray(array($result));
                 if (!empty($result)) {
                     $result = $result[0];
                 }
             }
             return $operatorValue = $result;
         case 'redirect':
             $url = $namedParameters['url'];
             header('Location: ' . $url);
             break;
         case 'sort_nodes':
             $sortNodes = array();
             if (!empty($operatorValue) && is_array($operatorValue)) {
                 $nodes = $operatorValue;
                 foreach ($nodes as $node) {
                     if (!$node instanceof eZContentObjectTreeNode) {
                         continue;
                     }
                     $object = $node->object();
                     switch ($namedParameters['by']) {
                         case 'published':
                         default:
                             $sortby = $object->attribute('published');
                             break;
                     }
                     $sortNodes[$sortby] = $node;
                 }
                 ksort($sortNodes);
                 if ($namedParameters['order'] == 'desc') {
                     $sortNodes = array_reverse($sortNodes);
                 }
             }
             return $operatorValue = $sortNodes;
             break;
         case 'to_query_string':
             if (!empty($namedParameters['param'])) {
                 $value = $namedParameters['param'];
             } else {
                 $value = $operatorValue;
             }
             $string = http_build_query($value);
             return $operatorValue = $string;
             break;
         case 'has_abstract':
         case 'abstract':
             $node = $operatorValue;
             if (!$node instanceof eZContentObjectTreeNode && isset($namedParameters['node'])) {
                 $node = $namedParameters['node'];
                 if (is_numeric($node)) {
                     $node = eZContentObjectTreeNode::fetch($node);
                 }
             }
             return $operatorValue = $this->getAbstract($node, $operatorName == 'has_abstract');
             break;
         case 'subsite':
             $path = $this->getPath($tpl);
             $result = false;
             $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array();
             $root = eZContentObjectTreeNode::fetch(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode'));
             if (in_array($root->attribute('class_identifier'), $identifiers)) {
                 $result = $root;
             }
             foreach ($path as $item) {
                 if (isset($item['node_id'])) {
                     $node = eZContentObjectTreeNode::fetch($item['node_id']);
                     if (in_array($node->attribute('class_identifier'), $identifiers)) {
                         $result = $node;
                     }
                 }
             }
             return $operatorValue = $result;
             break;
         case 'in_subsite':
             $result = false;
             $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array();
             $root = eZContentObjectTreeNode::fetch(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode'));
             if (in_array($root->attribute('class_identifier'), $identifiers)) {
                 $result = $root;
             }
             $node = $operatorValue;
             if (is_numeric($node)) {
                 $node = eZContentObjectTreeNode::fetch($node);
             }
             if (!$node) {
                 return $operatorValue = $result;
             }
             foreach ($node->attribute('path') as $item) {
                 if (in_array($item->attribute('class_identifier'), $identifiers)) {
                     $result = $item;
                     break;
                 }
             }
             return $operatorValue = $result;
             break;
         case 'is_subsite':
             $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array();
             $inSubsite = false;
             $node = $operatorValue;
             if (is_numeric($node)) {
                 $node = eZContentObjectTreeNode::fetch($node);
             }
             if (!$node instanceof eZContentObjectTreeNode) {
                 $inSubsite = false;
             } elseif (in_array($node->attribute('class_identifier'), $identifiers)) {
                 $inSubsite = true;
             }
             return $operatorValue = $inSubsite;
             break;
         case 'is_in_subsite':
             if ($operatorValue instanceof eZContentObject) {
                 $nodes = $operatorValue->attribute('assigned_nodes');
                 foreach ($nodes as $node) {
                     if ($this->isNodeInCurrentSiteaccess($node)) {
                         return $operatorValue;
                     }
                 }
             } elseif ($operatorValue instanceof eZContentObjectTreeNode) {
                 if ($this->isNodeInCurrentSiteaccess($operatorValue)) {
                     return $operatorValue;
                 }
             }
             return $operatorValue = false;
         case 'section_color':
             $path = $this->getPath($tpl);
             $color = false;
             $attributesIdentifiers = $ini->hasVariable('Color', 'Attributes') ? $ini->variable('Color', 'Attributes') : array();
             foreach ($path as $item) {
                 if (isset($item['node_id'])) {
                     $node = eZContentObjectTreeNode::fetch($item['node_id']);
                     /** @var eZContentObjectAttribute[] $attributes */
                     $attributes = $node->attribute('object')->fetchAttributesByIdentifier($attributesIdentifiers);
                     if (is_array($attributes)) {
                         foreach ($attributes as $attribute) {
                             if ($attribute->hasContent()) {
                                 $color = $attribute->content();
                             }
                         }
                     }
                 }
             }
             return $operatorValue = $color;
             break;
         case 'oc_shorten':
             $search = array('@<script[^>]*?>.*?</script>@si', '@<style[^>]*?>.*?</style>@siU');
             $operatorValue = preg_replace($search, '', $operatorValue);
             $operatorValue = strip_tags($operatorValue, $namedParameters['allowable_tags']);
             $operatorValue = preg_replace('!\\s+!', ' ', $operatorValue);
             $operatorValue = str_replace('&nbsp;', ' ', $operatorValue);
             $strlenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen';
             $operatorLength = $strlenFunc($operatorValue);
             if ($operatorLength > $namedParameters['chars_to_keep']) {
                 if ($namedParameters['trim_type'] === 'middle') {
                     $appendedStrLen = $strlenFunc($namedParameters['str_to_append']);
                     if ($namedParameters['chars_to_keep'] > $appendedStrLen) {
                         $chop = $namedParameters['chars_to_keep'] - $appendedStrLen;
                         $middlePos = (int) ($chop / 2);
                         $leftPartLength = $middlePos;
                         $rightPartLength = $chop - $middlePos;
                         $operatorValue = trim($this->custom_substr($operatorValue, 0, $leftPartLength) . $namedParameters['str_to_append'] . $this->custom_substr($operatorValue, $operatorLength - $rightPartLength, $rightPartLength));
                     } else {
                         $operatorValue = $namedParameters['str_to_append'];
                     }
                 } else {
                     $chop = $namedParameters['chars_to_keep'] - $strlenFunc($namedParameters['str_to_append']);
                     $operatorValue = $this->custom_substr($operatorValue, 0, $chop);
                     $operatorValue = trim($operatorValue);
                     if ($operatorLength > $chop) {
                         $operatorValue = $operatorValue . $namedParameters['str_to_append'];
                     }
                 }
             }
             if ($namedParameters['allowable_tags'] !== '') {
                 $operatorValue = $this->force_balance_tags($operatorValue);
             }
             break;
         case 'cookieset':
             $key = isset($namedParameters['cookie_name']) ? $namedParameters['cookie_name'] : false;
             $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix');
             $key = "{$prefix}{$key}";
             // Get our parameters:
             $value = $namedParameters['cookie_val'];
             $expire = $namedParameters['expiry_time'];
             // Check and calculate the expiry time:
             if ($expire > 0) {
                 // It is a number of days:
                 $expire = time() + 60 * 60 * 24 * $expire;
             }
             setcookie($key, $value, $expire, '/');
             eZDebug::writeDebug('setcookie(' . $key . ', ' . $value . ', ' . $expire . ', "/")', __METHOD__);
             return $operatorValue = false;
             break;
         case 'cookieget':
             $key = isset($namedParameters['cookie_name']) ? $namedParameters['cookie_name'] : false;
             $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix');
             $key = "{$prefix}{$key}";
             $operatorValue = false;
             if (isset($_COOKIE[$key])) {
                 $operatorValue = $_COOKIE[$key];
             }
             return $operatorValue;
             break;
         case 'check_and_set_cookies':
             $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix');
             $http = eZHTTPTool::instance();
             $return = array();
             if ($ini->hasVariable('Cookies', 'Cookies')) {
                 $cookies = $ini->variable('Cookies', 'Cookies');
                 foreach ($cookies as $key) {
                     $_key = "{$prefix}{$key}";
                     $default = isset($_COOKIE[$_key]) ? $_COOKIE[$_key] : $ini->variable($key, 'Default');
                     $value = $http->variable($key, $default);
                     setcookie($_key, $value, time() + 60 * 60 * 24 * 365, '/');
                     $return[$key] = $value;
                 }
             }
             $operatorValue = $return;
             break;
         case 'checkbrowser':
             @(require 'extension/ocoperatorscollection/lib/browser_detection.php');
             if (function_exists('browser_detection')) {
                 $full = browser_detection('full_assoc', 2);
                 $operatorValue = $full;
             } else {
                 eZDebug::writeError("function browser_detection not found", __METHOD__);
             }
             break;
         case 'is_deprecated_browser':
             $browser = $namedParameters['browser_array'];
             if ($browser['browser_working'] == 'ie' && $browser['browser_number'] > '7.0') {
                 $operatorValue = true;
             }
             $operatorValue = false;
             break;
         case 'slugize':
             $operatorValue = $this->sanitize_title_with_dashes($operatorValue);
             break;
     }
     return false;
 }