Ejemplo n.º 1
0
 public function __construct()
 {
     socialFeed::get_favicon_from('http://www.delicious.com/sydlawrence');
     $this->session = Session::instance();
     $this->db = new Database();
     parent::__construct();
     $_POST = $this->input->xss_clean($_POST);
     if ($this->input->post('attempt_login')) {
         $return = login::attempt_login();
         if (isset($return->id) && $return->id > 0) {
             $this->user = $return;
         } else {
             $this->__set_options(array('error' => $return));
         }
         if (isset($_GET['redirect'])) {
             url::redirect(urldecode($_GET['redirect']));
         }
     }
     $this->user = login::check_login();
     if ($this->input->get('logout')) {
         Auth::instance()->logout(TRUE);
         url::redirect();
     }
     $this->page = Page_Model::get_by_url();
     $this->feed = Feed_Model::get_by_url();
     $this->feedpost = Feedpost_Model::get_by_url();
     $this->__setup();
     $this->header = new View('includes/header');
     $this->footer = new View('includes/footer');
     $this->__binds();
 }
Ejemplo n.º 2
0
 /**
  * 单例
  * @return Friend_Model
  */
 public static function &instance()
 {
     if (!is_object(Feed_Model::$instances)) {
         // Create a new instance
         Feed_Model::$instances = new Feed_Model();
     }
     return Feed_Model::$instances;
 }
Ejemplo n.º 3
0
 /**
  * Tests Feed_Model::is_valid_feed
  * @test
  */
 public function testIsValidFeed()
 {
     if (ORM::factory('feed')->count_all() == 0) {
         $this->markTestSkipped('There are no records in the feeds table');
     }
     // Test with a valid feed id
     $random_feed_id = testutils::get_random_id('feed');
     $this->assertEquals(TRUE, Feed_Model::is_valid_feed($random_feed_id));
     // Test with an invalid feed id
     $this->assertEquals(FALSE, Feed_Model::is_valid_feed('90.9999'));
 }
