コード例 #1
0
/**
* gets the star rating of the item from the int rating
*
* @param string $start_url The url which will be used to rate each item (the rating part of the url should be *rating*, EX: blog.php?page=rate&b=1&rating=*rating*)
* @param string $delete_url The url which will be used to remove the rating for the item
* @param int $average_rating The current rating of the item
* @param int $num_ratings The number of times the item has been rated
* @param int $user_rating The rating the user gave for the item
* @param bool $force_average If you want to force it to display the average score without the links to submit the rating
*/
function get_star_rating($start_url, $delete_url, $average_rating, $num_ratings, $user_rating, $force_average = false)
{
    global $auth, $config, $phpbb_root_path, $phpEx, $user, $blog_plugins, $blog_images_path;
    if (!$config['user_blog_enable_ratings']) {
        return false;
    }
    $temp = compact('start_url', 'delete_url', 'average_rating', 'num_ratings', 'user_rating', 'force_average');
    blog_plugins::plugin_do_ref('function_get_star_rating', $temp);
    extract($temp);
    $can_rate = $user->data['is_registered'] && !$force_average && $user_rating === false ? true : false;
    // If it has not had any ratings yet, give it 1/2 the max for the rating
    if ($num_ratings == 0) {
        // If they can not rate the item and there are no ratings, do not show it at all.
        if (!$can_rate) {
            return '';
        }
        $average_rating = ceil($config['user_blog_max_rating'] / 2);
    }
    // Some variables we'll need
    $star_green = $blog_images_path . 'star_green.gif';
    $star_grey = $blog_images_path . 'star_grey.gif';
    $star_orange = $blog_images_path . 'star_orange.gif';
    $star_red = $blog_images_path . 'star_red.gif';
    $star_remove = $blog_images_path . 'star_remove.gif';
    $final_code = $force_average ? sprintf($num_ratings == 1 ? $user->lang['AVERAGE_OF_RATING'] : $user->lang['AVERAGE_OF_RATINGS'], $num_ratings) . ':' : '';
    // A unique string that will get added to the rating.  So if the item is shown more than once, hovering over and trying to rate one doesn't mess up the other list.
    $unique_str = md5(microtime());
    $unique_str = "u_{$unique_str}_s_";
    // If the user has rated this already and we are not just getting the average, get the average as well.
    if ($user_rating !== false && !$force_average) {
        $final_code = get_star_rating($start_url, $delete_url, $average_rating, $num_ratings, $user_rating, true) . '';
        $average_rating = $user_rating;
    }
    $final_code .= $user_rating !== false && !$force_average ? $user->lang['MY_RATING'] . ': ' : '';
    $final_code .= '<div>';
    for ($i = $config['user_blog_min_rating']; $i <= $config['user_blog_max_rating']; $i++) {
        $title = $user_rating === false && !$force_average ? sprintf($user->lang['RATE_ME'], $i, $config['user_blog_max_rating']) : sprintf($user->lang['RATE_ME'], $average_rating, $config['user_blog_max_rating']);
        $final_code .= $can_rate ? '<a href="' . str_replace('*rating*', $i, $start_url) . '">' : '';
        $final_code .= '<img id="' . $unique_str . $i . '" ';
        if ($user_rating !== false && $i <= $user_rating && !$force_average) {
            $final_code .= 'src="' . $star_green . '" ';
        } else {
            if ($i <= $average_rating) {
                $final_code .= 'src="' . $star_orange . '" ';
            } else {
                $final_code .= 'src="' . $star_grey . '" ';
            }
        }
        $final_code .= $can_rate ? "onmouseover=\"ratingHover('{$i}', '{$unique_str}')\"  onmouseout=\"ratingUnHover('{$average_rating}', '{$unique_str}')\"  onmousedown=\"ratingDown('{$i}', '{$unique_str}')\"" : '';
        $final_code .= ' alt="' . $title . '" title="' . $title . '" />';
        $final_code .= $can_rate ? '</a>' : '';
    }
    // If required, we will add the remove rating icon at the end
    if ($user_rating !== false && !$force_average) {
        $final_code .= ' <a href="' . $delete_url . '"><img id="' . $unique_str . 'remove" src="' . $star_remove . '"  alt="' . $user->lang['REMOVE_RATING'] . '" title="' . $user->lang['REMOVE_RATING'] . '" /></a>';
    }
    $final_code .= '</div>';
    return $final_code;
}
コード例 #2
0
/**
* Obtain allowed extensions
*
* @return array allowed extensions array.
*/
function obtain_blog_attach_extensions()
{
    global $cache, $config;
    if (!$config['user_blog_enable_attachments']) {
        return;
    }
    if (($extensions = $cache->get('_blog_extensions')) === false) {
        global $db;
        $extensions = array('_allowed_blog' => array());
        // The rule is to only allow those extensions defined. ;)
        $sql = 'SELECT e.extension, g.*
			FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
			WHERE e.group_id = g.group_id
				AND (g.allow_group = 1 OR g.allow_in_blog = 1)';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $extension = strtolower(trim($row['extension']));
            $extensions[$extension] = array('display_cat' => (int) $row['cat_id'], 'download_mode' => (int) $row['download_mode'], 'upload_icon' => trim($row['upload_icon']), 'max_filesize' => (int) $row['max_filesize'], 'allow_group' => $row['allow_group'], 'allow_in_blog' => $row['allow_in_blog']);
            if ($row['allow_in_blog']) {
                $extensions['_allowed_blog'][$extension] = 0;
            }
        }
        $db->sql_freeresult($result);
        $cache->put('_blog_extensions', $extensions);
    }
    $return = array('_allowed_' => array());
    foreach ($extensions['_allowed_blog'] as $extension => $check) {
        $return['_allowed_'][$extension] = 0;
        $return[$extension] = $extensions[$extension];
    }
    blog_plugins::plugin_do_ref('function_obtain_blog_attach_extensions', $return);
    return $return;
}
コード例 #3
0
ファイル: delete.php プロジェクト: EXreaction/User-Blog-Mod
// Add the language Variables for posting
$user->add_lang('posting');
// check to see if editing this message is locked, or if the one editing it has mod powers
if (blog_data::$reply[$reply_id]['reply_edit_locked'] && !$auth->acl_get('m_blogreplyedit')) {
    trigger_error('REPLY_EDIT_LOCKED');
}
// Setup the page header and sent the title of the page that will go into the browser header
page_header($user->lang['DELETE_REPLY']);
// Generate the breadcrumbs
generate_blog_breadcrumbs($user->lang['DELETE_REPLY']);
blog_plugins::plugin_do('reply_delete');
$display_vars = array();
if ($auth->acl_get('a_blogdelete') && blog_data::$reply[$reply_id]['reply_deleted'] == 0) {
    $display_vars = array('legend1' => $user->lang['HARD_DELETE'], 'hard_delete' => array('lang' => 'HARD_DELETE', 'validate' => 'bool', 'type' => 'checkbox', 'default' => false, 'explain' => true));
}
blog_plugins::plugin_do_ref('blog_delete', $display_vars);
include "{$phpbb_root_path}blog/includes/functions_confirm.{$phpEx}";
$settings = blog_confirm('DELETE_REPLY', 'DELETE_REPLY_CONFIRM', $display_vars, 'yes/no');
if (is_array($settings)) {
    blog_plugins::plugin_do('reply_delete_confirm');
    // if it has already been soft deleted
    if ((isset($settings['hard_delete']) && $settings['hard_delete'] || blog_data::$reply[$reply_id]['reply_deleted'] != 0) && $auth->acl_get('a_blogreplydelete')) {
        // If it has not been soft deleted we need to do a few more things...
        if (blog_data::$reply[$reply_id]['reply_deleted'] == 0) {
            // Remove the search index
            $blog_search->index_remove($blog_id, $reply_id);
            // update the reply count for the blog
            $sql = 'UPDATE ' . BLOGS_TABLE . ' SET blog_reply_count = blog_reply_count - 1 WHERE blog_id = ' . intval($blog_id) . ' AND blog_reply_count > 0';
            $db->sql_query($sql);
            set_config('num_blog_replies', --$config['num_blog_replies'], true);
        }
コード例 #4
0
/**
* handles sending subscription notices for blogs or replies
*
* Sends a PM or Email to each user in the subscription list, depending on what they want
*
* @param string $mode The mode (new_blog, or new_reply)
* @param string $post_subject The subject of the post made
* @param int|bool $uid The user_id of the user who made the new blog (if there is one).  If this is left as 0 it will grab the global value of $user_id.
* @param int|bool $bid The blog_id of the blog.  If this is left as 0 it will grab the global value of $blog_id.
* @param int|bool $rid The reply_id of the new reply (if there is one).  If this is left as 0 it will grab the global value of $reply_id.
*/
function handle_subscription($mode, $post_subject, $uid = 0, $bid = 0, $rid = 0)
{
    global $db, $user, $phpbb_root_path, $phpEx, $config;
    global $user_id, $blog_id, $reply_id;
    global $blog_data, $blog_urls;
    // if $uid, $bid, or $rid are not set, use the globals
    $uid = $uid != 0 ? $uid : $user_id;
    $bid = $bid != 0 ? $bid : $blog_id;
    $rid = $rid != 0 ? $rid : $reply_id;
    // make sure that subscriptions are enabled and that a blog_id is sent
    if (!$config['user_blog_subscription_enabled'] || $bid == 0) {
        return;
    }
    if (!isset($user->lang['BLOG_SUBSCRIPTION_NOTICE'])) {
        $user->add_lang('mods/blog/posting');
    }
    // This will hold all the send info, all ones that will be sent via PM would be $send[1], or Email would be $send[2], next would be $send[4], etc.
    $send = array();
    $subscribe_modes = get_blog_subscription_types();
    $temp = compact('mode', 'post_subject', 'uid', 'bid', 'rid', 'send');
    blog_plugins::plugin_do_ref('function_handle_subscription', $temp);
    extract($temp);
    // Fix the URLs...
    if (isset($config['user_blog_seo']) && $config['user_blog_seo']) {
        $view_url = $rid ? blog_url($uid, $bid, $rid) : blog_url($uid, $bid);
        $unsubscribe_url = $rid ? blog_url($uid, $bid, false, array('page' => 'unsubscribe')) : blog_url($uid, false, false, array('page' => 'unsubscribe'));
    } else {
        $view_url = redirect($rid ? blog_url($uid, $bid, $rid) : blog_url($uid, $bid), true);
        $unsubscribe_url = redirect($rid ? blog_url($uid, $bid, false, array('page' => 'unsubscribe')) : blog_url($uid, false, false, array('page' => 'unsubscribe')), true);
    }
    if ($mode == 'new_reply' && $rid != 0) {
        $sql = 'SELECT * FROM ' . BLOGS_SUBSCRIPTION_TABLE . '
			WHERE blog_id = ' . intval($bid) . '
			AND sub_user_id != ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (!array_key_exists($row['sub_type'], $send)) {
                $send[$row['sub_type']] = array($row['sub_user_id']);
            } else {
                $send[$row['sub_type']][] = $row['sub_user_id'];
            }
        }
        $db->sql_freeresult($result);
        $message = sprintf($user->lang['BLOG_SUBSCRIPTION_NOTICE'], $view_url, $user->data['username'], $unsubscribe_url);
    } else {
        if ($mode == 'new_blog' && $uid != 0) {
            $sql = 'SELECT * FROM ' . BLOGS_SUBSCRIPTION_TABLE . '
			WHERE user_id = ' . intval($uid) . '
			AND sub_user_id != ' . $user->data['user_id'];
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if (!array_key_exists($row['sub_type'], $send)) {
                    $send[$row['sub_type']] = array($row['sub_user_id']);
                } else {
                    $send[$row['sub_type']][] = $row['sub_user_id'];
                }
            }
            $db->sql_freeresult($result);
            $message = sprintf($user->lang['USER_SUBSCRIPTION_NOTICE'], $user->data['username'], $view_url, $unsubscribe_url);
        }
    }
    $blog_data->get_user_data($config['user_blog_message_from']);
    // Send the PM
    if (isset($send[1]) && sizeof($send[1])) {
        if (!function_exists('submit_pm')) {
            // include the private messages functions page
            include "{$phpbb_root_path}includes/functions_privmsgs.{$phpEx}";
        }
        if (!class_exists('parse_message')) {
            include "{$phpbb_root_path}includes/message_parser.{$phpEx}";
        }
        $message_parser = new parse_message();
        $message_parser->message = $message;
        $message_parser->parse(true, true, true);
        // setup out to address list
        $address_list = array();
        foreach ($send[1] as $id) {
            $address_list[$id] = 'to';
        }
        $pm_data = array('from_user_id' => $config['user_blog_message_from'], 'from_username' => blog_data::$user[$config['user_blog_message_from']]['username'], 'address_list' => array('u' => $address_list), 'icon_id' => 10, 'from_user_ip' => '0.0.0.0', 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $message_parser->message, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid);
        submit_pm('post', $user->lang['SUBSCRIPTION_NOTICE'], $pm_data, false);
        unset($message_parser, $address_list, $pm_data);
    }
    // Send the email
    if (isset($send[2]) && sizeof($send[2]) && $config['email_enable']) {
        if (!class_exists('messenger')) {
            include "{$phpbb_root_path}includes/functions_messenger.{$phpEx}";
        }
        $messenger = new messenger(false);
        $blog_data->get_user_data($send[2]);
        $reply_url_var = $rid ? "r={$rid}#r{$rid}" : '';
        foreach ($send[2] as $uid) {
            $messenger->template('blog_notify', $config['default_lang']);
            $messenger->replyto($config['board_contact']);
            $messenger->to(blog_data::$user[$uid]['user_email'], blog_data::$user[$uid]['username']);
            $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
            $messenger->headers('X-AntiAbuse: User_id - ' . blog_data::$user[$config['user_blog_message_from']]['user_id']);
            $messenger->headers('X-AntiAbuse: Username - ' . blog_data::$user[$config['user_blog_message_from']]['username']);
            $messenger->headers('X-AntiAbuse: User IP - ' . blog_data::$user[$config['user_blog_message_from']]['user_ip']);
            $messenger->assign_vars(array('BOARD_CONTACT' => $config['board_contact'], 'SUBJECT' => $user->lang['SUBSCRIPTION_NOTICE'], 'TO_USERNAME' => blog_data::$user[$uid]['username'], 'TYPE' => $rid ? $user->lang['REPLY'] : $user->lang['BLOG'], 'NAME' => $post_subject, 'BY_USERNAME' => $user->data['username'], 'U_VIEW' => $view_url, 'U_UNSUBSCRIBE' => $unsubscribe_url));
            $messenger->send(NOTIFY_EMAIL);
        }
        // save the queue if we must
        $messenger->save_queue();
        unset($messenger);
    }
    blog_plugins::plugin_do('function_handle_subscription_end');
}
コード例 #5
0
ファイル: ucp_blog.php プロジェクト: EXreaction/User-Blog-Mod
 function main($id, $mode)
 {
     global $auth, $cache, $template, $user, $db, $config, $phpEx, $phpbb_root_path;
     global $blog_plugins, $blog_plugins_path, $user_settings;
     $preview = isset($_POST['preview']) ? true : false;
     $submit = isset($_POST['submit']) ? true : false;
     $error = array();
     $user->add_lang(array('mods/blog/common', 'mods/blog/ucp'));
     include $phpbb_root_path . 'blog/functions.' . $phpEx;
     blog_plugins::plugin_do('ucp_start');
     get_user_settings($user->data['user_id']);
     switch ($mode) {
         case 'ucp_blog_settings':
             $subscription_types = get_blog_subscription_types();
             if ($submit) {
                 $sql_ary = array('instant_redirect' => request_var('instant_redirect', 0), 'blog_subscription_default' => 0, 'blog_style' => $auth->acl_get('u_blog_style') ? request_var('blog_style', '') : '', 'blog_css' => $auth->acl_get('u_blog_css') ? request_var('blog_css', '') : '');
                 if ($config['user_blog_subscription_enabled']) {
                     foreach ($subscription_types as $type => $name) {
                         if (request_var('subscription_' . $type, false)) {
                             $sql_ary['blog_subscription_default'] += $type;
                         }
                     }
                 }
                 update_user_blog_settings($user->data['user_id'], $sql_ary);
             } else {
                 if ($config['user_blog_subscription_enabled']) {
                     $subscribed = array();
                     if (isset($user_settings[$user->data['user_id']])) {
                         foreach ($subscription_types as $type => $name) {
                             // Bitwise check
                             if ($user_settings[$user->data['user_id']]['blog_subscription_default'] & $type) {
                                 $subscribed[$type] = true;
                             }
                         }
                     }
                     foreach ($subscription_types as $type => $name) {
                         $template->assign_block_vars('subscriptions', array('TYPE' => 'subscription_' . $type, 'NAME' => isset($user->lang[$name]) ? $user->lang[$name] : $name, 'S_CHECKED' => isset($subscribed[$type]) ? true : false));
                     }
                 }
                 if ($auth->acl_get('u_blog_style')) {
                     $available_styles = array(array('name' => $user->lang['NONE'], 'value' => 0, 'demo' => $phpbb_root_path . 'images/spacer.gif'));
                     $sql = 'SELECT * FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' st WHERE style_active = 1 AND s.template_id = st.template_id';
                     $result = $db->sql_query($sql);
                     while ($row = $db->sql_fetchrow($result)) {
                         $demo = $phpbb_root_path . 'images/spacer.gif';
                         if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.png')) {
                             $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.png';
                         } else {
                             if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.gif')) {
                                 $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.gif';
                             } else {
                                 if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.jpg')) {
                                     $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.jpg';
                                 }
                             }
                         }
                         $available_styles[] = array('name' => $row['style_name'], 'value' => $row['style_id'], 'demo' => $demo);
                     }
                     $db->sql_freeresult($result);
                     $dh = @opendir($phpbb_root_path . 'blog/styles/');
                     if ($dh) {
                         while (($file = readdir($dh)) !== false) {
                             if (file_exists($phpbb_root_path . 'blog/styles/' . $file . '/style.' . $phpEx)) {
                                 // Inside of the style.php file, add to the $available_styles array
                                 include $phpbb_root_path . 'blog/styles/' . $file . '/style.' . $phpEx;
                             }
                         }
                         closedir($dh);
                     }
                     foreach ($available_styles as $row) {
                         if (isset($user_settings[$user->data['user_id']]) && $user_settings[$user->data['user_id']]['blog_style'] == $row['value'] && isset($row['demo']) && $row['demo']) {
                             $default_demo = $row['demo'];
                         }
                         $template->assign_block_vars('blog_styles', array('VALUE' => $row['value'], 'SELECTED' => isset($user_settings[$user->data['user_id']]) && $user_settings[$user->data['user_id']]['blog_style'] == $row['value'] ? true : false, 'NAME' => $row['name'], 'BLOG_CSS' => isset($row['blog_css']) && $row['blog_css'] ? true : false, 'DEMO' => isset($row['demo']) && $row['demo'] ? $row['demo'] : ''));
                     }
                 }
                 $template->assign_vars(array('S_BLOG_INSTANT_REDIRECT' => isset($user_settings[$user->data['user_id']]) ? $user_settings[$user->data['user_id']]['instant_redirect'] : 0, 'S_SUBSCRIPTIONS' => $config['user_blog_subscription_enabled'] ? true : false, 'S_BLOG_STYLE' => isset($available_styles) && sizeof($available_styles) > 1 ? true : false, 'S_BLOG_CSS' => $auth->acl_get('u_blog_css') ? true : false, 'DEFAULT_DEMO' => isset($default_demo) ? $default_demo : $phpbb_root_path . 'images/spacer.gif', 'BLOG_CSS' => isset($user_settings[$user->data['user_id']]) ? $user_settings[$user->data['user_id']]['blog_css'] : ''));
             }
             break;
         case 'ucp_blog_permissions':
             if (!$config['user_blog_user_permissions']) {
                 $error[] = $user->lang['USER_PERMISSIONS_DISABLED'];
                 $template->assign_vars(array('PERMISSIONS_DISABLED' => true));
             } else {
                 if ($submit) {
                     $sql_ary = array('perm_guest' => request_var('perm_guest', 1), 'perm_registered' => request_var('perm_registered', 2), 'perm_foe' => request_var('perm_foe', 0), 'perm_friend' => request_var('perm_friend', 2));
                     update_user_blog_settings($user->data['user_id'], $sql_ary, isset($_POST['resync']) ? true : false);
                 } else {
                     permission_settings_builder();
                 }
             }
             break;
         case 'ucp_blog_title_description':
             include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
             include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
             include $phpbb_root_path . 'blog/includes/functions_posting.' . $phpEx;
             if (!function_exists('display_custom_bbcodes')) {
                 include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
             }
             $user->add_lang('posting');
             $post_options = new post_options();
             $post_options->set_status(true, true, true);
             $post_options->set_in_template();
             if ($submit || $preview) {
                 // see if they tried submitting a message or suject(if they hit preview or submit) put it in an array for consistency with the edit mode
                 $blog_title = utf8_normalize_nfc(request_var('title', '', true));
                 $blog_description = utf8_normalize_nfc(request_var('message', '', true));
                 // set up the message parser to parse BBCode, Smilies, etc
                 $message_parser = new parse_message();
                 $message_parser->message = $blog_description;
                 $message_parser->parse($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, $post_options->img_status, $post_options->flash_status, $post_options->bbcode_status, $post_options->url_status);
             } else {
                 if (isset($user_settings[$user->data['user_id']])) {
                     $blog_title = $user_settings[$user->data['user_id']]['title'];
                     $blog_description = $user_settings[$user->data['user_id']]['description'];
                     decode_message($blog_description, $user_settings[$user->data['user_id']]['description_bbcode_uid']);
                 } else {
                     $blog_title = $blog_description = '';
                 }
             }
             if (!$submit || sizeof($error)) {
                 if ($preview && !sizeof($error)) {
                     $preview_message = $message_parser->format_display($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, false);
                     // output some data to the template parser
                     $template->assign_vars(array('S_DISPLAY_PREVIEW' => true, 'PREVIEW_SUBJECT' => censor_text($blog_title), 'PREVIEW_MESSAGE' => $preview_message, 'POST_DATE' => $user->format_date(time())));
                 }
                 // Generate smiley listing
                 generate_smilies('inline', false);
                 // Build custom bbcodes array
                 display_custom_bbcodes();
                 $template->assign_vars(array('S_PREVIEW_BUTTON' => true, 'TITLE' => $blog_title, 'MESSAGE' => $blog_description));
             } else {
                 if ($submit) {
                     $sql_ary = array('user_id' => $user->data['user_id'], 'title' => $blog_title, 'description' => $message_parser->message, 'description_bbcode_bitfield' => $message_parser->bbcode_bitfield, 'description_bbcode_uid' => $message_parser->bbcode_uid);
                     unset($message_parser);
                     update_user_blog_settings($user->data['user_id'], $sql_ary);
                 }
             }
             break;
         default:
             $default = true;
             $temp = compact('mode', 'error', 'default');
             blog_plugins::plugin_do_ref('ucp_default', $temp);
             // make sure you set default to false if you use your own page
             extract($temp);
             if ($default) {
                 trigger_error('NO_MODE');
             }
     }
     blog_plugins::plugin_do('ucp_end');
     if ($submit && !sizeof($error)) {
         //$cache->destroy('_blog_settings_' . $user->data['user_id']);
         meta_refresh(3, $this->u_action);
         $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
         trigger_error($message);
     }
     $template->assign_vars(array('L_TITLE' => $user->lang[strtoupper($mode)], 'L_TITLE_EXPLAIN' => $user->lang[strtoupper($mode) . '_EXPLAIN'], 'ERROR' => sizeof($error) ? implode($error, '<br />') : false, 'MODE' => $mode, 'S_UCP_ACTION' => $this->u_action));
     $this->tpl_name = 'blog/ucp_blog';
     $this->page_title = strtoupper($mode);
 }
