本文整理汇总了PHP中K2HelperUtilities::wordLimit方法的典型用法代码示例。如果您正苦于以下问题:PHP K2HelperUtilities::wordLimit方法的具体用法?PHP K2HelperUtilities::wordLimit怎么用?PHP K2HelperUtilities::wordLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类K2HelperUtilities
的用法示例。
在下文中一共展示了K2HelperUtilities::wordLimit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLatestComments
public static function getLatestComments($params)
{
$model = K2Model::getInstance('Comments');
$model->setState('filter.items', true);
$model->setState('state', 1);
$filter = $params->get('category_id');
if ($filter && isset($filter->enabled) && $filter->enabled) {
$model->setState('category', $filter->categories);
}
$model->setState('limit', (int) $params->get('comments_limit', '5'));
$model->setState('sorting', 'id.reverse');
$comments = $model->getRows();
foreach ($comments as $comment) {
if ((int) $params->get('comments_word_limit')) {
$comment->text = K2HelperUtilities::wordLimit($comment->text, $params->get('comments_word_limit'));
}
$comment->user->displayName = $params->get('commenterName', 1) == 2 ? $comment->user->username : $comment->user->name;
}
return $comments;
}
示例2:
echo $user->name;
?>
</a>
<?php
}
?>
<?php
if ($params->get('userDescription') && $user->description) {
?>
<div class="ubUserDescription">
<?php
if ($params->get('userDescriptionWordLimit')) {
?>
<?php
echo K2HelperUtilities::wordLimit($user->description, $params->get('userDescriptionWordLimit'));
?>
<?php
} else {
?>
<?php
echo $user->description;
?>
<?php
}
?>
</div>
<?php
}
?>
示例3: prepareFeedItem
function prepareFeedItem(&$item)
{
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
$params =& JComponentHelper::getParams('com_k2');
$limitstart = 0;
//Category
$category =& JTable::getInstance('K2Category', 'Table');
$category->load($item->catid);
$item->category = $category;
//Read more link
$item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid . ':' . urlencode($item->category->alias))));
//Filtering
if ($params->get('introTextCleanup')) {
$filterTags = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupExcludeTags')));
$filterAttrs = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupTagAttr')));
$filter = new JFilterInput($filterTags, $filterAttrs, 0, 1);
$item->introtext = $filter->clean($item->introtext);
}
if ($params->get('fullTextCleanup')) {
$filterTags = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupExcludeTags')));
$filterAttrs = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupTagAttr')));
$filter = new JFilterInput($filterTags, $filterAttrs, 0, 1);
$item->fulltext = $filter->clean($item->fulltext);
}
//Description
$item->description = '';
//Item image
if ($params->get('feedItemImage') && JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_' . $params->get('feedImgSize') . '.jpg')) {
$item->description .= '<div class="K2FeedImage"><img src="' . JURI::root() . '/media/k2/items/cache/' . md5('Image' . $item->id) . '_' . $params->get('feedImgSize') . '.jpg" alt="' . $item->title . '"/></div>';
}
//Item Introtext
if ($params->get('feedItemIntroText')) {
//Introtext word limit
if ($params->get('feedTextWordLimit')) {
$item->introtext = K2HelperUtilities::wordLimit($item->introtext, $params->get('feedTextWordLimit'));
}
$item->description .= '<div class="K2FeedIntroText">' . $item->introtext . '<div>';
}
//Item Fulltext
if ($params->get('feedItemFullText')) {
$item->description .= '<div class="K2FeedFullText">' . $item->fulltext . '<div>';
}
//Author
if (!empty($item->created_by_alias)) {
$item->author->name = $item->created_by_alias;
} else {
$author = JFactory::getUser($item->created_by);
$item->author = $author;
$item->author->link = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
$item->author->profile = K2ModelItem::getUserProfile($item->created_by);
}
return $item;
}
示例4: getItems
//.........这里部分代码省略.........
break;
case 'best':
$orderby = 'rating DESC';
break;
case 'comments':
if ($params->get('popularityRange')) {
$datenow = JFactory::getDate();
$date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql();
$query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) ";
}
$query .= " GROUP BY i.id ";
$orderby = 'numOfComments DESC';
break;
case 'modified':
$orderby = 'lastChanged DESC';
break;
case 'publishUp':
$orderby = 'i.publish_up DESC';
break;
default:
$orderby = 'i.id DESC';
break;
}
$query .= " ORDER BY " . $orderby;
$db->setQuery($query, 0, $limit);
$items = $db->loadObjectList();
}
$model = K2Model::getInstance('Item', 'K2Model');
if (count($items)) {
foreach ($items as $item) {
//Clean title
$item->title = JFilterOutput::ampReplace($item->title);
//Images
if ($params->get('itemImage')) {
$date = JFactory::getDate($item->modified);
$timestamp = '?t=' . $date->toUnix();
if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) {
$item->imageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageXSmall .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
$item->imageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageSmall .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) {
$item->imageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageMedium .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
$item->imageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageLarge .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) {
$item->imageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageXLarge .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) {
$item->imageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageGeneric .= $timestamp;
}
}
$image = 'image' . $params->get('itemImgSize', 'Small');
if (isset($item->{$image})) {
$item->image = $item->{$image};
}
}
//Read more link
$item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
//Category link
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// Introtext
$item->text = '';
if ($params->get('itemIntroText')) {
// Word limit
if ($params->get('itemIntroTextWordLimit')) {
$item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
} else {
$item->text .= $item->introtext;
}
}
// Restore the intotext variable after plugins execution
$item->introtext = $item->text;
//Clean the plugin tags
$item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext);
$rows[] = $item;
}
return $rows;
}
}
示例5: prepareFeedItem
function prepareFeedItem(&$item){
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
$params = & JComponentHelper::getParams('com_k2');
$limitstart=0;
//Category
$category = & JTable::getInstance('K2Category', 'Table');
$category->load($item->catid);
$item->category=$category;
//Read more link
$item->link=urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id.':'.$item->alias,$item->catid.':'.urlencode($item->category->alias))));
//Filtering
if ($params->get('introTextCleanup')){
$filterTags = preg_split( '#[,\s]+#', trim( $params->get( 'introTextCleanupExcludeTags' ) ) );
$filterAttrs = preg_split( '#[,\s]+#', trim( $params->get( 'introTextCleanupTagAttr' ) ) );
$filter = new JFilterInput( $filterTags, $filterAttrs, 0, 1 );
$item->introtext= $filter->clean( $item->introtext );
}
if ($params->get('fullTextCleanup')){
$filterTags = preg_split( '#[,\s]+#', trim( $params->get( 'fullTextCleanupExcludeTags' ) ) );
$filterAttrs = preg_split( '#[,\s]+#', trim( $params->get( 'fullTextCleanupTagAttr' ) ) );
$filter = new JFilterInput( $filterTags, $filterAttrs, 0, 1 );
$item->fulltext= $filter->clean( $item->fulltext );
}
//Description
$item->description = '';
//Item image
if ($params->get('feedItemImage') && JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_'.$params->get('feedImgSize').'.jpg')){
$item->description.= '<div class="K2FeedImage"><img src="'.JURI::root().'/media/k2/items/cache/'.md5('Image'.$item->id).'_'.$params->get('feedImgSize').'.jpg" alt="'.$item->title.'" /></div>';
}
//Item Introtext
if($params->get('feedItemIntroText')){
//Introtext word limit
if ($params->get('feedTextWordLimit') && $item->introtext){
$item->introtext=K2HelperUtilities::wordLimit($item->introtext,$params->get('feedTextWordLimit'));
}
$item->description.= '<div class="K2FeedIntroText">'.$item->introtext.'</div>';
}
//Item Fulltext
if($params->get('feedItemFullText') && $item->fulltext){
$item->description.= '<div class="K2FeedFullText">'.$item->fulltext.'</div>';
}
//Item Tags
if($params->get('feedItemTags')){
$tags = K2ModelItem::getItemTags($item->id);
if(count($tags)){
$item->description.='<div class="K2FeedTags"><ul>';
foreach($tags as $tag){
$item->description.='<li>'.$tag->name.'</li>';
}
$item->description.='<ul></div>';
}
}
//Item Video
if($params->get('feedItemVideo') && $item->video){
if (!empty($item->video) && JString::substr($item->video, 0, 1) !== '{') {
$item->description.= '<div class="K2FeedVideo">'.$item->video.'</div>';
}
else {
$params->set('vfolder', 'media/k2/videos');
if(JString::strpos($item->video, 'remote}')){
preg_match("#}(.*?){/#s",$item->video, $matches);
if(!JString::strpos($matches[1], 'http://}'))
$item->video = str_replace($matches[1], JURI::root().$matches[1], $item->video);
}
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin ('content');
$item->text=$item->video;
$dispatcher->trigger ( 'onPrepareContent', array (&$item, &$params, $limitstart ) );
$item->description.= '<div class="K2FeedVideo">'.$item->text.'</div>';
}
}
//Item gallery
if($params->get('feedItemGallery') && $item->gallery){
$params->set('galleries_rootfolder', 'media/k2/galleries');
$params->set('popup_engine', 'mootools_slimbox');
$params->set('enabledownload', '0');
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin ('content');
$item->text=$item->gallery;
$dispatcher->trigger ( 'onPrepareContent', array (&$item, &$params, $limitstart ) );
$item->description.= '<div class="K2FeedGallery">'.$item->text.'</div>';
}
//Item attachments
if($params->get('feedItemAttachments')){
$attachments = K2ModelItem::getItemAttachments($item->id);
if(count($attachments)){
$item->description.='<div class="K2FeedAttachments"><ul>';
//.........这里部分代码省略.........
示例6: getLatestComments
public static function getLatestComments(&$params)
{
$mainframe = JFactory::getApplication();
$limit = $params->get('comments_limit', '5');
$user = JFactory::getUser();
$aid = $user->get('aid');
$db = JFactory::getDBO();
$cid = $params->get('category_id', NULL);
$jnow = JFactory::getDate();
$now = K2_JVERSION != '15' ? $jnow->toSql() : $jnow->toMySQL();
$nullDate = $db->getNullDate();
$model = K2Model::getInstance('Item', 'K2Model');
$componentParams = JComponentHelper::getParams('com_k2');
$query = "SELECT c.*, i.catid, i.title, i.alias, category.alias as catalias, category.name as categoryname\n\t\tFROM #__k2_comments as c\n\t\tLEFT JOIN #__k2_items as i ON i.id=c.itemID\n\t\tLEFT JOIN #__k2_categories as category ON category.id=i.catid\n\t\tWHERE i.published=1\n\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\tAND i.trash=0 ";
if (K2_JVERSION != '15') {
$query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
} else {
$query .= " AND i.access<={$aid} ";
}
$query .= " AND category.published=1 AND category.trash=0 ";
if (K2_JVERSION != '15') {
$query .= " AND category.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
} else {
$query .= " AND category.access<={$aid} ";
}
$query .= " AND c.published=1 ";
if ($params->get('catfilter')) {
if (!is_null($cid)) {
if (is_array($cid)) {
JArrayHelper::toInteger($cid);
$query .= " AND i.catid IN(" . implode(',', $cid) . ")";
} else {
$query .= " AND i.catid=" . (int) $cid;
}
}
}
if (K2_JVERSION != '15') {
if ($mainframe->getLanguageFilter()) {
$languageTag = JFactory::getLanguage()->getTag();
$query .= " AND category.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")";
}
}
$query .= " ORDER BY c.commentDate DESC ";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
if (count($rows)) {
foreach ($rows as $row) {
if ($params->get('commentDateFormat') == 'relative') {
$config = JFactory::getConfig();
$tzoffset = K2_JVERSION == '30' ? $config->get('config.offset') : $config->getValue('config.offset');
$now = new JDate();
$now->setOffset($tzoffset);
$created = new JDate($row->commentDate);
$diff = $now->toUnix() - $created->toUnix();
$dayDiff = floor($diff / 86400);
if ($dayDiff == 0) {
if ($diff < 5) {
$row->commentDate = JText::_('K2_JUST_NOW');
} elseif ($diff < 60) {
$row->commentDate = $diff . ' ' . JText::_('K2_SECONDS_AGO');
} elseif ($diff < 120) {
$row->commentDate = JText::_('K2_1_MINUTE_AGO');
} elseif ($diff < 3600) {
$row->commentDate = floor($diff / 60) . ' ' . JText::_('K2_MINUTES_AGO');
} elseif ($diff < 7200) {
$row->commentDate = JText::_('K2_1_HOUR_AGO');
} elseif ($diff < 86400) {
$row->commentDate = floor($diff / 3600) . ' ' . JText::_('K2_HOURS_AGO');
}
}
}
$row->commentText = K2HelperUtilities::wordLimit($row->commentText, $params->get('comments_word_limit'));
$row->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $row->commentText);
$row->itemLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->itemID . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->catalias))));
$row->link = $row->itemLink . "#comment{$row->id}";
$row->catLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->catid . ':' . urlencode($row->catalias))));
if ($row->userID > 0) {
$row->userLink = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
$getExistingUser = JFactory::getUser($row->userID);
$row->userUsername = $getExistingUser->username;
} else {
$row->userUsername = $row->userName;
}
// Switch between commenter name and username
if ($params->get('commenterName', 1) == 2) {
$row->userName = $row->userUsername;
}
$row->userImage = '';
if ($params->get('commentAvatar')) {
$row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
}
$comments[] = $row;
}
return $comments;
}
}
示例7:
<!-- K2 Plugins: K2BeforeDisplayContent -->
<?php
echo $this->item->event->K2BeforeDisplayContent;
?>
<?php
if ($this->item->params->get('catItemIntroText')) {
?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php
if ($this->item->params->get('catItemIntroTextWordLimit') > 1) {
echo K2HelperUtilities::wordLimit($this->item->introtext, $this->item->params->get('catItemIntroTextWordLimit') - 1, '');
} else {
echo $this->item->introtext;
}
?>
</div>
<?php
}
?>
<aside class="article-aside">
<dl class="article-info muted">
<dt></dt>
<!-- Item Author -->
<?php
if ($this->item->params->get('catItemAuthor')) {
?>
示例8: getItems
public static function getItems($params)
{
// Component params
$componentParams = JComponentHelper::getParams('com_k2');
// Get model
$model = K2Model::getInstance('Items');
// Set site state
$model->setState('site', true);
// Set states depending on source
if ($params->get('source') == 'specific') {
$items = array();
if ($params->get('items')) {
$itemIds = array_filter((array) $params->get('items'));
if (count($itemIds)) {
// Apply sorting
foreach ($itemIds as $itemId) {
// Fetch item
$model->setState('id', $itemId);
$items[] = $model->getRow();
}
}
}
} else {
// Category filter
$model->setState('category.filter', $params->get('filter'));
// Featured
if ($params->get('featured') == 2) {
$model->setState('featured', 1);
} else {
if ($params->get('featured') == 0) {
$model->setState('featured', 0);
}
}
// Set time range if sorting is comments or hits
if ($params->get('timeRange') && ($params->get('sorting') == 'comments' || $params->get('sorting') == 'hits')) {
$now = JFactory::getDate();
switch ($params->get('timeRange')) {
case '1':
$interval = 'P1D';
break;
case '3':
$interval = 'P3D';
break;
case '7':
$interval = 'P1W';
break;
case '15':
$interval = 'P2W';
break;
case '30':
$interval = 'P1M';
break;
case '90':
$interval = 'P3M';
break;
case '180':
$interval = 'P6M';
break;
}
$date = $now->sub(new DateInterval($interval));
$model->setState('created.value', $date->toSql());
$model->setState('created.operator', '>');
}
// Fetch only items with media
if ($params->get('media')) {
$model->setState('media', true);
}
// Set limit
$model->setState('limit', $params->get('limit'));
// Set sorting
$model->setState('sorting', $params->get('sorting'));
// Get items
$items = $model->getRows();
}
// Prepare data
foreach ($items as $item) {
// Plugins
$item->events = $item->getEvents('mod_k2_content', $params, 0, $params->get('k2Plugins'), $params->get('jPlugins'));
// Introtext word limit
if ($params->get('itemIntroTextWordLimit')) {
$item->introtext = K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
}
// Set the selected image as default
$item->image = $item->getImage($params->get('itemImgSize'));
}
// Load the comments counters in a single query for all items
if ($params->get('itemCommentsCounter') && $componentParams->get('comments')) {
K2Items::countComments($items);
}
// Set the avatar width if it's inherited from component settings
if ($params->get('itemAuthorAvatarWidthSelect') == 'custom') {
$params->set('itemAuthorAvatarWidth', $componentParams->get('userImageWidth'));
}
// Set the custom link url if user has selected a menu link item
if ($params->get('itemCustomLinkMenuItem') && $params->get('itemCustomLink')) {
$application = JFactory::getApplication();
$menu = $application->getMenu();
$menuLink = $menu->getItem($params->get('itemCustomLinkMenuItem'));
if ($menuLink) {
if (!$params->get('itemCustomLinkTitle')) {
//.........这里部分代码省略.........
示例9:
px; height:auto;" />
</a>
</span>
<div class="clr"></div>
</div>
<?php
}
?>
<?php
if ($item->params->get('tagItemIntroText', 1)) {
?>
<!-- Item introtext -->
<div class="tagItemIntroText">
<?php
echo $item->introtext = K2HelperUtilities::wordLimit(20);
?>
</div>
<?php
}
?>
<div class="clr"></div>
</div>
<div class="clr"></div>
<?php
if ($item->params->get('tagItemExtraFields', 0) && count($item->extra_fields)) {
?>
<!-- Item extra fields -->
示例10:
?>
<?php
}
?>
</div>
<?php
}
?>
<?php
if ($params->get('itemIntroText')) {
?>
<div class="moduleItemIntrotext">
<?php
echo $params->get('itemIntroTextWordLimit') > 1 ? K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit') - 1, '') : $item->introtext;
?>
</div>
<?php
}
?>
<?php
if ($params->get('itemExtraFields') && count($item->extra_fields)) {
?>
<div class="moduleItemExtraFields">
<b><?php
echo JText::_('K2_ADDITIONAL_INFO');
?>
</b>
<ul>
示例11: display
//.........这里部分代码省略.........
}
// Prepare item
if ($cacheFlag)
{
$hits = $items[$i]->hits;
$items[$i]->hits = 0;
JTable::getInstance('K2Category', 'Table');
$items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task);
$items[$i]->hits = $hits;
}
else
{
$items[$i] = $model->prepareItem($items[$i], $view, $task);
}
*/
// JA K2 Filter: PrepareItem
$items[$i] = $model->prepareItem($items[$i], $view, '');
// Plugins
$items[$i]->params->set('genericItemIntroText', $params->get('catItemIntroText'));
$items[$i]->params->set('catItemK2Plugins', $params->get('catItemK2Plugins'));
$items[$i] = $model->execPlugins($items[$i], 'itemlist', '');
// Trigger comments counter event
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
$items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
//JA K2 FILTER - CUSTOM VIEW OPTIONS
$items[$i]->params->merge($params);
if (!is_array($items[$i]->extra_fields)) {
$items[$i]->extra_fields = $model->getItemExtraFields($items[$i]->extra_fields, $items[$i]);
}
if ($params->get('catItemIntroTextWordLimit')) {
$items[$i]->introtext = K2HelperUtilities::wordLimit($items[$i]->introtext, $params->get('catItemIntroTextWordLimit'));
}
//JA K2 FILTER - CUSTOM VIEW OPTIONS - AUTHOR
if (!empty($items[$i]->created_by_alias)) {
$items[$i]->author = new stdClass();
$items[$i]->author->name = $items[$i]->created_by_alias;
$items[$i]->author->avatar = K2HelperUtilities::getAvatar('alias');
$items[$i]->author->link = JURI::root();
} else {
$author = JFactory::getUser($items[$i]->created_by);
$items[$i]->author = $author;
$items[$i]->author->link = JRoute::_(K2HelperRoute::getUserRoute($items[$i]->created_by));
$items[$i]->author->profile = $model->getUserProfile($items[$i]->created_by);
$items[$i]->author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $params->get('userImageWidth'));
}
if (!isset($items[$i]->author->profile) || is_null($items[$i]->author->profile)) {
$items[$i]->author->profile = new JObject();
$items[$i]->author->profile->gender = NULL;
}
//JA K2 FILTER - CUSTOM VIEW OPTIONS - RATING
$items[$i]->votingPercentage = $model->getVotesPercentage($items[$i]->id);
$items[$i]->numOfvotes = $model->getVotesNum($items[$i]->id);
}
// Set title
$document = JFactory::getDocument();
$application = JFactory::getApplication();
$menus = $application->getMenu();
$menu = $menus->getActive();
if (is_object($menu)) {
if (is_string($menu->params)) {
$menu_params = K2_JVERSION == '15' ? new JParameter($menu->params) : new JRegistry($menu->params);
} else {
$menu_params = $menu->params;
示例12: getItems
//.........这里部分代码省略.........
if ($params->get('itemExtraFields')) {
$item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
}
//Comments counter
if ($params->get('itemCommentsCounter')) {
$item->numOfComments = $model->countItemComments($item->id);
}
//Attachments
if ($params->get('itemAttachments')) {
$item->attachments = $model->getItemAttachments($item->id);
}
//Import plugins
if ($format != 'feed') {
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
}
//Video
if ($params->get('itemVideo') && $format != 'feed') {
$params->set('vfolder', 'media/k2/videos');
$params->set('afolder', 'media/k2/audio');
$item->text = $item->video;
if (K2_JVERSION == '15') {
$dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
} else {
$dispatcher->trigger('onContentPrepare', array('mod_k2_content.', &$item, &$params, $limitstart));
}
$item->video = $item->text;
}
// Introtext
$item->text = '';
if ($params->get('itemIntroText')) {
// Word limit
if ($params->get('itemIntroTextWordLimit')) {
$item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
} else {
$item->text .= $item->introtext;
}
}
if ($format != 'feed') {
$params->set('parsedInModule', 1);
// for plugins to know when they are parsed inside this module
$item->event = new stdClass();
$item->event->BeforeDisplay = '';
$item->event->AfterDisplay = '';
$item->event->AfterDisplayTitle = '';
$item->event->BeforeDisplayContent = '';
$item->event->AfterDisplayContent = '';
if ($params->get('JPlugins', 1)) {
//Plugins
if (K2_JVERSION != '15') {
$item->event->BeforeDisplay = '';
$item->event->AfterDisplay = '';
$dispatcher->trigger('onContentPrepare', array('mod_k2_content', &$item, &$params, $limitstart));
$results = $dispatcher->trigger('onContentAfterTitle', array('mod_k2_content', &$item, &$params, $limitstart));
$item->event->AfterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentBeforeDisplay', array('mod_k2_content', &$item, &$params, $limitstart));
$item->event->BeforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentAfterDisplay', array('mod_k2_content', &$item, &$params, $limitstart));
$item->event->AfterDisplayContent = trim(implode("\n", $results));
} else {
$results = $dispatcher->trigger('onBeforeDisplay', array(&$item, &$params, $limitstart));
$item->event->BeforeDisplay = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplay', array(&$item, &$params, $limitstart));
$item->event->AfterDisplay = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
$item->event->AfterDisplayTitle = trim(implode("\n", $results));
示例13: getItems
public static function getItems(&$params)
{
jimport('joomla.filesystem.file');
$mainframe = JFactory::getApplication();
$limit = $params->get('itemCount', 5);
$cid = $params->get('category_id', NULL);
$componentParams = JComponentHelper::getParams('com_k2');
$user = JFactory::getUser();
$db = JFactory::getDBO();
$jnow = JFactory::getDate();
$now = $jnow->toSql();
$nullDate = $db->getNullDate();
$query = "SELECT i.*,";
$query .= "c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
$query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid";
$query .= " WHERE i.published = 1 AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND c.trash = 0";
$query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
$query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
if ($params->get('catfilter')) {
if (!is_null($cid)) {
if (is_array($cid)) {
$itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
$categories = $itemListModel->getCategoryTree($cid);
$sql = @implode(',', $categories);
$query .= " AND i.catid IN ({$sql})";
} else {
$itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
$categories = $itemListModel->getCategoryTree($cid);
$sql = @implode(',', $categories);
$query .= " AND i.catid IN ({$sql})";
}
}
}
$query .= " AND i.featured = 1";
$query .= " ORDER BY i.created DESC";
$db->setQuery($query, 0, $limit);
$items = $db->loadObjectList();
$model = K2Model::getInstance('Item', 'K2Model');
if (count($items)) {
foreach ($items as $item) {
$item->event = new stdClass();
//Clean title
$item->title = JFilterOutput::ampReplace($item->title);
//Images
$date = JFactory::getDate($item->modified);
$timestamp = '?t=' . $date->toUnix();
if (JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg')) {
$item->imageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageXSmall .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg')) {
$item->imageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageSmall .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg')) {
$item->imageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageMedium .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg')) {
$item->imageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageLarge .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg')) {
$item->imageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageXLarge .= $timestamp;
}
}
if (JFile::exists(JPATH_SITE . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg')) {
$item->imageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg';
if ($componentParams->get('imageTimestamp')) {
$item->imageGeneric .= $timestamp;
}
}
$image = 'image' . $params->get('itemImgSize', 'Small');
if (isset($item->{$image})) {
$item->image = $item->{$image};
} else {
$item->image = JURI::base(true) . '/modules/mod_sp_k2_featured_slider/assets/images/no-image.png';
}
//Read more link
$item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
//Category link
if ($params->get('itemCategory')) {
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
}
// Introtext
$item->text = '';
if ($params->get('itemIntroText')) {
// Word limit
if ($params->get('itemIntroTextWordLimit')) {
$item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
//.........这里部分代码省略.........
示例14: getLatestComments
function getLatestComments(&$params)
{
$limit = $params->get('comments_limit', '5');
$user =& JFactory::getUser();
$aid = $user->get('aid');
$db =& JFactory::getDBO();
$cid = $params->get('category_id', NULL);
$jnow =& JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $db->getNullDate();
require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php';
$model = new K2ModelItem();
$componentParams =& JComponentHelper::getParams('com_k2');
$query = "SELECT c.*, i.catid, i.title, i.alias, category.alias as catalias, category.name as categoryname FROM #__k2_comments as c" . " LEFT JOIN #__k2_items as i ON i.id=c.itemID" . " LEFT JOIN #__k2_categories as category ON category.id=i.catid" . " WHERE i.published=1 " . " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " ) " . " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )" . " AND i.trash=0 AND i.access<={$aid}" . " AND category.published=1 AND category.trash=0 AND category.access<={$aid}" . " AND c.published=1 ";
if ($params->get('catfilter')) {
if (!is_null($cid)) {
if (is_array($cid)) {
JArrayHelper::toInteger($cid);
$query .= " AND i.catid IN(" . implode(',', $cid) . ")";
} else {
$query .= " AND i.catid=" . (int) $cid;
}
}
}
$query .= " ORDER BY c.commentDate DESC ";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
if (count($rows)) {
foreach ($rows as $row) {
if ($params->get('commentDateFormat') == 'relative') {
$config =& JFactory::getConfig();
$tzoffset = $config->getValue('config.offset');
$now = new JDate();
$now->setOffset($tzoffset);
$created = new JDate($row->commentDate);
$diff = $now->toUnix() - $created->toUnix();
$dayDiff = floor($diff / 86400);
if ($dayDiff == 0) {
if ($diff < 5) {
$row->commentDate = JText::_('Just Now');
} elseif ($diff < 60) {
$row->commentDate = $diff . ' ' . JText::_('Seconds ago');
} elseif ($diff < 120) {
$row->commentDate = JText::_('1 Minute Ago');
} elseif ($diff < 3600) {
$row->commentDate = floor($diff / 60) . ' ' . JText::_('Minutes Ago');
} elseif ($diff < 7200) {
$row->commentDate = JText::_('1 Hour Ago');
} elseif ($diff < 86400) {
$row->commentDate = floor($diff / 3600) . ' ' . JText::_('Hours Ago');
}
}
}
$row->commentText = K2HelperUtilities::wordLimit($row->commentText, $params->get('comments_word_limit'));
$row->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $row->commentText);
$row->itemLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->itemID . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->catalias))));
$row->link = $row->itemLink . "#comment{$row->id}";
$row->catLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->catid . ':' . urlencode($row->catalias))));
if ($row->userID > 0) {
$row->userLink = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
}
$row->userImage = '';
if ($params->get('commentAvatar')) {
$row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
}
$comments[] = $row;
}
return $comments;
}
}
示例15: getItems
//.........这里部分代码省略.........
//Category link
if ($params->get('itemCategory')) {
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
}
//Extra fields
if ($params->get('itemExtraFields')) {
$item->extra_fields = $model->getItemExtraFields($item->extra_fields);
}
//Comments counter
if ($params->get('itemCommentsCounter')) {
$item->numOfComments = $model->countItemComments($item->id);
}
//Attachments
if ($params->get('itemAttachments')) {
$item->attachments = $model->getItemAttachments($item->id);
}
//Import plugins
if ($format != 'feed') {
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
}
//Video
if ($params->get('itemVideo') && $format != 'feed') {
$params->set('vfolder', 'media/k2/videos');
$item->text = $item->video;
$dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
$item->video = $item->text;
}
// Introtext
$item->text = '';
if ($params->get('itemIntroText')) {
// Word limit
if ($params->get('itemIntroTextWordLimit')) {
$item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
} else {
$item->text .= $item->introtext;
}
}
if ($format != 'feed') {
$params->set('parsedInModule', 1);
// for plugins to know when they are parsed inside this module
if ($params->get('JPlugins', 1)) {
//Plugins
$results = $dispatcher->trigger('onBeforeDisplay', array(&$item, &$params, $limitstart));
$item->event->BeforeDisplay = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplay', array(&$item, &$params, $limitstart));
$item->event->AfterDisplay = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
$item->event->AfterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onBeforeDisplayContent', array(&$item, &$params, $limitstart));
$item->event->BeforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
$item->event->AfterDisplayContent = trim(implode("\n", $results));
$dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
$item->introtext = $item->text;
}
//Init K2 plugin events
$item->event->K2BeforeDisplay = '';
$item->event->K2AfterDisplay = '';
$item->event->K2AfterDisplayTitle = '';
$item->event->K2BeforeDisplayContent = '';
$item->event->K2AfterDisplayContent = '';
$item->event->K2CommentsCounter = '';
if ($params->get('K2Plugins', 1)) {
//K2 plugins
JPluginHelper::importPlugin('k2');