/**
  * Regression test for issue #15155
  *
  * @link http://issues.ez.no/15155
  */
 public function testIssue15155()
 {
     // figure out the max versions for images
     $contentINI = eZINI::instance('content.ini');
     $versionlimit = $contentINI->variable('VersionManagement', 'DefaultVersionHistoryLimit');
     $limitList = eZContentClass::classIDByIdentifier($contentINI->variable('VersionManagement', 'VersionHistoryClass'));
     $classID = 5;
     // image class, can remain hardcoded, I guess
     foreach ($limitList as $key => $value) {
         if ($classID == $key) {
             $versionlimit = $value;
         }
     }
     if ($versionlimit < 2) {
         $versionlimit = 2;
     }
     $baseImagePath = dirname(__FILE__) . '/ezimagealiashandler_regression_issue15155.png';
     $parts = pathinfo($baseImagePath);
     $imagePattern = $parts['dirname'] . DIRECTORY_SEPARATOR . $parts['filename'] . '_%s_%d.' . $parts['extension'];
     $toDelete = array();
     // Create version 1
     $imagePath = sprintf($imagePattern, md5(1), 1);
     copy($baseImagePath, $imagePath);
     $toDelete[] = $imagePath;
     $image = new ezpObject('image', 43);
     $image->name = __FUNCTION__;
     $image->image = $imagePath;
     $image->publish();
     $image->refresh();
     $contentObjectID = $image->object->attribute('id');
     $dataMap = eZContentObject::fetch($contentObjectID)->dataMap();
     $originalAliases[1] = $image->image->imageAlias('original');
     for ($i = 2; $i <= 20; $i++) {
         // Create a new image file
         $imagePath = sprintf($imagePattern, md5($i), $i);
         copy($baseImagePath, $imagePath);
         $toDelete[] = $imagePath;
         $newVersion = $image->createNewVersion();
         $dataMap = $newVersion->dataMap();
         $dataMap['image']->fromString($imagePath);
         ezpObject::publishContentObject($image->object, $newVersion);
         $image->refresh();
         $originalAliases[$i] = $image->image->imageAlias('original');
         if ($i > $versionlimit) {
             $removeVersion = $i - $versionlimit;
             $aliasPath = $originalAliases[$removeVersion]['url'];
             $this->assertFalse(file_exists($aliasPath), "Alias {$aliasPath} for version {$removeVersion} should have been removed");
         }
     }
     array_map('unlink', $toDelete);
     $image->purge();
 }
Пример #2
0
    function modify( $tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        $parentNodeID = $namedParameters['parent_node_id'];

        switch ( $operatorName )
        {
            case 'ezkeywordlist':
            {
                include_once( 'lib/ezdb/classes/ezdb.php' );
                $db = eZDB::instance();
                
                if( $parentNodeID )
                {
                    $node = eZContentObjectTreeNode::fetch( $parentNodeID );
                    if ( $node )
                        $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute( 'path_string' ) . "%'";
                    $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int)$parentNodeID;
                }

                $limitation = false;
                $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( eZContentObjectTreeNode::getLimitationList( $limitation ) );

                // eZContentObjectTreeNode::classIDByIdentifier() might need to be used for eZ Publish < 4.1
                $classIDs = eZContentClass::classIDByIdentifier( $namedParameters['class_identifier'] );

                $operatorValue = $db->arrayQuery(
                    "SELECT DISTINCT ezkeyword.keyword
                     FROM ezkeyword
                          JOIN ezkeyword_attribute_link ON ezkeyword.id = ezkeyword_attribute_link.keyword_id
                          JOIN ezcontentobject_attribute ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id
                          JOIN ezcontentobject ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id
                          JOIN ezcontentobject_name ON ezcontentobject.id = ezcontentobject_name.contentobject_id
                          JOIN ezcontentobject_tree ON ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version
                          $sqlPermissionChecking[from]
                     WHERE " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' ) . "
                         AND " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) .
                         ( empty( $classIDs ) ? '' : ( ' AND ' . $db->generateSQLINStatement( $classIDs, 'ezkeyword.class_id' ) ) ) . "
                         $pathString
                         $parentNodeIDSQL " .
                         ( $namedParameters['depth'] > 0 ? ("AND ezcontentobject_tree.depth=" . (int)$namedParameters['depth']) : '' ) . "
                         " . eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ) . "
                         $sqlPermissionChecking[where]
                     ORDER BY ezkeyword.keyword ASC" );
            } break;
        }
    }
 /**
  * Setup an environment for this test.
  *
  */
 public function setUp()
 {
     parent::setUp();
     // Create a class 1
     $class1 = new ezpClass('Test 1', 'test_1', '<name>');
     $class1->add('Name', 'name');
     $class1->add('Relations', 'relations', 'ezobjectrelationlist');
     $class1->store();
     // Generate class*.php cache files;
     eZContentClass::classIDByIdentifier('test_1');
     // Wait 3 seconds to get the proper timestamps for test
     sleep(3);
     // Create a class 2
     // It marks class-identifier-cache as expired because a new class has been created
     $class2 = new ezpClass('Test 2', 'test_2', '<name>');
     $class2->add('Name', 'name');
     $class2->add('Relations', 'relations', 'ezobjectrelationlist');
     $class2->store();
 }
