getPublishedArticlesByJournalId($cache->getCacheId()); while ($publishedArticle =& $publishedArticles->next()) { $keywords = array_map('trim', explode(';', $publishedArticle->getLocalizedSubject())); foreach ($keywords as $keyword) if (!empty($keyword)) $keywordMap[$keyword]++; unset($publishedArticle); } arsort($keywordMap, SORT_NUMERIC); $i=0; $newKeywordMap = array(); foreach ($keywordMap as $k => $v) { $newKeywordMap[$k] = $v; if ($i++ >= KEYWORD_BLOCK_MAX_ITEMS) break; } $cache->setEntireCache($newKeywordMap); return $newKeywordMap[$id]; } /** * Get the HTML contents for this block. * @param $templateMgr object * @return $string */ function getContents(&$templateMgr) { $journal =& Request::getJournal(); $cacheManager =& CacheManager::getManager(); $cache =& $cacheManager->getFileCache('keywords_' . AppLocale::getLocale(), $journal->getId(), array(&$this, '_cacheMiss')); // If the cache is older than a couple of days, regenerate it if (time() - $cache->getCacheTime() > 60 * 60 * 24 * KEYWORD_BLOCK_CACHE_DAYS) $cache->flush(); $keywords =& $cache->getContents(); if (empty($keywords)) return ''; // Get the max occurrences for all keywords $maxOccurs = array_shift(array_values($keywords)); // Now sort the array alphabetically ksort($keywords); $templateMgr->assign_by_ref('cloudKeywords', $keywords); $templateMgr->assign_by_ref('maxOccurs', $maxOccurs); return parent::getContents($templateMgr); } } ?>