/** * Returns a subtree node items for given parent node * * Following parameters are supported: * ezjscnode::subtree::parent_node_id::limit::offset::sort::order * * @since 1.2 * @param mixed $args * @return array */ public static function subTree($args) { $parentNodeID = isset($args[0]) ? $args[0] : null; $limit = isset($args[1]) ? $args[1] : 25; $offset = isset($args[2]) ? $args[2] : 0; $sort = isset($args[3]) ? self::sortMap($args[3]) : 'published'; $order = isset($args[4]) ? $args[4] : false; $objectNameFilter = isset($args[5]) ? $args[5] : ''; if (!$parentNodeID) { throw new ezcBaseFunctionalityNotSupportedException('Fetch node list', 'Parent node id is not valid'); } $node = eZContentObjectTreeNode::fetch($parentNodeID); if (!$node instanceof eZContentObjectTreeNode) { throw new ezcBaseFunctionalityNotSupportedException('Fetch node list', "Parent node '{$parentNodeID}' is not valid"); } $params = array('Depth' => 1, 'Limit' => $limit, 'Offset' => $offset, 'SortBy' => array(array($sort, $order)), 'DepthOperator' => 'eq', 'ObjectNameFilter' => $objectNameFilter, 'AsObject' => true); // fetch nodes and total node count $count = $node->subTreeCount($params); if ($count) { $nodeArray = $node->subTree($params); } else { $nodeArray = array(); } unset($node); // We have on purpose not checked permission on $node itself, so it should not be used // generate json response from node list if ($nodeArray) { $list = ezjscAjaxContent::nodeEncode($nodeArray, array('formatDate' => 'shortdatetime', 'fetchThumbPreview' => true, 'fetchSection' => true, 'fetchCreator' => true, 'fetchClassIcon' => true), 'raw'); } else { $list = array(); } return array('parent_node_id' => $parentNodeID, 'count' => count($nodeArray), 'total_count' => (int) $count, 'list' => $list, 'limit' => $limit, 'offset' => $offset, 'sort' => $sort, 'order' => $order); }
function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters) { switch ($operatorName) { case 'json_encode': // Lets you use json_encode from templates $operatorValue = json_encode($namedParameters['hash']); break; case 'xml_encode': // Lets you use ezjscAjaxContent::xmlEncode from templates $operatorValue = ezjscAjaxContent::xmlEncode($namedParameters['hash']); break; case 'node_encode': // Lets you use ezjscAjaxContent::nodeEncode from templates $operatorValue = ezjscAjaxContent::nodeEncode($namedParameters['node'], $namedParameters['params'], $namedParameters['type']); break; } }
$embedObject = eZContentObject::fetch($embedId); } } if (!$embedObject instanceof eZContentObject || !$embedObject->canRead()) { echo 'false'; eZExecution::cleanExit(); } // Params for node to json encoder $params = array('loadImages' => true); $params['imagePreGenerateSizes'] = array('small', 'original'); // look for datamap parameter ( what datamap attribute we should load ) if (isset($Params['DataMap']) && $Params['DataMap']) { $params['dataMap'] = array($Params['DataMap']); } // what image sizes we want returned with full data ( url++ ) if ($http->hasPostVariable('imagePreGenerateSizes')) { $params['imagePreGenerateSizes'][] = $http->postVariable('imagePreGenerateSizes'); } else { if (isset($Params['ImagePreGenerateSizes']) && $Params['ImagePreGenerateSizes']) { $params['imagePreGenerateSizes'][] = $Params['ImagePreGenerateSizes']; } } // encode embed object as a json response $json = ezjscAjaxContent::nodeEncode($embedObject, $params); // display debug as a js comment //echo "/*\r\n"; //eZDebug::printReport( false, false ); //echo "*/\r\n"; echo $json; eZDB::checkTransactionCounter(); eZExecution::cleanExit();
/** * 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; }
if ($contentIni->hasVariable('embed-inline-type_' . $contentType, 'CustomAttributes')) { $customAttributes['embed-inline'] = $contentIni->variable('embed-inline-type_' . $contentType, 'CustomAttributes'); } else { if ($contentIni->hasVariable('embed-inline', 'CustomAttributes')) { $customAttributes['embed-inline'] = $contentIni->variable('embed-inline', 'CustomAttributes'); } } } $tpl = eZTemplate::factory(); $tpl->setVariable('object', $object); $tpl->setVariable('object_id', $objectID); $tpl->setVariable('object_version', $objectVersion); $tpl->setVariable('embed_id', $embedId); $tpl->setVariable('embed_type', $embedType); $tpl->setVariable('embed_object', $embedObject); $tpl->setVariable('embed_data', ezjscAjaxContent::nodeEncode($embedObject, $params)); $tpl->setVariable('content_type', $contentType); $tpl->setVariable('content_type_name', ucfirst(rtrim($contentType, 's'))); $tpl->setVariable('compatibility_mode', $ezoeIni->variable('EditorSettings', 'CompatibilityMode')); $tpl->setVariable('tag_name', $tagName); $xmlTagAliasList = $ezoeIni->variable('EditorSettings', 'XmlTagNameAlias'); if (isset($xmlTagAliasList[$tagName])) { $tpl->setVariable('tag_name_alias', $xmlTagAliasList[$tagName]); } else { $tpl->setVariable('tag_name_alias', $tagName); } $tpl->setVariable('view_list', json_encode(array('embed' => $viewList, 'embed-inline' => $viewListInline))); $tpl->setVariable('class_list', json_encode(array('embed' => $classList, 'embed-inline' => $classListInline))); $tpl->setVariable('attribute_defaults', json_encode(array('embed' => $attributeDefaults, 'embed-inline' => $attributeDefaultsInline))); $tpl->setVariable('custom_attributes', $customAttributes); $tpl->setVariable('size_list', $sizeTypeArray);
/** * Gets current users bookmarks by offset and limit * * @param array $args 0 => node id:1, 1 => offset:0, 2 => limit:10 * @return hash */ public static function browse($args) { $nodeID = isset($args[0]) ? (int) $args[0] : 1; $offset = isset($args[1]) ? (int) $args[1] : 0; $limit = isset($args[2]) ? (int) $args[2] : 10; $http = eZHTTPTool::instance(); if (!$nodeID) { throw new ezcBaseFunctionalityNotSupportedException('Browse node list', 'Parent node id is not valid'); } $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node instanceof eZContentObjectTreeNode) { throw new ezcBaseFunctionalityNotSupportedException('Browse node list', "Parent node '{$nodeID}' is not valid"); } else { if (!$node->canRead()) { throw new ezcBaseFunctionalityNotSupportedException('Browse node list', "Parent node '{$nodeID}' is not valid"); } } $params = array('Depth' => 1, 'Limit' => $limit, 'Offset' => $offset, 'SortBy' => $node->attribute('sort_array'), 'DepthOperator' => 'eq', 'AsObject' => true); // Look for some (class filter and sort by) post params to use as fetch params if ($http->hasPostVariable('ClassFilterArray') && $http->postVariable('ClassFilterArray') !== '') { $params['ClassFilterType'] = 'include'; $params['ClassFilterArray'] = $http->postVariable('ClassFilterArray'); } if ($http->hasPostVariable('SortBy') && $http->postVariable('SortBy') !== '') { $params['SortBy'] = $http->postVariable('SortBy'); } // fetch nodes and total node count $count = $node->subTreeCount($params); if ($count) { $nodeArray = $node->subTree($params); } else { $nodeArray = false; } // generate json response from node list if ($nodeArray) { $list = ezjscAjaxContent::nodeEncode($nodeArray, array('fetchChildrenCount' => true, 'loadImages' => true), 'raw'); } else { $list = array(); } return array('list' => $list, 'count' => count($nodeArray), 'total_count' => (int) $count, 'node' => ezjscAjaxContent::nodeEncode($node, array('fetchPath' => true), 'raw'), 'offset' => $offset, 'limit' => $limit); }