Пример #4
0
 /**
  * Computes the version history limit for a content class
  *
  * @param mixed $class
  *        Content class ID, content class identifier or content class object
  * @return int
  * @since 4.2
  */
 public static function versionHistoryLimit($class)
 {
     // default version limit
     $contentINI = eZINI::instance('content.ini');
     $versionLimit = $contentINI->variable('VersionManagement', 'DefaultVersionHistoryLimit');
     // version limit can't be < 2
     if ($versionLimit < 2) {
         eZDebug::writeWarning("Global version history limit must be equal to or higher than 2", __METHOD__);
         $versionLimit = 2;
     }
     // we need to take $class down to a class ID
     if (is_numeric($class)) {
         if (!eZContentClass::classIdentifierByID($class)) {
             eZDebug::writeWarning("class integer parameter doesn't match any content class ID", __METHOD__);
             return $versionLimit;
         }
         $classID = (int) $class;
     } elseif (is_string($class)) {
         $classID = eZContentClass::classIDByIdentifier($class);
         if (!$classID) {
             eZDebug::writeWarning("class string parameter doesn't match any content class identifier", __METHOD__);
             return $versionLimit;
         }
     } elseif (is_object($class)) {
         if (!$class instanceof eZContentClass) {
             eZDebug::writeWarning("class object parameter is not an eZContentClass", __METHOD__);
             return $versionLimit;
         } else {
             $classID = $class->attribute('id');
         }
     }
     $classLimitSetting = $contentINI->variable('VersionManagement', 'VersionHistoryClass');
     $classArray = array_keys($classLimitSetting);
     $limitsArray = array_values($classLimitSetting);
     $classArray = eZContentClass::classIDByIdentifier($classArray);
     foreach ($classArray as $index => $id) {
         if ($id == $classID) {
             $limit = $limitsArray[$index];
             // version limit can't be < 2
             if ($limit < 2) {
                 $classIdentifier = eZContentClass::classIdentifierByID($classID);
                 eZDebug::writeWarning("Version history limit for class {$classIdentifier} must be equal to or higher than 2", __METHOD__);
                 $limit = 2;
             }
             $versionLimit = $limit;
         }
     }
     return $versionLimit;
 }
