function render() { $op = $this->op = @$this->module_params['op']; if ($this->op) { if (!empty($this->module_params['comment'])) { $target = new Comment2(); $target->load($this->module_params['comment']); } else { if (!empty($this->module_params['review'])) { $target = new Review(); $target->load($this->module_params['review']); } else { if (!empty($this->module_params['uid'])) { $target = new ShadowUser('videoplay'); $target->load_by_pa((int) $this->module_params['uid']); } } } switch ($op) { case "delete": if (!empty($this->module_params['uid'])) { $target->remove(); } else { $target->delete(); } break; case "hide": case "show": if (!empty($this->module_params['uid'])) { $target->toggle_active($op == 'hide' ? -1 : 1); } else { $target->toggle_active($op == 'hide' ? 0 : 1); } break; } } switch ($this->mode) { case "comments": $inner_template = dirname(__FILE__) . '/admin_content.tpl'; list($this->contents, $this->n, $this->n_pages, $this->page, $this->per_page) = Comment2::get_recent($this->per_page, $this->page); break; case "reviews": $inner_template = dirname(__FILE__) . '/admin_content.tpl'; list($this->contents, $this->n, $this->n_pages, $this->page, $this->per_page) = Review::get_recent($this->per_page, $this->page); break; case "users": $inner_template = dirname(__FILE__) . '/admin_users.tpl'; list($this->users, $this->n, $this->n_pages, $this->page, $this->per_page) = ShadowUser::admin_paged('videoplay', $this->per_page, $this->page); break; default: return "Unknown display type.<pre>" . print_r($this, 1) . "</pre>"; break; } $inner_html_gen =& new Template($inner_template, $this); $this->inner_HTML = $inner_html_gen->fetch(); $content = parent::render(); return $content; }
public function testAddDeleteShadowUser() { // Dal::register_query_callback("explain_query"); global $network_info; echo "getting a user\n"; $user = Test::get_test_user(); $testusername = $user->first_name . " " . $user->last_name; echo "test user = {$testusername}\n"; $namespace = 'php_unit'; // testuser data $testdata = array('user_id' => "pa_" . $user->user_id, 'login_name' => 'testuser', 'email' => $namespace . $user->email, 'first_name' => $user->first_name, 'last_name' => $user->last_name); echo "TEST DATA:\n"; print_r($testdata); $shadow_user = new ShadowUser($namespace); echo "Test load this shadow user, this should fail\n"; $sh = $shadow_user->load($testdata['user_id']); $this->assertNull($sh); echo "Create a shadow user\n"; $shadow_user = ShadowUser::create($namespace, $testdata, $network_info); echo "SHADOW USER DATA:\n"; print_r($shadow_user); $this->assertNotNull($shadow_user); echo "Test updating the data\n"; $testdata2 = $testdata; $testdata2['email'] = $namespace . "add" . $user->email; $testdata2['login_name'] = "newlogin"; $testdata2['first_name'] = "newName"; print_r($testdata2); $su2 = new ShadowUser($namespace); // load this with new data $su2->load($testdata2); unset($su2); Cache::reset(); // now load it only via the original remote uid $su3 = new ShadowUser($namespace); $su3->load($testdata['user_id']); echo "UPDATED SHADOW USER DATA:\n"; print_r($su3); echo "Delete it\n"; ShadowUser::delete($shadow_user->user_id); // there should not be a shadow user of this id anymore $this->assertNull($shadow_user->load($testdata['user_id'])); }
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); }
static function create($namespace, $userinfo, $network_info) { // setup the needed info if (empty($userinfo['login_name'])) { $userinfo['display_login_name'] = $userinfo['first_name'] . '.' . $userinfo['last_name']; } else { $userinfo['display_login_name'] = $userinfo['login_name']; } // this is the real internal PA login_name // which should NOT be displayed // instead use the display_login_name $userinfo['login_name'] = $namespace . "." . $userinfo['user_id']; $userinfo['confirm_password'] = $userinfo['password'] = substr(md5($userinfo['email'] . rand()), 0, 12); $reg_user = new User_Registration(); if ($reg_user->register($userinfo, $network_info)) { // Success! $reg_user->newuser->set_last_login(); // also save the external user_id $reg_user->newuser->set_profile_field($namespace, 'user_id', $userinfo['user_id'], 0); $reg_user->newuser->set_profile_field($namespace, 'display_login_name', $userinfo['display_login_name'], 0); // load it as a shadow user Cache::reset(); $su = new ShadowUser($namespace); $su->load($userinfo['user_id']); return $su; } else { throw new PAException(BAD_PARAMETER, $reg_user->msg); return NULL; } }
function handle_request() { $json = new Services_JSON(); try { global $_PA, $HTTP_RAW_POST_DATA; if (!@$_PA->enable_widgetization_server) { $this->fail("Widget server is not enabled; you must set \$_PA->enable_widgetization_server = TRUE in local_config.php."); } if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->fail("This URL handles POST requests only"); } if ($_SERVER['CONTENT_TYPE'] != 'application/x-javascript') { $this->fail("Content-Type of application/x-javascript required"); } // Parse input $request = $json->decode($HTTP_RAW_POST_DATA); if ($request == NULL) { $this->fail("Null request"); } if (@$_PA->log_widget_requests) { Logger::log("WidgetServer::handle_request(): request={$HTTP_RAW_POST_DATA}", LOGGER_ACTION); } $this->global = $request->global; // This should probably be in config.inc. For the moment // we figure out the network based on the URL, as with the // rest of the system. PA::$network_info = get_network_info(); $lang = "english"; if (!empty($this->global->language)) { switch ($this->global->language) { case 'en': break; case 'fr': $lang = "french"; break; default: $this->fail("Unknown language: {$this->global}->language"); } } PA::load_language($lang); // Create items as required if (!empty($this->global->items)) { foreach ($this->global->items as $item) { $item_params = array(); foreach ($item as $k => $v) { $item_params[$k] = $v; } Item::sync($item_params); // create or update row in 'items' database table } } // Set up globals - network, user etc if (!empty($this->global->user)) { $user_info = array("user_id" => $this->global->user->id, "login_name" => $this->global->user->login, "email" => $this->global->user->email, "first_name" => $this->global->user->first_name, "last_name" => $this->global->user->last_name, "url" => $this->global->user->url, "thumbnail_url" => $this->global->user->thumbnail_url); // load (and sync!) or create a shadow user for the current remote user PA::$login_user = new ShadowUser($this->global->user->namespace); if (!PA::$login_user->load($user_info)) { // we haven't seen this remote user before - create account PA::$login_user = ShadowUser::create($this->global->user->namespace, $user_info, PA::$network_info); //FIXME: need to define what remote urls mean. in this case "url" should be used instead of /users/$login_name when generating internal urls, so it should go in a global profile block rather than something specific to the remote site. PA::$login_user->set_profile_field($this->global->user->namespace, "url", $this->global->user->url); } PA::$login_uid = PA::$login_user->user_id; } // Render modules $modules = array(); foreach ($request->modules as $req_module) { $module = array(); $module['id'] = $req_module->id; $module['name'] = $name = $req_module->name; $params = array(); foreach ($req_module->params as $k => $v) { $params[$k] = $v; } // clean up URLs that may have the port 80 specified // this would lead to cross server AJAX problems in safari etc // although we are actually on the same server // domain.tld:80/file/ and domain.tld/file/ foreach (array('get_url', 'ajax_url', 'post_url') as $i => $url) { $req_module->{$url} = preg_replace('|:80/*|', '/', $req_module->{$url}); } // dispatch module ob_start(); $module['html'] = $this->render_module($req_module->method, $req_module->name, $req_module->args, $params, $req_module->get_url, $req_module->ajax_url, $req_module->post_url, $req_module->param_prefix); // prefix for input parameters and textareas $errors = ob_get_contents(); ob_end_clean(); if (!empty($errors)) { $module['errors'] = $errors; } $modules[] = $module; } $response = array('modules' => $modules); header("Content-Type: application/x-javascript"); echo $json->encode($response); } catch (WidgetException $e) { echo $json->encode(array("error" => $e->getMessage())); } }
function get_users() { if ($this->mode == 'alphabetical') { $this->sort_by = 'UP.field_value'; $sorting_direction = 'ASC'; } else { $this->sort_by = 'U.created'; $sorting_direction = 'DESC'; } $this->search = array('field_type' => $this->skin, 'field_name' => 'login_name'); if (@$this->q) { $this->search['operator'] = 'LIKE'; $this->search['value'] = "%{$this->q}%"; } $users = array(); if ($this->mode == 'friends') { $this->users = Relation::get_all_relations((int) $this->uid); foreach ($relations as $i => $rel) { $relations[$i]['no_of_relations'] = count(Relation::get_relations($rel['user_id'], APPROVED)); } foreach ($this->users as $i => $u) { if ($u['status'] == PENDING) { unset($this->users[$i]); } else { // we make Object of Array $r = NULL; foreach ($u as $k => $v) { $r->{$k} = $v; } $this->users[$i] = $r; $this->users[$i]->pa_id = $r->user_id; } } $this->user_count = count($this->users); if (!$this->user_count) { // this user has no friends $this->mode = 'newest'; } } if (!$this->user_count) { // load users on the basis of the search parameters. $this->users = ShadowUser::search($this->search, $this->show, $this->page, $this->sort_by, $sorting_direction); $this->user_count = ShadowUser::search($this->search, "COUNT"); } if ($this->user_count) { // prepare paging info $this->n_pages = (int) ceil($this->user_count / $this->show); } }
function render_for_ajax() { $op = $this->params["op"]; $this->gid = @$this->params['blog_id']; if ($op != 'paging' && empty(PA::$login_user)) { return __("Login required"); } switch ($op) { case "save_post": // $this->note = "Save piost goes here."; // validation // return "<pre>".print_r($this->params,1)."</pre>"; $post = $this->params; $this->cid = @$post['cid']; $errmsg = ''; $err = FALSE; if (empty($post['title'])) { $errmsg .= __("Please add a title."); $err = TRUE; } else { $post['title'] = $this->html($post['title']); } if (empty($post['body'])) { $errmsg .= __("Please add some text."); $err = TRUE; } else { $post['body'] = $this->html($post['body']); } if ($err) { $this->err = $errmsg; foreach ($post as $k => $v) { $this->content->{$k} = $v; } $this->inner_template = 'newpost.tpl'; } else { $tags = array(); if (!empty($post['tags'])) { foreach (explode(',', $post['tags']) as $term) { $tr = trim($term); if ($tr) { $tags[] = $tr; } } } $post_saved = BlogPost::save_blogpost($this->cid, PA::$login_user->user_id, $post["title"], $post["body"], NULL, $tags, $this->gid); if (empty($post_saved['cid'])) { $this->note = "<pre>" . print_r($this, 1) . "</pre>"; $this->err = "<pre>" . print_r($post_saved['errors'], 1) . "</pre>"; foreach ($post as $k => $v) { $this->content->{$k} = $v; } $this->inner_template = 'newpost.tpl'; } } break; case "new_post": $this->inner_template = 'newpost.tpl'; break; case "edit_post": $this->inner_template = 'newpost.tpl'; $this->cid = @$this->params['cid']; $this->content = NULL; if ($this->cid) { $this->content = Content::load_content((int) $this->cid, (int) PA::$login_uid); } break; case "delete_post": $post = $this->params; // owner check would go here try { Content::delete_by_id($post['cid']); $this->note = __("Post was deleted successfully."); unset($this->params['cid']); // or we'd have a permalink to a post we no longer have } catch (PAException $e) { $this->err = __("There was an error deleting this post: ") . $e->getMessage(); } break; case "remove_author": // the group is not loaded at this point soo we do it here $g = ContentCollection::load_collection($this->gid, PA::$login_user->user_id); // unjoin user to group if ($g->leave($this->params['pa_id'])) { $this->note = "Successfully removed author."; } else { $this->err = "Couldn't remove author."; } break; case "add_author": // the group is not loaded at this point soo we do it here $g = ContentCollection::load_collection($this->gid, PA::$login_user->user_id); // find real PA user_id $su = new ShadowUser($this->skin); try { $su->load($this->params['remote_id']); if ($su->user_id) { // join user to group if ($g->join($su->user_id)) { $this->note = "Successfully removed author."; unset($this->params['remote_id']); } else { $this->err = "Couldn't add author."; } } else { $this->err = "Couldn't add author with UserID " . $this->params['remote_id'] . " no such user."; } } catch (PAException $e) { $this->err = "There was an error adding author: " . $e->getMessage(); } break; default: break; } return $this->render(); }
function peopleaggregator_deleteShadowUser($args) { global $_PA; $remote_user = @$args['remoteUser']; if (!$_PA->enable_widgetization_server) { throw new PAException(OPERATION_NOT_PERMITTED, "Widgetization disabled; you cannot use remote user functions"); } require_once PA::$path . "/api/User/ShadowUser.php"; $remote_id = explode(":", $remote_user); if (count($remote_id) == 1) { throw new PAException(INVALID_ID, "Remote user IDs must be of the form 'namespace:id'"); } $u = new ShadowUser($remote_id[0]); $u->load($remote_id[1]); if (!$u->user_id) { throw new PAException(USER_NOT_FOUND, "Failed to locate user '" . $remote_id[1] . "' in namespace '" . $remote_id[0] . "'"); } $u->remove(); return array("success" => TRUE, "msg" => "User {$remote_user} was deleted."); }
function handle_request() { $json = new Services_JSON(); try { global $HTTP_RAW_POST_DATA; if (!@PA::$config->enable_widgetization_server) { $this->fail("Widget server is not enabled; you must set \\PA::{$config->enable_widgetization_server} = TRUE in local_config.php."); } if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->fail("This URL handles POST requests only"); } if ($_SERVER['CONTENT_TYPE'] != 'application/x-javascript') { $this->fail("Content-Type of application/x-javascript required"); } // Parse input $request = $json->decode($HTTP_RAW_POST_DATA); if ($request == NULL) { $this->fail("Null request"); } $this->global = $request->global; // Set up globals - network, user etc if (!empty($this->global->user)) { PA::$login_user = new ShadowUser($this->global->namespace); // see if we can load it already if (!PA::$login_user->load($this->global->user->user_id)) { // wasn't here before, so we create a shadow account PA::$login_user = ShadowUser::create($this->global->namespace, $this->global->user, PA::$network_info); } PA::$login_uid = PA::$login_user->user_id; } // This should probably be in config.inc. For the moment // we figure out the network based on the URL, as with the // rest of the system. PA::$network_info = get_network_info(); // Render modules $modules = array(); foreach ($request->modules as $req_module) { $module = array(); $module['id'] = $req_module->id; $module['name'] = $name = $req_module->name; $params = array(); foreach ($req_module->params as $k => $v) { $params[$k] = $v; } // dispatch module ob_start(); $module['html'] = $this->render_module($req_module->method, $req_module->name, $req_module->args, $params, $req_module->post_url, $req_module->param_prefix); // prefix for input parameters and textareas $errors = ob_get_contents(); ob_end_clean(); if (!empty($errors)) { $module['errors'] = $errors; } $modules[] = $module; } $response = array('modules' => $modules); header("Content-Type: application/x-javascript"); echo $json->encode($response); } catch (WidgetException $e) { echo $json->encode(array("error" => $e->getMessage())); } }
<?php require_once dirname(__FILE__) . '/../../config.inc'; require_once PA::$path . "/db/Dal/Dal.php"; require_once PA::$path . "/api/User/ShadowUser.php"; require_once PA::$path . "/ext/JSON.php"; if (!@$_PA->enable_vp_user_dump) { echo '"$_PA->enable_vp_user_dump must be TRUE to use this, for security reasons."'; exit; } $sql = "SELECT user_id FROM user_profile_data WHERE field_type='videoplay' AND field_name='user_id'"; $res = Dal::query($sql); $vp_users = array(); if ($res->numrows() > 0) { $fields = array('display_login_name', 'remote_id', 'user_id', 'login_name', 'first_name', 'last_name', 'email', 'url'); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $uid = (int) $row->user_id; $vpu = new ShadowUser('videoplay'); $vpu->load_by_pa($uid); foreach ($fields as $i => $k) { $vp_users[$uid][$k] = @$vpu->{$k}; } } } $json = new Services_JSON(); header("Content-Type: application/x-javascript"); echo $json->encode($vp_users);