当前位置: 首页>>代码示例>>PHP>>正文


PHP Q::json_encode方法代码示例

本文整理汇总了PHP中Q::json_encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Q::json_encode方法的具体用法?PHP Q::json_encode怎么用?PHP Q::json_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Q的用法示例。


在下文中一共展示了Q::json_encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: walk

 /**
  * Helper function for walking the Mustache token parse tree.
  *
  * @throws {InvalidArgumentException} upon encountering unknown token types.
  *
  * @param array $tree  Parse tree of Mustache tokens
  * @param int   $level (default: 0)
  *
  * @return {string} Generated PHP source code
  */
 private function walk(array $tree, $level = 0)
 {
     $code = '';
     $level++;
     foreach ($tree as $node) {
         switch ($node[Mustache_Tokenizer::TYPE]) {
             case Mustache_Tokenizer::T_SECTION:
                 $code .= $this->section($node[Mustache_Tokenizer::NODES], $node[Mustache_Tokenizer::NAME], $node[Mustache_Tokenizer::INDEX], $node[Mustache_Tokenizer::END], $node[Mustache_Tokenizer::OTAG], $node[Mustache_Tokenizer::CTAG], $level);
                 break;
             case Mustache_Tokenizer::T_INVERTED:
                 $code .= $this->invertedSection($node[Mustache_Tokenizer::NODES], $node[Mustache_Tokenizer::NAME], $level);
                 break;
             case Mustache_Tokenizer::T_PARTIAL:
             case Mustache_Tokenizer::T_PARTIAL_2:
                 $code .= $this->partial($node[Mustache_Tokenizer::NAME], isset($node[Mustache_Tokenizer::INDENT]) ? $node[Mustache_Tokenizer::INDENT] : '', $level);
                 break;
             case Mustache_Tokenizer::T_UNESCAPED:
             case Mustache_Tokenizer::T_UNESCAPED_2:
                 $code .= $this->variable($node[Mustache_Tokenizer::NAME], false, $level);
                 break;
             case Mustache_Tokenizer::T_COMMENT:
                 break;
             case Mustache_Tokenizer::T_ESCAPED:
                 $code .= $this->variable($node[Mustache_Tokenizer::NAME], true, $level);
                 break;
             case Mustache_Tokenizer::T_TEXT:
                 $code .= $this->text($node[Mustache_Tokenizer::VALUE], $level);
                 break;
             default:
                 throw new InvalidArgumentException('Unknown node type: ' . Q::json_encode($node));
         }
     }
     return $code;
 }
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:44,代码来源:Compiler.php

示例2: Streams_interests_response

function Streams_interests_response()
{
    // serve a javascript file and tell client to cache it
    $app = Q_Config::expect('Q', 'app');
    $communityId = Q::ifset($_REQUEST, 'communityId', $app);
    $tree = new Q_Tree();
    $tree->load("files/Streams/interests/{$communityId}.json");
    $categories = $tree->getAll();
    foreach ($categories as $category => &$v1) {
        foreach ($v1 as $k2 => &$v2) {
            if (!Q::isAssociative($v2)) {
                ksort($v1);
                break;
            }
            ksort($v2);
        }
    }
    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($categories, true);
    echo "Q.setObject(['Q', 'Streams', 'Interests', 'all', '{$communityId}'], {$json});";
    return false;
}
开发者ID:dmitriz,项目名称:Platform,代码行数:29,代码来源:response.php

示例3: Streams_interest_delete

