public function __construct($file_info)
 {
     if (is_array($file_info)) {
         $r = $file_info;
     } else {
         if (preg_match("|pa://(\\d+)|", $file_info, $m)) {
             $file_id = (int) $m[1];
         } else {
             $file_id = (int) $file_info;
         }
         if (!$file_id) {
             throw new PAException(INVALID_ID, "Invalid file ID: {$file_info}");
         }
         $r = Dal::query_one_assoc("SELECT * FROM files WHERE file_id=?", array($file_id));
         if (empty($r)) {
             throw new PAException(FILE_NOT_FOUND, "File {$file_id} not found");
         }
     }
     if ($r['incomplete']) {
         throw new PAException(FILE_NOT_FOUND, "File {$file_id} is incomplete and should not be accessed");
     }
     foreach ($r as $k => $v) {
         $this->{$k} = $v;
     }
 }
 function load($review_id)
 {
     $row = Dal::query_one_assoc("SELECT * FROM {reviews} WHERE review_id=?", array($review_id));
     if (empty($row)) {
         throw new PAException(CONTENT_NOT_FOUND, "Could not find review id {$review_id}");
     }
     $this->load_from_row($row);
 }
 function load($comment_id)
 {
     $row = Dal::query_one_assoc("SELECT * FROM {comments2} WHERE comment_id=?", array($comment_id));
     if (empty($row)) {
         throw new PAException(CONTENT_NOT_FOUND, "Could not find comment id {$comment_id}");
     }
     $this->load_from_row($row);
 }
Exemple #4
0
 public static function find_by_subject($subject_type, $subject_id)
 {
     // cached already?  this is important as we often have several modules referencing the same item
     $cache_key = "item:{$subject_type}:{$subject_id}";
     $item = Cache::getValue($cache_key);
     if (!empty($item)) {
         return $item;
     }
     $r = Dal::query_one_assoc("SELECT * FROM {items} WHERE subject_type=? AND subject_id=?", array($subject_type, $subject_id));
     if (!$r) {
         return NULL;
     }
     $item = new Item();
     $item->load_from_row($r);
     Cache::setValue($cache_key, $item);
     return $item;
 }
 public function __construct($host, $noisy = FALSE)
 {
     if (!trim($host)) {
         throw new PAException(BAD_PARAMETER, "Invalid host");
     }
     $dom = Dal::query_one_assoc("SELECT * FROM spam_domains WHERE domain=?", array($host));
     if ($dom) {
         // exists
         foreach ($dom as $k => $v) {
             $this->{$k} = $v;
         }
     } else {
         // need to create it
         $this->domain = $host;
         $this->count = $this->blacklisted = $this->whitelisted = 0;
         if ($noisy) {
             echo "Querying blacklists for {$host}:";
         }
         foreach (array("multi.uribl.com", "multi.surbl.org") as $bl) {
             if ($noisy) {
                 echo " {$bl}";
             }
             if (gethostbyname("{$host}.{$bl}") != "{$host}.{$bl}") {
                 $this->blacklisted = DOMAIN_BLACKLISTED_AUTOMATICALLY;
                 if ($noisy) {
                     echo " BLACKLISTED!";
                 }
                 break;
             }
         }
         if ($noisy) {
             echo "\n";
         }
         Dal::query("INSERT INTO spam_domains SET domain=?, blacklisted=?", array($this->domain, $this->blacklisted));
         $this->id = Dal::insert_id();
     }
 }
 /**
  *  Function : get_members_by_type()
  *  Purpose  : get members of the network based on the parameters passed to it
  *  @param    $params - array - the various elements of this array may be defined
  *            as follows
  *            $params['cnt']=>TRUE - if we want to get count
  *            $params['network_id']=>2 - get members of network having id 2
  *            $params['sort_by']=> 'U.created' - column name
  *            $params['direction']=> DESC - order by clause
  *            $params['page']=> 2 - page number 2
  *            $params['show']=> 5 - show 5 records
  *  @return   type array
  *            returns array of members of n/w
  */
 public static function get_members_by_type($params)
 {
     Logger::log("[ Enter: function Network::get_members_by_type] \n");
     $data = array();
     $sql = "SELECT NU.user_id, NU.network_id, NU.user_type, U.*\n            FROM {networks_users} AS NU, {users} AS U\n            WHERE NU.network_id = ?\n            AND NU.user_id = U.user_id\n            AND U.is_active <> ? AND U.is_active <> ? AND NU.user_type = ? ";
     //count query to find total members
     $sql_count = "SELECT count(*) AS CNT\n                  FROM {networks_users} AS NU, {users} AS U\n                  WHERE NU.network_id = ?\n                  AND NU.user_id = U.user_id\n                  AND U.is_active <> ? AND U.is_active <> ? AND NU. user_type = ? ";
     array_push($data, $params['network_id'], DELETED, UNVERIFIED, $params['user_type']);
     // get only active members
     //we dont want the owner of the network to come in listing
     // if we are intersted in getting total records only then return count
     if (!empty($params['cnt']) && $params['cnt'] == TRUE) {
         $cnt = Dal::query_one_assoc($sql_count, $data);
         Logger::log("[ Enter: function Network::get_members_by_type returning count] \n");
         return $cnt['CNT'];
     }
     // OK we want to find the details
     $sort_by = !empty($params['sort_by']) ? $params['sort_by'] : 'U.created';
     $direction = !empty($params['direction']) ? $params['direction'] : 'DESC';
     $order_by = ' ORDER BY ' . $sort_by . ' ' . $direction;
     if (!empty($params['page']) && !empty($params['show'])) {
         $start = ($params['page'] - 1) * $params['show'];
         $limit = ' LIMIT ' . $start . ',' . $params['show'];
     } else {
         $limit = "";
     }
     $sql = $sql . $order_by . $limit;
     $res = Dal::query($sql, $data);
     $users_data = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $users_data[] = $row;
     }
     if (empty($users_data)) {
         return NULL;
     }
     $final_array = array('users_data' => $users_data, 'total_users' => count($users_data));
     Logger::log("[ Exit: function Network::get_members_by_type] \n");
     return $final_array;
 }
 public static function get_relation_record($user_id, $relation_id)
 {
     $rel = Dal::query_one_assoc("SELECT * FROM {relations} WHERE user_id=? AND " . (is_numeric($relation_id) ? 'relation_id' : 'profile_url') . "=?", array($user_id, $relation_id));
     if (!$rel) {
         return NULL;
     }
     if ($rel['relation_id'] != -1) {
         $u = new User();
         $u->load((int) $rel['relation_id']);
         $rel['display_name'] = "{$u->first_name} {$u->last_name}";
         $rel['thumbnail_url'] = $rel['picture'] = $u->picture;
         $rel['user_id'] = (int) $u->user_id;
     } else {
         $rel['picture'] = $rel['thumbnail_url'];
         $rel['user_id'] = $rel['profile_url'];
     }
     return $rel;
 }
 public static function get_or_make_static($path, $mime_type = "application/octet-stream")
 {
     if (!$path) {
         throw new CNException(INVALID_ID, "Storage::get_or_make_static() requires a filename");
     }
     if (!file_exists(PA::$project_dir . "/web/{$path}")) {
         throw new CNException(FILE_NOT_FOUND, "File {$path} does not exist");
     }
     // Call this for files distributed with PA that need to be in
     // Storage (FixedStorage backend) so they can be resized.
     $r = Dal::query_one_assoc("SELECT file_id FROM files WHERE storage_backend='fixed' AND local_id=?", array($path));
     if (!empty($r)) {
         return new StoredFile($r);
     }
     // Not in storage -- add it
     if (strlen($path) > 255) {
         throw new CNException(INVALID_ID, "Path of file to store in fixed storage is too long - max 255 chars ({$path})");
     }
     $path_bits = explode("/", $path);
     $leaf = $path_bits[count($path_bits) - 1];
     Dal::query("INSERT INTO files SET filename=?, file_class='fixed', mime_type=?, created=NOW(), incomplete=0, storage_backend='fixed', local_id=?", array($leaf, $mime_type, $path));
     return new StoredFile(Dal::insert_id());
 }