Ejemplo n.º 4
0
 /**
  * 添加赞
  */
 public function create()
 {
     $post = $this->get_data();
     $statuses_id = $post['statuses_id'];
     if (empty($statuses_id)) {
         $this->send_response(400, NULL, '对象id为空');
     }
     $feed = new Feed_Model();
     $doc = $feed->findFeed($statuses_id);
     if (!$doc) {
         $this->send_response(404, NULL, '该动态不存在');
     }
     $owner = $doc['owner_uid'];
     $had_praise = 0;
     foreach ($doc['like_list'] as $key => $var) {
         $uid = $var['uid'] ? $var['uid'] : $var['id'];
         if ((int) $uid == (int) $this->uid) {
             $had_praise = 1;
             break;
         }
     }
     $group_member = array();
     if ($doc['group_type'] > 0) {
         $grade = Group_Model::instance()->getMemberGrade($doc['group_id'], $this->uid);
         if ($grade < 1) {
             $this->send_response(400, NULL, '400:你不是该群成员,无权限赞');
         }
         $group_member = Group_Model::instance()->getGroupAllMember($doc['group_id']);
     }
     $is_bubble = $owner == Kohana::config('uap.xiaomo') ? false : true;
     if ($doc['last_updated'] && $had_praise == 0) {
         if (count($group_member) > 0) {
             foreach ($group_member as $member) {
                 if ($member['uid'] != $this->uid) {
                     if (!$feed->addAboutme($member['uid'], $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) {
                         $this->send_response(400, NULL, $feed->get_error_msg());
                     }
                 }
             }
         } elseif ($owner != $this->uid) {
             if (!$feed->addAboutme($owner, $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) {
                 $this->send_response(400, NULL, $feed->get_error_msg());
             }
         }
         $feed->addLike($this->uid, sns::getrealname($this->uid), $statuses_id, $is_bubble);
         if ($doc['group_type'] == 1 && $doc['group_id']) {
             Tab_Model::instance()->lastModify($this->uid, 1, $doc['group_id']);
         }
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '赞失败,你已经赞过');
 }
Ejemplo n.º 5
0
 /**
  * Returns a feedpost from the current url
  *
  * $param	bool	$unpublished	Return unpublished posts too?
  * @return	object|bool	$post		The feedpost generated by the url, or null if no feedpost found
  */
 public static function get_by_url($unpublished = false)
 {
     $uri = uri::instance();
     $feed = Feed_Model::get_by_url();
     if ($feed && $feed->id > 0) {
         $post_id = $uri->segment(2);
         $post = ORM::factory('feedpost', $post_id);
         if (!$unpublished) {
             if ($post->status_id == 2) {
                 return $post;
             }
         } else {
             return $post;
         }
     }
     return null;
 }
Ejemplo n.º 6
0
 /**
  * 
  * 搜索
  * @param string $query
  * @param int $start
  * @param int $group_id
  * @param int $pagesize
  */
 private function search($query, $start, $group_id, $pagesize)
 {
     $options = array('offset' => $start, 'limit' => $pagesize);
     if ($group_id) {
         $options['group_id'] = $group_id;
     }
     $ids = $this->sphinx_query($query, $options);
     $cursor = $this->mongo_query($ids);
     if (is_null($cursor)) {
         return 0;
     }
     $result = array();
     $i = 0;
     while ($cursor->hasNext()) {
         $doc = $cursor->getNext();
         $result[] = Feed_Model::instance()->new_feedview($doc, 1, $this->source);
         $i++;
     }
     return $this->send_response(200, array('data' => $result));
 }
Ejemplo n.º 7
0
 /**
  * 创建活动
  */
 public function create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400505:活动信息非法');
     }
     $post = new Validation($data);
     $post->add_rules('title', 'required', 'length[1, 30]');
     $post->add_rules('start_at', 'required', 'numeric');
     $post->add_rules('end_at', 'required', 'numeric');
     $post->add_rules('spot', 'required', 'length[1, 30]');
     $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation'));
     $post->add_rules('is_allow_invite', 'required', 'numeric', array($this, '_check_allow_invite_validation'));
     $post->add_rules('content', 'length[0, 300]');
     $post->add_rules('group_ids', array($this, '_check_group_ids_validation'));
     $post->add_callbacks(TRUE, array($this, '_check_time_validation'));
     if ($post->validate()) {
         $activity = array();
         $form = $post->as_array();
         $activity['creator_id'] = $this->user_id;
         $activity['title'] = $form['title'];
         $activity['start_time'] = $form['start_at'];
         $activity['end_time'] = $form['end_at'];
         $nowTime = time();
         $activity['create_time'] = $nowTime;
         $activity['spot'] = $form['spot'];
         $activity['type'] = $form['type'];
         $activity['is_allow_invite'] = $form['is_allow_invite'];
         if (isset($form['content'])) {
             $activity['content'] = $form['content'];
         }
         $groupIds = array();
         if (isset($form['group_ids'])) {
             $groupIds = $form['group_ids'];
         }
         $groupModel = new Group_Model();
         $gidArray = array();
         foreach ($groupIds as $id) {
             $id = floatval($id);
             if ($id != -1) {
                 $groupInfo = $groupModel->getGroupInfo($id);
                 if (!$groupInfo) {
                     $this->send_response(400, NULL, '400506:活动发布到的群不存在');
                 }
                 $grade = $groupModel->getMemberGrade($id, $this->user_id);
                 if ($grade < 1) {
                     $this->send_response(400, NULL, '400507:您不是活动指定发布到群的成员');
                 }
             }
             $gidArray[] = $id;
         }
         if (!$gidArray) {
             $activity['is_publish'] = 0;
         } else {
             $activity['is_publish'] = 1;
         }
         $activity_id = $this->model->add($activity);
         $activityMember = array('aid' => $activity_id, 'uid' => $this->user_id, 'apply_type' => Kohana::config('activity.apply_type.join'), 'apply_time' => $nowTime, 'grade' => Kohana::config('activity.grade.creator'));
         $result = $this->model->applyActivity($activityMember);
         $this->model->addActivityUser($activity_id, $this->user_id);
         $friendModel = new Friend_Model();
         $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
         //活动动态发送到指定momo成员
         foreach ($gidArray as $gid) {
             $this->model->addActivityGroup($activity_id, $gid);
             if ($gid == -1) {
                 $friendModel = new Friend_Model();
                 $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
                 foreach ($fidList as $fid) {
                     $this->model->addActivityUser($activity_id, $fid);
                 }
             } else {
                 $this->model->addActivityGroup($activity_id, $gid);
                 $members = $groupModel->getGroupAllMember($gid);
                 foreach ($members as $value) {
                     $this->model->addActivityUser($activity_id, $value['uid']);
                 }
             }
         }
         $feedModel = new Feed_Model();
         $title = array('uid' => $this->user_id, 'name' => sns::getrealname($this->user_id), 'id' => $activity_id, 'title' => $activity['title']);
         $messageModel = new Message_Model();
         if ($activity['is_publish']) {
             $feedModel->addFeed($this->user_id, 'action_add', Kohana::config('uap.app.action'), $title, array(), $activity_id);
         }
         $this->send_response(200, array('id' => floatval($activity_id)));
     }
     $errors = $post->errors();
     $this->send_response(400, NULL, '400505:活动信息非法');
 }
