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 testOwnerIdMemberCount()
 {
     $networks = array();
     $sth = Dal::query("SELECT network_id, address, member_count, owner_id FROM networks WHERE is_active=1");
     while (list($net_id, $address, $member_count, $owner_id) = Dal::row($sth)) {
         $networks[$net_id] = array("address" => $address, "member_count" => $member_count, "owner_id" => $owner_id);
     }
     // count all members for all networks
     $sth = Dal::query("SELECT network_id, COUNT(user_id) FROM networks_users GROUP BY network_id");
     while (list($net_id, $member_count) = Dal::row($sth)) {
         $networks[$net_id]['calc_member_count'] = $member_count;
     }
     // find all owners
     $sth = Dal::query("SELECT network_id, user_id FROM networks_users where user_type='owner'");
     while (list($net_id, $owner_id) = Dal::row($sth)) {
         $networks[$net_id]['calc_owner_id'] = $owner_id;
     }
     // verify them all
     $ok = TRUE;
     foreach ($networks as $nid => $net) {
         $address = $net['address'];
         $mc = $net['member_count'];
         $cmc = $net['calc_member_count'];
         $oi = $net['owner_id'];
         $coi = (int) $net['calc_owner_id'];
         if ($cmc && ($mc != $cmc || $oi != $coi)) {
             echo "NetworkDataTest ERROR: Network {$nid} [{$address}]: member_count {$mc}, calc {$cmc} | owner_id {$oi}, found {$coi}\n";
             $ok = FALSE;
         }
     }
     $this->assertTrue($ok);
 }
 public function delete($leaf)
 {
     //TODO: use innodb so this actually matters
     list($file_id, $servers) = Dal::query_one("SELECT file_id, servers FROM local_files WHERE filename=? FOR UPDATE", array($leaf));
     try {
         if (!$file_id) {
             throw new PAException(FILE_NOT_FOUND, "Unable to find file {$leaf} in local_files table:");
         }
         $path = $this->getPath($leaf);
         $server_ids = explode(",", $servers);
         if (in_array(PA::$server_id, $server_ids)) {
             if (empty($path)) {
                 throw new PAException(FILE_NOT_FOUND, "Unable to delete nonexistent file {$path}");
             }
             if (!@unlink($path)) {
                 throw new PAException(STORAGE_ERROR, "Error deleting {$path}");
             }
             $server_ids = array_filter($server_ids, "not_this_server");
             $servers = implode(",", $server_ids);
         }
         Dal::query("UPDATE local_files SET is_deletion=1, timestamp=NOW(), servers=? WHERE file_id=?", array($file_id, $servers));
     } catch (PAException $e) {
         Dal::rollback();
         throw $e;
     }
     return TRUE;
 }
 public static function save_tags_for_item($user_id, $subject_type, $subject_id, $tags_array)
 {
     // remove all existig tags of this user for this item
     Dal::query("DELETE FROM {itemtags} WHERE  user_id=? AND subject_type=? AND subject_id=?", array($user_id, $subject_type, $subject_id));
     // add the given ones
     foreach ($tags_array as $i => $tag_string) {
         Dal::query("INSERT INTO {itemtags} SET \n\t\t  user_id=?, subject_type=?, subject_id=?, \n\t\t  tag_string=?", array($user_id, $subject_type, $subject_id, $tag_string));
     }
 }
 /**
  * Loads the given setting for the given user id.
  *
  * @param integer $type The type of the entity for whom settings are to be loaded.
  * @param integer $assoc_id The id of the association entity for whom settings are to be added.
  * @return $value string This string contains the object of given settings.
  */
 static function load_setting($page_id, $assoc_id, $assoc_type = "network", $child_type = null, $only_configurable = false)
 {
     Logger::log("Enter: function ModuleSetting::load_setting");
     $settings = null;
     $sql = "SELECT page_id, settings FROM {page_settings} WHERE assoc_id=? AND page_id=? AND assoc_type =?";
     $data = array($assoc_id, $page_id, $assoc_type);
     $res = Dal::query($sql, $data);
     $dynamic_page = new DynamicPage($page_id);
     if (!is_object($dynamic_page) or !$dynamic_page->docLoaded) {
         throw new Exception("Page XML config file for page ID: {$page_id} - not found!");
     }
     $dynamic_page->initialize();
     $page_settings = $xml_settings = $dynamic_page->getPageSettings();
     if ($res->numRows() > 0) {
         $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
         $settings = unserialize($row->settings);
         foreach ($settings as $key => $value) {
             // merge DB and XML settings
             $page_settings[$key] = $value;
         }
         if (!is_null($child_type)) {
             if (false !== strpos($dynamic_page->page_type, $child_type)) {
                 $settings = $page_settings;
             } else {
                 $settings = null;
             }
         } else {
             $settings = $page_settings;
         }
     } else {
         if ($assoc_type == 'user' || $assoc_type == 'group') {
             // try to get default settings for current network
             $settings = self::load_setting($page_id, PA::$network_info->network_id, "network", $assoc_type, $only_configurable);
         } else {
             if ($only_configurable == false) {
                 $settings = $dynamic_page->getPageSettings();
             } else {
                 if ($only_configurable == true && $dynamic_page->is_configurable) {
                     if (!is_null($child_type)) {
                         if (false !== strpos($dynamic_page->page_type, $child_type)) {
                             $settings = $dynamic_page->getPageSettings();
                         } else {
                             $settings = null;
                         }
                     } else {
                         $settings = $dynamic_page->getPageSettings();
                     }
                 }
             }
         }
     }
     // Fix: always return navigation_code and boot_code from XML file
     $settings['navigation_code'] = $xml_settings['navigation_code'];
     $settings['boot_code'] = $xml_settings['boot_code'];
     Logger::log("Exit: function ModuleSetting::load_setting");
     return $settings;
 }
 static function get($module_name)
 {
     Logger::log("Enter: function ModuleData::get");
     $sql = "SELECT  data AS data FROM {moduledata}  WHERE modulename LIKE ? ";
     $data = array($module_name);
     $res = Dal::query($sql, $data);
     if ($res->numRows() > 0) {
         $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
         Logger::log("Exit: function ModuleData::get");
         return $row->data;
     }
 }
 public static function get_recent_by_user($uid, $cnt = 5)
 {
     $sql = 'SELECT * FROM {rating} WHERE user_id=? 
 ORDER BY index_id
 LIMIT ?';
     $data = array($uid, $cnt);
     $res = Dal::query($sql, $data);
     $return = array();
     if ($res->numRows()) {
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             array_push($return, $row);
         }
     }
     return $return;
 }
 function testProfileReadingFunctions()
 {
     // find a user with 'newcss' set
     list($uid, $css) = Dal::query_one("SELECT user_id, field_value FROM user_profile_data WHERE field_type='ui' AND field_name='newcss' ORDER BY user_id LIMIT 1");
     if (empty($uid)) {
         echo "Test not possible as nobody has the newcss field set.  Try again on a more populated database.\n";
         return;
     }
     // find another field, so we can test with more than one
     list($f2_name, $f2_value) = Dal::query_one("SELECT field_name, field_value FROM user_profile_data WHERE field_type='ui' AND user_id=? AND field_name <>'newcss' AND field_value IS NOT NULL LIMIT 1", $uid);
     echo "getting ui/newcss and {$f2_name} properties from user_profile_data for user_id {$uid}.\n";
     $user = new User();
     $user->load((int) $uid);
     // load just the newcss field
     echo "getting just the newcss property for user {$uid}\n";
     $css2 = $user->get_profile_field('ui', 'newcss');
     $this->assertEquals($css, $css2);
     // load just the second field
     echo "getting just the {$f2_name} property for user {$uid}\n";
     $v = $user->get_profile_field('ui', $f2_name);
     $this->assertEquals($v, $f2_value);
     // load newcss and the second field, with get_profile_fields()
     echo "getting the newcss and {$f2_name} properties, with get_profile_fields()\n";
     $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name));
     $this->assertEquals($css, $data['newcss']);
     $this->assertEquals(NULL, $data['graagh']);
     $this->assertEquals($f2_value, $data[$f2_name]);
     // try again, flushing the cache first
     Cache::reset();
     echo "(without cache) getting the newcss and {$f2_name} properties, with get_profile_fields()\n";
     $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name));
     $this->assertEquals($css, $data['newcss']);
     $this->assertEquals(NULL, $data['graagh']);
     $this->assertEquals($f2_value, $data[$f2_name]);
     // regression test (phil) 2007-04-01, for bug spotted by martin
     // 2007-03-23: make sure we don't crash if we request fields that
     // are all cached.
     echo "regression: make sure it doesn't crash if everything is in the cache\n";
     $data = $user->get_profile_fields('ui', array('newcss'));
     $this->assertEquals($css, $data['newcss']);
     // try by loading the entire 'ui' section
     echo "getting entire ui section for user {$uid}\n";
     $ui = User::load_profile_section($uid, "ui");
     $this->assertEquals($css, $ui['newcss']['value']);
     $this->assertEquals($f2_value, $ui[$f2_name]['value']);
 }
 public function update()
 {
     Logger::log("Enter: function ConfigurableText::update");
     $sql = "SELECT * FROM {configurable_text} WHERE caption = ? AND id <> ?";
     $data = array('caption' => $this->caption, 'id' => $this->id);
     $res = Dal::query($sql, $data);
     if ($res->numRows() == 0) {
         $sql = "UPDATE {configurable_text} SET caption = ?, caption_value = ? WHERE id = ?";
         $data = array('caption' => $this->caption, 'caption_value' => $this->caption_value, 'id' => $this->id);
         $res = Dal::query($sql, $data);
     } else {
         // Caption already exists
         Logger::log("Throwing exception CAPTION_NAME_EXISTS | Caption with the given name already exists", LOGGER_ERROR);
         throw new PAException(CAPTION_NAME_EXISTS, "Caption with the given name already exists");
     }
     Logger::log("Enter: function ConfigurableText::update");
     return;
 }
 public static function get($conditions = NULL, $params = NULL)
 {
     Logger::log("Enter: CNRatingData::get()");
     $sql = 'SELECT * FROM {rating} WHERE 1';
     $data = array();
     if (!empty($params)) {
         foreach ($params as $key => $value) {
             $sql .= ' AND ' . $key . ' = ?';
             array_push($data, $value);
         }
     }
     $res = Dal::query($sql, $data);
     $return = array();
     if ($res->numRows()) {
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             array_push($return, $row);
         }
     }
     Logger::log("Exit: CNRatingData::get()");
     return $return;
 }
