/** ---------------------------------------- /** Browse Avatars /** ----------------------------------------*/ function browse_avatars() { global $IN, $DSP, $DB, $LANG, $PREFS, $SESS, $FNS; if (FALSE === ($id = $this->auth_id())) { return $DSP->no_access_message(); } /** ---------------------------------------- /** Are avatars enabled? /** ----------------------------------------*/ if ($PREFS->ini('enable_avatars') == 'n') { return $DSP->error_message($LANG->line('avatars_not_enabled')); } /** ---------------------------------------- /** Define the paths and get the avatars /** ----------------------------------------*/ $avatar_path = $PREFS->ini('avatar_path', TRUE) . $FNS->filename_security($IN->GBL('folder')) . '/'; $avatar_url = $PREFS->ini('avatar_url', TRUE) . $FNS->filename_security($IN->GBL('folder')) . '/'; $avatars = $this->_get_avatars($avatar_path); /** ---------------------------------------- /** Did we succeed? /** ----------------------------------------*/ if (count($avatars) == 0) { return $DSP->error_message($LANG->line('avatars_not_found')); } /** ---------------------------------------- /** Pagination anyone? /** ----------------------------------------*/ $pagination = ''; $max_rows = 2; $max_cols = 3; $col_ct = 0; $perpage = $max_rows * $max_cols; $total_rows = count($avatars); $rownum = $IN->GBL('row') == '' ? 0 : $IN->GBL('row'); $base_url = BASE . AMP . 'C=myaccount' . AMP . 'M=browse_avatars' . AMP . 'id=' . $id . AMP . 'folder=' . $IN->GBL('folder'); if ($rownum > count($avatars)) { $rownum = 0; } if ($total_rows > $perpage) { $avatars = array_slice($avatars, $rownum, $perpage); if (!class_exists('Paginate')) { require PATH_CORE . 'core.paginate' . EXT; } $PGR = new Paginate(); $PGR->base_url = $base_url; $PGR->first_url = $base_url; $PGR->qstr_var = 'row'; $PGR->total_count = $total_rows; $PGR->per_page = $perpage; $PGR->cur_page = $rownum; $pagination = $PGR->show_links(); // We add this for use later if ($rownum != '') { $base_url .= $rownum . '/'; } } /** ---------------------------------------- /** Build the table rows /** ----------------------------------------*/ $avstr = ''; foreach ($avatars as $image) { if ($col_ct == 0) { $avstr .= "<tr>\n"; } $avstr .= "<td align='center'><img src='" . $avatar_url . $image . "' border='0' /><br /><input type='radio' name='avatar' value='" . $image . "' /></td>\n"; $col_ct++; if ($col_ct == $max_cols) { $avstr .= "</tr>"; $col_ct = 0; } } if ($col_ct < $max_cols and count($avatars) >= $max_cols) { for ($i = $col_ct; $i < $max_cols; $i++) { $avstr .= "<td> </td>\n"; } $avstr .= "</tr>"; } if (!preg_match("#\\<\\/tr\\>\$#i", $avstr)) { $avstr .= "</tr>"; } /** ---------------------------------------- /** Finalize the output /** ----------------------------------------*/ $title = $LANG->line('browse_avatars'); $r = $DSP->form_open(array('action' => 'C=myaccount' . AMP . 'M=select_avatar')) . $DSP->input_hidden('id', $id) . $DSP->input_hidden('folder', $IN->GBL('folder')); $r .= $DSP->table('tableBorder', '0', '10', '100%') . $DSP->tr() . $DSP->td('tableHeading'); $r .= $title; $r .= $DSP->td_c() . $DSP->tr_c(); $avstr = $DSP->table('', '0', '10', '100%') . $avstr . $DSP->table_c(); $r .= $DSP->tr(); $r .= $DSP->table_qcell('tableCellOne', $avstr); $r .= $DSP->tr_c(); if ($pagination != '') { $r .= $DSP->tr(); $r .= $DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultCenter', $pagination)); $r .= $DSP->tr_c(); } $r .= $DSP->tr(); $r .= $DSP->td('tableCellTwo'); $r .= $DSP->div('defaultCenter'); $r .= $DSP->qdiv('buttonWrapper', $DSP->input_submit($LANG->line('choose_selected'))); $r .= $DSP->div_c(); $r .= $DSP->td_c(); $r .= $DSP->tr_c(); $r .= $DSP->table_c(); $r .= $DSP->form_close(); return $this->account_wrapper($title, $title, $r); }
/** ---------------------------------------- /** Browse Avatars /** ----------------------------------------*/ function browse_avatars() { global $DB, $LANG, $PREFS, $SESS, $FNS; /** ---------------------------------------- /** Are avatars enabled? /** ----------------------------------------*/ if ($PREFS->ini('enable_avatars') == 'n') { return $this->_trigger_error('edit_avatar', 'avatars_not_enabled'); } /** ---------------------------------------- /** Define the paths /** ----------------------------------------*/ $avatar_path = $PREFS->ini('avatar_path', TRUE).$this->cur_id.'/'; $avatar_url = $PREFS->ini('avatar_url', TRUE).$this->cur_id.'/'; /** ---------------------------------------- /** Is this a valid avatar folder? /** ----------------------------------------*/ $extensions = array('.gif', '.jpg', '.jpeg', '.png'); if ( ! @is_dir($avatar_path) OR ! $fp = @opendir($avatar_path)) { return $this->_trigger_error('edit_avatar', 'avatars_not_found'); } /** ---------------------------------------- /** Grab the image names /** ----------------------------------------*/ $avatars = array(); while (FALSE !== ($file = readdir($fp))) { if (FALSE !== ($pos = strpos($file, '.'))) { if (in_array(substr($file, $pos), $extensions)) { $avatars[] = $file; } } } closedir($fp); /** ---------------------------------------- /** Did we succeed? /** ----------------------------------------*/ if (count($avatars) == 0) { return $this->_trigger_error('edit_avatar', 'avatars_not_found'); } /** ---------------------------------------- /** Pagination anyone? /** ----------------------------------------*/ $pagination = ''; $max_rows = 8; $max_cols = 3; $col_ct = 0; $perpage = $max_rows * $max_cols; $total_rows = count($avatars); $rownum = ($this->uri_extra == '') ? 0 : $this->uri_extra; $base_url = $this->_member_path('browse_avatars/'.$this->cur_id.'/'); if ($rownum > count($avatars)) $rownum = 0; if ($total_rows > $perpage) { $avatars = array_slice($avatars, $rownum, $perpage); if ( ! class_exists('Paginate')) { require PATH_CORE.'core.paginate'.EXT; } $PGR = new Paginate(); $PGR->path = $base_url; $PGR->prefix = ''; $PGR->total_count = $total_rows; $PGR->per_page = $perpage; $PGR->cur_page = $rownum; $pagination = $PGR->show_links(); // We add this for use later if ($rownum != '') { $base_url .= $rownum.'/'; } } /** ---------------------------------------- /** Build the table rows /** ----------------------------------------*/ $avstr = ''; foreach ($avatars as $image) { if ($col_ct == 0) { $avstr .= "<tr>\n"; } $avstr .= "<td align='center'><img src='".$avatar_url.$image."' border='0' alt='".$image."'/><br /><input type='radio' name='avatar' value='".$image."' /></td>\n"; $col_ct++; if ($col_ct == $max_cols) { $avstr .= "</tr>"; $col_ct = 0; } } if ($col_ct < $max_cols AND count($avatars) >= $max_cols) { for ($i = $col_ct; $i < $max_cols; $i++) { $avstr .= "<td> </td>\n"; } $avstr .= "</tr>"; } if ( ! ereg("\<\/tr\>$", $avstr)) { $avstr .= "</tr>"; } /** ---------------------------------------- /** Finalize the output /** ----------------------------------------*/ $template = $this->_load_element('browse_avatars'); if ($pagination == '') { $template = $this->_deny_if('pagination', $template); } else { $template = $this->_allow_if('pagination', $template); } return $this->_var_swap($template, array( 'form_declaration' => $FNS->form_declaration( array( 'action' => $this->_member_path('select_avatar'), 'hidden_fields' => array('referrer' => $base_url, 'folder' => $this->cur_id) ) ), 'avatar_set' => ucwords(str_replace("_", " ", $this->cur_id)), 'avatar_table_rows' => $avstr, 'pagination' => $pagination ) ); }
/** ---------------------------------------- /** Show search results /** ----------------------------------------*/ function search_results() { global $IN, $DB, $TMPL, $LANG, $FNS, $OUT, $LOC, $PREFS, $REGX; /** ---------------------------------------- /** Fetch the search language file /** ----------------------------------------*/ $LANG->fetch_language_file('search'); /** ---------------------------------------- /** Check search ID number /** ----------------------------------------*/ // If the QSTR variable is less than 32 characters long we // don't have a valid search ID number if (strlen($IN->QSTR) < 32) { return $OUT->show_user_error('off', array($LANG->line('search_no_result')), $LANG->line('search_result_heading')); } /** ---------------------------------------- /** Clear old search results /** ----------------------------------------*/ $expire = time() - $this->cache_expire * 3600; $DB->query("DELETE FROM exp_search WHERE site_id = '" . $DB->escape_str($PREFS->ini('site_id')) . "' AND search_date < '{$expire}'"); /** ---------------------------------------- /** Fetch ID number and page number /** ----------------------------------------*/ // We cleverly disguise the page number in the ID hash string $cur_page = 0; if (strlen($IN->QSTR) == 32) { $search_id = $IN->QSTR; } else { $search_id = substr($IN->QSTR, 0, 32); $cur_page = substr($IN->QSTR, 32); } /** ---------------------------------------- /** Fetch the cached search query /** ----------------------------------------*/ $query = $DB->query("SELECT * FROM exp_search WHERE search_id = '" . $DB->escape_str($search_id) . "'"); if ($query->num_rows == 0 or $query->row['total_results'] == 0) { return $OUT->show_user_error('off', array($LANG->line('search_no_result')), $LANG->line('search_result_heading')); } $fields = $query->row['custom_fields'] == '' ? array() : unserialize(stripslashes($query->row['custom_fields'])); $sql = unserialize(stripslashes($query->row['query'])); $sql = str_replace('MDBMPREFIX', 'exp_', $sql); $per_page = $query->row['per_page']; $res_page = $query->row['result_page']; /** ---------------------------------------- /** Run the search query /** ----------------------------------------*/ $query = $DB->query(preg_replace("/SELECT(.*?)\\s+FROM\\s+/is", 'SELECT COUNT(*) AS count FROM ', $sql)); if ($query->row['count'] == 0) { return $OUT->show_user_error('off', array($LANG->line('search_no_result')), $LANG->line('search_result_heading')); } /** ---------------------------------------- /** Calculate total number of pages /** ----------------------------------------*/ $current_page = $cur_page / $per_page + 1; $total_pages = intval($query->row['count'] / $per_page); if ($query->row['count'] % $per_page) { $total_pages++; } $page_count = $LANG->line('page') . ' ' . $current_page . ' ' . $LANG->line('of') . ' ' . $total_pages; /** ----------------------------- /** Do we need pagination? /** -----------------------------*/ // If so, we'll add the LIMIT clause to the SQL statement and run the query again $pager = ''; if ($query->row['count'] > $per_page) { if (!class_exists('Paginate')) { require PATH_CORE . 'core.paginate' . EXT; } $PGR = new Paginate(); $PGR->path = $FNS->create_url($res_page . '/' . $search_id, 0, 0); $PGR->total_count = $query->row['count']; $PGR->per_page = $per_page; $PGR->cur_page = $cur_page; $pager = $PGR->show_links(); $sql .= " LIMIT " . $cur_page . ", " . $per_page; } $query = $DB->query($sql); $output = ''; if (!class_exists('Weblog')) { require PATH_MOD . '/weblog/mod.weblog' . EXT; } unset($TMPL->var_single['auto_path']); unset($TMPL->var_single['excerpt']); unset($TMPL->var_single['id_auto_path']); unset($TMPL->var_single['full_text']); unset($TMPL->var_single['switch']); foreach ($TMPL->var_single as $key => $value) { if (substr($key, 0, strlen('member_path')) == 'member_path') { unset($TMPL->var_single[$key]); } } $weblog = new Weblog(); // This allows the weblog {absolute_count} variable to work $weblog->p_page = $per_page * $current_page - $per_page; $weblog->fetch_custom_weblog_fields(); $weblog->fetch_custom_member_fields(); $weblog->query = $DB->query($sql); if ($weblog->query->num_rows == 0) { return $TMPL->no_results(); } if (!class_exists('Typography')) { require PATH_CORE . 'core.typography' . EXT; } $weblog->TYPE = new Typography(); $weblog->TYPE->convert_curly = FALSE; $weblog->TYPE->encode_email = FALSE; $weblog->fetch_categories(); $weblog->parse_weblog_entries(); $tagdata = $TMPL->tagdata; // Does the tag contain "related entries" that we need to parse out? if (count($TMPL->related_data) > 0 and count($weblog->related_entries) > 0) { $weblog->parse_related_entries(); } if (count($TMPL->reverse_related_data) > 0 and count($weblog->reverse_related_entries) > 0) { $weblog->parse_reverse_related_entries(); } $output = $weblog->return_data; $TMPL->tagdata = $tagdata; /** ----------------------------- /** Fetch member path variable /** -----------------------------*/ // We do it here in case it's used in multiple places. $m_paths = array(); if (preg_match_all("/" . LD . "member_path(\\s*=.*?)" . RD . "/s", $TMPL->tagdata, $matches)) { for ($j = 0; $j < count($matches['0']); $j++) { $m_paths[] = array($matches['0'][$j], $FNS->extract_path($matches['1'][$j])); } } /** ----------------------------- /** Fetch switch param /** -----------------------------*/ $switch1 = ''; $switch2 = ''; if ($switch = $TMPL->fetch_param('switch')) { if (strpos($switch, '|') !== FALSE) { $x = explode("|", $switch); $switch1 = $x['0']; $switch2 = $x['1']; } else { $switch1 = $switch; } } /** ----------------------------- /** Result Loop - Legacy! /** -----------------------------*/ $i = 0; foreach ($query->result as $row) { if (isset($row['field_id_' . $row['search_excerpt']]) and $row['field_id_' . $row['search_excerpt']]) { $format = !isset($row['field_ft_' . $row['search_excerpt']]) ? 'xhtml' : $row['field_ft_' . $row['search_excerpt']]; $full_text = $weblog->TYPE->parse_type(strip_tags($row['field_id_' . $row['search_excerpt']]), array('text_format' => $format, 'html_format' => 'safe', 'auto_links' => 'y', 'allow_img_url' => 'n')); $excerpt = strip_tags($full_text); $excerpt = trim(preg_replace("/(\r\n)|(\r)|(\n)/", " ", $excerpt)); $excerpt = $FNS->word_limiter($excerpt, 50); } else { $excerpt = ''; $full_text = ''; } // Parse permalink path $url = $row['search_results_url'] != '' ? $row['search_results_url'] : $row['blog_url']; $path = $FNS->remove_double_slashes($REGX->prep_query_string($url) . '/' . $row['url_title'] . '/'); $idpath = $FNS->remove_double_slashes($REGX->prep_query_string($url) . '/' . $row['entry_id'] . '/'); $switch = $i++ % 2 ? $switch1 : $switch2; $output = preg_replace("/" . LD . 'switch' . RD . "/", $switch, $output, sizeof(explode(LD . 'switch' . RD, $TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'auto_path' . RD . "/", $path, $output, sizeof(explode(LD . 'auto_path' . RD, $TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'id_auto_path' . RD . "/", $idpath, $output, sizeof(explode(LD . 'id_auto_path' . RD, $TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'excerpt' . RD . "/", preg_quote($excerpt), $output, sizeof(explode(LD . 'excerpt' . RD, $TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'full_text' . RD . "/", preg_quote($full_text), $output, sizeof(explode(LD . 'full_text' . RD, $TMPL->tagdata)) - 1); // Parse member_path if (count($m_paths) > 0) { foreach ($m_paths as $val) { $output = preg_replace("/" . $val['0'] . "/", $FNS->create_url($val['1'] . '/' . $row['member_id']), $output, 1); } } } $TMPL->tagdata = $output; /** ---------------------------------------- /** Parse variables /** ----------------------------------------*/ $swap = array('lang:total_search_results' => $LANG->line('search_total_results'), 'lang:search_engine' => $LANG->line('search_engine'), 'lang:search_results' => $LANG->line('search_results'), 'lang:search' => $LANG->line('search'), 'lang:title' => $LANG->line('search_title'), 'lang:weblog' => $LANG->line('search_weblog'), 'lang:excerpt' => $LANG->line('search_excerpt'), 'lang:author' => $LANG->line('search_author'), 'lang:date' => $LANG->line('search_date'), 'lang:total_comments' => $LANG->line('search_total_comments'), 'lang:recent_comments' => $LANG->line('search_recent_comment_date'), 'lang:keywords' => $LANG->line('search_keywords')); $TMPL->template = $FNS->var_swap($TMPL->template, $swap); /** ---------------------------------------- /** Add Pagination /** ----------------------------------------*/ if ($pager == '') { $TMPL->template = preg_replace("/" . LD . "if paginate" . RD . ".*?" . LD . "/if" . RD . "/s", '', $TMPL->template); } else { $TMPL->template = preg_replace("/" . LD . "if paginate" . RD . "(.*?)" . LD . "/if" . RD . "/s", "\\1", $TMPL->template); } $TMPL->template = str_replace(LD . 'paginate' . RD, $pager, $TMPL->template); $TMPL->template = str_replace(LD . 'page_count' . RD, $page_count, $TMPL->template); return stripslashes($TMPL->tagdata); }
/** ---------------------------------------- /** Create pagination /** ----------------------------------------*/ function create_pagination($count = 0, $query = '') { global $FNS, $TMPL, $IN, $REGX, $EXT, $PREFS, $SESS; // ------------------------------------------- // 'weblog_module_create_pagination' hook. // - Rewrite the pagination function in the Weblog module // - Could be used to expand the kind of pagination available // - Paginate via field length, for example // if ($EXT->active_hook('weblog_module_create_pagination') === TRUE) { $edata = $EXT->universal_call_extension('weblog_module_create_pagination', $this); if ($EXT->end_script === TRUE) { return; } } // // ------------------------------------------- if ($this->paginate == TRUE) { /* -------------------------------------- /* For subdomain's or domains using $template_group and $template /* in path.php, the pagination for the main index page requires /* that the template group and template are specified. /* --------------------------------------*/ if (($IN->URI == '' or $IN->URI == '/') && $PREFS->ini('template_group') != '' && $PREFS->ini('template') != '') { $this->basepath = $FNS->create_url($PREFS->ini('template_group') . '/' . $PREFS->ini('template'), 1); } if ($this->basepath == '') { $this->basepath = $FNS->create_url($IN->URI, 1); if (preg_match("#^P(\\d+)|/P(\\d+)#", $this->QSTR, $match)) { $this->p_page = isset($match['2']) ? $match['2'] : $match['1']; $this->basepath = $FNS->remove_double_slashes(str_replace($match['0'], '', $this->basepath)); } } /** ---------------------------------------- /** Standard pagination - base values /** ----------------------------------------*/ if ($this->field_pagination == FALSE) { if ($this->display_by == '') { if ($count == 0) { $this->sql = ''; return; } $this->total_rows = $count; } if ($this->dynamic_sql == FALSE) { $cat_limit = FALSE; if ((in_array($this->reserved_cat_segment, explode("/", $IN->URI)) and $TMPL->fetch_param('dynamic') != 'off' and $TMPL->fetch_param('weblog')) || (preg_match("#(^|\\/)C(\\d+)#", $IN->URI, $match) and $TMPL->fetch_param('dynamic') != 'off')) { $cat_limit = TRUE; } if ($cat_limit && is_numeric($TMPL->fetch_param('cat_limit'))) { $this->p_limit = $TMPL->fetch_param('cat_limit'); } else { $this->p_limit = !is_numeric($TMPL->fetch_param('limit')) ? $this->limit : $TMPL->fetch_param('limit'); } } $this->p_page = $this->p_page == '' || ($this->p_limit > 1 and $this->p_page == 1) ? 0 : $this->p_page; if ($this->p_page > $this->total_rows) { $this->p_page = 0; } $this->current_page = floor($this->p_page / $this->p_limit + 1); $this->total_pages = intval(floor($this->total_rows / $this->p_limit)); } else { /** ---------------------------------------- /** Field pagination - base values /** ----------------------------------------*/ if ($count == 0) { $this->sql = ''; return; } $m_fields = array(); foreach ($this->multi_fields as $val) { foreach ($this->cfields as $site_id => $cfields) { if (isset($cfields[$val])) { if (isset($query->row['field_id_' . $cfields[$val]]) and $query->row['field_id_' . $cfields[$val]] != '') { $m_fields[] = $val; } } } } $this->p_limit = 1; $this->total_rows = count($m_fields); $this->total_pages = $this->total_rows; if ($this->total_pages == 0) { $this->total_pages = 1; } $this->p_page = $this->p_page == '' ? 0 : $this->p_page; if ($this->p_page > $this->total_rows) { $this->p_page = 0; } $this->current_page = floor($this->p_page / $this->p_limit + 1); if (isset($m_fields[$this->p_page])) { $TMPL->tagdata = preg_replace("/" . LD . "multi_field\\=[\"'].+?[\"']" . RD . "/s", LD . $m_fields[$this->p_page] . RD, $TMPL->tagdata); $TMPL->var_single[$m_fields[$this->p_page]] = $m_fields[$this->p_page]; } } /** ---------------------------------------- /** Create the pagination /** ----------------------------------------*/ if ($this->total_rows % $this->p_limit) { $this->total_pages++; } if ($this->total_rows > $this->p_limit) { if (!class_exists('Paginate')) { require PATH_CORE . 'core.paginate' . EXT; } $PGR = new Paginate(); if (!stristr($this->basepath, SELF) and $PREFS->ini('site_index') != '') { $this->basepath .= SELF . '/'; } if ($TMPL->fetch_param('paginate_base')) { $this->basepath = $FNS->create_url($REGX->trim_slashes($TMPL->fetch_param('paginate_base'))); } $first_url = preg_match("#\\.php/\$#", $this->basepath) ? substr($this->basepath, 0, -1) : $this->basepath; $PGR->first_url = $first_url; $PGR->path = $this->basepath; $PGR->prefix = 'P'; $PGR->total_count = $this->total_rows; $PGR->per_page = $this->p_limit; $PGR->cur_page = $this->p_page; $this->pagination_links = $PGR->show_links(); if ($this->total_pages * $this->p_limit - $this->p_limit > $this->p_page) { $this->page_next = $this->basepath . 'P' . ($this->p_page + $this->p_limit) . '/'; } if ($this->p_page - $this->p_limit >= 0) { $this->page_previous = $this->basepath . 'P' . ($this->p_page - $this->p_limit) . '/'; } } else { $this->p_page = ''; } } }
/** ----------------------------------- /** Bulletin Board /** -----------------------------------*/ function bulletin_board($message = '') { global $LANG, $DB, $OUT, $IN, $LOC, $SESS, $PREFS; $DB->query("UPDATE exp_members SET last_view_bulletins = '" . $LOC->now . "' WHERE member_id = '{$this->member_id}'"); $this->title = $LANG->line('bulletin_board'); $this->crumb = $LANG->line('bulletin_board'); $this->conditionals['bulletins'] = 'n'; $this->conditionals['no_bulletins'] = 'y'; $this->conditionals['paginate'] = 'n'; $this->conditionals['can_post_bulletin'] = $SESS->userdata['can_send_bulletins'] == 'y' ? 'y' : 'n'; $this->single_parts['include']['message'] = $message; $this->conditionals['message'] = $message != '' ? 'y' : 'n'; $this->single_parts['path']['send_bulletin'] = $this->_create_path('send_bulletin'); /** --------------------------------------- /** Retrieve Bulletins /** ---------------------------------------*/ $dql = "SELECT m.screen_name, b.sender_id, b.bulletin_message, b.bulletin_date, b.bulletin_id "; $sql = "FROM exp_member_bulletin_board b, exp_members m\n\t\t\t\t WHERE b.sender_id = m.member_id\n\t\t\t\t AND b.bulletin_group = " . $DB->escape_str($SESS->userdata['group_id']) . "\n\t\t\t\t AND bulletin_date < " . $LOC->now . "\n\t\t\t\t AND \n\t\t\t\t (\n\t\t\t\t \tb.bulletin_expires > " . $LOC->now . "\n\t\t\t\t \tOR\n\t\t\t\t \tb.bulletin_expires = 0\n\t\t\t\t )\n\t\t\t\t ORDER BY b.bulletin_date DESC"; /** ---------------------------------------- /** Run "count" query for pagination /** ----------------------------------------*/ $query = $DB->query("SELECT COUNT(b.bulletin_id) AS count " . $sql); /** ---------------------------------------- /** If No Messages, we say so. /** ----------------------------------------*/ if ($query->row['count'] == 0) { $this->single_parts['include']['bulletins'] = $LANG->line('message_no_bulletins'); $this->return_data = $this->_process_template($this->retrieve_template('bulletin_board')); return; } /** ---------------------------------------- /** Determine Current Page /** ----------------------------------------*/ $row_count = 0; // How many rows shown this far (i.e. offset) if ($this->allegiance == 'user') { $row_count = $this->cur_id; } else { $row_count = $IN->GBL('page', 'GP') === false ? 0 : $IN->GBL('page', 'GP'); } if (!is_numeric($row_count)) { $row_count = 0; } $this->per_page = 5; $current_page = $row_count / $this->per_page + 1; $total_pages = intval($query->row['count'] / $this->per_page); if ($query->row['count'] % $this->per_page) { $total_pages++; } $this->single_parts['include']['page_count'] = $current_page . ' ' . $LANG->line('of') . ' ' . $total_pages; /** ----------------------------- /** Do we need pagination? /** -----------------------------*/ $pager = ''; if ($query->row['count'] > $this->per_page) { if (!class_exists('Paginate')) { require PATH_CORE . 'core.paginate' . EXT; } $PGR = new Paginate(); if ($this->allegiance == 'user') { $PGR->path = $this->base_url . 'bulletin_board/'; } else { $PGR->base_url = $this->base_url . 'bulletin_board'; $PGR->qstr_var = 'page'; } $PGR->total_count = $query->row['count']; $PGR->per_page = $this->per_page; $PGR->cur_page = $row_count; $this->single_parts['include']['pagination_link'] = $PGR->show_links(); $this->conditionals['paginate'] = 'y'; $sql .= " LIMIT " . $row_count . ", " . $this->per_page; } /** ---------------------------------------- /** Create Bulletins /** ----------------------------------------*/ $this->conditionals['bulletins'] = 'y'; $this->conditionals['no_bulletins'] = 'n'; $folder_rows_template = $this->retrieve_template('bulletin'); $i = 0; $r = ''; $censor = FALSE; if ($PREFS->ini('enable_censoring') == 'y' && $PREFS->ini('censored_words') != '') { $censor = TRUE; if (!class_exists('Typography')) { require PATH_CORE . 'core.typography' . EXT; } $TYPE = new Typography(0); } $query = $DB->query($dql . $sql); if ($query->row['bulletin_date'] != $SESS->userdata['last_bulletin_date']) { $DB->query($DB->update_string('exp_members', array('last_bulletin_date' => $query->row['bulletin_date']), "group_id = '" . $DB->escape_str($SESS->userdata['group_id']) . "'")); } foreach ($query->result as $row) { ++$i; $data = $row; $this->conditionals['can_delete_bulletin'] = ($SESS->userdata['group_id'] == 1 or $row['sender_id'] == $SESS->userdata['member_id']) ? 'y' : 'n'; if ($this->allegiance == 'cp') { $this->single_parts['path']['delete_bulletin'] = $this->_create_path('delete_bulletin', AMP . 'bulletin_id=' . $row['bulletin_id']); } else { $this->single_parts['path']['delete_bulletin'] = $this->_create_path('delete_bulletin') . $row['bulletin_id'] . '/'; } $data['bulletin_message'] = $censor === FALSE ? $data['bulletin_message'] : $TYPE->filter_censored_words($data['bulletin_message']); $data['bulletin_sender'] = $row['screen_name']; $data['bulletin_date'] = $LOC->set_human_time($row['bulletin_date']); $data['style'] = $i % 2 ? 'tableCellTwo' : 'tableCellOne'; $r .= $this->_process_template($folder_rows_template, $data); } $this->single_parts['include']['bulletins'] = $r; /** ---------------------------------------- /** Return the Folder's Contents /** ----------------------------------------*/ $this->return_data = $this->_process_template($this->retrieve_template('bulletin_board')); }
/** ---------------------------------------- /** Comment Entries /** ----------------------------------------*/ function entries() { global $IN, $DB, $TMPL, $LOC, $PREFS, $REGX, $FNS, $SESS, $EXT; // Base variables $return = ''; $current_page = ''; $qstring = $IN->QSTR; $uristr = $IN->URI; $switch = array(); $search_link = ''; // Pagination variables $paginate = FALSE; $paginate_data = ''; $pagination_links = ''; $page_next = ''; $page_previous = ''; $current_page = 0; $t_current_page = ''; $total_pages = 1; if ($TMPL->fetch_param('dynamic') == 'off') { $dynamic = FALSE; } else { $dynamic = TRUE; } $force_entry = FALSE; if ($TMPL->fetch_param('entry_id') !== FALSE or $TMPL->fetch_param('url_title') !== FALSE) { $force_entry = TRUE; } /** ---------------------------------------------- /** Do we allow dynamic POST variables to set parameters? /** ----------------------------------------------*/ if ($TMPL->fetch_param('dynamic_parameters') !== FALSE and isset($_POST) and count($_POST) > 0) { foreach (explode('|', $TMPL->fetch_param('dynamic_parameters')) as $var) { if (isset($_POST[$var]) and in_array($var, array('weblog', 'limit', 'sort', 'orderby'))) { $TMPL->tagparams[$var] = $_POST[$var]; } } } /** -------------------------------------- /** Parse page number /** --------------------------------------*/ // We need to strip the page number from the URL for two reasons: // 1. So we can create pagination links // 2. So it won't confuse the query with an improper proper ID if (!$dynamic) { if (preg_match("#N(\\d+)#", $qstring, $match) or preg_match("#/N(\\d+)#", $qstring, $match)) { $current_page = $match['1']; $uristr = $FNS->remove_double_slashes(str_replace($match['0'], '', $uristr)); } } else { if (preg_match("#/P(\\d+)#", $qstring, $match)) { $current_page = $match['1']; $uristr = $FNS->remove_double_slashes(str_replace($match['0'], '', $uristr)); $qstring = $FNS->remove_double_slashes(str_replace($match['0'], '', $qstring)); } } if ($dynamic == TRUE or $force_entry == TRUE) { // see if entry_id or url_title parameter is set if ($entry_id = $TMPL->fetch_param('entry_id')) { $entry_sql = " entry_id = '" . $DB->escape_str($entry_id) . "' "; } elseif ($url_title = $TMPL->fetch_param('url_title')) { $entry_sql = " url_title = '" . $DB->escape_str($url_title) . "' "; } else { // If there is a slash in the entry ID we'll kill everything after it. $entry_id = trim($qstring); $entry_id = preg_replace("#/.+#", "", $entry_id); $entry_sql = !is_numeric($entry_id) ? " url_title = '" . $DB->escape_str($entry_id) . "' " : " entry_id = '" . $DB->escape_str($entry_id) . "' "; } /** ---------------------------------------- /** Do we have a vaild entry ID number? /** ----------------------------------------*/ $timestamp = $TMPL->cache_timestamp != '' ? $LOC->set_gmt($TMPL->cache_timestamp) : $LOC->now; $sql = "SELECT entry_id, exp_weblog_titles.weblog_id \n\t\t\t\t\tFROM exp_weblog_titles, exp_weblogs \n\t\t\t\t\tWHERE exp_weblog_titles.weblog_id = exp_weblogs.weblog_id\n\t\t\t\t\tAND exp_weblog_titles.site_id IN ('" . implode("','", $TMPL->site_ids) . "') "; if ($TMPL->fetch_param('show_expired') !== 'yes') { $sql .= "AND (expiration_date = 0 || expiration_date > " . $timestamp . ") "; } $sql .= "AND status != 'closed' AND "; $sql .= $entry_sql; /** ---------------------------------------------- /** Limit to/exclude specific weblogs /** ----------------------------------------------*/ if (USER_BLOG !== FALSE) { // If it's a "user blog" we limit to only their assigned blog $sql .= " AND exp_weblogs.weblog_id = '" . $DB->escape_str(UB_BLOG_ID) . "' "; } else { $sql .= "AND exp_weblogs.is_user_blog = 'n' "; if ($weblog = $TMPL->fetch_param('weblog') or $TMPL->fetch_param('site')) { $xql = "SELECT weblog_id FROM exp_weblogs WHERE site_id IN ('" . implode("','", $TMPL->site_ids) . "') "; if ($weblog !== FALSE) { $xql .= $FNS->sql_andor_string($weblog, 'blog_name'); } $query = $DB->query($xql); if ($query->num_rows == 1) { $sql .= "AND exp_weblog_titles.weblog_id = '" . $query->row['weblog_id'] . "' "; } elseif ($query->num_rows > 1) { $sql .= "AND ("; foreach ($query->result as $row) { $sql .= "exp_weblog_titles.weblog_id = '" . $row['weblog_id'] . "' OR "; } $sql = substr($sql, 0, -3); $sql .= ") "; } } } $query = $DB->query($sql); // Bad ID? See ya! if ($query->num_rows == 0) { return false; } unset($sql); // We'll reassign the entry ID so it's the true numeric ID $entry_id = $query->row['entry_id']; } // If the comment tag is being used in freeform mode // we need to fetch the weblog ID numbers $w_sql = ''; if (!$dynamic) { if (USER_BLOG !== FALSE) { // If it's a "user blog" we limit to only their assigned blog $w_sql .= "AND weblog_id = '" . UB_BLOG_ID . "' "; } else { if ($weblog = $TMPL->fetch_param('weblog') or $TMPL->fetch_param('site')) { $xql = "SELECT weblog_id FROM exp_weblogs WHERE site_id IN ('" . implode("','", $TMPL->site_ids) . "') "; if ($weblog !== FALSE) { $xql .= $FNS->sql_andor_string($weblog, 'blog_name'); } $query = $DB->query($xql); if ($query->num_rows == 0) { return $TMPL->no_results(); } else { if ($query->num_rows == 1) { $w_sql .= "AND weblog_id = '" . $query->row['weblog_id'] . "' "; } else { $w_sql .= "AND ("; foreach ($query->result as $row) { $w_sql .= "weblog_id = '" . $row['weblog_id'] . "' OR "; } $w_sql = substr($w_sql, 0, -3); $w_sql .= ") "; } } } } } /** ---------------------------------------- /** Set trackback flag /** ----------------------------------------*/ // Depending on whether the {if trackbacks} conditional // is present will determine whether we need to show trackbacks $show_trackbacks = preg_match("/" . LD . "if\\s+trackbacks" . RD . ".+?" . LD . SLASH . "if" . RD . "/s", $TMPL->tagdata) ? TRUE : FALSE; /** ---------------------------------------- /** Set sorting and limiting /** ----------------------------------------*/ if (!$dynamic) { $limit = !$TMPL->fetch_param('limit') ? 100 : $TMPL->fetch_param('limit'); $sort = !$TMPL->fetch_param('sort') ? 'desc' : $TMPL->fetch_param('sort'); } else { $limit = !$TMPL->fetch_param('limit') ? $this->limit : $TMPL->fetch_param('limit'); $sort = !$TMPL->fetch_param('sort') ? 'asc' : $TMPL->fetch_param('sort'); } $allowed_sorts = array('date', 'email', 'location', 'name', 'url'); /** ---------------------------------------- /** Fetch comment ID numbers /** ----------------------------------------*/ $temp = array(); $i = 0; $comments_exist = FALSE; // Left this here for backward compatibility // We need to deprecate the "order_by" parameter if ($TMPL->fetch_param('orderby') != '') { $order_by = $TMPL->fetch_param('orderby'); } else { $order_by = $TMPL->fetch_param('order_by'); } $order_by = ($order_by == 'date' or !in_array($order_by, $allowed_sorts)) ? 'comment_date' : $order_by; if (!$dynamic) { // When we are only showing comments and it is not based on an entry id or url title // in the URL, we can make the query much more efficient and save some work. $e_sql = isset($entry_id) && $entry_id != '' ? "AND entry_id = '" . $DB->escape_str($entry_id) . "' " : ''; if ($show_trackbacks === FALSE) { $this_page = $current_page == '' || ($limit > 1 and $current_page == 1) ? 0 : $current_page; $this_sort = strtolower($sort) == 'desc' ? 'DESC' : 'ASC'; $sql = "SELECT comment_date, comment_id FROM exp_comments \n\t\t\t\t\t\tWHERE status = 'o' " . $e_sql . $w_sql . " \n\t\t\t\t\t\tORDER BY " . $order_by . " " . $this_sort . "\n\t\t\t\t\t\tLIMIT {$this_page}, " . $limit; $query = $DB->query($sql); $count_query = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE status = 'o' " . $e_sql . $w_sql); $total_rows = $count_query->row['count']; } else { $sql = "SELECT comment_date, comment_id FROM exp_comments WHERE status = 'o' " . $e_sql . $w_sql . " ORDER BY " . $order_by; } $query = $DB->query($sql); } else { $query = $DB->query("SELECT comment_date, comment_id FROM exp_comments WHERE entry_id = '" . $DB->escape_str($entry_id) . "' AND status = 'o' ORDER BY " . $order_by); } if ($query->num_rows > 0) { $comments_exist = TRUE; foreach ($query->result as $row) { $key = $row['comment_date']; while (isset($temp[$key])) { $key++; } $temp[$key] = 'c' . $row['comment_id']; } } /** ---------------------------------------- /** Fetch trackback ID numbers /** ----------------------------------------*/ $trackbacks_exist = FALSE; if ($show_trackbacks) { if (!$dynamic) { $t_sql = ''; if ($w_sql != '') { $t_sql = trim($w_sql); $t_sql = "WHERE " . substr($t_sql, 3); } $sql = "SELECT trackback_date, trackback_id FROM exp_trackbacks " . $t_sql . " ORDER BY trackback_date"; $query = $DB->query($sql); } else { $query = $DB->query("SELECT trackback_date, trackback_id FROM exp_trackbacks WHERE entry_id = '" . $DB->escape_str($entry_id) . "' ORDER BY trackback_date"); } if ($query->num_rows > 0) { $trackbacks_exist = TRUE; foreach ($query->result as $row) { $key = $row['trackback_date']; while (isset($temp[$key])) { $key++; } $temp[$key] = 't' . $row['trackback_id']; } } } /** ------------------------------------ /** No results? No reason to continue... /** ------------------------------------*/ if (count($temp) == 0) { return $TMPL->no_results(); } // Sort the array based on the keys (which contain the Unix timesamps // of the comments and trackbacks) if ($order_by == 'comment_date') { ksort($temp); } // Create a new, sequentially indexed array $result_ids = array(); foreach ($temp as $val) { $result_ids[$val] = $val; } // Reverse the array if order is descending if ($sort == 'desc') { $result_ids = array_reverse($result_ids); } /** --------------------------------- /** Do we need pagination? /** ---------------------------------*/ // When showing only comments and no using the URL, then we already have this value if ($dynamic or $show_trackbacks === TRUE) { $total_rows = count($result_ids); } if (preg_match("/" . LD . "paginate(.*?)" . RD . "(.+?)" . LD . SLASH . "paginate" . RD . "/s", $TMPL->tagdata, $match)) { $paginate = TRUE; $paginate_data = $match['2']; $anchor = ''; if ($match['1'] != '') { if (preg_match("/anchor.*?=[\"|\\'](.+?)[\"|\\']/", $match['1'], $amatch)) { $anchor = '#' . $amatch['1']; } } $TMPL->tagdata = preg_replace("/" . LD . "paginate.*?" . RD . ".+?" . LD . SLASH . "paginate" . RD . "/s", "", $TMPL->tagdata); $current_page = $current_page == '' || ($limit > 1 and $current_page == 1) ? 0 : $current_page; if ($current_page > $total_rows) { $current_page = 0; } $t_current_page = floor($current_page / $limit + 1); $total_pages = intval(floor($total_rows / $limit)); if ($total_rows % $limit) { $total_pages++; } if ($total_rows > $limit) { if (!class_exists('Paginate')) { require PATH_CORE . 'core.paginate' . EXT; } $PGR = new Paginate(); $deft_tmpl = ''; if ($uristr == '') { if (USER_BLOG !== FALSE) { $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '" . $DB->escape_str(UB_TMP_GRP) . "'"); $deft_tmpl = $query->row['group_name'] . '/index/'; } else { if ($PREFS->ini('template_group') == '') { $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE is_site_default = 'y' AND is_user_blog = 'n'"); $deft_tmpl = $query->row['group_name'] . '/index/'; } else { $deft_tmpl = $PREFS->ini('template_group') . '/'; $deft_tmpl .= $PREFS->ini('template') == '' ? 'index' : $PREFS->ini('template'); $deft_tmpl .= '/'; } } } $basepath = $FNS->remove_double_slashes($FNS->create_url($uristr, 1, 0) . '/' . $deft_tmpl); $first_url = substr($basepath, -5) == '.php/' ? substr($basepath, 0, -1) : $basepath; if ($TMPL->fetch_param('paginate_base')) { $pbase = $REGX->trim_slashes($TMPL->fetch_param('paginate_base')); $pbase = str_replace("/index", "/", $pbase); if (!strstr($basepath, $pbase)) { $basepath = $FNS->remove_double_slashes($basepath . '/' . $pbase . '/'); } } $PGR->first_url = $first_url; $PGR->path = $basepath; $PGR->prefix = !$dynamic ? 'N' : 'P'; $PGR->total_count = $total_rows; $PGR->per_page = $limit; $PGR->cur_page = $current_page; $PGR->suffix = $anchor; $pagination_links = $PGR->show_links(); if ($total_pages * $limit - $limit > $current_page) { $page_next = $basepath . 'P' . ($current_page + $limit) . '/'; } if ($current_page - $limit >= 0) { $page_previous = $basepath . 'P' . ($current_page - $limit) . '/'; } } else { $current_page = ''; } } // When only non-dynamic comments are show, all results are valid as the // query is restricted with a LIMIT clause if ($dynamic or $show_trackbacks === TRUE) { if ($current_page == '') { $result_ids = array_slice($result_ids, 0, $limit); } else { $result_ids = array_slice($result_ids, $current_page, $limit); } } /** ----------------------------------- /** Fetch Comments if necessary /** -----------------------------------*/ $results = $result_ids; $mfields = array(); if ($comments_exist == TRUE) { $com = ''; foreach ($result_ids as $val) { if (substr($val, 0, 1) == 'c') { $com .= substr($val, 1) . ","; } } if ($com != '') { /** ---------------------------------------- /** "Search by Member" link /** ----------------------------------------*/ // We use this with the {member_search_path} variable $result_path = preg_match("/" . LD . "member_search_path\\s*=(.*?)" . RD . "/s", $TMPL->tagdata, $match) ? $match['1'] : 'search/results'; $result_path = str_replace("\"", "", $result_path); $result_path = str_replace("'", "", $result_path); $qs = $PREFS->ini('force_query_string') == 'y' ? '' : '?'; $search_link = $FNS->fetch_site_index(0, 0) . $qs . 'ACT=' . $FNS->fetch_action_id('Search', 'do_search') . '&result_path=' . $result_path . '&mbr='; $sql = "SELECT \n\t\t\t\t\t\texp_comments.comment_id, exp_comments.entry_id, exp_comments.weblog_id, exp_comments.author_id, exp_comments.name, exp_comments.email, exp_comments.url, exp_comments.location as c_location, exp_comments.ip_address, exp_comments.comment_date, exp_comments.edit_date, exp_comments.comment, exp_comments.notify, exp_comments.site_id AS comment_site_id,\n\t\t\t\t\t\texp_members.location, exp_members.occupation, exp_members.interests, exp_members.aol_im, exp_members.yahoo_im, exp_members.msn_im, exp_members.icq, exp_members.group_id, exp_members.member_id, exp_members.signature, exp_members.sig_img_filename, exp_members.sig_img_width, exp_members.sig_img_height, exp_members.avatar_filename, exp_members.avatar_width, exp_members.avatar_height, exp_members.photo_filename, exp_members.photo_width, exp_members.photo_height, \n\t\t\t\t\t\texp_member_data.*,\n\t\t\t\t\t\texp_weblog_titles.title, exp_weblog_titles.url_title, exp_weblog_titles.author_id AS entry_author_id,\n\t\t\t\t\t\texp_weblogs.comment_text_formatting, exp_weblogs.comment_html_formatting, exp_weblogs.comment_allow_img_urls, exp_weblogs.comment_auto_link_urls, exp_weblogs.blog_url, exp_weblogs.comment_url, exp_weblogs.blog_title \n\t\t\t\t\t\tFROM exp_comments \n\t\t\t\t\t\tLEFT JOIN exp_weblogs ON exp_comments.weblog_id = exp_weblogs.weblog_id \n\t\t\t\t\t\tLEFT JOIN exp_weblog_titles ON exp_comments.entry_id = exp_weblog_titles.entry_id \n\t\t\t\t\t\tLEFT JOIN exp_members ON exp_members.member_id = exp_comments.author_id \n\t\t\t\t\t\tLEFT JOIN exp_member_data ON exp_member_data.member_id = exp_members.member_id\n\t\t\t\t\t\tWHERE exp_comments.comment_id IN (" . substr($com, 0, -1) . ")"; $query = $DB->query($sql); if ($query->num_rows > 0) { $i = 0; foreach ($query->result as $row) { if (isset($results['c' . $row['comment_id']])) { $results['c' . $row['comment_id']] = $query->result[$i]; $i++; } } } /** ---------------------------------------- /** Fetch custom member field IDs /** ----------------------------------------*/ $query = $DB->query("SELECT m_field_id, m_field_name FROM exp_member_fields"); if ($query->num_rows > 0) { foreach ($query->result as $row) { $mfields[$row['m_field_name']] = $row['m_field_id']; } } } } /** ----------------------------------- /** Fetch Trackbacks if necessary /** -----------------------------------*/ if ($trackbacks_exist == TRUE) { $trb = ''; foreach ($result_ids as $val) { if (substr($val, 0, 1) == 't') { $trb .= substr($val, 1) . ","; } } if ($trb != '') { $sql = "SELECT \n\t\t\t\t\t\texp_trackbacks.trackback_id, exp_trackbacks.title, exp_trackbacks.content, exp_trackbacks.weblog_name, exp_trackbacks.trackback_url, exp_trackbacks.trackback_date, exp_trackbacks.trackback_ip,\n\t\t\t\t\t\texp_weblog_titles.weblog_id, exp_weblog_titles.allow_trackbacks, exp_weblog_titles.url_title\n\t\t\t\t\t\tFROM exp_trackbacks \n\t\t\t\t\t\tLEFT JOIN exp_weblog_titles ON (exp_weblog_titles.entry_id = exp_trackbacks.entry_id)\n\t\t\t\t\t\tWHERE exp_trackbacks.trackback_id IN (" . substr($trb, 0, -1) . ")"; $query = $DB->query($sql); if ($query->num_rows > 0) { $i = 0; foreach ($query->result as $row) { if (isset($results['t' . $row['trackback_id']])) { $results['t' . $row['trackback_id']] = $query->result[$i]; $i++; } } } } } /** ---------------------------------------- /** Instantiate Typography class /** ----------------------------------------*/ if (!class_exists('Typography')) { require PATH_CORE . 'core.typography' . EXT; } $TYPE = new Typography(FALSE, FALSE); /** ---------------------------------------- /** Fetch all the date-related variables /** ----------------------------------------*/ $gmt_comment_date = array(); $comment_date = array(); $trackback_date = array(); $edit_date = array(); // We do this here to avoid processing cycles in the foreach loop $date_vars = array('gmt_comment_date', 'comment_date', 'trackback_date', 'edit_date'); foreach ($date_vars as $val) { if (preg_match_all("/" . LD . $val . "\\s+format=[\"'](.*?)[\"']" . RD . "/s", $TMPL->tagdata, $matches)) { for ($j = 0; $j < count($matches['0']); $j++) { $matches['0'][$j] = str_replace(LD, '', $matches['0'][$j]); $matches['0'][$j] = str_replace(RD, '', $matches['0'][$j]); switch ($val) { case 'comment_date': $comment_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); break; case 'gmt_comment_date': $gmt_comment_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); break; case 'trackback_date': $trackback_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); break; case 'edit_date': $edit_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); break; } } } } /** ---------------------------------------- /** Protected Variables for Cleanup Routine /** ----------------------------------------*/ // Since comments do not necessarily require registration, and since // you are allowed to put member variables in comments, we need to kill // left-over unparsed junk. The $member_vars array is all of those // member related variables that should be removed. $member_vars = array('location', 'occupation', 'interests', 'aol_im', 'yahoo_im', 'msn_im', 'icq', 'signature', 'sig_img_filename', 'sig_img_width', 'sig_img_height', 'avatar_filename', 'avatar_width', 'avatar_height', 'photo_filename', 'photo_width', 'photo_height'); $member_cond_vars = array(); foreach ($member_vars as $var) { $member_cond_vars[$var] = ''; } /** ---------------------------------------- /** Start the processing loop /** ----------------------------------------*/ $item_count = 0; $relative_count = 0; $absolute_count = $current_page == '' ? 0 : $current_page; $total_results = sizeof($results); foreach ($results as $id => $row) { if (!is_array($row)) { continue; } $relative_count++; $absolute_count++; $row['count'] = $relative_count; $row['absolute_count'] = $absolute_count; $row['total_comments'] = $total_rows; $row['total_results'] = $total_results; // This lets the {if location} variable work if ($comments_exist == TRUE and isset($row['author_id'])) { if ($row['author_id'] == 0) { $row['location'] = $row['c_location']; } } $tagdata = $TMPL->tagdata; // ------------------------------------------- // 'comment_entries_tagdata' hook. // - Modify and play with the tagdata before everyone else // if ($EXT->active_hook('comment_entries_tagdata') === TRUE) { $tagdata = $EXT->call_extension('comment_entries_tagdata', $tagdata, $row); if ($EXT->end_script === TRUE) { return $tagdata; } } // // ------------------------------------------- /** ---------------------------------------- /** Conditionals /** ----------------------------------------*/ $cond = array_merge($member_cond_vars, $row); $cond['comments'] = substr($id, 0, 1) == 't' ? 'FALSE' : 'TRUE'; $cond['trackbacks'] = substr($id, 0, 1) == 'c' ? 'FALSE' : 'TRUE'; $cond['logged_in'] = $SESS->userdata('member_id') == 0 ? 'FALSE' : 'TRUE'; $cond['logged_out'] = $SESS->userdata('member_id') != 0 ? 'FALSE' : 'TRUE'; $cond['allow_comments'] = (isset($row['allow_comments']) and $row['allow_comments'] == 'n') ? 'FALSE' : 'TRUE'; $cond['allow_trackbacks'] = (isset($row['allow_trackbacks']) and $row['allow_trackbacks'] == 'n') ? 'FALSE' : 'TRUE'; $cond['signature_image'] = (!isset($row['sig_img_filename']) or $row['sig_img_filename'] == '' or $PREFS->ini('enable_signatures') == 'n' or $SESS->userdata('display_signatures') == 'n') ? 'FALSE' : 'TRUE'; $cond['avatar'] = (!isset($row['avatar_filename']) or $row['avatar_filename'] == '' or $PREFS->ini('enable_avatars') == 'n' or $SESS->userdata('display_avatars') == 'n') ? 'FALSE' : 'TRUE'; $cond['photo'] = (!isset($row['photo_filename']) or $row['photo_filename'] == '' or $PREFS->ini('enable_photos') == 'n' or $SESS->userdata('display_photos') == 'n') ? 'FALSE' : 'TRUE'; $cond['is_ignored'] = (!isset($row['member_id']) or !in_array($row['member_id'], $SESS->userdata['ignore_list'])) ? 'FALSE' : 'TRUE'; if (isset($mfields) && is_array($mfields) && sizeof($mfields) > 0) { foreach ($mfields as $key => $value) { if (isset($row['m_field_id_' . $value])) { $cond[$key] = $row['m_field_id_' . $value]; } } } $tagdata = $FNS->prep_conditionals($tagdata, $cond); /** ---------------------------------------- /** Parse "single" variables /** ----------------------------------------*/ foreach ($TMPL->var_single as $key => $val) { /** ---------------------------------------- /** parse {switch} variable /** ----------------------------------------*/ if (strncmp($key, 'switch', 6) == 0) { $sparam = $FNS->assign_parameters($key); $sw = ''; if (isset($sparam['switch'])) { $sopt = @explode("|", $sparam['switch']); $sw = $sopt[($relative_count + count($sopt) - 1) % count($sopt)]; /* Old style switch parsing /* if (count($sopt) == 2) { if (isset($switch[$sparam['switch']]) AND $switch[$sparam['switch']] == $sopt['0']) { $switch[$sparam['switch']] = $sopt['1']; $sw = $sopt['1']; } else { $switch[$sparam['switch']] = $sopt['0']; $sw = $sopt['0']; } } */ } $tagdata = $TMPL->swap_var_single($key, $sw, $tagdata); } /** ---------------------------------------- /** parse permalink /** ----------------------------------------*/ if (strncmp('permalink', $key, 9) == 0 && isset($row['comment_id'])) { $tagdata = $TMPL->swap_var_single($key, $FNS->create_url($uristr . '#' . $row['comment_id'], 0, 0), $tagdata); } /** ---------------------------------------- /** parse comment_path or trackback_path /** ----------------------------------------*/ if (preg_match("#^(comment_path|trackback_path|entry_id_path)#", $key)) { $tagdata = $TMPL->swap_var_single($key, $FNS->create_url($FNS->extract_path($key) . '/' . $row['entry_id']), $tagdata); } /** ---------------------------------------- /** parse title permalink /** ----------------------------------------*/ if (preg_match("#^(title_permalink|url_title_path)#", $key)) { $path = ($FNS->extract_path($key) != '' and $FNS->extract_path($key) != 'SITE_INDEX') ? $FNS->extract_path($key) . '/' . $row['url_title'] : $row['url_title']; $tagdata = $TMPL->swap_var_single($key, $FNS->create_url($path, 1, 0), $tagdata); } /** ---------------------------------------- /** parse comment date /** ----------------------------------------*/ if (isset($comment_date[$key]) and $comments_exist == TRUE and isset($row['comment_date'])) { foreach ($comment_date[$key] as $dvar) { $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $row['comment_date'], TRUE), $val); } $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); } /** ---------------------------------------- /** parse GMT comment date /** ----------------------------------------*/ if (isset($gmt_comment_date[$key]) and $comments_exist == TRUE and isset($row['comment_date'])) { foreach ($gmt_comment_date[$key] as $dvar) { $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $row['comment_date'], FALSE), $val); } $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); } /** ---------------------------------------- /** parse trackback date /** ----------------------------------------*/ if (isset($trackback_date[$key]) and $trackbacks_exist == TRUE and isset($row['trackback_date'])) { foreach ($trackback_date[$key] as $dvar) { $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $row['trackback_date'], TRUE), $val); } $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); } /** ---------------------------------------- /** parse "last edit" date /** ----------------------------------------*/ if (isset($edit_date[$key])) { if (isset($row['edit_date'])) { foreach ($edit_date[$key] as $dvar) { $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $LOC->timestamp_to_gmt($row['edit_date']), TRUE), $val); } $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); } } /** ---------------------------------------- /** {member_search_path} /** ----------------------------------------*/ if (strncmp('member_search_path', $key, 18) == 0) { $tagdata = $TMPL->swap_var_single($key, $search_link . $row['author_id'], $tagdata); } // Prep the URL if (isset($row['url'])) { $row['url'] = $REGX->prep_url($row['url']); } /** ---------------------------------------- /** {author} /** ----------------------------------------*/ if ($key == "author") { $tagdata = $TMPL->swap_var_single($val, isset($row['name']) ? $row['name'] : '', $tagdata); } /** ---------------------------------------- /** {url_or_email} - Uses Raw Email Address, Like Weblog Module /** ----------------------------------------*/ if ($key == "url_or_email" and isset($row['url'])) { $tagdata = $TMPL->swap_var_single($val, $row['url'] != '' ? $row['url'] : $row['email'], $tagdata); } /** ---------------------------------------- /** {url_as_author} /** ----------------------------------------*/ if ($key == "url_as_author" and isset($row['url'])) { if ($row['url'] != '') { $tagdata = $TMPL->swap_var_single($val, "<a href=\"" . $row['url'] . "\">" . $row['name'] . "</a>", $tagdata); } else { $tagdata = $TMPL->swap_var_single($val, $row['name'], $tagdata); } } /** ---------------------------------------- /** {url_or_email_as_author} /** ----------------------------------------*/ if ($key == "url_or_email_as_author" and isset($row['url'])) { if ($row['url'] != '') { $tagdata = $TMPL->swap_var_single($val, "<a href=\"" . $row['url'] . "\">" . $row['name'] . "</a>", $tagdata); } else { if ($row['email'] != '') { $tagdata = $TMPL->swap_var_single($val, $TYPE->encode_email($row['email'], $row['name']), $tagdata); } else { $tagdata = $TMPL->swap_var_single($val, $row['name'], $tagdata); } } } /** ---------------------------------------- /** {url_or_email_as_link} /** ----------------------------------------*/ if ($key == "url_or_email_as_link" and isset($row['url'])) { if ($row['url'] != '') { $tagdata = $TMPL->swap_var_single($val, "<a href=\"" . $row['url'] . "\">" . $row['url'] . "</a>", $tagdata); } else { if ($row['email'] != '') { $tagdata = $TMPL->swap_var_single($val, $TYPE->encode_email($row['email']), $tagdata); } else { $tagdata = $TMPL->swap_var_single($val, $row['name'], $tagdata); } } } if (substr($id, 0, 1) == 'c') { /** ---------------------------------------- /** {comment_auto_path} /** ----------------------------------------*/ if ($key == "comment_auto_path") { $path = $row['comment_url'] == '' ? $row['blog_url'] : $row['comment_url']; $tagdata = $TMPL->swap_var_single($key, $path, $tagdata); } /** ---------------------------------------- /** {comment_url_title_auto_path} /** ----------------------------------------*/ if ($key == "comment_url_title_auto_path" and $comments_exist == TRUE) { $path = $row['comment_url'] == '' ? $row['blog_url'] : $row['comment_url']; $tagdata = $TMPL->swap_var_single($key, $path . $row['url_title'] . '/', $tagdata); } /** ---------------------------------------- /** {comment_entry_id_auto_path} /** ----------------------------------------*/ if ($key == "comment_entry_id_auto_path" and $comments_exist == TRUE) { $path = $row['comment_url'] == '' ? $row['blog_url'] : $row['comment_url']; $tagdata = $TMPL->swap_var_single($key, $path . $row['entry_id'] . '/', $tagdata); } /** ---------------------------------------- /** parse comment field /** ----------------------------------------*/ if ($key == 'comment' and isset($row['comment'])) { // ------------------------------------------- // 'comment_entries_comment_format' hook. // - Play with the tagdata contents of the comment entries // if ($EXT->active_hook('comment_entries_comment_format') === TRUE) { $comment = $EXT->call_extension('comment_entries_comment_format', $row); if ($EXT->end_script === TRUE) { return; } } else { $comment = $TYPE->parse_type($row['comment'], array('text_format' => $row['comment_text_formatting'], 'html_format' => $row['comment_html_formatting'], 'auto_links' => $row['comment_auto_link_urls'], 'allow_img_url' => $row['comment_allow_img_urls'])); } // // ------------------------------------------- $tagdata = $TMPL->swap_var_single($key, $comment, $tagdata); } } /** ---------------------------------------- /** {location} /** ----------------------------------------*/ if ($key == 'location' and isset($row['location']) || isset($row['c_location'])) { $tagdata = $TMPL->swap_var_single($key, empty($row['location']) ? $row['c_location'] : $row['location'], $tagdata); } /** ---------------------------------------- /** {signature} /** ----------------------------------------*/ if ($key == "signature") { if ($SESS->userdata('display_signatures') == 'n' or !isset($row['signature']) or $row['signature'] == '' or $SESS->userdata('display_signatures') == 'n') { $tagdata = $TMPL->swap_var_single($key, '', $tagdata); } else { $tagdata = $TMPL->swap_var_single($key, $TYPE->parse_type($row['signature'], array('text_format' => 'xhtml', 'html_format' => 'safe', 'auto_links' => 'y', 'allow_img_url' => $PREFS->ini('sig_allow_img_hotlink'))), $tagdata); } } if ($key == "signature_image_url") { if ($SESS->userdata('display_signatures') == 'n' or $row['sig_img_filename'] == '' or $SESS->userdata('display_signatures') == 'n') { $tagdata = $TMPL->swap_var_single($key, '', $tagdata); $tagdata = $TMPL->swap_var_single('signature_image_width', '', $tagdata); $tagdata = $TMPL->swap_var_single('signature_image_height', '', $tagdata); } else { $tagdata = $TMPL->swap_var_single($key, $PREFS->ini('sig_img_url', TRUE) . $row['sig_img_filename'], $tagdata); $tagdata = $TMPL->swap_var_single('signature_image_width', $row['sig_img_width'], $tagdata); $tagdata = $TMPL->swap_var_single('signature_image_height', $row['sig_img_height'], $tagdata); } } if ($key == "avatar_url") { if (!isset($row['avatar_filename'])) { $row['avatar_filename'] = ''; } if ($SESS->userdata('display_avatars') == 'n' or $row['avatar_filename'] == '' or $SESS->userdata('display_avatars') == 'n') { $tagdata = $TMPL->swap_var_single($key, '', $tagdata); $tagdata = $TMPL->swap_var_single('avatar_image_width', '', $tagdata); $tagdata = $TMPL->swap_var_single('avatar_image_height', '', $tagdata); } else { $tagdata = $TMPL->swap_var_single($key, $PREFS->ini('avatar_url', 1) . $row['avatar_filename'], $tagdata); $tagdata = $TMPL->swap_var_single('avatar_image_width', $row['avatar_width'], $tagdata); $tagdata = $TMPL->swap_var_single('avatar_image_height', $row['avatar_height'], $tagdata); } } if ($key == "photo_url") { if (!isset($row['photo_filename'])) { $row['photo_filename'] = ''; } if ($SESS->userdata('display_photos') == 'n' or $row['photo_filename'] == '' or $SESS->userdata('display_photos') == 'n') { $tagdata = $TMPL->swap_var_single($key, '', $tagdata); $tagdata = $TMPL->swap_var_single('photo_image_width', '', $tagdata); $tagdata = $TMPL->swap_var_single('photo_image_height', '', $tagdata); } else { $tagdata = $TMPL->swap_var_single($key, $PREFS->ini('photo_url', 1) . $row['photo_filename'], $tagdata); $tagdata = $TMPL->swap_var_single('photo_image_width', $row['photo_width'], $tagdata); $tagdata = $TMPL->swap_var_single('photo_image_height', $row['photo_height'], $tagdata); } } /** ---------------------------------------- /** parse basic fields /** ----------------------------------------*/ if (isset($row[$val]) && $val != 'member_id') { $tagdata = $TMPL->swap_var_single($val, $row[$val], $tagdata); } /** ---------------------------------------- /** parse custom member fields /** ----------------------------------------*/ if (isset($mfields[$val])) { // Since comments do not necessarily require registration, and since // you are allowed to put custom member variables in comments, // we delete them if no such row exists $return_val = isset($row['m_field_id_' . $mfields[$val]]) ? $row['m_field_id_' . $mfields[$val]] : ''; $tagdata = $TMPL->swap_var_single($val, $return_val, $tagdata); } /** ---------------------------------------- /** Clean up left over member variables /** ----------------------------------------*/ if (in_array($val, $member_vars)) { $tagdata = str_replace(LD . $val . RD, '', $tagdata); } } if ($this->show_anchor == TRUE) { $return .= "<a name=\"" . $item_count . "\"></a>\n"; } $return .= $tagdata; $item_count++; } /** ---------------------------------------- /** Parse path variable /** ----------------------------------------*/ $return = preg_replace_callback("/" . LD . "\\s*path=(.+?)" . RD . "/", array(&$FNS, 'create_url'), $return); /** ---------------------------------------- /** Add pagination to result /** ----------------------------------------*/ if ($paginate == TRUE) { $paginate_data = str_replace(LD . 'current_page' . RD, $t_current_page, $paginate_data); $paginate_data = str_replace(LD . 'total_pages' . RD, $total_pages, $paginate_data); $paginate_data = str_replace(LD . 'pagination_links' . RD, $pagination_links, $paginate_data); if (preg_match("/" . LD . "if previous_page" . RD . "(.+?)" . LD . SLASH . "if" . RD . "/s", $paginate_data, $match)) { if ($page_previous == '') { $paginate_data = preg_replace("/" . LD . "if previous_page" . RD . ".+?" . LD . SLASH . "if" . RD . "/s", '', $paginate_data); } else { $match['1'] = str_replace(array(LD . 'path' . RD, LD . 'auto_path' . RD), $page_previous, $match['1']); $paginate_data = str_replace($match['0'], $match['1'], $paginate_data); } } if (preg_match("/" . LD . "if next_page" . RD . "(.+?)" . LD . SLASH . "if" . RD . "/s", $paginate_data, $match)) { if ($page_next == '') { $paginate_data = preg_replace("/" . LD . "if next_page" . RD . ".+?" . LD . SLASH . "if" . RD . "/s", '', $paginate_data); } else { $match['1'] = str_replace(array(LD . 'path' . RD, LD . 'auto_path' . RD), $page_next, $match['1']); $paginate_data = str_replace($match['0'], $match['1'], $paginate_data); } } $position = !$TMPL->fetch_param('paginate') ? '' : $TMPL->fetch_param('paginate'); switch ($position) { case "top": $return = $paginate_data . $return; break; case "both": $return = $paginate_data . $return . $paginate_data; break; default: $return .= $paginate_data; break; } } return $return; }
/** ---------------------------------------- /** Subscriptions Edit Form /** ----------------------------------------*/ function edit_subscriptions() { global $IN, $LANG, $FNS, $DB, $LOC, $PREFS, $SESS, $REGX; // Set some base values $blog_subscriptions = FALSE; $galery_subscriptions = FALSE; $forum_subscriptions = FALSE; $result_ids = array(); $result_data = array(); $pageurl = $this->_member_path('edit_subscriptions'); $perpage = 50; $total_count = 0; $rownum = $this->cur_id; $page_links = ''; /** ---------------------------------------- /** Set update path /** ----------------------------------------*/ $swap['path:update_subscriptions'] = $this->_member_path('update_subscriptions'); /** ---------------------------------------- /** Fetch Weblog Comment Subscriptions /** ----------------------------------------*/ $query = $DB->query("SELECT DISTINCT(entry_id) FROM exp_comments WHERE email = '".$SESS->userdata['email']."' AND notify = 'y' ORDER BY comment_date DESC"); if ($query->num_rows > 0) { $blog_subscriptions = TRUE; foreach ($query->result as $row) { $result_ids[$total_count.'b'] = $row['entry_id']; $total_count++; } } /** ---------------------------------------- /** Fetch Gallery Comment Subscriptions /** ----------------------------------------*/ // Since the gallery module might not be installed we'll test for it first. if ($DB->table_exists('exp_gallery_comments')) { $query = $DB->query("SELECT DISTINCT(entry_id) FROM exp_gallery_comments WHERE email = '".$DB->escape_str($SESS->userdata['email'])."' AND notify = 'y' ORDER BY comment_date DESC"); if ($query->num_rows > 0) { $galery_subscriptions = TRUE; foreach ($query->result as $row) { $result_ids[$total_count.'g'] = $row['entry_id']; $total_count++; } } } /** ---------------------------------------- /** Fetch Forum Topic Subscriptions /** ----------------------------------------*/ // Since the forum module might not be installed we'll test for it first. if ($DB->table_exists('exp_forum_subscriptions')) { $query = $DB->query("SELECT topic_id FROM exp_forum_subscriptions WHERE member_id = '".$DB->escape_str($SESS->userdata('member_id'))."' ORDER BY subscription_date DESC"); if ($query->num_rows > 0) { $forum_subscriptions = TRUE; foreach ($query->result as $row) { $result_ids[$total_count.'f'] = $row['topic_id']; $total_count++; } } } /** ------------------------------------ /** No results? Bah, how boring... /** ------------------------------------*/ if (count($result_ids) == 0) { $swap['subscription_results'] = $this->_var_swap($this->_load_element('no_subscriptions_message'), array('lang:no_subscriptions'=> $LANG->line('no_subscriptions'))); return $this->_var_swap($this->_load_element('subscriptions_form'), $swap); } // Sort the array ksort($result_ids); /** --------------------------------- /** Do we need pagination? /** ---------------------------------*/ $total_rows = count($result_ids); if ($rownum != '') $rownum = substr($rownum, 1); $rownum = ($rownum == '' || ($perpage > 1 AND $rownum == 1)) ? 0 : $rownum; if ($rownum > $total_rows) { $rownum = 0; } $t_current_page = floor(($rownum / $perpage) + 1); $total_pages = intval(floor($total_rows / $perpage)); if ($total_rows % $perpage) $total_pages++; if ($total_rows > $perpage) { if ( ! class_exists('Paginate')) { require PATH_CORE.'core.paginate'.EXT; } $PGR = new Paginate(); $PGR->first_url = $pageurl; $PGR->path = $pageurl; $PGR->prefix = 'R'; $PGR->total_count = $total_rows; $PGR->per_page = $perpage; $PGR->cur_page = $rownum; $PGR->qstr_var = 'rownum'; $page_links = $PGR->show_links(); $result_ids = array_slice($result_ids, $rownum, $perpage); } else { $result_ids = array_slice($result_ids, 0, $perpage); } /** --------------------------------- /** Fetch Weblog Titles /** ---------------------------------*/ if ($blog_subscriptions == TRUE) { $sql = "SELECT exp_weblog_titles.title, exp_weblog_titles.url_title, exp_weblog_titles.weblog_id, exp_weblog_titles.entry_id, exp_weblogs.comment_url, exp_weblogs.blog_url FROM exp_weblog_titles LEFT JOIN exp_weblogs ON exp_weblog_titles.weblog_id = exp_weblogs.weblog_id WHERE entry_id IN ("; $idx = ''; foreach ($result_ids as $key => $val) { if (substr($key, strlen($key)-1) == 'b') { $idx .= $val.","; } } $idx = substr($idx, 0, -1); if ($idx != '') { $query = $DB->query($sql.$idx.') '); if ($query->num_rows > 0) { foreach ($query->result as $row) { $result_data[] = array( 'path' => $FNS->remove_double_slashes($REGX->prep_query_string(($row['comment_url'] != '') ? $row['comment_url'] : $row['blog_url']).'/'.$row['url_title'].'/'), 'title' => str_replace(array('<', '>', '{', '}', '\'', '"', '?'), array('<', '>', '{', '}', '’', '"', '?'), $row['title']), 'id' => 'b'.$row['entry_id'], 'type' => $LANG->line('comment') ); } } } } /** --------------------------------- /** Fetch Gallery Titles /** ---------------------------------*/ if ($galery_subscriptions == TRUE) { $sql = "SELECT exp_gallery_entries.title, exp_gallery_entries.entry_id, exp_gallery_entries.gallery_id, exp_galleries.gallery_comment_url FROM exp_gallery_entries LEFT JOIN exp_galleries ON exp_gallery_entries.gallery_id = exp_galleries.gallery_id WHERE entry_id IN ("; $idx = ''; foreach ($result_ids as $key => $val) { if (substr($key, strlen($key)-1) == 'g') { $idx .= $val.","; } } $idx = substr($idx, 0, -1); if ($idx != '') { $query = $DB->query($sql.$idx.') '); if ($query->num_rows > 0) { foreach ($query->result as $row) { $result_data[] = array( 'path' => $FNS->remove_double_slashes($REGX->prep_query_string($row['gallery_comment_url'] ).'/'.$row['entry_id'].'/'), 'title' => str_replace(array('<', '>', '{', '}', '\'', '"', '?'), array('<', '>', '{', '}', '’', '"', '?'), $row['title']), 'id' => 'g'.$row['entry_id'], 'type' => $LANG->line('mbr_image_gallery') ); } } } } /** --------------------------------- /** Fetch Forum Topics /** ---------------------------------*/ if ($forum_subscriptions == TRUE) { $sql = "SELECT title, topic_id, board_forum_url FROM exp_forum_topics, exp_forum_boards WHERE exp_forum_topics.board_id = exp_forum_boards.board_id AND topic_id IN ("; $idx = ''; foreach ($result_ids as $key => $val) { if (substr($key, strlen($key)-1) == 'f') { $idx .= $val.","; } } $idx = substr($idx, 0, -1); if ($idx != '') { $query = $DB->query($sql.$idx.') '); if ($query->num_rows > 0) { foreach ($query->result as $row) { $result_data[] = array( 'path' => $FNS->remove_double_slashes($REGX->prep_query_string($row['board_forum_url'] ).'/viewthread/'.$row['topic_id'].'/'), 'title' => str_replace(array('<', '>', '{', '}', '\'', '"', '?'), array('<', '>', '{', '}', '’', '"', '?'), $row['title']), 'id' => 'f'.$row['topic_id'], 'type' => $LANG->line('mbr_forum_post') ); } } } } // Build the result table... $out = $this->_var_swap($this->_load_element('subscription_result_heading'), array( 'lang:title' => $LANG->line('title'), 'lang:type' => $LANG->line('type'), 'lang:unsubscribe' => $LANG->line('unsubscribe') ) ); $i = 0; foreach ($result_data as $val) { $rowtemp = $this->_load_element('subscription_result_rows'); $rowtemp = str_replace('{class}', ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo', $rowtemp); $rowtemp = str_replace('{path}', $val['path'], $rowtemp); $rowtemp = str_replace('{title}', $val['title'], $rowtemp); $rowtemp = str_replace('{id}', $val['id'], $rowtemp); $rowtemp = str_replace('{type}', $val['type'], $rowtemp); $out .= $rowtemp; } $out .= $this->_var_swap($this->_load_element('subscription_pagination'), array('pagination' => $page_links, 'lang:unsubscribe' => $LANG->line('unsubscribe'), 'class' => ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo')); $swap['subscription_results'] = $out; return $this->_var_swap( $this->_load_element('subscriptions_form'), $swap ); }
/** ------------------------------------- /** Paginate /** -------------------------------------*/ function pager($base_url = '', $total_count = '', $per_page = '', $cur_page = '', $qstr_var = '') { global $LANG; // Instantiate the "paginate" class. if (!class_exists('Paginate')) { require PATH_CORE . 'core.paginate' . EXT; } $PGR = new Paginate(); $PGR->base_url = $base_url; $PGR->total_count = $total_count; $PGR->per_page = $per_page; $PGR->cur_page = $cur_page; $PGR->qstr_var = $qstr_var; return $PGR->show_links(); }
/** ---------------------------------------- /** Member List /** ----------------------------------------*/ function memberlist() { global $IN, $DB, $LANG, $OUT, $SESS, $LOC, $FNS, $PREFS; /** ---------------------------------------- /** Can the user view profiles? /** ----------------------------------------*/ if ($SESS->userdata['can_view_profiles'] == 'n') { return $OUT->show_user_error('general', array($LANG->line('mbr_not_allowed_to_view_profiles'))); } /** ---------------------------------------- /** Grab the templates /** ----------------------------------------*/ $template = $this->_load_element('memberlist'); $vars = $FNS->assign_variables($template, '/'); $var_cond = $FNS->assign_conditional_variables($template, '/'); $memberlist_rows = $this->_load_element('memberlist_rows'); $mvars = $FNS->assign_variables($memberlist_rows, '/'); $mvar_cond = $FNS->assign_conditional_variables($memberlist_rows, '/'); $this->var_cond = array_merge($var_cond, $mvar_cond); $this->var_single = array_merge($vars['var_single'], $mvars['var_single']); $this->var_pair = array_merge($vars['var_pair'], $mvars['var_pair']); /** ---------------------------------------- /** Fetch the custom member field definitions /** ----------------------------------------*/ $fields = array(); $query = $DB->query("SELECT m_field_id, m_field_name FROM exp_member_fields"); if ($query->num_rows > 0) { foreach ($query->result as $row) { $fields[$row['m_field_name']] = $row['m_field_id']; } } /** ---------------------------------------- /** Assign default variables /** ----------------------------------------*/ $vars = array( 'group_id' => 0, 'order_by' => ($PREFS->ini('memberlist_order_by') == '') ? 'total_posts' : $PREFS->ini('memberlist_order_by'), 'sort_order' => ($PREFS->ini('memberlist_sort_order') == '') ? 'desc' : $PREFS->ini('memberlist_sort_order'), 'row_limit' => ($PREFS->ini('memberlist_row_limit') == '') ? 20 : $PREFS->ini('memberlist_row_limit'), 'row_count' => 0 ); foreach ($vars as $key => $val) { $$key = ( ! isset($_POST[$key])) ? $val : $_POST[$key]; } /* ---------------------------------------- /* Check for Search URL /* - In an attempt to be clever, I decided to first check for the Search ID and if found, use an explode to set it and find a new $this->cur_id. This solves the problem easily and saves me from using substr() and strpos() far too many times for a sane man to consider reasonable. -Paul /* ----------------------------------------*/ $search_path = ''; if (preg_match("|\/([a-z0-9]{32})\/|i", '/'.$IN->QSTR.'/', $match)) { foreach(explode('/', '/'.$IN->QSTR.'/') as $val) { if (isset($search_id)) { $this->cur_id = $val; break; } elseif($match['1'] == $val) { $search_id = $val; $search_path .= '/'.$search_id.'/'; } } } /** ---------------------------------------- /** Parse the request URI /** ----------------------------------------*/ $path = ''; if (eregi("^[0-9]{1,}\-[0-9a-z_]{1,}\-[0-9a-z]{1,}\-[0-9]{1,}\-[0-9]{1,}$", $this->cur_id)) { $x = explode("-", $this->cur_id); $group_id = $x['0']; $order_by = $x['1']; $sort_order = $x['2']; $row_limit = $x['3']; $row_count = $x['4']; $path = '/'.$x['0'].'-'.$x['1'].'-'.$x['2'].'-'.$x['3'].'-'; } else { $path = '/'.$group_id.'-'.$order_by.'-'.$sort_order.'-'.$row_limit.'-'; } /** ---------------------------------------- /** Build the query /** ----------------------------------------*/ $f_sql = "SELECT m.member_id, m.username, m.screen_name, m.email, m.url, m.location, m.icq, m.aol_im, m.yahoo_im, m.msn_im, m.location, m.join_date, m.last_visit, m.last_activity, m.last_entry_date, m.last_comment_date, m.last_forum_post_date, m.total_entries, m.total_comments, m.total_forum_topics, m.total_forum_posts, m.language, m.timezone, m.daylight_savings, m.bday_d, m.bday_m, m.bday_y, m.accept_user_email, m.avatar_filename, m.avatar_width, m.avatar_height, (m.total_forum_topics + m.total_forum_posts) AS total_posts, g.group_title "; $p_sql = "SELECT COUNT(member_id) AS count "; $sql = "FROM exp_members m, exp_member_groups g WHERE m.group_id = g.group_id AND g.group_id != '3' AND g.group_id != '4' AND g.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND g.include_in_memberlist = 'y' "; if ($this->is_admin == FALSE OR $SESS->userdata('group_id') != 1) { $sql .= "AND g.group_id != '2' "; } // 2 = Banned 3 = Guests 4 = Pending if ($group_id != 0) { $sql .= " AND g.group_id = '$group_id'"; } /** ---------------------------------------- /** Load the Search's Member IDs /** ----------------------------------------*/ if (isset($search_id)) { $sql .= $this->fetch_search($search_id); //echo $this->search_keywords.' => '.$this->search_fields; } /** ------------------------------------- /** First Letter of Screen Name, Secret Addition /** -------------------------------------*/ $first_letter = ''; // No pagination // Pagination or No Pagination & Forum // Pagination & Forum for ($i=3; $i <= 5; ++ $i) { if (isset($IN->SEGS[$i]) && strlen($IN->SEGS[$i]) == 1 && preg_match("/[A-Z]{1}/", $IN->SEGS[$i])) { $first_letter = $IN->SEGS[$i]; $sql .= " AND m.screen_name LIKE '{$first_letter}%' "; break; } } /** ---------------------------------------- /** Run "count" query for pagination /** ----------------------------------------*/ $query = $DB->query($p_sql.$sql); if ($order_by == 'total_posts') { $sql .= " ORDER BY ".$order_by." ".$sort_order; } else { $sql .= " ORDER BY m.".$order_by." ".$sort_order; } /** ----------------------------- /** Build Pagination /** -----------------------------*/ // Set the stats for: {current_page} of {total_pages} $current_page = floor(($row_count / $row_limit) + 1); $total_pages = ceil($query->row['count'] / $row_limit); // Deprecate this $page_count = $LANG->line('page').' '.$current_page.' '.$LANG->line('of').' '.$total_pages; $pager = ''; if ($query->row['count'] > $row_limit) { if ( ! class_exists('Paginate')) { require PATH_CORE.'core.paginate'.EXT; } $PGR = new Paginate(); $PGR->first_url = $this->_member_path('memberlist'.$search_path); $PGR->path = $this->_member_path('memberlist'.$search_path.$path, ''); $PGR->suffix = ($first_letter != '') ? $first_letter.'/' : ''; $PGR->total_count = $query->row['count']; $PGR->per_page = $row_limit; $PGR->cur_page = $row_count; $PRG->first_page = $LANG->line('first'); $PRG->last_page = $LANG->line('last'); if (preg_match("/".LD.'pagination_links'.RD."/", $template)) { $PGR->first_div_o = '<td><div class="paginate">'; $PGR->first_div_c = '</div></td>'; $PGR->next_div_o = '<td><div class="paginate">'; $PGR->next_div_c = '</div></td>'; $PGR->prev_div_o = '<td><div class="paginate">'; $PGR->prev_div_c = '</div></td>'; $PGR->num_div_o = '<td><div class="paginate">'; $PGR->num_div_c = '</div></td>'; $PGR->cur_div_o = '<td><div class="paginateCur">'; $PGR->cur_div_c = '</div></td>'; $PGR->last_div_o = '<td><div class="paginate">'; $PGR->last_div_c = '</div></td>'; } $pager = $PGR->show_links(); $sql .= " LIMIT ".$row_count.", ".$row_limit; } /** ---------------------------------------- /** Run the full query and process result /** ----------------------------------------*/ $query = $DB->query($f_sql.$sql); $str = ''; $i = 0; if ($query->num_rows > 0) { foreach ($query->result as $row) { $temp = $memberlist_rows; $style = ($i++ % 2) ? 'memberlistRowOne' : 'memberlistRowTwo'; $temp = str_replace("{member_css}", $style, $temp); $temp = str_replace("{path:profile}", $this->_member_path($row['member_id']), $temp); if ($row['url'] != '' AND substr($row['url'], 0, 4) != "http") { $row['url'] = "http://".$row['url']; } $temp = $this->_var_swap($temp, array( 'aim_console' => "onclick=\"window.open('".$this->_member_path('aim_console/'.$row['member_id'])."', '_blank', 'width=240,height=360,scrollbars=yes,resizable=yes,status=yes,screenx=5,screeny=5');\"", 'icq_console' => "onclick=\"window.open('".$this->_member_path('icq_console/'.$row['member_id'])."', '_blank', 'width=650,height=580,scrollbars=yes,resizable=yes,status=yes,screenx=5,screeny=5');\"", 'yahoo_console' => "http://edit.yahoo.com/config/send_webmesg?.target=".$row['yahoo_im']."&.src=pg", 'email_console' => "onclick=\"window.open('".$this->_member_path('email_console/'.$row['member_id'])."', '_blank', 'width=650,height=600,scrollbars=yes,resizable=yes,status=yes,screenx=5,screeny=5');\"", ) ); /** ---------------------------------------- /** Parse conditional pairs /** ----------------------------------------*/ foreach ($this->var_cond as $val) { /** ---------------------------------------- /** Conditional statements /** ----------------------------------------*/ $cond = $FNS->prep_conditional($val['0']); $lcond = substr($cond, 0, strpos($cond, ' ')); $rcond = substr($cond, strpos($cond, ' ')); /** ---------------------------------------- /** Parse conditions in standard fields /** ----------------------------------------*/ if ( isset($row[$val['3']])) { $lcond = str_replace($val['3'], "\$row['".$val['3']."']", $lcond); $cond = $lcond.' '.$rcond; $cond = str_replace("\|", "|", $cond); eval("\$result = ".$cond.";"); if ($result) { $temp = preg_replace("/".LD.$val['0'].RD."(.*?)".LD.'\/if'.RD."/s", "\\1", $temp); } else { $temp = preg_replace("/".LD.$val['0'].RD."(.*?)".LD.'\/if'.RD."/s", "", $temp); } } /** ------------------------------------------ /** Parse conditions in custom member fields /** ------------------------------------------*/ elseif (isset($fields[$val['3']])) { if (isset($row['m_field_id_'.$fields[$val['3']]])) { $v = $row['m_field_id_'.$fields[$val['3']]]; $lcond = str_replace($val['3'], "\$v", $lcond); $cond = $lcond.' '.$rcond; $cond = str_replace("\|", "|", $cond); eval("\$result = ".$cond.";"); if ($result) { $temp = preg_replace("/".LD.$val['0'].RD."(.*?)".LD.'\/if'.RD."/s", "\\1", $temp); } else { $temp = preg_replace("/".LD.$val['0'].RD."(.*?)".LD.'\/if'.RD."/s", "", $temp); } } } /** ---------------------------------------- /** {if accept_email} /** ----------------------------------------*/ if (preg_match("/^if\s+accept_email.*/i", $val['0'])) { if ($row['accept_user_email'] == 'n') { $temp = $this->_deny_if('accept_email', $temp); } else { $temp = $this->_allow_if('accept_email', $temp); } } /** ---------------------------------------- /** {if avatar} /** ----------------------------------------*/ if (preg_match("/^if\s+avatar.*/i", $val['0'])) { if ($PREFS->ini('enable_avatars') == 'y' AND $row['avatar_filename'] != '' AND $SESS->userdata('display_avatars') == 'y' ) { $avatar_path = $PREFS->ini('avatar_url', 1).$row['avatar_filename']; $avatar_width = $row['avatar_width']; $avatar_height = $row['avatar_height']; $temp = $this->_allow_if('avatar', $temp); } else { $avatar_path = ''; $avatar_width = ''; $avatar_height = ''; $temp = $this->_deny_if('avatar', $temp); } } } // END PAIRS /** ---------------------------------------- /** Manual replacements /** ----------------------------------------*/ $temp = str_replace(LD.'name'.RD, ($row['screen_name'] != '') ? $row['screen_name'] : $row['username'], $temp); /** ---------------------------------------- /** 1:1 variables /** ----------------------------------------*/ foreach ($this->var_single as $key => $val) { /** ---------------------------------------- /** parse profile path /** ----------------------------------------*/ if (ereg("^profile_path", $key)) { $temp = $this->_var_swap_single($key, $FNS->create_url($FNS->extract_path($key).'/'.$row['member_id']), $temp); } /** ---------------------------------------- /** parse avatar path /** ----------------------------------------*/ if (ereg("^path:avatars", $key)) { $temp = $this->_var_swap_single($key, $avatar_path, $temp); } /** ---------------------------------------- /** parse "last_visit" /** ----------------------------------------*/ if (ereg("^last_visit", $key)) { $temp = $this->_var_swap_single($key, ($row['last_activity'] > 0) ? $LOC->decode_date($val, $row['last_activity']) : '--', $temp); } /** ---------------------------------------- /** parse "join_date" /** ----------------------------------------*/ if (ereg("^join_date", $key)) { $temp = $this->_var_swap_single($key, ($row['join_date'] > 0) ? $LOC->decode_date($val, $row['join_date']) : '--', $temp); } /** ---------------------------------------- /** parse "last_entry_date" /** ----------------------------------------*/ if (ereg("^last_entry_date", $key)) { $temp = $this->_var_swap_single($key, ($row['last_entry_date'] > 0) ? $LOC->decode_date($val, $row['last_entry_date']) : '--', $temp); } /** ---------------------------------------- /** parse "last_comment_date" /** ----------------------------------------*/ if (ereg("^last_comment_date", $key)) { $temp = $this->_var_swap_single($key, ($row['last_comment_date'] > 0) ? $LOC->decode_date($val, $row['last_comment_date']) : '--', $temp); } /** ---------------------------------------- /** parse "last_forum_post_date" /** ----------------------------------------*/ if (ereg("^last_forum_post_date", $key)) { $temp = $this->_var_swap_single($key, ($row['last_forum_post_date'] > 0) ? $LOC->decode_date($val, $row['last_forum_post_date']) : '--', $temp); } /** ---------------------------------------- /** {total_forum_posts} /** ----------------------------------------*/ if ($key == 'total_forum_posts') { $temp = $this->_var_swap_single($val, $row['total_forum_topics']+$row['total_forum_posts'], $temp); } /** ---------------------------------------- /** {total_combined_posts} /** ----------------------------------------*/ if ($key == 'total_combined_posts') { $temp = $this->_var_swap_single($val, $row['total_forum_topics']+$row['total_forum_posts']+$row['total_entries']+$row['total_comments'], $temp); } /** ---------------------------------------- /** {total_entries} /** ----------------------------------------*/ if ($key == 'total_entries') { $temp = $this->_var_swap_single($val, $row['total_entries'], $temp); } /** ---------------------------------------- /** {total_comments} /** ----------------------------------------*/ if ($key == 'total_comments') { $temp = $this->_var_swap_single($val, $row['total_comments'], $temp); } /** ---------------------------------------- /** parse literal variables /** ----------------------------------------*/ if (isset($row[$val])) { $temp = $this->_var_swap_single($val, $row[$val], $temp); } /** ---------------------------------------- /** parse custom member fields /** ----------------------------------------*/ if ( isset($fields[$val]) AND isset($row['m_field_id_'.$fields[$val]])) { $temp = $this->_var_swap_single($val, $row['m_field_id_'.$fields[$val]], $temp); } } $str .= $temp; } } /** ---------------------------------------- /** Render the member group list /** ----------------------------------------*/ $english = array('Guests', 'Banned', 'Members', 'Pending', 'Super Admins'); $sql = "SELECT group_id, group_title FROM exp_member_groups WHERE include_in_memberlist = 'y' AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id != '3' AND group_id != '4' "; if ($this->is_admin == FALSE OR $SESS->userdata('group_id') != 1) { $sql .= "AND group_id != '2' "; } $sql .= " order by group_title"; $query = $DB->query($sql); $selected = ($group_id == 0) ? " selected='selected' " : ''; $menu = "<option value='0'".$selected.">".$LANG->line('mbr_all_member_groups')."</option>\n"; foreach ($query->result as $row) { $group_title = $row['group_title']; if (in_array($group_title, $english)) { $group_title = $LANG->line(strtolower(str_replace(" ", "_", $group_title))); } $selected = ($group_id == $row['group_id']) ? " selected='selected' " : ''; $menu .= "<option value='".$row['group_id']."'".$selected.">".$group_title."</option>\n"; } $template = str_replace(LD.'group_id_options'.RD, $menu, $template); /** ---------------------------------------- /** Create the "Order By" menu /** ----------------------------------------*/ $selected = ($order_by == 'screen_name') ? " selected='selected' " : ''; $menu = "<option value='screen_name'".$selected.">".$LANG->line('mbr_member_name')."</option>\n"; if ($this->in_forum == TRUE) { $selected = ($order_by == 'total_posts') ? " selected='selected' " : ''; $menu .= "<option value='total_posts'".$selected.">".$LANG->line('total_posts')."</option>\n"; } else { $selected = ($order_by == 'total_comments') ? " selected='selected' " : ''; $menu .= "<option value='total_comments'".$selected.">".$LANG->line('mbr_total_comments')."</option>\n"; $selected = ($order_by == 'total_entries') ? " selected='selected' " : ''; $menu .= "<option value='total_entries'".$selected.">".$LANG->line('mbr_total_entries')."</option>\n"; } $selected = ($order_by == 'join_date') ? " selected='selected' " : ''; $menu .= "<option value='join_date'".$selected.">".$LANG->line('join_date')."</option>\n"; $template = str_replace(LD.'order_by_options'.RD, $menu, $template); /** ---------------------------------------- /** Create the "Sort By" menu /** ----------------------------------------*/ $selected = ($sort_order == 'asc') ? " selected='selected' " : ''; $menu = "<option value='asc'".$selected.">".$LANG->line('mbr_ascending')."</option>\n"; $selected = ($sort_order == 'desc') ? " selected='selected' " : ''; $menu .= "<option value='desc'".$selected.">".$LANG->line('mbr_descending')."</option>\n"; $template = str_replace(LD.'sort_order_options'.RD, $menu, $template); /** ---------------------------------------- /** Create the "Row Limit" menu /** ----------------------------------------*/ $selected = ($row_limit == '10') ? " selected='selected' " : ''; $menu = "<option value='10'".$selected.">10</option>\n"; $selected = ($row_limit == '20') ? " selected='selected' " : ''; $menu .= "<option value='20'".$selected.">20</option>\n"; $selected = ($row_limit == '30') ? " selected='selected' " : ''; $menu .= "<option value='30'".$selected.">30</option>\n"; $selected = ($row_limit == '40') ? " selected='selected' " : ''; $menu .= "<option value='40'".$selected.">40</option>\n"; $selected = ($row_limit == '50') ? " selected='selected' " : ''; $menu .= "<option value='50'".$selected.">50</option>\n"; if ($row_limit > 50) { $menu .= "<option value='".$row_limit."' selected='selected'>".$row_limit."</option>\n"; } $template = str_replace(LD.'row_limit_options'.RD, $menu, $template); /** ---------------------------------------- /** Custom Profile Fields for Member Search /** ----------------------------------------*/ $sql = "SELECT m_field_id, m_field_label FROM exp_member_fields WHERE m_field_public = 'y' ORDER BY m_field_order "; $query = $DB->query($sql); $profile_options = ''; foreach ($query->result as $row) { $profile_options .= "<option value='m_field_id_".$row['m_field_id']."'>".$row['m_field_label']."</option>\n"; } $template = str_replace(LD.'custom_profile_field_options'.RD, $profile_options, $template); /** ---------------------------------------- /** Put rendered chunk into template /** ----------------------------------------*/ if ($pager == '') { $template = $this->_deny_if('paginate', $template); } else { $template = $this->_allow_if('paginate', $template); // Deprecate these... $template = str_replace(LD.'paginate'.RD, $pager, $template); $template = str_replace(LD.'page_count'.RD, $page_count, $template); //..... $template = str_replace(LD.'pagination_links'.RD, $pager, $template); $template = str_replace(LD.'current_page'.RD, $current_page, $template); $template = str_replace(LD.'total_pages'.RD, $total_pages, $template); } if ($this->is_search === TRUE) { $template = str_replace(LD."form_declaration".RD, "<form method='post' action='".$this->_member_path('member_search'.$search_path)."'>", $template); } else { $template = str_replace(LD."form_declaration".RD, "<form method='post' action='".$this->_member_path('memberlist'.(($first_letter != '') ? $first_letter.'/' : $search_path))."'>", $template); } $template = str_replace(LD."form:form_declaration:do_member_search".RD, "<form method='post' action='".$this->_member_path('do_member_search')."'>", $template); $template = str_replace(LD."member_rows".RD, $str, $template); return $template; }