Esempio n. 1
0
function get_network_info()
{
    if (CURRENT_NETWORK_URL_PREFIX != 'www' && CURRENT_NETWORK_URL_PREFIX != '') {
        // not mother (home) network
        $network_info = Network::get_network_by_address(CURRENT_NETWORK_URL_PREFIX);
    } else {
        // home network
        $network_info = Network::get_mothership_info();
    }
    return $network_info;
}
function get_network_info($network_name = null)
{
    if ($network_name) {
        return Network::get_network_by_address($network_name);
    } else {
        if (defined('CURRENT_NETWORK_URL_PREFIX')) {
            return Network::get_network_by_address(CURRENT_NETWORK_URL_PREFIX);
        } else {
            return Network::get_network_by_address('default');
            // if CURRENT_NETWORK_URL_PREFIX not defined
            //  return mother network info
        }
    }
}
require_once dirname(__FILE__) . '/../config.inc';
require_once "{$path_prefix}/db/Dal/Dal.php";
require_once "{$path_prefix}/db/Dal/DbUpdate.php";
require_once "{$path_prefix}/api/Network/Network.php";
// Re-include constants.php to make sure we have the most up to date
// constants.  If we are in the middle of an update and this script is
// being included by web/update/run_scripts.php, we might not have all
// the constants.
include "{$path_prefix}/web/includes/constants.php";
// $settings_new contains the mapping of page names to modules they contain.
global $settings_new;
$db = Dal::get_connection();
foreach (DbUpdate::get_valid_networks() as $net_address) {
    set_time_limit(30);
    $net = Network::get_network_by_address($net_address);
    $table_name = 'page_default_settings';
    if ($net->type != MOTHER_NETWORK_TYPE) {
        // 1 for home network
        $table_name = $net->address . '_' . $table_name;
    }
    $sql = ' TRUNCATE TABLE ' . $table_name;
    $res = Dal::query($sql);
    foreach ($settings_new as $page_id => $v1) {
        $page_name = $v1['page_name'];
        $data = $v1['data'];
        $settings_data = serialize($data);
        $is_configurable = isset($v1['is_configurable']) ? $v1['is_configurable'] : FALSE;
        //default value will be false is not specified
        $sql = "INSERT INTO {$table_name} (page_id, page_name, default_settings, is_configurable) VALUES (?, ?, ?, ?)";
        $data = array($page_id, $page_name, $settings_data, $is_configurable);
 function testNetworkCreation()
 {
     // check that we can create networks
     $can = Network::can_network_be_created();
     $this->assertFalse($can['error'], $can['error_msg']);
     // get network owner user and figure out name etc
     $user = Test::get_test_user();
     $name = "testnet" . rand(10000, 99999);
     $network_basic_controls = array();
     // with crossed fingers, we hope that it will succeed without any of the detail here!
     // make a new network
     $net = new Network();
     $net->set_params(array('user_id' => $user->user_id, 'name' => "auto-test network ({$name})", 'address' => $name, 'tagline' => "not much of a tagline", 'category_id' => 8, 'type' => 0, 'description' => "This network has been created automatically by a PHPUnit test.  If the test succeeds, it will be deleted, too!", 'extra' => serialize($network_basic_controls), 'created' => time(), 'changed' => time()));
     $net->save();
     //default_page_setting($net->address);
     // read it in again and see if it still works
     $net_read = Network::get_network_by_address($net->address);
     $this->assertEquals($net_read->network_id, $net->network_id);
     $this->assertEquals($net_read->type, 0);
     $this->assertEquals($net_read->member_count, 1);
     $this->assertEquals($net_read->owner_id, $user->user_id);
     // a user joins
     $user2 = Test::get_test_user(2);
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 2);
     // a user leaves
     Network::leave($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // make it into a moderated network
     $net->type = 2;
     $net->save();
     // check that it really is moderated
     $net_read = Network::get_network_by_address($net->address);
     $this->assertEquals($net_read->network_id, $net->network_id);
     $this->assertEquals($net_read->type, 2);
     // a user requests
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // request approved
     Network::approve($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 2);
     // user leaves
     Network::leave($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // user requests
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // all requests accepted (of course, there will only be the one)
     Network::approve_all($net->network_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 2);
     // user leaves
     Network::leave($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // user requests
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // request denied
     Network::deny($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // delete network
     Network::delete($net->network_id);
 }
function peopleaggregator_editUser($args)
{
    // check admin password
    global $admin_password;
    if (!$admin_password) {
        header('HTTP/1.1 412 Precondition Failed');
        throw new PAException(OPERATION_NOT_PERMITTED, "editUser API method may not be called without an admin password defined in the Application Configuration File");
    } else {
        if (!isset($args['adminPassword']) || !$args['adminPassword']) {
            header('HTTP/1.1 412 Precondition Failed');
            throw new PAException(OPERATION_NOT_PERMITTED, "editUser API method may not be called without an admin password");
        } else {
            if ($admin_password != $args['adminPassword']) {
                header('HTTP/1.1 401 Unauthorized');
                throw new PAException(USER_INVALID_PASSWORD, "adminPassword incorrect");
            }
        }
    }
    // fetch network info
    $home_network = Network::get_network_by_address($args['homeNetwork']);
    if (!$home_network) {
        //TODO: read this from AppConfig.xml
        $home_network = "default";
    }
    if (isset($args['id']) && !empty($args['id'])) {
        $user_id = $args['id'];
        $user = new User();
        $user->load($user_id);
        $user->api_call = true;
        // api_call indicates that this is a PeopleAggregator API request
        $user->password = isset($args['password']) && !empty($args['password']) ? $args['password'] : $user->password;
        $user->first_name = isset($args['firstName']) && !empty($args['firstName']) ? $args['firstName'] : $user->first_name;
        $user->last_name = isset($args['lastName']) && !empty($args['lastName']) ? $args['lastName'] : $user->last_name;
        $user->login_name = isset($args['login']) && !empty($args['login']) ? $args['login'] : $user->login_name;
        $user->email = isset($args['email']) && !empty($args['email']) ? $args['email'] : $user->email;
        $user->changed = time();
        try {
            $user->save(false);
            // dont check if email already exists because the system calling this function should check
            return array('success' => TRUE, 'msg' => "Modified user successfully");
        } catch (Exception $e) {
            echo $e->msg;
            return array('success' => FALSE, 'msg' => $e->msg);
        }
    } else {
        header('HTTP/1.1 412 Precondition Failed');
        throw new PAException(OPERATION_NOT_PERMITTED, "editUser API method may not be called without a user id");
        // no user id was specified, so this is an error condition
    }
}
Esempio n. 6
0
 * @todo
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * @version 0.0.0-1
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * @author Cyberspace Networks <*****@*****.**>
 * @license GNU General Public License
 * @copyright Copyright (c) 2000-2015 Cyberspace Networks
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * The lastest version of Cyberspace Networks CoreSystem can be obtained from:
 * https://github.com/CyberspaceNetworks/CoreSystem
 * For questions, help, comments, discussion, etc. please visit
 * http://www.cyberspace-networks.com
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */
require_once "api/CNContent/CNContent.php";
PA::$network_info = Network::get_network_by_address(CURRENT_NETWORK_URL_PREFIX);
// hack: do this here to avoid having to include page.php and friends
$uid = (int) $_GET['uid'];
$gid = (int) $_GET['gid'];
$type = $_GET['type'];
if ($uid) {
    $feed = Content::get_content_feed_for_user($uid, 5);
} else {
    if ($gid) {
        $group = ContentCollection::load_collection((int) $gid);
        $contents = $group->get_contents_for_collection($type = 'all', $cnt = FALSE, 5, 1, 'created', 'DESC');
        $content_ids = array();
        foreach ($contents as $i => $con) {
            $content_ids[] = $con['content_id'];
        }
        $feed = Content::get_feed_for_content($content_ids);
Esempio n. 7
0
function peopleaggregator_newUser($args)
{
    // check admin password
    global $admin_password;
    if (!$admin_password) {
        throw new PAException(OPERATION_NOT_PERMITTED, "newUser API method may not be called without an admin password defined in local_config.php");
    }
    if ($admin_password != $args['adminPassword']) {
        throw new PAException(USER_INVALID_PASSWORD, "adminPassword incorrect");
    }
    // fetch network info
    $home_network = Network::get_network_by_address($args['homeNetwork']);
    if (!$home_network) {
        throw new PAException(INVALID_ID, "Network " . $args['homeNetwork'] . " not found");
    }
    // register the user
    $reg = new User_Registration();
    if (!$reg->register(array('login_name' => $args['login'], 'first_name' => $args['firstName'], 'last_name' => $args['lastName'], 'email' => $args['email'], 'password' => $args['password'], 'confirm_password' => $args['password']), $home_network)) {
        return array('success' => FALSE, 'msg' => $reg->msg);
    }
    // success!
    $user = $reg->newuser;
    return array('success' => TRUE, 'msg' => "Created a user: id={$user->user_id}; login={$user->login_name}; firstName={$user->first_name}; lastName={$user->last_name}; email={$user->email}; password={$user->password}; joined to network id {$home_network->network_id} name {$home_network->address}", 'id' => 'user:' . $user->user_id);
}
<?php
/** !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* [filename] is a part of PeopleAggregator.
* [description including history]
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @author [creator, or "Original Author"]
* @license http://bit.ly/aVWqRV PayAsYouGo License
* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
?>
<?php
require_once dirname(__FILE__)."/../config.inc";
require_once "api/Content/Content.php";
PA::$network_info = Network::get_network_by_address(CURRENT_NETWORK_URL_PREFIX); // hack: do this here to avoid having to include page.php and friends

$uid = (int)@$_GET['uid'];
$gid = (int)@$_GET['gid'];
$type = @$_GET['type'];


if ($uid) {
    $feed = Content::get_content_feed_for_user($uid, 5);
} else if ($gid) {
	$group = ContentCollection::load_collection((int)$gid);
	$contents = $group->get_contents_for_collection($type = 'all', $cnt=FALSE, 5, 1,'created','DESC');
	$content_ids = array();
	foreach($contents as $i=>$con) {
		$content_ids[] = $con['content_id'];
	}