/** * Set RSSExportItem defaults based on site.ini [RSSSettings] settings * * @param eZRSSExportItem $rssExportItem * @return bool True if changes where made */ static function setItemDefaults(eZRSSExportItem $rssExportItem) { $nodeId = $rssExportItem->attribute('source_node_id'); $node = $nodeId ? eZContentObjectTreeNode::fetch($nodeId) : null; if (!$node instanceof eZContentObjectTreeNode) { return false; } $config = eZINI::instance('site.ini'); $nodeClassIdentifier = $node->attribute('class_identifier'); $defaultFeedItemClasses = $config->variable('RSSSettings', 'DefaultFeedItemClasses'); if (!isset($defaultFeedItemClasses[$nodeClassIdentifier])) { return false; } $feedItemClasses = explode(';', $defaultFeedItemClasses[$nodeClassIdentifier]); $iniSection = 'RSSSettings_' . $feedItemClasses[0]; if (!$config->hasVariable($iniSection, 'FeedObjectAttributeMap')) { return false; } $feedObjectAttributeMap = $config->variable($iniSection, 'FeedObjectAttributeMap'); $subNodesMap = $config->hasVariable($iniSection, 'Subnodes') ? $config->variable($iniSection, 'Subnodes') : array(); $rssExportItem->setAttribute('class_id', eZContentObjectTreeNode::classIDByIdentifier($feedItemClasses[0])); $rssExportItem->setAttribute('title', $feedObjectAttributeMap['title']); if (isset($feedObjectAttributeMap['description'])) { $rssExportItem->setAttribute('description', $feedObjectAttributeMap['description']); } if (isset($feedObjectAttributeMap['category'])) { $rssExportItem->setAttribute('category', $feedObjectAttributeMap['category']); } if (isset($feedObjectAttributeMap['enclosure'])) { $rssExportItem->setAttribute('enclosure', $feedObjectAttributeMap['enclosure']); } $rssExportItem->setAttribute('subnodes', isset($subNodesMap[$nodeClassIdentifier]) && $subNodesMap[$nodeClassIdentifier] === 'true'); $rssExportItem->store(); }
/** * Creates a RSS/ATOM Feed export for a node * * @param int $nodeID Node ID * * @since 4.3 */ public static function createFeedForNode($nodeID) { $hasExport = eZRSSFunctionCollection::hasExportByNode($nodeID); if (isset($hasExport['result']) && $hasExport['result']) { eZDebug::writeError('There is already a rss/atom export feed for this node: ' . $nodeID, __METHOD__); return array('status' => false); } $node = eZContentObjectTreeNode::fetch($nodeID); $currentClassIdentifier = $node->attribute('class_identifier'); $config = eZINI::instance('site.ini'); $feedItemClasses = $config->variable('RSSSettings', 'DefaultFeedItemClasses'); if (!$feedItemClasses || !isset($feedItemClasses[$currentClassIdentifier])) { eZDebug::writeError("EnableRSS: content class {$currentClassIdentifier} is not defined in site.ini[RSSSettings]DefaultFeedItemClasses[<class_id>].", __METHOD__); return array('status' => false); } $object = $node->object(); $objectID = $object->attribute('id'); $currentUserID = eZUser::currentUserID(); $rssExportItems = array(); $db = eZDB::instance(); $db->begin(); $rssExport = eZRSSExport::create($currentUserID); $rssExport->setAttribute('access_url', 'rss_feed_' . $nodeID); $rssExport->setAttribute('node_id', $nodeID); $rssExport->setAttribute('main_node_only', '1'); $rssExport->setAttribute('number_of_objects', $config->variable('RSSSettings', 'NumberOfObjectsDefault')); $rssExport->setAttribute('rss_version', $config->variable('RSSSettings', 'DefaultVersion')); $rssExport->setAttribute('status', eZRSSExport::STATUS_VALID); $rssExport->setAttribute('title', $object->name()); $rssExport->store(); $rssExportID = $rssExport->attribute('id'); foreach (explode(';', $feedItemClasses[$currentClassIdentifier]) as $classIdentifier) { $iniSection = 'RSSSettings_' . $classIdentifier; if ($config->hasVariable($iniSection, 'FeedObjectAttributeMap')) { $feedObjectAttributeMap = $config->variable($iniSection, 'FeedObjectAttributeMap'); $subNodesMap = $config->hasVariable($iniSection, 'Subnodes') ? $config->variable($iniSection, 'Subnodes') : array(); $rssExportItem = eZRSSExportItem::create($rssExportID); $rssExportItem->setAttribute('class_id', eZContentObjectTreeNode::classIDByIdentifier($classIdentifier)); $rssExportItem->setAttribute('title', $feedObjectAttributeMap['title']); if (isset($feedObjectAttributeMap['description'])) { $rssExportItem->setAttribute('description', $feedObjectAttributeMap['description']); } if (isset($feedObjectAttributeMap['category'])) { $rssExportItem->setAttribute('category', $feedObjectAttributeMap['category']); } if (isset($feedObjectAttributeMap['enclosure'])) { $rssExportItem->setAttribute('enclosure', $feedObjectAttributeMap['enclosure']); } $rssExportItem->setAttribute('source_node_id', $nodeID); $rssExportItem->setAttribute('status', eZRSSExport::STATUS_VALID); $rssExportItem->setAttribute('subnodes', isset($subNodesMap[$currentClassIdentifier]) && $subNodesMap[$currentClassIdentifier] === 'true'); $rssExportItem->store(); } else { eZDebug::writeError("site.ini[{$iniSection}]Source[] setting is not defined.", __METHOD__); } } $db->commit(); eZContentCacheManager::clearContentCacheIfNeeded($objectID); return array('status' => true); }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { switch ($operatorName) { case 'eztagcloud': $tags = array(); $tagCloud = array(); $parentNodeID = 0; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; $dbParams = array(); $params = $namedParameters['params']; $orderBySql = 'ORDER BY ezkeyword.keyword ASC'; if (isset($params['class_identifier'])) { $classIdentifier = $params['class_identifier']; } if (isset($params['parent_node_id'])) { $parentNodeID = $params['parent_node_id']; } if (isset($params['limit'])) { $dbParams['limit'] = $params['limit']; } if (isset($params['offset'])) { $dbParams['offset'] = $params['offset']; } if (isset($params['sort_by']) && is_array($params['sort_by']) && count($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { if ($key !== 0) { $orderBySql .= ', '; } $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'keyword': $orderBySql .= 'ezkeyword.keyword ' . ($direction ? 'ASC' : 'DESC'); break; case 'count': $orderBySql .= 'keyword_count ' . ($direction ? 'ASC' : 'DESC'); break; } } } $db = eZDB::instance(); if ($classIdentifier) { $classID = eZContentObjectTreeNode::classIDByIdentifier($classIdentifier); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = '" . $classID . "'"; } 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; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $languageFilter .= 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject_attribute', 'language_id'); $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(ezkeyword.keyword) AS keyword_count\n FROM ezkeyword_attribute_link\n LEFT JOIN ezcontentobject_attribute\n ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n LEFT JOIN ezcontentobject\n ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n LEFT JOIN ezcontentobject_tree\n ON ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n LEFT JOIN ezkeyword\n ON ezkeyword.id = ezkeyword_attribute_link.keyword_id\n {$sqlPermissionChecking['from']}\n WHERE\n ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_attribute.version = ezcontentobject.current_version\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n {$pathString}\n {$parentNodeIDSQL}\n {$classIdentifierSQL}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n GROUP BY ezkeyword.id, ezkeyword.keyword\n {$orderBySql}", $dbParams); foreach ($rs as $row) { $tags[$row['keyword']] = $row['keyword_count']; } // To be able to combine count sorting with keyword sorting // without being limited by sql LIMIT result clipping if (isset($params['post_sort_by'])) { if ($params['post_sort_by'] === 'keyword') { ksort($tags, SORT_LOCALE_STRING); } else { if ($params['post_sort_by'] === 'keyword_reverse') { krsort($tags, SORT_LOCALE_STRING); } else { if ($params['post_sort_by'] === 'count') { asort($tags, SORT_NUMERIC); } else { if ($params['post_sort_by'] === 'count_reverse') { arsort($tags, SORT_NUMERIC); } } } } } $maxFontSize = 200; $minFontSize = 100; $maxCount = 0; $minCount = 0; if (count($tags) != 0) { $maxCount = max(array_values($tags)); $minCount = min(array_values($tags)); } $spread = $maxCount - $minCount; if ($spread == 0) { $spread = 1; } $step = ($maxFontSize - $minFontSize) / $spread; foreach ($tags as $key => $value) { $size = $minFontSize + ($value - $minCount) * $step; $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key); } $tpl = eZTemplate::factory(); $tpl->setVariable('tag_cloud', $tagCloud); $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl'); break; } }
function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters) { switch ($operatorName) { // note: these functions are not cache-block safe // as in: if called inside a cache-block then they will not be called when cache is used. case 'ezpagedata_set': case 'ezpagedata_append': self::setPersistentVariable($namedParameters['key'], $namedParameters['value'], $tpl, $operatorName === 'ezpagedata_append'); break; case 'ezpagedata': $currentNodeId = 0; $pageData = array(); $parameters = $namedParameters['params']; // Get module_result for later use if ($tpl->hasVariable('module_result')) { $moduleResult = $tpl->variable('module_result'); } else { $moduleResult = array(); } if (isset($moduleResult['content_info'])) { $contentInfo = $moduleResult['content_info']; } else { $contentInfo = array(); } // Get persistent_variable if (isset($contentInfo['persistent_variable']) && is_array($contentInfo['persistent_variable'])) { $pageData['persistent_variable'] = $contentInfo['persistent_variable']; } else { $pageData['persistent_variable'] = self::getPersistentVariable(); if ($pageData['persistent_variable'] === null) { $pageData['persistent_variable'] = array(); } } // Merge parameters with persistent_variable $parameters = array_merge($parameters, $pageData['persistent_variable']); // Figgure out current node id if (isset($parameters['current_node_id'])) { $currentNodeId = (int) $parameters['current_node_id']; // Allow parameters to set current path if (isset($parameters['set_current_node_path']) && $parameters['set_current_node_path']) { if ($setPath = self::getNodePath($currentNodeId)) { $moduleResult['path'] = $setPath['path']; $moduleResult['title_path'] = $setPath['title_path']; $tpl->setVariable('module_result', $moduleResult); } else { eZDebug::writeWarning("Could not fetch 'current_node_id'", 'eZPageData::getNodePath()'); } } } else { if ($tpl->hasVariable('current_node_id')) { $currentNodeId = (int) $tpl->variable('current_node_id'); } else { if (isset($moduleResult['node_id'])) { $currentNodeId = (int) $moduleResult['node_id']; } else { if (isset($moduleResult['path'], $moduleResult['path'][count($moduleResult['path']) - 1]['node_id'])) { $currentNodeId = (int) $moduleResult['path'][count($moduleResult['path']) - 1]['node_id']; } } } } // Init variables and return values $ini = eZINI::instance('site.ini'); $menuIni = eZINI::instance('menu.ini'); $contentIni = eZINI::instance('content.ini'); $uiContext = $tpl->variable('ui_context'); $uriString = $tpl->variable('uri_string'); $pageDepth = isset($moduleResult['path']) ? count($moduleResult['path']) : 0; $pageData['main_node_id'] = isset($contentInfo['main_node_id']) ? $contentInfo['main_node_id'] : $currentNodeId; $pageData['show_path'] = 'path'; $pageData['website_toolbar'] = false; $pageData['node_id'] = $currentNodeId; $pageData['is_edit'] = false; $pageData['page_root_depth'] = 0; $pageData['page_depth'] = $pageDepth; $pageData['root_node'] = (int) $contentIni->variable('NodeSettings', 'RootNode'); $pageData['canonical_url'] = false; $pageData['canonical_language_url'] = false; // is_edit if not on user/edit and not on content/action when // you get info collector warning about missing attributes if ($uiContext === 'edit' && strpos($uriString, 'user/edit') === false && (empty($contentInfo) || strpos($uriString, 'content/action') === false)) { $pageData['is_edit'] = true; } if (isset($contentInfo['viewmode'])) { $viewMode = $contentInfo['viewmode']; } else { $viewMode = ''; } // Get custom template_look object. false|eZContentObject (set as parameter from caller) if (isset($parameters['template_look'])) { $pageData['template_look'] = $parameters['template_look']; } else { // Get template_look eZContentObject if (!isset($parameters['template_look_class'])) { $parameters['template_look_class'] = 'template_look'; } $templateLookClassID = eZContentObjectTreeNode::classIDByIdentifier($parameters['template_look_class']); $templateLookObjectList = eZContentObject::fetchFilteredList(array('contentclass_id' => $templateLookClassID), 0, 1); if ($templateLookObjectList) { $pageData['template_look'] = $templateLookObjectList[0]; } else { $pageData['template_look'] = false; } } // canonical url, to let search engines know about main location on content with multiple locations if (isset($parameters['canonical_url'])) { $pageData['canonical_url'] = $parameters['canonical_url']; } elseif (isset($contentInfo['main_node_url_alias']) && $contentInfo['main_node_url_alias']) { $pageData['canonical_url'] = $contentInfo['main_node_url_alias']; } elseif (isset($contentInfo['current_language']) && $contentInfo['current_language'] !== $ini->variable('RegionalSettings', 'ContentObjectLocale')) { $siteaccess = eZSiteAccess::saNameByLanguage($contentInfo['current_language']); if ($siteaccess !== null) { $lang = eZContentLanguage::fetchByLocale($ini->variable('RegionalSettings', 'ContentObjectLocale')); if (($contentInfo['language_mask'] & $lang->attribute('id')) < 1) { $handlerOptions = new ezpExtensionOptions(); $handlerOptions->iniFile = 'site.ini'; $handlerOptions->iniSection = 'RegionalSettings'; $handlerOptions->iniVariable = 'LanguageSwitcherClass'; $handlerOptions->handlerParams = array(array('Parameters' => array('sa', $currentNodeId), 'UserParameters' => array())); $langSwitch = eZExtension::getHandlerClass($handlerOptions); $langSwitch->setDestinationSiteAccess($siteaccess); $langSwitch->process(); $pageData['canonical_language_url'] = $langSwitch->destinationUrl(); } } } /* RootNodeDepth is a setting for letting you have a very simple multisite, single database and singe siteaccess setup. The content of the menues will be the same on all system pages like user/login, content/edit and so on, and also when you surf bellow the defined page_root_depth. The sites will also share siteaccess and thus also the same ez publish design and templates. You can however custimize the design with css using the class on div#page html output: subtree_level_x_node_id_y class Note: It is recommended to turn it of by setting it to 0 for normal sites! Example having 2 or more 'sub-sites' with RootNodeDepth=2: root (menu shows sub sites as menu choices like it will on system pages) - sub site 1 (menu show content of this sub site) - sub site 2 (-- " --) - sub site 3 (-- " --) - sub site 4 (-- " --) - sub site 5 (-- " --) */ if ($currentNodeId && isset($moduleResult['path'][0]['node_id']) && $moduleResult['path'][0]['node_id'] == '2' && $ini->hasVariable('SiteSettings', 'RootNodeDepth') && $ini->variable('SiteSettings', 'RootNodeDepth') !== '0') { $pageData['page_root_depth'] = $ini->variable('SiteSettings', 'RootNodeDepth') - 1; if (isset($moduleResult['path'][$pageData['page_root_depth']]['node_id'])) { $pageData['root_node'] = $moduleResult['path'][$pageData['page_root_depth']]['node_id']; } } // Get class identifier for easier access in tempaltes $pageData['class_identifier'] = ''; if (isset($contentInfo['class_identifier'])) { $pageData['class_identifier'] = $contentInfo['class_identifier']; } // Use custom path template. bool|string ( default: path ) if (isset($parameters['show_path'])) { $pageData['show_path'] = $parameters['show_path'] === true ? 'path' : $parameters['show_path']; } else { if ($viewMode === 'sitemap' || $viewMode === 'tagcloud') { $pageData['show_path'] = false; } } // See if we should show website toolbar. bool ( default: false ) if (isset($parameters['website_toolbar'])) { $pageData['website_toolbar'] = $parameters['website_toolbar']; } else { if ($viewMode === 'sitemap' || $viewMode === 'tagcloud' || strpos($uriString, 'content/versionview') === 0) { $pageData['website_toolbar'] = false; } else { if ($tpl->hasVariable('current_user')) { $currentUser = $tpl->variable('current_user'); $pageData['website_toolbar'] = $currentNodeId && $currentUser->attribute('is_logged_in'); } } } // Init default menu settings $pageData['top_menu'] = $menuIni->variable('SelectedMenu', 'TopMenu'); $pageData['left_menu'] = $menuIni->variable('SelectedMenu', 'LeftMenu'); $pageData['current_menu'] = $menuIni->variable('SelectedMenu', 'CurrentMenu'); $pageData['extra_menu'] = 'extra_info'; $pageData['extra_menu_node_id'] = $currentNodeId; $pageData['extra_menu_subitems'] = 0; $pageData['extra_menu_class_list'] = array('infobox'); // BC: Setting to hide left and extra menu by class identifier if ($menuIni->hasVariable('MenuSettings', 'HideLeftMenuClasses')) { $hideMenuClasses = in_array($pageData['class_identifier'], $menuIni->variable('MenuSettings', 'HideLeftMenuClasses')); } else { $hideMenuClasses = false; } // Use custom top menu template. bool|string ( default: from menu.ini[SelectedMenu]TopMenu ) if (isset($parameters['top_menu']) && $parameters['top_menu'] !== true) { $pageData['top_menu'] = $parameters['top_menu']; } // Use custom left menu template. bool|string ( default: from menu.ini[SelectedMenu]LeftMenu ) if (isset($parameters['left_menu'])) { if ($parameters['left_menu'] !== true) { $pageData['left_menu'] = $parameters['left_menu']; } } else { if ($hideMenuClasses) { $pageData['left_menu'] = false; } } // Use custom extra menu template. bool|string (default: extra_info) if (isset($parameters['extra_menu'])) { if ($parameters['extra_menu'] !== true) { $pageData['extra_menu'] = $parameters['extra_menu']; } } else { if ($hideMenuClasses) { $pageData['extra_menu'] = false; } } // Use custom node id. int|array (default: current node id) if (isset($parameters['extra_menu_node_id'])) { $pageData['extra_menu_node_id'] = $parameters['extra_menu_node_id']; } // Use custom extra menu identifier list. false|array (default: infobox) if (isset($parameters['extra_menu_class_list'])) { $pageData['extra_menu_class_list'] = $parameters['extra_menu_class_list']; } else { if ($menuIni->hasVariable('MenuContentSettings', 'ExtraIdentifierList')) { $pageData['extra_menu_class_list'] = $menuIni->variable('MenuContentSettings', 'ExtraIdentifierList'); } } if ($menuIni->variable('MenuSettings', 'AlwaysAvailable') === 'false') { // A set of cases where left/extra menu's are hidden unless set by parameters if ($pageData['is_edit'] || strpos($uriString, 'content/versionview') === 0) { if (!isset($parameters['left_menu'])) { $pageData['left_menu'] = false; } if (!isset($parameters['extra_menu'])) { $pageData['extra_menu'] = false; } } else { if (!$currentNodeId || $uiContext === 'browse') { if (!isset($parameters['left_menu'])) { $pageData['left_menu'] = false; } if (!isset($parameters['extra_menu'])) { $pageData['extra_menu'] = false; } } } } // Count extra menu objects if all extra menu settings are present if (isset($parameters['extra_menu_subitems'])) { $pageData['extra_menu_subitems'] = $parameters['extra_menu_subitems']; if (!$pageData['extra_menu_subitems']) { $pageData['extra_menu'] = false; } } else { if ($pageData['extra_menu'] && $pageData['extra_menu_class_list'] && $pageData['extra_menu_node_id']) { if ($menuIni->variable('MenuContentSettings', 'ExtraMenuSubitemsCheck') === 'enabled') { $pageData['extra_menu_subitems'] = eZContentObjectTreeNode::subTreeCountByNodeID(array('Depth' => 1, 'DepthOperator' => 'eq', 'ClassFilterType' => 'include', 'ClassFilterArray' => $pageData['extra_menu_class_list']), $pageData['extra_menu_node_id']); if (!$pageData['extra_menu_subitems']) { $pageData['extra_menu'] = false; } } } } // Init path parameters $pageData['path_array'] = array(); $pageData['path_id_array'] = array(); $pageData['path_normalized'] = ''; // Creating menu css classes for div#page $pageData['css_classes'] = $pageData['left_menu'] ? 'sidemenu' : 'nosidemenu'; $pageData['css_classes'] .= $pageData['extra_menu'] ? ' extrainfo' : ' noextrainfo'; // Add section css class for div#page if (isset($moduleResult['section_id'])) { $pageData['css_classes'] .= ' section_id_' . $moduleResult['section_id']; } // Generate relative path array as well full path id array and path css classes for div#page $path = isset($moduleResult['path']) && is_array($moduleResult['path']) ? $moduleResult['path'] : array(); foreach ($path as $key => $item) { if ($key >= $pageData['page_root_depth']) { $pageData['path_array'][] = $item; } if (isset($item['node_id'])) { $pageData['path_normalized'] .= ' subtree_level_' . $key . '_node_id_' . $item['node_id']; $pageData['path_id_array'][] = $item['node_id']; } } $pageData['css_classes'] .= $pageData['path_normalized']; if (isset($pageData['persistent_variable']['pagestyle_css_classes']) && is_array($pageData['persistent_variable']['pagestyle_css_classes'])) { $pageData['css_classes'] .= ' ' . implode(' ', $pageData['persistent_variable']['pagestyle_css_classes']); } $operatorValue = $pageData; break; } }
/** * Returns the tag cloud for specified parameters using eZ Publish database * * @param array $params * * @return array */ private function tagCloud($params) { $parentNodeID = 0; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; $dbParams = array(); $orderBySql = 'ORDER BY eztags.keyword ASC'; if (isset($params['class_identifier'])) { $classIdentifier = $params['class_identifier']; } if (isset($params['parent_node_id'])) { $parentNodeID = $params['parent_node_id']; } if (isset($params['limit'])) { $dbParams['limit'] = $params['limit']; } if (isset($params['offset'])) { $dbParams['offset'] = $params['offset']; } if (isset($params['sort_by']) && is_array($params['sort_by']) && !empty($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { if ($key !== 0) { $orderBySql .= ', '; } $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'keyword': $orderBySql .= 'eztags.keyword ' . ($direction ? 'ASC' : 'DESC'); break; case 'count': $orderBySql .= 'keyword_count ' . ($direction ? 'ASC' : 'DESC'); break; } } } $db = eZDB::instance(); if ($classIdentifier) { $classID = eZContentObjectTreeNode::classIDByIdentifier($classIdentifier); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = '" . $classID . "'"; } 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; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $languageFilter .= 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject_attribute', 'language_id'); $rs = $db->arrayQuery("SELECT eztags.id, eztags.keyword, COUNT(DISTINCT ezcontentobject.id) AS keyword_count\n FROM eztags_attribute_link\n LEFT JOIN ezcontentobject_attribute\n ON eztags_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND eztags_attribute_link.objectattribute_version = ezcontentobject_attribute.version\n LEFT JOIN ezcontentobject\n ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n LEFT JOIN ezcontentobject_tree\n ON ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n LEFT JOIN eztags\n ON eztags.id = eztags_attribute_link.keyword_id\n LEFT JOIN eztags_keyword\n ON eztags.id = eztags_keyword.keyword_id\n {$sqlPermissionChecking['from']}\n WHERE " . eZContentLanguage::languagesSQLFilter('eztags') . "\n AND " . eZContentLanguage::sqlFilter('eztags_keyword', 'eztags') . "\n AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_attribute.version = ezcontentobject.current_version\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n {$pathString}\n {$parentNodeIDSQL}\n {$classIdentifierSQL}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n GROUP BY eztags.id, eztags.keyword\n {$orderBySql}", $dbParams); $tagsCountList = array(); foreach ($rs as $row) { $tagsCountList[$row['id']] = $row['keyword_count']; } /** @var eZTagsObject[] $tagObjects */ $tagObjects = eZTagsObject::fetchList(array('id' => array(array_keys($tagsCountList)))); if (!is_array($tagObjects) || empty($tagObjects)) { return array(); } $tagSortArray = array(); $tagKeywords = array(); $tagCounts = array(); foreach ($tagObjects as $tag) { $tagKeyword = $tag->attribute('keyword'); $tagCount = $tagsCountList[$tag->attribute('id')]; $tagSortArray[] = array('keyword' => $tagKeyword, 'count' => $tagCount, 'tag' => $tag); $tagKeywords[] = $tagKeyword; $tagCounts[] = $tagCount; } if (isset($params['post_sort_by'])) { if ($params['post_sort_by'] === 'keyword') { array_multisort($tagKeywords, SORT_ASC, SORT_LOCALE_STRING, $tagSortArray); } else { if ($params['post_sort_by'] === 'keyword_reverse') { array_multisort($tagKeywords, SORT_DESC, SORT_LOCALE_STRING, $tagSortArray); } else { if ($params['post_sort_by'] === 'count') { array_multisort($tagCounts, SORT_ASC, SORT_NUMERIC, $tagSortArray); } else { if ($params['post_sort_by'] === 'count_reverse') { array_multisort($tagCounts, SORT_DESC, SORT_NUMERIC, $tagSortArray); } } } } } $this->normalizeTagCounts($tagSortArray, $tagCounts); return $tagSortArray; }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { switch ($operatorName) { case 'eztagcloud': /* $tags = array(); $tagCloud = array(); $parentNodeID = 0; $classID = ''; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; if ( isset( $namedParameters['params']['class_identifier'] ) ) $classIdentifier = $namedParameters['params']['class_identifier']; if ( isset( $namedParameters['params']['parent_node_id'] ) ) $parentNodeID = $namedParameters['params']['parent_node_id']; if ( isset( $namedParameters['params']['limit'] ) ) $tagCloudLimit = $namedParameters['params']['limit']; else $tagCloudLimit = 25; include_once( 'lib/ezdb/classes/ezdb.php' ); $db = eZDB::instance(); if( $classIdentifier ) { $classID = eZContentObjectTreeNode::classIDByIdentifier( $classIdentifier ); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = $classID"; } 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; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation ); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList ); $versionNameJoins = " AND ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version AND "; $languageFilter = " AND " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' ); $versionNameJoins .= eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ); $rs = $db->arrayQuery( "SELECT DISTINCT ezkeyword.keyword FROM ezkeyword, ezkeyword_attribute_link, ezcontentobject, ezcontentobject_name, ezcontentobject_attribute, ezcontentobject_tree $sqlPermissionChecking[from] WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id AND ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id AND ezcontentobject.status = '".eZContentObject::STATUS_PUBLISHED."' AND ezcontentobject_attribute.version = ezcontentobject.current_version AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id $pathString $parentNodeIDSQL $classIdentifierSQL $showInvisibleNodesCond $sqlPermissionChecking[where] $languageFilter $versionNameJoins ORDER BY ezkeyword.keyword ASC" ); include_once ('lib/ezutils/classes/ezfunctionhandler.php'); foreach( $rs as $row ) { $tags[$row['keyword']] = eZFunctionHandler::execute( 'content', 'keyword_count', array( 'alphabet' => $row['keyword'], 'strict_matching' => true, 'classid' => $classID ) ); } $maxFontSize = 180; $minFontSize = 90; $maxCount = 0; $minCount = 0; if( count( $tags ) != 0 ) { $maxCount = max( array_values( $tags ) ); $minCount = min( array_values($tags ) ); } $spread = $maxCount - $minCount; if ( $spread == 0 ) $spread = 1; $step = ( $maxFontSize - $minFontSize )/( $spread ); foreach ($tags as $key => $value) { $size = $minFontSize + ( ( $value - $minCount ) * $step ); $tagCloud[] = array( 'font_size' => $size, 'count' => $value, 'tag' => $key ); } // Now sort and truncate the tag cloud results usort($tagCloud, array("eZTagCloud","tagCountSort")); array_splice($tagCloud, $tagCloudLimit); shuffle($tagCloud); $tpl = eZTemplate::factory(); $tpl->setVariable( 'tag_cloud', $tagCloud ); $operatorValue = $tpl->fetch( 'design:tagcloud/tagcloud.tpl' ); */ // End original version // Start trunk version of ezwebin: $tags = array(); $tagCloud = array(); $parentNodeID = 0; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; $dbParams = array(); $params = $namedParameters['params']; $orderBySql = 'ORDER BY ezkeyword.keyword ASC'; if (isset($params['class_identifier'])) { $classIdentifier = $params['class_identifier']; } if (isset($params['parent_node_id'])) { $parentNodeID = $params['parent_node_id']; } if (isset($params['limit'])) { $dbParams['limit'] = $params['limit']; } if (isset($params['offset'])) { $dbParams['offset'] = $params['offset']; } if (isset($params['sort_by']) && is_array($params['sort_by']) && count($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { if ($key !== 0) { $orderBySql .= ', '; } $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'keyword': $orderBySql .= 'ezkeyword.keyword ' . ($direction ? 'ASC' : 'DESC'); break; case 'count': $orderBySql .= 'keyword_count ' . ($direction ? 'ASC' : 'DESC'); break; } } } $db = eZDB::instance(); if ($classIdentifier) { $classID = eZContentObjectTreeNode::classIDByIdentifier($classIdentifier); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = '" . $classID . "'"; } 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; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(*) as keyword_count\n FROM ezkeyword,\n ezkeyword_attribute_link,\n ezcontentobject,\n ezcontentobject_attribute,\n ezcontentobject_tree\n {$sqlPermissionChecking['from']}\n WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_attribute.version = ezcontentobject.current_version\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n {$pathString}\n {$parentNodeIDSQL}\n {$classIdentifierSQL}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n GROUP BY ezkeyword.id, ezkeyword.keyword\n {$orderBySql}", $dbParams); foreach ($rs as $row) { $tags[$row['keyword']] = $row['keyword_count']; } // To be able to combine count sorting with keyword sorting // without being limited by sql LIMIT result clipping if (isset($params['post_sort_by'])) { if ($params['post_sort_by'] === 'keyword') { ksort($tags, SORT_LOCALE_STRING); } else { if ($params['post_sort_by'] === 'keyword_reverse') { krsort($tags, SORT_LOCALE_STRING); } else { if ($params['post_sort_by'] === 'count') { asort($tags, SORT_NUMERIC); } else { if ($params['post_sort_by'] === 'count_reverse') { arsort($tags, SORT_NUMERIC); } } } } } // $maxFontSize = 10; // $minFontSize = 1; $maxFontSize = 200; $minFontSize = 100; $maxCount = 0; $minCount = 0; if (count($tags) != 0) { $maxCount = max(array_values($tags)); $minCount = min(array_values($tags)); } $spread = $maxCount - $minCount; if ($spread == 0) { $spread = 1; } $step = ($maxFontSize - $minFontSize) / $spread; foreach ($tags as $key => $value) { // $size = round( log( $value ) / ( log( $maxCount ) / ( $maxFontSize - $minFontSize ) ) + $minFontSize ); $size = $minFontSize + ($value - $minCount) * $step; $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key); } $tpl = eZTemplate::factory(); $tpl->setVariable('tag_cloud', $tagCloud); $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl'); break; case 'eztagcloud_new': // Start trunk version of ezwebin: $tags = array(); $tagCloud = array(); $parentNodeID = 0; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; $dbParams = array(); $params = $namedParameters['params']; $orderBySql = 'ORDER BY ezkeyword.keyword ASC'; if (isset($params['class_identifier'])) { $classIdentifier = $params['class_identifier']; } if (isset($params['parent_node_id'])) { $parentNodeID = $params['parent_node_id']; } if (isset($params['limit'])) { $dbParams['limit'] = $params['limit']; } if (isset($params['offset'])) { $dbParams['offset'] = $params['offset']; } if (isset($params['sort_by']) && is_array($params['sort_by']) && count($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { if ($key !== 0) { $orderBySql .= ', '; } $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'keyword': $orderBySql .= 'ezkeyword.keyword ' . ($direction ? 'ASC' : 'DESC'); break; case 'count': $orderBySql .= 'keyword_count ' . ($direction ? 'ASC' : 'DESC'); break; } } } $db = eZDB::instance(); if ($classIdentifier) { $classID = eZContentObjectTreeNode::classIDByIdentifier($classIdentifier); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = '" . $classID . "'"; } 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; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(*) as keyword_count\n FROM ezkeyword,\n ezkeyword_attribute_link,\n ezcontentobject,\n ezcontentobject_attribute,\n ezcontentobject_tree\n {$sqlPermissionChecking['from']}\n WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_attribute.version = ezcontentobject.current_version\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n {$pathString}\n {$parentNodeIDSQL}\n {$classIdentifierSQL}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n GROUP BY ezkeyword.id, ezkeyword.keyword\n {$orderBySql}", $dbParams); foreach ($rs as $row) { $tags[$row['keyword']] = $row['keyword_count']; } // To be able to combine count sorting with keyword sorting // without being limited by sql LIMIT result clipping if (isset($params['post_sort_by'])) { if ($params['post_sort_by'] === 'keyword') { ksort($tags, SORT_LOCALE_STRING); } else { if ($params['post_sort_by'] === 'keyword_reverse') { krsort($tags, SORT_LOCALE_STRING); } else { if ($params['post_sort_by'] === 'count') { asort($tags, SORT_NUMERIC); } else { if ($params['post_sort_by'] === 'count_reverse') { arsort($tags, SORT_NUMERIC); } } } } } $maxFontSize = 10; $minFontSize = 4; $maxCount = 0; $minCount = 0; if (count($tags) != 0) { $maxCount = max(array_values($tags)); $minCount = min(array_values($tags)); } $spread = $maxCount - $minCount; if ($spread == 0) { $spread = 1; } $step = ($maxFontSize - $minFontSize) / $spread; foreach ($tags as $key => $value) { $weight = (log($value) - log($minCount)) / (log($maxCount) - log($minCount)); $size = $minFontSize + round(($maxFontSize - $minFontSize) * $weight); $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key); } $tpl = eZTemplate::factory(); $tpl->setVariable('tag_cloud', $tagCloud); $tpl->setVariable('tag_cloud_exclude', $params['exclude_tags']); $tpl->setVariable('tag_cloud_strings', $params['exclude_strings']); $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl'); break; } }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { switch ($operatorName) { case 'eztagcloud': $tags = array(); $tagCloud = array(); $parentNodeID = 0; $classIdentifier = ''; $classIdentifierSQL = ''; $pathString = ''; $parentNodeIDSQL = ''; $dbParams = array(); $params = $namedParameters['params']; $orderBySql = 'ORDER BY ezkeyword.keyword ASC'; if (isset($params['class_identifier'])) { $classIdentifier = $params['class_identifier']; } if (isset($params['parent_node_id'])) { $parentNodeID = $params['parent_node_id']; } if (isset($params['limit'])) { $dbParams['limit'] = $params['limit']; } if (isset($params['offset'])) { $dbParams['offset'] = $params['offset']; } if (isset($params['sort_by']) && is_array($params['sort_by']) && count($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { if ($key !== 0) { $orderBySql .= ', '; } $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'keyword': $orderBySql .= 'ezkeyword.keyword ' . ($direction ? 'ASC' : 'DESC'); break; case 'count': $orderBySql .= 'keyword_count ' . ($direction ? 'ASC' : 'DESC'); break; } } } $db = eZDB::instance(); if ($classIdentifier) { $classID = eZContentObjectTreeNode::classIDByIdentifier($classIdentifier); $classIdentifierSQL = "AND ezcontentobject.contentclass_id = '" . $classID . "'"; } 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; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = 'AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $rs = $db->arrayQuery("SELECT ezkeyword.keyword, count(*) as keyword_count\n FROM ezkeyword,\n ezkeyword_attribute_link,\n ezcontentobject,\n ezcontentobject_attribute,\n ezcontentobject_tree\n {$sqlPermissionChecking['from']}\n WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND ezcontentobject_attribute.contentobject_id = ezcontentobject_tree.contentobject_id\n AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n AND ezcontentobject.status = " . eZContentObject::STATUS_PUBLISHED . "\n AND ezcontentobject_attribute.version = ezcontentobject.current_version\n AND ezcontentobject_tree.main_node_id = ezcontentobject_tree.node_id\n {$pathString}\n {$parentNodeIDSQL}\n {$classIdentifierSQL}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n GROUP BY ezkeyword.id, ezkeyword.keyword\n {$orderBySql}", $dbParams); foreach ($rs as $row) { $tags[$row['keyword']] = $row['keyword_count']; } $maxFontSize = 200; $minFontSize = 100; $maxCount = 0; $minCount = 0; if (count($tags) != 0) { $maxCount = max(array_values($tags)); $minCount = min(array_values($tags)); } $spread = $maxCount - $minCount; if ($spread == 0) { $spread = 1; } $step = ($maxFontSize - $minFontSize) / $spread; // stevo - combine lower/upper case $realTags = array(); $realkey = ''; foreach ($tags as $key => $value) { $key = strtolower($key); if (isset($realTags[$key])) { $realTags[$key] += $value; } else { $realTags[$key] = $value; } } // stevo - add minimum tag count option $min = isset($params['min']) ? $params['min'] : 0; //$minCount -= $min; foreach ($realTags as $key => $value) { if ($value > $min) { $size = $minFontSize + ($value - $minCount) * $step; $tagCloud[] = array('font_size' => $size, 'count' => $value, 'tag' => $key); } } require_once 'kernel/common/template.php'; $tpl = templateInit(); $tpl->setVariable('tag_cloud', $tagCloud); $operatorValue = $tpl->fetch('design:tagcloud/tagcloud.tpl'); break; } }