/**
  * @brief showIndex 显示主页
  *
  * @return void
  */
 public function showIndex($params)
 {
     Widget::initWidget('Post');
     Widget::getWidget('Post')->setPerPage(8);
     Widget::getWidget('Post')->setCurrentPage(isset($params['page']) ? $params['page'] : 1);
     Widget::getWidget('Post')->query();
     $this->display('index.php');
 }
 /**
  * @brief showTag 显示某标签下的文章
  *
  * @param $params 参数
  *
  * @return void
  */
 public function showTag($params)
 {
     // 根据 Meta 别名获取 Meta ID
     $meta = new MetaLibrary();
     $meta->setType(2);
     $meta->setName(urldecode($params['name']));
     if (!($m = $meta->getMeta())) {
         Response::error(404);
         return;
     }
     // 获取文章数据
     Widget::initWidget('Post');
     Widget::getWidget('Post')->setPerPage(8);
     Widget::getWidget('Post')->setCurrentPage(isset($params['page']) ? $params['page'] : 1);
     Widget::getWidget('Post')->setCurrentMeta($m[0]['mid']);
     Widget::getWidget('Post')->query();
     // 设置标题、描述、关键词
     Widget::getWidget('Global')->title = $m[0]['name'];
     Widget::getWidget('Global')->description = $m[0]['description'];
     Widget::getWidget('Global')->keywords = $m[0]['name'];
     $this->display('index.php');
 }
 /**
  * @brief showSearch 显示搜索结果
  *
  * @param $params 传入参数
  *
  * @return void
  */
 public function showSearch($params)
 {
     if (!isset($params['word'])) {
         if (!($word = Request::P('word', 'string'))) {
             Response::back();
         } else {
             Response::redirect(Router::patch('SearchWord', array('word' => urlencode(trim($word)))));
         }
         return;
     }
     // 获取文章数据
     Widget::initWidget('Post');
     Widget::getWidget('Post')->setPerPage(8);
     Widget::getWidget('Post')->setCurrentPage(isset($params['page']) ? $params['page'] : 1);
     // 未来支持分类内搜索
     // Widget::getWidget('Post')->setCurrentMeta( $m[0]['mid'] );
     Widget::getWidget('Post')->setSearchWord(urldecode(trim($params['word'])));
     Widget::getWidget('Post')->query();
     // 设置标题、描述、关键词
     Widget::getWidget('Global')->title = urldecode($params['word']);
     // Widget::getWidget('Global')->description = $m[0]['description'];
     Widget::getWidget('Global')->keywords = urldecode($params['word']);
     $this->display('index.php');
 }
function widget_content($widget, $format = '')
{
    return Widget::getWidget('Widget')->widgetContent($widget, $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 commentDo 发表评论
  *
  * @return void
  */
 private function commentDo()
 {
     Widget::initWidget('Comment');
     Widget::getWidget('Comment')->postComment();
 }
Esempio n. 7
0
            ?>
</a></li>
				<?php 
        }
        ?>
				</ul>
			</div>
		</div>
		<?php 
    }
    ?>
	</div>