/**
 * 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'));
    }
    $app = Q_Config::expect('Q', 'app');
    $publisherId = Q::ifset($_REQUEST, 'publisherId', $app);
    $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/interest', $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');
}
开发者ID:dmitriz,项目名称:Platform,代码行数:43,代码来源:delete.php

示例4: Broadcast_before_Streams_message_Broadcast

function Broadcast_before_Streams_message_Broadcast($params)
{
    extract($params);
    if (!empty($_REQUEST['link'])) {
        $parts = parse_url($_REQUEST['link']);
        if (empty($parts['host'])) {
            throw new Q_Exception_WrongType(array('field' => 'link', 'type' => 'a valid url'), 'link');
        }
    }
    $content = array();
    foreach (array('link', 'description', 'picture') as $field) {
        if (!empty($_REQUEST[$field])) {
            $content[$field] = $_REQUEST[$field];
        }
    }
    if (!empty($_REQUEST['content'])) {
        $content['message'] = $_REQUEST['content'];
    }
    if (!$content) {
        throw new Q_Exception_RequiredField(array('field' => 'content'), 'content');
    }
    // Manually adding a link for 'Manage or Remove'
    $appUrl = Q_Config::get('Users', 'facebookApps', 'Broadcast', 'url', '');
    $content['actions'] = Q::json_encode(array(array('name' => 'Manage or Remove', 'link' => $appUrl)));
    $message->broadcast_instructions = Q::json_encode($content);
}
开发者ID:dmitriz,项目名称:Platform,代码行数:26,代码来源:Broadcast.php

示例5: Websites_seo_post

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());
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:28,代码来源:post.php

示例6: Users_before_Q_session_save

function Users_before_Q_session_save($params)
{
    $row = $params['row'];
    $row->deviceId = "";
    $row->timeout = 0;
    $row->content = isset($_SESSION) ? Q::json_encode($_SESSION, JSON_FORCE_OBJECT) : "{}";
    $row->duration = Q_Config::get('Q', 'session', 'durations', Q_Request::formFactor(), Q_Config::expect('Q', 'session', 'durations', 'session'));
}
开发者ID:dmitriz,项目名称:Platform,代码行数:8,代码来源:Q_session_save.php

示例7: Q_columns_tool

/**
 * This tool contains functionality to show things in columns
 * @class Q columns
 * @constructor
 * @param {array}   [options] Provide options for this tool
 *  @param {array}  [options.animation] For customizing animated transitions
 *  @param {integer}  [options.animation.duration] The duration of the transition in milliseconds, defaults to 500
 *  @param {array}  [options.animation.hide] The css properties in "hide" state of animation
 *  @param {array}  [options.animation.show] The css properties in "show" state of animation
 *  @param {array}  [options.back] For customizing the back button on mobile
 *  @param {string}  [options.back.src] The src of the image to use for the back button
 *  @param {boolean} [options.back.triggerFromTitle] Whether the whole title would be a trigger for the back button. Defaults to true.
 *  @param {boolean} [options.back.hide] Whether to hide the back button. Defaults to false, but you can pass true on android, for example.
 *  @param {array}  [options.close] For customizing the back button on desktop and tablet
 *  @param {string}  [options.close.src] The src of the image to use for the close button
 *  @param {string}  [options.title] You can put a default title for all columns here (which is shown as they are loading)
 *  @param {string}  [options.column] You can put a default content for all columns here (which is shown as they are loading)
 *  @param {array}  [options.clickable] If not null, enables the Q/clickable tool with options from here. Defaults to null.
 *  @param {array}  [options.scrollbarsAutoHide] If not null, enables Q/scrollbarsAutoHide functionality with options from here. Enabled by default.
 *  @param {boolean} [options.fullscreen] Whether to use fullscreen mode on mobile phones, using document to scroll instead of relying on possibly buggy "overflow" CSS implementation. Defaults to true on Android, false everywhere else.
 *  @param {array}   [options.columns] In PHP only, an array of $name => $column pairs, where $column is in the form array('title' => $html, 'content' => $html, 'close' => true)
 * @return {string}
 */
