Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('params.inc.php');
- require 'fbbase.inc.php';
- class fbManager {
- const DEBUGFILE = 'debugf.txt';
- const FBPAGE = 'http://www.facebook.com/UnisampleDebug';
- //----------------------------------------------------------------
- const USERFQL ='select uid, username, first_name, middle_name, last_name,
- name, pic_small, pic_big, pic_square, pic, affiliations, profile_update_time,
- timezone, religion, birthday, birthday_date, devices, sex, hometown_location,
- meeting_sex, meeting_for, relationship_status, significant_other_id, political,
- current_location, activities, interests, is_app_user, music, tv, movies, books, quotes,
- about_me, notes_count, wall_count, status, online_presence, locale, proxied_email,
- profile_url, pic_small_with_logo, pic_big_with_logo, pic_square_with_logo, pic_with_logo,
- pic_cover, allowed_restrictions, verified, profile_blurb, family, website, is_blocked, contact_email,
- email, third_party_id, name_format, video_upload_limits, games, work, education, sports,
- favorite_athletes, favorite_teams, inspirational_people, languages, likes_count,
- friend_count, mutual_friend_count, can_post from user ';
- private $apigr_reqs = array("",
- "achievements","activities","albums","apprequests",
- "books","checkins","events","family",
- "friendrequests","friends","games","groups","interests","likes",
- "links","locations","movies",
- "music","notes",
- "photos","photos/uploaded","picture",
- "posts","questions","scores","sharedposts",
- "statuses","subscribedto","subscribers",
- "tagged","television","videos");
- private static $instance;
- public $db;
- public $debug_mode=false;
- public $debug_fname;
- public $debug_array=array();
- private $pgn=0;
- private $user=0;
- public $loginUrl='';
- public $logoutUrl='';
- //-----------------------------------------
- // debug mode on
- //-----------------------------------------
- public function debugOn() {
- $this->debug_mode = true;
- $zuu=explode('.',fbManager::DEBUGFILE);
- $this->debug_fname = array_shift($zuu).'_'.
- date('d_m_Y_H_i_s_').rand(100,300).'.'.array_shift($zuu);
- $_SESSION['debug_mode']=$this->debug_mode;
- $_SESSION['debug_fname']=$this->debug_fname;
- $this->dewr ('started');
- $_SESSION['pgn']=0;
- return 'debug mode switched on<br/>'.
- '<a href="'.$this->debug_fname.'" target="_blank">'.$this->debug_fname.'</a><br/>';
- }
- //-----------------------------------------
- // debug mode off
- //-----------------------------------------
- public function debugOff() {
- $this->debug_mode = false;
- $_SESSION['debug_mode'] = $this->debug_mode;
- return 'debug mode switched off<br/>';
- }
- //-----------------------------------------
- // switch debug mode
- //-----------------------------------------
- public function switchDebug() {
- if ($this->debug_mode) {
- return $this->debugOff();
- } else {
- return $this->debugOn();
- }
- }
- //-----------------------------------------
- // cleanup debug files
- //-----------------------------------------
- public function cleanUpDebug() {
- $s = '';
- $dir = opendir('.');
- while ($f=readdir($dir)) {
- if (preg_match('/^debugf.*?\.txt/i',$f)>0) {
- $s.=$f.'<br/>';
- unlink($f);
- }
- }
- closedir($dir);
- return 'deleted files:<br/>'.$s;
- }
- //-----------------------------------------
- // write debug information
- //-----------------------------------------
- private function dewr($s) {
- if (($this->debug_mode) && ($this->debug_fname)) {
- if (file_exists($this->debug_fname)) {
- $fh = fopen($this->debug_fname,'a');
- }
- else
- {
- $fh = fopen ($this->debug_fname,'w');
- }
- $cpath = pathinfo($_SERVER["PHP_SELF"]);
- $cname = $cpath['basename'];
- fwrite($fh, date('d.m.Y H:i:s ').$cname.' '.$s.' ('.$this->pgn.')'."\r\n\r\n");
- fclose($fh);
- //$this->debug_array[]=$s;
- }
- }
- //-------------------------------------------get instance
- public static function getInstance() {
- if (!self::$instance) {
- self::$instance = new fbManager();
- }
- return self::$instance;
- }
- //------------------------------------------init facebook object
- private function __construct() {
- if (isset($_SESSION['debug_fname']))
- $this->debug_fname = $_SESSION['debug_fname'];
- if (isset($_SESSION['debug_mode']))
- $this->debug_mode = $_SESSION['debug_mode'];
- if (isset($_SESSION['pgn'])) {
- $_SESSION['pgn']++;
- $this->pgn=$_SESSION['pgn'];
- }
- if (isset($_REQUEST["logoutapp"])) {
- unset($_SESSION['fb_'.APPID.'_access_token']);
- unset($_SESSION['fb_'.APPID.'_user_id']);
- }
- if (isset($_SESSION['fb_'.APPID.'_user_id']))
- $this->user = $_SESSION['fb_'.APPID.'_user_id'];
- else
- $this->user = $this->getUserAsync();
- $this->db = Baser::getInstance($this->user);
- $this->dewr('fbManager constructed');
- }
- //--------------------------------------------------------------
- // get urls
- //--------------------------------------------------------------
- public function getUrls() {
- $this->logoutUrl = $this->getLogoutUrlAsync();
- $this->loginUrl = $this->getLoginUrlAsync();
- }
- //--------------------------------------------------------------
- // direct calls to Baser methods
- //--------------------------------------------------------------
- public function __call($name, $arguments) {
- if (substr($name,0,3)=='db_') {
- $pname = substr($name,3);
- if (method_exists($this->db, $pname)) {
- $rez = call_user_func_array(array($this->db, $pname), $arguments);
- return $rez;
- }
- else {
- return 'error: unknown db method: '.$pname;
- }
- }
- else
- return 'error: unknown method: '.$name;
- }
- //--------------------------------------------connected
- public function connected() {
- return $this->user;
- }
- //-----------------------------------------register error
- private function saveError($e, $mtname, $args) {
- $s = 'Exception: '.$e->getType().':'.$e->getMessage()."\r\n";
- $s.= 'in method: '.$mtname."\r\n";
- $s.= 'arguments: '.implode(',',$args)."\r\n\r\n";
- return $s;
- }
- //--------------------------------------get login url async
- public function getUserAsync() {
- return $this->getAsync('', 'reqtype=user');
- }
- //--------------------------------------get login url async
- public function getLoginUrlAsync() {
- return $this->getAsync('http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"],
- 'reqtype=loginurl');
- }
- //--------------------------------------get logout url async
- public function getLogoutUrlAsync() {
- return $this->getAsync('http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"].'?logoutapp',
- 'reqtype=logouturl');
- }
- //--------------------------------------get GraphApi node async
- public function getNodeAsync($inf) {
- return $this->getAsync($inf, 'reqtype=apigraph');
- }
- //--------------------------------------get Fql async
- public function getFqlAsync($inf) {
- return $this->getAsync($inf, 'reqtype=fql');
- }
- //--------------------------------------get async query
- public function getAsync($inf, $reqt) {
- $cpath = pathinfo($_SERVER["PHP_SELF"]);
- $cdir = $cpath['dirname'];
- $url = 'http://'.$_SERVER["SERVER_NAME"].$cdir.'/async.php'.
- '?ajax&'.$reqt.'&req='.urlencode($inf);
- $this->dewr('start async curl: '.$url);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER,0);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($ch, CURLOPT_TIMEOUT,10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- if (isset($_COOKIE[session_name()]))
- curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.$_COOKIE[session_name()].'; path=/');
- session_write_close();
- $result = curl_exec($ch);
- if (curl_errno($ch)) {
- $inf = array();
- $inf['err'] = 'curl error: '.curl_error($ch).'<br/>'.$url;
- $this->dewr($inf['err']);
- curl_close($ch);
- return $inf;
- }
- $this->dewr('curl success');
- curl_close($ch);
- session_start();
- $inf = unserialize($result);
- return $inf;
- }
- //------------------------------------create structure for node
- public function createNodeTable($inf, $checkifexists=false) {
- $desc = $this->getNodeAsync($inf);
- echo $desc;
- if (isset($desc['err']))
- return $desc;
- $tabname = 'fb_'.array_pop(explode('/',$inf));
- $res = $this->db->createTable($desc, $tabname, $checkifexists );
- return $res;
- }
- //-------------------------------------create table for fql_query
- public function createFqlTable($fql, $checkifexists=false) {
- $desc = $this->getFqlAsync($fql);
- if (isset($desc['err']))
- return $desc;
- if (isset($desc[0]))
- $desc = $desc[0];
- $tname = trim(substr($fql, strpos($fql, 'from')+4));
- $tname = substr($tname,0, strpos($tname,' '));
- $tname='fql_'.$tname;
- $res = $this->db->createTable($desc, $tname, $checkifexists);
- return $res;
- }
- //-----------------------------------filling node table
- public function fillNodeTable($inf, $clear=true) {
- $desc = $this->getNodeAsync($inf);
- if (isset($desc['err']))
- return $desc;
- if (strpos($inf,'/')===false) {
- $usr = $inf;
- $tabname = 'fb_me';
- }
- else {
- $usr = substr($inf,0,strpos($inf,'/'));
- $tabname = 'fb_'.array_pop(explode('/',$inf));
- }
- $res = $this->db->fillTable($desc, $tabname, $clear, $usr);
- return $res;
- }
- //-----------------------------------fill fql table
- public function fillFqlTable($fql, $clear=true) {
- $desc = $this->getFqlAsync($fql);
- if (isset($desc['err']))
- return $desc;
- $tname = trim(substr($fql, strpos($fql,'from')+4));
- $tname = substr($tname, 0, strpos($tname,' '));
- $tname='fql_'.$tname;
- $res = $this->db->fillTable($desc, $tname, $clear);
- return $res;
- }
- //---------------------------------insert users into fql_user
- public function insertFqlUsers($filter) {
- $inf = $this->getFqlAsync(fbManager::USERFQL.$filter);
- if (isset($inf['err']))
- return $inf;
- $tname='fql_user';
- $this->dewr('filling fql_user table');
- $res = array();
- for ($i=0; $i<count($inf); $i++) {
- if (!$this->db->checkQuery("select * from $tname where fb_uid={$inf[$i]["uid"]}")) {
- $res = array_merge_recursive($res, $this->db->fillTable($inf[$i],$tname,false));
- }
- }
- $this->dewr('insertFqlUsers finished');
- return $res;
- }
- //-------------------------insert fb_likes ->fb_base_user_id into fql_users
- public function likesBasesToFqlUsers() {
- $usrs = $this->db->fetchQueryField(
- 'select fb_base_user_id from fb_likes group by fb_base_user_id',
- 'fb_base_user_id');
- if (isset($usrs['err']))
- return $usrs;
- $filt=' where uid in('.implode(',',$usrs).')';
- $rez = $this->insertFqlUsers($filt);
- return $rez;
- }
- //---------------------------------------------get user info
- public function getUserInfo($userid='') {
- $cuser = ($userid=='') ? $this->user : $userid;
- $info = $this->db->getQuery('select fb_name, fb_pic_square, fb_uid, fb_profile_url '.
- 'from fql_user where fb_uid=\''.$cuser.'\'');
- if (isset($info['err']))
- $info= $info['err'];
- return($info);
- }
- //---------------------------------------find Related Users
- public function findRelatedUsers() {
- $result = array();
- $result['inf']=$this->db->getQuery(
- 'select a.fb_name, a.fb_category, c.fb_name, c.fb_pic_square, '.
- 'c.fb_profile_url, c.fb_uid '.
- 'from fb_likes a, fbs_likes_users b, fql_user c '.
- 'where a.fb_base_user_id=b.fb_base_user_id '.
- ' '.
- 'and a.fb_id=b.fb_like_id and b.fb_reluser_id=c.fb_uid '.
- 'and a.fb_base_user_id=\''.$this->user.'\'');
- $result['likes']=$this->db->getQuery(
- 'select * from fb_likes where fb_base_user_id=\''.$this->user.'\'');
- $result['rel_users']=$this->db->getQuery(
- 'select * from fbs_likes_users where fb_base_user_id=\''.$this->user.'\'');
- return $result;
- }
- //-------------------------------------------------------------
- // draw related users page
- //-------------------------------------------------------------
- public function getAcceptors() {
- $result=$this->db->getQuery(
- 'select a.fb_base_user_id as user_id, b.fb_name as user_name,
- b.fb_pic_square as userpic from fbs_likes_users a, fql_user b
- where a.fb_base_user_id=b.fb_uid
- group by a.fb_base_user_id, b.fb_name, b.fb_pic_square');
- return $result;
- }
- //-------------------------------------------------------------
- // draw related users page
- //-------------------------------------------------------------
- public function drawRelatedUsers($userid, $altmode=false) {
- $userid = ($userid) ? $userid : $this->user;
- if (!$altmode) {
- $result=$this->db->getQuery(
- 'select a.fb_name as likename, a.fb_category as likecategory, '.
- 'c.fb_name as username, c.fb_pic_square as userpic, '.
- 'c.fb_profile_url as userurl, c.fb_uid as userid '.
- 'from fb_likes a, fbs_likes_users b, fql_user c '.
- 'where a.fb_base_user_id=b.fb_base_user_id '.
- ' '.
- 'and a.fb_id=b.fb_like_id and b.fb_reluser_id=c.fb_uid '.
- 'and a.fb_base_user_id=\''.$userid.'\'');
- } else {
- $result=$this->db->getQuery(
- 'select count(*) as lk_count, '.
- 'c.fb_name as username, c.fb_pic_square as userpic, '.
- 'c.fb_profile_url as userurl, c.fb_uid as userid, '.
- 'c.fb_sex as usersex, c.fb_locale as userlocale '.
- 'from fb_likes a, fbs_likes_users b, fql_user c '.
- 'where a.fb_base_user_id=b.fb_base_user_id '.
- ' '.
- 'and a.fb_id=b.fb_like_id and b.fb_reluser_id=c.fb_uid '.
- 'and a.fb_base_user_id=\''.$userid.'\''.
- ' group by c.fb_name, c.fb_pic_square, c.fb_profile_url, '.
- ' c.fb_uid, c.fb_sex, c.fb_locale');
- }
- if ($altmode) {
- if (isset($result['err']))
- $result = $result['err'];
- return $result;
- }
- $s = '<table><tr><td>like</td><td>username</td><td>userpic</td></tr>';
- foreach ($result as $el) {
- $s.= "<tr><td>{$el["likename"]}</td>".
- "<td>{$el["username"]}</td>".
- "<td><a href=\"{$el["userurl"]}\" target=\"_blank\">".
- "<img src=\"{$el["userpic"]}\" /></a></td></tr>";
- }
- $s.='</table>';
- return $s;
- }
- //---------------------------------------------------
- // halt on error
- //---------------------------------------------------
- private function halt($err, $header='<html><head></head>') {
- if (isset($err['err'])) {
- if (strpos($err['err'],'argument is empty')!==false)
- return;
- if (strpos($err['err'],'fb query returns empty result')!==false)
- return;
- if (strpos($err['err'],'Unsupported operation')!==false)
- return;
- echo $header;
- echo '<body><h3>error during operation</h3>';
- echo '<pre>'.print_r($err,true).'</pre></body></html>';
- exit();
- }
- }
- //---------------------------------------------------
- // download csv file
- //---------------------------------------------------
- public function downloadcsv() {
- $result=array();
- header('content-type:text/csv');
- header('content-disposition: attachment; filename=allinfo.csv');
- $f = fopen('php://output','w');
- $func = create_function('$a','return strtr($a,"\n\r\t"," ");');
- $fstr= array_fill(0,50,'fld');
- fputcsv($f, array_map($func,$fstr), "\t");
- foreach ($this->apigr_reqs as $str) {
- if ($str=='')
- $str='me';
- $zinf = array();
- $zinf[] = 'output '.$str;
- fputcsv($f, array_map($func,$zinf), "\t");
- $rez = @$this->db->getQuery('select b.fb_username, a.* from fb_'.$str.' a, fql_user b
- where a.fb_base_user_id=b.fb_uid');
- if (isset($rez['err']))
- continue;
- if (count($rez)==0)
- continue;
- $z = $rez[0];
- $headers = array_keys($z);
- fputcsv($f, array_map($func,$headers), "\t");
- foreach ($rez as $el) {
- $vals = array_values($el);
- fputcsv($f, array_map($func,$vals), "\t");
- }
- }
- fclose($f);
- }
- //---------------------------------------------------
- // create/fill all apigraph tables
- //---------------------------------------------------
- public function writeApiGraphTables() {
- $header = '<html><head><script type="text/javascript">
- setTimeout(function() {location.replace(
- location.protocol+"//"+location.host+location.pathname+
- location.search.replace("start","cont"));
- }, 1000);
- </script></head>';
- $header4 = '<html><head><script type="text/javascript">
- window.onload = function() {
- var el = document.createElement("DIV");
- document.body.appendChild(el);
- el.num=10;
- el.zz = setInterval(
- function() {
- el.innerHTML= "reload after "+el.num+" s";
- el.num--;
- if (el.num==0) {
- clearInterval(el.zz);
- location.replace(location.href);
- }
- }
- ,1000)
- }
- </script></head>';
- if (isset($_REQUEST['start']))
- $_SESSION['step']=1;
- switch ($_SESSION['step']) {
- //----------------------------------
- // step 1
- //----------------------------------
- case 1:
- $func = create_function('$el', 'return $el[\'user_id\'];');
- $z_acceptors = array_map($func,$this->getAcceptors());
- array_unshift($z_acceptors,"me");
- $_SESSION['z_acceptors']=$z_acceptors;
- $_SESSION['step']+=2;
- $_SESSION['step_ac']=0;
- $_SESSION['step_gr']=0;
- echo $header;
- echo '<body>step 1. getting acceptors</body></html>';
- break;
- //----------------------------------
- // step 3
- //----------------------------------
- case 3:
- $acceptor = $_SESSION['z_acceptors'][$_SESSION['step_ac']];
- $grnode = $this->apigr_reqs[$_SESSION['step_gr']];
- $rez = $this->fillNodeTable($acceptor.(($grnode=='')?'':'/').$grnode, true);
- $this->halt($rez, $header4);
- $tab = $this->db->drawTab('fb_'.(($grnode=='')?'me':array_pop(explode('/',$grnode))));
- //-------------------------------
- $_SESSION['step_gr']++;
- if ($_SESSION['step_gr']>= count($this->apigr_reqs)) {
- $_SESSION['step_gr']=0;
- $_SESSION['step_ac']++;
- if ($_SESSION['step_ac']>=count($_SESSION['z_acceptors'])) {
- $_SESSION['step']++;
- }
- }
- echo $header;
- echo "<body>step 3. filling apigraph tables<br/>
- step_ac = {$_SESSION['step_ac']} <br/>
- step_gr = {$_SESSION['step_gr']} <br/><br/>
- {$tab}
- </body></html>";
- break;
- //----------------------------------
- // step 4
- //----------------------------------
- case 4:
- echo '<html><head></head><body>operation finished</body></html>';
- break;
- }
- }
- //---------------------------------------------------
- // fill related users table
- //---------------------------------------------------
- public function writeRelatedUsers() {
- //header('content-type: text/html; charset=utf-8');
- //set_time_limit(0);
- //ob_implicit_flush(true);
- //$exc = 1/0;
- //@ini_set('zlib.output_compression',0);
- //@ini_set('implicit_flush',1);
- $this->dewr('start writeRelatedUsers');
- $header = '<html><head><script type="text/javascript">'.
- ''.
- 'setTimeout(function(){location.replace(location.href);},2000);'.
- '</script></head>';
- $header4 = '<html><head><script type="text/javascript">
- window.onload=function() {
- var inf = document.createElement(\'DIV\');
- inf.id=\'inf8\';
- document.body.appendChild(inf);
- inf.num=15;
- inf.zint = setInterval( function () {
- inf.innerHTML=\'reload after \'+inf.num+\' s\';
- inf.num--;
- if (inf.num==0) {
- clearInterval(inf.zint);
- location.replace(location.href);
- }}, 1000);
- }
- </script></head>';
- $lk_addr = <<<INF
- http://www.facebook.com/plugins/likebox.php?
- href=https%3A%2F%2Fwww.facebook.com%2F
- ##LIKEID##
- &width=200&height=6000&
- colorscheme=light&show_faces=true&border_color&
- stream=false
- INF;
- $lk_addr = str_replace(array(chr(10),chr(9),chr(32)), "", $lk_addr);
- $opts = array(
- 'http'=>array (
- 'method'=>'GET',
- 'header'=>"Accept: text/html\r\n".
- "User-Agent: Mozilla/5.0\r\n"));
- $context = stream_context_create($opts);
- //------------------------------
- function restruct($val, $key) {
- $z = $key;
- if ($val<4)
- return $z;
- }
- //------------------------------
- if (!isset($_SESSION["step"]))
- $_SESSION["step"]=1;
- //----------------------------------
- switch ($_SESSION["step"]) {
- //----------------------------------
- // step 1
- //----------------------------------
- case 1:
- //---------------------------
- $this->dewr('(step 1) start fill likes');
- $err = $this->fillNodeTable('me/likes');
- $this->halt($err);
- $err = $this->createFqlTable(fbManager::USERFQL.' where uid=me()', true);
- $this->halt($err);
- $like_ids = $this->db->fetchField('fb_likes','fb_id');
- $this->halt($like_ids);
- $_SESSION['like_ids']=$like_ids;
- $_SESSION['users_likes']=array();
- $_SESSION['step_ids']=0;
- $_SESSION['step']+=2;
- echo $header;
- echo $_SESSION['step'].'<br/>';
- echo '<body>Start processing...'.count($like_ids).' likes</body></html>';
- break;
- //----------------------------------------------
- // step 3
- //----------------------------------------------
- case 3:
- $like_ids = $_SESSION['like_ids'];
- //------------------------------
- $users_likes = $_SESSION['users_likes'];
- $j= $_SESSION['step_ids'];
- $this->dewr('(step 3) get widget for like objects :step_ids='.$j);
- //-----------------------------
- $lk_addr3 = str_replace('##LIKEID##', $like_ids[$j], $lk_addr);
- $users = array();
- for ($i=0; $i<3; $i++) {
- $inf = file_get_contents($lk_addr3, false, $context);
- preg_match_all('/<div[^>]*class=[\'"]grid_item[\'"][^>]*>'.
- '[^<]*<a[^>]*href=([\'"])([^\1>]*?)\1[^>]*>/ims', $inf, $out);
- $users = array_merge($users, $out[2]);
- }
- $users3 = array_count_values($users);
- $users4 = array_values(array_filter(array_map('restruct', $users3, array_keys($users3))));
- $users_like=array();
- $users_like['like']=$like_ids[$j];
- $users_like['users']=$users4;
- $users_likes[]=$users_like;
- $_SESSION["users_likes"]=$users_likes;
- $_SESSION['step_ids']++;
- if ($_SESSION['step_ids']==min(3000,count($like_ids)))
- $_SESSION['step']++;
- echo $header;
- echo '<body>iteration...'.$j.' like='.$like_ids[$j].'</body></html>';
- break;
- //----------------------------------------------
- // step 4
- //----------------------------------------------
- case 4:
- $this->dewr('(step 4) delete from fbs_likes_users');
- $insstr = $this->db->execQuery(
- 'delete from fbs_likes_users where fb_base_user_id=\''.$this->user.'\'');
- $this->halt($insstr);
- $users_likes=$_SESSION['users_likes'];
- $likes_users = array();
- $f = create_function('$el1,$el2',
- '$rez["like"]=$el1; $rez["user"]=$el2; return $rez;');
- foreach ($users_likes as $el) {
- $arr1= array_fill(0,count($el['users']),$el['like']);
- $likes_users=array_merge($likes_users, array_map($f, $arr1, $el['users']));
- }
- $_SESSION['step']++;
- $_SESSION['step_lu']=0;
- $_SESSION['likes_users']=$likes_users;
- echo $header;
- echo '<body>step 4, delete previous info<br/>'.
- '<pre>'.print_r($insstr,true).'</pre>'.
- '</body></html>';
- break;
- //----------------------------------------------
- // step 5
- //----------------------------------------------
- case 5:
- $this->dewr('(step 5) collect user information : step_lu='.$_SESSION['step_lu']);
- $likes_users = $_SESSION['likes_users'];
- $el = $likes_users[$_SESSION['step_lu']];
- $reluser = $el['user'];
- $reluser = substr(strrchr($reluser,'/'),1);
- $user_all = $this->getNodeAsync($reluser);
- $this->halt($user_all, $header4);
- $userid = $user_all['id'];
- $user_all3 = $this->insertFqlUsers(' where username ="'.$reluser.'"');
- //-------------------------------------
- if (isset($user_all3['err']))
- {
- //--------------------------ftg
- $_SESSION["errorsz"]++;
- echo $header4;
- echo '<body>error '.$_SESSION['errorsz'].'on step '.$_SESSION['step_lu'].'<br/>';
- echo '<pre>'.print_r($user_all3['err'],true).'</pre></body></html>';
- }
- else {
- $this->dewr('fill fbs_likes_users');
- $insstr=$this->db->execQuery(
- 'insert into fbs_likes_users(fb_base_user_id, fb_like_id, fb_reluser_id) '.
- ' values(\''.$this->user.'\',\''.$el['like'].'\',\''.$userid.'\')');
- $this->halt($insstr);
- //$out_fql_user = $this->db->drawTab('fql_user');
- $out_likes_users = $this->db->drawTab('fbs_likes_users');
- $_SESSION['step_lu']++;
- if ($_SESSION['step_lu']==min(8000, count($likes_users)))
- $_SESSION['step']++;
- $this->dewr('starting output');
- echo $header;
- echo '<body>current step: '.$_SESSION['step_lu'].'<br/>';
- //echo 'fql_user<br/>';
- //echo $out_fql_user.'<br/><br/>';
- echo 'fbs_likes_users<br/>';
- echo $out_likes_users.'</body></html>';
- $this->dewr('output finished');
- }
- break;
- //----------------------------------------------
- // step 6 ftg
- //----------------------------------------------
- case 6:
- echo '<h3>Information collected</h3>';
- $out_fql_user = $this->db->drawTab('fql_user');
- $out_likes_users = $this->db->drawTab('fbs_likes_users');
- echo 'fql_user<br/>';
- echo $out_fql_user.'<br/><br/>';
- echo 'fbs_likes_users<br/>';
- echo $out_likes_users;
- break;
- //---------------------------------------------------------
- }
- }
- //---------------------------------------------draw widget
- public function drawWidget($widget) {
- ob_start();
- //---------------------------------------
- // common part
- //---------------------------------------
- ?>
- <html xmlns:fb="http://ogp.me/ns/fb#">
- <head>
- <script type="text/javascript" src="jquery.min.js"></script>
- </head>
- <body>
- <div id="fb-root"></div>
- <script>
- (function(d, s, id) {
- //---------------------------------------------------
- // load all.js asynchronously
- //---------------------------------------------------
- var js;
- var fjs = d.getElementsByTagName(s)[0];
- if (d.getElementById(id))
- return;
- js = d.createElement(s);
- js.id = id;
- js.src = "//connect.facebook.net/ru_RU/all.js#xfbml=1&appId=<?php echo APPID;?>";
- fjs.parentNode.insertBefore(js, fjs);
- }(document, 'script', 'facebook-jssdk'));
- </script>
- <script type="text/javascript">
- //---------------------------------------------------
- // get widget iframe ref
- //---------------------------------------------------
- $(document).ready(
- setTimeout(
- function() {
- var ifr=$('.fb_iframe_widget iframe:first');
- $(ifr).parents('.fb_iframe_widget').before($('<div/>')
- .css('word-wrap','break-word')
- .html('<a href="'+ifr.get(0).src+
- '" target="_blank">'+ifr.get(0).src+'</a>'));
- },3000));
- </script>
- <?php
- //------------------------------------------
- // choose widget
- //------------------------------------------
- if (isset($_REQUEST["alt3"]))
- $targ = fbManager::FBPAGE;
- else
- $targ = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
- switch($widget) {
- //---------------------------
- case 'login_html5':
- echo '<div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1">';
- echo '</div>';
- break;
- //---------------------------
- case 'login_opengraph':
- echo '<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>';
- break;
- //---------------------------
- case 'activity_html5':
- echo '<div class="fb-activity"'.
- ' data-href="'.$targ.'"'.
- ' data-app-id="'.APPID.'"'.
- ' data-width="300" data-height="300" '.
- ' data-header="true" data-recommendations="false"></div>';
- break;
- //---------------------------
- case 'activity_opengraph':
- echo '<fb:activity '.
- ' href="'.$targ.'" '.
- ' app_id="'.APPID.'" '.
- ' width="300" height="300" header="true" recommendations="false"></fb:activity>';
- break;
- //---------------------------
- case 'activity_iframe':
- echo '<iframe '.
- 'src="//www.facebook.com'.
- '/plugins/activity.php'.
- '?href='.urlencode($targ).'&'.
- 'app_id='.APPID.'&'.
- 'action&width=300&height=300&header=true&'.
- 'colorscheme=light&linktarget=_blank&border_color&'.
- 'font&recommendations=false&'.
- 'appId='.APPID.'" scrolling="no" frameborder="0"'.
- ' style="border:none; overflow:hidden;'.
- ' width:300px; height:300px;" allowTransparency="true"></iframe>';
- break;
- //---------------------------
- case 'activity_link':
- $lnk = 'http://www.facebook.com/plugins/activity.php'.
- '?href='.urlencode($targ).'&'.
- 'app_id='.APPID.
- '&action&width=300&height=300&'.
- 'header=true&colorscheme=light&linktarget=_blank'.
- '&border_color&font&recommendations=false&appId='.APPID;
- echo "<a href=\"$lnk\" target=\"_blank\">$lnk</a>";
- break;
- //---------------------------
- case 'comments_html5':
- echo
- '<div class="fb-comments" '.
- ' data-href="'.$targ.'" '.
- ' data-num-posts="6" data-width="470"></div>';
- break;
- //---------------------------
- case 'comments_opengraph':
- echo '<fb:comments href="'.$targ.'"'.
- ' num_posts="6" width="470"></fb:comments>';
- break;
- //---------------------------
- case 'facepile_html5':
- echo '<div class="fb-facepile" '.
- 'data-href="'.$targ.'" '.
- 'data-size="large" data-max-rows="6" data-width="300"></div>';
- break;
- //---------------------------
- case 'facepile_opengraph':
- echo '<fb:facepile href="'.$targ.'" '.
- 'size="large" max_rows="6" width="300"></fb:facepile>';
- break;
- //---------------------------
- case 'facepile_iframe':
- echo '<iframe '.
- ' src="//www.facebook.com/plugins/facepile.php?'.
- 'href='.urlencode($targ).'&'.
- 'action&size=large&'.
- 'max_rows=6&width=300&'.
- 'colorscheme=light&appId='.APPID.
- '" scrolling="no" frameborder="0"'.
- ' style="border:none; overflow:hidden;'.
- ' width:300px;" allowTransparency="true"></iframe>';
- break;
- //---------------------------
- case 'facepile_link':
- $lnk = 'http://www.facebook.com/plugins/facepile.php?'.
- 'href='.urlencode($targ).
- '&action&size=large&max_rows=6&width=300'.
- '&colorscheme=light&appId='.APPID;
- echo "<a href=\"$lnk\" target=\"_blank\">$lnk</a>";
- break;
- //---------------------------
- case 'likebox_html5':
- echo '<div class="fb-like-box" '.
- 'data-href="'.$targ.'" '.
- 'data-width="292" data-height="700" '.
- 'data-show-faces="true" data-stream="true" '.
- 'data-header="true"></div>';
- break;
- //---------------------------
- case 'likebox_opengraph':
- echo '<fb:like-box '.
- 'href="'.$targ.'" '.
- 'width="292" height="700" show_faces="true"'.
- ' stream="true" header="true"></fb:like-box>';
- break;
- //---------------------------
- case 'likebox_iframe':
- echo
- '<iframe src="//www.facebook.com/plugins/likebox.php'.
- '?href='.urlencode($targ).
- '&width=292&height=590&'.
- 'colorscheme=light&show_faces=true&'.
- 'border_color&stream=true&'.
- 'header=true&appId='.APPID.'" '.
- 'scrolling="no" frameborder="0" '.
- 'style="border:none; overflow:hidden; '.
- 'width:292px; height:590px;" allowTransparency="true"></iframe>';
- break;
- //----------------------------
- case 'likebox_link':
- $lnk = 'http://www.facebook.com/plugins/likebox.php'.'
- ?href='.urlencode($targ).'&'.
- 'width=292&height=590&colorscheme=light&'.
- 'show_faces=true&border_color&stream=true'.'
- &header=true&appId='.APPID;
- echo "<a href=\"$lnk\" target=\"_blank\">$lnk</a>";
- break;
- //----------------------------
- case 'likebutton_html5':
- echo '<div class="fb-like" '.
- 'data-href="'.$targ.'" '.
- 'data-send="true" '.
- 'data-width="450" '.
- 'data-show-faces="true"></div>';
- break;
- //----------------------------
- case 'likebutton_opengraph':
- echo '<fb:like href="'.$targ.'" '.
- 'send="true" width="450" show_faces="true"></fb:like>';
- break;
- //----------------------------
- case 'recommendbar_html5':
- echo '<div class="fb-recommendations-bar" '.
- 'data-href="'.$targ.'"></div>';
- break;
- //----------------------------
- case 'recommendbar_opengraph':
- echo '<fb:recommendations-bar '.
- 'href="'.$targ.'"></fb:recommendations-bar>';
- break;
- //----------------------------
- case 'recommendbox_html5':
- echo '<div class="fb-recommendations" '.
- 'data-site="'.$targ.'" data-app-id="'.APPID.'" '.
- 'data-width="300" data-height="300" data-header="true"></div>';
- break;
- //----------------------------
- case 'recommendbox_opengraph':
- echo '<fb:recommendations site="'.$targ.'" '.
- 'app_id="'.APPID.'" '.
- 'width="300" height="300" header="true"></fb:recommendations>';
- break;
- //----------------------------
- case 'sendbutton_html5':
- echo '<div class="fb-send" data-href="'.$targ.'"></div>';
- break;
- //----------------------------
- case 'sendbutton_opengraph':
- echo '<fb:send href="'.$targ.'"></fb:send>';
- break;
- //----------------------------
- case 'sharedactivity_html5':
- echo '<div class="fb-shared-activity" data-width="300" '.
- 'data-height="300"></div>';
- break;
- //----------------------------
- case 'sharedactivity_opengraph':
- echo '<fb:shared-activity width="300" height="300">'.
- '</fb:shared-activity>';
- break;
- //----------------------------
- case 'subscribebutton_html5':
- echo '<div class="fb-subscribe" data-href="'.$targ.'" '.
- 'data-show-faces="true" data-width="450"></div>';
- break;
- }
- echo '</body></html>';
- $inf = ob_get_clean();
- return $inf;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement