Esempio n. 1
0
 public function setUp()
 {
     parent::setUp();
     $dbCon = RingsideApiDbDatabase::getConnection();
     $this->assertNotNull($dbCon);
     $this->m_fqlEngine = FQLEngine::getInstance($dbCon);
 }
Esempio n. 2
0
 public function execute()
 {
     $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
     $fqlEngine = FQLEngine::getInstance($dbCon);
     $result = null;
     try {
         //execute query
         $result = $fqlEngine->query($this->getAppId(), $this->getUserId(), $this->m_query);
     } catch (FQLException $exception) {
         throw new OpenFBAPIException($exception->getMessage(), FB_ERROR_CODE_DATABASE_ERROR);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * Constructing this class forces a user to login in on any page it is created on.
  * $uid sets the user the profile app will refer to.
  *
  * @param string $uid The user who's profile we are displaying
  * @param boolean $readOnly should be set if you are allowing a user to view but not edit the contents of the profile.
  * @param Object $restClient The client to use to populate this page
  */
 public function __construct($uid = -1, $readOnly = false, $restClient = null)
 {
     $this->ringside = new RingsideApiClients(RingsideSocialConfig::$apiKey, RingsideSocialConfig::$secretKey);
     $this->readOnly = $readOnly;
     if ($uid == -1) {
         $this->ringside->require_login();
         $this->uid = $this->ringside->get_loggedin_user();
     } else {
         $this->uid = $uid;
     }
     $this->database = RingsideApiDbDatabase::getDatabaseConnection();
     // remove this
     $this->restClient = $restClient;
 }
Esempio n. 4
0
 /**
  * Constructs a principal object
  *
  * @param int $uid
  * @param string $network_key
  * @param string $user_name
  * @return unknown
  */
 public static function getTrustAuthorities($tids = null)
 {
     $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
     $sql = 'SELECT * FROM ' . RS_TRUST_AUTHORITIES_TABLE;
     if (!empty($tids)) {
         $tid_list = array();
         foreach ($tids as $tid) {
             $tid_list[] = "'" . mysql_real_escape_string($tid) . "'";
         }
         $sql .= ' WHERE ' . RS_TRUST_AUTHORITIES_COL_TRUST_KEY . ' in (' . implode(',', $tid_list) . ')';
     }
     $result = mysql_query($sql, $dbCon);
     if (mysql_errno($dbCon) > 0) {
         throw new Exception(mysql_error(), mysql_errno());
     }
     $results = array();
     while ($row = mysql_fetch_assoc($result)) {
         $results[$row[RS_TRUST_AUTHORITIES_COL_TRUST_KEY]] = $row;
     }
     return $results;
 }
Esempio n. 5
0
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 ******************************************************************************/
include_once 'utils.php';
/**
 * Clean all the current data. 
 * 
 * @author Richard Friedman
 */
writeDatabaseInformation();
writeLine("<b>Cleaning up all the data.</b>");
$database = RingsideApiDbDatabase::getDatabaseConnection();
if ($database === false) {
    writeLine("No such database is currently available");
    RingsideApiDbDatabase::closeConnection($database);
} else {
    $schema = readSqlFile('RingsideDbCleanData.sql');
    if ($schema === false) {
        writeError(' The SQL could not be loade from the application ');
        exit;
    }
    $result = RingsideApiDbDatabase::queryMultiLine($schema, $database);
    if ($result === false) {
        writeError('The database was not cleaned properly, check the error log.');
    } else {
        writeLine("Database " . RingsideApiConfig::$db_name . " cleaned successfully ");
    }
}
writeLine();
writeLine("<b>Other options</b>");
writeLink("index.php", "Main Page");
writeLink("clean.php", "Clean Database");
 /**
  * Get's the auth token approval class for this trust
  *
  * @param int $trust_key
  * @return string
  */
 public static function getTrustAuthority($trust_key)
 {
     if (!isset($trust_key)) {
         return null;
     }
     $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
     $trust_key = mysql_real_escape_string($trust_key);
     $sql = "SELECT trust_key, trust_name, trust_auth_class, trust_auth_url FROM rs_trust_authorities WHERE trust_key='{$trust_key}'";
     $result = mysql_query($sql, $dbCon);
     if (mysql_errno($dbCon)) {
         throw new Exception(mysql_error(), mysql_errno());
     }
     $row = mysql_fetch_array($result);
     if ($row) {
         return $row;
     }
     return null;
 }
Esempio n. 7
0
     //application_getPublicInfo( $application_id = null, $application_canvas_name = null, $application_api_key = null)
     try {
         // If the app doesn't exist this method will throw an exception
         $client->api_client->application_getPublicInfo($app_id, null, null);
         $status = $client->api_client->users_isAppEnabled($uid, $app_id);
         include 'add_form.php';
     } catch (Exception $e) {
         if (FB_ERROR_CODE_NO_APP == $e->getCode()) {
             echo "<fb:error>\r\n            <fb:message>Application Does Not Exist</fb:message>\r\n            Application with Application ID {$app_id} does not exist on this Ringside instance!\r\n            </fb:error>";
         } else {
             echo "<fb:error>\r\n            <fb:message>Application Get Public Info Error</fb:message>\r\n            Application with Application ID {$app_id} threw the following error:" . $e->getMessage() . "</fb:error>";
         }
     }
 } else {
     if (isset($_GET['api_key'])) {
         $database = RingsideApiDbDatabase::getDatabaseConnection();
         $api_key = mysql_real_escape_string($_REQUEST['api_key']);
         $query = "SELECT app.id FROM app WHERE app.api_key='{$api_key}'";
         $result = mysql_query($query, $database);
         if (mysql_errno($database) || !$result) {
             $error = mysql_error($database);
             include 'add_empty.php';
         } else {
             if (mysql_num_rows($result) == 0) {
                 $error = 'No such application is registered here. ';
                 include 'add_empty.php';
             } else {
                 $row = mysql_fetch_assoc($result);
                 $app_id = $row['id'];
                 $result = $client->api_client->users_isAppAdded($uid, $app_id);
                 if ($result == 1) {
 /**
  * Constructs a subject from one or more principals
  *
  * @param array $pids the principal IDs
  * @param string $network_key the network key, typically the Social Key from another Ringside installation
  * @param string $trust_key the trust key
  * 
  * @return array the set of subjects in the network identified by the $network_key
  */
 public static function getSubjectForPrincipal($pids, $network_key, $app_id, $trust_key)
 {
     $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
     if (!isset($pids)) {
         error_log("getSubjectForPrincipal: Unable to get subject id, no principal id provided");
         return null;
     }
     if (!isset($app_id)) {
         error_log("getSubjectForPrincipal: Unable to get subject id, no app_id provided");
         return NULL;
     }
     if (!is_array($pids)) {
         $pids = array($pids);
     }
     $db_pids = array();
     foreach ($pids as $pid) {
         $db_pids[] = mysql_real_escape_string($pid);
     }
     if (!isset($network_key)) {
         $network_key = 'Ringside_Network';
     }
     $pid_list = implode(',', $db_pids);
     $network_key = mysql_real_escape_string($network_key);
     $app_id = mysql_real_escape_string($app_id);
     // TODO: Figure out if it is safe to ignore trust_key
     $sql = "SELECT id, principal_id, uid, network_key, user_name FROM principal_map\n\t\t\tWHERE principal_id in ({$pid_list}) AND network_key='{$network_key}' AND app_id = {$app_id}";
     $result = mysql_query($sql, $dbCon);
     if (mysql_errno($dbCon)) {
         throw new Exception(mysql_error(), mysql_errno());
     }
     $results = array();
     if (mysql_num_rows($result) != 0) {
         $row = mysql_fetch_array($result);
         while ($row) {
             $results[$row['principal_id']] = $row['uid'];
             $row = mysql_fetch_array($result);
         }
     }
     // Make sure we return the same number of output entries as we received
     $final_results = array();
     foreach ($pids as $pid) {
         $final_results[] = array_key_exists($pid, $results) ? $results[$pid] : null;
     }
     return $final_results;
 }
Esempio n. 9
0
function checkHasData()
{
    try {
        $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
        if ($dbCon === false) {
            return false;
        }
        $data = Api_Dao_App::getApplicationInfoByApiKey(RingsideWebConfig::$networkKey, RingsideSocialConfig::$apiKey, $dbCon);
        if ($data !== false) {
            return true;
        } else {
            return false;
        }
    } catch (Exception $exception) {
        return false;
    }
}
Esempio n. 10
0
 public static function getInfo($apiParams, $app_id, $uid)
 {
     $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
     $fqlEngine = FQLEngine::getInstance($dbCon);
     $fieldNames = explode(",", $apiParams["fields"]);
     if (array_search("uid", $fieldNames) === false) {
         $fieldNames[] = "uid";
     }
     $uids = explode(",", $apiParams["uids"]);
     //list of user hierarchies
     $result = null;
     try {
         //construct base FQL for queries
         $fql = "SELECT " . implode(",", $fieldNames) . " FROM user WHERE uid IN (" . implode(",", $uids) . ")";
         $result = $fqlEngine->query($app_id, $uid, $fql);
     } catch (FQLException $exception) {
         throw new OpenFBAPIException($exception->getMessage(), FB_ERROR_CODE_DATABASE_ERROR);
     }
     return $result;
 }
Esempio n. 11
0
/**
 * Authenticate a user.
 *
 * @param string $username
 * @param string $password
 * @return true if there were no errors and user was authenticated, error string if there was an error. 
 */
function authenticate($username, $password, $flavor)
{
    // Authenticate user.
    try {
        // TODO move to use PHP Auth?
        $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
        $userDb = new Api_Dao_User();
        $uid = $userDb->login($username, $password, $dbCon);
        return $uid;
    } catch (Exception $e) {
        $error = '';
        $code = $e->getCode();
        if ($code == NO_USER) {
            $error = "No User with User Name {$username} exists!<BR><a href=\"register.php\">Sign Up!</a>";
        } else {
            if ($code == BAD_PASSWORD) {
                $error = 'Invalid Password';
            } else {
                $error = $e->getMessage();
            }
        }
        loadForm($flavor, $error, $_REQUEST);
    }
    return false;
}
Esempio n. 12
0
 public static function updateApp($appId, $apiKey, $uid)
 {
     // TODO: DEPRECATE: Can't update API key or secret
     $sql = "UPDATE developer_app SET api_key='{$apiKey}' WHERE user_id={$uid} AND app_id={$appId}";
     $db = RingsideApiDbDatabase::getDatabaseConnection();
     try {
         if (!($result = mysql_query($sql, $db))) {
             throw new Exception("DB error: " . mysql_error() . "\nSQL='{$sql}'");
         }
     } catch (Exception $e) {
         throw new Exception("Unable to update data, API Key cannot be changed to that of another application!");
     }
 }