function Streams_0_8_8_Streams_mysql()
{
    $communityId = Users::communityId();
    $user = Users_User::fetch($communityId, true);
    Streams::create($communityId, $communityId, 'Streams/resource', array('name' => 'Streams/invitations', 'readLevel' => 0, 'writeLevel' => 0, 'adminLevel' => 0));
    Streams_Access::insert(array('publisherId' => $communityId, 'streamName' => "Streams/invitations", 'ofUserId' => '', 'grantedByUserId' => null, 'ofContactLabel' => "{$app}/admins", 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['close'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']))->execute();
}
function Streams_0_8_6_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    // access for managing communities
    $access = new Streams_Access();
    $access->publisherId = $communityId;
    $access->streamName = 'Streams/community*';
    $access->ofUserId = '';
    $access->ofContactLabel = "{$app}/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['edit'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
    // access for managing categories
    $access = new Streams_Access();
    $access->publisherId = $communityId;
    $access->streamName = 'Streams/category/';
    $access->ofUserId = '';
    $access->ofContactLabel = "{$app}/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['close'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
    // template to help users relate things to Streams/category streams
    Streams_Stream::insert(array('publisherId' => '', 'name' => 'Streams/category/', 'type' => 'Streams/template', 'title' => 'Untitled Category', 'icon' => 'Streams/category', 'content' => '', 'attributes' => null, 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['relate'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']))->execute();
    // template to help users create subcategories for things
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'subcategories', 'fromPublisherId' => '', 'fromStreamName' => 'Streams/category/'))->execute();
}
function Users_0_9_2_Users_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    $rows = Users_Session::select('COUNT(1)')->where($criteria)->fetchAll(PDO::FETCH_NUM);
    $count = $rows[0][0];
    $limit = 100;
    $offset = 0;
    $sessions = Users_Session::select('*')->orderBy('id')->limit($limit, $offset)->caching(false)->fetchDbRows();
    echo "Adding userId to sessions...";
    while ($sessions) {
        foreach ($sessions as $s) {
            $parsed = Q::json_decode($s->content, true);
            if (empty($parsed['Users']['loggedInUser']['id'])) {
                continue;
            }
            $s->userId = $parsed['Users']['loggedInUser']['id'];
        }
        Users_Session::insertManyAndExecute($sessions, array('onDuplicateKeyUpdate' => array('userId' => new Db_Expression("VALUES(userId)"))));
        $min = min($offset + $limit, $count);
        echo "";
        echo "Updated {$min} of {$count} sessions";
        $offset += $limit;
        if ($offset > $count) {
            break;
        }
        $sessions = Users_Session::select('*')->orderBy('id')->limit($limit, $offset)->caching(false)->fetchDbRows();
    }
    echo "\n";
}
Example #4
0
function Shipping_scheduled_response_content($params)
{
    // redirect to home page if not logged in
    if (!Users::loggedInUser()) {
        header("Location: " . Q_Request::baseUrl());
        exit;
    }
    // get "Shipping/shipments" stream
    $publisherId = Users::communityId();
    $streamName = 'Shipping/shipment/' . Q_Request::uri()->shipmentStreamName;
    $stream = Streams::fetchOne($publisherId, $publisherId, $streamName);
    //$xml = simplexml_load_file(APP_DIR.'/classes/dhl/response.xml');
    //$xml = simplexml_load_string(str_replace('req:', '', file_get_contents(APP_DIR.'/classes/dhl/response.xml')));
    //print_r($xml); exit;
    // test pickup
    //$carrier = new Shipping_Carrier_DHL();
    //$carrier->createAWBBarCode($stream, 'iVBORw0KGgoAAAANSUhEUgAAAYwAAABeAQMAAAAKdrGZAAAABlBMVEX///8AAABVwtN+AAAAaklEQVR42mNkYGBIyL8wZcutG2wTzVMZfG99eep7y1tp5oIokaMMOtabG6PuTflrnnHqVfI013vzlRYwMDAxkAxGtYxqGdUyqmVUy6iWUS2jWka1jGoZ1TKqZVTLqJZRLaNaRrWMaiEVAABqDRe8DYfcJgAAAABJRU5ErkJggg==', "AWBBarCode");
    // -----------
    //echo Shipping::getShipmentRelation($stream, true);
    //unlink("/tmp/dhl-api-autoload.php");
    if (!$stream || !$stream->testReadLevel('see')) {
        throw new Users_Exception_NotAuthorized();
    }
    return Q::view('Shipping/content/scheduled.php', compact('streamName'));
}
Example #5
0
/**
 * Tool for admins to edit the url, title, keywords, description of the current page
 * @class Websites seo
 * @constructor
 * @param {Object} [$options] Options for the tool
 * @param {String} [$options.skipIfNotAuthorized=true] Whether to skip rendering the contents of the tool if the logged-in user is not authorized to edit the SEO information for this page.
 */
function Websites_seo_tool($options)
{
    $skipIfNotAuthorized = Q::ifset($options, 'skipIfNotAuthorized', true);
    if ($skipIfNotAuthorized) {
        $websitesUserId = Users::communityId();
        $sha1 = sha1(Q_Dispatcher::uri());
        $seoStreamName = "Websites/seo/{$sha1}";
        $stream = Streams::fetchOne(null, $websitesUserId, $seoStreamName);
        $user = Users::loggedInUser();
        if (!$user or $stream and !$stream->testWriteLevel('suggest')) {
            $options['skip'] = true;
        }
        if (!$stream and !Streams::isAuthorizedToCreate($user->id, $websitesUserId, 'Websites/seo')) {
            $options['skip'] = true;
        }
    }
    unset($options['skipIfNotAuthorized']);
    Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
    Q_Response::addScript("plugins/Websites/js/Websites.js");
    Q_Response::setToolOptions($options);
    $user = Users::loggedInUser(false, false);
    $userId = $user ? $user->id : "";
    $communityId = Users::communityId();
    $sha1 = sha1(Q_Dispatcher::uri());
    $seoStreamName = "Websites/seo/{$sha1}";
    $streams = Streams::fetch($userId, $communityId, array("Websites/header", "Websites/title", "Websites/slogan", $seoStreamName));
    foreach ($streams as $name => $s) {
        if ($s) {
            $s->addPreloaded($userId);
        }
    }
}
Example #6
0
function Websites_seo_post()
{
    if (empty($_REQUEST['streamName'])) {
        throw new Q_Exception_RequiredField(array('field' => 'streamName'));
    }
    $prefix = "Websites/seo/";
    if (substr($_REQUEST['streamName'], 0, strlen($prefix)) !== $prefix) {
        throw new Q_Exception_WrongValue(array('field' => 'streamName', 'range' => "string beginning with {$prefix}"));
    }
    $user = Users::loggedInUser(true);
    $publisherId = Users::communityId();
    $type = "Websites/seo";
    if (!Streams::isAuthorizedToCreate($user->id, $publisherId, $type)) {
        throw new Users_Exception_NotAuthorized();
    }
    $stream = new Streams_Stream($publisherId);
    $stream->publisherId = $publisherId;
    $stream->name = $_REQUEST['streamName'];
    $stream->type = $type;
    if (isset($_REQUEST['uri'])) {
        $stream->setAttribute('uri', $_REQUEST['uri']);
    }
    $stream->save();
    $stream->post($user->id, array('type' => 'Streams/created', 'content' => '', 'instructions' => Q::json_encode($stream->toArray())), true);
    $stream->subscribe();
    // autosubscribe to streams you yourself create, using templates
    Q_Response::setSlot('stream', $stream->exportArray());
}
function Websites_0_9_1_Streams_mysql()
{
    $userId = Users::communityId();
    $ofUserId = '';
    $ofContactLabel = 'Websites/admins';
    $grantedByUserId = null;
    $streams = array("Websites/presentation/" => array('type' => "Streams/template", "title" => "Untitled Presentation", "icon" => "{{baseUrl}}/plugins/Websites/img/icons/Websites/presentation", "content" => "", "deletable" => true), "Websites/slide/" => array('type' => "Streams/template", "title" => "Untitled Slide", "icon" => "{{baseUrl}}/plugins/Websites/img/icons/Websites/presentation", "content" => "", "deletable" => true));
    $readLevel = Streams::$READ_LEVEL['messages'];
    $adminLevel = Streams::$ADMIN_LEVEL['own'];
    $rows = array();
    foreach ($streams as $streamName => $stream) {
        $publisherId = substr($streamName, -1) == '/' ? '' : $userId;
        $level = !empty($stream['deletable']) ? 'close' : 'edit';
        $writeLevel = Streams::$WRITE_LEVEL[!empty($stream['deletable']) ? 'close' : 'edit'];
        $rows[] = compact('publisherId', 'streamName', 'ofUserId', 'ofContactLabel', 'grantedByUserId', 'readLevel', 'writeLevel', 'adminLevel');
    }
    Streams_Access::insertManyAndExecute($rows);
    $attributes = null;
    $closedTime = null;
    $readLevel = Streams::$READ_LEVEL['messages'];
    $writeLevel = Streams::$WRITE_LEVEL['join'];
    $adminLevel = Streams::$ADMIN_LEVEL['invite'];
    $inheritAccess = null;
    $rows = array();
    foreach ($streams as $name => $s) {
        extract($s);
        $publisherId = substr($name, -1) == '/' ? '' : $userId;
        $rows[] = compact('publisherId', 'name', 'type', 'title', 'icon', 'content', 'attributes', 'readLevel', 'writeLevel', 'adminLevel', 'inheritAccess');
    }
    Streams_Stream::insertManyAndExecute($rows);
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Websites/presentation/', 'type' => 'slides', 'fromPublisherId' => '', 'fromStreamName' => 'Websites/slide/'))->execute();
}
Example #8
0
function Shipping_shipment_response_content($params)
{
    $user = Users::loggedInUser(true);
    // copy from shipment
    $useTemplate = Q_Request::uri()->template ? "Shipping/shipment/" . Q_Request::uri()->template : false;
    // Check if stream "Shipping/shipments" exists for current user. If no -> create one.
    Shipping::shipments();
    // Check if stream "Shipping/templates" exists for current user. If no -> create one.
    Shipping::createTemplatesStream();
    // Collect streams for shipments. Relations: "describing", "scheduled", "confirmed", "shipping", "canceled", "returned"
    $shipment = Shipping::shipment();
    //$shipment->addPreloaded($userId);
    // test for UPS pickup
    //$stream = Streams::fetchOne("Shipping", "Shipping", "Shipping/shipment/Qdqpcspny");
    //$carrier = new Shipping_Carrier_UPS();
    //$carrier->pickupCreate($stream);
    //-------------------------------
    // add main style
    Q_Response::addStylesheet('css/Shipment.css');
    // set communityId
    Q_Response::setScriptData("Q.info.communityId", Users::communityId());
    Q_Response::setScriptData("Q.info.useTemplate", $useTemplate);
    Q_Response::addScript('js/shipment.js');
    Q_Response::addScript('js/date.js');
    // add jquery UI
    //Q_Response::addStylesheet('//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
    //Q_Response::addScript('//code.jquery.com/ui/1.11.4/jquery-ui.js');
    // add pickadate as date picker
    Q_Response::addStylesheet('js/pickadate/compressed/themes/default.css');
    Q_Response::addStylesheet('js/pickadate/compressed/themes/default.date.css');
    Q_Response::addScript('js/pickadate/compressed/picker.js');
    Q_Response::addScript('js/pickadate/compressed/picker.date.js');
    return Q::view('Shipping/content/shipment.php', compact('user', 'shipment', 'useTemplate'));
}
Example #9
0
/**
 * Used to create a new stream
 *
 * @param {array} $_REQUEST 
 * @param {string} [$_REQUEST.title] Required. The title of the interest.
 * @param {string} [$_REQUEST.publisherId] Optional. Defaults to the app name.
 * @return {void}
 */
function Streams_interest_delete()
{
    $user = Users::loggedInUser(true);
    $title = Q::ifset($_REQUEST, 'title', null);
    if (!isset($title)) {
        throw new Q_Exception_RequiredField(array('field' => 'title'));
    }
    $publisherId = Q::ifset($_REQUEST, 'publisherId', Users::communityId());
    $name = 'Streams/interest/' . Q_Utils::normalize($title);
    $stream = Streams::fetchOne(null, $publisherId, $name);
    if (!$stream) {
        throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => Q::json_encode(compact('publisherId', 'name'))));
    }
    $miPublisherId = $user->id;
    $miName = 'Streams/user/interests';
    $myInterests = Streams::fetchOne($user->id, $miPublisherId, $miName);
    if (!$myInterests) {
        throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => Q::json_encode(array('publisherId' => $miPublisherId, 'name' => $miName))));
    }
    $stream->leave();
    Streams::unrelate($user->id, $user->id, 'Streams/user/interests', 'Streams/interests', $publisherId, $name, array('adjustWeights' => true));
    Q_Response::setSlot('publisherId', $publisherId);
    Q_Response::setSlot('streamName', $name);
    /**
     * Occurs when the logged-in user has successfully removed an interest via HTTP
     * @event Streams/interest/delete {after}
     * @param {string} publisherId The publisher of the interest stream
     * @param {string} title The title of the interest
     * @param {Users_User} user The logged-in user
     * @param {Streams_Stream} stream The interest stream
     * @param {Streams_Stream} myInterests The user's "Streams/user/interests" stream
     */
    Q::event("Streams/interest/remove", compact('publisherId', 'title', 'subscribe', 'user', 'stream', 'myInterests'), 'after');
}
function Websites_0_8_Users_mysql()
{
    $userId = Users::communityId();
    Users_Label::addLabel('Websites/admins', $userId, 'Website Admins', 'labels/Websites/admins', false);
    if (!file_exists(USERS_PLUGIN_FILES_DIR . DS . 'Users' . DS . 'icons' . DS . 'Websites')) {
        Q_Utils::symlink(WEBSITES_PLUGIN_FILES_DIR . DS . 'Websites' . DS . 'icons' . DS . 'labels' . DS . 'Websites', USERS_PLUGIN_FILES_DIR . DS . 'Users' . DS . 'icons' . DS . 'labels' . DS . 'Websites');
    }
}
Example #11
0
function Trump_about_response_content()
{
    $publisherId = Users::communityId();
    $streamName = 'Communities/about';
    Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
    Q_Response::addScript("plugins/Websites/js/Websites.js");
    return Q::view("Communities/content/article.php", compact('publisherId', 'streamName'));
}
function Streams_0_8_4_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    $user = Users_User::fetch($communityId);
    // avatar for the App user
    $avatar = new Streams_Avatar();
    $avatar->toUserId = $communityId;
    $avatar->publisherId = $communityId;
    $avatar->username = $user->username;
    $avatar->firstName = Users::communityName();
    $avatar->lastName = Users::communitySuffix();
    $avatar->icon = $user->icon;
    $avatar->save();
    $avatar2 = new Streams_Avatar();
    $avatar2->copyFrom($avatar, null, false, true);
    $avatar->toUserId = '';
    $avatar->save();
    // access stream for managing app roles
    $stream = new Streams_Stream();
    $stream->publisherId = Users::communityId();
    $stream->name = 'Streams/contacts';
    $stream->type = 'Streams/resource';
    $stream->title = "Contacts";
    $stream->setAttribute('prefixes', array("Users/", "{$app}/"));
    $stream->save();
    // access stream for managing app roles
    $stream = new Streams_Stream();
    $stream->publisherId = $app;
    $stream->name = 'Streams/labels';
    $stream->type = 'Streams/resource';
    $stream->title = "Labels";
    $stream->setAttribute('prefixes', array("Users/", "{$app}/"));
    $stream->save();
    // access for managing app contacts
    $access = new Streams_Access();
    $access->publisherId = $communityId;
    $access->streamName = 'Streams/contacts';
    $access->ofUserId = '';
    $access->ofContactLabel = "{$app}/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['edit'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
    // access for managing app roles
    $access = new Streams_Access();
    $access->publisherId = $communityId;
    $access->streamName = 'Streams/labels';
    $access->ofUserId = '';
    $access->ofContactLabel = "{$app}/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['edit'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
}
Example #13
0
/**
 * Lets the user search for streams they can relate a given stream to, and relate it
 * @class Streams relate
 * @constructor
 * @param {array} [$options] Override various options for this tool
 * @param {string} $publisherId publisher id of the stream to relate
 * @param {string} $streamName name of stream to relate
 * @param {string} [$communityId=Users::communityId()] id of the user publishing the streams to relate to
 * @param {array} [$types=Q_Config::expect('Streams','relate','types')] the types of streams the user can select
 * @param {array} [$typeNames] pairs of array($type => $typeName) to override names of the types, which would otherwise be taken from the types
 * @param {Boolean} [options.multiple=true] whether the user can select multiple types for the lookup
 * @param {boolean} [$relateFrom=false] if true, will relate FROM the user-selected stream TO the streamName instead
 * @param {string} [$types=Q_Config::expect('Streams','relate','types')] the types of streams the user can select
 * @param {Q.Event} [$options.onRelate] This event handler occurs when a stream is successfully related
 */
