コード例 #1
0
 /**
  * Handle blog data
  *
  * To handle the raw data gotten from the database
  *
  * @param int $id The id of the blog we want to handle
  * @param int|bool $trim_text If we want to trim the text or not(if true we will trim with the setting in $config['user_blog_user_text_limit'], else if it is an integer we will trim the text to that length)
  */
 public function handle_blog_data($id, $trim_text = false)
 {
     global $config, $user, $phpbb_root_path, $phpEx, $auth, $highlight_match;
     global $blog_attachment, $category_id;
     if (!isset(self::$blog[$id])) {
         return array();
     }
     $blog =& self::$blog[$id];
     $user_id = $blog['user_id'];
     blog_plugins::plugin_do('blog_handle_data_start');
     if ($trim_text !== false) {
         $blog_text = trim_text_length($id, false, $trim_text === true ? $config['user_blog_user_text_limit'] : intval($trim_text));
         $shortened = $blog_text === false ? false : true;
         $blog_text = $blog_text === false ? $blog['blog_text'] : $blog_text;
     } else {
         $blog_text = $blog['blog_text'];
         $shortened = false;
     }
     // censor the text of the subject
     $blog_subject = censor_text($blog['blog_subject']);
     // Parse BBCode and prepare the message for viewing
     $bbcode_options = ($blog['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($blog['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($blog['enable_magic_url'] ? OPTION_FLAG_LINKS : 0);
     $blog_text = generate_text_for_display($blog_text, $blog['bbcode_uid'], $blog['bbcode_bitfield'], $bbcode_options);
     if ($config['user_blog_enable_ratings']) {
         $rating_data = get_user_blog_rating_data($user->data['user_id']);
         $rate_url = blog_url($user_id, $id, false, array('page' => 'rate', 'rating' => '*rating*'));
         $delete_rate_url = blog_url($user_id, $id, false, array('page' => 'rate', 'delete' => $id));
     }
     // For Highlighting
     if ($highlight_match) {
         $blog_subject = preg_replace('#(?!<.*)(?<!\\w)(' . $highlight_match . ')(?!\\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\\1</span>', $blog_subject);
         $blog_text = preg_replace('#(?!<.*)(?<!\\w)(' . $highlight_match . ')(?!\\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\\1</span>', $blog_text);
     }
     $reply_count = $this->get_reply_data('reply_count', $id);
     $blog['blog_read_count'] = $user->data['user_id'] != $user_id ? $blog['blog_read_count'] + 1 : $blog['blog_read_count'];
     // Polls
     $poll_options = $my_vote = array();
     $total_votes = 0;
     foreach ($blog['poll_votes'] as $option_id => $poll_row) {
         if ($option_id !== 'my_vote') {
             $total_votes += $poll_row['votes'];
         } else {
             $my_vote = $poll_row;
         }
     }
     foreach ($blog['poll_options'] as $option_id => $poll_row) {
         $option_pct = $total_votes > 0 && isset($blog['poll_votes'][$option_id]['votes']) ? $blog['poll_votes'][$option_id]['votes'] / $total_votes : 0;
         $option_pct_txt = sprintf("%.1d%%", $option_pct * 100);
         $poll_options[] = array('POLL_OPTION_ID' => $option_id, 'POLL_OPTION_CAPTION' => generate_text_for_display($poll_row['poll_option_text'], $blog['bbcode_uid'], $blog['bbcode_bitfield'], $bbcode_options), 'POLL_OPTION_RESULT' => isset($blog['poll_votes'][$option_id]['votes']) ? $blog['poll_votes'][$option_id]['votes'] : 0, 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PCT' => round($option_pct * 100), 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)), 'POLL_OPTION_VOTED' => in_array($option_id, $my_vote) ? true : false);
     }
     $s_can_vote = (!sizeof($my_vote) && check_blog_permissions('blog', 'vote', true, $id) || $auth->acl_get('u_blog_vote_change') && $blog['poll_vote_change']) && ($blog['poll_length'] != 0 && $blog['poll_length'] > time() || $blog['poll_length'] == 0) ? true : false;
     // Attachments
     $update_count = $attachments = array();
     parse_attachments_for_view($blog_text, $blog['attachment_data'], $update_count);
     foreach ($blog['attachment_data'] as $i => $attachment) {
         $attachments[]['DISPLAY_ATTACHMENT'] = $attachment;
     }
     $blog_row = array('ID' => $id, 'MESSAGE' => $blog_text, 'DATE' => $user->format_date($blog['blog_time']), 'DELETED_MESSAGE' => $blog['deleted_message'], 'EDIT_REASON' => $blog['edit_reason'], 'EDITED_MESSAGE' => $blog['edited_message'], 'EXTRA' => '', 'POLL_QUESTION' => generate_text_for_display($blog['poll_title'], $blog['bbcode_uid'], $blog['bbcode_bitfield'], $bbcode_options), 'RATING_STRING' => $config['user_blog_enable_ratings'] ? get_star_rating($rate_url, $delete_rate_url, $blog['rating'], $blog['num_ratings'], isset($rating_data[$id]) ? $rating_data[$id] : false, $user->data['user_id'] == $user_id ? true : false) : false, 'NUM_REPLIES' => $reply_count, 'REPLIES' => '<a href="' . blog_url($user_id, $id, false, array('anchor' => 'replies')) . '">' . ($reply_count == 1 ? $user->lang['ONE_COMMENT'] : sprintf($user->lang['CNT_COMMENTS'], $reply_count)) . '</a>', 'TITLE' => $blog_subject, 'TOTAL_VOTES' => $total_votes, 'USER_FULL' => self::$user[$user_id]['username_full'], 'VIEWS' => $blog['blog_read_count'] == 1 ? $user->lang['ONE_VIEW'] : sprintf($user->lang['CNT_VIEWS'], $blog['blog_read_count']), 'L_MAX_VOTES' => $blog['poll_max_options'] == 1 ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $blog['poll_max_options']), 'L_POLL_LENGTH' => $blog['poll_length'] ? sprintf($user->lang[$blog['poll_length'] > time() ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($blog['poll_length'])) : '', 'U_APPROVE' => check_blog_permissions('blog', 'approve', true, $id) && $blog['blog_approved'] == 0 && !$shortened ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'approve')) : '', 'U_DELETE' => check_blog_permissions('blog', 'delete', true, $id) ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'delete')) : '', 'U_DIGG' => 'http://digg.com/submit?phase=2&amp;url=' . urlencode(generate_board_url() . '/blog.' . $phpEx . '?b=' . $blog['blog_id']), 'U_EDIT' => check_blog_permissions('blog', 'edit', true, $id) ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'edit')) : '', 'U_QUOTE' => check_blog_permissions('reply', 'quote', true, $id) ? blog_url(false, $id, false, array('page' => 'reply', 'mode' => 'quote')) : '', 'U_REPORT' => check_blog_permissions('blog', 'report', true, $id) ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'report')) : '', 'U_REPLY' => check_blog_permissions('reply', 'add', true, $id) ? blog_url(false, $id, false, array('page' => 'reply', 'mode' => 'add')) : '', 'U_VIEW' => blog_url($user_id, $id), 'U_VIEW_PERMANENT' => blog_url(false, $id, false, array(), array(), true), 'U_WARN' => $auth->acl_get('m_warn') && $user_id != $user->data['user_id'] && $user_id != ANONYMOUS ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=warn&amp;mode=warn_user&amp;u={$user_id}", true, $user->session_id) : '', 'S_CAN_VOTE' => $s_can_vote, 'S_DELETED' => $blog['blog_deleted'] ? true : false, 'S_DISPLAY_NOTICE' => !$auth->acl_get('u_download') && $blog['blog_attachment'] && sizeof($blog['attachment_data']) ? true : false, 'S_DISPLAY_RESULTS' => !$s_can_vote || $s_can_vote && sizeof($my_vote) || isset($_GET['view']) && $_GET['view'] == 'viewpoll' ? true : false, 'S_HAS_ATTACHMENTS' => $blog['blog_attachment'] ? true : false, 'S_HAS_POLL' => $blog['poll_title'] ? true : false, 'S_IS_MULTI_CHOICE' => $blog['poll_max_options'] > 1 ? true : false, 'S_REPORTED' => $blog['blog_reported'] && $auth->acl_get('m_blogreport') ? true : false, 'S_SHORTENED' => $shortened, 'S_UNAPPROVED' => !$blog['blog_approved'] && ($user_id == $user->data['user_id'] || $auth->acl_get('m_blogapprove')) ? true : false, 'attachment' => $attachments, 'poll_option' => $poll_options);
     blog_plugins::plugin_do_ref('blog_handle_data_end', $blog_row);
     return $blog_row;
 }
