function tags_function_generate_menu(&$args) { global $db, $phpbb_root_path, $phpEx, $template; $tag_list = array(); $total = 0; $sql = 'SELECT blog_tags FROM ' . BLOGS_TABLE . ($args['user_id'] ? ' WHERE user_id = ' . intval($args['user_id']) . build_permission_sql(intval($args['user_id'])) : ''); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { foreach (get_tags_from_text($row['blog_tags']) as $tag) { if (!isset($tag_list[$tag])) { $tag_list[$tag] = 1; } else { $tag_list[$tag]++; } $total++; } } $db->sql_freeresult($result); ksort($tag_list); if (sizeof($tag_list)) { $med = (int) $total / sizeof($tag_list); foreach ($tag_list as $tag => $cnt) { $template->assign_block_vars('tags', array('TAG' => $tag, 'CNT' => $cnt, 'SIZE' => min(26, 10 + 4 * $cnt / $med), 'U_VIEW' => append_sid("{$phpbb_root_path}blog.{$phpEx}", 'page=tag&tag=' . $tag))); } $tag_output = blog_plugins::parse_template('blog/plugins/tags/tags_menu.html'); $args['user_menu_extra'] .= $tag_output; $args['extra'] .= $tag_output; } }
function archive_function_generate_menu(&$arg) { global $auth, $db, $user, $template, $phpbb_root_path, $blog_images_path; if (!$arg['user_id']) { return; } $last_mon = 0; $archive_rows = array(); $sql = 'SELECT blog_id, blog_time, blog_subject FROM ' . BLOGS_TABLE . ' WHERE user_id = ' . intval($arg['user_id']) . ($auth->acl_get('m_blogapprove') ? '' : ' AND blog_approved = 1') . (!$auth->acl_gets('m_blogdelete', 'a_blogdelete') ? ' AND (blog_deleted = 0 OR blog_deleted = ' . $user->data['user_id'] . ')' : '') . build_permission_sql($user->data['user_id']) . ' ORDER BY blog_time DESC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $date = getdate($row['blog_time']); // If we are starting a new month if ($date['mon'] != $last_mon) { $archive_row = array('MONTH' => $user->lang['datetime'][$date['month']], 'YEAR' => $date['year'], 'monthrow' => array()); $archive_rows[] = $archive_row; } $archive_row_month = array('TITLE' => censor_text($row['blog_subject']), 'U_VIEW' => blog_url($arg['user_id'], $row['blog_id'], false, array(), array('blog_subject' => $row['blog_subject'])), 'DATE' => $user->format_date($row['blog_time'])); $archive_rows[sizeof($archive_rows) - 1]['monthrow'][] = $archive_row_month; // set the last month variable as the current month $last_mon = $date['mon']; } $db->sql_freeresult($result); foreach ($archive_rows as $row) { $template->assign_block_vars('archiverow', $row); } $template->assign_vars(array('S_ARCHIVES' => sizeof($archive_rows) ? true : false, 'T_THEME_PATH' => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme', 'IMG_PLUS' => $blog_images_path . 'plus.gif', 'IMG_MINUS' => $blog_images_path . 'minus.gif')); $arg['user_menu_extra'] .= blog_plugins::parse_template('blog/plugins/archive/archive_body.html'); unset($template->_tpldata['archiverow']); }
/** * Get reply data * * To select reply data from the database * * @param string $mode The mode we want * @param int $id To input the wanted blog_id, this may be an array if you want to select more than 1 * @param array $selection_data For extras, like start, limit, order by, order direction, etc, all of the options are listed a few lines below */ public function get_reply_data($mode, $id = 0, $selection_data = array()) { global $db, $user, $phpbb_root_path, $phpEx, $auth; blog_plugins::plugin_do_ref('reply_data_start', $selection_data); // input options for selection_data $start = isset($selection_data['start']) ? $selection_data['start'] : 0; // the start used in the Limit sql query $limit = isset($selection_data['limit']) ? $selection_data['limit'] : 10; // the limit on how many blogs we will select $order_by = isset($selection_data['order_by']) ? $selection_data['order_by'] : 'reply_id'; // the way we want to order the request in the SQL query $order_dir = isset($selection_data['order_dir']) ? $selection_data['order_dir'] : 'DESC'; // the direction we want to order the request in the SQL query $sort_days = isset($selection_data['sort_days']) ? $selection_data['sort_days'] : 0; // the sort days selection $custom_sql = isset($selection_data['custom_sql']) ? $selection_data['custom_sql'] : ''; // add your own custom WHERE part to the query $category_id = isset($selection_data['category_id']) ? $selection_data['category_id'] : 0; // The category ID, if selecting replies only from blogs from a certain category // Setup some variables... $reply_ids = array(); // make sure $id is an array for consistency if (!is_array($id)) { $id = array(intval($id)); } $sql_array = array('SELECT' => 'r.*', 'FROM' => array(BLOGS_REPLY_TABLE => array('r')), 'WHERE' => array(), 'ORDER_BY' => $order_by . ' ' . $order_dir); if ($category_id) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(BLOGS_IN_CATEGORIES_TABLE => 'bc'), 'ON' => 'bc.blog_id = r.blog_id'); $sql_array['WHERE'][] = is_array($category_id) ? $db->sql_in_set('bc.category_id', $category_id) : 'bc.category_id = ' . $category_id; } if (!$auth->acl_get('m_blogreplyapprove')) { if ($user->data['is_registered']) { $sql_array['WHERE'][] = '(r.reply_approved = 1 OR r.reply_id = ' . $user->data['user_id'] . ')'; } else { $sql_array['WHERE'][] = 'r.reply_approved = 1'; } } if (!$auth->acl_gets('m_blogreplydelete', 'a_blogreplydelete')) { $sql_array['WHERE'][] = '(r.reply_deleted = 0 OR r.reply_deleted = ' . $user->data['user_id'] . ')'; // Make sure we do not select replies from blogs that have been deleted (if the user isn't allowed to view deleted items) $sql_array['LEFT_JOIN'][] = array('FROM' => array(BLOGS_TABLE => 'b'), 'ON' => 'b.blog_id = r.blog_id'); $sql_array['WHERE'][] = '(b.blog_deleted = 0 OR b.blog_deleted = ' . $user->data['user_id'] . ')'; if (build_permission_sql($user->data['user_id'], false)) { // remove the first AND $sql_array['WHERE'][] = substr(build_permission_sql($user->data['user_id'], false, 'b.'), 5); } } if ($sort_days) { $sql_array['WHERE'][] = 'r.reply_time >= ' . (time() - $sort_days * 86400); } if ($custom_sql) { $sql_array['WHERE'][] = $custom_sql; } switch ($mode) { case 'blog': // view all replys by a blog_id $sql_array['WHERE'][] = $db->sql_in_set('r.blog_id', $id); break; case 'reply': // select replies by reply_id(s) $sql_array['WHERE'][] = $db->sql_in_set('r.reply_id', $id); $limit = 0; break; case 'reported': // select reported replies if (!$auth->acl_get('m_blogreplyreport')) { return false; } $sql_array['WHERE'][] = 'r.reply_reported = 1'; break; case 'disapproved': // select disapproved replies if (!$auth->acl_get('m_blogreplyapprove')) { return false; } $sql_array['WHERE'][] = 'r.reply_approved = 0'; break; case 'reply_count': // for counting how many replies there are for a blog if (self::$blog[$id[0]]['blog_real_reply_count'] == 0 || self::$blog[$id[0]]['blog_real_reply_count'] == self::$blog[$id[0]]['blog_reply_count']) { return self::$blog[$id[0]]['blog_real_reply_count']; } if (!$sort_days && ($auth->acl_get('m_blogreplyapprove') && $auth->acl_gets('m_blogreplydelete', 'a_blogreplydelete'))) { return self::$blog[$id[0]]['blog_real_reply_count']; } else { if ($auth->acl_get('m_blogreplyapprove') || $auth->acl_gets('m_blogreplydelete', 'a_blogreplydelete') || $sort_days || self::$blog[$id[0]]['user_id'] == $user->data['user_id'] && $auth->acl_get('u_blogmoderate')) { $sql_array['SELECT'] = 'count(r.reply_id) AS total'; $sql_array['WHERE'][] = 'r.blog_id = ' . $id[0]; $sql_array['WHERE'] = implode(' AND ', $sql_array['WHERE']); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $total = $db->sql_fetchrow($result); $db->sql_freeresult($result); return $total['total']; } else { return self::$blog[$id[0]]['blog_reply_count']; } } break; case 'page': // Special mode for trying to find out what page the reply is on $cnt = 0; $sql = 'SELECT reply_id FROM ' . BLOGS_REPLY_TABLE . ' WHERE blog_id = ' . $id[0] . ($sort_days != 0 ? ' AND reply_time >= ' . (time() - $sort_days * 86400) : '') . ' ORDER BY ' . $order_by . ' ' . $order_dir; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($row['reply_id'] == $id[1]) { break; } $cnt++; } $db->sql_freeresult($result); return $cnt; break; case 'count': // this just does a count of the number of replies $sql_array['SELECT'] = 'count(r.reply_id) AS total'; $sql_array['WHERE'] = implode(' AND ', $sql_array['WHERE']); unset($sql_array['ORDER_BY']); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $total = $db->sql_fetchrow($result); $db->sql_freeresult($result); return $total['total']; break; case 'recent': if (!isset($selection_data['order_by'])) { $sql_array['ORDER_BY'] = 'r.reply_time DESC'; } break; } $temp = compact('sql_array', 'sql_where'); blog_plugins::plugin_do_ref('reply_data_sql', $temp); extract($temp); $sql_array['WHERE'] = implode(' AND ', $sql_array['WHERE']); $sql = $db->sql_build_query('SELECT', $sql_array); if ($limit) { $result = $db->sql_query_limit($sql, $limit, $start); } else { $result = $db->sql_query($sql); } while ($row = $db->sql_fetchrow($result)) { blog_plugins::plugin_do_ref('reply_data_while', $row); // Initialize the attachment data $row['attachment_data'] = array(); // now put all the data in the reply array self::$reply[$row['reply_id']] = $row; // Add this user's ID to the user_queue self::$user_queue[] = $row['user_id']; // has the reply been edited? If so add that user to the user_queue if ($row['reply_edit_count'] != 0) { self::$user_queue[] = $row['reply_edit_user']; } // has the reply been deleted? If so add that user to the user_queue if ($row['reply_deleted'] != 0) { self::$user_queue[] = $row['reply_deleted']; } // make sure we don't record the same ID more than once if (!in_array($row['reply_id'], $reply_ids)) { $reply_ids[] = $row['reply_id']; } } $db->sql_freeresult($result); // if there are no replys, return false if (sizeof($reply_ids) == 0) { return false; } return $reply_ids; }
$order_dir = $sort_dir == 'a' ? 'ASC' : 'DESC'; if ($sort_key == 'pt') { $order_dir = $order_dir == 'ASC' ? 'DESC' : 'ASC'; } $user->add_lang(array('mods/blog/view', 'viewtopic')); $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; $sort_by_text = array('t' => $user->lang['USERNAME'], 'pt' => $user->lang['LAST_BLOG_TIME']); $sort_by_sql = array('t' => 'u.username', 'pt' => 'MAX(b.blog_id)'); $users = array(); $blog_ids = array(); $sql = 'SELECT COUNT(b.blog_id) AS blog_count, MAX(b.blog_id) AS blog_id, u.user_id, u.user_colour, u.username, bu.title FROM ' . BLOGS_TABLE . ' b, ' . USERS_TABLE . ' u LEFT JOIN ' . BLOGS_USERS_TABLE . ' bu ON bu.user_id = u.user_id WHERE u.user_id = b.user_id' . ($sort_days ? ' AND b.blog_time >= ' . (time() - $sort_days * 86400) : '') . build_permission_sql($user->data['user_id'], false, 'b.') . ' GROUP BY b.user_id ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . $order_dir; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $users[] = $row; $blog_ids[] = $row['blog_id']; } $db->sql_freeresult($result); $total = sizeof($users); $last_blogs = array(); if (sizeof($blog_ids)) { $sql = 'SELECT * FROM ' . BLOGS_TABLE . ' WHERE ' . $db->sql_in_set('blog_id', $blog_ids); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $last_blogs[$row['blog_id']] = $row;