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; }
/** * 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; }
/** * 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; }
* Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 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 "); }
/** * 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; }
/** * 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; }
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; } }
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; }
/** * 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; }
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!"); } }