Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
function render_activity($row, $use_inside_ocp = true)
{
    $guest_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    // Details of member
    $member_id = $row['a_member_id'];
    $memberpic = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id);
    $member_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id, false, $use_inside_ocp);
    $datetime = $row['a_time'];
    $message = new ocp_tempcode();
    $test = do_lang($row['a_language_string_code'], '{1}', '{2}', '{3}');
    // Convert our parameters and links to Tempcode
    $label = array();
    $link = array();
    for ($i = 1; $i <= 3; $i++) {
        $label[$i] = comcode_to_tempcode($row['a_label_' . strval($i)], $guest_id, false, NULL);
        $link[$i] = $row['a_pagelink_' . strval($i)] == '' ? new ocp_tempcode() : pagelink_to_tempcode($row['a_pagelink_' . strval($i)], !$use_inside_ocp);
        if ($row['a_pagelink_' . strval($i)] != '' && strpos($test, '{' . strval($i + 3) . '}') === false) {
            $label[$i] = hyperlink($link[$i], $label[$i]->evaluate());
        }
    }
    // Render primary language string
    $extra_lang_string_params = array($label[3], escape_html($link[1]->evaluate()), escape_html($link[2]->evaluate()), escape_html($link[3]->evaluate()));
    if (!is_null($row['a_also_involving'])) {
        $_username = $GLOBALS['FORUM_DRIVER']->get_username($row['a_also_involving']);
        $url = $GLOBALS['FORUM_DRIVER']->member_profile_url($row['a_also_involving'], false, $use_inside_ocp);
        $hyperlink = hyperlink($url, $_username, false, true);
        $extra_lang_string_params[] = static_evaluate_tempcode($hyperlink);
    } else {
        $extra_lang_string_params[] = do_lang('GUEST');
    }
    $message->attach(do_lang_tempcode($row['a_language_string_code'], $label[1], $label[2], $extra_lang_string_params));
    // Lang string may not use all params, so add extras on if were unused
    for ($i = 1; $i <= 3; $i++) {
        if (strpos($test, '{1}') === false && strpos($test, '{2}') === false && strpos($test, '{3}') === false && $row['a_label_' . strval($i)] != '') {
            if (!$message->is_empty()) {
                $message->attach(': ');
            }
            $message->attach($label[$i]->evaluate());
        }
    }
    return array($message, $memberpic, $datetime, $member_url, $row['a_language_string_code']);
}