コード例 #2
0
ファイル: rate.php プロジェクト: EXreaction/User-Blog-Mod
* @copyright (c) 2008 EXreaction
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
if (!defined('IN_PHPBB')) {
    exit;
}
if (!$config['user_blog_enable_ratings']) {
    trigger_error('USER_BLOG_RATINGS_DISABLED');
}
if ($blog_id == 0) {
    trigger_error('BLOG_NOT_EXIST');
}
$delete_id = request_var('delete', 0);
$rating = request_var('rating', $config['user_blog_min_rating'] - 1);
$rating_data = get_user_blog_rating_data($user->data['user_id']);
$did_something = false;
if (!$delete_id && $rating != $config['user_blog_min_rating'] - 1 && !isset($rating_data[$blog_id]) && $rating >= $config['user_blog_min_rating'] && $rating <= $config['user_blog_max_rating']) {
    $sql_data = array('blog_id' => intval($blog_id), 'user_id' => $user->data['user_id'], 'rating' => $rating);
    $sql = 'INSERT INTO ' . BLOGS_RATINGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data);
    $db->sql_query($sql);
    $did_something = true;
} else {
    if ($delete_id && isset($rating_data[$blog_id])) {
        $sql = 'DELETE FROM ' . BLOGS_RATINGS_TABLE . ' WHERE blog_id = ' . $delete_id . ' AND user_id = ' . $user->data['user_id'];
        $db->sql_query($sql);
        $did_something = true;
    }
}
blog_plugins::plugin_do_ref('rate', $did_something);
if ($did_something) {