</div>
<?php 
} else {
    $u = Widget::getWidget('User')->getUser($uid);
    ?>
<div class="box">
	<div class="box-title">
		<h3><?php 
    _e('User Edit');
    ?>
</h3>
		<span></span>
	</div>
	<div class="box-content">
		<form action="<?php 
    path(array('do' => 'editUser'), 'AdminDo');
    ?>
" method="post" name="edit_user" id="edit-user">
			<ul id="add-post-option">
 /**
  * @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);
 }
Esempio n. 9
0
 /**
  * @author giorgio 25/set/2013
  * 
  * renders the widgets of the page as described in the passed xml config file
  * 
  * @param string $widgetsConfFilename xml configuration filename for the widgets
  * @param arrayn $optionsArray array of option to be passed to the widget loader
  * 
  * @return array|AMA_Error
  */
 public function fillin_widgetsFN($widgetsConfFilename = '', $optionsArray = array())
 {
     require_once ROOT_DIR . '/widgets/include/widget_includes.inc.php';
     if (is_file($widgetsConfFilename)) {
         try {
             $widgetAr = ArrayToXML::toArray(file_get_contents($widgetsConfFilename));
         } catch (Exception $e) {
             /*
              * see config_errors.inc.php line 167 and following.
              * depending on the erorr phase / severity something will happen...
              */
             return new ADA_Error(NULL, 'Widget configuration XML is not valid', __METHOD__, ADA_ERROR_ID_XML_PARSING);
         }
     }
     /**
      * @author giorgio 25/feb/2014
      * ArrayToXML::toArray does not return an array of array if there's
      * only one widget in the xml. Let's build an array of array even in this case.
      */
     if (!is_array(reset($widgetAr['widget']))) {
         $widgets = array($widgetAr['widget']);
     } else {
         $widgets = $widgetAr['widget'];
     }
     $retArray = array();
     foreach ($widgets as $widget) {
         // if widget is not active skip the current iteration
         if (isset($widget['active']) && intval($widget['active']) === 0 || isset($widget[$widget['id']]) && intval($widget[$widget['id']['isActive']]) === 0) {
             continue;
         }
         $wobj = new Widget($widget);
         /**
          * if there are some params passed in, tell it to the widget
          */
         if (isset($optionsArray[$wobj->templateField]) && !empty($optionsArray[$wobj->templateField])) {
             foreach ($optionsArray[$wobj->templateField] as $name => $value) {
                 $wobj->setParam($name, $value);
             }
         }
         $retArray[$wobj->templateField] = $wobj->getWidget();
     }
     return $retArray;
 }
Esempio n. 10
0
 /**
  * @brief init LogX 全局初始化方法
  *
  * @return void
  */
 public static function init()
 {
     // 输出 Logo
     if (isset($_GET['591E-D5FC-8065-CD36-D3E8-E45C-DB86-9197'])) {
         Response::logo();
     }
     // 非 DEBUG 模式下关闭错误输出
     if (defined('LOGX_DEBUG')) {
         error_reporting(E_ALL);
     } else {
         error_reporting(0);
     }
     // 设置自动载入函数
     function __autoLoad($className)
     {
         if (substr($className, -7) == 'Library' && is_file(LOGX_LIB . $className . '.php')) {
             @(require_once LOGX_LIB . $className . '.php');
         }
     }
     // 设置错误与异常处理函数
     set_error_handler(array(__CLASS__, 'error'));
     set_exception_handler(array(__CLASS__, 'exception'));
     // 运行环境检查
     if (!version_compare(PHP_VERSION, '5.0.0', '>=')) {
         throw new LogXException(sprintf(_t('LogX needs PHP 5.0.x or higher to run. You are currently running PHP %s.'), PHP_VERSION));
     }
     if (!version_compare(PHP_VERSION, '5.2.0', '>=')) {
         // 针对低版本 PHP 的兼容代码
         @(require_once LOGX_CORE . 'Compat.php');
     }
     // 设置语言
     if (defined('LOGX_LANGUAGE')) {
         Language::set(LOGX_LANGUAGE);
     } else {
         Language::set('zh-cn');
     }
     // 预编译核心文件
     global $coreFiles;
     if (!defined('LOGX_DEBUG') && !file_exists(LOGX_CACHE . '~core.php')) {
         Compile::build(LOGX_CACHE, $coreFiles, 'core');
     } elseif (!defined('LOGX_DEBUG')) {
         $file_time = filemtime(LOGX_CACHE . '~core.php');
         foreach ($coreFiles as $file) {
             if (filemtime($file) > $file_time) {
                 Compile::build(LOGX_CACHE, $coreFiles, 'core');
                 break;
             }
         }
     }
     self::$_globalVars = array('RUN' => array('TIME' => microtime(TRUE), 'MEM' => function_exists('memory_get_usage') ? memory_get_usage() : 0, 'LANG' => 'zh-cn'), 'SYSTEM' => array('OS' => PHP_OS, 'HTTP' => Request::S('SERVER_SOFTWARE', 'string'), 'PHP' => PHP_VERSION, 'MYSQL' => ''), 'SUPPORT' => array('MYSQL' => function_exists('mysql_connect'), 'GD' => function_exists('imagecreate'), 'MEMCACHE' => function_exists('memcache_connect'), 'SHMOP' => function_exists('shmop_open'), 'GZIP' => function_exists('ob_gzhandler'), 'TIMEZONE' => function_exists('date_default_timezone_set'), 'AUTOLOAD' => function_exists('spl_autoload_register')), 'INI' => array('ALLOW_CALL_TIME_PASS_REFERENCE' => ini_get('allow_call_time_pass_reference'), 'MAGIC_QUOTES_GPC' => ini_get('magic_quotes_gpc'), 'REGISTER_GLOBALS' => ini_get('register_globals'), 'ALLOW_URL_FOPEN' => ini_get('allow_url_fopen'), 'ALLOW_URL_INCLUDE' => ini_get('allow_url_include'), 'SAFE_MODE' => ini_get('safe_mode'), 'MAX_EXECUTION_TIME' => ini_get('max_execution_time'), 'MEMORY_LIMIT' => ini_get('memory_limit'), 'POST_MAX_SIZE' => ini_get('post_max_size'), 'FILE_UPLOADS' => ini_get('file_uploads'), 'UPLOAD_MAX_FILESIZE' => ini_get('upload_max_filesize'), 'MAX_FILE_UPLOADS' => ini_get('max_file_uploads')));
     // 清除不需要的变量,防止变量注入
     $defined_vars = get_defined_vars();
     foreach ($defined_vars as $key => $value) {
         if (!in_array($key, array('_POST', '_GET', '_COOKIE', '_SERVER', '_FILES'))) {
             ${$key} = '';
             unset(${$key});
         }
     }
     // 对用户输入进行转义处理
     if (!get_magic_quotes_gpc()) {
         $_GET = self::addSlashes($_GET);
         $_POST = self::addSlashes($_POST);
         $_COOKIE = self::addSlashes($_COOKIE);
     }
     // 开启输出缓存
     if (defined('LOGX_GZIP') && self::$_globalVars['SUPPORT']['GZIP']) {
         ob_start('ob_gzhandler');
     } else {
         ob_start();
     }
     // 连接到数据库
     Database::connect(DB_HOST, DB_USER, DB_PWD, DB_NAME, DB_PCONNECT);
     self::$_globalVars['SYSTEM']['MYSQL'] = Database::version();
     // 设定时区
     if (self::$_globalVars['SUPPORT']['TIMEZONE']) {
         date_default_timezone_set(OptionLibrary::get('timezone'));
     }
     // 连接到缓存
     Cache::connect(CACHE_TYPE);
     // 初始化路由表
     Router::init();
     // 初始化主题控制器
     Theme::init();
     // 初始化 Plugin
     Plugin::initPlugins();
     // 初始化全局组件
     Widget::initWidget('Global');
     Widget::initWidget('Widget');
     Widget::initWidget('Page');
     Widget::initWidget('User');
     // 尝试自动登录
     Widget::getWidget('User')->autoLogin();
     // 启动路由分发
     Router::dispatch();
 }
 /**
  * @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);
 }
 /**
  * @brief advancedSettingsDo 保存高级设置
  *
  * @return void
  */
 private function advancedSettingsDo()
 {
     // 验证用户权限
     if (!Widget::getWidget('User')->isAdmin()) {
         Response::ajaxReturn(array('success' => FALSE, 'message' => _t('Permission denied.')));
         return;
     }
     $rewrite = Request::P('rewrite', 'string');
     $timezone = Request::P('timezone', 'string');
     $register = Request::P('register', 'string');
     if (!$rewrite || !$timezone || !$register) {
         $r = array('success' => FALSE, 'message' => _t('Option can not be null.'));
         Response::ajaxReturn($r);
     } else {
         if ($rewrite == 'close') {
             if (file_exists(LOGX_ROOT . '.htaccess') && !@unlink(LOGX_ROOT . '.htaccess')) {
                 $r = array('success' => FALSE, 'message' => _t('Can not delete .htaccess file.'));
                 Response::ajaxReturn($r);
                 return;
             }
         } else {
             $content = "# BEGIN LogX\n\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase " . LOGX_PATH . "\nRewriteCond \$1 ^(index\\.php)?\$ [OR]\nRewriteCond \$1 \\.(gif|jpg|png|css|js|ico)\$ [NC,OR]\nRewriteCond %{REQUEST_FILENAME} -f [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^(.*)\$ - [S=1]\nRewriteRule . " . LOGX_PATH . "index.php [L]\n</IfModule>\n\n# END LogX";
             if (!file_exists(LOGX_ROOT . '.htaccess') && !@file_put_contents(LOGX_ROOT . '.htaccess', $content)) {
                 $r = array('success' => FALSE, 'message' => _t('Can not create .htaccess file.'));
                 Response::ajaxReturn($r);
                 return;
             }
         }
         OptionLibrary::set('rewrite', $rewrite);
         OptionLibrary::set('timezone', $timezone);
         OptionLibrary::set('register', $register);
         $r = array('success' => TRUE, 'message' => _t('Settings Saved.'));
         Response::ajaxReturn($r);
     }
 }
 /**
  * @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);
 }
function run_info()
{
    return Widget::getWidget('Global')->runInfo();
}
Esempio n. 15
0
_e('Reply');
?>
</th>
					<th class="radius-topright"><?php 
_e('Date');
?>
</th>
				</tr>
			</thead>
			<tbody>
			<?php 
$i = 0;
Widget::initWidget('Post');
Widget::getWidget('Post')->setPerPage(10);
Widget::getWidget('Post')->setCurrentPage(Request::G('page') ? Request::G('page') : 1);
Widget::getWidget('Post')->query();
while (post_next()) {
    ?>
				<tr<?php 
    if ($i % 2 == 0) {
        ?>
 class="even"<?php 
    }
    ?>
 id="post-<?php 
    post_id();
    ?>
">
					<td><input type="checkbox" value="<?php 
    post_id();
    ?>
 /**
  * @brief showUser 显示某用户发布的文章
  *
  * @param $params 传入参数
  *
  * @return void
  */
 public function showUser($params)
 {
     // 根据 uid 获取 用户信息
     $user = new UserLibrary();
     $user->setUID($params['uid']);
     if (!($u = $user->getUser())) {
         Response::error(404);
         return;
     }
     // 获取文章数据
     Widget::initWidget('Post');
     Widget::getWidget('Post')->setPerPage(8);
     Widget::getWidget('Post')->setCurrentPage(isset($params['page']) ? $params['page'] : 1);
     Widget::getWidget('Post')->setAuthor($u['uid']);
     Widget::getWidget('Post')->query();
     // 设置标题、描述、关键词
     Widget::getWidget('Global')->title = urldecode($u['username']);
     $this->display('index.php');
 }
?>
</th>
					<th class="radius-topright"><?php 
_e('Date');
?>
</th>
				</tr>
			</thead>
			<tbody>
			<?php 
$i = 0;
Widget::initWidget('Comment');
Widget::getWidget('Comment')->setStatus(2);
Widget::getWidget('Comment')->setPerPage(20);
Widget::getWidget('Comment')->setCurrentPage(Request::G('cpage') ? Request::G('cpage') : 1);
Widget::getWidget('Comment')->query();
while (comment_next()) {
    ?>
				<tr<?php 
    if ($i % 2 == 0) {
        ?>
 class="even"<?php 
    }
    ?>
 id="post-<?php 
    comment_id();
    ?>
">
					<td><input type="checkbox" value="<?php 
    comment_id();
    ?>