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


PHP hook函数代码示例

本文整理汇总了PHP中hook函数的典型用法代码示例。如果您正苦于以下问题:PHP hook函数的具体用法?PHP hook怎么用?PHP hook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: activate_plugin

/**
 * Activate a named plugin.
 *
 * Parses the plugins directory to look for a pluginname.yaml
 * file and adds the plugin to the plugins database, setting
 * the inst_version field to the version specified in the yaml file.
 *
 * @param string $name Name of plugin to be activated.
 * @return bool Returns true if plugin directory was found.
 * @see deactivate_plugin
 */
function activate_plugin($name)
{
    $plugins_dir = dirname(__FILE__) . '/../plugins/';
    $plugin_dir = $plugins_dir . $name;
    if (file_exists($plugin_dir)) {
        $plugin_yaml = get_plugin_yaml("{$plugin_dir}/{$name}.yaml", false);
        # If no yaml, or yaml file but no description present, attempt to read an 'about.txt' file
        if ($plugin_yaml['desc'] == '') {
            $about = $plugins_dir . $name . '/about.txt';
            if (file_exists($about)) {
                $plugin_yaml['desc'] = substr(file_get_contents($about), 0, 95) . '...';
            }
        }
        # escape the plugin information
        $plugin_yaml_esc = array();
        foreach (array_keys($plugin_yaml) as $thekey) {
            $plugin_yaml_esc[$thekey] = escape_check($plugin_yaml[$thekey]);
        }
        # Add/Update plugin information.
        # Check if the plugin is already in the table.
        $c = sql_value("SELECT name as value FROM plugins WHERE name='{$name}'", '');
        if ($c == '') {
            sql_query("INSERT INTO plugins(name) VALUE ('{$name}')");
        }
        sql_query("UPDATE plugins SET config_url='{$plugin_yaml_esc['config_url']}', " . "descrip='{$plugin_yaml_esc['desc']}', author='{$plugin_yaml_esc['author']}', " . "inst_version='{$plugin_yaml_esc['version']}', " . "priority='{$plugin_yaml_esc['default_priority']}', " . "update_url='{$plugin_yaml_esc['update_url']}', info_url='{$plugin_yaml_esc['info_url']}' " . "WHERE name='{$plugin_yaml_esc['name']}'");
        hook("after_activate_plugin", "", array($name));
        return true;
    } else {
        return false;
    }
}
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:42,代码来源:plugin_functions.php

示例2: update

 /**
  * 新增或更新一个文档
  * @param array  $data 手动传入的数据
  * @return boolean fasle 失败 , int  成功 返回完整的数据
  * @author huajie <banhuajie@163.com>
  */
 public function update($data = null)
 {
     /* 获取数据对象 */
     $data = $this->token(false)->create($data);
     if (empty($data)) {
         return false;
     }
     /* 添加或新增基础内容 */
     if (empty($data['id'])) {
         //新增数据
         $id = $this->add($_POST);
         //添加基础内容
         if (!$id) {
             $this->error = '新增基础内容出错!';
             return false;
         }
     } else {
         //更新数据
         $status = $this->save();
         //更新基础内容
         if (false === $status) {
             $this->error = '更新基础内容出错!';
             return false;
         }
     }
     hook('documentSaveComplete', array('model_id' => $data['model_id']));
     //行为记录
     if ($id) {
         action_log('add_document', 'document', $id, UID);
     }
     //内容添加或更新完成
     return $data;
 }
开发者ID:LuckyHJH,项目名称:charlie_brown,代码行数:39,代码来源:RecordModel.class.php

示例3: displayHtmlContent

 public function displayHtmlContent($content)
 {
     $content = parse_popup($content);
     $content = parse_at_users($content);
     hook('parseContent', array('content' => &$content));
     return $content;
 }
开发者ID:sunjie20081001,项目名称:sns,代码行数:7,代码来源:ContentHandlerModel.class.php

示例4: init

 /**
  * Init
  */
 public function init()
 {
     parent::init();
     if (access('Dev.*') && cogear()->config->development) {
         hook('done', array($this, 'finish'));
     }
 }
开发者ID:brussens,项目名称:cogear2,代码行数:10,代码来源:Gear.php