Exemple #9
0
 public static function load($entity_service, $entity_type, $entity_id)
 {
     // cached already?
     $cache_key = "entity:{$entity_service}:{$entity_type}:{$entity_id}";
     $entity = Cache::getExtCache(0, $cache_key);
     if (!empty($entity)) {
         return $entity;
     }
     // load from DB otherwise
     $r = Dal::query_one_assoc("SELECT * FROM {entities}\n    \tWHERE entity_service=? AND entity_type=? AND entity_id=?", array($entity_service, $entity_type, $entity_id));
     if (!$r) {
         return NULL;
     }
     $entity = new Entity();
     $entity->load_from_row($r);
     // get attributes
     $entity->attributes = Entity::load_attributes($entity->id);
     Cache::setExtCache(0, $cache_key, $entity);
     return $entity;
 }
 /**
  * count all user relations for by status or network_id
  * @param user_id user_id for which user ids are to be counted
  * @param status : status of the relation; ie approved or denied.
  * @param network_uid : get relations by specific network
  * @return $count
  */
 public static function count_user_relations($user_id, $status = NULL, $network_uid = NULL)
 {
     Logger::log("Enter: function Relation::count_user_relations");
     //selecting friend list for a particular user
     $sql = 'SELECT count(user_id) AS count FROM {relations} WHERE user_id = ?';
     $data = array($user_id);
     if (!empty($status)) {
         $sql .= ' AND status = ?';
         $data = array_merge($data, array($status));
     }
     if (!empty($network_uid)) {
         $sql .= ' AND network_uid = ?';
         $data = array_merge($data, array($network_uid));
     }
     $res = Dal::query_one_assoc($sql, $data);
     Logger::log("Exit: function Relation::count_user_relations");
     return $res['count'];
 }