Exemple #11
0
 public function update($params)
 {
     $updates = array();
     $args = array();
     foreach ($params as $k => $v) {
         $col = @Item::$columns[$k];
         if (empty($col)) {
             throw new Exception("Unknown item table column '{$k}'");
         }
         if ($this->{$col} != $v) {
             $updates[] = "{$col}=?";
             $args[] = $v;
         }
     }
     if (count($updates)) {
         $args[] = $this->item_id;
         Dal::query("UPDATE {items} SET " . implode(",", $updates) . " WHERE item_id=?", $args);
         Cache::setValue("item:" . $params['type'] . ":" . $params['id'], $this);
         // update cache
     }
 }
 /**
  * Function to process the user feed.
  * This function will check for the feed url added by the user in 
  * user_profile in external feeds. If it exists then it will return the associated 
  * feed_id otherwise it will add 
  */
 private function import_user_feed()
 {
     Logger::log("Enter: UserProfileFeed::import_user_feed");
     $sql = 'SELECT feed_id FROM {external_feed} WHERE import_url = ? AND is_active = ?';
     try {
         $res = Dal::query($sql, array($this->import_url, ACTIVE));
     } catch (PAException $e) {
         Logger::log("Exit UserProfileFeed::import_user_feed.Not able to get feed details for given import_url. Associated sql = {$sql}, import_url = {$this->import_url}");
         throw $e;
     }
     if ($res->numRows()) {
         //given import url exists already in the external feed list
         $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
         //TODO: refresh the feed data
         $this->feed_id = $row->feed_id;
     } else {
         // Given feed does not exists in the external feeds. So add it first and then return the associated feed_id.
         //setting the feed_type to user_profile feed
         $this->feed_type = USER_PROFILE_FEED;
         $this->save();
     }
     Logger::log("Exit: UserProfileFeed::import_user_feed");
     return $this->feed_id;
 }