Ejemplo n.º 8
0
 /**
  * 删除群
  * @param int $id 群组ID
  */
 public function destroy($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } elseif (empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupInfo = $this->model->getGroupInfo($id);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $this->model->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('group.grade.master')) {
         $this->send_response(400, NULL, '400413:非群主,无权限删除群');
     }
     $memberList = $this->model->getGroupAllMember($id);
     $result = $this->model->delete($id);
     if ($result) {
         $feedModel = Feed_Model::instance();
         $userModel = User_Model::instance();
         $content = '您加入的群"' . $groupInfo['gname'] . '"已解散';
         foreach ($memberList as $value) {
             $feedModel->deleteItem($id, 32, $value['uid']);
             $userModel->present_mo_notice(Kohana::config('uap.xiaomo'), $value['uid'], $content);
         }
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '删除群失败');
 }
Ejemplo n.º 9
0
 public function newmsg_onget()
 {
     $res = $this->model->getNewNoticeNum($this->user_id);
     //获取新通知条数
     if ($res) {
         $noticeNum = (int) $res;
     } else {
         $noticeNum = 0;
     }
     $feed = new Feed_Model();
     $aboutmeNum = $feed->aboutmeCount(1);
     //$imUser = $feed->findImNew();
     $this->setResponseCode(200);
     return array('noticeNum' => $noticeNum, 'aboutmeNum' => $aboutmeNum);
 }
Ejemplo n.º 10
0
 /**
 		Function for the administrator to add feeds.
 */
 public function add($feedtype = 'rss2')
 {
     //$this->template->header->this_page = 'feed_add';
     $this->template->content = new View('feed_add');
     // setup and initialize form field names
     $form = array('feed_name' => '', 'feed_url' => '', 'feed_active' => 1, 'feed_category' => 0);
     //copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('feed_name', 'required', 'length[3,200]');
         $post->add_rules('feed_url', 'required');
         //$post->add_rules('feed_active', 'required');
         $post->add_rules('feed_category', 'required');
         //	echo " post->feed_active ".(isset($post->feed_active))?"True","FALSE" ;
         //	exit(0);
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // STEP 2: SAVE INCIDENT
             $feed = new Feed_Model();
             $feed->feed_name = $post->feed_name;
             $feed->feed_url = $post->feed_url;
             $feed->feed_active = isset($post->feed_active) ? 1 : 0;
             $feed->category_id = $post->feed_category;
             if (ORM::factory('feed')->where('feed_url', $post->feed_url)->count_all() == 0) {
                 $feed->save();
             } else {
                 $errors['feed_url'] = 'This url is already in the database';
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('report'));
                 $form_error = TRUE;
             }
             // Notify Admin Of New Report
             $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_report.subject'), Kohana::lang('notifications.admin_new_report.message') . "\n\n'" . strtoupper($feed->feed_name) . "'" . "\n" . $feed->feed_url);
             //	url::redirect('reports/thanks');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->categories = $this->_get_categories($form['feed_category']);
     $this->template->header->render(TRUE);
     $this->template->content->render(TRUE);
     $this->template->Render();
 }
