static function addPhrase($phrase, $returnCount) { $db = eZDB::instance(); $db->begin(); $db->lock("ezsearch_search_phrase"); $trans = eZCharTransform::instance(); $phrase = $trans->transformByGroup(trim($phrase), 'search'); // 250 is the numbers of characters accepted by the DB table, so shorten to fit if (strlen($phrase) > 250) { $phrase = substr($phrase, 0, 247) . "..."; } $phrase = $db->escapeString($phrase); // find or store the phrase $phraseRes = $db->arrayQuery("SELECT id FROM ezsearch_search_phrase WHERE phrase='{$phrase}'"); if (count($phraseRes) == 1) { $phraseID = $phraseRes[0]['id']; $db->query("UPDATE ezsearch_search_phrase\n SET phrase_count = phrase_count + 1,\n result_count = result_count + {$returnCount}\n WHERE id = {$phraseID}"); } else { $db->query("INSERT INTO\n ezsearch_search_phrase ( phrase, phrase_count, result_count )\n VALUES ( '{$phrase}', 1, {$returnCount} )"); /* when breaking BC: delete next line */ $phraseID = $db->lastSerialID('ezsearch_search_phrase', 'id'); } $db->unlock(); /* when breaking BC: delete next lines */ /* ezsearch_return_count is not used any more by eZ Publish but perhaps someone else added some functionality... */ $time = time(); // store the search result $db->query("INSERT INTO\n ezsearch_return_count ( phrase_id, count, time )\n VALUES ( '{$phraseID}', '{$returnCount}', '{$time}' )"); /* end of BC breaking delete*/ $db->commit(); }
/** * Provides auto complete results when adding tags to object * * @static * * @param array $args * * @return array */ public static function autocomplete($args) { $http = eZHTTPTool::instance(); $searchString = trim($http->postVariable('search_string'), ''); if (empty($searchString)) { return array('status' => 'success', 'message' => '', 'tags' => array()); } // Initialize transformation system $trans = eZCharTransform::instance(); $searchString = $trans->transformByGroup($http->postVariable('search_string'), 'lowercase'); return self::generateOutput(array('LOWER( eztags_keyword.keyword )' => array('like', $searchString . '%')), $http->postVariable('subtree_limit', 0), $http->postVariable('hide_root_tag', '0'), $http->postVariable('locale', '')); }
function addColumn($name = false, $id = false) { if ($name == false) { $name = 'Col_' . count($this->ColumnNames); } if ($id == false) { // Initialize transformation system $trans = eZCharTransform::instance(); $id = $trans->transformByGroup($name, 'identifier'); } $this->ColumnNames[] = array('name' => $name, 'identifier' => $id, 'index' => count($this->ColumnNames)); }
function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute) { $postVariableName = $base . "_data_object_relation_id_" . $contentObjectAttribute->attribute("id"); $haveData = false; if ($http->hasPostVariable($postVariableName)) { $relatedObjectID = $http->postVariable($postVariableName); if ($relatedObjectID == '') { $relatedObjectID = null; } $contentObjectAttribute->setAttribute('data_int', $relatedObjectID); $haveData = true; } $fuzzyMatchVariableName = $base . "_data_object_relation_fuzzy_match_" . $contentObjectAttribute->attribute("id"); if ($http->hasPostVariable($fuzzyMatchVariableName)) { $trans = eZCharTransform::instance(); $fuzzyMatchText = trim($http->postVariable($fuzzyMatchVariableName)); if ($fuzzyMatchText != '') { $fuzzyMatchText = $trans->transformByGroup($fuzzyMatchText, 'lowercase'); $classAttribute = $contentObjectAttribute->attribute('contentclass_attribute'); if ($classAttribute) { $classContent = $classAttribute->content(); if ($classContent['default_selection_node']) { $nodeID = $classContent['default_selection_node']; $nodeList = eZContentObjectTreeNode::subTreeByNodeID(array('Depth' => 1), $nodeID); $lastDiff = false; $matchObjectID = false; foreach ($nodeList as $node) { $name = $trans->transformByGroup(trim($node->attribute('name')), 'lowercase'); $diff = $this->fuzzyTextMatch($name, $fuzzyMatchText); if ($diff === false) { continue; } if ($diff == 0) { $matchObjectID = $node->attribute('contentobject_id'); break; } if ($lastDiff === false or $diff < $lastDiff) { $lastDiff = $diff; $matchObjectID = $node->attribute('contentobject_id'); } } if ($matchObjectID !== false) { $contentObjectAttribute->setAttribute('data_int', $matchObjectID); $haveData = true; } } } } } return $haveData; }
function install($package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData) { //$this->Package =& $package; $trans = eZCharTransform::instance(); $name = $content->getAttribute('name'); $extensionName = $trans->transformByGroup($name, 'urlalias'); if (strcmp($name, $extensionName) !== 0) { $description = ezpI18n::tr('kernel/package', 'Package contains an invalid extension name: %extensionname', false, array('%extensionname' => $name)); $installParameters['error'] = array('error_code' => false, 'element_id' => $name, 'description' => $description); return false; } $siteINI = eZINI::instance(); $extensionRootDir = $siteINI->variable('ExtensionSettings', 'ExtensionDirectory'); $extensionDir = $extensionRootDir . '/' . $extensionName; $packageExtensionDir = $package->path() . '/' . $parameters['sub-directory'] . '/' . $extensionName; // Error: extension already exists. if (file_exists($extensionDir)) { $description = ezpI18n::tr('kernel/package', "Extension '%extensionname' already exists.", false, array('%extensionname' => $extensionName)); $choosenAction = $this->errorChoosenAction(self::ERROR_EXISTS, $installParameters, $description, $this->HandlerType); switch ($choosenAction) { case self::ACTION_SKIP: return true; case eZPackage::NON_INTERACTIVE: case self::ACTION_REPLACE: eZDir::recursiveDelete($extensionDir); break; default: $installParameters['error'] = array('error_code' => self::ERROR_EXISTS, 'element_id' => $extensionName, 'description' => $description, 'actions' => array(self::ACTION_REPLACE => ezpI18n::tr('kernel/package', "Replace extension"), self::ACTION_SKIP => ezpI18n::tr('kernel/package', 'Skip'))); return false; } } eZDir::mkdir($extensionDir, false, true); eZDir::copy($packageExtensionDir, $extensionRootDir); // Regenerate autoloads for extensions to pick up the newly created extension ezpAutoloader::updateExtensionAutoloadArray(); // Activate extension $siteINI = eZINI::instance('site.ini', 'settings/override', null, null, false, true); if ($siteINI->hasVariable('ExtensionSettings', "ActiveExtensions")) { $selectedExtensions = $siteINI->variable('ExtensionSettings', "ActiveExtensions"); } else { $selectedExtensions = array(); } if (!in_array($extensionName, $selectedExtensions)) { $selectedExtensions[] = $extensionName; $siteINI->setVariable("ExtensionSettings", "ActiveExtensions", $selectedExtensions); $siteINI->save('site.ini.append', '.php', false, false); } return true; }
static function addPhrase($phrase, $returnCount) { $db = eZDB::instance(); $db->begin(); $db->lock("ezsearch_search_phrase"); $trans = eZCharTransform::instance(); $phrase = $trans->transformByGroup(trim($phrase), 'search'); // 250 is the numbers of characters accepted by the DB table, so shorten to fit if (strlen($phrase) > 250) { $phrase = substr($phrase, 0, 247) . "..."; } $phrase = $db->escapeString($phrase); // find or store the phrase $phraseRes = $db->arrayQuery("SELECT id FROM ezsearch_search_phrase WHERE phrase='{$phrase}'"); if (count($phraseRes) == 1) { $phraseID = $phraseRes[0]['id']; $db->query("UPDATE ezsearch_search_phrase\n SET phrase_count = phrase_count + 1,\n result_count = result_count + {$returnCount}\n WHERE id = {$phraseID}"); } else { $db->query("INSERT INTO\n ezsearch_search_phrase ( phrase, phrase_count, result_count )\n VALUES ( '{$phrase}', 1, {$returnCount} )"); } $db->unlock(); $db->commit(); }
/** * Returns a key to sort attributes. * * @param mixed $contentObjectAttribute Class eZContentObjectAttribute. * * @return string */ public function sortKey($contentObjectAttribute) { include_once 'lib/ezi18n/classes/ezchartransform.php'; $trans = eZCharTransform::instance(); $data = $contentObjectAttribute->attribute('data_text'); return $trans->transformByGroup($data, 'lowercase'); }
static public function fetchKeyword( $alphabet, $classid, $offset, $limit, $owner = false, $sortBy = array(), $parentNodeID = false, $includeDuplicates = true, $strictMatching = false ) { $classIDArray = array(); if ( is_numeric( $classid ) ) { $classIDArray = array( $classid ); } else if ( is_array( $classid ) ) { $classIDArray = $classid; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation ); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList ); $db_params = array(); $db_params['offset'] = $offset; $db_params['limit'] = $limit; $keywordNodeArray = array(); $lastKeyword = ''; $db = eZDB::instance(); //in SELECT clause below we will use a full keyword value //or just a part of ezkeyword.keyword matched to $alphabet respective to $includeDuplicates parameter. //In the case $includeDuplicates = ture we need only a part //of ezkeyword.keyword to be fetched in field to allow DISTINCT to remove rows with the same node id's $sqlKeyword = 'ezkeyword.keyword'; if ( !$includeDuplicates ) { $sqlKeyword = $db->subString('ezkeyword.keyword', 1, strlen( $alphabet ) ) . ' AS keyword '; } $alphabet = $db->escapeString( $alphabet ); $sortingInfo = array(); $sortingInfo['attributeFromSQL'] = ', ezcontentobject_attribute a1'; $sortingInfo['attributeWhereSQL'] = ''; $sqlTarget = $sqlKeyword.',ezcontentobject_tree.node_id'; if ( is_array( $sortBy ) && count ( $sortBy ) > 0 ) { switch ( $sortBy[0] ) { case 'keyword': case 'name': { $sortingString = ''; if ( $sortBy[0] == 'name' ) { $sortingString = 'ezcontentobject.name'; $sortingInfo['attributeTargetSQL'] = ', ' . $sortingString; } elseif ( $sortBy[0] == 'keyword' ) { if ( $includeDuplicates ) $sortingString = 'ezkeyword.keyword'; else $sortingString = 'keyword'; $sortingInfo['attributeTargetSQL'] = ''; } $sortOrder = true; // true is ascending if ( isset( $sortBy[1] ) ) $sortOrder = $sortBy[1]; $sortingOrder = $sortOrder ? ' ASC' : ' DESC'; $sortingInfo['sortingFields'] = $sortingString . $sortingOrder; } break; default: { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortBy ); if ( $sortBy[0] == 'attribute' ) { // if sort_by is 'attribute' we should add ezcontentobject_name to "FromSQL" and link to ezcontentobject $sortingInfo['attributeFromSQL'] .= ', ezcontentobject_name, ezcontentobject_attribute a1'; $sortingInfo['attributeWhereSQL'] .= ' ezcontentobject.id = ezcontentobject_name.contentobject_id AND'; $sqlTarget = 'DISTINCT ezcontentobject_tree.node_id, '.$sqlKeyword; } else // for unique declaration { $sortByArray = explode( ' ', $sortingInfo['sortingFields'] ); $sortingInfo['attributeTargetSQL'] .= ', ' . $sortByArray[0]; $sortingInfo['attributeFromSQL'] .= ', ezcontentobject_attribute a1'; } } break; } $sqlTarget .= $sortingInfo['attributeTargetSQL']; } else { $sortingInfo['sortingFields'] = 'ezkeyword.keyword ASC'; } $sortingInfo['attributeWhereSQL'] .= " a1.version=ezcontentobject.current_version AND a1.contentobject_id=ezcontentobject.id AND"; //Adding DISTINCT to avoid duplicates, //check if DISTINCT keyword was added before providing clauses for sorting. if ( !$includeDuplicates && substr( $sqlTarget, 0, 9) != 'DISTINCT ' ) { $sqlTarget = 'DISTINCT ' . $sqlTarget; } $sqlOwnerString = is_numeric( $owner ) ? "AND ezcontentobject.owner_id = '$owner'" : ''; $parentNodeIDString = is_numeric( $parentNodeID ) ? "AND ezcontentobject_tree.parent_node_id = '$parentNodeID'" : ''; $sqlClassIDString = ''; if ( is_array( $classIDArray ) and count( $classIDArray ) ) { $sqlClassIDString = 'AND ' . $db->generateSQLINStatement( $classIDArray, 'ezkeyword.class_id', false, false, 'int' ) . ' '; } // composing sql for matching tag word, it could be strict equiality or LIKE clause // dependent of $strictMatching parameter. $sqlMatching = "ezkeyword.keyword LIKE '$alphabet%'"; if ( $strictMatching ) { $sqlMatching = "ezkeyword.keyword = '$alphabet'"; } $query = "SELECT $sqlTarget FROM ezkeyword, ezkeyword_attribute_link,ezcontentobject_tree,ezcontentobject,ezcontentclass $sortingInfo[attributeFromSQL] $sqlPermissionChecking[from] WHERE $sortingInfo[attributeWhereSQL] $sqlMatching $showInvisibleNodesCond $sqlPermissionChecking[where] $sqlClassIDString $sqlOwnerString $parentNodeIDString AND ezcontentclass.version=0 AND ezcontentobject.status=".eZContentObject::STATUS_PUBLISHED." AND ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id AND ezcontentobject_tree.contentobject_id = ezcontentobject.id AND ezcontentclass.id = ezcontentobject.contentclass_id AND a1.id=ezkeyword_attribute_link.objectattribute_id AND ezkeyword_attribute_link.keyword_id = ezkeyword.id ORDER BY {$sortingInfo['sortingFields']}"; $keyWords = $db->arrayQuery( $query, $db_params ); $trans = eZCharTransform::instance(); foreach ( $keyWords as $keywordArray ) { $keyword = $keywordArray['keyword']; $nodeID = $keywordArray['node_id']; $nodeObject = eZContentObjectTreeNode::fetch( $nodeID ); if ( $nodeObject != null ) { $keywordLC = $trans->transformByGroup( $keyword, 'lowercase' ); if ( $lastKeyword == $keywordLC ) $keywordNodeArray[] = array( 'keyword' => '', 'link_object' => $nodeObject ); else $keywordNodeArray[] = array( 'keyword' => $keyword, 'link_object' => $nodeObject ); $lastKeyword = $keywordLC; } else { $lastKeyword = $trans->transformByGroup( $keyword, 'lowercase' ); } } return array( 'result' => $keywordNodeArray ); }
function validatePackageInformation($package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList) { $packageName = false; $packageSummary = false; $packageVersion = false; $packageDescription = false; $packageLicence = 'GPL'; $packageHost = false; $packagePackager = false; if ($http->hasPostVariable('PackageName')) { $packageName = trim($http->postVariable('PackageName')); } if ($http->hasPostVariable('PackageSummary')) { $packageSummary = $http->postVariable('PackageSummary'); } if ($http->hasPostVariable('PackageDescription')) { $packageDescription = $http->postVariable('PackageDescription'); } if ($http->hasPostVariable('PackageVersion')) { $packageVersion = trim($http->postVariable('PackageVersion')); } if ($http->hasPostVariable('PackageLicence')) { $packageLicence = $http->postVariable('PackageLicence'); } if ($http->hasPostVariable('PackageHost')) { $packageHost = $http->postVariable('PackageHost'); } if ($http->hasPostVariable('PackagePackager')) { $packagePackager = $http->postVariable('PackagePackager'); } $persistentData['name'] = $packageName; $persistentData['summary'] = $packageSummary; $persistentData['description'] = $packageDescription; $persistentData['version'] = $packageVersion; $persistentData['licence'] = $packageLicence; $persistentData['host'] = $packageHost; $persistentData['packager'] = $packagePackager; $result = true; if ($packageName == '') { $errorList[] = array('field' => ezpI18n::tr('kernel/package', 'Package name'), 'description' => ezpI18n::tr('kernel/package', 'Package name is missing')); $result = false; } else { $existingPackage = eZPackage::fetch($packageName, false, true); if ($existingPackage) { $errorList[] = array('field' => ezpI18n::tr('kernel/package', 'Package name'), 'description' => ezpI18n::tr('kernel/package', 'A package named %packagename already exists, please give another name', false, array('%packagename' => $packageName))); $result = false; } else { // Make sure the package name contains only valid characters $trans = eZCharTransform::instance(); $validPackageName = $trans->transformByGroup($packageName, 'identifier'); if (strcmp($validPackageName, $packageName) != 0) { $errorList[] = array('field' => ezpI18n::tr('kernel/package', 'Package name'), 'description' => ezpI18n::tr('kernel/package', "The package name %packagename is not valid, it can only contain characters in the range a-z, 0-9 and underscore.", false, array('%packagename' => $packageName))); $result = false; } } } if (!$packageSummary) { $errorList[] = array('field' => ezpI18n::tr('kernel/package', 'Summary'), 'description' => ezpI18n::tr('kernel/package', 'Summary is missing')); $result = false; } if (!preg_match("#^[0-9](\\.[0-9]([a-zA-Z]+[0-9]*)?)*\$#", $packageVersion)) { $errorList[] = array('field' => ezpI18n::tr('kernel/package', 'Version'), 'description' => ezpI18n::tr('kernel/package', 'The version must only contain numbers (optionally followed by text) and must be delimited by dots (.), e.g. 1.0, 3.4.0beta1')); $result = false; } return $result; }
/** * Checks if a package name is valid * * @param string $packageName the package name * @param string $transformedPackageName the package name, transformed to be valid * @return boolean true if the package name is valid, false if not */ static function isValidName($packageName, &$transformedPackageName = null) { $trans = eZCharTransform::instance(); $transformedPackageName = $trans->transformByGroup($packageName, 'identifier'); return $transformedPackageName === $packageName; }
function sortKey($contentObjectAttribute) { $trans = eZCharTransform::instance(); return $trans->transformByGroup($contentObjectAttribute->attribute('data_text'), 'lowercase'); }
function sortKey($contentObjectAttribute) { $trans = eZCharTransform::instance(); $content = $contentObjectAttribute->content(); return $trans->transformByGroup($content['value'], 'lowercase'); }
function sortKey($contentObjectAttribute) { //include_once( 'lib/ezpI18n::tr/classes/ezchartransform.php' ); $trans = eZCharTransform::instance(); return $trans->transformByGroup($contentObjectAttribute->attribute('data_text'), 'lowercase'); }
function normalizeText($text, $isMetaData = false) { $trans = eZCharTransform::instance(); $text = $trans->transformByGroup($text, 'search'); // Remove quotes and asterix when not handling search text by end-user if ($isMetaData) { $text = str_replace(array("\"", "*"), array(" ", " "), $text); } return $text; }
<?php /** * File containing the section identifier upgrade script. * * @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version 2013.11 * @package update */ require 'autoload.php'; $script = eZScript::instance(array('description' => 'eZ Publish section identifier update script. ' . 'This script will update existing sections with missing identifiers.', 'use-session' => false, 'use-modules' => false, 'use-extensions' => true)); $script->startup(); $options = $script->getOptions('', '', array('-q' => 'Quiet mode')); $script->initialize(); $cli = eZCLI::instance(); $trans = eZCharTransform::instance(); // Fetch 50 items per iteration $limit = 50; $offset = 0; do { // Fetch items with empty identifier $rows = eZSection::fetchFilteredList(null, $offset, $limit); if (!$rows) { break; } foreach ($rows as $row) { if ($row->attribute('identifier') == '') { // Create a new section identifier with NAME_ID pattern $name = $row->attribute('name'); $identifier = $trans->transformByGroup($name, 'identifier') . '_' . $row->attribute('id'); // Set new section identifier and store it
function normalizeImageName($imageName) { // Initialize transformation system $trans = eZCharTransform::instance(); $imageName = eZURLAliasML::convertToAlias($imageName); return $imageName; }
function normalizeText($text, $isMetaData = false) { $text = self::removeDuplicatedSpaces(trim(self::removeAllQuotes(eZCharTransform::instance()->transformByGroup($text, 'search')))); // Remove quotes and asterix when not handling search text by end-user if ($isMetaData) { $text = str_replace("*", " ", $text); } return $text; }
function batchInitializeObjectAttributeData($classAttribute) { $default = $classAttribute->attribute('data_text1'); if ($default !== '' && $default !== NULL) { $db = eZDB::instance(); $default = "'" . $db->escapeString($default) . "'"; $trans = eZCharTransform::instance(); $lowerCasedDefault = $trans->transformByGroup($default, 'lowercase'); return array('data_text' => $default, 'sort_key_string' => $lowerCasedDefault); } return array(); }
/** * Generates an identifier from provided name * * @param string $name * @param array $identifierArray * * @return string */ protected function generateIdentifier($name, $identifierArray = array()) { if (empty($name)) { return ''; } $identifier = $name; $generatedIdentifier = eZCharTransform::instance()->transformByGroup($identifier, 'identifier'); // We have $generatedIdentifier now, check for existence if (is_array($identifierArray) && !empty($identifierArray) && in_array($generatedIdentifier, $identifierArray)) { $highestNumber = 0; foreach ($identifierArray as $identifierItem) { if (preg_match('/^' . $generatedIdentifier . '__(\\d+)$/', $identifierItem, $matchArray)) { if ($matchArray[1] > $highestNumber) { $highestNumber = $matchArray[1]; } } } $generatedIdentifier .= "__" . ++$highestNumber; } return $generatedIdentifier; }
/** * I link da riportare nella parte bassa del footer, vengono inseriti in una * matrice chiamata footer_link_bottom nella classe Homepage * * @return array */ public static function getFooterBottomLinks() { $data = array(); $homePage = FooterTool::fetchRootNode(); if ($homePage instanceof eZContentObjectTreeNode) { $homeObject = $homePage->attribute('object'); if ($homeObject instanceof eZContentObject) { $dataMap = $homeObject->attribute('data_map'); if (isset($dataMap['footer_link_bottom']) && $dataMap['footer_link_bottom'] instanceof eZContentObjectAttribute && $dataMap['footer_link_bottom']->attribute('data_type_string') == 'ezmatrix' && $dataMap['footer_link_bottom']->attribute('has_content')) { $trans = eZCharTransform::instance(); $matrix = $dataMap['footer_link_bottom']->attribute('content')->attribute('matrix'); foreach ($matrix['rows']['sequential'] as $row) { $columns = $row['columns']; $name = $columns[0]; $identifier = $trans->transformByGroup($name, 'identifier'); if (!empty($columns[1])) { $data[$identifier] = $columns[1]; } } } } } return $data; }
function sortKey( $contentObjectAttribute ) { $trans = eZCharTransform::instance(); $content = $contentObjectAttribute->content(); if ( is_array( $content['value'] ) ) { $imploded = ''; foreach ( $content['value'] as $country ) { $countryName = $country['Name']; if ( $imploded == '' ) $imploded = $countryName; else $imploded .= ',' . $countryName; } $content['value'] = $imploded; } return $trans->transformByGroup( $content['value'], 'lowercase' ); }
public static function convertToAliasCompat($urlElement, $defaultValue = false) { $trans = eZCharTransform::instance(); $urlElement = $trans->transformByGroup($urlElement, "urlalias_compat"); if (strlen($urlElement) == 0) { if ($defaultValue === false) { $urlElement = '_1'; } else { $urlElement = $defaultValue; $urlElement = $trans->transformByGroup($urlElement, "urlalias_compat"); } } return $urlElement; }
public static function fetchKeyword($alphabet, $classid, $offset, $limit, $owner = false, $sortBy = array(), $parentNodeID = false, $includeDuplicates = true, $strictMatching = false, $depth = 1) { $classIDArray = array(); if (is_numeric($classid)) { $classIDArray = array($classid); } else { if (is_array($classid)) { $classIDArray = $classid; } } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $db_params = array(); $db_params['offset'] = $offset; $db_params['limit'] = $limit; $keywordNodeArray = array(); $lastKeyword = ''; $db = eZDB::instance(); //in SELECT clause below we will use a full keyword value //or just a part of ezkeyword.keyword matched to $alphabet respective to $includeDuplicates parameter. //In the case $includeDuplicates = ture we need only a part //of ezkeyword.keyword to be fetched in field to allow DISTINCT to remove rows with the same node id's $sqlKeyword = 'ezkeyword.keyword'; if (!$includeDuplicates) { $sqlKeyword = $db->subString('ezkeyword.keyword', 1, strlen($alphabet)) . ' AS keyword '; } $alphabet = $db->escapeString($alphabet); $sortingInfo = array(); $sortingInfo['attributeFromSQL'] = ''; $sqlTarget = $sqlKeyword . ',ezcontentobject_tree.node_id'; if (is_array($sortBy) && count($sortBy) > 0) { switch ($sortBy[0]) { case 'keyword': case 'name': $sortingString = ''; if ($sortBy[0] == 'name') { $sortingString = 'ezcontentobject.name'; } elseif ($sortBy[0] == 'keyword') { if ($includeDuplicates) { $sortingString = 'ezkeyword.keyword'; } else { $sortingString = 'keyword'; } } $sortOrder = true; // true is ascending if (isset($sortBy[1])) { $sortOrder = $sortBy[1]; } $sortingOrder = $sortOrder ? ' ASC' : ' DESC'; $sortingInfo['sortingFields'] = $sortingString . $sortingOrder; break; default: $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($sortBy); } // Fixing the attributeTargetSQL switch ($sortBy[0]) { case 'keyword': $sortingInfo['attributeTargetSQL'] = ''; break; case 'name': $sortingInfo['attributeTargetSQL'] = ', ezcontentobject.name'; break; case 'attribute': case 'class_name': break; default: $sortingInfo['attributeTargetSQL'] .= ', ' . strtok($sortingInfo["sortingFields"], " "); } $sqlTarget .= $sortingInfo['attributeTargetSQL']; } else { $sortingInfo['sortingFields'] = 'ezkeyword.keyword ASC'; } //Adding DISTINCT to avoid duplicates, //check if DISTINCT keyword was added before providing clauses for sorting. if (!$includeDuplicates && substr($sqlTarget, 0, 9) != 'DISTINCT ') { $sqlTarget = 'DISTINCT ' . $sqlTarget; } $sqlOwnerString = is_numeric($owner) ? "AND ezcontentobject.owner_id = '{$owner}'" : ''; $parentNodeIDString = ''; if (is_numeric($parentNodeID)) { $notEqParentString = ''; // If the node(s) doesn't exist we return null. if (!eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($parentNodeIDString, $notEqParentString, $parentNodeID, $depth)) { return null; } } $sqlClassIDString = ''; if (is_array($classIDArray) and count($classIDArray)) { $sqlClassIDString = 'AND ' . $db->generateSQLINStatement($classIDArray, 'ezkeyword.class_id', false, false, 'int') . ' '; } // composing sql for matching tag word, it could be strict equiality or LIKE clause // dependent of $strictMatching parameter. $sqlMatching = "ezkeyword.keyword LIKE '{$alphabet}%'"; if ($strictMatching) { $sqlMatching = "ezkeyword.keyword = '{$alphabet}'"; } $query = "SELECT {$sqlTarget}\n FROM ezkeyword\n INNER JOIN ezkeyword_attribute_link ON (ezkeyword_attribute_link.keyword_id = ezkeyword.id)\n INNER JOIN ezcontentobject_attribute ON (ezcontentobject_attribute.id = ezkeyword_attribute_link.objectattribute_id)\n INNER JOIN ezcontentobject ON (ezcontentobject_attribute.version = ezcontentobject.current_version AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id)\n INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n {$sortingInfo['attributeFromSQL']}\n {$sqlPermissionChecking['from']}\n WHERE\n {$parentNodeIDString}\n {$sqlMatching}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$sqlClassIDString}\n {$sqlOwnerString}\n AND ezcontentclass.version = 0\n AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n ORDER BY {$sortingInfo['sortingFields']}"; $keyWords = $db->arrayQuery($query, $db_params); $trans = eZCharTransform::instance(); foreach ($keyWords as $keywordArray) { $keyword = $keywordArray['keyword']; $nodeID = $keywordArray['node_id']; $nodeObject = eZContentObjectTreeNode::fetch($nodeID); if ($nodeObject != null) { $keywordLC = $trans->transformByGroup($keyword, 'lowercase'); if ($lastKeyword == $keywordLC) { $keywordNodeArray[] = array('keyword' => '', 'link_object' => $nodeObject); } else { $keywordNodeArray[] = array('keyword' => $keyword, 'link_object' => $nodeObject); } $lastKeyword = $keywordLC; } else { $lastKeyword = $trans->transformByGroup($keyword, 'lowercase'); } } return array('result' => $keywordNodeArray); }
/** * Returns the sort key of the attribute * * @param eZContentObjectAttribute $contentObjectAttribute * * @return string */ function sortKey($contentObjectAttribute) { $trans = eZCharTransform::instance(); return $trans->transformByGroup(trim($contentObjectAttribute->attribute(self::OIB_FIELD)), "lowercase"); }
/** * Checks if all data is valid and can be stored to the database. * * @param array &$messages * @return boolean true when valid, false when not valid * @see eZContentObjectState::store() */ public function isValid(&$messages = array()) { $isValid = true; // missing identifier if (!isset($this->Identifier) || $this->Identifier == '') { $messages[] = ezpI18n::tr('kernel/state/edit', 'Identifier: input required'); $isValid = false; } else { // make sure the identifier contains only valid characters $trans = eZCharTransform::instance(); $validIdentifier = $trans->transformByGroup($this->Identifier, 'identifier'); if (strcmp($validIdentifier, $this->Identifier) != 0) { // invalid identifier $messages[] = ezpI18n::tr('kernel/state/edit', 'Identifier: invalid, it can only consist of characters in the range a-z, 0-9 and underscore.'); $isValid = false; } else { if (strlen($this->Identifier) > self::MAX_IDENTIFIER_LENGTH) { $messages[] = ezpI18n::tr('kernel/state/edit', 'Identifier: invalid, maximum %max characters allowed.', null, array('%max' => self::MAX_IDENTIFIER_LENGTH)); $isValid = false; } else { if (isset($this->GroupID)) { // check for existing identifier $existingState = self::fetchByIdentifier($this->Identifier, $this->GroupID); if ($existingState && (!isset($this->ID) || $existingState->attribute('id') !== $this->ID)) { $messages[] = ezpI18n::tr('kernel/state/edit', 'Identifier: a content object state group with this identifier already exists, please give another identifier'); $isValid = false; } } } } } $translationsWithData = 0; foreach ($this->AllTranslations as $translation) { if ($translation->hasData()) { $translationsWithData++; if (!$translation->isValid($messages)) { $isValid = false; } } else { if (($translation->attribute('language_id') & ~1) == $this->DefaultLanguageID) { // if name nor description are set but translation is specified as main language $isValid = false; $messages[] = ezpI18n::tr('kernel/state/edit', '%language_name: this language is the default but neither name or description were provided for this language', null, array('%language_name' => $translation->attribute('language')->attribute('locale_object')->attribute('intl_language_name'))); } } } if ($translationsWithData == 0) { $isValid = false; $messages[] = ezpI18n::tr('kernel/state/edit', 'Translations: you need to add at least one localization'); } else { if (empty($this->DefaultLanguageID) && $translationsWithData > 1) { $isValid = false; $messages[] = ezpI18n::tr('kernel/state/edit', 'Translations: there are multiple localizations but you did not specify which is the default one'); } } return $isValid; }
function fetchClassAttributeHTTPInput($http, $base, $classAttribute) { // 'default name' is never used => just a stub // $defaultValueName = $base . self::DEFAULT_NAME_VARIABLE . $classAttribute->attribute( 'id' ); $defaultValueName = ''; $defaultNumColumnsName = $base . self::NUM_COLUMNS_VARIABLE . $classAttribute->attribute('id'); $defaultNumRowsName = $base . self::NUM_ROWS_VARIABLE . $classAttribute->attribute('id'); $dataFetched = false; // 'default name' is never used => just a stub /* if ( $http->hasPostVariable( $defaultValueName ) ) { $defaultValueValue = $http->postVariable( $defaultValueName ); if ( $defaultValueValue == '' ) { $defaultValueValue = ''; } $classAttribute->setAttribute( 'data_text1', $defaultValueValue ); $dataFetched = true; } */ if ($http->hasPostVariable($defaultNumRowsName)) { $defaultNumRowsValue = $http->postVariable($defaultNumRowsName); if ($defaultNumRowsValue == '') { $defaultNumRowsValue = '1'; } $classAttribute->setAttribute('data_int1', $defaultNumRowsValue); $dataFetched = true; } $columnNameVariable = $base . '_data_ezmatrix_column_name_' . $classAttribute->attribute('id'); $columnIDVariable = $base . '_data_ezmatrix_column_id_' . $classAttribute->attribute('id'); if ($http->hasPostVariable($columnNameVariable) && $http->hasPostVariable($columnIDVariable)) { $columns = array(); $i = 0; $columnNameList = $http->postVariable($columnNameVariable); $columnIDList = $http->postVariable($columnIDVariable); $matrixDefinition = $classAttribute->attribute('content'); $columnNames = $matrixDefinition->attribute('columns'); foreach ($columnNames as $columnName) { $columnID = ''; $name = ''; $index = $columnName['index']; // after adding a new column $columnIDList and $columnNameList doesn't contain values for new column. // if so just add column with empty 'name' and 'columnID'. if (isset($columnIDList[$index]) && isset($columnNameList[$index])) { $columnID = $columnIDList[$index]; $name = $columnNameList[$index]; if (strlen($columnID) == 0) { $columnID = $name; // Initialize transformation system $trans = eZCharTransform::instance(); $columnID = $trans->transformByGroup($columnID, 'identifier'); } } $columns[] = array('name' => $name, 'identifier' => $columnID, 'index' => $i); $i++; } $matrixDefinition->ColumnNames = $columns; $classAttribute->setContent($matrixDefinition); $classAttribute->setAttribute('data_text5', $matrixDefinition->xmlString()); $dataFetched = true; } if ($dataFetched) { return true; } return false; }
function repositoryByVendor($vendor) { // it's copy/paste from eZPackage $trans = eZCharTransform::instance(); $repository = $trans->transformByGroup($vendor, 'urlalias'); return $repository; }
/** * Returns a key to sort attributes. * * @param mixed $contentObjectAttribute Class eZContentObjectAttribute. * * @return string */ public function sortKey($contentObjectAttribute) { return eZCharTransform::instance()->transformByGroup($contentObjectAttribute->attribute('id'), 'lowercase'); }