Exemple #13
0
 /**
     For loading group information in the basis of group_id
     Requirement :- take a group id
     Return :- all the information of group as well as group_owner name, ID and number of members in the group
 */
 public static function load_group($group_id = FALSE, $cnt = FALSE, $show = 'ALL', $page = 1, $sort_by = 'created', $direction = 'DESC', $speacial_condition = FALSE)
 {
     Logger::log("Enter: Group::load_group() ");
     if ($sort_by == 'members') {
         $order_by = 'members' . ' ' . $direction;
     } else {
         $order_by = ' CC.' . $sort_by . ' ' . $direction;
     }
     if ($show == 'ALL' || $cnt == TRUE) {
         $limit = '';
     } else {
         $start = ($page - 1) * $show;
         $limit = 'LIMIT ' . $start . ',' . $show;
     }
     if ($group_id) {
         $sql = "SELECT count(GU.user_id) AS members,CC.collection_id AS group_id,CC.title AS group_name,CC.*,U.first_name AS owner_first_name,U.login_name AS owner_login_name,U.user_id  AS owner_id FROM {contentcollections} AS CC INNER JOIN {groups_users} AS GU on GU.group_id = CC.collection_id AND CC.is_active =1 LEFT JOIN {users} AS U on CC.author_id = U.user_id WHERE CC.collection_id = ? {$speacial_condition} GROUP BY CC.collection_id ORDER BY {$order_by} {$limit}";
         $res = Dal::query($sql, $group_id);
         if ($cnt) {
             return $res->numRows();
         }
         if ($res->numRows()) {
             while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
                 $group_description = $row;
             }
         }
         Logger::log("Exit: Group::load_group() ");
         return $group_description;
     }
 }
 /**
  *   Method to load a links or links.
  *   @param $condition_array associative array of the class variables with their values.
  *   @access public
  */
 public function network_owner_link($condition = NULL, $limit = NULL)
 {
     Logger::log("Enter: function Links::network_owner_link");
     $sql = "SELECT L.* FROM {links} AS L INNER JOIN {linkcategories} AS LC ON L.category_id = LC.category_id";
     if (count($condition) > 0) {
         foreach ($condition as $key => $value) {
             $sql .= " AND L.{$key} = ?";
             $data[] = $value;
         }
     }
     $sql .= " ORDER BY L.created";
     if (!empty($limit)) {
         $sql .= " LIMIT {$limit}";
     }
     $res = Dal::query($sql, $data);
     $return = array();
     if ($res->numRows() > 0) {
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             $return[] = $row;
         }
     }
     Logger::log("Exit: function Links::load_link");
     return $return;
 }
 public static function content_type_exists()
 {
     $sql = "SELECT type_id FROM {content_types} WHERE name LIKE ?";
     $res = Dal::query($sql, array(self::TYPE_NAME));
     if ($res->numRows()) {
         return true;
     }
     return false;
 }
 /**
  * @todo Implement testAssign_role_to_user().
  */
 public function testAssign_role_to_user()
 {
     $role_id = 1;
     $user_id = 1;
     Roles::assign_role_to_user($role_id, $user_id);
     $res = Dal::query('SELECT count(*) AS CNT FROM {users_adminroles} where user_id = 1 and role_id=1');
     $r = $res->fetchRow(DB_FETCHMODE_OBJECT);
     $this->assertEquals(1, $r->CNT);
 }
    echo "Page {$page} of {$pages}; current mem use {$start_mem}...";
    $cmt_rows = Comment::get_all_comments(0, $per_page, $page);
    echo " after comments loaded, mem usage is " . memory_get_usage() . "\n";
    $del_ct = 0;
    foreach ($cmt_rows as $cmt_row) {
        $cmt = new Comment();
        $cmt->load_from_row($cmt_row);
        $del_ct += $cmt->index_spam_domains(TRUE);
        $cmt->index_words();
    }
    echo "{$del_ct} comments deleted due to blacklisting or excessive linking\n";
    unset($cmt_rows);
    unset($cmt_row);
    $end_mem = memory_get_usage();
    //  echo "end of page - mem used $end_mem (delta ".($end_mem - $start_mem).").\n";
    echo "Counting up totals\n";
    SpamDomain::recalculate_total_link_counts();
}
echo "Analyzed {$total} comments\n";
echo "Worst domains:\n";
$sth = Dal::query("SELECT id,domain,count,active_count FROM spam_domains ORDER BY count DESC LIMIT 25");
while ($r = Dal::row($sth)) {
    list($domain_id, $domain, $count, $active_count) = $r;
    echo "{$count}: {$domain} (id={$domain_id}); {$active_count} not deleted\n";
}
echo "Worst domains with still-active comments:\n";
$sth = Dal::query("SELECT id,domain,count,active_count FROM spam_domains WHERE active_count <> 0 ORDER BY count DESC LIMIT 25");
while ($r = Dal::row($sth)) {
    list($domain_id, $domain, $count, $active_count) = $r;
    echo "{$count}: {$domain} (id={$domain_id}); {$active_count} not deleted\n";
}
 private function getUserStatus()
 {
     // MySQL query
     $sql = "SELECT user_status+0 AS status FROM { pa_forums_users } WHERE user_id = ? AND board_id = ?;";
     $res = null;
     // record ID
     $params = array($this->user_id, $this->board_id);
     // execute query
     $res = Dal::query($sql, $params);
     if ($res->numRows() > 0) {
         $_objarr = $res->fetchRow(DB_FETCHMODE_OBJECT);
         $res = $_objarr->status;
     }
     return $res;
 }
 public function load($assoc_id)
 {
     Logger::log("Enter: EventAssociation::load");
     $sql = "SELECT * FROM {events_associations} WHERE assoc_id = ? LIMIT 1";
     $data = array($assoc_id);
     $res = Dal::query($sql, $data);
     if (!$res->numRows()) {
         Logger::log(" Throwing exception EVENT_NOT_EXIST | Message: EventAssociation with assoc_id({$assoc_id}) does not exist.", LOGGER_ERROR);
         throw new PAException(EVENT_NOT_EXIST, "EventAssociation with assoc_id({$assoc_id}) does not exist.");
     }
     if ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $this->assoc_id = $row->assoc_id;
         $this->event_id = $row->event_id;
         $this->user_id = $row->user_id;
         $this->assoc_target_type = $row->assoc_target_type;
         $this->assoc_target_id = $row->assoc_target_id;
         $this->assoc_target_name = $row->assoc_target_name;
         $this->event_title = $row->event_title;
         $this->start_time = $row->start_time;
         $this->end_time = $row->end_time;
         $this->assoc_data = unserialize($row->assoc_data);
     }
     Logger::log("Exit: EventAssociation::load");
 }
 /**
  * Get top ranked users
  *
  */
 public static function get_top_ranked_users($count = FALSE, $params = array())
 {
     Logger::log("Enter: Ranking::get_top_ranked_users() with count=" . $count);
     $qw = ' WHERE u.is_active = 1';
     if (isset($params["in"])) {
         $qw .= ' AND u.user_id IN (' . $params["in"] . ')';
     } elseif (isset($params["not_in"])) {
         $qw .= ' AND u.user_id NOT IN (' . $params["not_in"] . ')';
     }
     $qo = ' ORDER BY';
     if (isset($params["order_by"]) && $params["order_by"] == 2) {
         $qo .= ' u.created DESC';
     } elseif (isset($params["order_by"]) && $params["order_by"] == 3) {
         $qo .= ' CAST(upd.field_value AS UNSIGNED) ASC';
     } else {
         $qo .= ' CAST(upd.field_value AS UNSIGNED) DESC';
     }
     if (!empty($params["page"]) && !empty($params["show"])) {
         $start = ($params["page"] - 1) * $params["show"];
         $limit = ' LIMIT ' . $start . ', ' . $params["show"];
     } else {
         $limit = "";
     }
     $sql = "SELECT u.user_id, u.login_name, u.picture, u.email, upd.field_value FROM {users} u LEFT JOIN {user_profile_data} upd ON u.user_id = upd.user_id AND upd.field_name = 'site_points' " . $qw . " " . $qo . " " . $limit;
     $users = array();
     $result = Dal::query($sql);
     if ($count == TRUE) {
         return $result->numRows();
     }
     while ($user = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
         $users[$user->user_id]["user_id"] = $user->user_id;
         $users[$user->user_id]["site_points"] = $user->field_value;
         $users[$user->user_id]["login_name"] = $user->login_name;
         $users[$user->user_id]["picture"] = $user->picture;
         $users[$user->user_id]["email"] = $user->email;
     }
     Logger::log("Exit: Ranking::get_top_ranked_users()");
     return $users;
 }