Пример #5
0
 /**
  * Returns search results based on given post params
  *
  * @param mixed $args Only used if post parameter is not set
  *              0 => SearchStr
  *              1 => SearchOffset
  *              2 => SearchLimit (10 by default, max 50)
  * @return array
  */
 public static function search($args)
 {
     $http = eZHTTPTool::instance();
     if ($http->hasPostVariable('SearchStr')) {
         $searchStr = trim($http->postVariable('SearchStr'));
     } else {
         if (isset($args[0])) {
             $searchStr = trim($args[0]);
         }
     }
     if ($http->hasPostVariable('SearchOffset')) {
         $searchOffset = (int) $http->postVariable('SearchOffset');
     } else {
         if (isset($args[1])) {
             $searchOffset = (int) $args[1];
         } else {
             $searchOffset = 0;
         }
     }
     if ($http->hasPostVariable('SearchLimit')) {
         $searchLimit = (int) $http->postVariable('SearchLimit');
     } else {
         if (isset($args[2])) {
             $searchLimit = (int) $args[2];
         } else {
             $searchLimit = 10;
         }
     }
     // Do not allow to search for more then x items at a time
     $ini = eZINI::instance();
     $maximumSearchLimit = (int) $ini->variable('SearchSettings', 'MaximumSearchLimit');
     if ($searchLimit > $maximumSearchLimit) {
         $searchLimit = $maximumSearchLimit;
     }
     // Prepare node encoding parameters
     $encodeParams = array();
     if (self::hasPostValue($http, 'EncodingLoadImages')) {
         $encodeParams['loadImages'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchChildrenCount')) {
         $encodeParams['fetchChildrenCount'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchSection')) {
         $encodeParams['fetchSection'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFormatDate')) {
         $encodeParams['formatDate'] = $http->postVariable('EncodingFormatDate');
     }
     // Prepare search parameters
     $params = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SortArray' => array('published', 0), 'SortBy' => array('published' => 'desc'));
     if (self::hasPostValue($http, 'SearchContentClassAttributeID')) {
         $params['SearchContentClassAttributeID'] = self::makePostArray($http, 'SearchContentClassAttributeID');
     } else {
         if (self::hasPostValue($http, 'SearchContentClassID')) {
             $params['SearchContentClassID'] = self::makePostArray($http, 'SearchContentClassID');
         } else {
             if (self::hasPostValue($http, 'SearchContentClassIdentifier')) {
                 $params['SearchContentClassID'] = eZContentClass::classIDByIdentifier(self::makePostArray($http, 'SearchContentClassIdentifier'));
             }
         }
     }
     if (self::hasPostValue($http, 'SearchSubTreeArray')) {
         $params['SearchSubTreeArray'] = self::makePostArray($http, 'SearchSubTreeArray');
     }
     if (self::hasPostValue($http, 'SearchSectionID')) {
         $params['SearchSectionID'] = self::makePostArray($http, 'SearchSectionID');
     }
     if (self::hasPostValue($http, 'SearchDate')) {
         $params['SearchDate'] = (int) $http->postVariable('SearchDate');
     } else {
         if (self::hasPostValue($http, 'SearchTimestamp')) {
             $params['SearchTimestamp'] = self::makePostArray($http, 'SearchTimestamp');
             if (!isset($params['SearchTimestamp'][1])) {
                 $params['SearchTimestamp'] = $params['SearchTimestamp'][0];
             }
         }
     }
     if (self::hasPostValue($http, 'EnableSpellCheck') || self::hasPostValue($http, 'enable-spellcheck', '0')) {
         $params['SpellCheck'] = array(true);
     }
     if (self::hasPostValue($http, 'GetFacets') || self::hasPostValue($http, 'show-facets', '0')) {
         $params['facet'] = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array());
     }
     $result = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SearchResultCount' => 0, 'SearchCount' => 0, 'SearchResult' => array(), 'SearchString' => $searchStr, 'SearchExtras' => array());
     // Possibility to keep track of callback reference for use in js callback function
     if ($http->hasPostVariable('CallbackID')) {
         $result['CallbackID'] = $http->postVariable('CallbackID');
     }
     // Only search if there is something to search for
     if ($searchStr) {
         $searchList = eZSearch::search($searchStr, $params);
         $result['SearchResultCount'] = $searchList['SearchResult'] !== false ? count($searchList['SearchResult']) : 0;
         $result['SearchCount'] = (int) $searchList['SearchCount'];
         $result['SearchResult'] = ezjscAjaxContent::nodeEncode($searchList['SearchResult'], $encodeParams, false);
         // ezfind stuff
         if (isset($searchList['SearchExtras']) && $searchList['SearchExtras'] instanceof ezfSearchResultInfo) {
             if (isset($params['SpellCheck'])) {
                 $result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck');
             }
             if (isset($params['facet'])) {
                 $facetInfo = array();
                 $retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields');
                 $baseSearchUrl = "/content/search/";
                 eZURI::transformURI($baseSearchUrl, false, 'full');
                 foreach ($params['facet'] as $key => $defaultFacet) {
                     $facetData = $retrievedFacets[$key];
                     $facetInfo[$key] = array('name' => $defaultFacet['name'], 'list' => array());
                     if ($facetData !== null) {
                         foreach ($facetData['nameList'] as $key2 => $facetName) {
                             if ($key2 != '') {
                                 $tmp = array('value' => $facetName);
                                 $tmp['url'] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName;
                                 $tmp['count'] = $facetData['countList'][$key2];
                                 $facetInfo[$key]['list'][] = $tmp;
                             }
                         }
                     }
                 }
                 $result['SearchExtras']['facets'] = $facetInfo;
             }
         }
         //$searchList['SearchExtras'] instanceof ezfSearchResultInfo
     }
     // $searchStr
     return $result;
 }
 static function subTreeCountByNodeID($params = array(), $nodeID)
 {
     if (!is_numeric($nodeID) and !is_array($nodeID)) {
         return null;
     }
     $language = isset($params['Language']) ? $params['Language'] : false;
     if ($language) {
         if (!is_array($language)) {
             $language = array($language);
         }
         eZContentLanguage::setPrioritizedLanguages($language);
     }
     $depth = isset($params['Depth']) && is_numeric($params['Depth']) ? $params['Depth'] : false;
     $depthOperator = isset($params['DepthOperator']) ? $params['DepthOperator'] : false;
     $pathStringCond = '';
     $notEqParentString = '';
     // If the node(s) doesn't exist we return null.
     if (!eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator)) {
         return null;
     }
     $db = eZDB::instance();
     $ini = eZINI::instance();
     // Check for class filtering
     $classCondition = '';
     if (isset($params['ClassFilterType']) and isset($params['ClassFilterArray']) and ($params['ClassFilterType'] == 'include' or $params['ClassFilterType'] == 'exclude') and count($params['ClassFilterArray']) > 0) {
         $classCondition = '  ';
         $i = 0;
         $classCount = count($params['ClassFilterArray']);
         $classIDArray = array();
         foreach ($params['ClassFilterArray'] as $classID) {
             $originalClassID = $classID;
             // Check if classes are recerenced by identifier
             if (is_string($classID) && !is_numeric($classID)) {
                 $classID = eZContentClass::classIDByIdentifier($classID);
             }
             if (is_numeric($classID)) {
                 $classIDArray[] = $classID;
             } else {
                 eZDebugSetting::writeWarning('kernel-content-class', "Invalid class identifier in subTree() classfilterarray, classID : " . $originalClassID);
             }
         }
         if (count($classIDArray) > 0) {
             $classCondition .= " ezcontentobject.contentclass_id ";
             if ($params['ClassFilterType'] == 'include') {
                 $classCondition .= " IN ";
             } else {
                 $classCondition .= " NOT IN ";
             }
             $classIDString = implode(', ', $classIDArray);
             $classCondition .= ' ( ' . $classIDString . ' ) AND';
         }
     }
     // Main node check
     $mainNodeOnlyCond = '';
     if (isset($params['MainNodeOnly']) && $params['MainNodeOnly'] === true) {
         $mainNodeOnlyCond = 'ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id AND';
     }
     $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject');
     $objectNameLanguageFilter = eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject');
     if ($language) {
         eZContentLanguage::clearPrioritizedLanguages();
     }
     $objectNameFilter = isset($params['ObjectNameFilter']) ? $params['ObjectNameFilter'] : false;
     $attributeFilterParam = isset($params['AttributeFilter']) ? $params['AttributeFilter'] : false;
     $sortingInfo = array('sortCount' => 0, 'attributeJoinCount' => 0);
     $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings($attributeFilterParam, $sortingInfo, $language);
     if ($attributeFilter === false) {
         return null;
     }
     $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString($objectNameFilter);
     $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['ExtendedAttributeFilter']);
     // Determine whether we should show invisible nodes.
     $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false;
     $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
     $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false;
     $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
     $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
     $query = "SELECT\n                        count( DISTINCT ezcontentobject_tree.node_id ) as count\n                  FROM\n                       ezcontentobject_tree\n                       INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n                       INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_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                       {$attributeFilter['from']}\n                       {$extendedAttributeFilter['tables']}\n                       {$sqlPermissionChecking['from']}\n                  WHERE {$pathStringCond}\n                        {$extendedAttributeFilter['joins']}\n                        {$mainNodeOnlyCond}\n                        {$classCondition}\n                        {$attributeFilter['where']}\n                        ezcontentclass.version=0 AND\n                        {$notEqParentString}\n                        {$objectNameLanguageFilter}\n                        {$showInvisibleNodesCond}\n                        {$sqlPermissionChecking['where']}\n                        {$objectNameFilterSQL}\n                        {$languageFilter} ";
     $server = count($sqlPermissionChecking['temp_tables']) > 0 ? eZDBInterface::SERVER_SLAVE : false;
     $nodeListArray = $db->arrayQuery($query, array(), $server);
     // cleanup temp tables
     $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
     return $nodeListArray[0]['count'];
 }
 /**
  * Unit test for eZContentClass::classIDByIdentifier()
  * @dataProvider providerForTestClassIDByIdentifier
  */
 public function testClassIDByIdentifier($sourceArray, $expectedArray)
 {
     $transformedClassArray = eZContentClass::classIDByIdentifier($sourceArray);
     $this->assertEquals($expectedArray, $transformedClassArray);
 }
