function actionModify() { $id = (int) $this->_context->get('id'); $rs = Account::find('user_id = ?', $id)->getOne(); if (!$rs->id()) { return $this->msg($tip = '参数错误', url('manage::account')); } $form = Form_Common::createForm('', 'manage/profile'); if ($this->_context->isPOST() && $form->validate($_POST)) { $post = $form->values(); $user_mail = $post['user_mail']; $user_pass = $post['user_pass']; $is_locked = $post['is_locked'] ? '1' : '0'; #dump($post); if ($user_pass) { $user_pass = sha1(md5('sike' . $post['user_pass'] . Q::ini('appini/secret_key'))); $rs->user_pass; } $rs->user_mail = $user_mail; $rs->is_locked = $is_locked; $rs->save(); return $this->msg($tip = '修改成功', url('manage::account/modify', array('id' => $id))); } $form->import($rs->toArray()); $form->element('user_pass')->value = ''; $form->element('is_locked')->checked = $rs->is_locked; #dump($form->element('is_locked')); $this->_view['form'] = $form; $this->_view['rs'] = $rs; $order = Order::find('user_id = ?', $id)->order('created DESC')->getAll(); $this->_view['order'] = $order; $this->_view['_UDI'] = 'manage::account/index'; }
/** * 载入缓存的 YAML 解析结果,如果缓存失效,则重新解析并生成缓存 * * @param string $filename * 要解析的 yaml 文件名 * @param array $replace * 对于 YAML 内容要进行自动替换的字符串对 * @param string $cache_backend * 要使用的缓存后端 * * @return array * 解析结果 */ static function loadCached($filename, array $replace = null, $cache_backend = null) { static $cache_obj = null; if (!is_file($filename)) { throw new QException_FileNotFound($filename); } $policy = array('lifetime' => 86400, 'serialize' => true); $mtime = filemtime($filename); $id = 'yaml_cache_' . md5($filename); if (is_null($cache_backend)) { if (is_null($cache_obj)) { $cache_obj = Q::getSingleton(Q::getIni('runtime_cache_backend')); } $cache = $cache_obj; } else { $cache = self::getSingleton($cache_backend); } /* @var $cache QCache_File */ $data = $cache->get($id, $policy); if (!isset($data['yaml']) || empty($data['mtime']) || $data['mtime'] < $mtime) { // 缓存失效 $data = array('mtime' => $mtime, 'yaml' => self::load($filename, $replace)); $cache->set($id, $data, $policy); } return $data['yaml']; }
function log_shard_query($params) { foreach ($params['queries'] as $shard => $query) { if ($query->className === 'Users_Session') { continue; } $connection = $query->db->connectionName(); if ($begin = $query->getClause('BEGIN') and $query->nestedTransactionCount == 1) { Q::log($begin); } $duration = ceil($query->endedTime - $query->startedTime); Q::log("Query {$connection} on shard \"{$shard}\":\n{$params['sql']}\n(duration: {$duration} ms)\n\n"); if ($commit = $query->getClause('COMMIT') and $query->nestedTransactionCount == 0) { Q::log($commit); } if (!empty($params['exception'])) { Q::log("ROLLBACK (due to exception)"); Q::log("query was: " . $params['sql']); Q::log($params['exception']); } else { if ($rollback = $query->getClause('ROLLBACK')) { Q::log($rollback); } } } }
function Q_response_dashboard() { $app = Q_Config::expect('Q', 'app'); $slogan = "Powered by Q."; $user = Users::loggedInUser(); return Q::view("{$app}/dashboard.php", compact('slogan', 'user')); }
/** * 实现接口 * */ function render() { //得到子菜单的标题 $menu_title = $this->_extract('menu'); //的到子菜单的属性 $sub_menu = Q::ini('appini/admin_sub_menus/' . $menu_title); //是否存在 if (!is_array($sub_menu)) { $sub_menu = array(); } //得到当前的属性 $currentmenu = $this->_extract('current'); //输出子菜单 如果是当前的加上css $out = "<ul>\n"; foreach ($sub_menu as $menu) { //是否是当前菜单 if ($menu['title'] == $currentmenu) { $out .= "<li class=\"current\">"; } else { $out .= "<li>"; } $out .= '<a href="' . url($menu['udi']) . '"> <span>'; $out .= h($menu['title']) . '</span>'; $out .= "</a></li>\n"; } $out .= "</ul>\n"; return $out; }
function Streams_stream_response_Q_inplace() { $stream = isset(Streams::$cache['stream']) ? Streams::$cache['stream'] : null; if (!$stream) { throw new Exception("No stream"); } if (isset($_REQUEST['title'])) { $result = $stream->title; } else { if (isset($_REQUEST['attributes'])) { if (is_array($_REQUEST['attributes'])) { reset($_REQUEST['attributes']); $result = $stream->getAttribute(key($_REQUEST['attributes'])); } else { $result = $stream->attributes; } } else { $fieldNames = array_diff(Streams::getExtendFieldNames($stream->type), array('insertedTime', 'updatedTime')); $field = 'content'; foreach ($fieldNames as $f) { if (isset($_REQUEST[$f])) { $field = $f; break; } } $result = $stream->{$field}; } } $convert = Q::ifset($_REQUEST, 'convert', '["\\n"]'); return Q_Html::text($result, json_decode($convert, true)); }
function Streams_invite_response_data() { if (isset(Streams::$cache['invited'])) { return Streams::$cache['invited']; } $user = Users::loggedInUser(true); $publisherId = Streams::requestedPublisherId(); $streamType = Streams::requestedType(); $invitingUserId = Streams::requestedField('invitingUserId'); $limit = Q::ifset($_REQUEST, 'limit', Q_Config::get('Streams', 'invites', 'limit', 100)); $invited = Streams_Invited::select('*')->where(array('userId' => $user->id, 'state' => 'pending', 'expireTime <' => new Db_Expression('CURRENT_TIMESTAMP')))->limit($limit)->fetchDbRows(null, null, 'token'); $query = Streams_Invite::select('*')->where(array('token' => array_keys($invited))); if (isset($publisherId)) { $query = $query->where(array('publisherId' => $publisherId)); } if (isset($streamType)) { $query = $query->where(array('streamName' => new Db_Range($streamType . '/', true, false, true))); } if (isset($invitingUserId)) { $query = $query->where(array('invitingUserId' => $invitingUserId)); } $invites = $query->fetchDbRows(); $streams = array(); foreach ($invites as $invite) { $stream = new Streams_Stream(); $stream->publisherId = $invite->publisherId; $stream->name = $invite->streamName; if ($stream->retrieve()) { $streams[$invite->token] = $stream->exportArray(); $streams[$invite->token]['displayName'] = $invite->displayName; } } return compact('streams', 'invites'); }
/** * Add contact with one or more labels * @method addContact * @static * @param {string} $userId * The id of the user whose contact will be added * @param {string} $contactUserId * The id of the user who is the contact * @param {string|array} $label * The label of the contact. This can be a string or an array of strings, in which case * multiple contact rows are saved. * @param {string} [$nickname=''] * Optional nickname to assign to the contact * @optional * @throws {Q_Exception_RequiredField} * if $label is missing * @return {array} Array of contacts that are saved */ static function addContact($userId, $label, $contactUserId, $nickname = '') { foreach (array('userId', 'label', 'contactUserId') as $field) { if (empty(${$field})) { throw new Q_Exception_RequiredField(compact('field')); } } $labels = is_array($label) ? $label : array($label); $contacts = array(); foreach ($labels as $l) { // Insert the contacts one by one $contact = new Users_Contact(); $contact->userId = $userId; $contact->contactUserId = $contactUserId; $contact->label = $l; if ($nickname) { $contact->nickname = $nickname; } $contact->save(true); $contacts[] = $contact; } /** * @event Users/Contact/addContact {after} * @param {string} contactUserId * @param {string} label * @param {array} contacts */ Q::event('Users/Contact/addContact', compact('contactUserId', 'label', 'contacts'), 'after'); return $contacts; }
function UserAclRoles($user_id = '') { $show_box['title'] = '获取用户全部角色'; $return_value = ''; $roles_idname = array(); $roles_id = array(); $sp_roles = Q::ini('appini/sp_role'); // 第一步:直接从中间表获得用户的全部角色ID $user_roles = UsersHaveRoles::find('user_id = ?', intval($user_id))->asArray()->getAll(); //dump($user_roles); // 取出有用的ID,去除deny的ID foreach ($user_roles as $value) { if ($value['is_include']) { $roles_id[] = $value['role_id']; } } //dump ( $roles_id); $roles_arr = Roles::find('role_id in (?)', Q::normalize($roles_id, ","))->asArray()->getAll(); foreach ($roles_arr as $value) { $roles_idname[$value['role_id']] = $value['rolename']; } //dump($roles_idname); if (in_array($sp_roles['REPEAL'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['REPEAL']); return $return_value; } elseif (in_array($sp_roles['FREEZE'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['FREEZE']); return $return_value; } elseif (in_array($sp_roles['UNCHECKED'], $roles_idname)) { $return_value = array($value['role_id'] => $sp_roles['UNCHECKED']); return $return_value; } else { return $roles_idname; } }
/** * Standard tool for making payments. * @class Assets payment * @constructor * @param {array} $options Override various options for this tool * @param {string} $options.payments can be "authnet" or "stripe" * @param {string} $options.amount the amount to pay. * @param {double} [$options.currency="usd"] the currency to pay in. (authnet supports only "usd") * @param {string} [$options.payButton] Can override the title of the pay button * @param {String} [$options.publisherId=Users::communityId()] The publisherId of the Assets/product or Assets/service stream * @param {String} [$options.streamName] The name of the Assets/product or Assets/service stream * @param {string} [$options.name=Users::communityName()] The name of the organization the user will be paying * @param {string} [$options.image] The url pointing to a square image of your brand or product. The recommended minimum size is 128x128px. * @param {string} [$options.description=null] A short name or description of the product or service being purchased. * @param {string} [$options.panelLabel] The label of the payment button in the Stripe Checkout form (e.g. "Pay {{amount}}", etc.). If you include {{amount}}, it will be replaced by the provided amount. Otherwise, the amount will be appended to the end of your label. * @param {string} [$options.zipCode] Specify whether Stripe Checkout should validate the billing ZIP code (true or false). The default is false. * @param {boolean} [$options.billingAddress] Specify whether Stripe Checkout should collect the user's billing address (true or false). The default is false. * @param {boolean} [$options.shippingAddress] Specify whether Checkout should collect the user's shipping address (true or false). The default is false. * @param {string} [$options.email=Users::loggedInUser(true)->emailAddress] You can use this to override the email address, if any, provided to Stripe Checkout to be pre-filled. * @param {boolean} [$options.allowRememberMe=true] Specify whether to include the option to "Remember Me" for future purchases (true or false). * @param {boolean} [$options.bitcoin=false] Specify whether to accept Bitcoin (true or false). * @param {boolean} [$options.alipay=false] Specify whether to accept Alipay ('auto', true, or false). * @param {boolean} [$options.alipayReusable=false] Specify if you need reusable access to the customer's Alipay account (true or false). */ function Assets_payment_tool($options) { Q_Valid::requireFields(array('payments', 'amount'), $options, true); if (empty($options['name'])) { $options['name'] = Users::communityName(); } if (!empty($options['image'])) { $options['image'] = Q_Html::themedUrl($options['image']); } $options['payments'] = strtolower($options['payments']); if (empty($options['email'])) { $options['email'] = Users::loggedInUser(true)->emailAddress; } $payments = ucfirst($options['payments']); $currency = strtolower(Q::ifset($options, 'currency', 'usd')); if ($payments === 'Authnet' and $currency !== 'usd') { throw new Q_Exception("Authnet doesn't support currencies other than USD", 'currency'); } $className = "Assets_Payments_{$payments}"; switch ($payments) { case 'Authnet': $adapter = new $className($options); $token = $options['token'] = $adapter->authToken(); $testing = $options['testing'] = Q_Config::expect('Assets', 'payments', $lcpayments, 'testing'); $action = $options['action'] = $testing ? "https://test.authorize.net/profile/manage" : "https://secure.authorize.net/profile/manage"; break; case 'Stripe': $publishableKey = Q_Config::expect('Assets', 'payments', 'stripe', 'publishableKey'); break; } $titles = array('Authnet' => 'Authorize.net', 'Stripe' => 'Stripe'); Q_Response::setToolOptions($options); $payButton = Q::ifset($options, 'payButton', "Pay with " . $titles[$payments]); return Q::view("Assets/tool/payment/{$payments}.php", compact('token', 'publishableKey', 'action', 'payButton')); }
/** * 获得一个数据库连接对象 * * $dsn_name 参数指定要使用应用程序设置中的哪一个项目作为创建数据库连接的 DSN 信息。 * 对于同样的 DSN 信息,只会返回一个数据库连接对象。 * * @param string $dsn_name * * @return QDB_Adapter_Abstract */ static function getConn($dsn_name = null) { $default = empty($dsn_name); if ($default && Q::isRegistered('dbo_default')) { return Q::registry('dbo_default'); } if (empty($dsn_name)) { $dsn = Q::getIni('db_dsn_pool/default'); } else { $dsn = Q::getIni('db_dsn_pool/' . $dsn_name); } if (empty($dsn)) { // LC_MSG: Invalid DSN. trigger_error('invalid dsn'); throw new QException(__('Invalid DSN.')); } $dbtype = $dsn['driver']; $objid = "dbo_{$dbtype}_" . md5(serialize($dsn)); if (Q::isRegistered($objid)) { return Q::registry($objid); } $class_name = 'QDB_Adapter_' . ucfirst($dbtype); $dbo = new $class_name($dsn, $objid); Q::register($dbo, $objid); if ($default) { Q::register($dbo, 'dbo_default'); } return $dbo; }
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 testRegisterAutoLoad() { Q::registerAutoload(__CLASS__); $obj = new Class3(); Q::registerAutoLoad(__CLASS__, false); $this->assertFalse(class_exists('Class4')); }
/** * Used by HTTP clients to upload a new file to the server * @class Q/file * @method post * @param {array} [$params] Parameters that can come from the request * @param {string} [$params.data] Required if $_FILES is empty. Base64-encoded image data URI - see RFC 2397 * @param {string} [$params.path="uploads"] parent path under web dir (see subpath) * @param {string} [$params.subpath=""] subpath that should follow the path, to save the image under * @param {string} [$params.name] override the name of the file, after the subpath */ function Q_file_post($params = null) { $p = $params ? $params : Q::take($_REQUEST, array('data', 'path', 'subpath')); if (!empty($_FILES)) { $file = reset($_FILES); if ($tmp = $file['tmp_name']) { if (empty($p['data'])) { $p['data'] = file_get_contents($tmp); $p['name'] = $file['name']; } unlink($tmp); } } else { if (empty($p['data'])) { throw new Q_Exception_RequiredField(array('field' => 'data'), 'data'); } $p['data'] = base64_decode(chunk_split(substr($p['data'], strpos($p['data'], ',') + 1))); } $timeLimit = Q_Config::get('Q', 'uploads', 'limits', 'file', 'time', 5 * 60 * 60); set_time_limit($timeLimit); // default is 5 min $data = Q_File::save($p); if (empty($params)) { Q_Response::setSlot('data', $data); } return $data; }
/** * This tool implements expandable containers that work on most modern browsers, * including ones on touchscreens. * @class Q expandable * @constructor * @param {array} $options Options for the tool * @param {string} $options.title Required. The title for the expandable. * @param {string} $options.content The content. Required unless you pass "items" instead. * @param {array} [$options.items] An array of strings to wrap in <span> elements and render in the content * @param {string} [$options.class] If you use "items", optionally specify the class of the container elements for each item * @param {integer} [$options.title] A number, if any, to display when collapsed * @param {boolean} [$options.autoCollapseSiblings] Whether, when expanding an expandable, its siblings should be automatically collapsed. */ function Q_expandable_tool($options) { if (isset($options['items'])) { $classString = isset($options['class']) ? "class='{$options['class']}'" : ''; $lines = array(); foreach ($options['items'] as $key => $value) { $lines[] = "<span {$classString}>{$key}</span>"; } $between = Q::ifset($options, 'between', ''); $options['content'] = implode($between, $lines); } foreach (array('title', 'content') as $field) { if (!isset($options[$field])) { throw new Q_Exception_RequiredField(compact('field')); } } Q_Response::addScript('plugins/Q/js/tools/expandable.js'); Q_Response::addStylesheet('plugins/Q/css/expandable.css'); $count = Q::ifset($options, 'count', ''); $style = empty($options['expanded']) ? '' : 'style="display:block"'; $h2 = "<h2>\n\t<span class='Q_expandable_count'>{$count}</span>\n\t{$options['title']}\n</h2>"; $div = "<div class='Q_expandable_container' {$style}><div class='Q_expandable_content'>\n\t{$options['content']}\n</div></div>"; Q_Response::setToolOptions($options); return $h2 . $div; }
/** * Default Q/dir handler. * Just displays a simple directory listing, * and prevents further processing by returning true. */ function Q_dir() { $filename = Q_Request::filename(); // TODO: show directory listing echo Q::view('Q/dir.php', compact('filename')); return true; }
function Broadcast_control_response_content($params) { $user = Users::loggedInUser(true); $organizations = Broadcast_Agreement::select('a.userId, a.publisherId, u.organization_title, u.organization_domain', 'a')->join(Broadcast_User::table() . ' u', array('a.publisherId' => 'u.userId'))->where(array('a.userId' => $user->id))->fetchAll(PDO::FETCH_ASSOC); foreach ($organizations as $k => $org) { $messages = Streams_Message::select('content')->where(array('publisherId' => $org['publisherId'], 'streamName' => 'Broadcast/main'))->orderBy('sentTime')->fetchAll(PDO::FETCH_ASSOC); $organizations[$k]['messages'] = array(); foreach ($messages as $msg) { $content = json_decode($msg['content'], true); if (isset($content['link'])) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $content['link']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; cs-CZ; rv:1.7.12) Gecko/20050929"); $page_contents = curl_exec($ch); curl_close($ch); preg_match('/<title>([^<]+)<\\/title>/', $page_contents, $matches); if (isset($matches[1])) { $content['link_title'] = $matches[1]; } } $organizations[$k]['messages'][] = $content; } } Q_Config::set('Q', 'response', 'Broadcast', 'layout_html', 'Broadcast/layout/canvas.php'); Q_Response::addStylesheet('css/canvas.css'); Q_Response::addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); Q_Response::addScript('js/canvas.js'); return Q::view('Broadcast/content/control.php', compact('organizations')); }
/** * 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'); }
function Streams_message_response_messages() { if (isset(Streams::$cache['message'])) { $message = Streams::$cache['message']; return Db::exportArray(array($message->ordinal => $message)); } if (isset(Streams::$cache['messages'])) { return Db::exportArray(Streams::$cache['messages']); } $publisherId = Streams::requestedPublisherId(true); $streamName = Streams::requestedName(true); $type = Streams::requestedMessageType(); $stream = Q::ifset(Streams::$cache, 'stream', Streams::fetchOne(null, $publisherId, $streamName, true)); $maxLimit = Streams_Stream::getConfigField($type, 'getMessagesLimit', 100); $limit = min($maxLimit, Q::ifset($_REQUEST, 'limit', $maxLimit)); if (isset($_REQUEST['ordinal'])) { $min = $_REQUEST['ordinal']; $limit = 1; } if (isset($_REQUEST['min'])) { $min = $_REQUEST['min']; } $max = isset($_REQUEST['max']) ? $_REQUEST['max'] : -1; if (isset($_REQUEST['ascending'])) { $ascending = $_REQUEST['ascending']; } if (!$stream->testReadLevel('messages')) { throw new Users_Exception_NotAuthorized(); } $messages = $stream->getMessages(compact('type', 'min', 'max', 'limit', 'ascending')); return Db::exportArray($messages); }
/** * Adds a label to the system. Fills the "label" (and possibly "icon") slot. * @param {array} $_REQUEST * @param {string} $_REQUEST.title The title of the label * @param {string} [$_REQUEST.label] You can override the label to use * @param {string} [$_REQUEST.icon] Optional path to an icon * @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this */ function Users_label_post($params = array()) { $req = array_merge($_REQUEST, $params); Q_Request::requireFields(array('title'), $req, true); $loggedInUserId = Users::loggedInUser(true)->id; $userId = Q::ifset($req, 'userId', $loggedInUserId); $icon = Q::ifset($req, 'icon', null); $title = $req['title']; $l = Q::ifset($req, 'label', 'Users/' . Q_Utils::normalize($title)); Users::canManageLabels($loggedInUserId, $userId, $l, true); $label = new Users_Label(); $label->userId = $userId; $label->label = $l; if ($label->retrieve()) { throw new Users_Exception_LabelExists(); } $label->title = $title; if (is_array($icon)) { // Process any icon that was posted $icon['path'] = 'uploads/Users'; $icon['subpath'] = "{$userId}/label/{$label}/icon"; $data = Q::event("Q/image/post", $icon); Q_Response::setSlot('icon', $data); $label->icon = Q_Request::baseUrl() . '/' . $data['']; } else { $label->icon = 'default'; } $label->save(); Q_Response::setSlot('label', $label->exportArray()); }
function render() { //路径 $baseDir = $this->_context->get('base_dir', $this->_context->baseDir() . 'js/fckeditor/'); $baseDir = h(rtrim($baseDir, '/\\') . '/'); $width = $this->get('width', "100%"); $height = $this->get('height', "250px"); $value = $this->get('value', ''); $class = $this->get('class', ''); //控件的id $id = $this->id(); $config = $this->get('config'); if (!is_array($config)) { $config = array(); } $out = Q::control('memo', $id, array('value' => $value, 'class' => $class))->render(); $out .= <<<EOT \t<script type="text/javascript" src="{$baseDir}fckeditor.js"></script> <script type="text/javascript"> var oFCKeditor = new FCKeditor('{$id}'); oFCKeditor.BasePath = "{$baseDir}"; oFCKeditor.Height="{$height}"; oFCKeditor.Width="{$width}"; oFCKeditor.ReplaceTextarea(); </script>\t EOT; return $out; }
/** * This tool generates an HTML article viewer that lets authorized users edit the article. * @class Websites article * @constructor * @param {Object} [$options] parameters for the tool * @param {String} $options.publisherId The article publisher's user id * @param {String} $options.streamName The article's stream name * @param {String} $options.stream The article's stream, if it is already fetched * @param {String} [$options.html=array()] Any additional for the Streams/html editor * @param {String} [$options.getintouch=array()] Additional options for the Users/getintouch tool, in case it's rendered */ function Websites_article_tool($options) { $publisherId = $options['publisherId']; $streamName = $options['streamName']; $article = Q::ifset($options, 'stream', Streams::fetchOne(null, $publisherId, $streamName)); if (!$article) { throw new Q_Exception_MissingRow(array('table' => 'article', 'criteria' => $streamName)); } $getintouch = array_merge(array('user' => $article->userId, 'email' => true, 'sms' => true, 'call' => true, 'between' => "", 'emailSubject' => 'Reaching out from your website', 'class' => 'Q_button Q_clickable'), Q::ifset($options, 'getintouch', array())); $canView = $article->testReadLevel('content'); $canEdit = $article->testWriteLevel('edit'); if ($article->getintouch) { if (is_array($git = json_decode($article->getintouch, true))) { $getintouch = array_merge($getintouch, $git); } } $getintouch['class'] = 'Q_button'; if (!$canView) { throw new Users_Exception_NotAuthorized(); } $html = Q::ifset($options, 'html', array()); $article->addPreloaded(); Q_Response::addStylesheet('plugins/Websites/css/Websites.css'); Q_Response::addScript("plugins/Websites/js/Websites.js"); Q_Response::setToolOptions($options); return Q::view("Websites/tool/article.php", compact('article', 'getintouch', 'canEdit', 'canView', 'html')); }
/** * 根据运行时上下文对象,调用相应的控制器动作方法 * * @param array $args * * @return mixed */ function run(array $args = array()) { $context = QContext::instance(); $udi = $context->requestUDI('array'); $dir = dirname(__FILE__) . '/app/controller'; $class_name = 'controller_'; $controller_name = strtolower($udi[QContext::UDI_CONTROLLER]); $class_name .= $controller_name; $filename = "{$controller_name}_controller.php"; // 载入控制器文件 if (!class_exists($class_name, false)) { Q::loadClassFile($filename, array($dir), $class_name); } // 构造控制器对象 $controller = new $class_name($this); $action_name = $udi[QContext::UDI_ACTION]; $response = $controller->execute($action_name, $args); if (is_object($response) && method_exists($response, 'execute')) { // 如果返回结果是一个对象,并且该对象有 execute() 方法,则调用 $response = $response->execute(); } elseif ($response instanceof QController_Forward) { // 如果是一个 QController_Forward 对象,则将请求进行转发 $response = $this->run($response->args); } // 其他情况则返回执行结果 return $response; }
protected function _after_destroy() { $dir = rtrim(Q::ini('appini/teapics/upload_dir'), '/\\') . DS; if ($this->ico->value != null) { @unlink($dir . $this->ico); } }
/** * Standard tool for starting or managing subscriptions. * @class Assets subscription * @constructor * @param {array} $options Override various options for this tool * @param {string} $options.payments can be "authnet" or "stripe" * @param {string} $options.planStreamName the name of the subscription plan's stream * @param {string} [$options.publisherId=Q.Users.communityId] the publisher of the subscription plan's stream * @param {string} [$options.subscribeButton] Can override the title of the subscribe button * @param {array} [$options=array()] Any additional options * @param {string} [$options.token=null] required unless the user is an existing customer */ function Assets_subscription_tool($options) { if (empty($options['payments'])) { throw new Q_Exception_RequiredField(array('field' => 'payments'), 'payments'); } $payments = ucfirst($options['payments']); $lcpayments = strtolower($payments); $currency = strtolower(Q::ifset($options, 'currency', 'usd')); if ($payments === 'Authnet' and $currency !== 'usd') { throw new Q_Exception("Authnet doesn't support currencies other than USD", 'currency'); } $className = "Assets_Payments_{$payments}"; switch ($payments) { case 'Authnet': $adapter = new $className($options); $token = $options['token'] = $adapter->authToken(); $testing = $options['testing'] = Q_Config::expect('Assets', 'payments', $lcpayments, 'testing'); $action = $options['action'] = $testing ? "https://test.authorize.net/profile/manage" : "https://secure.authorize.net/profile/manage"; break; case 'Stripe': $publishableKey = Q_Config::expect('Assets', 'payments', 'stripe', 'publishableKey'); break; } $titles = array('Authnet' => 'Authorize.net', 'Stripe' => 'Stripe'); $subscribeButton = Q::ifset($options, 'subscribeButton', "Subscribe with " . $titles[$payments]); Q_Response::setToolOptions($options); return Q::view("Assets/tool/subscription/{$payments}.php", compact('token', 'publishableKey', 'action', 'paymentButton', 'subscribeButton', 'planStreamName')); }
public function init() { parent::init(); if (!Yii::app()->request->isAjaxRequest) { $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction')); } }
function Q_post($params) { $uri = Q_Dispatcher::uri(); $module = $uri->module; $action = $uri->action; if (!Q::canHandle("{$module}/{$action}/post")) { throw new Q_Exception_MethodNotSupported(array('method' => 'POST')); } if (isset($_SERVER['CONTENT_LENGTH'])) { $contentLength = (int) $_SERVER['CONTENT_LENGTH']; foreach (array('upload_max_filesize', 'post_max_size') as $name) { $value = ini_get($name); switch (substr($value, -1)) { case 'K': $value *= 1024; break; case 'M': $value *= 1024 * 1024; break; case 'B': $value *= 1024 * 1024 * 1024; break; } if ($contentLength > $value) { throw new Q_Exception_ContentLength(array('contentLength' => $contentLength, 'exceeds' => $name)); } } } return Q::event("{$module}/{$action}/post", $params); }
function Overlay_before_Q_responseExtras() { $app = Q_Config::expect('Q', 'app'); Q_Response::addStylesheet('plugins/Q/css/Q.css'); Q_Response::addStylesheet('css/Overlay.css', '@end'); Q_Response::addStylesheet('http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,700'); if (Q_Config::get('Q', 'firebug', false)) { Q_Response::addScript("https://getfirebug.com/firebug-lite-debug.js"); } Q_Response::addScript('js/Overlay.js'); Q_Response::setMeta("title", "Customize My Pic!"); Q_Response::setMeta("description", "Make a statement on Facebook by customizing your profile picture, even from your smartphone."); Q_Response::setMeta("image", Q_Html::themedUrl('img/icon/icon.png')); if (Q_Request::isIE()) { header("X-UA-Compatible", "IE=edge"); } header('Vary: User-Agent'); // running an event for loading action-specific extras (if there are any) $uri = Q_Dispatcher::uri(); $module = $uri->module; $action = $uri->action; $event = "{$module}/{$action}/response/responseExtras"; if (Q::canHandle($event)) { Q::event($event); } }
public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(); } return self::$_instance; }
function Users_account_validate() { Q_Valid::nonce(true); $birthday_year = $birthday_month = $birthday_day = null; extract($_REQUEST); $field_names = array('firstName' => 'First name', 'lastName' => 'Last name', 'username' => 'Username', 'gender' => 'Your gender', 'desired_gender' => 'Gender preference', 'orientation' => 'Orientation', 'relationship_status' => 'Status', 'zipcode' => 'Zipcode'); foreach ($field_names as $name => $label) { if (isset($_POST[$name]) and !$_POST[$name]) { Q_Response::addError(new Q_Exception_RequiredField(array('field' => $label), $name)); } } if (isset($birthday_year)) { if (!checkdate($birthday_month, $birthday_day, $birthday_year)) { $field = 'Birthday'; $range = 'a valid date'; Q_Response::addError(new Q_Exception_WrongValue(compact('field', 'range'), 'birthday')); } } global $Q_installing; if (isset($username) and isset($Q_installing)) { try { Q::event('Users/validate/username', compact('username')); } catch (Exception $e) { Q_Response::addError($e); } } }