Exemple #21
0
 /**
  * Delete the persona and its properties.
  *
  */
 public static function delete($persona_id)
 {
     Logger::log("Enter: function Persona::delete");
     $params = array($persona_id);
     $sql = 'DELETE FROM {personas} WHERE persona_id = ?';
     Dal::query($sql, $params);
     $sql = 'DELETE FROM {persona_properties} WHERE persona_id = ?';
     Dal::query($sql, $params);
     Logger::log("Exit: function Persona::delete");
 }
 public static function admin_paged($namespace, $per_page = 10, $page = 1)
 {
     $per_page = (int) $per_page;
     $page = (int) $page;
     $sql = "SELECT COUNT(*) FROM {users}";
     $ct = Dal::query_first($sql, array());
     $n_pages = (int) ceil($ct / $per_page);
     $start = ($page - 1) * $per_page;
     $sql = "SELECT user_id, is_active, comment_count, review_count, rating_count FROM {users} ORDER BY created DESC LIMIT {$start}, {$per_page}";
     $uids = self::load_many_from_query("User", $sql, array());
     $shUsers = array();
     foreach ($uids as $i => $u) {
         $su = new ShadowUser($namespace);
         $su->load_by_pa((int) $u->user_id);
         $su->is_active = $u->is_active;
         $su->comment_count = $u->comment_count;
         $su->review_count = $u->review_count;
         $su->rating_count = $u->rating_count;
         $shUsers[] = $su;
     }
     return array($shUsers, $ct, $n_pages, $page, $per_page);
 }
 /**
  * Count records based on a given params - dynamic method: count_PaForum()
  *
  *
  * Generated with the DalClassGenerator created by:
  * Zoran Hron <*****@*****.**>
  *
  * @param conditionalStatement = null
  * @param selectFields = array()
  * @param groupByFields = array()
  * @result int or array of counted objects
  **/
 public function count_PaForum($conditionalStatement = null, $selectFields = array(), $groupByFields = array())
 {
     // build MySQL query
     $sql = "SELECT ";
     if (count($selectFields) > 0) {
         $sql .= implode(", ", $selectFields) . ", COUNT(*) AS counter ";
     } else {
         $sql .= "COUNT(*) AS counter ";
     }
     $sql .= "FROM { pa_forum } ";
     if ($conditionalStatement) {
         $sql .= "WHERE {$conditionalStatement} ";
     }
     if (count($groupByFields) > 0) {
         $sql .= "GROUP BY " . implode(", ", $groupByFields);
     }
     $sql .= ";";
     // execute query
     $res = Dal::query($sql);
     $objects = array();
     // data found?
     if ($res->numRows() > 1) {
         // retrieve data objects
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             $objects[] = $row;
         }
         return $objects;
     } else {
         if ($res->numRows() == 1) {
             $data = $res->fetchRow(DB_FETCHMODE_OBJECT);
             return $data->counter;
         } else {
             return 0;
         }
     }
 }
 /**
  * disapprove content/user in moderated queue
  * @access public
  * @param int id of user/content
  * @param string type ie user/content
  */
 public static function disapprove_suggestion($suggestion_id)
 {
     Logger::log("Enter : Network::disapprove_suggestion() | Args: \$suggestion_id = {$suggestion_id}");
     // nab the author ID for the suggestion
     $sql = 'SELECT author_id FROM {contents} WHERE content_id = ?';
     $data = array($suggestion_id);
     $res = Dal::query($sql, $data);
     if ($res->numRows()) {
         $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
         $author_id = intval($row['author_id']);
     }
     // and email them
     $suggestion_user = new User();
     $suggestion_user->load($author_id);
     $check = PAMail::send('suggestion_received', $suggestion_user, PA::$login_user, array());
     if ($check == FALSE) {
         Logger::log("Throwing exception MAIL_FUNCTION_FAILED | Mail was not sent to suggester ", LOGGER_ERROR);
         throw new PAException(MAIL_FUNCTION_FAILED, "Mail was not sent to suggester");
     }
     ModerationQueue::disapprove_suggestion($suggestion_id);
     Logger::log("Exit : Network::disapprove_suggestion()");
     return;
 }
 public static function flushExtCache($user_id, $key)
 {
     Dal::query("DELETE FROM ext_cache WHERE user_id=? AND cache_key=?", array($user_id, $key));
 }
 /**
  * Delete the persona service path.
  *
  */
 public static function delete($persona_service_path_id)
 {
     Logger::log("Enter: function PersonaServicePath::delete");
     $params = array($persona_service_path_id);
     $sql = 'DROP FROM {persona_service_paths} WHERE persona_service_path_id = ?';
     Dal::query($sql, $params);
     Logger::log("Exit: function PersonaServicePath::delete");
 }
 /**
  * Generic function to get the data from feed_data table
  * @param array of parameters as key value pairs eg. array('feed_id'=>1, ''is_active'=>1)
  * @return data object
  */
 public function get_feed_data($params)
 {
     Logger::log("Enter: ExternalFeed::get_feed_data");
     $sql = 'SELECT * FROM {feed_data}';
     $data = array();
     if (count($params)) {
         $sql .= ' WHERE 1';
         foreach ($params as $key => $value) {
             $sql .= ' AND ' . $key . ' = ?';
             $data[] = $value;
         }
     }
     $sql .= ' ORDER BY publish_date DESC';
     //code for refreshing the feed data if params have feed_id
     if (!empty($params['feed_id'])) {
         $this->feed_id = $params['feed_id'];
         $this->refresh_feed_data();
     }
     try {
         $res = Dal::query($sql, $data);
     } catch (CNException $e) {
         Logger::log("Exit: ExternalFeed::get_feed_data. Query failed, associated sql = {$sql}");
         throw $e;
     }
     $feed_data_obj = array();
     if ($res->numRows()) {
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             $feed_data_obj[] = $row;
         }
     }
     Logger::log("Enter: ExternalFeed::get_feed_data");
     return $feed_data_obj;
 }
 public function delete()
 {
     Dal::query("UPDATE {blog_badges} SET is_active=0 WHERE user_id=? AND badge_id=?", array($this->user_id, $this->badge_id));
 }
