/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('activities'); require_css('activities'); require_javascript('javascript_activities'); require_javascript('javascript_jquery'); require_javascript('javascript_base64'); if (!array_key_exists('max', $map)) { $map['max'] = '10'; } if (array_key_exists('param', $map)) { $title = $map['param']; } else { $title = do_lang_tempcode('ACTIVITIES_TITLE'); } // See if we're displaying for a specific member if (array_key_exists('member', $map)) { $member_ids = array_map('intval', explode(',', $map['member'])); } else { // No specific user. Use ourselves. $member_ids = array(get_member()); } require_css('side_blocks'); require_lang('activities'); require_code('activities'); require_code('addons_overview'); $mode = array_key_exists('mode', $map) ? $map['mode'] : 'all'; $viewer_id = get_member(); //We'll need this later anyway. $guest_id = $GLOBALS['FORUM_DRIVER']->get_guest_id(); list($proceed_selection, $whereville) = find_activities($viewer_id, $mode, $member_ids); $can_remove_others = has_zone_access($viewer_id, 'adminzone') ? true : false; $content = array(); global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'act_start'; $start = get_param_integer('act_start', 0); $max = get_param_integer('act_max', intval($map['max'])); if ($proceed_selection === true) { $max_rows = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'activities WHERE ' . $whereville); require_code('templates_results_browser'); $results_browser = results_browser(do_lang('ACTIVITIES_TITLE'), NULL, $start, 'act_start', $max, 'act_max', $max_rows, NULL, NULL, true, false, 7, NULL, 'tab__activities'); $activities = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'activities WHERE ' . $whereville . ' ORDER BY a_time DESC', $max, $start); if (!is_null($activities) && count($activities) > 0) { foreach ($activities as $row) { list($message, $memberpic, $datetime, $member_url, $lang_string) = render_activity($row); $content[] = array('LANG_STRING' => $lang_string, 'ADDON_ICON' => find_addon_icon($row['a_addon']), 'BITS' => $message, 'MEMPIC' => $memberpic, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($row['a_member_id']), 'DATETIME' => strval($datetime), 'MEMBER_URL' => $member_url, 'LIID' => strval($row['id']), 'ALLOW_REMOVE' => $row['a_member_id'] == $viewer_id || $can_remove_others ? '1' : '0'); } } } else { $results_browser = new ocp_tempcode(); } // No entries return do_template('BLOCK_MAIN_ACTIVITIES', array('TITLE' => $title, 'MODE' => $mode, 'MEMBER_IDS' => implode(',', $member_ids), 'CONTENT' => $content, 'GROW' => array_key_exists('grow', $map) ? $map['grow'] == '1' : true, 'RESULTS_BROWSER' => $results_browser, 'MAX' => $start == 0 ? strval($max) : NULL)); }
function activities_ajax_update_list_handler() { $map = array(); $map['max'] = $GLOBALS['SITE_DB']->query_value_null_ok('values', 'the_value', array('the_name' => get_zone_name() . "_" . get_page_name() . "_update_max")); if (is_null($map['max'])) { $map['max'] = '10'; } $last_id = post_param('lastid', '-1'); $mode = post_param('mode', 'all'); //require_css('side_blocks'); require_lang('activities'); require_code('activities'); require_code('addons_overview'); $proceed_selection = true; //There are some cases in which even glancing at the database is a waste of precious time. $guest_id = intval($GLOBALS['FORUM_DRIVER']->get_guest_id()); $viewer_id = intval(get_member()); //We'll need this later anyway. $can_remove_others = has_zone_access($viewer_id, 'adminzone') ? true : false; //Getting the member viewed ids if available, member viewing if not $member_ids = array_map('intval', explode(',', post_param('member_ids', strval($viewer_id)))); list($proceed_selection, $whereville) = find_activities($viewer_id, $mode, $member_ids); header("Content-Type: text/xml"); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past $response = '<' . '?xml version="1.0" encoding="' . get_charset() . '" ?' . '>'; $can_remove_others = has_zone_access($viewer_id, 'adminzone') ? true : false; if ($proceed_selection === true) { $activities = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'activities WHERE ((' . $whereville . ') AND id>' . ($last_id == '' ? '-1' : $last_id) . ') ORDER BY a_time DESC', intval($map['max'])); if (count($activities) > 0) { $list_items = ''; foreach ($activities as $row) { list($message, $memberpic, $datetime, $member_url) = render_activity($row); $list_item = do_template('BLOCK_MAIN_ACTIVITIES_XML', array('ADDON_ICON' => find_addon_icon($row['a_addon']), 'BITS' => $message, 'MEMPIC' => $memberpic, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($row['a_member_id']), 'DATETIME' => strval($datetime), 'MEMBER_URL' => $member_url, 'LIID' => strval($row['id']), 'ALLOW_REMOVE' => $row['a_member_id'] == $viewer_id || $can_remove_others)); // We dump our response in CDATA, since that lets us work around the // fact that our list elements aren't actually in a list, etc. // However, we allow comcode but some tags make use of CDATA. Since // CDATA can't be nested (as it's a form of comment), we take this // into account by base64 encoding the whole template and decoding // it in the browser. We wrap it in some arbitrary XML and a CDATA // tag so that the Javascript knows what it's received $list_items .= '<listitem id="' . strval($row['id']) . '"><![CDATA[' . base64_encode($list_item->evaluate()) . ']]></listitem>'; } $response .= '<response><success>1</success><feedlen>' . $map['max'] . '</feedlen><content>' . $list_items . '</content><supp>' . escape_html($whereville) . '</supp></response>'; } else { $response .= '<response><success>2</success><content>NU - Nothing new.</content></response>'; } } else { $response .= '<response><success>2</success><content>NU - No feeds to select from.</content></response>'; } echo $response; }