示例5: __construct

 /**
  * 构造方法,添加消息提醒的钩子
  */
 function __construct()
 {
     $this->message = new Message();
     $hook = hook();
     $hook->add('FollowManagement_follow', [$this, 'mail_follow_me']);
     $hook->add('FollowManagement_follow', [$this, 'message_follow_me']);
     $hook->add('FollowManagement_follow_gallery', [$this, 'mail_follow_gallery']);
     $hook->add('FollowManagement_follow_gallery', [$this, 'message_follow_gallery']);
     $hook->add('PictureComment_comment', [$this, 'mail_comment_picture']);
     $hook->add('PictureComment_comment', [$this, 'message_comment_picture']);
     $hook->add('GalleryComment_comment', [$this, 'mail_comment_gallery']);
     $hook->add('GalleryComment_comment', [$this, 'message_comment_gallery']);
     $hook->add('Comment_reply', [$this, 'mail_comment_reply']);
     $hook->add('Comment_reply', [$this, 'message_comment_reply']);
     $hook->add('Picture_like', [$this, 'mail_like_pic']);
     $hook->add('Picture_like', [$this, 'message_like_pic']);
     $hook->add('Gallery_like', [$this, 'mail_like_gallery']);
     $hook->add('Gallery_like', [$this, 'message_like_gallery']);
     $hook->add('CommentManagement_like', [$this, 'mail_like_comment']);
     $hook->add('CommentManagement_like', [$this, 'message_like_comment']);
     $hook->add('Message_send_success', [$this, 'mail_send_message']);
     $hook->add('Message_send_success', [$this, 'mail_send_system_message']);
     $hook->add('UserLogin_PostLogin_Success', [$this, 'mail_exception_login']);
     $hook->add('UserLogin_PostLogin_Success', [$this, 'message_exception_login']);
     $hook->add('UserLogin_PostLogin_restrictions', [$this, 'mail_login_restrictions']);
     $hook->add('UserLogin_PostLogin_restrictions', [$this, 'message_login_restrictions']);
 }
开发者ID:ttym7993,项目名称:Linger,代码行数:30,代码来源:NoticeApply.php

示例6: __construct

 /**
  * Constructor
  */
 public function __construct()
 {
     $this->clear();
     Template::bindGlobal('scripts', $this->scripts);
     Template::bindGlobal('styles', $this->styles);
     hook('head', array($this, 'output'));
 }
开发者ID:romartyn,项目名称:cogear,代码行数:10,代码来源:Harvester.php

示例7: send_research_request

 function send_research_request()
 {
     # Insert a search request into the requests table.
     # Resolve resource types
     $rt = "";
     $types = get_resource_types();
     for ($n = 0; $n < count($types); $n++) {
         if (getval("resource" . $types[$n]["ref"], "") != "") {
             if ($rt != "") {
                 $rt .= ", ";
             }
             $rt .= $types[$n]["ref"];
         }
     }
     global $userref;
     $as_user = getvalescaped("as_user", $userref, true);
     # If userref submitted, use that, else use this user
     # Insert the request
     sql_query("insert into research_request(created,user,name,description,deadline,contact,email,finaluse,resource_types,noresources,shape)\n\tvalues (now(),'{$as_user}','" . getvalescaped("name", "") . "','" . getvalescaped("description", "") . "'," . (getvalescaped("deadline", "") == "" ? "null" : "'" . getvalescaped("deadline", "") . "'") . ",'" . getvalescaped("contact", "") . "','" . getvalescaped("email", "") . "','" . getvalescaped("finaluse", "") . "','" . $rt . "'," . (getvalescaped("noresources", "") == "" ? "null" : "'" . getvalescaped("noresources", "") . "'") . ",'" . getvalescaped("shape", "") . "')");
     # E-mails a resource request (posted) to the team
     global $applicationname, $email_from, $baseurl, $email_notify, $username, $userfullname, $useremail, $lang;
     $templatevars['ref'] = sql_insert_id();
     $templatevars['teamresearchurl'] = $baseurl . "/pages/team/team_research.php";
     $templatevars['username'] = $username;
     $templatevars['userfullname'] = $userfullname;
     $templatevars['useremail'] = getvalescaped("email", $useremail);
     # Use provided e-mail (for anonymous access) or drop back to user email.
     $templatevars['url'] = $baseurl . "/pages/team/team_research_edit.php?ref=" . $templatevars['ref'];
     $message = "'{$username}' ({$userfullname} - {$useremail}) " . $lang["haspostedresearchrequest"] . ".\n\n";
     $message .= $templatevars['teamresearchurl'];
     hook("modifyresearchrequestemail");
     send_mail($email_notify, $applicationname . ": " . $lang["newresearchrequestwaiting"], $message, $useremail, "", "emailnewresearchrequestwaiting", $templatevars);
 }
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:33,代码来源:research_functions.php