function exception_handler($exception)
{
    // clean out any buffering so we can write straight to the client
    // while (ob_end_clean());
    try {
        while ($exception->getCode() == 100 && strpos($exception->getMessage(), "no such table") != -1) {
            // See if the database hasn't been populated.
            // (Note: we use 'while' here rather than 'if' so we can use break
            // to avoid this turning into a mess of nested blocks).
            // First, make sure we have a working database connection.
            try {
                $sth = Dal::query("SHOW TABLES");
            } catch (CNException $e) {
                // The database connection isn't working - so fall through to
                // the normal error handler.
                break;
            }
            // Now run through the results and see if we can find a familiar
            // table.
            $found = 0;
            while ($r = $sth->fetchRow()) {
                if ($r[0] == "page_settings") {
                    $found = 1;
                    break;
                }
            }
            if ($found) {
                // ok, the db *has* been populated - fall through
                break;
            }
            // If we get this far, it means that the DB isn't populated, so we
            // show a message to the user (who is presumably an admin,
            // installing the system).
            // global var $path_prefix has been removed - please, use PA::$path static variable
            ?>

            <h1>Database not populated</h1>

            <p>Before you can run Cyberspace-Networks, you need to populate the database by running the script <code><?php 
            echo PA::$path;
            ?>
/api/DB/CNDB.mysql</code> on your database.  You can do it in the MySQL console like this:</p>

            <pre><i>user</i>@<i>server</i>:<?php 
            echo PA::$path;
            ?>
$ <b>mysql -u <i>username</i> -p</b>
                  Enter password: <b><i>password</i></b>

                  Welcome to the MySQL monitor.  Commands end with ; or \g.
                  Your MySQL connection id is 63048 to server version: 4.1.14-Debian_6-log

                  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

                  mysql> <b>use paalpha</b>
                  Database changed
                  mysql> <b>source <?php 
            echo PA::$path;
            ?>
/api/DB/CNDB.mysql</b></pre>

            <?php 
            exit;
        }
        // render an error message
        $code_esc = intval($exception->getCode());
        $msg_esc = htmlspecialchars($exception->getMessage());
        $traceback = $exception->getTraceAsString();
        //$template_file = getShadowedPath(PA::$theme_path . '/cnexception.php');
        $template_file = getShadowedPath('web/Themes/Default/cnexception.php');
        $template = new Template($template_file);
        $template->set('code_esc', $code_esc);
        $template->set('msg_esc', $msg_esc);
        $template->set('traceback', $traceback);
        echo $template->fetch();
        /*
         $page = new PageRenderer(NULL, NULL, "Error $code_esc: $msg_esc", "container_one_column.php");
         $msg_tpl = new Template(CURRENT_THEME_FSPATH."/error_middle.tpl");
         $msg_tpl->set('code', $code_esc);
         $msg_tpl->set('msg', $msg_esc);
         $page->add_module("middle", "top", $msg_tpl->fetch());
        
         $css_path = PA::$theme_url . '/layout.css';
         $page->add_header_css($css_path);
         $css_path = PA::$theme_url . '/network_skin.css';
         $page->add_header_css($css_path);
         $page->header->set('navigation_links', null);//setting the links to null
         echo $page->render();
        */
        // write a copy into the log
        Logger::log("An exception occurred: code " . $exception->getCode() . ", message " . $exception->getMessage() . "\nLast error: " . var_export(error_get_last(), TRUE) . "\n" . $exception->getTraceAsString(), LOGGER_ERROR);
    } catch (Exception $e) {
        // If an error occurred in PageRenderer or something, present a much plainer screen with both errors:
        echo "<h1>Lots of errors occurred!</h1>\n<p>An error occurred, then the error handler crashed while trying to handle the error.  Whoops!</p>\n<p><b>Here are the details of the original error:</b></p>\n<p>" . $exception->getMessage() . "</p>\n<pre>" . $exception->getTraceAsString() . "</pre>\n<p><b>Here are the details of the second error:</b></p>\n<p>" . $e->getMessage() . "</p>\n<pre>" . $e->getTraceAsString() . "</pre>";
    }
    exit;
}
 /**
  * Builds a category tree for all cateogories
  * @access public static
  * return array of all categories
  */
 public static function build_all_category_list($position = '', $spacing = '', $category_tree_array = '', $type = 'Default', $exclude = 1)
 {
     if (!is_array($category_tree_array)) {
         $category_tree_array = array();
     }
     if (sizeof($category_tree_array) < 1 && $exclude != 0) {
         $category_tree_array[] = array('category_id' => '0', 'name' => 'Select Category');
     }
     $sql = "SELECT * FROM {categories} WHERE position RLIKE  '^" . $position . "[0-9]+>\$' AND type = ?";
     $res = Dal::query($sql, array($type));
     if ($res->numRows() > 0) {
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             $category_tree_array[] = array('category_id' => $row->category_id, 'name' => $spacing . $row->name);
             $category_tree_array = Category::build_all_category_list($row->position, $spacing . '&nbsp;&nbsp;&nbsp;', $category_tree_array, $type);
         }
     }
     return $category_tree_array;
 }