コード例 #6
0
 /**
  * Handle User Data
  *
  * @param int $user_id The user_id of the user we will setup data for
  */
 public function handle_user_data($user_id)
 {
     global $phpbb_root_path, $phpEx, $user, $auth, $config, $template;
     global $blog_data, $zebra_list;
     if (!isset(self::$user[$user_id])) {
         return array();
     }
     $custom_fields = array();
     if ($config['user_blog_custom_profile_enable']) {
         // output the custom profile fields
         if (isset(self::$user[$user_id]['cp_row']['blockrow'])) {
             foreach (self::$user[$user_id]['cp_row']['blockrow'] as $row) {
                 $custom_fields[] = array('PROFILE_FIELD_NAME' => $row['PROFILE_FIELD_NAME'], 'PROFILE_FIELD_VALUE' => $row['PROFILE_FIELD_VALUE']);
             }
         }
     }
     // add the blog links in the custom fields
     if ($user_id != ANONYMOUS) {
         $custom_fields[] = add_blog_links($user_id, '', self::$user[$user_id], false, true, true);
     }
     $output_data = array('USER_ID' => $user_id, 'AGE' => '', 'AVATAR' => $user->optionget('viewavatars') ? self::$user[$user_id]['avatar'] : '', 'POSTER_FROM' => self::$user[$user_id]['user_from'], 'POSTER_JOINED' => $user->format_date(self::$user[$user_id]['user_regdate']), 'POSTER_POSTS' => self::$user[$user_id]['user_posts'], 'RANK_IMG' => self::$user[$user_id]['rank_img'], 'RANK_IMG_SRC' => self::$user[$user_id]['rank_img_src'], 'RANK_TITLE' => self::$user[$user_id]['rank_title'], 'SIGNATURE' => $config['allow_sig'] && $user->optionget('viewsigs') && self::$user[$user_id]['user_sig'] ? generate_text_for_display(self::$user[$user_id]['user_sig'], self::$user[$user_id]['user_sig_bbcode_uid'], self::$user[$user_id]['user_sig_bbcode_bitfield'], 7) : '', 'STATUS_IMG' => self::$user[$user_id]['status'] ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE'), 'USERNAME' => self::$user[$user_id]['username'], 'USER_COLOUR' => self::$user[$user_id]['user_colour'], 'USER_FULL' => self::$user[$user_id]['username_full'], 'USER_FOE' => isset($zebra_list[$user->data['user_id']]['foe']) && in_array($user_id, $zebra_list[$user->data['user_id']]['foe']) ? true : false, 'L_USER_FOE' => sprintf($user->lang['POSTED_BY_FOE'], self::$user[$user_id]['username_full']), 'U_AIM' => self::$user[$user_id]['aim_url'], 'U_EMAIL' => self::$user[$user_id]['email_url'], 'U_ICQ' => self::$user[$user_id]['icq_url'], 'U_JABBER' => self::$user[$user_id]['jabber_url'], 'U_MSN' => self::$user[$user_id]['msn_url'], 'U_PM' => self::$user[$user_id]['pm_url'], 'U_PROFILE' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;u={$user_id}"), 'U_WWW' => self::$user[$user_id]['user_website'], 'U_YIM' => self::$user[$user_id]['yim_url'], 'S_CUSTOM_FIELDS' => isset(self::$user[$user_id]['cp_row']['blockrow']) ? true : false, 'S_ONLINE' => self::$user[$user_id]['status'], 'ONLINE_IMG' => self::$user[$user_id]['status'] ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE'), 'USER_EXTRA' => '', 'custom_fields' => $custom_fields);
     if ($config['allow_birthdays'] && !empty(self::$user[$user_id]['user_birthday'])) {
         list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', self::$user[$user_id]['user_birthday']));
         if ($bday_year) {
             $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
             $diff = $now['mon'] - $bday_month;
             if ($diff == 0) {
                 $diff = $now['mday'] - $bday_day < 0 ? 1 : 0;
             } else {
                 $diff = $diff < 0 ? 1 : 0;
             }
             $output_data['AGE'] = (int) ($now['year'] - $bday_year - $diff);
         }
     }
     blog_plugins::plugin_do_ref('user_handle_data', $output_data);
     return $output_data;
 }