function Q_columns_tool($options)
{
    $jsOptions = array('animation', 'back', 'close', 'title', 'scrollbarsAutoHide', 'fullscreen');
    Q_Response::setToolOptions(Q::take($options, $jsOptions));
    if (!isset($options['columns'])) {
        return '';
    }
    Q_Response::addScript('plugins/Q/js/tools/columns.js');
    Q_Response::addStylesheet('plugins/Q/css/columns.css');
    $result = '<div class="Q_columns_container Q_clearfix">';
    $columns = array();
    $i = 0;
    $closeSrc = Q::ifset($options, 'close', 'src', 'plugins/Q/img/x.png');
    $backSrc = Q::ifset($options, 'back', 'src', 'plugins/Q/img/back-v.png');
    foreach ($options['columns'] as $name => $column) {
        $close = Q::ifset($column, 'close', $i > 0);
        $Q_close = Q_Request::isMobile() ? 'Q_close' : 'Q_close Q_back';
        $closeHtml = !$close ? '' : (Q_Request::isMobile() ? '<div class="Q_close Q_back">' . Q_Html::img($backSrc, 'Back') . '</div>' : '<div class="Q_close">' . Q_Html::img($closeSrc, 'Close') . '</div>');
        $n = Q_Html::text($name);
        $columnClass = 'Q_column_' . Q_Utils::normalize($name) . ' Q_column_' . $i;
        if (isset($column['html'])) {
            $html = $column['html'];
            $columns[] = <<<EOT
\t<div class="Q_columns_column {$columnClass}" data-index="{$i}" data-name="{$n}">
\t\t{$html}
\t</div>
EOT;
        } else {
            $titleHtml = Q::ifset($column, 'title', '[title]');
            $columnHtml = Q::ifset($column, 'column', '[column]');
            $classes = $columnClass . ' ' . Q::ifset($column, 'class', '');
            $attrs = '';
            if (isset($column['data'])) {
                $json = Q::json_encode($column['data']);
                $attrs = 'data-more="' . Q_Html::text($json) . '"';
                foreach ($column['data'] as $k => $v) {
                    $attrs .= 'data-' . Q_Html::text($k) . '="' . Q_Html::text($v) . '" ';
                }
            }
            $data = Q::ifset($column, 'data', '');
            $columns[] = <<<EOT
\t<div class="Q_columns_column {$classes}" data-index="{$i}" data-name="{$n}" {$attrs}>
\t\t<div class="Q_columns_title">
\t\t\t{$closeHtml}
\t\t\t<h2 class="Q_title_slot">{$titleHtml}</h2>
\t\t</div>
\t\t<div class="Q_column_slot">{$columnHtml}</div>
\t</div>
EOT;
        }
        ++$i;
    }
    $result .= "\n" . implode("\n", $columns) . "\n</div>";
    return $result;
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:78,代码来源:tool.php

示例8: Platform_api_response

function Platform_api_response()
{
    $result = array();
    if ($_REQUEST['discover']) {
        $discover = $_REQUEST['discover'];
        if (is_string($discover)) {
            $discover = explode(',', $_REQUEST['discover']);
        }
        $discover = array_flip($discover);
        if (isset($discover['user'])) {
            $result['user'] = 'itzabhws';
        }
        if (isset($discover['contacts'])) {
            $result['contacts'] = array('bhbsneuc' => array('labels' => array(1, 4)), 'bgeoekat' => array('labels' => array(1, 7)));
        }
    }
    $json = Q::json_encode($result);
    $referer = $_SERVER['HTTP_REFERER'];
    $parts = parse_url($referer);
    $origin = Q::json_encode($parts['scheme'] . '://' . $parts['host']);
    $appUrl = Q::json_encode(Q_Request::baseUrl());
    echo <<<EOT
<!doctype html>
<html>
    <head>
        <title>Qbix Platform</title>
\t\t<script type="text/javascript">
\t\twindow.addEventListener("message", receiveMessage, false);
\t\tfunction receiveMessage(event) {
\t\t\tvar request = event.data;
\t\t\tvar response = '';
\t\t\tif (!request.method) {
\t\t\t\tresponse = {"error": "Missing method"};
\t\t\t}
\t\t\tif (request.appUrl.substr(0, event.origin.length) !== event.origin) {
\t\t\t\tresponse = {"error": "Origin doesn't match"};
\t\t\t} else {
\t\t\t\tresponse = {$json};
\t\t\t}
\t\t\twindow.parent.postMessage(response, {$origin});
\t\t}
\t\tvar ExposedMethods = function () {
\t
\t\t};
\t\t</script>
    </head>
    <body>
    </body>
</html>
EOT;
    return false;
}
开发者ID:dmitriz,项目名称:Platform,代码行数:52,代码来源:response.php

示例9: Streams_form_tool

/**
 * Generates a form with inputs that modify various streams
 * @class Streams form
 * @constructor
 * @param {array} $options
 *  An associative array of parameters, containing:
 * @param {array} [$options.fields] an associative array of $id => $fieldinfo pairs,
 *   where $id is the id to append to the tool's id, to generate the input's id,
 *   and fieldinfo is either an associative array with the following fields,
 *   or a regular array consisting of fields in the following order:
 *     "publisherId" => Required. The id of the user publishing the stream
 *     "streamName" => Required. The name of the stream
 *     "field" => The stream field to edit, or "attribute:$attributeName" for an attribute.
 *     "input" => The type of the input (@see Q_Html::smartTag())
 *     "attributes" => Additional attributes for the input
 *     "options" => options for the input (if type is "select", "checkboxes" or "radios")
 *     "params" => array of extra parameters to Q_Html::smartTag
 */
function Streams_form_tool($options)
{
    $fields = Q::ifset($options, 'fields', array());
    $defaults = array('publisherId' => null, 'streamName' => null, 'field' => null, 'type' => 'text', 'attributes' => array(), 'value' => array(), 'options' => array(), 'params' => array());
    $sections = array();
    $hidden = array();
    $contents = '';
    foreach ($fields as $id => $field) {
        if (Q::isAssociative($field)) {
            $r = Q::take($field, $defaults);
        } else {
            $c = count($field);
            if ($c < 4) {
                throw new Q_Exception("Streams/form tool: field needs at least 4 values");
            }
            $r = array('publisherId' => $field[0], 'streamName' => $field[1], 'field' => $field[2], 'type' => $field[3], 'attributes' => isset($field[4]) ? $field[4] : array(), 'value' => isset($field[5]) ? $field[5] : '', 'options' => isset($field[6]) ? $field[6] : null, 'params' => isset($field[7]) ? $field[7] : null);
        }
        $r['attributes']['name'] = "input_{$id}";
        if (!isset($r['type'])) {
            var_dump($r['type']);
            exit;
        }
        $stream = Streams::fetchOne(null, $r['publisherId'], $r['streamName']);
        if ($stream) {
            if (substr($r['field'], 0, 10) === 'attribute:') {
                $attribute = trim(substr($r['field'], 10));
                $value = $stream->get($attribute, $r['value']);
            } else {
                $field = $r['field'];
                $value = $stream->{$field};
            }
        } else {
            $value = $r['value'];
        }
        $tag = Q_Html::smartTag($r['type'], $r['attributes'], $value, $r['options'], $r['params']);
        $class1 = 'publisherId_' . Q_Utils::normalize($r['publisherId']);
        $class2 = 'streamName_' . Q_Utils::normalize($r['streamName']);
        $contents .= "<span class='Q_before {$class1} {$class2}'></span>" . Q_Html::tag('span', array('data-publisherId' => $r['publisherId'], 'data-streamName' => $r['streamName'], 'data-field' => $r['field'], 'data-type' => $r['type'], 'class' => "{$class1} {$class2}"), $tag);
        $hidden[$id] = array(!!$stream, $r['publisherId'], $r['streamName'], $r['field']);
    }
    $contents .= Q_Html::hidden(array('inputs' => Q::json_encode($hidden)));
    return Q_Html::form('Streams/form', 'post', array(), $contents);
    //
    // $fields = array('onSubmit', 'onResponse', 'onSuccess', 'slotsToRequest', 'loader', 'contentElements');
    // Q_Response::setToolOptions(Q::take($options, $fields));
    // Q_Response::addScript('plugins/Q/js/tools/form.js');
    // Q_Response::addStylesheet('plugins/Q/css/form.css');
    // return $result;
}
开发者ID:dmitriz,项目名称:Platform,代码行数:67,代码来源:tool.php

示例10: Q_scripts_combine

function Q_scripts_combine()
{
    $environment = Q_Config::get('Q', 'environment', false);
    if (!$environment) {
        return "Config field 'Q'/'environment' is empty";
    }
    $files = Q_Config::get('Q', 'environments', $environment, 'files', Q_Config::get('Q', 'environments', '*', 'files', false));
    if (empty($files)) {
        return "Config field 'Q'/'environments'/'{$environment}'/files is empty";
    }
    $filters = Q_Config::get('Q', 'environments', $environment, 'filters', Q_Config::get('Q', 'environments', '*', 'filters', false));
    if (empty($filters)) {
        return "Config field 'Q'/'environments'/'{$environment}'/filters is empty";
    }
    $combined = array();
    foreach ($files as $src => $dest) {
        $f = Q_Uri::filenameFromUrl(Q_Html::themedUrl($src, true));
        if (!file_exists($f)) {
            return "Aborting: File corresponding to {$src} doesn't exist";
        }
        $content = file_get_contents($f);
        $combined[$dest][$src] = $content;
    }
    foreach ($combined as $dest => $parts) {
        $df = Q_Uri::filenameFromUrl(Q_Html::themedUrl($dest));
        $ext = pathinfo($df, PATHINFO_EXTENSION);
        echo "Writing {$df}\n";
        if (!empty($filters)) {
            foreach ($filters as $e => $filter) {
                if ($ext !== $e) {
                    continue;
                }
                $p = !empty($filter['params']) ? Q::json_encode($filter['params']) : '';
                echo "\t" . $filter['handler'] . "{$p}\n";
                foreach ($parts as $src => $part) {
                    echo "\t\t{$src}\n";
                }
                $params = compact('dest', 'parts');
                if (!empty($filter['params'])) {
                    $params = array_merge($params, $filter['params']);
                }
                $content = Q::event($filter['handler'], $params);
            }
        }
        file_put_contents($df, $content);
    }
    echo "Success.";
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:48,代码来源:combine.php

示例11: Q_after_Q_tool_render

function Q_after_Q_tool_render($params, &$result)
{
    $info = $params['info'];
    $extra = $params['extra'];
    if (!is_array($extra)) {
        $extra = array();
    }
    $id_prefix = Q_Html::getIdPrefix();
    $tool_ids = Q_Html::getToolIds();
    $tag = Q::ifset($extra, 'tag', 'div');
    if (empty($tag)) {
        Q_Html::popIdPrefix();
        return;
    }
    $classes = '';
    $data_options = '';
    $count = count($info);
    foreach ($info as $name => $opt) {
        $classes = ($classes ? "{$classes} " : $classes) . implode('_', explode('/', $name)) . '_tool';
        $options = Q_Response::getToolOptions($name);
        if (isset($options)) {
            $friendly_options = str_replace(array('&quot;', '\\/'), array('"', '/'), Q_Html::text(Q::json_encode($options)));
        } else {
            $friendly_options = '';
        }
        $normalized = Q_Utils::normalize($name, '-');
        if (isset($options) or $count > 1) {
            $id = $tool_ids[$name];
            $id_string = $count > 1 ? "{$id} " : '';
            $data_options .= " data-{$normalized}='{$id_string}{$friendly_options}'";
        }
        $names[] = $name;
    }
    if (isset($extra['classes'])) {
        $classes .= ' ' . $extra['classes'];
    }
    $attributes = isset($extra['attributes']) ? ' ' . Q_Html::attributes($extra['attributes']) : '';
    $data_retain = !empty($extra['retain']) || Q_Response::shouldRetainTool($id_prefix) ? " data-Q-retain=''" : '';
    $data_replace = !empty($extra['replace']) || Q_Response::shouldReplaceWithTool($id_prefix) ? " data-Q-replace=''" : '';
    $names = $count === 1 ? ' ' . key($info) : 's ' . implode(" ", $names);
    $ajax = Q_Request::isAjax();
    $result = "<{$tag} id='{$id_prefix}tool' " . "class='Q_tool {$classes}'{$data_options}{$data_retain}{$data_replace}{$attributes}>" . "{$result}</{$tag}>";
    if (!Q_Request::isAjax()) {
        $result = "<!--\nbegin tool{$names}\n-->{$result}<!--\nend tool{$names} \n-->";
    }
    Q_Html::popIdPrefix();
}
开发者ID:dmitriz,项目名称:Platform,代码行数:47,代码来源:render.php

示例12: Streams_interests_response

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;
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:17,代码来源:response.php

示例13: Streams_after_Streams_message_Streams_unrelatedTo

function Streams_after_Streams_message_Streams_unrelatedTo($params)
{
    $message = $params['message'];
    $type = $message->getInstruction('type', null);
    $stream = $params['stream'];
    $rtypes = Q_Config::get('Streams', 'categorize', 'relationTypes', array());
    $stypes = Q_Config::get('Streams', 'categorize', 'streamTypes', array());
    if (!in_array($type, $rtypes) or !in_array($stream->type, $stypes)) {
        return;
    }
    $c = new Streams_Category();
    $c->publisherId = $stream->publisherId;
    $c->streamName = $stream->name;
    $fromPublisherId = $message->getInstruction('fromPublisherId', null);
    $fromStreamName = $message->getInstruction('fromStreamName', null);
    if (!isset($fromPublisherId) or !isset($fromStreamName)) {
        return;
    }
    // Begin database transaction
    $relatedTo = $c->retrieve(null, array('ignoreCache' => true, 'begin' => true)) ? json_decode($c->relatedTo, true) : array();
    if (isset($relatedTo[$type])) {
        foreach ($relatedTo[$type] as $weight => $info) {
            if ($info[0] === $fromPublisherId and $info[1] === $fromStreamName) {
                unset($relatedTo[$type][$weight]);
                break;
            }
        }
        $o = $message->getInstruction('options', null);
        $w = $message->getInstruction('weight', null);
        if (!empty($o['adjustWeights'])) {
            $rt = array();
            foreach ($relatedTo[$type] as $weight => $info) {
                if ($weight > $w) {
                    $rt[$weight - 1] = $info;
                } else {
                    $rt[$weight] = $info;
                }
            }
            $relatedTo[$type] = $rt;
        }
    }
    $c->relatedTo = Q::json_encode($relatedTo);
    $c->save();
    // End database transaction
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:45,代码来源:Streams_message_Streams_unrelatedTo.php

示例14: Users_before_Q_session_save

function Users_before_Q_session_save($params)
{
    if (empty($params['row'])) {
        return;
    }
    $row = $params['row'];
    $user = Users::loggedInUser(false, false);
    $userId = $user ? $user->id : null;
    if (Q::ifset($row, 'userId', null) !== $userId) {
        $row->userId = $userId;
    }
    $row->content = isset($_SESSION) ? Q::json_encode($_SESSION, JSON_FORCE_OBJECT) : "{}";
    if (empty($params['inserting'])) {
        return;
    }
    $row->deviceId = "";
    $row->timeout = 0;
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:18,代码来源:Q_session_save.php

示例15: Streams_after_Streams_message_Streams_updateRelateTo

function Streams_after_Streams_message_Streams_updateRelateTo($params)
{
    $message = $params['message'];
    $type = $message->getInstruction('type', null);
    $stream = $params['stream'];
    $rtypes = Q_Config::get('Streams', 'categorize', 'relationTypes', array());
    $stypes = Q_Config::get('Streams', 'categorize', 'streamTypes', array());
    if (!in_array($type, $rtypes) or !in_array($stream->type, $stypes)) {
        return;
    }
    $c = new Streams_Category();
    $c->publisherId = $stream->publisherId;
    $c->streamName = $stream->name;
    $fromPublisherId = $message->getInstruction('fromPublisherId', null);
    $fromStreamName = $message->getInstruction('fromStreamName', null);
    if (!isset($fromPublisherId) or !isset($fromStreamName)) {
        return;
    }
    // Begin database transaction
    $relatedTo = $c->retrieve(null, array('ignoreCache' => true, 'begin' => true)) ? json_decode($c->relatedTo, true) : array();
    $weight = (double) $message->getInstruction('weight', null);
    $previousWeight = (double) $message->getInstruction('previousWeight', null);
    $adjustWeightsBy = $message->getInstruction('adjustWeightsBy', null);
    if (isset($relatedTo[$type])) {
        $prev = $relatedTo[$type][$previousWeight];
        $rt = array();
        foreach ($relatedTo[$type] as $w => $info) {
            if ($weight < $previousWeight and ($w < $weight or $previousWeight <= $w)) {
                $rt[$w] = $info;
            } else {
                if ($weight >= $previousWeight and ($w <= $previousWeight or $weight < $w)) {
                    $rt[$w] = $info;
                } else {
                    $rt[$w + $adjustWeightsBy] = $info;
                }
            }
        }
        $rt[$weight] = $prev;
        $relatedTo[$type] = $rt;
    }
    $c->relatedTo = Q::json_encode($relatedTo);
    $c->save();
    // End database transaction
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:44,代码来源:Streams_message_Streams_updateRelateTo.php


注:本文中的Q::json_encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。