Ejemplo n.º 1
0
 /**
  * Enter description here...
  *
  * @param unknown_type $loggedInUser
  * @param unknown_type $uid
  * @param unknown_type $pageId
  * @return unknown
  */
 public static function isFan($loggedInUser, $uid, $pageId)
 {
     if (Api_Dao_Friends::friendCheck($loggedInUser, $uid) === false) {
         throw new OpenFBAPIException(FB_ERROR_MSG_ISFAN_NOTFRIENDS, FB_ERROR_CODE_ISFAN_NOTFRIENDS);
     }
     return Api_Dao_Pages::isFan($pageId, $uid);
 }
Ejemplo n.º 2
0
 /**
  * Sends an email notification
  *
  * @param Array $toids
  * @param Array $uid
  * @param string $notification
  */
 public static function sendNotification($toids, $uid, $subject, $notification, $isEmail)
 {
     if ($toids == null) {
         $mailid = Api_Dao_Notification::createMail($uid, $subject);
         Api_Dao_Notification::addUserToMail($mailid, $uid);
         Api_Dao_Notification::addMessage($mailid, $uid, $notification, $isEmail);
     } else {
         $getFriends = Api_Dao_Friends::friendsGetFriends($uid);
         $sendFriends = array_intersect($toids, $getFriends);
         if (count($sendFriends) > 0) {
             $mailid = Api_Dao_Notification::createMail($uid, $subject);
             // If uid sends email to others, are they really in the thread yet?  only when response exists?
             foreach ($sendFriends as $friend) {
                 Api_Dao_Notification::addUserToMail($mailid, $friend);
             }
             Api_Dao_Notification::addMessage($mailid, $uid, $notification, 0);
         }
     }
 }
Ejemplo n.º 3
0
 public function retrieveFields($engine, $parsedStatement, $vars = array())
 {
     $rootObj = parent::retrieveFields($engine, $parsedStatement, $vars);
     //get friend list
     $userId = $vars['USER_ID'];
     $friendList = Api_Dao_Friends::friendsGetFriends($userId, $engine->getDbConnection());
     //filter out un-viewable parameters for non-friends
     $allowedFields = array('first_name', 'last_name', 'pic_small', 'uid');
     foreach ($rootObj['user'] as $indx => $userProps) {
         $uid = $userProps['uid'];
         if (!in_array($uid, $friendList) && $uid != $userId) {
             foreach ($userProps as $fld => $val) {
                 if (!in_array($fld, $allowedFields)) {
                     $rootObj['user'][$indx][$fld] = null;
                 }
             }
         }
     }
     return $rootObj;
 }
 public function sendNotifications($app_id, $from, $to, $subject, $body, $cc = null, $bcc = null, $attachments = null)
 {
     if (!is_array($to)) {
         $to = array();
     }
     $getFriends = Api_Dao_Friends::friendsGetFriends($from->id);
     $toids = array();
     foreach ($to as $to_user) {
         $toids[] = $to->id;
     }
     $sendFriends = array_intersect($toids, $getFriends);
     if (count($sendFriends) > 0) {
         $mailid = Api_Dao_Notification::createMail($uid, $subject);
         // If uid sends email to others, are they really in the thread yet?  only when response exists?
         foreach ($sendFriends as $friend) {
             Api_Dao_Notification::addUserToMail($mailid, $friend);
         }
         Api_Dao_Notification::addMessage($mailid, $uid, $notification, 0);
     }
 }
