当前位置: 首页>>代码示例>>PHP>>正文


PHP DiscussHelper::getDurationString方法代码示例

本文整理汇总了PHP中DiscussHelper::getDurationString方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussHelper::getDurationString方法的具体用法?PHP DiscussHelper::getDurationString怎么用?PHP DiscussHelper::getDurationString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DiscussHelper的用法示例。


在下文中一共展示了DiscussHelper::getDurationString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getSimilarPosts

 public static function getSimilarPosts($postId, $params)
 {
     $db = DiscussHelper::getDBO();
     $post = DiscussHelper::getTable('Posts');
     $post->load($postId);
     $title = $post->title;
     $categoryId = $post->category_id;
     $search = trim($title);
     if (empty($title)) {
         return array();
     }
     $limit = (int) $params->get('count', 5);
     $search = preg_replace("/(?![.=\$'â‚-])\\p{P}/u", "", $search);
     $numwords = explode(' ', $search);
     //$fulltextType 	= ( $numwords <= 2 ) ? ' WITH QUERY EXPANSION' : '';
     $fulltextType = ' WITH QUERY EXPANSION';
     // get the total score and count.
     $query = 'select count(a.`id`) as totalcnt , sum( MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($search) . $fulltextType . ') ) as totalscore';
     $query .= ' FROM `#__discuss_posts` as a';
     $query .= ' WHERE MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($search) . $fulltextType . ')';
     $query .= ' AND a.`published` = ' . $db->Quote('1');
     $query .= ' AND a.`parent_id` = ' . $db->Quote('0');
     if ($params->get('resolved_only', 0)) {
         $query .= ' AND a.`isresolve` = 1';
     }
     $query .= ' AND a.`category_id` = ' . $db->Quote($categoryId);
     $query .= ' and a.`id` != ' . $db->Quote($postId);
     $db->setQuery($query);
     $totalData = $db->loadObject();
     //var_dump( $totalData );
     $totalScore = $totalData->totalscore;
     $totalItem = round($totalData->totalcnt);
     //$db->setQuery( $query );
     $result = array();
     if ($totalItem) {
         $date = DiscussHelper::getDate();
         // now try to get the main topic
         $query = 'SELECT DATEDIFF(' . $db->Quote($date->toMySQL()) . ', a.`created`) as `noofdays`, ';
         $query .= ' DATEDIFF(' . $db->Quote($date->toMySQL()) . ', a.`created`) as `daydiff`, TIMEDIFF(' . $db->Quote($date->toMySQL()) . ', a.`created`) as `timediff`';
         $query .= ', a.`id`,  a.`title`, MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($search) . $fulltextType . ') AS score';
         $query .= ', b.`id` as `category_id`, b.`title` as `category_name`';
         $query .= ' FROM `#__discuss_posts` as a';
         $query .= ' inner join `#__discuss_category` as b ON a.category_id = b.id';
         $query .= ' WHERE MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($search) . $fulltextType . ')';
         $query .= ' AND a.`published` = ' . $db->Quote('1');
         $query .= ' AND a.`parent_id` = ' . $db->Quote('0');
         // Hack by mark
         $query .= ' AND a.`category_id` = ' . $db->Quote($categoryId);
         if ($params->get('resolved_only', 0)) {
             $query .= ' AND a.`isresolve` = 1';
         }
         $query .= ' and a.`id` != ' . $db->Quote($postId);
         $query .= ' ORDER BY score DESC';
         $query .= ' LIMIT ' . $limit;
         // echo $query;
         //exit;
         $db->setQuery($query);
         $result = $db->loadObjectList();
         for ($i = 0; $i < count($result); $i++) {
             $item =& $result[$i];
             $score = round($item->score) * 100 / $totalScore;
             $item->score = $score;
             //get post duration so far.
             $durationObj = new stdClass();
             $durationObj->daydiff = $item->daydiff;
             $durationObj->timediff = $item->timediff;
             $item->duration = DiscussHelper::getDurationString($durationObj);
         }
     }
     //var_dump( $result );
     //exit;
     return $result;
 }
开发者ID:pguilford,项目名称:vcomcc,代码行数:73,代码来源:helper.php

示例2: formatComments

 public static function formatComments($comments)
 {
     $config = DiscussHelper::getConfig();
     if (!$comments) {
         return false;
     }
     $result = array();
     foreach ($comments as $row) {
         $duration = new StdClass();
         $duration->daydiff = $row->daydiff;
         $duration->timediff = $row->timediff;
         $comment = DiscussHelper::getTable('Comment');
         $comment->bind($row);
         $comment->duration = DiscussHelper::getDurationString($duration);
         $creator = DiscussHelper::getTable('Profile');
         $creator->load($comment->user_id);
         $comment->creator = $creator;
         if ($config->get('main_content_trigger_comments')) {
             // process content plugins
             $comment->content = $comment->comment;
             DiscussEventsHelper::importPlugin('content');
             DiscussEventsHelper::onContentPrepare('comment', $comment);
             $comment->event = new stdClass();
             $results = DiscussEventsHelper::onContentBeforeDisplay('comment', $comment);
             $comment->event->beforeDisplayContent = trim(implode("\n", $results));
             $results = DiscussEventsHelper::onContentAfterDisplay('comment', $comment);
             $comment->event->afterDisplayContent = trim(implode("\n", $results));
             $comment->comment = $comment->content;
             unset($comment->content);
             $comment->comment = DiscussHelper::wordFilter($comment->comment);
         }
         $result[] = $comment;
     }
     return $result;
 }