function Streams_relate_tool($options)
{
    Q_Valid::requireFields(array('publisherId', 'streamName'), $options, true);
    if (!isset($options['communityId'])) {
        $options['communityId'] = Users::communityId();
    }
    if (!isset($options['types'])) {
        $options['types'] = Q_Config::get('Streams', 'relate', 'types', array());
    }
    Q_Response::setToolOptions($options);
    return '';
}
Example #14
0
/**
 * Used by HTTP clients to start a subscription
 * @class HTTP Assets subscription
 * @method post
 * @param {array} $_REQUEST
 * @param {string} $_REQUEST.payments Required. Should be either "authnet" or "stripe"
 *  @param {String} $_REQUEST.planStreamName the name of the subscription plan's stream
 *  @param {String} [$_REQUEST.planPublisherId=Users::communityId()] the publisher of the subscription plan's stream
 *  @param {String} [$_REQUEST.token=null] if using stripe, pass the token here
 */
function Assets_subscription_post($params = array())
{
    $req = array_merge($_REQUEST, $params);
    Q_Valid::requireFields(array('payments'), $req, true);
    // to be safe, we only start subscriptions from existing plans
    $planPublisherId = Q::ifset($req, 'planPublisherId', Users::communityId());
    $plan = Streams::fetchOne($planPublisherId, $planPublisherId, $req['planStreamName'], true);
    // the currency will always be assumed to be "USD" for now
    // and the amount will always be assumed to be in dollars, for now
    $token = Q::ifset($req, 'token', null);
    $subscription = Assets::startSubscription($plan, $req['payments'], compact('token'));
    Q_Response::setSlot('subscription', $subscription);
}
function Websites_0_8_4_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    // allow inserting images in articles
    $r = new Streams_RelatedTo();
    $r->toPublisherId = $communityId;
    $r->toStreamName = 'Websites/article/';
    $r->type = 'images';
    $r->fromPublisherId = $communityId;
    $r->fromStreamName = 'Streams/image/';
    $r->save();
}
function Streams_after_Users_setLoggedInUser($params)
{
    // if this the first time the user has ever logged in...
    $user = $params['user'];
    if ($user->sessionCount != 1) {
        return;
    }
    // subscribe to main community announcements
    $communityId = Users::communityId();
    $stream = Streams::fetchOne($user->id, $communityId, 'Streams/community/main');
    if ($stream and !$stream->subscription($user->id)) {
        $stream->subscribe();
    }
}
function Users_0_8_3_Users_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    $communityName = Q_Config::get('Users', 'community', 'name', $app);
    $appRootUrl = Q_Config::expect('Q', 'web', 'appRootUrl');
    $user = new Users_User();
    $user->id = $communityId;
    $user->username = $communityName;
    $user->url = $appRootUrl;
    $user->icon = "{$appRootUrl}/img/icon";
    $user->signedUpWith = 'none';
    $user->save();
}
function Users_before_Q_responseExtras()
{
    Q_Response::addScript('plugins/Users/js/Users.js');
    $app = Q_Config::expect('Q', 'app');
    $requireLogin = Q_Config::get('Users', 'requireLogin', array());
    $rl_array = array();
    foreach ($requireLogin as $rl => $value) {
        $rl_array[Q_Uri::url($rl)] = $value;
    }
    if (!Q_Request::isAjax()) {
        Q_Response::setScriptData('Q.plugins.Users.requireLogin', $rl_array);
        $successUrl = Q_Config::get('Users', 'uris', "{$app}/successUrl", "{$app}/home");
        $afterActivate = Q_Config::get('Users', 'uris', "{$app}/afterActivate", $successUrl);
        $loginOptions = Q_Config::get('Users', 'login', array("identifierType" => 'email,mobile', "userQueryUri" => 'Users/user', "using" => "native,facebook", "noRegister" => false));
        $loginOptions["afterActivate"] = Q_Uri::url($afterActivate);
        $loginOptions["successUrl"] = Q_Uri::url($successUrl);
        Q_Response::setScriptData('Q.plugins.Users.login.serverOptions', $loginOptions);
        $setIdentifierOptions = Q::take($loginOptions, array('identifierType'));
        Q_Response::setScriptData('Q.plugins.Users.setIdentifier.serverOptions', $setIdentifierOptions);
    }
    $fb_app_info = Q_Config::get('Users', 'facebookApps', $app, array());
    if ($fb_app_info) {
        unset($fb_app_info['secret']);
        Q_Response::setScriptData("Q.plugins.Users.facebookApps.{$app}", $fb_app_info);
    }
    if ($node_server_url = Q_Config::get('Users', 'nodeServer', 'url', null)) {
        Q_Response::setScriptData("Q.plugins.Users.nodeServer", parse_url($node_server_url));
    }
    if (Q_Config::get('Users', 'showLoggedInUser', true)) {
        $user = Q_Session::id() ? Users::loggedInUser() : null;
        if ($user) {
            $u = $user->exportArray();
            $u['sessionCount'] = $user->sessionCount;
            Q_Response::setScriptData("Q.plugins.Users.loggedInUser", $u);
            Q_Response::addScriptLine("Q.plugins.Users.loggedInUser = new Q.plugins.Users.User(Q.plugins.Users.loggedInUser);");
        }
    }
    Q_Response::setScriptData('Q.plugins.Users.communityId', Users::communityId());
    Q_Response::setScriptData('Q.plugins.Users.communityName', Users::communityName());
    Q_Response::setScriptData('Q.plugins.Users.communitySuffix', Users::communitySuffix());
    Q_Response::setScriptData('Q.plugins.Users.hinted', Q::ifset($_SESSION, 'Users', 'hinted', array()));
    if ($sizes = Q_Config::expect('Users', 'icon', 'sizes')) {
        sort($sizes);
        Q_Response::setScriptData('Q.plugins.Users.icon.sizes', $sizes);
    }
    $defaultSize = Q_Config::get('Users', 'icon', 'defaultSize', 40);
    Q_Response::setScriptData('Q.plugins.Users.icon.defaultSize', $defaultSize);
    Q_Response::addStylesheet("plugins/Users/css/Users.css");
}
function Websites_0_8_3_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    // access for managing communities
    $access = new Streams_Access();
    $access->publisherId = $communityId;
    $access->streamName = 'Streams/community*';
    $access->ofUserId = '';
    $access->ofContactLabel = "Websites/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['edit'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
}
Example #20
0
 /**
  * @param string [$publisherId] The id of the publisher relative to whom to calculate the roles. Defaults to the app name.
  * @param {string|array|Db_Expression} [$filter=null] 
  *  You can pass additional criteria here for the label field
  *  in the `Users_Contact::select`, such as an array or Db_Range
  * @param {array} [$options=array()] Any additional options to pass to the query, such as "ignoreCache"
  * @param {string} [$userId=null] If not passed, the logged in user is used, if any
  * @return {array} An associative array of $roleName => $contactRow pairs
  * @throws {Users_Exception_NotLoggedIn}
  */
 static function roles($publisherId = null, $filter = null, $options = array(), $userId = null)
 {
     if (empty($publisherId)) {
         $publisherId = Users::communityId();
     }
     if (!isset($userId)) {
         $user = Users::loggedInUser();
         if (!$user) {
             return array();
         }
         $userId = $user->id;
     }
     $contacts = Users_Contact::select('*')->where(array('userId' => $publisherId, 'contactUserId' => $userId))->andWhere($filter ? array('label' => $filter) : null)->options($options)->fetchDbRows(null, null, 'label');
     return $contacts;
 }