Ejemplo n.º 11
0
 /**
  * 
  * 更新头像接口
  * POST update_avatar.json
  * {
  * 	"pid":"原始照片的id",
  * 	"middle_content":"大头像base64数据"
  *  "original_content":"原图base64数据"
  * }
  */
 public function update_avatar()
 {
     if ($_POST['data']) {
         //flash截取头像
         $data = json_decode($_POST['data'], TRUE);
     } else {
         $data = $this->get_data();
         //手机端
     }
     //如果是j2me平台直接取原图
     if ($this->get_source() == 6) {
         $middle_data = @base64_decode($data['original_content']);
     } else {
         $middle_data = @base64_decode($data['middle_content']);
     }
     $pid = $data['pid'];
     //原图PID
     $original_data = @base64_decode($data['original_content']);
     //原图数据
     if ($pid) {
         $photoModel = new Models\Photo();
         if (!$photoModel->findOne($pid)) {
             $this->response(ResponseType::PHOTO_UPAVATAR_ERROR_INVALID);
         }
     }
     if (!$pid && $original_data) {
         $tmporigin = Core::tempname();
         file_put_contents($tmporigin, $original_data);
         $uploader = new Uploader();
         $uploader->process($tmporigin);
         //不是图片类型
         if ($uploader->getType() !== Uploader::FILETYPE_IMAGE) {
             $this->response(ResponseType::PHOTO_ERROR_IMAGETYPE);
         }
         if ($result = $this->_processUpload($uploader, 1)) {
             $pid = $result['id'];
         } else {
             $this->response(ResponseType::PHOTO_UPAVATAR_ERROR_INVALID);
         }
     }
     if (!$pid || !$middle_data) {
         $this->response(ResponseType::ERROR_LACKPARAMS);
     }
     $tmpfile = Core::tempname();
     if (!file_put_contents($tmpfile, $middle_data)) {
         $this->response(ResponseType::PHOTO_UPAVATAR_ERROR);
     }
     $uploader = new Uploader();
     $uploader->process($tmpfile);
     //不是图片类型
     if ($uploader->getType() !== Uploader::FILETYPE_IMAGE) {
         $this->response(ResponseType::PHOTO_ERROR_IMAGETYPE);
     }
     $photoModel = new Models\Photo();
     $updata['cid'] = 1;
     //我的头像相册
     $updata['oid'] = $pid;
     $updata['ctrl_type'] = 1;
     $updata['is_animated'] = 0;
     $updata['mtime'] = time();
     if ($photoModel->create($uploader, $updata)) {
         $result['id'] = $photoModel->get_pid();
         $result['md5'] = $photoModel->md5;
         $imgurls = $photoModel->geturi($result['id'], 48);
         $result['src'] = $imgurls[0];
         list($set_avatar, $first_time) = $photoModel->setAvatar($photoModel->get_pid(), $updata['oid'], $updata['mtime']);
         if (!$set_avatar) {
             $this->response(ResponseType::PHOTO_UPAVATAR_ERROR);
         }
         $user_model = User_Model::instance();
         $member_field = array('updatetime' => time());
         if ($first_time) {
             $sms_content = '您好,这是您第一次设置头像,系统赠送了100条短信给您';
             $user_model->present_sms($this->getUid(), 100, $sms_content, FALSE);
             $user_info = $user_model->get_user_info($this->getUid());
             $member_field['completed'] = $user_info['completed'] + 10;
         }
         //发送头像修改动态
         $feedModel = new Feed_Model();
         $accessory[] = array('id' => $result['id']);
         $feedModel->addFeed($this->user_id, 3, '更新头像', $this->get_source(), array(), array(), $accessory);
         //更新memberinfo表
         $user_model->update_user_info($this->getUid(), $member_field);
         $this->response(ResponseType::PHOTO_UPAVATAR_OK, '', $result);
         unlink($tmpfile);
     } else {
         $this->response(ResponseType::PHOTO_UPAVATAR_ERROR);
     }
 }
Ejemplo n.º 12
0
    /**
     * 获取评论js
     * @param string $title 评论的题头,目前有留言和评论两个,默认为评论
     * @param integer $vuid 登录者id
     * @param integer $uid 被访问者id
     * @param integer $appid 评论的唯一标识,即文章id,图片id等
     * @param string $appdescribe 评论类型描述,目前有blog,vote,album,photo,record,index等。
     * @param string feed 模板名称,目前有vote_add,diary_add等。
     */
    public function getCommentJs($title = '评论', $vuid, $uid, $appid, $appdescribe)
    {
        $allow = $this->retrunAllow($vuid, $uid);
        $showInput = 'false';
        //是否显示输入
        $showInputMsg = '用户关闭评论';
        $feedModel = new Feed_Model();
        if ($allow == 1) {
            $showInput = 'true';
            $showInputMsg = '';
        } elseif ($allow == 2) {
            $showInput = 'false';
            $showInputMsg = '仅好友可以评论';
        }
        $praise = new Praise_Model();
        $str .= '
		    	<script src="' . url::js_url() . 'lib/ui.pagination/jquery.pagination.js" type="text/javascript"></script>
				<div>
					<span class="span-comment-opt"></span>
				</div>
				<div class="tip-1 feed">
					<textarea class="hiddenJSON hide">
					{
						"uid": ' . $uid . '
						,"commentCount":"0"             
						,"success":true
						,"msg":""
						,"typeid":"' . $feedModel->getFeedTplId($appdescribe) . '"
						,"objid":' . $appid . '
						,"pid":0
						,"commentEnabled":' . $showInput . '
						,"likeCount":' . $praise->getPraiseCount($appdescribe, $appid) . '
						,"likeList":' . json_encode($praise->getPraiseUser($appdescribe, $appid, null, null, $uid)) . '
					}
					</textarea>
				</div>

				<script type="text/javascript">
		        $(document).ready(function() {
                    $("#div_comment .hiddenJSON").initComment({
                            title: "' . $title . '",
                            pageSize: 12, 
                            showPrivateChk: true,   //显示悄悄话的checkbox
                            showHeader: true,       //显示头部
                            uid: ' . $uid . ',                //被访问者
                            vuid: ' . $vuid . ',               //当前登录者
                            showInput:' . $showInput . ',
                            showInputMsg:"' . $showInputMsg . '",
                            typeid: "' . $feedModel->getFeedTplId($appdescribe) . '",    //diary,index,vote等
                            objid: ' . $appid . ',               //当前应用id 如日志id,投票id,首页留言appid=uid
                            inputPosition: "top",
                            inputExpand: true,
                            showPager: true
                    });
		        });
		    </script>';
        return $str;
    }
