コード例 #1
0
ファイル: Post.php プロジェクト: shibuya246/Hotaru-Plugins
 /**
  * Count posts in the last X hours/minutes for this user
  *
  * @param int $hours
  * @param int $minutes
  * @param int $user_id (optional)
  * @param int $post_type (optional)
  * @return int 
  */
 public function countPosts($h, $hours = 0, $minutes = 0, $user_id = 0, $post_type = 'news')
 {
     if (!$user_id) {
         $user_id = $h->currentUser->id;
     }
     if ($hours) {
         $time_ago = "-" . $hours . " Hours";
     } else {
         $time_ago = "-" . $minutes . " minutes";
     }
     $start = date('YmdHis', time_block());
     $end = date('YmdHis', strtotime($time_ago));
     $sql = "SELECT COUNT(post_id) FROM " . TABLE_POSTS . " WHERE post_archived = %s AND post_author = %d AND post_type = %s AND (post_date >= %s AND post_date <= %s)";
     $count = $h->db->get_var($h->db->prepare($sql, 'N', $user_id, $post_type, $end, $start));
     return $count;
 }
コード例 #2
0
 /**
  * Prepare list filters
  *
  * @param string $type e.g. latest, upcoming, top-24-hours
  */
 public function prepareListFilters($h, $type = '')
 {
     if ($type == 'new') {
         // Filters page to "new" stories only
         $h->vars['filter']['post_archived = %s'] = 'N';
         $h->vars['filter']['post_status = %s'] = 'new';
         $h->vars['orderby'] = "post_date DESC";
     } elseif ($type == 'upcoming') {
         // Filters page to "new" stories by most votes, but only stories from the last X days!
         $vote_settings = unserialize($h->getSetting('vote_settings', 'vote'));
         $upcoming_duration = "-" . $vote_settings['upcoming_duration'] . " days";
         // default: -5 days
         $h->vars['filter']['post_archived = %s'] = 'N';
         $h->vars['filter']['post_status = %s'] = 'new';
         $start = date('YmdHis', time_block());
         $end = date('YmdHis', strtotime($upcoming_duration));
         // should be negative
         $h->vars['filter']['(post_date >= %s AND post_date <= %s)'] = array($end, $start);
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top-24-hours') {
         // Filters page to "top" stories from the last 24 hours only
         $h->vars['filter']['post_status = %s'] = 'top';
         $start = date('YmdHis', time_block());
         $end = date('YmdHis', strtotime("-1 day"));
         $h->vars['filter']['(post_date >= %s AND post_date <= %s)'] = array($end, $start);
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top-48-hours') {
         // Filters page to "top" stories from the last 48 hours only
         $h->vars['filter']['post_status = %s'] = 'top';
         $start = date('YmdHis', time_block());
         $end = date('YmdHis', strtotime("-2 days"));
         $h->vars['filter']['(post_date >= %s AND post_date <= %s)'] = array($end, $start);
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top-7-days') {
         // Filters page to "top" stories from the last 7 days only
         $h->vars['filter']['post_status = %s'] = 'top';
         $start = date('YmdHis', time_block());
         $end = date('YmdHis', strtotime("-7 days"));
         $h->vars['filter']['(post_date >= %s AND post_date <= %s)'] = array($end, $start);
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top-30-days') {
         // Filters page to "top" stories from the last 30 days only
         $h->vars['filter']['post_status = %s'] = 'top';
         $start = date('YmdHis', time_block());
         $end = date('YmdHis', strtotime("-30 days"));
         $h->vars['filter']['(post_date >= %s AND post_date <= %s)'] = array($end, $start);
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top-365-days') {
         // Filters page to "top" stories from the last 365 days only
         $h->vars['filter']['post_status = %s'] = 'top';
         $start = date('YmdHis', time_block());
         $end = date('YmdHis', strtotime("-365 days"));
         $h->vars['filter']['(post_date >= %s AND post_date <= %s)'] = array($end, $start);
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top-all-time') {
         // Filters page to "top" stories in order of votes
         $h->vars['filter']['post_status = %s'] = 'top';
         $h->vars['orderby'] = "post_votes_up DESC, post_date DESC";
     } elseif ($type == 'top') {
         // Assume 'top' page and filter to 'top' stories.
         $h->vars['filter']['post_archived = %s'] = 'N';
         $h->vars['filter']['post_status = %s'] = 'top';
         $h->vars['orderby'] = "post_date DESC";
     } else {
         // Filters page to "all" stories
         $h->vars['filter']['post_archived = %s'] = 'N';
         $h->vars['filter']['(post_status = %s OR post_status = %s)'] = array('top', 'new');
         $h->vars['orderby'] = "post_date DESC";
     }
 }
コード例 #3
0
ファイル: Comment.php プロジェクト: hotarucms/hotarucms
 /**
  * Count daily comments for this commenter
  *
  * @return int 
  */
 public function countDailyComments($h)
 {
     $start = date('YmdHis', time_block());
     $end = date('YmdHis', strtotime("-1 day"));
     $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_user_id = %d AND (comment_date >= %s AND comment_date <= %s)";
     $query = $h->db->prepare($sql, 'N', $this->author, $end, $start);
     $h->smartCache('on', 'comments', 60, $query);
     // start using cache
     $count = $h->db->get_var($query);
     $h->smartCache('off');
     // stop using cache
     return $count;
 }
コード例 #4
0
ファイル: Comment.php プロジェクト: shibuya246/Hotaru-Plugins
 /**
  * Count daily comments for this commenter
  *
  * @return int 
  */
 public function countDailyComments($h)
 {
     $start = date('YmdHis', time_block());
     $end = date('YmdHis', strtotime("-1 day"));
     $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_user_id = %d AND (comment_date >= %s AND comment_date <= %s)";
     $count = $h->db->get_var($h->db->prepare($sql, 'N', $this->author, $end, $start));
     return $count;
 }
コード例 #5
0
ファイル: Post.php プロジェクト: hotarucms/hotarucms
 /**
  * Count posts in the last X hours/minutes for this user
  *
  * @param int $hours
  * @param int $minutes
  * @param int $user_id (optional)
  * @param int $post_type (optional)
  * @return int 
  */
 public function countPostsFilter($h, $hours = 0, $minutes = 0, $filter = '', $filterText = '', $link = '', $post_type = 'news')
 {
     if ($hours) {
         $time_ago = "-" . $hours . " Hours";
     } else {
         $time_ago = "-" . $minutes . " minutes";
     }
     $and = '';
     if ($filter == 'tag') {
         $and = ' AND post_tags = %s';
     } elseif ($filter == 'category') {
         $and = ' AND post_category = %s';
     } else {
         $and = ' AND 1= %d';
         $filterText = 1;
     }
     $start = date('YmdHis', time_block());
     $end = date('YmdHis', strtotime($time_ago));
     $sql = "SELECT COUNT(post_id) FROM " . TABLE_POSTS . " WHERE post_archived = %s" . $and . ' AND post_type = %s AND post_status <> %s';
     // . " AND (post_date >= %s AND post_date <= %s)";
     $count = $h->db->get_var($h->db->prepare($sql, 'N', $filterText, $post_type, 'pending'));
     //, $end, $start));
     return $count;
 }