function _retreat($params) { $user = $params['user']; $channel = $params['channel']; $inchannels = DB::get()->col('SELECT name FROM channels WHERE user_id = :user_id', array('user_id' => $user->id)); $join = 'office:' . $user->username; $joinalias = $this->_room_alias($join); foreach ($inchannels as $partchan) { DB::get()->query('DELETE FROM channels WHERE name = :name AND user_id = :user_id;', array('name' => $partchan, 'user_id' => $user->id)); if (preg_match('%^search:(?P<criteria>.+)$%i', $partchan, $searchmatches)) { DB::get()->query("DELETE FROM options WHERE name = :name AND grouping = 'searches' AND user_id = :user_id;", array('name' => $searchmatches['criteria'], 'user_id' => $user->id)); } else { if ($partchan != $join) { Status::create()->data("{$user->username} has retreated to <a href=\"#\" onclick=\"joinRoom('" . addslashes($join) . "');return false;\">{$joinalias}</a> from {$partchan}")->type('part')->channel($partchan)->insert(); } } } DB::get()->query('INSERT INTO channels (name, user_id, last) VALUES (:name, :user_id, NOW());', array('name' => $join, 'user_id' => $user->id)); if (!($herald = DB::get()->val("SELECT value FROM options WHERE user_id = :user_id AND name = :name AND grouping = :grouping", array('user_id' => $user->id, 'name' => 'Herald', 'grouping' => 'Identity')))) { $herald = '{$nickname} has joined {$room}'; } $js = ''; $cssclass = ''; $packed = Plugin::call('herald', array('herald' => $herald, 'js' => $js, 'cssclass' => $cssclass)); extract($packed); $herald = str_replace('{$nickname}', $user->nickname, $herald); $herald = str_replace('{$room}', $joinalias, $herald); $msg = htmlspecialchars($herald); Status::create()->data($msg)->type('join')->cssclass($cssclass)->channel($join)->js($js)->insert(); Immediate::create()->laststatus()->js('setRoom("' . addslashes($join) . '");'); return true; }
function index($path) { $cmd = $_POST['cmd']; $auto = array($_POST['cmd']); $auto = $this->_autocomplete($auto, $cmd); $users = DB::get()->col('SELECT username FROM users;'); $nicks = DB::get()->col("SELECT value FROM options WHERE grouping = 'Identity' AND name = 'Nickname';"); $users = $users + $nicks; $userregex = implode('|', array_map('preg_quote', $users)); $cmd = preg_replace('%(' . $userregex . ')%i', '{$nickname}', $cmd); $autos = Plugin::call('autocomplete', $auto, $cmd); $auto = array(); foreach ($autos as $op) { if (strpos($op, '{$nickname}') === false) { $auto[] = $op; } else { foreach ($users as $user) { $auto[] = str_replace('{$nickname}', $user, $op); } } } foreach ($auto as $k => $v) { if ($v[0] == '*') { $auto[$k] = substr($v, 1); continue; } if (strncasecmp($cmd, $v, strlen($cmd)) != 0) { unset($auto[$k]); } } sort($auto); echo json_encode($auto); }
public function render($viewname = '') { $glob = glob(MICROSITE_PATH . '/microsite/views/*.php'); $views = array(); foreach ($glob as $view) { $views[basename($view, '.php')] = $view; } $views = Plugin::call('viewlist', $views); if ($viewname == '') { if ($this->vars['_view'] != '') { $viewname = $this->vars['_view']; } else { $viewname = '404'; } } if (isset($views[$viewname])) { foreach ($this->vars as $k => $v) { if ($k[0] != '_') { ${$k} = $v; } } $view = $this; ob_start(); include $views[$viewname]; $out = ob_get_clean(); $out = new Dom($out); return $out; } else { throw new Exception('View does not exist: ' . $viewname); } }
function __construct($path) { $chanbar = ' <ul> <li id="settings" class="option"><a href="#" class="button">settings</a></li> <li id="files" class="option"><a href="#" class="button">files</a></li> <li id="people" class="option"><a href="#" class="button">people</a></li> </ul> '; $user = Auth::user(); $curchan = DB::get()->val('SELECT name from channels where user_id = :user_id AND active = 1', array('user_id' => $user->id)); if ($curchan == '') { $curchan = 'bar'; } $widgets = Widgets::get_widgets(); $components = array('title' => 'Barchat Home', 'path' => $path, 'chanbar' => $chanbar, 'user_id' => Auth::user_id(), 'username' => $user->username, 'nickname' => $user->nickname, 'session_key' => $user->session_key, 'cur_chan' => addslashes($curchan), 'widgets' => $widgets); $v = new View($components); Plugin::call('reload', $user); //check for user agent $useragent = $_SERVER['HTTP_USER_AGENT']; // if (preg_match('/ip(hone|od|ad)/i', $useragent)) { $v->render('template-ios'); } else { $v->render('template'); } }
public function render($viewname = '') { $glob = glob(MICROSITE_PATH . '/microsite/views/*.php'); $views = array(); foreach ($glob as $view) { $views[basename($view, '.php')] = $view; } $views = Plugin::call('viewlist', $views); if ($viewname == '') { if ($this->vars['_view'] != '') { $viewname = $this->vars['_view']; } else { $viewname = 'table'; } } if (isset($views[$viewname])) { foreach ($this->vars as $k => $v) { if ($k[0] != '_') { ${$k} = $v; } } $view = $this; include $views[$viewname]; } else { echo 'View does not exist: ' . $viewname; } }
function get_widgets() { $user = Auth::user(); $active_widgets = DB::get()->results("SELECT * FROM options WHERE user_id = :user_id AND grouping = 'widgets' ORDER BY name ASC", array('user_id' => $user->id)); $widgets = array(); foreach ($active_widgets as $widgetdata) { $data = (object) unserialize($widgetdata->value); $data->id = $widgetdata->id; $contents = Plugin::call('widget_' . $data->name, "{$data->name}", $data); $title = isset($data->title) ? $data->title : $data->name; $widgets[$data->id] = '<div class="widget ' . $data->name . '" id="widget_' . $data->id . '"> <div class="widgettitle" ondblclick="$(this).parents(\'.widget\').children(\'.widgetbody\').slideToggle();return false;">' . $title . ' <a class="removewidget" href="#" onclick="removeWidget(' . $data->id . ');return false;">[-]</a> <a class="collapsewidget" href="#" onclick="$(this).parents(\'.widget\').children(\'.widgetbody\').slideToggle();return false;">[v]</a> </div><div class="widgetbody"><div class="widgetcontent">' . $contents . '</div></div></div>'; } $widgets = implode('', array_filter($widgets)); return $widgets; }
/** * @brief dispatch 路由分发方法 * * @return void */ public static function dispatch() { // 注册最后的通用路由 $route = array('widget' => 'Page', 'method' => 'showPage', 'format' => '/%s/', 'patter' => '|^/([^/]+)[/]?$|', 'params' => array('alias')); self::setRoute('Page', $route); // 获取地址信息 if (OptionLibrary::get('rewrite') == 'open') { $pathInfo = str_replace(substr(LOGX_PATH, 0, strlen(LOGX_PATH) - 1), '', Request::S('REQUEST_URI', 'string')); $pathInfo = str_replace('?' . Request::S('QUERY_STRING', 'string'), '', $pathInfo); } else { $pathInfo = self::getPathInfo(); } $pathInfo = Plugin::call('pathInfo', $pathInfo); // 遍历路由表进行匹配 foreach (self::$_routeTable as $key => $route) { if (preg_match($route['patter'], $pathInfo, $matches)) { self::$_currentRoute = $key; $params = NULL; if (!empty($route['params'])) { unset($matches[0]); $params = array_combine($route['params'], $matches); } self::$_currentParams = $params; if (isset($route['widget'])) { Widget::getWidget($route['widget'])->{$route}['method']($params); } elseif (isset($route['plugin'])) { Plugin::getPlugin($route['plugin'])->{$route}['method']($params); } return; } } //echo '**'.$_SERVER['QUERY_STRING']; //$path = explode( '/', $pathInfo ); // 永久重定向为规范的 URL 地址 //Response::redirect( $pathInfo.'/', true ); // 没有匹配的路由则显示 404 页面 Response::error(404); }
function _get_options() { // Core options: $optionlist = array(array('Amazon Web Services', 'AWS Secret Access Key'), array('Amazon Web Services', 'AWS Access Key ID'), array('Amazon Web Services', 'S3 Bucket Name'), array('Time', 'Zone Offset')); // Plugin options $optionlist = Plugin::call('get_options', $optionlist); $options = array('system' => array(), 'user' => array()); foreach ($optionlist as $option) { $opobj = Option::get($option[0], $option[1]); if (!is_object($opobj)) { $opobj = new Option(); $opobj->grouping = $option[0]; $opobj->name = $option[1]; $opobj->id = $option[0] . ':' . $option[1]; } if ($opobj->user_id == 0) { $options['system'][] = $opobj; } else { $options['user'][] = $opobj; } } return $options; }
/** * @brief widgetContent 输出小工具内容 * * @param $widget 小工具对象 * @param $format 输出格式 * * @return void */ public function widgetContent($widget, $format = '') { echo Plugin::call($widget['call'], $format); }
/** * @brief postComment 发表评论 * * @return void */ public function postComment() { $c = array(); // 如果用户已登录,则可以不填写基本信息 if (Widget::getWidget('User')->isLogin()) { $user = Widget::getWidget('User')->getUser(); $c['uid'] = $user['uid']; $c['author'] = $user['username']; $c['email'] = $user['email']; $c['website'] = $user['website']; } else { $c['uid'] = 0; $c['author'] = Request::P('author', 'string'); $c['email'] = Request::P('email', 'string'); $c['website'] = Request::P('website', 'string'); } $c['pid'] = Request::P('postId'); $c['content'] = Request::P('content', 'string'); $error = ''; if (!$c['pid'] || !$c['author'] || !$c['email'] || !$c['content']) { // 检查信息完整性 $error = _t('Author, Email and Content can not be null.'); } else { // 检查文章是否存在、是否允许评论 Widget::initWidget('Post'); $post = new PostLibrary(); $p = $post->getPost($c['pid']); if ($p) { Widget::getWidget('Post')->setPID($c['pid']); } else { $p = $post->getPage($c['pid'], FALSE); Widget::getWidget('Post')->setAlias($p['alias']); } if (!Widget::getWidget('Post')->query() || !Widget::getWidget('Post')->postAllowReply()) { $error = _t('Comment closed.'); } else { // TODO 敏感词过滤 // TODO 内容处理 $c['content'] = str_replace(array("\r\n", "\n", "\r"), '<br />', htmlspecialchars($c['content'])); $c = Plugin::call('postComment', $c); // 写入评论 $comment = new CommentLibrary(); $comment->postComment($c); // 评论计数加一 $post->incReply($c['pid']); // 保存用户信息 Response::setCookie('author', $c['author'], time() + 24 * 3600 * 365); Response::setCookie('email', $c['email'], time() + 24 * 3600 * 365); Response::setCookie('website', $c['website'], time() + 24 * 3600 * 365); } } if ($error) { $r = array('success' => FALSE, 'message' => $error); } else { $r = array('success' => TRUE, 'message' => _t('Post comment success.')); } if (Request::isAjax()) { Response::ajaxReturn($r); } else { if ($error) { Response::error(_t('Post failed'), $error); } else { Response::back(); } } }
/** * @brief __call 魔术方法,用于处理钩子 * * @param $name 钩子名 * @param $arguments 钩子参数 * * @return mix */ public function __call($name, $arguments) { return Plugin::call($name, $arguments); }
/** * @brief postPage 发布页面 * * @return void */ public function postPage() { $p = array(); $p['title'] = Request::P('title', 'string'); $p['alias'] = Request::P('alias', 'string'); $p['content'] = Request::P('content', 'string'); if (!$p['title'] || !$p['content'] || !$p['alias']) { $r = array('success' => FALSE, 'message' => _t('Title, Content and Alias can not be null.')); Response::ajaxReturn($r); return; } $p['allow_reply'] = Request::P('allowComment') ? 1 : 0; $user = Widget::getWidget('User')->getUser(); $p['uid'] = $user['uid']; $p['top'] = 0; $p['type'] = 2; $p['status'] = 1; $post = new PostLibrary(); // 检查别名是否重复 if ($post->getPage($p['alias'])) { $r = array('success' => FALSE, 'message' => _t('Alias already exists.')); Response::ajaxReturn($r); return; } // 写入页面 $pid = $post->postPost($p); // 处理新附件 $meta = new MetaLibrary(); $meta->setType(3); $meta->setPID(1000000000); $attachments = $meta->getMeta(); foreach ($attachments as $a) { $meta->movRelation($a['mid'], 1000000000, $pid); } // 插件接口 $p['pid'] = $pid; Plugin::call('postPage', $p); $r = array('success' => TRUE, 'message' => _t('Add page success.')); Response::ajaxReturn($r); }
<script type="text/javascript" src="/js/jquery.cssrule.js"></script> <link type="text/css" rel="stylesheet" href="/js/syntax/styles/shCore.css"/> <link type="text/css" rel="stylesheet" href="/js/syntax/styles/shThemeDefault.css"/> <script type="text/javascript"> SyntaxHighlighter.config.clipboardSwf = '/js/syntax/scripts/clipboard.swf'; var cur_chan = '<?php echo $cur_chan; ?> '; </script> <script type="text/javascript">$P = new PHP_JS();</script> <?php Plugin::call('header'); ?> </head> <body> <div id="drawer"><table></table></div> <div id="mainscroller"> <table id="notices" class="notices"></table> <div id="portal" class="portal"></div> <script type="text/javascript"> var user_id = <?php echo $user_id; ?> ; var username = '<?php
function _instant_time($params) { $user = $params['user']; $channel = $params['channel']; $task = $params['task']; $pcode = $this->_project_alias($params['pcode']); $time = $params['time']; $approx = $params['approx']; $notes = $params['notes']; $return = true; if (strpos($time, ':') === 0) { $hours = floatval(substr($time, 1)) / 60; } elseif (strpos($time, ':') > 0) { list($hours, $minutes) = split(':', $time); $hours = intval($hours) + $minutes / 60; } else { $hours = floatval($time); } if (strpos($approx, ':') === 0) { $est = floatval(substr($approx, 1)) / 60; } elseif (strpos($approx, ':') > 0) { $est = (strtotime($approx) - strtotime($time)) / 3600; } elseif (trim($approx) == '') { $est = null; } else { $est = floatval($approx); } extract(Plugin::call('task_filter', array('task' => $task, 'notes' => $notes))); $timerec = array('time' => $hours, 'ondate' => date('Y-m-d'), 'pcode' => $pcode, 'task' => $task, 'notes' => $notes, 'billable' => !(preg_match('%-\\$%', $task) || preg_match('%-\\$%', $notes))); $projects = $this->_get_projects(); if (in_array($timerec['pcode'], $projects)) { $this->_add_time($timerec); $msg = "<span class=\"time\">Added {$hours} hours</span> <span class=\"project\">{$pcode}</span> <span class=\"task\">{$task}</span>"; Immediate::ok($msg, 'ok time time_instant'); } else { Immediate::error('Specified project "' . $timerec['pcode'] . '" does not exist.'); } return $return; }
<?php namespace Garradin; require_once __DIR__ . '/_inc.php'; $page = Utils::get('_u') ?: 'index.php'; $plugin = new Plugin(Utils::get('_p')); define('Garradin\\PLUGIN_ROOT', $plugin->path()); define('Garradin\\PLUGIN_URL', WWW_URL . 'admin/plugin/' . $plugin->id() . '/'); define('Garradin\\PLUGIN_QSP', '?'); $tpl->assign('plugin', $plugin->getInfos()); $tpl->assign('plugin_root', PLUGIN_ROOT); $plugin->call('admin/' . $page);
/** * @brief postPost 添加一篇文章 * * @return void */ public function postPost() { $p = array(); $p['title'] = htmlspecialchars(Request::P('title', 'string')); $p['content'] = Request::P('content', 'string'); $p['category'] = Request::P('category', 'array'); if (!$p['title'] || !$p['content'] || count($p['category']) == 1 && !$p['category'][0]) { $r = array('success' => FALSE, 'message' => _t('Title, Content and Category can not be null.')); Response::ajaxReturn($r); return; } $p['allow_reply'] = Request::P('allowComment') ? 1 : 0; $p['top'] = Request::P('top') ? 1 : 0; $user = Widget::getWidget('User')->getUser(); $p['uid'] = $user['uid']; $p['alias'] = ''; $p['type'] = 1; $p['status'] = 1; // 发布文章 $post = new PostLibrary(); $meta = new MetaLibrary(); $pid = $post->postPost($p); // 处理分类 foreach ($p['category'] as $c) { $meta->addRelation($c, $pid); } // 处理标签 if ($p['tags'] = Request::P('tags', 'string')) { $p['tags'] = str_replace(array(' ', ',', '、'), ',', $p['tags']); $p['tags'] = explode(',', $p['tags']); $meta->setType(2); foreach ($p['tags'] as $tag) { $meta->setName($tag); $t = $meta->getMeta(); if (!$t) { $t = $meta->addMeta(array('type' => 2, 'name' => $tag)); } else { $t = $t[0]['mid']; } $meta->addRelation($t, $pid); } } // 处理新附件 $meta = new MetaLibrary(); $meta->setType(3); $meta->setPID(1000000000); $attachments = $meta->getMeta(); foreach ($attachments as $a) { $meta->movRelation($a['mid'], 1000000000, $pid); } // 插件接口 $p['pid'] = $pid; Plugin::call('postPost', $p); $r = array('success' => TRUE, 'message' => _t('Add post success.')); Response::ajaxReturn($r); }
function uploadPanel() { art.dialog({ content:'<div class="fieldset flash" id="fsUploadProgress"></div><div id="divStatus">0 个文件已上传</div><div style="padding-top:10px;padding-left:5px;"><span id="spanButtonPlaceHolder"></span><input id="btnCancel" type="button" value="取消上传" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" /></div>', fixed:true, title:'<?php _e("Upload"); ?> ', width:400, id:'uploadPanel', style:'noIcon' }); swfu = new SWFUpload(settings); } </script> <?php if ($editor = Plugin::call('editor', '')) { echo $editor; } else { ?> <script> function insertToEditor( url, mime, name ) { if( mime.replace('image','') != mime ) { $('#add-post-content').insertAtCaret( '<img src="'+url+'" />' ); } else { $('#add-post-content').insertAtCaret( '<a href="'+url+'" target="_blank">'+name+'</a>' ); } } </script> <?php }
function chanbar() { $channels = DB::get()->col("select channel from presence WHERE channel <> '' GROUP BY presence.channel order by presence.user_id = :user_id desc, count(status) desc limit 5", array('user_id' => Auth::user_id())); $user = DB::get()->row("SELECT users.*, options.value as nickname FROM users LEFT JOIN options ON options.user_id = users.id AND options.name = 'Nickname' AND grouping = 'Identity' WHERE users.id = :user_id", array('user_id' => Auth::user_id())); if ($user->nickname == '') { $user->nickname = $user->username; } // $rooms = DB::get()->results("SELECT * FROM channels WHERE user_id = :user_id ORDER BY name ASC", array('user_id' => Auth::user_id())); $rooms = DB::get()->results("SELECT channels.*, options.value as alias, sq.value as squelch FROM channels \n\t\t\tLEFT JOIN options on channels.name = options.room and options.grouping = 'Rooms' and options.name = 'alias' and options.user_id = 0\n\t\t\tLEFT JOIN options sq on channels.name = sq.room and sq.grouping = 'squelch' and sq.user_id = channels.user_id\n\t\t\tWHERE channels.user_id = :user_id \n\t\t\tORDER BY channels.name ASC", array('user_id' => Auth::user_id())); $roomary = DB::get()->col("SELECT name FROM channels WHERE user_id = :user_id", array('user_id' => Auth::user_id())); $channels = array_diff($channels, $roomary); $channelhtml = ''; foreach ($channels as $channel) { if (!preg_match('%^\\w+:%i', $channel)) { $channelhtml .= '<li><a href="#" onclick="joinRoom(\'' . $channel . '\');return false;">' . $channel . '</a></li>'; } } $sups = DB::get()->assoc('SELECT channels.name, count(*) as ct FROM presence, channels WHERE presence.channel = channels.name AND presence.msgtime > channels.last AND channels.active = 0 AND channels.user_id = :user_id AND presence.user_id <> :user_id AND presence.type <> "status" GROUP BY channels.name;', array('user_id' => Auth::user_id())); $roomhtml = ''; foreach ($rooms as $room) { $classes = 'inroom'; if ($room->active == 1) { $classes .= ' active'; } if (preg_match('%^(?P<roomtype>\\w+):(?P<search>.+)$%i', $room->name, $searchmatch)) { $roomname = $searchmatch['search']; $classes .= ' ' . $searchmatch['roomtype']; } else { $searchmatch = array('roomtype' => '', 'search' => $room->name); $roomname = $room->name; } if ($room->alias != '') { $roomname = $room->alias; } $link = '<li class="' . $classes . '" id="tab__' . $room->name . '"><a href="#" onclick="setRoom(\'' . $room->name . '\', this);return false;">'; $link .= $roomname; if (isset($sups[$room->name]) && $sups[$room->name] > 0 && !$room->active) { $link .= '<sup>' . $sups[$room->name] . '</sup>'; } $link .= '</a>'; $link = Plugin::call('chanbar_roomlink', $link, $room, $searchmatch['roomtype']); $roomhtml .= $link; $roomhtml .= '<div class="submenu"><ul><li><a href="#" onclick="partRoom(\'' . $room->name . '\');return false;">Part</a></li>'; $roomsquelch = $room->squelch == 'true' ? 'on' : 'off'; //DB::get()->val("SELECT value from options where grouping = 'squelch' AND user_id = :user_id AND room = :room", array('user_id' => $user->id, 'room' => $room->name)) $roomhtml .= '<li><a href="#" onclick="toggler(this);squelchRoom(\'' . $room->name . '\',$(\'span\',this).hasClass(\'on\'));return false;"><span class="toggle ' . $roomsquelch . ' roomsquelch_' . $room->name . '"></span>Squelch </a></li>'; $add = ''; $add = Plugin::call('chanbar_menu', $add, $room, $searchmatch['roomtype']); $roomhtml .= $add; $roomhtml .= '</ul></div></li>'; } $components = array('roomhtml' => $roomhtml, 'channelhtml' => $channelhtml); $v = new View($components); return $v->capture('chanbar'); }
/** * @brief foot 输出底部信息 * * @return void */ public function foot() { echo Plugin::call('foot', ''); }
function process($path) { global $config; Plugin::call('bot_process_' . reset($path)); }
function __call($method, $path) { $method = preg_replace('%[^\\w_]%', '', $method); Plugin::call('ajax_' . $method, $path); }