Example #21
0
function Streams_interests_response()
{
    // serve a javascript file and tell client to cache it
    $communityId = Q::ifset($_REQUEST, 'communityId', Users::communityId());
    $interests = Streams::interests($communityId);
    header('Content-Type: text/javascript');
    header("Pragma: ", true);
    // 1 day
    header("Cache-Control: public, max-age=86400");
    // 1 day
    $expires = date("D, d M Y H:i:s T", time() + 86400);
    header("Expires: {$expires}");
    // 1 day
    $json = Q::json_encode($interests, true);
    echo "Q.setObject(['Q', 'Streams', 'Interests', 'all', '{$communityId}'], {$json});";
    return false;
}
function Websites_before_Q_responseExtras()
{
    $user = Users::loggedInUser(false, false);
    $userId = $user ? $user->id : "";
    $websitesUserId = Users::communityId();
    $sha1 = sha1(Q_Dispatcher::uri());
    $seoStreamName = "Websites/seo/{$sha1}";
    $stream = Streams::fetchOne($userId, $websitesUserId, $seoStreamName);
    if ($stream) {
        $fields = Q::take($stream->getAllAttributes(), array('keywords', 'description'));
        foreach ($fields as $k => $v) {
            Q_Response::setMeta($k, $v);
        }
        Q_Response::setSlot('title', $stream->getAttribute('title'));
    }
    Q_Response::setScriptData('Q.plugins.Websites.seoStreamName', $seoStreamName);
    Q_Response::setScriptData('Q.plugins.Websites.userId', Users::communityId());
    Q_Response::setScriptData('Q.plugins.Websites.seoReload', Q_Config::expect('Websites', 'seoReload'));
}
Example #23
0
function Q_response_dashboard()
{
    $app = Q_Config::expect('Q', 'app');
    $slogan = "Powered by Q.";
    $user = Users::loggedInUser();
    $classes = array();
    if ($user) {
        $tabs = array('shipment' => 'Shipment', 'addresses' => 'Addresses', 'invited' => 'Invited Users', 'templates' => 'Templates', 'history' => 'History', 'about' => 'About Us');
        $communityId = Users::communityId();
        if (Users::roles($communityId, 'Shipping/admins')) {
            $tabs = array_merge($tabs, array('admin-users' => 'Users', 'admin-shipments' => 'Shipments', 'admin-reports' => 'Reports', 'admin-prices' => 'Prices'));
            $classes = array('admin-users' => 'Shipping_admins_only', 'admin-shipments' => 'Shipping_admins_only', 'admin-reports' => 'Shipping_admins_only', 'admin-prices' => 'Shipping_admins_only');
        }
    } else {
        $tabs = array('welcome' => 'Welcome', 'about' => 'About Us');
    }
    $urls = array('welcome' => 'Shipping/welcome', 'about' => 'Shipping/about', 'shipment' => 'Shipping/shipment', 'addresses' => 'Shipping/addresses', 'invited' => 'Shipping/invited', 'templates' => 'Shipping/templates', 'history' => 'Shipping/history', 'admin-users' => 'Shipping/admin-users', 'admin-shipments' => 'Shipping/admin-shipments', 'admin-reports' => 'Shipping/admin-reports', 'admin-prices' => 'Shipping/admin-prices', 'admin' => 'Shipping/admin');
    Q_Response::addStylesheet('plugins/Q/font-awesome/css/font-awesome.css');
    return Q::view("{$app}/dashboard.php", compact('slogan', 'user', 'tabs', 'urls', 'classes'));
}
function Websites_0_8_Streams_mysql()
{
    $userId = Users::communityId();
    // $now = Streams::db()->toDateTime(Streams::db()->getCurrentTimestamp());
    $ofUserId = '';
    $ofContactLabel = 'Websites/admins';
    $grantedByUserId = null;
    $streams = array("Streams/images/" => array('type' => "Streams/template", "title" => "Images", "icon" => "default", "content" => "", "deletable" => true), "Streams/image/" => array('type' => "Streams/template", "title" => "Untitled Image", "icon" => "Streams/image", "content" => "", "deletable" => true), "Streams/file/" => array('type' => "Streams/template", "title" => "Untitled File", "icon" => "files/_blank", "content" => "", "deletable" => true), "Websites/article/" => array('type' => "Streams/template", "title" => "Untitled Article", "icon" => "default", "content" => "", "deletable" => true), "Websites/seo/" => array('type' => "Streams/template", "title" => "Website SEO", "icon" => Q_Html::themedUrl("plugins/Websites/img/seo"), "content" => "", "deletable" => true), "Websites/header" => array('type' => "Streams/image/icon", "title" => "Header image", "icon" => Q_Html::themedUrl("plugins/Websites/img/header"), "content" => ""), "Websites/slogan" => array('type' => "Streams/text/small", "title" => "Website slogan", "icon" => "default", "content" => "The coolest website"), "Websites/title" => array('type' => "Streams/text/small", "title" => "Website title", "icon" => "default", "content" => "Website Title"), "Websites/menu" => array('type' => "Streams/category", "title" => "Website Menu", "icon" => "default", "content" => ""), "Websites/articles" => array('type' => "Streams/category", "title" => "Articles", "icon" => "default", "content" => "Articles"), "Websites/images" => array('type' => "Streams/images", "title" => "Images", "icon" => "default", "content" => "Images"));
    $readLevel = Streams::$READ_LEVEL['messages'];
    $adminLevel = Streams::$ADMIN_LEVEL['own'];
    $rows = array();
    foreach ($streams as $streamName => $stream) {
        $publisherId = substr($streamName, -1) == '/' ? '' : $userId;
        $level = !empty($stream['deletable']) ? 'close' : 'edit';
        $writeLevel = Streams::$WRITE_LEVEL[$level];
        $rows[] = compact('publisherId', 'streamName', 'ofUserId', 'ofContactLabel', 'grantedByUserId', 'readLevel', 'writeLevel', 'adminLevel');
    }
    Streams_Access::insertManyAndExecute($rows);
    $attributes = null;
    $closedTime = null;
    $readLevel = Streams::$READ_LEVEL['messages'];
    $writeLevel = Streams::$WRITE_LEVEL['join'];
    $adminLevel = Streams::$ADMIN_LEVEL['invite'];
    $inheritAccess = null;
    $rows = array();
    foreach ($streams as $name => $s) {
        extract($s);
        if (substr($name, 0, 9) != 'Websites/') {
            continue;
            // this tempate was already added by Streams install script
        }
        $publisherId = substr($name, -1) == '/' ? '' : $userId;
        $rows[] = compact('publisherId', 'name', 'type', 'title', 'icon', 'content', 'attributes', 'readLevel', 'writeLevel', 'adminLevel', 'inheritAccess');
    }
    Streams_Stream::insertManyAndExecute($rows);
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/images/', 'type' => 'images', 'fromPublisherId' => '', 'fromStreamName' => 'Streams/image/'))->execute();
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'articles', 'fromPublisherId' => '', 'fromStreamName' => 'Websites/article/'))->execute();
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'announcements', 'fromPublisherId' => '', 'fromStreamName' => 'Websites/article/'))->execute();
}
function Streams_0_8_1_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $commmunityId = Users::communityId();
    // template for community stream
    $stream = new Streams_Stream();
    $stream->publisherId = '';
    $stream->name = 'Streams/community/';
    $stream->type = 'Streams/template';
    $stream->title = "Community";
    $stream->content = '';
    $stream->readLevel = Streams::$READ_LEVEL['content'];
    $stream->writeLevel = Streams::$WRITE_LEVEL['join'];
    $stream->adminLevel = Streams::$ADMIN_LEVEL['invite'];
    $stream->save();
    // app community stream, for announcements
    Streams::create($commmunityId, $commmunityId, 'Streams/community', array('skipAccess' => true, 'name' => 'Streams/community/main', 'title' => Users::communityName()));
    // symlink the labels folder
    if (!file_exists('Streams')) {
        Q_Utils::symlink(STREAMS_PLUGIN_FILES_DIR . DS . 'Streams' . DS . 'icons' . DS . 'labels' . DS . 'Streams', USERS_PLUGIN_FILES_DIR . DS . 'Users' . DS . 'icons' . DS . 'labels' . DS . 'Streams');
    }
}
function Streams_0_8_7_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    $communityId = Users::communityId();
    $user = Users_User::fetch($communityId, true);
    $simulated = array('row' => $user, 'inserted' => true, 'modifiedFields' => $user->fields, 'query' => null);
    Q::event('Db/Row/Users_User/saveExecute', $simulated, 'after');
    $stream = array('publisherId' => '', 'name' => "Streams/images/", 'type' => 'Streams/template', 'title' => 'Image Gallery', 'icon' => 'default', 'content' => '', 'attributes' => null, 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['close'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']);
    $access = array('publisherId' => '', 'streamName' => "Streams/images/", 'ofUserId' => '', 'grantedByUserId' => null, 'ofContactLabel' => "{$app}/admins", 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['close'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']);
    Streams_Stream::insert($stream)->execute();
    Streams_Access::insert($access)->execute();
    $stream['name'] = $access['streamName'] = 'Streams/image/';
    $stream['icon'] = 'Streams/image';
    $stream['title'] = 'Untitled Image';
    Streams_Stream::insert($stream)->execute();
    Streams_Access::insert($access)->execute();
    $stream['name'] = $access['streamName'] = 'Streams/file/';
    $stream['icon'] = 'files/_blank';
    $stream['title'] = 'Untitled File';
    Streams_Stream::insert($stream)->execute();
    Streams_Access::insert($access)->execute();
}
Example #27
0
 /**
  * Get a structured, sorted array with all the interests in a community
  * @method interests
  * @static
  * @param {string} [$communityId=Users::communityId()] the id of the community
  * @return {array} an array of $category => ($subcategory =>) $interest
  */
 static function interests($communityId = null)
 {
     if (!isset($communityId)) {
         $communityId = Users::communityId();
     }
     $tree = new Q_Tree();
     $tree->load("files/Streams/interests/{$communityId}.json");
     $interests = $tree->getAll();
     foreach ($interests as $category => &$v1) {
         foreach ($v1 as $k2 => &$v2) {
             if (!Q::isAssociative($v2)) {
                 ksort($v1);
                 break;
             }
             ksort($v2);
         }
     }
     return $interests;
 }
Example #28
0
 /**
  * Starts a recurring subscription
  * @param {Streams_Stream} $plan The subscription plan stream
  * @param {string} [$payments=null] The type of payments processor, could be "authnet" or "stripe". If omitted, the subscription proceeds without any payments.
  * @param {array} [$options=array()] Options for the subscription
  * @param {date} [$options.startDate=today] The start date of the subscription
  * @param {date} [$options.endDate=today+year] The end date of the subscription
  * @param {Users_User} [$options.user=Users::loggedInUser()] Allows us to set the user to subscribe
  * @param {Users_User} [$options.publisherId=Users::communityId()] Allows us to override the publisher to subscribe to
  * @param {string} [$options.description=null] description of the charge, to be sent to customer
  * @param {string} [$options.metadata=null] any additional metadata to store with the charge
  * @param {string} [$options.subscription=null] if this charge is related to a subscription stream
  * @param {string} [$options.subscription.publisherId]
  * @param {string} [$options.subscription.streamName]
  * @throws Assets_Exception_DuplicateTransaction
  * @throws Assets_Exception_HeldForReview
  * @throws Assets_Exception_ChargeFailed
  * @return {Streams_Stream} A stream of type 'Assets/subscription' representing this subscription
  */
 static function startSubscription($plan, $payments = null, $options = array())
 {
     if (!isset($options['user'])) {
         $options['user'] = Users::loggedInUser(true);
     }
     $app = Q_Config::expect('Q', 'app');
     $user = Q::ifset($options, 'user', Users::loggedInUser(true));
     $currency = 'USD';
     // TODO: may want to implement support for currency conversion
     $startDate = Q::ifset($options, 'startDate', date("Y-m-d"));
     $startDate = date('Y-m-d', strtotime($startDate));
     $months = $plan->getAttribute('months', 12);
     $amount = $plan->getAttribute('amount');
     $endDate = date("Y-m-d", strtotime("-1 day", strtotime("+{$months} month", strtotime($startDate))));
     $endDate = date('Y-m-d', strtotime($endDate));
     $publisherId = Q::ifset($options, 'publisherId', Users::communityId());
     $publisher = Users_User::fetch($publisherId);
     $streamName = "Assets/subscription/{$user->id}/{$plan->name}";
     if ($subscription = Streams::fetchOne($publisherId, $publisherId, $streamName)) {
         return $subscription;
         // it already started
     }
     $attributes = Q::json_encode(array('payments' => $payments, 'planPublisherId' => $plan->publisherId, 'planStreamName' => $plan->name, 'startDate' => $startDate, 'endDate' => $endDate, 'months' => $months, 'amount' => $amount, 'currency' => $currency));
     $stream = Streams::create($publisherId, $publisherId, "Assets/subscription", array('name' => $streamName, 'title' => $plan->title, 'readLevel' => Streams::$READ_LEVEL['none'], 'writeLevel' => Streams::$WRITE_LEVEL['none'], 'adminLevel' => Streams::$ADMIN_LEVEL['none'], 'attributes' => $attributes));
     $access = new Streams_Access(array('publisherId' => $publisherId, 'streamName' => $streamName, 'ofUserId' => $user->id, 'grantedByUserId' => $app, 'readLevel' => Streams::$READ_LEVEL['max'], 'writeLevel' => -1, 'adminLevel' => -1));
     $access->save();
     $amount = $plan->getAttribute('amount', null);
     if (!is_numeric($amount)) {
         throw new Q_Exception_WrongValue(array('field' => 'amount', 'range' => 'an integer'));
     }
     $options['stream'] = $stream;
     if ($payments) {
         Assets::charge($payments, $amount, $currency, $options);
     }
     /**
      * @event Assets/startSubscription {before}
      * @param {Streams_Stream} plan
      * @param {Streams_Stream} subscription
      * @param {string} startDate
      * @param {string} endDate
      * @return {Users_User}
      */
     Q::event('Assets/startSubscription', compact('plan', 'user', 'publisher', 'stream', 'startDate', 'endDate', 'months', 'currency'), 'after');
     return $stream;
 }
function Streams_after_Users_User_saveExecute($params)
{
    // If the username or icon was somehow modified,
    // update all the avatars for this publisher
    $modifiedFields = $params['modifiedFields'];
    $user = $params['row'];
    $updates = array();
    if (isset($modifiedFields['username'])) {
        $updates['username'] = $modifiedFields['username'];
    }
    if (isset($modifiedFields['icon'])) {
        $updates['icon'] = $modifiedFields['icon'];
    }
    if ($user->id === Users::communityId()) {
        $firstName = Users::communityName();
        $lastName = Users::communitySuffix();
        $firstName = $firstName ? $firstName : "";
        $lastName = $lastName ? $lastName : "";
    } else {
        $firstName = Q::ifset(Streams::$cache, 'register', 'first', '');
        $lastName = Q::ifset(Streams::$cache, 'register', 'last', '');
    }
    if ($params['inserted']) {
        // create some standard streams for them
        $onInsert = Q_Config::get('Streams', 'onInsert', 'Users_User', array());
        if (!$onInsert) {
            return;
        }
        $p = new Q_Tree();
        $p->load(STREAMS_PLUGIN_CONFIG_DIR . DS . 'streams.json');
        $p->load(APP_CONFIG_DIR . DS . 'streams.json');
        $values = array('Streams/user/firstName' => $firstName, 'Streams/user/lastName' => $lastName);
        // Check for user data from facebook
        if (!empty(Users::$cache['facebookUserData'])) {
            $userData = Users::$cache['facebookUserData'];
            foreach ($userData as $name_fb => $value) {
                foreach ($p->getAll() as $name => $info) {
                    if (isset($info['name_fb']) and $info['name_fb'] === $name_fb) {
                        $onInsert[] = $name;
                        $values[$name] = $value;
                    }
                }
            }
        }
        foreach ($onInsert as $name) {
            $stream = Streams::fetchOne($user->id, $user->id, $name);
            if (!$stream) {
                // it shouldn't really be in the db yet
                $stream = new Streams_Stream();
                $stream->publisherId = $user->id;
                $stream->name = $name;
            }
            $stream->type = $p->expect($name, "type");
            $stream->title = $p->expect($name, "title");
            $stream->content = $p->get($name, "content", '');
            // usually empty
            $stream->readLevel = $p->get($name, 'readLevel', Streams_Stream::$DEFAULTS['readLevel']);
            $stream->writeLevel = $p->get($name, 'writeLevel', Streams_Stream::$DEFAULTS['writeLevel']);
            $stream->adminLevel = $p->get($name, 'adminLevel', Streams_Stream::$DEFAULTS['adminLevel']);
            if ($name === "Streams/user/icon") {
                $sizes = Q_Config::expect('Users', 'icon', 'sizes');
                sort($sizes);
                $stream->setAttribute('sizes', $sizes);
                $stream->icon = $user->iconUrl();
            }
            if (isset($values[$name])) {
                $stream->content = $values[$name];
            }
            $stream->save();
            // this also inserts avatars
            $o = array('userId' => $user->id, 'skipAccess' => true);
            $so = $p->get($name, "subscribe", array());
            if ($so === false) {
                $stream->join($o);
            } else {
                $stream->subscribe(array_merge($o, $so));
            }
        }
        // Save a greeting stream, to be edited
        $communityId = Users::communityId();
        Streams::create($user->id, $user->id, "Streams/greeting", array('name' => "Streams/greeting/{$communityId}"));
        // Create some standard labels
        $label = new Users_Label();
        $label->userId = $user->id;
        $label->label = 'Streams/invited';
        $label->icon = 'labels/Streams/invited';
        $label->title = 'People I invited';
        $label->save(true);
        $label2 = new Users_Label();
        $label2->userId = $user->id;
        $label2->label = 'Streams/invitedMe';
        $label2->icon = 'labels/Streams/invitedMe';
        $label2->title = 'Who invited me';
        $label2->save(true);
        // By default, users they invite should see their full name
        $access = new Streams_Access();
        $access->publisherId = $user->id;
        $access->streamName = 'Streams/user/firstName';
        $access->ofUserId = '';
        $access->ofContactLabel = 'Streams/invited';
        $access->grantedByUserId = $user->id;
        $access->readLevel = Streams::$READ_LEVEL['content'];
        $access->writeLevel = -1;
        $access->adminLevel = -1;
        $access->save();
        $access = new Streams_Access();
        $access->publisherId = $user->id;
        $access->streamName = 'Streams/user/lastName';
        $access->ofUserId = '';
        $access->ofContactLabel = 'Streams/invited';
        $access->grantedByUserId = $user->id;
        $access->readLevel = Streams::$READ_LEVEL['content'];
        $access->writeLevel = -1;
        $access->adminLevel = -1;
        $access->save();
        // NOTE: the above saving of access caused Streams::updateAvatar to run,
        // insert a Streams_Avatar row for the new user, and properly configure it.
    } else {
        if ($modifiedFields) {
            if ($updates) {
                Streams_Avatar::update()->set($updates)->where(array('publisherId' => $user->id))->execute();
            }
            foreach ($modifiedFields as $field => $value) {
                $name = Q_Config::get('Streams', 'onUpdate', 'Users_User', $field, null);
                if (!$name) {
                    continue;
                }
                $stream = isset(Streams::$beingSaved[$field]) ? Streams::$beingSaved[$field] : Streams::fetchOne($user->id, $user->id, $name);
                if (!$stream) {
                    // it should probably already be in the db
                    continue;
                }
                $stream->content = $value;
                if ($name === "Streams/user/icon") {
                    $sizes = Q_Config::expect('Users', 'icon', 'sizes');
                    sort($sizes);
                    $attributes = $stream->attributes;
                    $stream->setAttribute('sizes', $sizes);
                    $stream->icon = $changes['icon'] = $user->iconUrl();
                }
                Streams::$beingSavedQuery = $stream->changed($user->id);
            }
        }
    }
}
Example #30
0
/**
 * Used by HTTP clients to create a new interest in the system.
 * @class HTTP Streams interest
 * @method post
 *
 * @param {array} $_REQUEST 
 * @param {string} [$_REQUEST.title] Required. The title of the interest.
 * @param {string} [$_REQUEST.publisherId] Optional. Defaults to the app name.
 * @param {string} [$_REQUEST.subscribe] Optional. Defauls to false. Whether to subscribe rather than just join the interest stream.
 * @return {void}
 */
function Streams_interest_post()
{
    $user = Users::loggedInUser(true);
    $title = Q::ifset($_REQUEST, 'title', null);
    if (!isset($title)) {
        throw new Q_Exception_RequiredField(array('field' => 'title'));
    }
    $publisherId = Q::ifset($_REQUEST, 'publisherId', Users::communityId());
    $name = 'Streams/interest/' . Q_Utils::normalize($title);
    $stream = Streams::fetchOne(null, $publisherId, $name);
    if (!$stream) {
        $stream = Streams::create($publisherId, $publisherId, 'Streams/interest', array('name' => $name, 'title' => $title));
        if (is_dir(APP_WEB_DIR . DS . "plugins" . DS . "Streams" . DS . "img" . DS . "icons" . DS . $name)) {
            $stream->icon = $name;
        } else {
            $parts = explode(': ', $title, 2);
            $keywords = implode(' ', $parts);
            $tries = array($keywords, $parts[1]);
            $data = null;
            foreach ($tries as $t) {
                try {
                    $data = Q_Image::pixabay($t, array('orientation' => 'horizontal', 'min_width' => '500', 'safesearch' => 'true', 'image_type' => 'photo'), true);
                } catch (Exception $e) {
                    Q::log("Exception during Streams/interest post: " . $e->getMessage());
                    $data = null;
                }
                if ($data) {
                    break;
                }
            }
            if ($data) {
                $sizes = Q_Config::expect('Streams', 'icons', 'sizes');
                ksort($sizes);
                $params = array('data' => $data, 'path' => "plugins/Streams/img/icons", 'subpath' => $name, 'save' => $sizes, 'skipAccess' => true);
                Q_Image::save($params);
                $stream->icon = $name;
            }
        }
        $stream->save();
    }
    $subscribe = !!Q::ifset($_REQUEST, 'subscribe', false);
    if ($subscribe) {
        $stream->subscribe();
    } else {
        $stream->join();
    }
    $myInterestsName = 'Streams/user/interests';
    $myInterests = Streams::fetchOne($user->id, $user->id, $myInterestsName);
    if (!$myInterests) {
        $myInterests = new Streams_Stream();
        $myInterests->publisherId = $user->id;
        $myInterests->name = $myInterestsName;
        $myInterests->type = 'Streams/category';
        $myInterests->title = 'My Interests';
        $myInterests->save();
    }
    Streams::relate($user->id, $user->id, 'Streams/user/interests', 'Streams/interests', $publisherId, $name, array('weight' => '+1'));
    Q_Response::setSlot('publisherId', $publisherId);
    Q_Response::setSlot('streamName', $name);
    /**
     * Occurs when the logged-in user has successfully added an interest via HTTP
     * @event Streams/interest/post {after}
     * @param {string} publisherId The publisher of the interest stream
     * @param {string} title The title of the interest
     * @param {boolean} subscribe Whether the user subscribed to the interest stream
     * @param {Users_User} user The logged-in user
     * @param {Streams_Stream} stream The interest stream
     * @param {Streams_Stream} myInterests The user's "Streams/user/interests" stream
     */
    Q::event("Streams/interest/add", compact('publisherId', 'title', 'subscribe', 'user', 'stream', 'myInterests'), 'after');
}