Ejemplo n.º 13
0
 public function find($str = '')
 {
     $result = $this->feedModel->text_search($str);
     $result = iterator_to_array($result);
     $this->send_response(200, $result);
 }
Ejemplo n.º 14
0
 private function _save_feed($feed_id, $feed_url, $feed_category, $feed_name = "none", $weight)
 {
     $feedname = $feed_name == "none" ? $feed_url : $feed_name;
     if (isset($feed_url) && !empty($feed_url) && $feed_url != '' && $feed_category > 0) {
         $feed = new Feed_Model();
         //if unique url then create new else update old.
         $numItems = ORM::factory('feed')->where('feed_url', $feed_url)->count_all();
         if ($numItems == 0 && $feed_id == 0) {
             $feed->feed_name = $feedname;
             $feed->feed_url = $feed_url;
             $feed->weight = $weight;
             $feed->category_id = $feed_category;
             $feed->save();
         } else {
             if ($feed_id != 0) {
                 $db = new Database();
                 $sql = " UPDATE feed SET feed_url = '" . $feed_url . "' , feed_name = '" . $feedname . "' , weight= " . $weight . "\t";
                 $sql .= " WHERE id = " . $feed_id;
                 //				echo $sql."<br/>";
                 $Result = $db->query($sql);
             }
         }
         $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_report.subject'), Kohana::lang('notifications.admin_new_report.message') . "\n\n'" . strtoupper($feed->feed_name) . "'" . "\n" . $feed->feed_url);
     }
 }
Ejemplo n.º 15
0
 /**
  * Add Edit News Feeds
  */
 public function feeds()
 {
     $this->template->content = new View('admin/feeds');
     // setup and initialize form field names
     $form = array('action' => '', 'feed_id' => '', 'feed_name' => '', 'feed_url' => '', 'feed_active' => '');
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         // Feed_Model instance
         $feed = (isset($_POST['feed_id']) and Feed_Model::is_valid_feed($_POST['feed_id'])) ? new Feed_Model($_POST['feed_id']) : new Feed_Model();
         if ($_POST['action'] == 'a') {
             // Manually extract the data to be validated
             $data = arr::extract($_POST, 'feed_name', 'feed_url');
             // Test validation
             if ($feed->validate($data)) {
                 $feed->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
             } else {
                 // Repopulate the form fields
                 $form = arr::overwrite($form, $data->as_array());
                 // Populate the error fields, if any
                 $errors = arr::overwrite($errors, $data->errors('feeds'));
                 $form_error = TRUE;
             }
         } elseif ($_POST['action'] == 'd') {
             // Delete Action
             if ($feed->loaded == TRUE) {
                 ORM::factory('feed_item')->where('feed_id', $feed->id)->delete_all();
                 $feed->delete();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             }
         } elseif ($_POST['action'] == 'v') {
             // Active/Inactive Action
             if ($feed->loaded == TRUE) {
                 $feed->feed_active = $feed->feed_active == 1 ? 0 : 1;
                 $feed->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             }
         } elseif ($_POST['action'] == 'r') {
             $this->_parse_feed();
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('feed')->count_all()));
     $feeds = ORM::factory('feed')->orderby('feed_name', 'asc')->find_all($this->items_per_page, $pagination->sql_offset);
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->feeds = $feeds;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
     $this->template->js = new View('admin/feeds_js');
 }