Пример #8
0
 public function run($argv, $additional)
 {
     $command = @$argv[2];
     $param1 = @$argv[3];
     $param2 = @$argv[4];
     if (!in_array($command, $this->availableCommands)) {
         throw new Exception("Command '" . $command . "' not recognized.");
     }
     $eepCache = eepCache::getInstance();
     switch ($command) {
         case "help":
             echo "\nAvailable commands:: " . implode(", ", $this->availableCommands) . "\n";
             echo "\n" . $this->help . "\n";
             break;
         case self::contentclass_listattributes:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             AttributeFunctions::listAttributes($classIdentifier);
             break;
         case self::contentclass_deleteclass:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             $this->deleteClass($classIdentifier);
             break;
         case self::contentclass_fetchallinstances:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             $this->fetchallinstances($classIdentifier, $additional);
             break;
         case self::contentclass_appendtogroup:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             if ($param2) {
                 $groupIdentifier = $param2;
             } else {
                 $groupIdentifier = null;
             }
             $this->appendToGroup($classIdentifier, $groupIdentifier);
             break;
         case self::contentclass_removefromgroup:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             if ($param2) {
                 $groupIdentifier = $param2;
             } else {
                 $groupIdentifier = null;
             }
             $this->removeFromGroup($classIdentifier, $groupIdentifier);
             break;
             // eep createclass <Display name> <Content class group identifier>
         // eep createclass <Display name> <Content class group identifier>
         case self::contentclass_createclass:
             $displayName = $param1;
             // convert the display name to lowercase and solo underscores
             $classIdentifier = strtolower(trim($displayName));
             $classIdentifier = preg_replace("/[^a-z0-9]/", "_", $classIdentifier);
             $classIdentifier = preg_replace("/_[_]+/", "_", $classIdentifier);
             if (0 == strlen($classIdentifier)) {
                 throw new Exception("Empty content class identifier");
             }
             $classId = eZContentClass::classIDByIdentifier($classIdentifier);
             if ($classId) {
                 throw new Exception("This content class identifier is already used: '" . $classIdentifier . "'");
             }
             $groupIdentifier = $param2;
             $groupObject = eZContentClassGroup::fetchByName($groupIdentifier);
             if (!is_object($groupObject)) {
                 throw new Exception("Failed to locate the content class group '" . $groupIdentifier . "'");
             }
             $groupId = $groupObject->ID;
             $this->createClass($displayName, $classIdentifier, $groupIdentifier, $groupId);
             echo "created " . $classIdentifier . " ok\n";
             break;
             // eep contentclass setclassobjectidentifier <class identifier> <object naming string or pattern>
         // eep contentclass setclassobjectidentifier <class identifier> <object naming string or pattern>
         case self::contentclass_setclassobjectidentifier:
             $classIdentifier = $param1;
             $classId = eZContentClass::classIDByIdentifier($classIdentifier);
             $contentClass = eZContentClass::fetch($classId);
             if (!is_object($contentClass)) {
                 throw new Exception("Failed to instantiate content class. [" . $classIdentifier . "]");
             }
             $contentClass->setAttribute('contentobject_name', $param2);
             $contentClass->store();
             break;
         case self::contentclass_setiscontainer:
             $classIdentifier = $param1;
             $classId = eZContentClass::classIDByIdentifier($classIdentifier);
             $contentClass = eZContentClass::fetch($classId);
             if (!is_object($contentClass)) {
                 throw new Exception("Failed to instantiate content class. [" . $classIdentifier . "]");
             }
             $newSetting = 0;
             if (0 != $param2) {
                 $newSetting = 1;
             }
             $contentClass->setAttribute('is_container', $newSetting);
             $contentClass->store();
             break;
     }
 }
