public static function can_see($persona_id, $owner_uid, $viewer_uid) { Logger::log("Enter: function PersonaHelper::can_see() persona_id: {$persona_id}, owner_uid; {$owner_uid}, viewer_uid: {$viewer_uid}"); // load the persona to see it's privacy data try { $persona = new Persona(); $persona->load($persona_id); } catch (PAException $e) { Logger::Log($e->getMessage()); Logger::log("Exit: function PersonaHelper::can_see() with NULL"); return null; // no persona! } $data = $persona->get_configuration_data(); $perm = intval($data->perm); if ($viewer_uid == 0) { // anon users don't have relations $relation = 0; // and are definetly not family $in_family = 0; } else { if ($owner_uid == $viewer_uid) { $relation = 2; $in_family = 1; } else { // $relation = Relation::get_relation($owner_uid, $viewer_uid); $relations = Relation::get_relations($owner_uid); $relation = in_array($viewer_uid, $relations); $in_family = Relation::is_relation_in_family($owner_uid, $viewer_uid); } } Logger::log("PersonaHelper::can_see() perm: {$perm}, relation: {$relation}, in_family: {$in_family}"); if (!$perm) { // permissions weren't set or are 0 == nobody Logger::log("Exit: function PersonaHelper::can_see() with NULL"); return null; } else { if ($perm == 1) { // show to world (everybody) Logger::log("Exit: function PersonaHelper::can_see() with Persona"); return $persona; } else { if ($perm == 2) { // show to relations if ($relation) { Logger::log("Exit: function PersonaHelper::can_see() with Persona"); return $persona; } } else { if ($perm == 3) { // show to family if ($in_family) { Logger::log("Exit: function PersonaHelper::can_see() with Persona"); return $persona; } } else { Logger::log("Exit: function PersonaHelper::can_see() with NULL"); return null; } } } } }
/** * Method to load information of selected profile. * order by can be applied like $order_by => 'seq' or 'seq DESC' or 'seq ASC' */ public static function load_user_profile($user_id, $my_user_id, $information_type = null, $order_by = null) { Logger::log("Enter: User::load_user_profile"); $relations = array(); $user_profile_data = array(); $i = 0; if (is_null($information_type)) { $sql = 'SELECT * FROM {user_profile_data} WHERE user_id = ? '; $data = array($user_id); } else { $sql = 'SELECT * FROM {user_profile_data} WHERE user_id = ? AND field_type = ?'; $data = array($user_id, $information_type); } //added for gurpreet if (!empty($order_by)) { $sql .= ' ORDER BY ' . $order_by; } $res = Dal::query($sql, $data); if ($res->numRows() > 0) { while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $array_of_data[$i]['uid'] = $row->user_id; $array_of_data[$i]['name'] = $row->field_name; $array_of_data[$i]['value'] = $row->field_value; $array_of_data[$i]['type'] = $row->field_type; $array_of_data[$i]['perm'] = $row->field_perm; $array_of_data[$i]['seq'] = $row->seq ? (int) $row->seq : NULL; $i++; } } if (!empty($array_of_data)) { // Getting degree 1 friendlist $relations = Relation::get_relations($user_id, null, PA::$network_info->network_id); if ($user_id == $my_user_id) { //Logged in user is viewing its own blog. $user_profile_data = $array_of_data; } else { if (in_array($my_user_id, $relations)) { //some from user's relations is viewing its blog //check whether relation is in user's family $in_family = Relation::is_relation_in_family($user_id, $my_user_id); foreach ($array_of_data as $user_data) { //user data viewable to family members. if ($user_data['perm'] == IN_FAMILY && $in_family) { $user_profile_data[] = $user_data; } if ($user_data['perm'] == WITH_IN_DEGREE_1 || $user_data['perm'] == ANYONE) { $user_profile_data[] = $user_data; } } //end for } else { //user data viewable to user which is not in relation wth given user. foreach ($array_of_data as $user_data) { if ($user_data['perm'] == ANYONE) { $user_profile_data[] = $user_data; } } } } } //end outer if Logger::log("Exit: User::load_user_profile"); return $user_profile_data; }