Ejemplo n.º 5
0
 public function retrieveFields($engine, $parsedStatement, $vars = array())
 {
     $fieldNames = $parsedStatement->getSelectFields();
     $whereTokens = $parsedStatement->getWhereFields();
     //verify SELECT
     if (count($fieldNames) != 1 || !(in_array("uid1", $fieldNames) xor in_array("uid2", $fieldNames))) {
         throw new FQLException("Only 'uid1' or 'uid2' can be selected from the friend table.");
     }
     $uidFieldName = $fieldNames[0];
     //verify WHERE
     $uidStr = $this->getUidStringFromWhere($whereTokens);
     //restrict to friends of $uid
     $uid = $vars["USER_ID"];
     // RXF - Commented out and using DAO layer.
     //  	$fg = new FriendsGet($uid, array("uid" => $uid));
     //  	$resp = $fg->execute();
     //  	$ulist = $resp["uid"];
     // RXF - Using the DAO to get list of friends.
     $ulist = Api_Dao_Friends::friendsGetFriends($uid);
     $esqlFrom = "";
     $esqlTo = "";
     if (is_array($ulist) && count($ulist) > 0) {
         $esqlFrom .= " AND from_id IN ({$uid}," . implode(",", $ulist) . ")";
         $esqlTo .= " AND to_id IN ({$uid}," . implode(",", $ulist) . ")";
     }
     $sql = "SELECT to_id AS uid FROM friends WHERE from_id {$uidStr} {$esqlFrom}" . "UNION SELECT from_id AS uid FROM friends WHERE to_id {$uidStr} {$esqlTo}";
     //print "\nfriendSQL='$sql'\n";
     $ds = mysql_query($sql, $engine->getDbConnection());
     if (!$ds) {
         throw new FQLException("Could not execute mapped FQL->SQL query: " . mysql_error() . "\nSQL='{$sql}'");
     }
     //construct response
     $obj = array();
     $obj["friend_info"] = array();
     while ($row = mysql_fetch_assoc($ds)) {
         $obj["friend_info"][] = array($uidFieldName => $row["uid"]);
     }
     return $obj;
 }
