Addons::requireHooks PHP Метод

requireHooks() публичный статический Метод

是否能请求钩子操作
public static requireHooks ( string $hookname, object $addon = null ) : boolean
$hookname string 钩子名称
$addon object 钩子对象
Результат boolean 是否能请求钩子操作
    public static function requireHooks($hookname, $addon = null)
    {
        if (empty($addon)) {
            return isset(self::$validHooks[$hookname]);
        }
    }

Usage Example

Пример #1
0
 /**
  * 添加分享
  * @param integer $uid 操作用户ID
  * @param string $app 分享应用类型,默认为public
  * @param string $type 分享类型,
  * @param array $data 分享相关数据
  * @param integer $app_id 应用资源ID,默认为0
  * @param string $app_table 应用资源表名,默认为feed
  * @param array  $extUid 额外用户ID,默认为null
  * @param array $lessUids 去除的用户ID,默认为null
  * @param boolean $isAtMe 是否为进行发送,默认为true
  * @return mix 添加失败返回false,成功返回新的分享ID
  */
 public function put($uid, $app = 'group', $type = '', $data = array(), $app_id = 0, $app_table = 'group_feed', $extUid = null, $lessUids = null, $isAtMe = true, $is_repost = 0)
 {
     // 判断数据的正确性
     if (!$uid || $type == '') {
         return false;
     }
     if (strpos($type, 'postvideo') !== false) {
         $type = 'postvideo';
     }
     //分享类型合法性验证 - 临时解决方案
     if (!in_array($type, array('post', 'repost', 'postvideo', 'postfile', 'postimage'))) {
         $type = 'post';
     }
     // //应用类型验证 用于分享框 - 临时解决方案
     // if ( !in_array( $app , array('public','weiba','tipoff') ) ){
     //     $app = 'public';
     //     $type = 'post';
     //     $app_table = 'feed';
     // }
     $app_table = strtolower($app_table);
     // 添加feed表记录
     $data['gid'] = $data['gid'];
     $data['uid'] = $uid;
     $data['app'] = $app;
     $data['type'] = $type;
     $data['app_row_id'] = $app_id;
     $data['app_row_table'] = $app_table;
     $data['publish_time'] = time();
     $data['from'] = isset($data['from']) ? intval($data['from']) : getVisitorClient();
     $data['is_del'] = $data['comment_count'] = $data['repost_count'] = 0;
     $data['is_repost'] = $is_repost;
     //判断是否先审后发
     //         $weiboSet = model('Xdata')->get('admin_Config:feed');
     //         $weibo_premission = $weiboSet['weibo_premission'];
     //         if(in_array('audit',$weibo_premission) || CheckPermission('core_normal','feed_audit')){
     //             $data['is_audit'] = 0;
     //         }else{
     $data['is_audit'] = 1;
     //         }
     // 分享内容处理
     if (Addons::requireHooks('weibo_publish_content')) {
         Addons::hook("weibo_publish_content", array(&$data));
     } else {
         // 拼装数据,如果是评论再转发、回复评论等情况,需要额外叠加对话数据
         $data['body'] = str_replace(SITE_URL, '[SITE_URL]', preg_html($data['body']));
         // 获取用户发送的内容,仅仅以//进行分割
         $scream = explode('//', $data['body']);
         // 截取内容信息为分享内容字数 - 重点
         $feedConf = model('Xdata')->get('admin_Config:feed');
         $feedNums = $feedConf['weibo_nums'];
         $body = array();
         foreach ($scream as $value) {
             $tbody[] = $value;
             $bodyStr = implode('//', $tbody);
             if (get_str_length($bodyStr) > $feedNums) {
                 break;
             }
             $body[] = $value;
             unset($bodyStr);
         }
         $data['body'] = implode('//', $body);
         // 获取用户发布内容
         $data['content'] = trim($scream[0]);
     }
     //分享到分享的应用资源,加入原资源链接
     $data['body'] .= $data['source_url'];
     $data['content'] .= $data['source_url'];
     // 分享类型插件钩子
     // if($type){
     //  $addonsData = array();
     //  Addons::hook("weibo_type",array("typeId"=>$type,"typeData"=>$type_data,"result"=>&$addonsData));
     //  $data = array_merge($data,$addonsData);
     // }
     if ($type == 'postvideo') {
         $typedata = model('Video')->_weiboTypePublish($_POST['videourl']);
         if ($typedata && $typedata['flashvar'] && $typedata['flashimg']) {
             $data = array_merge($data, $typedata);
         } else {
             $data['type'] = 'post';
         }
     }
     // 添加分享信息
     $feed_id = $this->data($data)->add();
     if (!$feed_id) {
         return false;
     }
     //         if(!$data['is_audit']){
     //             $touid = D('user_group_link')->where('user_group_id=1')->field('uid')->findAll();
     //             foreach($touid as $k=>$v){
     //                 model('Notify')->sendNotify($v['uid'], 'feed_audit');
     //             }
     //         }
     // 添加关联数据
     $feed_data = D('group_feed_data')->data(array('feed_id' => $feed_id, 'feed_data' => serialize($data), 'client_ip' => get_client_ip(), 'feed_content' => $data['body']))->add();
     // 添加分享成功后
     if ($feed_id && $feed_data) {
         //分享发布成功后的钩子
         //             Addons::hook("weibo_publish_after",array('weibo_id'=>$feed_id,'post'=>$data));
         // 发送通知消息 - 重点 - 需要简化把上节点的信息去掉.
         if ($data['is_repost'] == 1) {
             // 转发分享
             $isAtMe && ($content = $data['content']);
             // 内容用户
             $extUid[] = $data['sourceInfo']['transpond_data']['uid'];
             // 资源作者用户
             if ($isAtMe && !empty($data['curid'])) {
                 // 上节点用户
                 $appRowData = $this->get($data['curid']);
                 $extUid[] = $appRowData['uid'];
             }
         } else {
             // 其他分享
             $content = $data['content'];
         }
         // 发送@消息
         D('GroupAtme')->setAppName('group')->setAppTable('group_feed')->addAtme($content, $feed_id, $extUid, $lessUids, $data['gid']);
         $data['client_ip'] = get_client_ip();
         $data['feed_id'] = $feed_id;
         $data['feed_data'] = serialize($data);
         // 主动创建渲染后的缓存
         $return = $this->setFeedCache($data);
         $return['user_info'] = model('User')->getUserInfo($uid);
         $return['GroupData'] = model('UserGroupLink')->getUserGroupData($uid);
         //获取用户组信息
         $return['feed_id'] = $feed_id;
         $return['app_row_id'] = $data['app_row_id'];
         $return['is_audit'] = $data['is_audit'];
         // 统计数修改
         //             model('UserData')->setUid($uid)->updateKey('feed_count', 1);
         // if($app =='public'){ //TODO 分享验证条件
         //                 model('UserData')->setUid($uid)->updateKey('weibo_count', 1);
         // }
         if (!$return) {
             $this->error = L('PUBLIC_CACHE_FAIL');
             // Feed缓存写入失败
         }
         return $return;
     } else {
         $this->error = L('PUBLIC_ADMIN_OPRETING_ERROR');
         // 操作失败
         return false;
     }
 }
All Usage Examples Of Addons::requireHooks