Ejemplo n.º 16
0
 function feeds()
 {
     $this->template->content = new View('admin/feeds');
     // setup and initialize form field names
     $form = array('action' => '', 'feed_id' => '', 'feed_name' => '', 'feed_url' => '', 'feed_active' => '');
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         //print_r($_POST);
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->action == 'a') {
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('feed_name', 'required', 'length[3,70]');
             $post->add_rules('feed_url', 'required', 'url');
         }
         if ($post->validate()) {
             $feed_id = $post->feed_id;
             $feed = new Feed_Model($feed_id);
             if ($post->action == 'd') {
                 // Delete Action
                 if ($feed->loaded == true) {
                     ORM::factory('feed_item')->where('feed_id', $feed_id)->delete_all();
                 }
                 $feed->delete($feed_id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } else {
                 if ($post->action == 'v') {
                     // Active/Inactive Action
                     if ($feed->loaded == true) {
                         if ($feed->feed_active == 1) {
                             $feed->feed_active = 0;
                         } else {
                             $feed->feed_active = 1;
                         }
                         $feed->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                     }
                 } else {
                     if ($post->action == 'r') {
                         $this->_parse_feed();
                     } else {
                         // Save Action
                         // SAVE Feed
                         $feed->feed_name = $post->feed_name;
                         $feed->feed_url = $post->feed_url;
                         $feed->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('feeds'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('feed')->count_all()));
     $feeds = ORM::factory('feed')->orderby('feed_name', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->feeds = $feeds;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
     $this->template->js = new View('admin/feeds_js');
 }
Ejemplo n.º 17
0
 private function _add_feed_comment($activity, $old_apply_type, $apply_type, $uid)
 {
     $feedModel = new Feed_Model();
     if ($apply_type == Kohana::config('activity.apply_type.join')) {
         $feedStatus = "参加";
         $applyStatus = "参加";
     } else {
         if ($apply_type == Kohana::config('activity.apply_type.interest')) {
             $feedStatus = "关注";
             $applyStatus = "感兴趣";
         }
     }
     if ($activity['gid'] != 0) {
         if ($apply_type != Kohana::config('activity.apply_type.not_join')) {
             $commentModel = new Comment_Model();
             $content = "参与报名:" . $applyStatus;
             if ($activity['feed_id']) {
                 $feed_id = $activity['feed_id'];
                 $feedInfo = $feedModel->getFeedById($feed_id);
                 if ($feedInfo) {
                     $group_type = $feedInfo[$feed_id]['group_type'];
                     $group_id = $feedInfo[$feed_id]['group_id'];
                     $owner_uid = $feedInfo[$feed_id]['owner_uid'];
                     if (!$group_type) {
                         //好友
                         $friendModel = Friend_Model::instance();
                         $isFriend = $friendModel->check_isfriend($owner_uid, $uid);
                         if ($isFriend) {
                             $commentModel->saveComment($feed_id, $content, $owner_uid);
                         }
                     } else {
                         if ($group_type == 1) {
                             //群内
                             $groupModel = Group_Model::instance();
                             $grade = $groupModel->getMemberGrade($group_id, $uid);
                             if ($grade > 0) {
                                 $commentModel->saveComment($feed_id, $content, $owner_uid);
                             }
                         } else {
                             if ($group_type == 2) {
                                 //活动内
                                 $activityModel = Activity_Model::instance();
                                 $apply_type = $activityModel->getActivityApplyType($group_id, $uid);
                                 if ($apply_type > 0) {
                                     $commentModel->saveComment($feed_id, $content, $owner_uid);
                                 }
                             }
                         }
                     }
                 }
             }
             if ($activity['action_feed_id']) {
                 $commentModel->saveComment($activity['action_feed_id'], $content, $activity['creator_id']);
             }
         }
     }
     if (!$old_apply_type && ($apply_type == Kohana::config('activity.apply_type.join') || $apply_type == Kohana::config('activity.apply_type.interest')) && $activity['is_allow_invite']) {
         $application = array('id' => floatval($activity['aid']), 'title' => '查看活动', 'url' => 'action/showblogbox/' . $activity['aid']);
         $feedModel->addFeed($uid, 7, $text = $feedStatus . '了活动:' . $activity['title'], $this->get_source(), $application, $at = array(), $images = array(), $sync = array(), $group_type = 0, $group_id = 0, $retweet_id = 0, $allow_rt = 0, $allow_comment = 1, $allow_praise = 1, $allow_del = 1, $allow_hide = 1);
     }
 }