Пример #9
0
 private function createContentObject($classIdentifier, $parentNodeId, $fillMode)
 {
     $contentClass = eZContentClass::fetchByIdentifier($classIdentifier);
     if (!$contentClass) {
         throw new Exception("This content class does not exist: [" . $classIdentifier . "]");
     }
     if (!eepValidate::validateContentNodeId($parentNodeId)) {
         throw new Exception("This is not an node id: [" . $parentNodeId . "]");
     }
     // todo, in addition to "random" mode, datamap content should be
     // pullable from a suitable xml file; might also provide a way to dump
     // the framework for a content class "as xml"
     if ("random" == $fillMode) {
         $classId = eZContentClass::classIDByIdentifier($classIdentifier);
         $attributeList = eZContentClassAttribute::fetchListByClassID($classId);
         $words = explode(" ", self::fake_text);
         $dataSet = array();
         foreach ($attributeList as $attr) {
             switch ($attr->DataTypeString) {
                 default:
                 case "ezmedia":
                     echo "NOT YET SUPPORTED: [" . $attr->DataTypeString . "]\n";
                     $dataSet[$attr->Identifier] = "123";
                     break;
                 case "ezkeyword":
                     $randomKeys = array_flip(array_rand($words, 2));
                     $randomWords = array_intersect_key($words, $randomKeys);
                     $dataSet[$attr->Identifier] = implode(",", $randomWords);
                     break;
                 case "ezstring":
                     $randomKeys = array_flip(array_rand($words, 5));
                     $randomWords = array_intersect_key($words, $randomKeys);
                     $dataSet[$attr->Identifier] = implode(" ", $randomWords);
                     break;
                 case "eztext":
                     $randomKeys = array_flip(array_rand($words, 100));
                     $randomWords = array_intersect_key($words, $randomKeys);
                     $dataSet[$attr->Identifier] = implode(" ", $randomWords);
                     break;
                 case "ezdatetime":
                     $dataSet[$attr->Identifier] = time();
                     break;
                 case "ezxmltext":
                     $text = "";
                     for ($paraCount = 0; $paraCount < 5; $paraCount += 1) {
                         $randomKeys = array_flip(array_rand($words, 60));
                         $randomWords = array_intersect_key($words, $randomKeys);
                         $text .= "<p>" . implode(" ", $randomWords) . "</p>";
                     }
                     $parser = new eZOEInputParser();
                     $document = $parser->process($text);
                     $dataSet[$attr->Identifier] = eZXMLTextType::domString($document);
                     break;
             }
         }
         $createResults = $this->create($parentNodeId, $classIdentifier, $dataSet);
         //echo "\nobject creation results\n";
         //var_dump( $createResults );
     } else {
         throw new Exception("Only 'random' is currently supported.");
     }
 }
