示例#1
0
/**
* For display of custom parsed text on user-facing pages
* Expects $text to be the value directly from the database (stored value)
*/
function generate_text_for_display($text, $only_smileys = false, $censor = true, $acro_autolinks = false, $forum_id = '999999')
{
    global $bbcode, $config, $user;
    if (empty($text)) {
        return '';
    }
    if (defined('IS_ICYPHOENIX') && $censor) {
        $text = censor_text($text);
    }
    if (!class_exists('bbcode') || empty($bbcode)) {
        include_once IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT;
    }
    if (empty($bbcode)) {
        $bbcode = new bbcode();
        if (!$user->data['session_logged_in']) {
            $user->data['user_allowhtml'] = $config['allow_html'] ? true : false;
            $user->data['user_allowbbcode'] = $config['allow_bbcode'] ? true : false;
            $user->data['user_allowsmile'] = $config['allow_smilies'] ? true : false;
        }
        $bbcode->allow_html = $user->data['user_allowhtml'] && $config['allow_html'] ? true : false;
        $bbcode->allow_bbcode = $user->data['user_allowbbcode'] && $config['allow_bbcode'] ? true : false;
        $bbcode->allow_smilies = $user->data['user_allowsmile'] && $config['allow_smilies'] ? true : false;
    }
    if ($only_smileys) {
        $text = $bbcode->parse_only_smilies($text);
    } else {
        $text = $bbcode->parse($text);
        if ($acro_autolinks) {
            $text = $bbcode->acronym_pass($text);
            $text = $bbcode->autolink_text($text, $forum_id);
        }
    }
    return $text;
}
function get_event_topics(&$events, &$number, $start_date, $end_date, $limit = false, $start = 0, $max_limit = -1, $fid = '')
{
    global $tree, $template, $lang, $images, $user, $db, $cache, $config, $bbcode;
    if (!class_exists('bbcode')) {
        include IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT;
    }
    if (empty($bbcode)) {
        $bbcode = new bbcode();
    }
    // get some parameter
    $topic_title_length = isset($config['calendar_title_length']) ? intval($config['calendar_title_length']) : 30;
    $topic_text_length = isset($config['calendar_text_length']) ? intval($config['calendar_text_length']) : 200;
    if ($max_limit < 0) {
        $max_limit = $config['topics_per_page'];
    }
    // get the forums authorized (compliency with categories hierarchy v2 mod)
    $cat_hierarchy = function_exists(get_auth_keys);
    $s_forums_ids = '';
    if (!$cat_hierarchy) {
        // standard read
        $is_auth = array();
        $is_auth = auth(AUTH_ALL, AUTH_LIST_ALL, $user->data);
        // forum or cat asked
        $is_ask = array();
        if ($fid == 'Root' || $fid == POST_CAT_URL . 0) {
            $fid = '';
        }
        if (!empty($fid)) {
            $type = substr($fid, 0, 1);
            $id = intval(substr($fid, 1));
            if ($type == POST_CAT_URL) {
                $sql = "SELECT forum_id FROM " . FORUMS_TABLE . " WHERE parent_id = '" . $id . "'";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $is_ask[$row['forum_id']] = true;
                }
                $db->sql_freeresult($result);
            } elseif ($type == POST_FORUM_URL) {
                $is_ask[$id] = true;
            } else {
                return;
            }
        }
        // get the list of authorized forums
        while (list($forum_id, $forum_auth) = each($is_auth)) {
            if ($forum_auth['auth_read'] && (empty($fid) || isset($is_ask[$forum_id]))) {
                $s_forum_ids .= (empty($s_forum_ids) ? '' : ', ') . $forum_id;
            }
        }
    } else {
        if (empty($fid) || $fid == POST_CAT_URL . 0) {
            $fid = 'Root';
        }
        // get auth key
        $keys = array();
        $keys = get_auth_keys($fid, true, -1, -1, 'auth_read');
        for ($i = 0; $i < sizeof($keys['id']); $i++) {
            if ($tree['type'][$keys['idx'][$i]] == POST_FORUM_URL && $tree['auth'][$keys['id'][$i]]['auth_read']) {
                $s_forum_ids .= (empty($s_forum_ids) ? '' : ', ') . $tree['id'][$keys['idx'][$i]];
            }
        }
    }
    // no forums authed, return
    if (empty($s_forum_ids)) {
        return;
    }
    // select topics
    $sql_forums_field = '';
    $sql_forums_file = '';
    $sql_forums_match = '';
    if (!$cat_hierarchy) {
        $sql_forums_field = ', f.forum_name';
        $sql_forums_file = ', ' . FORUMS_TABLE . ' AS f';
        $sql_forums_match = ' AND f.forum_id = t.forum_id';
    }
    $sql = "SELECT\n\t\t\t\t\tt.*,\n\t\t\t\t\tp.poster_id, p.post_username, p.post_text, p.enable_bbcode, p.enable_html, p.enable_smilies,\n\t\t\t\t\tu.username, u.user_active, u.user_color,\n\t\t\t\t\tlp.poster_id AS lp_poster_id,\n\t\t\t\t\tlu.username AS lp_username,\n\t\t\t\t\tlp.post_username AS lp_post_username,\n\t\t\t\t\tlp.post_time AS lp_post_time\n\t\t\t\t\t{$sql_forums_field}\n\t\t\tFROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u, " . POSTS_TABLE . " AS lp, " . USERS_TABLE . " lu {$sql_forums_file}\n\t\t\tWHERE\n\t\t\t\tt.forum_id IN ({$s_forum_ids})\n\t\t\t\tAND p.post_id = t.topic_first_post_id\n\t\t\t\tAND u.user_id = p.poster_id\n\t\t\t\tAND lp.post_id = t.topic_last_post_id\n\t\t\t\tAND lu.user_id = lp.poster_id\n\t\t\t\tAND t.topic_calendar_time < {$end_date}\n\t\t\t\tAND (t.topic_calendar_time + t.topic_calendar_duration) >= {$start_date}\n\t\t\t\tAND t.topic_status <> " . TOPIC_MOVED . "\n\t\t\t\t{$sql_forums_match}\n\t\t\tORDER BY\n\t\t\t\tt.topic_calendar_time, t.topic_calendar_duration DESC, t.topic_last_post_id DESC";
    $result = $db->sql_query($sql);
    // get the number of occurences
    $number = $db->sql_numrows($result);
    // if limit per page asked, limit the number of results
    if ($limit) {
        $db->sql_freeresult($result);
        $sql .= " LIMIT {$start}, {$max_limit}";
        $result = $db->sql_query($sql);
    }
    $bbcode->allow_html = $user->data['user_allowhtml'] && $config['allow_html'] ? 1 : 0;
    $bbcode->allow_bbcode = $user->data['user_allowbbcode'] && $config['allow_bbcode'] ? 1 : 0;
    $bbcode->allow_smilies = $user->data['user_allowsmile'] && $config['allow_smilies'] ? 1 : 0;
    // read the items
    while ($row = $db->sql_fetchrow($result)) {
        // prepare the message
        $topic_author_id = $row['poster_id'];
        $topic_author = $row['poster_id'] == ANONYMOUS ? $row['post_username'] : $row['username'];
        $topic_time = $row['topic_time'];
        $topic_last_author_id = $row['lp_poster_id'];
        $topic_last_author = $row['lp_poster_id'] == ANONYMOUS ? $row['lp_post_username'] : $row['lp_username'];
        $topic_last_time = $row['lp_post_time'];
        $topic_views = $row['topic_views'];
        $topic_replies = $row['topic_replies'];
        $topic_icon = $row['topic_icon'];
        $topic_title = $row['topic_title'];
        $message = htmlspecialchars($row['post_text']);
        $topic_calendar_time = $row['topic_calendar_time'];
        $topic_calendar_duration = $row['topic_calendar_duration'];
        $topic_link = append_sid(IP_ROOT_PATH . CMS_PAGE_VIEWTOPIC . '?' . POST_TOPIC_URL . '=' . $row['topic_id']);
        $topic_title = censor_text($topic_title);
        $message = censor_text($message);
        $short_title = strlen($topic_title) > $topic_title_length + 3 ? substr($topic_title, 0, $topic_title_length) . '...' : $topic_title;
        // Convert and clean special chars!
        $topic_title = htmlspecialchars_clean($topic_title);
        $short_title = htmlspecialchars_clean($short_title);
        // SMILEYS IN TITLE - BEGIN
        if ($config['smilies_topic_title'] && !$lofi) {
            $topic_title = $bbcode->parse_only_smilies($topic_title);
            $short_title = $bbcode->parse_only_smilies($short_title);
        }
        // SMILEYS IN TITLE - END
        $dsp_topic_icon = '';
        if (function_exists('get_icon_title')) {
            $dsp_topic_icon = get_icon_title($topic_icon, 0, POST_CALENDAR);
        }
        // parse the message
        $message = substr($message, 0, $topic_text_length);
        // remove HTML if not allowed
        if (!$config['allow_html'] && $row['enable_html']) {
            $message = preg_replace('#(<)([\\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
        }
        $message = $bbcode->parse($message);
        // get the date format
        $fmt = $lang['DATE_FORMAT_CALENDAR'];
        if (!empty($topic_calendar_duration)) {
            $fmt = $config['default_dateformat'];
        }
        // replace \n with <br />
        //$message = preg_replace("/[\n\r]{1,2}/", '<br />', $message);
        // build the overview
        $sav_tpl = $template->_tpldata;
        $det_handler = '_overview_topic_' . $row['topic_id'];
        $template->set_filenames(array($det_handler => 'calendar_overview_topic.tpl'));
        $nav_desc = '';
        if ($cat_hierarchy) {
            $nav_desc = make_cat_nav_tree(POST_FORUM_URL . $row['forum_id'], '', '', 'gensmall');
        } else {
            $nav_desc = '<a href="' . append_sid(IP_ROOT_PATH . CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $row['forum_id']) . '" class="gensmall">' . $row['forum_name'] . '</a>';
        }
        $template->assign_vars(array('L_CALENDAR_EVENT' => $lang['Calendar_event'], 'L_AUTHOR' => $lang['Author'], 'L_TOPIC_DATE' => $lang['Date'], 'L_FORUM' => $lang['Forum'], 'L_VIEWS' => $lang['Views'], 'L_REPLIES' => $lang['Replies'], 'TOPIC_TITLE' => $dsp_topic_icon . '&nbsp;' . $topic_title, 'CALENDAR_EVENT' => get_calendar_title_date($topic_calendar_time, $topic_calendar_duration), 'AUTHOR' => $topic_author, 'TOPIC_DATE' => create_date($user->data['user_dateformat'], $topic_time, $config['board_timezone']), 'NAV_DESC' => $nav_desc, 'CALENDAR_MESSAGE' => $message, 'VIEWS' => $topic_views, 'REPLIES' => $topic_replies));
        $template->assign_var_from_handle('_calendar_overview', $det_handler);
        $message = $template->_tpldata['.'][0]['_calendar_overview'];
        $template->_tpldata = $sav_tpl;
        // remove \n remaining from the template
        $message = preg_replace("/[\n\r]{1,2}/", '', $message);
        // store only the new values
        $new_row = array();
        $new_row['event_id'] = POST_TOPIC_URL . $row['topic_id'];
        $new_row['event_author_id'] = $topic_author_id;
        $new_row['event_author'] = $topic_author;
        $new_row['event_author_active'] = $row['user_active'];
        $new_row['event_author_color'] = $row['user_color'];
        $new_row['event_time'] = $topic_time;
        $new_row['event_last_author_id'] = $topic_last_author_id;
        $new_row['event_last_author'] = $topic_last_author;
        $new_row['event_last_time'] = $topic_last_time;
        $new_row['event_replies'] = $topic_replies;
        $new_row['event_views'] = $topic_views;
        $new_row['event_type'] = $row['topic_type'];
        $new_row['event_status'] = $row['topic_status'];
        $new_row['event_moved_id'] = $row['topic_moved_id'];
        $new_row['event_last_id'] = $row['topic_last_post_id'];
        $new_row['event_forum_id'] = $row['forum_id'];
        $new_row['event_forum_name'] = $row['forum_name'];
        $new_row['event_icon'] = $topic_icon;
        $new_row['event_title'] = $topic_title;
        $new_row['event_short_title'] = $short_title;
        $new_row['event_message'] = $message;
        $new_row['event_calendar_time'] = $topic_calendar_time;
        $new_row['event_calendar_duration'] = $topic_calendar_duration;
        $new_row['event_link'] = $topic_link;
        $new_row['event_birthday'] = false;
        $new_row['event_txt_class'] = 'genmed';
        $new_row['event_type_icon'] = '<img src="' . $images['icon_tiny_topic'] . '" style="vertical-align: bottom;" alt="" hspace="2" />';
        $events[] = $new_row;
    }
    $db->sql_freeresult($result);
}
示例#3
0
 function generate_topic_title($topic_id, $topic_data, $max_title_length)
 {
     global $config, $bbcode, $lang, $lofi;
     $max_title_length = (int) $max_title_length > 255 || $max_title_length < 15 ? 255 : $max_title_length;
     $topic_title = censor_text($topic_data['topic_title']);
     $topic_title_clean = empty($topic_data['topic_title_clean']) ? substr(ip_clean_string($topic_title, $lang['ENCODING']), 0, 254) : $topic_data['topic_title_clean'];
     if (empty($topic_data['topic_title_clean'])) {
         if (!function_exists('update_clean_topic_title')) {
             @(include_once IP_ROOT_PATH . 'includes/functions_topics.' . PHP_EXT);
         }
         update_clean_topic_title($topic_id, $topic_title_clean);
     }
     $topic_title_prefix = empty($topic_data['title_compl_infos']) ? '' : trim($topic_data['title_compl_infos']) . ' ';
     // Convert and clean special chars!
     $topic_title = htmlspecialchars_clean($topic_title);
     // SMILEYS IN TITLE - BEGIN
     if ($config['smilies_topic_title'] == true && !$lofi) {
         if (!class_exists('bbcode')) {
             include IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT;
         }
         if (empty($bbcode)) {
             $bbcode = new bbcode();
         }
         $bbcode->allow_smilies = $config['allow_smilies'] && $topic_data['enable_smilies'] ? true : false;
         $topic_title = $bbcode->parse_only_smilies($topic_title);
     }
     // SMILEYS IN TITLE - END
     $topic_title = $topic_title_prefix . $topic_title;
     $topic_title_plain = htmlspecialchars(strip_tags($topic_title));
     $topic_title_short = $topic_title;
     if (strlen($topic_title) > $max_title_length - 3) {
         // remove tags from the short version, in case a smiley or a quick title prefix is in there
         $topic_title_short = substr(strip_tags($topic_title), 0, intval($max_title_length)) . '...';
     }
     $topic_title_data = array('title' => $topic_title, 'title_clean' => $topic_title_clean, 'title_plain' => $topic_title_plain, 'title_prefix' => $topic_title_prefix, 'title_short' => $topic_title_short);
     return $topic_title_data;
 }