コード例 #7
0
ファイル: add.php プロジェクト: EXreaction/User-Blog-Mod
            unset($attachment_data);
        }
        blog_plugins::plugin_do_ref('reply_add_preview', $preview_message);
        // output some data to the template parser
        $template->assign_vars(array('S_DISPLAY_PREVIEW' => true, 'PREVIEW_SUBJECT' => censor_text($reply_subject), 'PREVIEW_MESSAGE' => $preview_message, 'POST_DATE' => $user->format_date(time())));
    }
    blog_plugins::plugin_do('reply_add_after_preview');
    // handles the basic data we need to output for posting
    handle_basic_posting_data(false, 'reply');
    // Assign some variables to the template parser
    $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'MESSAGE' => $reply_text, 'SUBJECT' => $reply_subject, 'L_MESSAGE_BODY_EXPLAIN' => intval($config['max_post_chars']) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '', 'L_POST_A' => $user->lang['POST_A_NEW_REPLY']));
    $template->set_filenames(array('body' => 'blog/blog_posting_layout.html'));
} else {
    // insert array, not all of these really need to be inserted, since some are what the fields are as default, but I want it this way. :P
    $sql_data = array('blog_id' => $blog_id, 'user_id' => $user->data['user_id'], 'user_ip' => $user->data['user_ip'], 'reply_time' => time(), 'reply_subject' => $reply_subject, 'reply_text' => $message_parser->message, 'reply_checksum' => md5($message_parser->message), 'reply_approved' => $auth->acl_get('u_blogreplynoapprove') ? 1 : 0, 'enable_bbcode' => $post_options->enable_bbcode, 'enable_smilies' => $post_options->enable_smilies, 'enable_magic_url' => $post_options->enable_magic_url, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'reply_edit_reason' => '', 'reply_attachment' => sizeof($blog_attachment->attachment_data) ? 1 : 0);
    blog_plugins::plugin_do_ref('reply_add_sql', $sql_data);
    $sql = 'INSERT INTO ' . BLOGS_REPLY_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data);
    $db->sql_query($sql);
    $reply_id = $db->sql_nextid();
    $blog_search->index('add', $blog_id, $reply_id, $message_parser->message, $reply_subject, $user->data['user_id']);
    // update the URLS to include the new reply_id
    generate_blog_urls();
    $blog_attachment->update_attachment_data(false, $reply_id);
    blog_plugins::plugin_do_arg('reply_add_after_sql', $reply_id);
    // Handle the subscriptions
    add_blog_subscriptions($blog_id, 'subscription_');
    handle_blog_cache('add_reply', $user_id);
    // update the reply count for the blog
    if ($sql_data['reply_approved']) {
        $sql = 'UPDATE ' . BLOGS_TABLE . ' SET blog_reply_count = blog_reply_count + 1, blog_real_reply_count = blog_real_reply_count + 1 WHERE blog_id = ' . intval($blog_id);
        $db->sql_query($sql);
コード例 #8
0
$subscription_types = get_blog_subscription_types();
$display_vars = array('legend1' => 'SUBSCRIBE');
foreach ($subscription_types as $type => $name) {
    $display_vars[$type] = array('lang' => $name, 'validate' => 'bool', 'type' => 'checkbox', 'default' => false, 'explain' => false);
}
// Do not add subscription types here.  Add them with the function_get_subscription_types hook.
blog_plugins::plugin_do_ref('subscribe', $display_vars);
include "{$phpbb_root_path}blog/includes/functions_confirm.{$phpEx}";
$settings = blog_confirm('SUBSCRIBE_BLOG_TITLE', 'SUBSCRIBE_BLOG_CONFIRM', $display_vars);
if (is_array($settings)) {
    blog_plugins::plugin_do('subscribe_confirm');
    //$cache->destroy("_blog_subscription_{$user->data['user_id']}");
    foreach ($settings as $mode => $yn) {
        if ($yn && array_key_exists($mode, $display_vars)) {
            $sql_data = array('sub_user_id' => $user->data['user_id'], 'sub_type' => (int) $mode, 'blog_id' => (int) $blog_id, 'user_id' => (int) $user_id);
            blog_plugins::plugin_do_ref('subscription_add', $sql_data);
            $sql = 'INSERT INTO ' . BLOGS_SUBSCRIPTION_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data);
            $db->sql_query($sql);
        }
    }
    $message = $user->lang['SUBSCRIPTION_ADDED'] . '<br /><br />';
    if ($blog_id) {
        $message .= '<a href="' . $blog_urls['view_blog'] . '">' . $user->lang['VIEW_BLOG'] . '</a><br />';
        $redirect = $blog_urls['view_blog'];
    } else {
        $redirect = $blog_urls['view_user'];
    }
    if ($user_id == $user->data['user_id']) {
        $message .= sprintf($user->lang['RETURN_BLOG_OWN'], '<a href="' . $blog_urls['view_user'] . '">', '</a>');
    } else {
        $message .= sprintf($user->lang['RETURN_BLOG_MAIN'], '<a href="' . $blog_urls['view_user'] . '">', blog_data::$user[$user_id]['username'], '</a>') . '<br />';
コード例 #9
0
    function categories($id, $mode)
    {
        global $db, $user, $auth, $template, $cache;
        global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
        $this->tpl_name = 'acp_blog_categories';
        $this->page_title = 'ACP_BLOG_CATEGORIES';
        $form_key = 'acp_blog';
        $action = request_var('action', '');
        $update = isset($_POST['update']) ? true : false;
        $category_id = request_var('c', 0);
        $this->parent_id = request_var('parent_id', 0);
        $category_data = $errors = array();
        // Clear the categories cache
        $cache->destroy('_blog_categories');
        // Major routines
        if ($update) {
            switch ($action) {
                case 'delete':
                    $action_subcategories = request_var('action_subcategories', '');
                    $subcategories_to_id = request_var('subcategories_to_id', 0);
                    $action_blogs = request_var('action_blogs', '');
                    $blogs_to_id = request_var('blogs_to_id', 0);
                    $row = $this->get_category_info($category_id);
                    $errors = $this->delete_category($category_id, $action_blogs, $action_subcategories, $blogs_to_id, $subcategories_to_id);
                    blog_plugins::plugin_do_ref('acp_category_delete', $errors);
                    if (sizeof($errors)) {
                        break;
                    }
                    add_log('admin', 'LOG_BLOG_CATEGORY_DELETE', $row['category_name']);
                    trigger_error($user->lang['CATEGORY_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
                    break;
                case 'edit':
                    $category_data = array('category_id' => $category_id);
                    // No break here
                // No break here
                case 'add':
                    $category_data += array('parent_id' => request_var('category_parent_id', $this->parent_id), 'category_name' => utf8_normalize_nfc(request_var('category_name', '', true)), 'category_description' => utf8_normalize_nfc(request_var('category_description', '', true)), 'category_description_bitfield' => '', 'category_description_uid' => '', 'category_description_options' => 7, 'rules' => utf8_normalize_nfc(request_var('rules', '', true)), 'rules_bitfield' => '', 'rules_uid' => '', 'rules_options' => 7);
                    // Get data for category rules if specified...
                    if ($category_data['rules']) {
                        generate_text_for_storage($category_data['rules'], $category_data['rules_uid'], $category_data['rules_bitfield'], $category_data['rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
                    }
                    // Get data for category description if specified
                    if ($category_data['category_description']) {
                        generate_text_for_storage($category_data['category_description'], $category_data['category_description_uid'], $category_data['category_description_bitfield'], $category_data['category_description_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
                    }
                    $temp = compact('action', 'category_data');
                    blog_plugins::plugin_do_ref('acp_category_add_edit', $temp);
                    extract($temp);
                    $errors = $this->update_category_data($category_data);
                    if (!sizeof($errors)) {
                        $message = $action == 'add' ? $user->lang['CATEGORY_CREATED'] : $user->lang['CATEGORY_UPDATED'];
                        trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
                    }
                    break;
            }
        }
        switch ($action) {
            case 'move_up':
            case 'move_down':
                if (!$category_id) {
                    trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . BLOGS_CATEGORIES_TABLE . "\n\t\t\t\t\tWHERE category_id = {$category_id}";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$row) {
                    trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                $move_category_name = $this->move_category_by($row, $action, 1);
                break;
            case 'add':
            case 'edit':
                // Show form to create/modify a category
                if ($action == 'edit') {
                    $this->page_title = 'EDIT_CATEGORY';
                    $row = $this->get_category_info($category_id);
                    if (!$update) {
                        $category_data = $row;
                    } else {
                        $category_data['left_id'] = $row['left_id'];
                        $category_data['right_id'] = $row['right_id'];
                    }
                    // Make sure no direct child categories are able to be selected as parents.
                    $exclude_categories = array();
                    foreach (get_category_branch($category_id, 'children') as $row) {
                        $exclude_categories[] = $row['category_id'];
                    }
                    $parents_list = make_category_select($category_data['parent_id'], $exclude_categories);
                } else {
                    $this->page_title = 'CREATE_CATEGORY';
                    $category_id = $this->parent_id;
                    $parents_list = make_category_select($this->parent_id);
                    // Fill category data with default values
                    if (!$update) {
                        $category_data = array('parent_id' => $this->parent_id, 'category_name' => utf8_normalize_nfc(request_var('category_name', '', true)), 'category_description' => '', 'rules' => '');
                    }
                }
                $rules_data = array('text' => $category_data['rules'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                $category_description_data = array('text' => $category_data['category_description'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                $rules_preview = '';
                // Parse rules if specified
                if ($category_data['rules']) {
                    if (!isset($category_data['rules_uid'])) {
                        // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
                        $category_data['rules_uid'] = '';
                        $category_data['rules_bitfield'] = '';
                        $category_data['rules_options'] = 0;
                        generate_text_for_storage($category_data['rules'], $category_data['rules_uid'], $category_data['rules_bitfield'], $category_data['rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
                    }
                    // Generate preview content
                    $rules_preview = generate_text_for_display($category_data['rules'], $category_data['rules_uid'], $category_data['rules_bitfield'], $category_data['rules_options']);
                    // decode...
                    $rules_data = generate_text_for_edit($category_data['rules'], $category_data['rules_uid'], $category_data['rules_options']);
                }
                // Parse desciption if specified
                if ($category_data['category_description']) {
                    if (!isset($category_data['category_description_uid'])) {
                        // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
                        $category_data['category_description_uid'] = '';
                        $category_data['category_description_bitfield'] = '';
                        $category_data['category_description_options'] = 0;
                        generate_text_for_storage($category_data['category_description'], $category_data['category_description_uid'], $category_data['category_description_bitfield'], $category_data['category_description_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
                    }
                    // decode...
                    $category_description_data = generate_text_for_edit($category_data['category_description'], $category_data['category_description_uid'], $category_data['category_description_options']);
                }
                $sql = 'SELECT category_id
					FROM ' . BLOGS_CATEGORIES_TABLE . "\n\t\t\t\t\t\tWHERE category_id <> {$category_id}";
                $result = $db->sql_query($sql);
                if ($db->sql_fetchrow($result)) {
                    $template->assign_vars(array('S_MOVE_CATEGORY_OPTIONS' => make_category_select($category_data['parent_id'], $category_id)));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_ADD_ACTION' => $mode == 'add' ? true : false, 'S_EDIT_CATEGORY' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_PARENT_ID' => $this->parent_id, 'S_CATEGORY_PARENT_ID' => $category_data['parent_id'], 'S_PARENT_OPTIONS' => $parents_list, 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id, 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action={$action}&amp;c={$category_id}", 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'CATEGORY_NAME' => $category_data['category_name'], 'RULES' => $category_data['rules'], 'RULES_PREVIEW' => $rules_preview, 'RULES_PLAIN' => $rules_data['text'], 'S_BBCODE_CHECKED' => $rules_data['allow_bbcode'] ? true : false, 'S_SMILIES_CHECKED' => $rules_data['allow_smilies'] ? true : false, 'S_URLS_CHECKED' => $rules_data['allow_urls'] ? true : false, 'CATEGORY_DESCRIPTION' => $category_description_data['text'], 'S_DESC_BBCODE_CHECKED' => $category_description_data['allow_bbcode'] ? true : false, 'S_DESC_SMILIES_CHECKED' => $category_description_data['allow_smilies'] ? true : false, 'S_DESC_URLS_CHECKED' => $category_description_data['allow_urls'] ? true : false, 'S_CATEGORY_OPTIONS' => make_category_select($action == 'add' ? $category_data['parent_id'] : false, $action == 'edit' ? $category_data['category_id'] : false)));
                blog_plugins::plugin_do('acp_category_add_edit_initial');
                return;
                break;
            case 'delete':
                if (!$category_id) {
                    trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                $category_data = $this->get_category_info($category_id);
                $subcategories_id = array();
                $subcategories = get_category_branch($category_id, 'children');
                foreach ($subcategories as $row) {
                    $subcategories_id[] = $row['category_id'];
                }
                $categories_list = make_category_select($category_data['parent_id'], $subcategories_id);
                $sql = 'SELECT category_id
					FROM ' . BLOGS_CATEGORIES_TABLE . "\n\t\t\t\t\t\tWHERE category_id <> {$category_id}";
                $result = $db->sql_query($sql);
                if ($db->sql_fetchrow($result)) {
                    $template->assign_vars(array('S_MOVE_CATEGORY_OPTIONS' => make_category_select($category_data['parent_id'], $subcategories_id)));
                }
                $db->sql_freeresult($result);
                $parent_id = $this->parent_id == $category_id ? 0 : $this->parent_id;
                $template->assign_vars(array('S_DELETE_CATEGORY' => true, 'U_ACTION' => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;c={$category_id}", 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id, 'CATEGORY_NAME' => $category_data['category_name'], 'S_HAS_SUBCATEGORYS' => $category_data['right_id'] - $category_data['left_id'] > 1 ? true : false, 'S_CATEGORIES_LIST' => $categories_list, 'S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : ''));
                return;
                break;
        }
        // Default management page
        if (!$this->parent_id) {
            $navigation = $user->lang['CATEGORY_INDEX'];
        } else {
            $navigation = '<a href="' . $this->u_action . '">' . $user->lang['CATEGORY_INDEX'] . '</a>';
            $category_nav = get_category_branch($this->parent_id, 'parents', 'descending');
            foreach ($category_nav as $row) {
                if ($row['category_id'] == $this->parent_id) {
                    $navigation .= ' -&gt; ' . $row['category_name'];
                } else {
                    $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['category_id'] . '">' . $row['category_name'] . '</a>';
                }
            }
        }
        // Jumpbox
        $category_box = make_category_select($this->parent_id);
        $sql = 'SELECT *
			FROM ' . BLOGS_CATEGORIES_TABLE . "\n\t\t\tWHERE parent_id = {$this->parent_id}\n\t\t\tORDER BY left_id";
        $result = $db->sql_query($sql);
        if ($row = $db->sql_fetchrow($result)) {
            do {
                $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;c={$row['category_id']}";
                $category_title = $row['category_name'];
                $template->assign_block_vars('categories', array('CATEGORY_NAME' => $row['category_name'], 'CATEGORY_DESCRIPTION' => generate_text_for_display($row['category_description'], $row['category_description_uid'], $row['category_description_bitfield'], $row['category_description_options']), 'U_CATEGORY' => $this->u_action . '&amp;parent_id=' . $row['category_id'], 'U_MOVE_UP' => $url . '&amp;action=move_up', 'U_MOVE_DOWN' => $url . '&amp;action=move_down', 'U_EDIT' => $url . '&amp;action=edit', 'U_DELETE' => $url . '&amp;action=delete'));
            } while ($row = $db->sql_fetchrow($result));
        } else {
            if ($this->parent_id) {
                $row = $this->get_category_info($this->parent_id);
                $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;c=' . $row['category_id'];
                $template->assign_vars(array('S_NO_CATEGORIES' => true, 'U_EDIT' => $url . '&amp;action=edit', 'U_DELETE' => $url . '&amp;action=delete'));
            }
        }
        $db->sql_freeresult($result);
        $template->assign_vars(array('ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'NAVIGATION' => $navigation, 'CATEGORY_BOX' => $category_box, 'U_SEL_ACTION' => $this->u_action, 'U_ACTION' => $this->u_action . '&amp;parent_id=' . $this->parent_id));
    }
コード例 #10
0
/**
* Get subscription types
*/
function get_blog_subscription_types()
{
    global $config, $blog_plugins;
    if (!$config['user_blog_subscription_enabled']) {
        return array();
    }
    // First is the subscription ID (which will use the bitwise operator), the second is the language variable.
    $subscription_types = array();
    if ($config['allow_privmsg']) {
        $subscription_types[1] = 'PRIVATE_MESSAGE';
    }
    if ($config['email_enable']) {
        $subscription_types[2] = 'EMAIL';
    }
    /* Remember, we use the bitwise operator to find out what subscription type is the users default, like the bbcode options.
    	So if you add more, use 1,2,4,8,16,32,64,etc and make sure to use the next available number, don't assume 4 is available! */
    blog_plugins::plugin_do_ref('function_get_subscription_types', $subscription_types);
    return $subscription_types;
}
コード例 #11
0
/**
 *  Check blog permissions
 *
 * @param string $page The page requested - blog, reply, mcp, install, upgrade, update, dev, resync
 * @param string $mode The mode requested - depends on the $page requested
 * @param bool $return If you would like this function to return true or false (if they have permission or not).  If it is false we give them a login box if they are not logged in, or give them the NO_AUTH error message
 * @param int $blog_id The blog_id requested (needed for some things, like blog edit, delete, etc
 * @param int $reply_id The reply_id requested, used for the same reason as $blog_id
 *
 * @return Returns
 *	- true if the user is authorized to do the requested action
 *	- false if the user is not authorized to do the requested action
 */
function check_blog_permissions($page, $mode, $return = false, $blog_id = 0, $reply_id = 0)
{
    global $user, $config, $auth, $blog_plugins;
    blog_plugins::plugin_do('function_check_blog_permissions');
    switch ($page) {
        case 'blog':
            switch ($mode) {
                case 'add':
                    $is_auth = $auth->acl_get('u_blogpost') ? true : false;
                    break;
                case 'edit':
                    $is_auth = $user->data['user_id'] != ANONYMOUS && ($auth->acl_get('u_blogedit') && $user->data['user_id'] == blog_data::$blog[$blog_id]['user_id'] || $auth->acl_get('m_blogedit')) ? true : false;
                    break;
                case 'delete':
                    if (blog_data::$blog[$blog_id]['blog_deleted'] == 0 || $auth->acl_get('a_blogdelete')) {
                        $is_auth = $user->data['user_id'] != ANONYMOUS && ($auth->acl_get('u_blogdelete') && $user->data['user_id'] == blog_data::$blog[$blog_id]['user_id'] || $auth->acl_get('m_blogdelete') || $auth->acl_get('a_blogdelete')) ? true : false;
                    } else {
                        $is_auth = false;
                    }
                    break;
                case 'undelete':
                    $is_auth = $auth->acl_gets('m_blogdelete', 'a_blogdelete') || blog_data::$blog[$blog_id]['blog_deleted'] == $user->data['user_id'] ? true : false;
                    break;
                case 'report':
                    $is_auth = $auth->acl_get('u_blogreport') ? true : false;
                    break;
                case 'approve':
                    $is_auth = $auth->acl_get('m_blogapprove') ? true : false;
                    break;
                case 'vote':
                    $is_auth = $auth->acl_get('u_blog_vote') && handle_user_blog_permissions($blog_id) ? true : false;
                    break;
            }
            break;
        case 'reply':
            switch ($mode) {
                case 'add':
                case 'quote':
                    $is_auth = $auth->acl_get('u_blogreply') && handle_user_blog_permissions($blog_id, false, 'reply') ? true : false;
                    break;
                case 'edit':
                    $is_auth = $user->data['user_id'] != ANONYMOUS && ($auth->acl_get('u_blogreplyedit') && $user->data['user_id'] == blog_data::$reply[$reply_id]['user_id'] || isset(blog_data::$blog[$blog_id]['user_id']) && $auth->acl_get('u_blogmoderate') && $user->data['user_id'] == blog_data::$blog[$blog_id]['user_id'] || $auth->acl_get('m_blogreplyedit')) ? true : false;
                    break;
                case 'delete':
                    if (blog_data::$reply[$reply_id]['reply_deleted'] == 0 || $auth->acl_get('a_blogreplydelete')) {
                        $is_auth = $user->data['user_id'] != ANONYMOUS && ($auth->acl_get('u_blogreplydelete') && $user->data['user_id'] == blog_data::$reply[$reply_id]['user_id'] || isset(blog_data::$blog[$blog_id]['user_id']) && $auth->acl_get('u_blogmoderate') && $user->data['user_id'] == blog_data::$blog[$blog_id]['user_id'] || $auth->acl_gets('a_blogreplydelete', 'm_blogreplydelete')) ? true : false;
                    } else {
                        $is_auth = false;
                    }
                    break;
                case 'undelete':
                    $is_auth = $auth->acl_gets('m_blogreplydelete', 'a_blogreplydelete') || blog_data::$reply[$reply_id]['reply_deleted'] == $user->data['user_id'] ? true : false;
                    break;
                case 'report':
                    $is_auth = $auth->acl_get('u_blogreport') ? true : false;
                    break;
                case 'approve':
                    $is_auth = $auth->acl_get('m_blogreplyapprove') ? true : false;
                    break;
            }
            break;
        case 'mcp':
            $is_auth = $auth->acl_gets('m_blogapprove', 'acl_m_blogreport') ? true : false;
            break;
        case 'rate':
            $is_auth = $user->data['is_registered'] ? true : false;
            break;
        case 'install':
        case 'update':
        case 'upgrade':
        case 'dev':
        case 'resync':
            $is_auth = $user->data['user_type'] == USER_FOUNDER ? true : false;
            $founder = true;
            break;
    }
    $temp = compact('is_auth', 'page', 'mode', 'blog_id', 'reply_id');
    blog_plugins::plugin_do_ref('permissions_end', $temp);
    extract($temp);
    // if $is_auth hasn't been set yet they are just viewing a blog/user/etc, if it has been set also check to make sure they can view blogs
    if (!isset($is_auth)) {
        $is_auth = $auth->acl_get('u_blogview') ? true : false;
    } else {
        // if it is the install page they will not have viewing permissions, but they already need to be a founder :P
        $is_auth = !$auth->acl_get('u_blogview') && $page != 'install' ? false : $is_auth;
    }
    if (!$return) {
        if (!$is_auth) {
            if (!$user->data['is_registered']) {
                global $template;
                $template->set_template();
                // reset the template.  Required because of user styles.
                login_box();
            } else {
                if (isset($founder) && $founder) {
                    trigger_error('MUST_BE_FOUNDER');
                } else {
                    trigger_error('NO_AUTH_OPERATION');
                }
            }
        }
    } else {
        return $is_auth;
    }
}
コード例 #12
0
ファイル: blog.php プロジェクト: EXreaction/User-Blog-Mod
if ($default) {
    // for highlighting
    $highlight_match = $highlight = '';
    if ($hilit_words) {
        foreach (explode(' ', trim($hilit_words)) as $word) {
            if (trim($word)) {
                $word = str_replace('\\*', '\\w+?', preg_quote($word, '#'));
                $word = preg_replace('#(^|\\s)\\\\w\\*\\?(\\s|$)#', '$1\\w+?$2', $word);
                $highlight_match .= ($highlight_match != '' ? '|' : '') . $word;
            }
        }
        $highlight = urlencode($hilit_words);
    }
    // If you are adding your own page with this, make sure to set $default to false if the page matches yours, otherwise it will load the default page below
    $temp = compact('page', 'mode', 'default', 'inc_file', 'user_style');
    blog_plugins::plugin_do_ref('blog_page_switch', $temp);
    extract($temp);
    // Check again since a plugin could have used it's own page.
    if ($default) {
        $user->add_lang('mods/blog/view');
        // With SEO urls, we make it so that the page could be the username name of the user we want to view...
        if (!$user_id && $page && !$category_id && !in_array($page, array('last_visit_blogs', 'random_blogs', 'recent_blogs', 'popular_blogs', 'recent_comments'))) {
            $user_id = $blog_data->get_user_data(false, false, $page);
        }
        if ($blog_id || $reply_id) {
            $user_style = true;
            // Here and the view user page are the two places where users can view with their own custom style
            $inc_file = $inc_file ? array($inc_file, 'view/single') : 'view/single';
        } else {
            if ($user_id) {
                $user_style = true;
コード例 #13
0
/**
* Get all blog categories
*/
function get_blog_categories($order = 'left_id')
{
    global $cache;
    $blog_categories = $cache->get('_blog_categories');
    if ($blog_categories === false) {
        global $db;
        $blog_categories = array();
        $sql = 'SELECT * FROM ' . BLOGS_CATEGORIES_TABLE . "\n\t\t\tORDER BY left_id ASC";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $blog_categories[$row['left_id']] = $row;
        }
        $db->sql_freeresult($result);
        $cache->put('_blog_categories', $blog_categories);
    }
    if ($order != 'left_id') {
        $blog_cats = $blog_categories;
        $blog_categories = array();
        foreach ($blog_cats as $left_id => $row) {
            $blog_categories[$row[$order]] = $row;
        }
    }
    blog_plugins::plugin_do_ref('function_get_blog_categories', $blog_categories);
    return $blog_categories;
}
コード例 #14
0
/**
* Build configuration template for confirm pages
*
* Originally from adm/index.php
*/
function build_blog_cfg_template($tpl_type, $name, $default)
{
    global $user;
    $tpl = '';
    $name = 'setting[' . $name . ']';
    switch ($tpl_type[0]) {
        case 'text':
        case 'password':
            $size = (int) $tpl_type[1];
            $maxlength = (int) $tpl_type[2];
            $tpl = '<input id="' . $name . '" type="' . $tpl_type[0] . '"' . ($size ? ' size="' . $size . '"' : '') . ' maxlength="' . ($maxlength ? $maxlength : 255) . '" name="' . $name . '" value="' . $default . '" />';
            break;
        case 'textarea':
            $rows = (int) $tpl_type[1];
            $cols = (int) $tpl_type[2];
            $tpl = '<textarea id="' . $name . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $default . '</textarea>';
            break;
        case 'radio':
            $name_yes = $default ? ' checked="checked"' : '';
            $name_no = !$default ? ' checked="checked"' : '';
            $tpl_type_cond = explode('_', $tpl_type[1]);
            $type_no = $tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled' ? false : true;
            $tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $name_no . ' class="radio" /> ' . ($type_no ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
            $tpl_yes = '<label><input type="radio" id="' . $name . '" name="' . $name . '" value="1"' . $name_yes . ' class="radio" /> ' . ($type_no ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
            $tpl = $tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled' ? $tpl_yes . ' ' . $tpl_no : $tpl_no . ' ' . $tpl_yes;
            break;
        case 'checkbox':
            $tpl = '<input type="checkbox" name="' . $name . '"  id="' . $name . '"' . ($default ? ' checked="checked"' : '') . ' />';
            break;
        default:
            $temp = compact('tpl_type', 'name', 'default', 'tpl');
            blog_plugins::plugin_do_ref('function_build_blog_cfg_template', $temp);
            extract($temp);
            break;
    }
    return $tpl;
}
コード例 #15
0
ファイル: rate.php プロジェクト: EXreaction/User-Blog-Mod
$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) {
    $total_rating = $total_count = 0;
    $sql = 'SELECT * FROM ' . BLOGS_RATINGS_TABLE . ' WHERE blog_id = ' . intval($blog_id);
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $total_rating += $row['rating'];
        $total_count++;
    }
    $db->sql_freeresult($result);
    $average_rating = $total_count ? round($total_rating / $total_count, 2) : 0;
    $sql = 'UPDATE ' . BLOGS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array('rating' => $average_rating, 'num_ratings' => $total_count)) . ' WHERE blog_id = ' . intval($blog_id);
    $db->sql_query($sql);
    //$cache->destroy('_blog_rating_' . $user->data['user_id']);
}
blog_meta_refresh(0, $blog_urls['view_blog']);
コード例 #16
0
ファイル: edit.php プロジェクト: EXreaction/User-Blog-Mod
        // output some data to the template parser
        $template->assign_vars(array('S_DISPLAY_PREVIEW' => true, 'PREVIEW_SUBJECT' => censor_text($blog_subject), 'PREVIEW_MESSAGE' => $preview_message, 'POST_DATE' => $user->format_date(blog_data::$blog[$blog_id]['blog_time'])));
    }
    blog_plugins::plugin_do('blog_edit_after_preview');
    // handles the basic data we need to output for posting
    handle_basic_posting_data(false, 'blog', 'edit');
    // Assign some variables to the template parser
    $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'MESSAGE' => $blog_text, 'POLL_TITLE' => $poll_title, 'POLL_OPTIONS' => $poll_option_text ? $poll_option_text : '', 'POLL_MAX_OPTIONS' => $poll_max_options, 'POLL_LENGTH' => $poll_length, 'SUBJECT' => $blog_subject, 'VOTE_CHANGE_CHECKED' => $poll_vote_change ? 'checked="checked"' : '', 'L_MESSAGE_BODY_EXPLAIN' => intval($config['max_post_chars']) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '', 'L_POST_A' => $user->lang['EDIT_A_BLOG'], 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']), 'S_EDIT_REASON' => true, 'S_LOCK_POST_ALLOWED' => $auth->acl_get('m_bloglockedit') && $user->data['user_id'] != blog_data::$blog[$blog_id]['user_id'] ? true : false, 'S_POLL_DELETE' => $poll_title ? true : false, 'S_POLL_VOTE_CHANGE' => true));
    $template->set_filenames(array('body' => 'blog/blog_posting_layout.html'));
} else {
    // insert array
    $sql_data = array('user_ip' => $user->data['user_id'] == $user_id ? $user->data['user_ip'] : blog_data::$blog[$blog_id]['user_ip'], 'blog_subject' => $blog_subject, 'blog_text' => $message_parser->message, 'blog_checksum' => md5($message_parser->message), 'blog_approved' => blog_data::$blog[$blog_id]['blog_approved'] == 1 || $auth->acl_get('u_blognoapprove') ? 1 : 0, 'enable_bbcode' => $post_options->enable_bbcode, 'enable_smilies' => $post_options->enable_smilies, 'enable_magic_url' => $post_options->enable_magic_url, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'blog_edit_time' => time(), 'blog_edit_reason' => utf8_normalize_nfc(request_var('edit_reason', '', true)), 'blog_edit_user' => $user->data['user_id'], 'blog_edit_count' => blog_data::$blog[$blog_id]['blog_edit_count'] + 1, 'blog_edit_locked' => $auth->acl_get('m_bloglockedit') && $user->data['user_id'] != blog_data::$blog[$blog_id]['user_id'] ? request_var('lock_post', false) : false, 'perm_guest' => request_var('perm_guest', 1), 'perm_registered' => request_var('perm_registered', 2), 'perm_foe' => request_var('perm_foe', 0), 'perm_friend' => request_var('perm_friend', 2), 'blog_attachment' => sizeof($blog_attachment->attachment_data) ? 1 : 0, 'poll_title' => !empty($poll) ? $poll_title : '', 'poll_length' => !empty($poll) && $poll_length ? time() + $poll_length * 86400 : 0, 'poll_max_options' => !empty($poll) ? max($poll_max_options, 1) : 1, 'poll_vote_change' => !empty($poll) ? $poll_vote_change : 0);
    if ($original_poll_text != $poll_option_text) {
        $sql_data['poll_start'] = empty($poll) ? 0 : time();
    }
    blog_plugins::plugin_do_ref('blog_edit_sql', $sql_data);
    $sql = 'UPDATE ' . BLOGS_TABLE . '
		SET ' . $db->sql_build_array('UPDATE', $sql_data) . '
			WHERE blog_id = ' . intval($blog_id);
    $db->sql_query($sql);
    // Reindex the blog
    $blog_search->index('edit', $blog_id, 0, $message_parser->message, $blog_subject, $user_id);
    // Update the attachments
    $blog_attachment->update_attachment_data($blog_id, 0, blog_data::$blog[$blog_id]['user_id']);
    blog_plugins::plugin_do_arg('blog_edit_after_sql', $blog_id);
    // Submit the poll
    if ($auth->acl_get('u_blog_create_poll')) {
        submit_blog_poll($poll, $blog_id, 'edit');
    }
    // Handle the subscriptions
    add_blog_subscriptions($blog_id, 'subscription_');
コード例 #17
0
    /**
     * General attachment parsing
     *
     * @param string &$message The post/private message
     * @param array &$attachments The attachments to parse for (inline) display. The attachments array will hold templated data after parsing.
     * @param array &$update_count The attachment counts to be updated - will be filled
     * @param bool $preview If set to true the attachments are parsed for preview. Within preview mode the comments are fetched from the given $attachments array and not fetched from the database.
     */
    public function parse_attachments_for_view(&$message, &$attachments, &$update_count, $preview = false)
    {
        global $template, $user, $config, $phpbb_root_path, $auth;
        if (!$config['user_blog_enable_attachments'] || !sizeof($attachments) || !$auth->acl_get('u_download')) {
            return;
        }
        $compiled_attachments = array();
        $temp = compact('message', 'attachments', 'update_count', 'preview', 'compiled_attachments');
        blog_plugins::plugin_do_ref('function_parse_attachments_for_view', $temp);
        extract($temp);
        if (!isset($template->filename['attachment_tpl'])) {
            $template->set_filenames(array('attachment_tpl' => 'attachment.html'));
        }
        $extensions = $this->obtain_blog_attach_extensions();
        // Look for missing attachment information...
        $attach_ids = array();
        foreach ($attachments as $pos => $attachment) {
            // If is_orphan is set, we need to retrieve the attachments again...
            if (!isset($attachment['extension']) && !isset($attachment['physical_filename'])) {
                $attach_ids[(int) $attachment['attach_id']] = $pos;
            }
        }
        // Grab attachments (security precaution)
        if (sizeof($attach_ids)) {
            global $db;
            $new_attachment_data = array();
            $sql = 'SELECT *
				FROM ' . BLOGS_ATTACHMENT_TABLE . '
				WHERE ' . $db->sql_in_set('attach_id', array_unique(array_map('intval', array_keys($attach_ids))));
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if (!isset($attach_ids[$row['attach_id']])) {
                    continue;
                }
                // If we preview attachments we will set some retrieved values here
                if ($preview) {
                    $row['attach_comment'] = $attachments[$attach_ids[$row['attach_id']]]['attach_comment'];
                }
                $new_attachment_data[$attach_ids[$row['attach_id']]] = $row;
            }
            $db->sql_freeresult($result);
            $attachments = $new_attachment_data;
            unset($new_attachment_data);
        }
        ksort($attachments);
        foreach ($attachments as $attachment) {
            if (!sizeof($attachment)) {
                continue;
            }
            // We need to reset/empty the _file block var, because this function might be called more than once
            $template->destroy_block_vars('_file');
            $block_array = array();
            // Some basics...
            $attachment['extension'] = strtolower(trim($attachment['extension']));
            $filename = $phpbb_root_path . $config['upload_path'] . '/blog_mod/' . basename($attachment['physical_filename']);
            $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/blog_mod/thumb_' . basename($attachment['physical_filename']);
            $upload_icon = '';
            if (isset($extensions[$attachment['extension']])) {
                if ($user->img('icon_topic_attach', '') && !$extensions[$attachment['extension']]['upload_icon']) {
                    $upload_icon = $user->img('icon_topic_attach', '');
                } else {
                    if ($extensions[$attachment['extension']]['upload_icon']) {
                        $upload_icon = '<img src="' . $phpbb_root_path . $config['upload_icons_path'] . '/' . trim($extensions[$attachment['extension']]['upload_icon']) . '" alt="" />';
                    }
                }
            }
            $filesize = $attachment['filesize'];
            $size_lang = $filesize >= 1048576 ? $user->lang['MB'] : ($filesize >= 1024 ? $user->lang['KB'] : $user->lang['BYTES']);
            $filesize = $filesize >= 1048576 ? round(round($filesize / 1048576 * 100) / 100, 2) : ($filesize >= 1024 ? round(round($filesize / 1024 * 100) / 100, 2) : $filesize);
            $comment = str_replace("\n", '<br />', censor_text($attachment['attach_comment']));
            $block_array += array('UPLOAD_ICON' => $upload_icon, 'FILESIZE' => $filesize, 'SIZE_LANG' => $size_lang, 'DOWNLOAD_NAME' => basename($attachment['real_filename']), 'COMMENT' => $comment);
            $denied = false;
            if (!isset($extensions['_allowed_'][$attachment['extension']])) {
                $denied = true;
                $block_array += array('S_DENIED' => true, 'DENIED_MESSAGE' => sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
            }
            if (!$denied) {
                $l_downloaded_viewed = $download_link = '';
                $display_cat = $extensions[$attachment['extension']]['display_cat'];
                if ($display_cat == ATTACHMENT_CATEGORY_IMAGE) {
                    if ($attachment['thumbnail']) {
                        $display_cat = ATTACHMENT_CATEGORY_THUMB;
                    } else {
                        if ($config['img_display_inlined']) {
                            if ($config['img_link_width'] || $config['img_link_height']) {
                                $dimension = @getimagesize($filename);
                                // If the dimensions could not be determined or the image being 0x0 we display it as a link for safety purposes
                                if ($dimension === false || empty($dimension[0]) || empty($dimension[1])) {
                                    $display_cat = ATTACHMENT_CATEGORY_NONE;
                                } else {
                                    $display_cat = $dimension[0] <= $config['img_link_width'] && $dimension[1] <= $config['img_link_height'] ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE;
                                }
                            }
                        } else {
                            $display_cat = ATTACHMENT_CATEGORY_NONE;
                        }
                    }
                }
                // Make some descisions based on user options being set.
                if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg')) {
                    $display_cat = ATTACHMENT_CATEGORY_NONE;
                }
                if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash')) {
                    $display_cat = ATTACHMENT_CATEGORY_NONE;
                }
                $download_link = blog_url(false, false, false, array('page' => 'download', 'mode' => 'download', 'id' => $attachment['attach_id']));
                switch ($display_cat) {
                    // Images
                    case ATTACHMENT_CATEGORY_IMAGE:
                        $l_downloaded_viewed = 'VIEWED_COUNT';
                        $inline_link = blog_url(false, false, false, array('page' => 'download', 'mode' => 'download', 'id' => $attachment['attach_id']));
                        $block_array += array('S_IMAGE' => true, 'U_INLINE_LINK' => $inline_link);
                        $update_count[] = $attachment['attach_id'];
                        break;
                        // Images, but display Thumbnail
                    // Images, but display Thumbnail
                    case ATTACHMENT_CATEGORY_THUMB:
                        $l_downloaded_viewed = 'VIEWED_COUNT';
                        $thumbnail_link = blog_url(false, false, false, array('page' => 'download', 'mode' => 'thumbnail', 'id' => $attachment['attach_id']));
                        $block_array += array('S_THUMBNAIL' => true, 'THUMB_IMAGE' => $thumbnail_link);
                        break;
                        // Windows Media Streams
                    // Windows Media Streams
                    case ATTACHMENT_CATEGORY_WM:
                        $l_downloaded_viewed = 'VIEWED_COUNT';
                        // Giving the filename directly because within the wm object all variables are in local context making it impossible
                        // to validate against a valid session (all params can differ)
                        // $download_link = $filename;
                        $block_array += array('U_FORUM' => generate_board_url(), 'ATTACH_ID' => $attachment['attach_id'], 'S_WM_FILE' => true);
                        // Viewed/Heared File ... update the download count
                        $update_count[] = $attachment['attach_id'];
                        break;
                        // Real Media Streams
                    // Real Media Streams
                    case ATTACHMENT_CATEGORY_RM:
                    case ATTACHMENT_CATEGORY_QUICKTIME:
                        $l_downloaded_viewed = 'VIEWED_COUNT';
                        $block_array += array('S_RM_FILE' => $display_cat == ATTACHMENT_CATEGORY_RM ? true : false, 'S_QUICKTIME_FILE' => $display_cat == ATTACHMENT_CATEGORY_QUICKTIME ? true : false, 'U_FORUM' => generate_board_url(), 'ATTACH_ID' => $attachment['attach_id']);
                        // Viewed/Heared File ... update the download count
                        $update_count[] = $attachment['attach_id'];
                        break;
                        // Macromedia Flash Files
                    // Macromedia Flash Files
                    case ATTACHMENT_CATEGORY_FLASH:
                        list($width, $height) = @getimagesize($filename);
                        $l_downloaded_viewed = 'VIEWED_COUNT';
                        $block_array += array('S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height);
                        // Viewed/Heared File ... update the download count
                        $update_count[] = $attachment['attach_id'];
                        break;
                    default:
                        $l_downloaded_viewed = 'DOWNLOAD_COUNT';
                        $block_array += array('S_FILE' => true);
                        break;
                }
                $l_download_count = !isset($attachment['download_count']) || $attachment['download_count'] == 0 ? $user->lang[$l_downloaded_viewed . '_NONE'] : ($attachment['download_count'] == 1 ? sprintf($user->lang[$l_downloaded_viewed], $attachment['download_count']) : sprintf($user->lang[$l_downloaded_viewed . 'S'], $attachment['download_count']));
                $block_array += array('U_DOWNLOAD_LINK' => $download_link, 'L_DOWNLOAD_COUNT' => $l_download_count);
            }
            $template->assign_block_vars('_file', $block_array);
            $compiled_attachments[] = $template->assign_display('attachment_tpl');
        }
        $attachments = $compiled_attachments;
        unset($compiled_attachments);
        $tpl_size = sizeof($attachments);
        $unset_tpl = array();
        preg_match_all('#<!\\-\\- ia([0-9]+) \\-\\->(.*?)<!\\-\\- ia\\1 \\-\\->#', $message, $matches, PREG_PATTERN_ORDER);
        $replace = array();
        foreach ($matches[0] as $num => $capture) {
            // Flip index if we are displaying the reverse way
            $index = $config['display_order'] ? $tpl_size - ($matches[1][$num] + 1) : $matches[1][$num];
            $replace['from'][] = $matches[0][$num];
            $replace['to'][] = isset($attachments[$index]) ? $attachments[$index] : sprintf($user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]);
            $unset_tpl[] = $index;
        }
        if (isset($replace['from'])) {
            $message = str_replace($replace['from'], $replace['to'], $message);
        }
        $unset_tpl = array_unique($unset_tpl);
        // Needed to let not display the inlined attachments at the end of the post again
        foreach ($unset_tpl as $index) {
            unset($attachments[$index]);
        }
    }