Пример #10
0
 static function listAttributes($classIdentifier)
 {
     $contentClass = eZContentClass::fetchByIdentifier($classIdentifier);
     if (!$contentClass) {
         throw new Exception("This content class does not exist: [" . $classIdentifier . "]");
     }
     $classId = eZContentClass::classIDByIdentifier($classIdentifier);
     $attributeList = eZContentClassAttribute::fetchListByClassID($classId);
     $results = array();
     $results[] = array("Identifier", "Lang", "Id", "Type", "Srch", "Reqd", "Info", "Pos", "Name");
     foreach ($attributeList as $attribute) {
         $snl = unserialize($attribute->SerializedNameList);
         $results[] = array($attribute->Identifier, $snl["always-available"], $attribute->ID, $attribute->DataTypeString, $attribute->IsSearchable, $attribute->IsRequired, $attribute->IsInformationCollector, $attribute->Position, $snl[$snl["always-available"]]);
     }
     eep::printTable($results, "list attributes of class: " . $classIdentifier);
 }
Пример #11
0
 private function searchForNodes($parentNodeId, $classIdentifier, $searchString)
 {
     $contentClass = eZContentClass::fetchByIdentifier($classIdentifier);
     if (!$contentClass) {
         throw new Exception("This content class does not exist: [" . $classIdentifier . "]");
     }
     if (!eepValidate::validateContentNodeId($parentNodeId)) {
         throw new Exception("This is not a node id: [" . $parentNodeId . "]");
     }
     $classId = eZContentClass::classIDByIdentifier($classIdentifier);
     $attributeList = eZContentClassAttribute::fetchListByClassID($classId);
     $limit = 100;
     if (isset($additional["limit"])) {
         $limit = $additional["limit"];
     }
     $offset = 0;
     if (isset($additional["offset"])) {
         $offset = $additional["offset"];
     }
     $params["ClassFilterType"] = "include";
     $params["ClassFilterArray"] = array($classIdentifier);
     $params["MainNodeOnly"] = true;
     $params["IgnoreVisibility"] = true;
     $params['Limitation'] = array();
     $params['Offset'] = $offset;
     $params['Limit'] = $limit;
     $searchStringIsNumeric = is_numeric($searchString);
     $numericTypes = array("ezinteger", "ezfloat", "ezdatetime", "ezboolean");
     $params["AttributeFilter"] = array("or");
     foreach ($attributeList as $attribute) {
         $qualifiedAttributeName = $classIdentifier . "/" . $attribute->Identifier;
         // eg folder/name
         // if the string is not numeric and the attribute is numeric, don't
         // search on it -- this is still rough functionality
         if (in_array($attribute->DataTypeString, $numericTypes) && !$searchStringIsNumeric) {
             continue;
         }
         // search on everything else -- maybe a bad idea which generates too
         // many hits ...
         $params["AttributeFilter"][] = array($qualifiedAttributeName, "like", "*" . $searchString . "*");
     }
     $matches = eZContentObjectTreeNode::subTreeByNodeID($params, $parentNodeId);
     $title = "Search on all attributes in '" . $classIdentifier . "' for '" . $searchString . "' from parent " . $parentNodeId;
     eep::displayNodeList($matches, $title);
 }