示例8: upload

 /**
  * 文件上传
  * @param  array  $files   要上传的文件列表(通常是$_FILES数组)
  * @param  array  $setting 文件上传配置
  * @param  string $driver  上传驱动名称
  * @param  array  $config  上传驱动配置
  * @return array           文件上传成功后的信息
  */
 public function upload($files, $setting, $driver = 'Local', $config = null)
 {
     /* 上传文件 */
     $setting['callback'] = array($this, 'isFile');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     foreach ($files as $key => $file) {
         $ext = strtolower($file['ext']);
         if (in_array($ext, array('jpg', 'jpeg', 'bmp', 'png'))) {
             hook('dealPicture', $file['tmp_name']);
         }
     }
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 continue;
             }
             /* 记录文件信息 */
             if (strtolower($driver) == 'sae') {
                 $value['path'] = $config['rootPath'] . 'Picture/' . $value['savepath'] . $value['savename'];
                 //在模板里的url路径
             } else {
                 if (strtolower($driver) == 'qiniu') {
                     $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                 } elseif (strtolower($driver) != 'local') {
                     $value['path'] = $value['url'];
                 } else {
                     $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                     //在模板里的url路径
                 }
             }
             $value['type'] = strtolower($driver);
             if ($this->create($value) && ($id = $this->add())) {
                 $value['id'] = $id;
             } else {
                 //TODO: 文件上传成功,但是记录文件信息失败,需记录日志
                 unset($info[$key]);
             }
         }
         foreach ($info as &$t_info) {
             if ($t_info['type'] == 'local') {
                 $t_info['path'] = fixAttachUrl($t_info['path']);
             } else {
                 $t_info['path'] = $t_info['path'];
             }
         }
         /*  dump(getRootUrl());
             dump($info);
             exit;*/
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
开发者ID:chenyongze,项目名称:bighaha,代码行数:67,代码来源:PictureModel.class.php

示例9: save_themename

function save_themename()
{
    global $baseurl, $link, $themename, $collection_column;
    $sql = "update collection set\t" . $collection_column . "='" . getvalescaped("rename", "") . "' where " . $collection_column . "='" . escape_check($themename) . "'";
    sql_query($sql);
    hook("after_save_themename");
    redirect("pages/" . $link);
}
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:8,代码来源:theme_edit.php

示例10: catch_selected_project

function catch_selected_project()
{
    if (projectSelected() == true) {
        hook("site_begin", "projectDisplayers");
    } else {
        hook("site_begin", "dirtiness");
    }
}
开发者ID:Codechanic,项目名称:The-Secretary,代码行数:8,代码来源:view.php

示例11: init

 /**
  * Init
  */
 public function init()
 {
     parent::init();
     hook('form.page-createdit.init', array($this, 'extendPageForm'));
     hook('Pages.showPage.after', array($this, 'attachCommentsToPage'));
     hook('stack.Page.info', array($this, 'extendPageInfo'));
     allow_role(array('comments post'), 100);
 }
开发者ID:romartyn,项目名称:cogear,代码行数:11,代码来源:Gear.php

示例12: themeSettings

function themeSettings()
{
    global $manager;
    if (countHooks("design-settings") == 0) {
        hook("big_message", "noDesignSettings");
        return;
    }
}
开发者ID:Codechanic,项目名称:The-Secretary,代码行数:8,代码来源:design_settings.php

示例13: render

 /**
  * Отбражение региона
  *
  * @return string
  */
 public function render()
 {
     // Делаем всё через хуки, чтобы другие тоже могли выводить
     hook($this->options->name, array($this, 'output'));
     ob_start();
     event($this->options->name);
     return ob_get_clean();
 }
开发者ID:brussens,项目名称:cogear2,代码行数:13,代码来源:Region.php

示例14: __construct

 /**
  * Конструктор
  *
  * @param string $path
  * @param string $section
  */
 public function __construct($path = '', $section = '')
 {
     if ($path) {
         $this->file = $path;
         $this->load($path, $section);
         hook('exit', array($this, 'store'));
     }
 }
开发者ID:brussens,项目名称:cogear2,代码行数:14,代码来源:Config.php

示例15: setConfig

 private function setConfig()
 {
     $cfg = hook()->apply("Mail_setConfig", cfg()->get('mail'));
     foreach ($cfg as $name => $value) {
         if (isset($this->{$name})) {
             $this->{$name} = $value;
         }
     }
 }
开发者ID:dalinhuang,项目名称:StudentManage,代码行数:9,代码来源:mail.php


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