Ejemplo n.º 6
0
 /**
  * Enter description here...
  *
  * @param unknown_type $uid
  * @param unknown_type $appId
  * @param unknown_type $type
  * @param unknown_type $templatized
  * @param unknown_type $author
  * @param unknown_type $title
  * @param unknown_type $body
  * @param unknown_type $image1
  * @param unknown_type $image1Link
  * @param unknown_type $image2
  * @param unknown_type $image2Link
  * @param unknown_type $image3
  * @param unknown_type $image3Link
  * @param unknown_type $image4
  * @param unknown_type $image4Link
  * @param unknown_type $titleData
  * @param unknown_type $bodyData
  * @param unknown_type $bodyGeneral
  * @param unknown_type $priority
  * @param unknown_type $targets
  * @param unknown_type $actor
  * @return unknown
  */
 public static function createTemplatizedFeed($uid, $appId, $type, $templatized, $author, $title, $body, $image1, $image1Link, $image2, $image2Link, $image3, $image3Link, $image4, $image4Link, $titleData, $bodyData, $bodyGeneral, $priority, $targets, $actor)
 {
     if (null == $priority || strlen($priority) == 0) {
         $priority = 0;
     }
     if ($actor == null) {
         $actor = $uid;
     } else {
         // The ACTOR must be (a) friend (b) have app
         if (!Api_Dao_Friends::friendCheck($uid, $actor)) {
             throw new Exception(FB_ERROR_MSG_ACTOR_USER_NOT_FRIENDS, FB_ERROR_CODE_REQUIRES_PERMISSION);
         }
         if (!Api_Dao_UsersApp::isUsersApp($appId, $actor)) {
             throw new Exception(FB_ERROR_MSG_ACTOR_USER_DONT_SHAREAPPS, FB_ERROR_CODE_REQUIRES_PERMISSION);
         }
     }
     if ($targets != null) {
         // All targets must be frinds of acting user.
         $friends = Api_Dao_Friends::friendsGetFriends($actor);
         $targets = explode(",", $targets);
         $intersect = array_intersect($friends, $targets);
         if (count($targets) != count($intersect)) {
             throw new Exception(FB_ERROR_MSG_TARGETS_NOT_FRIENDS, FB_ERROR_CODE_REQUIRES_PERMISSION);
         }
     }
     // Validate title data, actor token must exist.
     $titleTokens = self::get_tokens($title);
     //		error_log( 'title tokens: ' . var_export( $titleTokens, true ) );
     $countTest = 1;
     if (!in_array("actor", $titleTokens)) {
         throw new Exception(FB_ERROR_MSG_FEED_MISSING_ACTOR, FB_ERROR_CODE_FEED_TITLE_PARAMS);
     }
     if (in_array("target", $titleTokens)) {
         if ($targets == null) {
             throw new Exception(FB_ERROR_MSG_FEED_MISSING_TARGETS, FB_ERROR_CODE_FEED_TITLE_PARAMS);
         }
         $countTest = 2;
     }
     if (count($titleTokens) > $countTest) {
         if ($titleData == null || empty($titleData)) {
             throw new Exception(FB_ERROR_MSG_FEED_TITLE_JSON_EMPTY, FB_ERROR_CODE_FEED_TITLE_JSON);
         }
         // check all tokens in string are in data
         $titleDataTokens = json_decode($titleData, true);
         //			error_log( 'title data tokens: ' . var_export( $titleDataTokens, true ) );
         if (array_key_exists('actor', $titleDataTokens) || array_key_exists('target', $titleDataTokens)) {
             throw new Exception(FB_ERROR_MSG_FEED_TITLE_JSON_INVALID, FB_ERROR_CODE_FEED_TITLE_JSON);
         }
         foreach ($titleTokens as $token) {
             //				error_log( 'title token: ' . $token );
             if ($token != 'target' && $token != 'actor' && !array_key_exists($token, $titleDataTokens)) {
                 throw new Exception(FB_ERROR_MSG_FEED_MISSING_PARAMS, FB_ERROR_CODE_FEED_TITLE_PARAMS);
             }
         }
     } else {
         $titleData = null;
     }
     // Validate body data
     $bodyTokens = self::get_tokens($body);
     $countTest = 0;
     if (in_array("actor", $bodyTokens)) {
         $countTest++;
     }
     if (in_array("target", $bodyTokens)) {
         if ($targets == null) {
             throw new Exception(FB_ERROR_MSG_FEED_BODY_MISSING_TARGETS, FB_ERROR_CODE_FEED_BODY_PARAMS);
         }
         $countTest++;
     }
     if (count($bodyTokens) > $countTest) {
         if ($bodyData == null || empty($bodyData)) {
             throw new Exception(FB_ERROR_MSG_FEED_BODY_JSON_EMPTY, FB_ERROR_CODE_FEED_BODY_JSON);
         }
         $bodyDataTokens = json_decode($bodyData, true);
         if (array_key_exists('actor', $bodyDataTokens) || array_key_exists('target', $bodyDataTokens)) {
             throw new Exception(FB_ERROR_MSG_FEED_BODY_JSON_INVALID, FB_ERROR_CODE_FEED_BODY_JSON);
         }
         foreach ($bodyTokens as $token) {
             if ($token != 'target' && $token != 'actor' && !array_key_exists($token, $bodyDataTokens)) {
                 throw new Exception(FB_ERROR_MSG_FEED_BODY_MISSING_PARAMS, FB_ERROR_CODE_FEED_BODY_PARAMS);
             }
         }
     } else {
         $bodyData = null;
     }
     return Api_Dao_Feed::createFeed($type, $templatized, $title, $titleData, $body, $bodyData, $bodyGeneral, $author, $image1, $image1Link, $image2, $image2Link, $image3, $image3Link, $image4, $image4Link, $actor, $targets, $priority);
 }
Ejemplo n.º 7
0
 /**
  * Enter description here...
  *
  * @param unknown_type $uid
  * @param unknown_type $fuid
  * @param unknown_type $status
  * @param unknown_type $access
  */
 public static function acceptInvite($uid, $fuid, $status, $access)
 {
     Api_Dao_Friends::acceptInvite($uid, $fuid, $status, $access);
 }