public function stream_publish_vo($campaign_name, $attachment = null, $action_links = null, $target_id = null, $uid = null, $msg_data_array = null, $page_data_array = null)
 {
     $msg_info_array = $this->m_an->m_ab_testing_mgr->get_selected_msg_info($campaign_name, $msg_data_array);
     $page_info = $this->m_an->m_ab_testing_mgr->get_selected_page_info($campaign_name, $page_data_array);
     $msg_id = $msg_info_array[0];
     $msg_text = $msg_info_array[2];
     $st1 = $this->m_an->format_kt_st1($campaign_name);
     $st2 = $this->m_an->format_kt_st2($msg_id);
     $st3 = $this->m_an->format_kt_st3($page_info[0]);
     $msg_action = json_decode($action_links);
     $msg_attachment = json_decode($attachment);
     $uuid = $this->m_an->gen_stream_link($msg_action, null, $st1, $st2, $st3);
     $this->m_an->gen_stream_link($msg_attachment, $uuid, $st1, $st2, $st3);
     $msg_action = json_encode($msg_action);
     $msg_attachment = json_encode($msg_attachment);
     $r = parent::stream_publish($msg_text, $msg_attachment, $msg_action, $target_id, $uid);
     if (!empty($r)) {
         $this->m_an->kt_stream_send($uuid, $st1, $st2, $st3);
     }
     return $r;
 }
예제 #2
0
function fbapp_mod_blog_post_publish($blog_id, $id, $title)
{
    global $ssc_site_url, $ssc_database, $ssc_site_path;
    require_once 'facebook.php';
    $api_key = "9c476aaa4b1654c09ede303a7d140a36";
    $secret_key = ssc_var_get('fbapp_blog_secret', '');
    if ($secret_key == '') {
        ssc_add_message(SSC_MSG_CRIT, "Facebook user secret key has not been set up yet!");
        return;
    }
    $session_key = ssc_var_get('fbapp_blog_session', '');
    if ($session_key == '') {
        ssc_add_message(SSC_MSG_CRIT, "Facebook user session key has not been set yet!");
        return;
    }
    $client = new FacebookRestClient($api_key, $secret_key, $session_key);
    if (!$client->users_getLoggedInUser()) {
        ssc_add_message(SSC_MSG_CRIT, "Unable to get userid");
        return;
    }
    $dbres = $ssc_database->query("SELECT body FROM #__blog_post WHERE id = %d LIMIT 1", $id);
    if (!$dbres) {
        ssc_add_message(SSC_MSG_CRIT, "Unable to retrieve posted item from database?!");
        return;
    }
    if (!($data = $ssc_database->fetch_assoc($dbres))) {
        ssc_add_message(SSC_MSG_CRIT, "Unable to retrieve posted item from database?!");
        return;
    }
    $img = null;
    // Extract the first image
    $i = strpos($data['body'], '[[img');
    if ($i !== false) {
        // Some basic error checking for a valid tag
        $j = strpos($data['body'], ']]', $i);
        $k = strpos($data['body'], '[[', $i + 3);
        if ($j !== false && ($j < $k || $k === FALSE)) {
            $path = explode("|", substr($data['body'], $i, $j - $i));
            if (count($path) > 1) {
                $path = $path[1];
                // Now match it up to the right path
                if (strpos($path, "://") === false) {
                    if ($path[0] == "/") {
                        $path = substr($path, 1);
                    }
                    // Relative path
                    if (file_exists($ssc_site_path . "/images/{$path}.jpg") || file_exists($ssc_site_path . "/images/{$path}.png") || file_exists($ssc_site_path . "/images/{$path}")) {
                        // Default to image directory base-dir
                        $img = $ssc_site_url . "/images/{$path}";
                    } elseif (file_exists($ssc_site_path . "/{$path}") || file_exists($ssc_site_path . "/{$path}.jpg") || file_exists($ssc_site_path . "/{$path}.png")) {
                        // Relative to site root instead
                        $img = $ssc_site_url . '/' . $path;
                    }
                }
            }
        }
    }
    // Hackish - TODO later for multiple blog paths, non-root based
    $uri = $ssc_site_url . "/id/{$id}";
    //$result = $client->feed_publishUserAction(30881549425, array("title"=>$title, "uri"=>$uri), '', '', 2);
    $attachment = array('name' => $title, 'href' => $uri, 'caption' => 'A blog post has just been made');
    if ($img != null) {
        $attachment['media'] = array(array('type' => 'image', 'src' => $img, 'href' => $uri));
    }
    $action_links = array(array('text' => 'Read this post', 'href' => $uri));
    $target_id = null;
    //array();
    $uid = null;
    $result = $client->stream_publish(" has been blogging", $attachment, $action_links, $target_id, $uid);
    if ($result) {
        ssc_var_set('fbapp_blog_lastid', $id);
    } else {
        ssc_add_message("Unable to post to FB");
    }
}