开发者ID:pguilford,项目名称:vcomcc,代码行数:35,代码来源:helper.php

示例3: save

 /**
  * Responsible to process a comment for saving.
  *
  * @since	3.0
  * @access	public
  */
 public function save()
 {
     $id = JRequest::getInt('id', 0);
     $my = JFactory::getUser();
     $acl = DiscussHelper::getHelper('ACL');
     $ajax = DiscussHelper::getHelper('Ajax');
     $config = DiscussHelper::getConfig();
     // Load the post item.
     $post = DiscussHelper::getTable('Post');
     $state = $post->load($id);
     // Test if a valid post id is provided.
     if (!$id || !$state) {
         $ajax->reject(JText::_('COM_EASYDISCUSS_COMMENTS_INVALID_POST_ID'));
         return $ajax->send();
     }
     $category = DiscussHelper::getTable('Category');
     $category->load($post->category_id);
     $access = $post->getAccess($category);
     // Test if the user is allowed to add comment or not.
     if (!$access->canComment()) {
         $ajax->reject(JText::_('COM_EASYDISCUSS_COMMENTS_NOT_ALLOWED'));
         return $ajax->send();
     }
     // Test if the comment message exists.
     $message = JRequest::getVar('comment', '');
     if (empty($message)) {
         $ajax->reject(JText::_('COM_EASYDISCUSS_COMMENT_IS_EMPTY'));
     }
     // Test if the user checked the terms and conditions box.
     if ($config->get('main_comment_tnc')) {
         $acceptedTerms = JRequest::getInt('tnc', 0);
         if (!$acceptedTerms) {
             $ajax->reject(JText::_('COM_EASYDISCUSS_TERMS_PLEASE_ACCEPT'));
             return $ajax->send();
         }
     }
     // Load user profile's object.
     $profile = DiscussHelper::getTable('Profile');
     $profile->load($my->id);
     // Build up comment object.
     $commentData = new stdClass();
     $commentData->user_id = $my->id;
     $commentData->name = $profile->getName();
     $commentData->email = $my->email;
     $commentData->comment = $message;
     $commentData->post_id = $post->id;
     // Run through akismet screening if necessary.
     if ($config->get('antispam_akismet') && $config->get('antispam_akismet_key')) {
         require_once DISCUSS_CLASSES . '/akismet.php';
         $data = array('author' => $my->name, 'email' => $my->email, 'website' => DISCUSS_JURIROOT, 'body' => $commentData->comment, 'alias' => '');
         $akismet = new Akismet(DISCUSS_JURIROOT, $config->get('antispam_akismet_key'), $data);
         if ($akismet->isSpam()) {
             $ajax->reject(JText::_('COM_EASYDISCUSS_AKISMET_SPAM_DETECTED'));
             return $ajax->send();
         }
     }
     $comment = DiscussHelper::getTable('Comment');
     $comment->bind($commentData, true);
     if (!$comment->store()) {
         $ajax->reject($comment->getError());
         return $ajax->send();
     }
     // Get post duration.
     $durationObj = new stdClass();
     $durationObj->daydiff = 0;
     $durationObj->timediff = '00:00:01';
     $comment->duration = DiscussHelper::getDurationString($durationObj);
     // Set the comment creator.
     $comment->creator = $profile;
     // Try to detect if the comment is posted to the main question or a reply.
     $liveNotificationText = '';
     if ($post->parent_id) {
         $question = DiscussHelper::getTable('Post');
         $question->load($post->parent_id);
         $liveNotificationText = 'COM_EASYDISCUSS_COMMENT_REPLY_NOTIFICATION_TITLE';
     } else {
         $question = DiscussHelper::getTable('Post');
         $question->load($id);
         $liveNotificationText = 'COM_EASYDISCUSS_COMMENT_QUESTION_NOTIFICATION_TITLE';
     }
     // Create notification item in EasySocial
     DiscussHelper::getHelper('EasySocial')->notify('new.comment', $post, $question, $comment);
     if ($comment->published && !$question->private) {
         // AUP integrations
         DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_NEW_COMMENT, $comment->user_id, '');
         // jomsocial activity stream
         DiscussHelper::getHelper('jomsocial')->addActivityComment($post, $question);
         DiscussHelper::getHelper('easysocial')->commentDiscussionStream($comment, $post, $question);
     }
     // Add notification to the post owner.
     if ($post->user_id != $my->id && $comment->published && $config->get('main_notifications_comments')) {
         $notification = DiscussHelper::getTable('Notifications');
         $notification->bind(array('title' => JText::sprintf($liveNotificationText, $question->title), 'cid' => $question->id, 'type' => DISCUSS_NOTIFICATIONS_COMMENT, 'target' => $post->user_id, 'author' => $my->id, 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $question->id));
         $notification->store();
//.........这里部分代码省略.........
开发者ID:BetterBetterBetter,项目名称:B3App,代码行数:101,代码来源:view.ajax.php


注:本文中的DiscussHelper::getDurationString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。