/** * Standard modular run function for RSS hooks. * * @param string A list of categories we accept from * @param TIME Cutoff time, before which we do not show results from * @param string Prefix that represents the template set we use * @set RSS_ ATOM_ * @param string The standard format of date to use for the syndication type represented in the prefix * @param integer The maximum number of entries to return, ordering by date * @return ?array A pair: The main syndication section, and a title (NULL: error) */ function run($_filters, $cutoff, $prefix, $date_string, $max) { require_lang('activities'); require_code('activities'); list(, $whereville) = find_activities(get_member(), $_filters == '' ? 'all' : 'some_members', $_filters == '' ? NULL : array_map('intval', explode(',', $_filters))); $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'activities WHERE (' . $whereville . ') AND a_time>' . strval($cutoff) . ' ORDER BY a_time DESC', $max, 0); $content = new ocp_tempcode(); foreach ($rows as $row) { $id = strval($row['id']); $author = $GLOBALS['FORUM_DRIVER']->get_username($row['a_member_id']); if (is_null($author)) { $author = do_lang('UNKNOWN'); } $news_date = date($date_string, $row['a_time']); $edit_date = ''; list($_title, ) = render_activity($row); $news_title = xmlentities($_title->evaluate()); $summary = xmlentities(''); $news = ''; $category = ''; $category_raw = ''; $view_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $row['a_member_id']), get_module_zone('members'), NULL, false, false, true); $if_comments = new ocp_tempcode(); $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date))); } return array($content, do_lang('ACTIVITIES_TITLE')); }
/** * 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; }
function _send($token, $secret, $row) { require_lang('twitter'); require_code('twitter'); list($message) = render_activity($row, false); $link = static_evaluate_tempcode(pagelink_to_tempcode($row['a_pagelink_1'])); // Shorten message for Twitter purposes $chopped_message = html_entity_decode(strip_tags($message->evaluate()), ENT_COMPAT, get_charset()); $max_length = 255; $shortened_link = mixed(); if ($link != '') { $shortened_link = http_download_file('http://is.gd/api.php?longurl=' . urlencode($link)); $max_length -= strlen($shortened_link) + 1; } if (strlen($chopped_message) > $max_length) { $chopped_message = substr($chopped_message, 0, $max_length - 3) . '...'; } if ($link != '') { $chopped_message .= ' ' . $shortened_link; } require_code('character_sets'); $chopped_message = convert_to_internal_encoding($chopped_message, get_charset(), 'utf-8'); require_code('developer_tools'); destrictify(); // Initiate Twitter connection $api_key = get_option('twitter_api_key'); $api_secret = get_option('twitter_api_secret'); $twitter = new Twitter($api_key, $api_secret); $twitter->setOAuthToken($token); $twitter->setOAuthTokenSecret($secret); // Send message try { $twitter->statusesUpdate($chopped_message); } catch (TwitterException $e) { attach_message($e->getMessage(), 'warn'); return false; } return true; }
function _send($token, $row, $post_to_uid = 'me', $member_id = NULL) { require_lang('facebook'); require_code('facebook_connect'); // Prepare message list($message) = render_activity($row, false); $name = $row['a_label_1']; require_code('character_sets'); $name = convert_to_internal_encoding($name, get_charset(), 'utf-8'); $link = $row['a_pagelink_1'] == '' ? '' : static_evaluate_tempcode(pagelink_to_tempcode($row['a_pagelink_1'])); $message = html_entity_decode(strip_tags($message->evaluate()), ENT_COMPAT, get_charset()); $message = convert_to_internal_encoding($message, get_charset(), 'utf-8'); // Send message $appid = get_option('facebook_appid'); $appsecret = get_option('facebook_secret_code'); $fb = new ocpFacebook(array('appId' => $appid, 'secret' => $appsecret)); $fb->setAccessToken($token); $attachment = array('description' => $message); if ($name != '' && $name != $message) { $attachment['name'] = $name; } if ($link != '') { $attachment['link'] = $link; } if (count($attachment) == 1) { $attachment = array('message' => $message); } if ($post_to_uid == 'me') { $post_to_uid = $fb->getUser(); } // May not be needed, but just in case try { $ret = $fb->api('/' . $post_to_uid . '/feed', 'POST', $attachment); } catch (Exception $e) { if (!is_null($member_id) && count($_POST) == 0) { $this->auth_set($member_id, get_self_url()); } warn_exit($e->getMessage()); } return true; }