作者:Willsho
项目:OLC
public function run(&$content)
{
if (isset($_GET['m']) && $_GET['m'] === 'Install') {
return;
}
$data = S('hooks');
if (!$data) {
$hooks = M('Hooks')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('Addons')->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
作者:yxz102
项目:weiphp3.
public function run(&$content)
{
if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
return;
}
$data = S('hooks');
if (!$data) {
$hooks = M('hooks')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = (array) M('addons')->where($map)->getField('id,name');
$data_plugin = (array) M('plugin')->where($map)->getField('id,name');
$data = array_merge($data, $data_plugin);
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
作者:nomagam
项目:Charm
/**
* 查询指定分类的详细信息
* @param int $info detail 查询的 id 或者slug
*/
public function detail($info = 1)
{
if (get_opinion("auto_channel", false, false)) {
$this->channel($info);
Hook::listen('app_end');
die;
}
$CatsLogic = new CatsLogic();
$PostsLogic = new PostsLogic();
$cat = $CatsLogic->detail($info);
//
$this->assign('cat_id', $cat['cat_id']);
// 赋值数据集
$this->if404($cat, "非常抱歉,没有这个分类,可能它已经躲起来了");
//优雅的404
$posts_id = $CatsLogic->getPostsId($cat['cat_id']);
$count = sizeof($posts_id);
$count == 0 ? $res404 = 0 : ($res404 = 1);
if (!empty($posts_id)) {
$Page = new GreenPage($count, get_opinion('PAGER'));
$pager_bar = $Page->show();
$limit = $Page->firstRow . ',' . $Page->listRows;
$posts_list = $PostsLogic->getList($limit, 'single', 'post_date desc', true, array(), $posts_id);
}
$this->assign('title', '分类 ' . $cat['cat_name'] . ' 所有文章');
// 赋值数据集
$this->assign('res404', $res404);
$this->assign('postslist', $posts_list);
// 赋值数据集
$this->assign('pager', $pager_bar);
// 赋值分页输出
$this->assign('breadcrumbs', get_breadcrumbs('cats', $cat['cat_id']));
$this->display('Archive/single-list');
}
作者:hujun123qw
项目:plove
/**
* 初始化方法
* @author jry <598821125@qq.com>
*/
protected function _initialize()
{
// 系统开关
if (!C('TOGGLE_WEB_SITE')) {
$this->error('站点已经关闭,请稍后访问~');
}
// 获取所有模块配置的用户导航
$mod_con['status'] = 1;
$_user_nav_main = array();
$_user_nav_list = D('Admin/Module')->where($mod_con)->getField('user_nav', true);
foreach ($_user_nav_list as $key => $val) {
if ($val) {
$val = json_decode($val, true);
$_user_nav_main = array_merge($_user_nav_main, $val['main']);
}
}
// 监听行为扩展
\Think\Hook::listen('corethink_behavior');
$this->assign('meta_keywords', C('WEB_SITE_KEYWORD'));
$this->assign('meta_description', C('WEB_SITE_DESCRIPTION'));
$this->assign('_new_message', cookie('_new_message'));
// 获取用户未读消息数量
$this->assign('_user_auth', session('user_auth'));
// 用户登录信息
$this->assign('_user_nav_main', $_user_nav_main);
// 用户导航信息
}
作者:easyt
项目:easyt
public function run(&$content)
{
if (!file_exist(UPLOAD_PATH . 'install.lock')) {
return true;
}
$data = S('common_behavior_hooks');
if (!$data) {
$hooks = M('hooks')->where(array('status' => 1))->getField('name, addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('addons')->where($map)->getField('id, name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('common_behavior_hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
作者:applemi
项目:tanggu
/**
* 行为扩展的执行入口必须是run
* @author jry <598821125@qq.com>
*/
public function run(&$content)
{
// 安装模式下直接返回
if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
return;
}
// 添加插件配置
$addon_config['ADDON_PATH'] = './Addons/';
$addon_config['AUTOLOAD_NAMESPACE'] = C('AUTOLOAD_NAMESPACE');
$addon_config['AUTOLOAD_NAMESPACE']['Addons'] = $addon_config['ADDON_PATH'];
C($addon_config);
$data = S('hooks');
if (!$data || APP_DEBUG === true) {
$hooks = D('Admin/Hook')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = D('Admin/Addon')->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
作者:beyondzg
项目:thinkph
public function run(&$params)
{
if (!defined('BUILD_LITE_FILE')) {
return;
}
$litefile = C('RUNTIME_LITE_FILE', null, RUNTIME_PATH . 'lite.php');
if (is_file($litefile)) {
return;
}
$defs = get_defined_constants(true);
$content = 'namespace {$GLOBALS[\'_beginTime\'] = microtime(TRUE);';
if (MEMORY_LIMIT_ON) {
$content .= '$GLOBALS[\'_startUseMems\'] = memory_get_usage();';
}
// 生成数组定义
unset($defs['user']['BUILD_LITE_FILE']);
$content .= $this->buildArrayDefine($defs['user']) . '}';
// 读取编译列表文件
$filelist = is_file(CONF_PATH . 'lite.php') ? include CONF_PATH . 'lite.php' : array(THINK_PATH . 'Common/functions.php', COMMON_PATH . 'Common/function.php', CORE_PATH . 'Think' . EXT, CORE_PATH . 'Hook' . EXT, CORE_PATH . 'App' . EXT, CORE_PATH . 'Dispatcher' . EXT, CORE_PATH . 'Log' . EXT, CORE_PATH . 'Log/Driver/File' . EXT, CORE_PATH . 'Route' . EXT, CORE_PATH . 'Controller' . EXT, CORE_PATH . 'View' . EXT, CORE_PATH . 'Storage' . EXT, CORE_PATH . 'Storage/Driver/File' . EXT, CORE_PATH . 'Exception' . EXT, BEHAVIOR_PATH . 'ParseTemplateBehavior' . EXT, BEHAVIOR_PATH . 'ContentReplaceBehavior' . EXT);
// 编译文件
foreach ($filelist as $file) {
if (is_file($file)) {
$content .= compile($file);
}
}
// 处理Think类的start方法
$content = preg_replace('/\\$runtimefile = RUNTIME_PATH(.+?)(if\\(APP_STATUS)/', '\\2', $content, 1);
$content .= "\nnamespace { Think\\Think::addMap(" . var_export(\Think\Think::getMap(), true) . ");";
$content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(\Think\Hook::get(), true) . ');Think\\Think::start();}';
// 生成运行Lite文件
file_put_contents($litefile, strip_whitespace('<?php ' . $content));
}
作者:xuyi591
项目:ipensof
/**
* 发送数据到客户端
* @access public
* @param mixed $data 数据
* @param string $type 返回类型
* @param bool $return 是否返回数据
* @return mixed
*/
public function send($data = [], $type = '', $return = false)
{
if ('' == $type) {
$type = $this->type ?: (IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'));
}
$type = strtolower($type);
$data = $data ?: $this->data;
if (!headers_sent() && isset($this->contentType[$type])) {
header('Content-Type:' . $this->contentType[$type] . '; charset=utf-8');
}
if (is_callable($this->transform)) {
$data = call_user_func_array($this->transform, [$data]);
} else {
switch ($type) {
case 'json':
// 返回JSON数据格式到客户端 包含状态信息
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
break;
case 'jsonp':
// 返回JSON数据格式到客户端 包含状态信息
$handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler');
$data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');';
break;
}
}
APP_HOOK && Hook::listen('return_data', $data);
if ($return) {
return $data;
}
echo $data;
$this->isExit() && exit;
}
作者:lipeng-githu
项目:corethin
/**
* 初始化方法
* @author jry <598821125@qq.com>
*/
protected function _initialize()
{
// 系统开关
if (!C('TOGGLE_WEB_SITE')) {
$this->error('站点已经关闭,请稍后访问~');
}
// 获取所有模块配置的用户导航
$mod_con['status'] = 1;
$_user_nav_main = array();
$_user_nav_list = D('Admin/Module')->where($mod_con)->getField('user_nav', true);
foreach ($_user_nav_list as $key => $val) {
if ($val) {
$val = json_decode($val, true);
if ($val['main']) {
$_user_nav_main = array_merge($_user_nav_main, $val['main']);
}
}
}
// 监听行为扩展
\Think\Hook::listen('corethink_behavior');
$this->assign('meta_keywords', C('WEB_SITE_KEYWORD'));
$this->assign('meta_description', C('WEB_SITE_DESCRIPTION'));
$this->assign('_new_message', cookie('_new_message'));
// 获取用户未读消息数量
$this->assign('_user_auth', session('user_auth'));
// 用户登录信息
$this->assign('_user_nav_main', $_user_nav_main);
// 用户导航信息
$this->assign('_user_center_side', C('USER_CENTER_SIDE'));
// 用户中心侧边
$this->assign('_user_login_modal', C('USER_LOGIN_MODAL'));
// 用户登录弹窗
$this->assign('_home_public_layout', C('HOME_PUBLIC_LAYOUT'));
// 页面公共继承模版
}
作者:zachdar
项目:GreenCM
/**
* @param mixed $content
*/
public function run(&$content)
{
/**
* //真不知道说什么好。。。
* 这里 原因是tp 不能把tag放在项目配置中,只能放在common中,而common模块先于install 初始化
* so。。。。。
*
*/
if (C('DB_TYPE') == 'GreenCMS_DB_TYPE') {
} else {
if (isset($_GET['m']) && strtolower($_GET['m']) == 'install') {
return;
}
$data = S('hooks');
if (!$data) {
$hooks = M('Hooks')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('Addons')->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, $addons);
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
}
作者:h13679971
项目:baseItboy
public function run(&$parms)
{
//安装时不执行
if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
return;
}
$data = S('global_hooks');
if (!$data) {
$hooks = M('Hooks', "common_")->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('Addons', "common_")->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('global_hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
作者:Anymagi
项目:Car-Sticke
public function GetUsers($UsersId, $Feild)
{
$where['userid'] = array('IN', $UsersId);
$result = self::where($where)->field($Feild)->select();
if ($result !== false) {
return $result;
} else {
\Think\Hook::listen('HomeLog', $parm = array('function' => 'GetUsers -> $result', 'logmsg' => 'result is false', 'level' => 'ALERT'));
}
}
作者:Anymagi
项目:Car-Sticke
public function SmsReady($mobile, $content)
{
$mobileids = $mobile . date('YmdHis');
$result = self::sendSMS($mobile, $content, $mobileids);
if ($result != true) {
\Think\Hook::listen('HomeLog', $parm = array('function' => 'SendSmsModel::SmsReady -> $result', 'logmsg' => 'result is false, ' . "{$result}", 'level' => 'ALERT'));
return false;
}
return true;
}
作者:jackycg
项目:GreenCM
/**
* 显示404页
* @function 404 ERROR 需要显示错误的信息
*
* @param string $message
*/
public function error404($message = "非常抱歉,你需要的页面暂时不存在,可能它已经躲起来了。.")
{
$this->assign("message", $message);
if (File::file_exists(T('Home@Index/404'))) {
$this->display('Index/404');
} else {
$this->show($message);
}
Hook::listen('app_end');
die;
}
作者:Anymagi
项目:Car-Sticke
public function BlackNew($RecordId, $UserId)
{
$data = array('recordid' => $RecordId, 'userid' => $UserId, 'lasttime' => time());
$result = self::add($data);
if ($result !== false) {
return true;
} else {
return false;
\Think\Hook::listen('HomeLog', $parm = array('function' => 'BlackNew -> $result', 'logmsg' => 'result is false', 'level' => 'ALERT'));
}
}
作者:Lofanm
项目:thin
public function testExec()
{
$data['id'] = 0;
$data['name'] = 'thinkphp';
$this->assertEquals(true, Hook::exec('\\tests\\thinkphp\\library\\think\\behavior\\One'));
$this->assertEquals(false, Hook::exec('\\tests\\thinkphp\\library\\think\\behavior\\One', 'test', $data));
$this->assertEquals('test', $data['name']);
$this->assertEquals('Closure', Hook::exec(function (&$data) {
$data['name'] = 'Closure';
return 'Closure';
}));
}
作者:bushiji
项目:500efum
/**
* @todo: 发送评论
* @author Saki <ilulu4ever816@gmail.com>
* @date 2014-12-22 上午9:34:18
* @version V1.0
*/
public function PostComment()
{
$model = new \Admin\Model\ArticleCommentModel();
$post = $_POST['ArticleComment'];
$id = $post['aid'];
$comment_id = $model->createComment($post);
//发送邮件,这里为游客发送评论,则为管理员邮箱收到邮件
if ($comment_id) {
\Think\Hook::listen('postComment', $comment_id);
\Think\Hook::add('postComment', 'Home\\Behaviors\\emailBehavior');
}
$this->redirect('Article/view', array('id' => $id, 'p' => 1));
}
作者:bushiji
项目:500efum
/**
* @todo: 发送评论-后台管理员发送
* @author Saki <ilulu4ever816@gmail.com>
* @date 2014-12-22 上午9:34:18
* @version V1.0
*/
public function PostComment()
{
$model = new \Admin\Model\ArticleCommentModel();
$post = $_POST['ArticleComment'];
$id = $post['aid'];
$admin_info = $this->admin_info;
$post['is_admin'] = $admin_info['id'];
$comment_id = $model->createComment($post);
if ($comment_id) {
\Think\Hook::listen('postComment', $comment_id);
\Think\Hook::add('postComment', 'Home\\Behaviors\\emailBehavior');
}
$this->redirect('ArticleList/view', array('id' => $id, 'p' => 1));
}
作者:homyi
项目:HyFram
public function ajax_add(&$json)
{
$offset = I('offset');
$data['content'] = I('content');
Hook::listen('hy_filter', $data['content']);
$data['user_id'] = ss_uid();
$data['create_time'] = time();
$data['anonymous'] = 0;
if (false === $this->add($data)) {
return $json['info'] = $this->getError();
}
$json['status'] = true;
$json['data'] = $this->lists($offset);
}
作者:snowai
项目:think-hookagen
public function app_init()
{
$bags = self::$tags;
foreach ($bags as $hook => $classes) {
foreach ($classes as $class) {
$tags = Hook::get($hook);
if (class_exists($class)) {
if (!array_search($class, $tags)) {
Hook::add($hook, $class);
}
}
}
}
}