コード例 #1
0
 /**
  * Function used to add comment
  * This is more advance function , 
  * in this function functions can be applied on comments
  */
 function add_comment($comment, $obj_id, $reply_to = NULL, $type = 'v', $obj_owner = NULL, $obj_link = NULL, $force_name_email = false)
 {
     global $userquery, $eh, $db, $Cbucket;
     //Checking maximum comments characters allowed
     if (defined("MAX_COMMENT_CHR")) {
         if (strlen($comment) > MAX_COMMENT_CHR) {
             e(sprintf("'%d' characters allowed for comment", MAX_COMMENT_CHR));
         }
     }
     if (!verify_captcha()) {
         e(lang('usr_ccode_err'));
     }
     if (empty($comment)) {
         e(lang("pelase_enter_something_for_comment"));
     }
     $params = array('comment' => $comment, 'obj_id' => $obj_id, 'reply_to' => $reply_to, 'type' => $type);
     $this->validate_comment_functions($params);
     /* 		
      if($type=='video' || $type=='v')
      {
      if(!$this->video_exists($obj_id))
      e(lang("class_vdo_del_err"));
     
      //Checking owner of video
      if(!USER_COMMENT_OWN)
      {
      if(userid()==$this->get_vid_owner($obj_id));
      e(lang("usr_cmt_err2"));
      }
      }
     */
     if (!userid() && $Cbucket->configs['anonym_comments'] != 'yes') {
         e(lang("you_not_logged_in"));
     }
     if (!userid() && $Cbucket->configs['anonym_comments'] == 'yes' || $force_name_email) {
         //Checking for input name and email
         if (empty($_POST['name'])) {
             e(lang("please_enter_your_name"));
         }
         if (empty($_POST['email'])) {
             e(lang("please_enter_your_email"));
         }
         $name = mysql_clean($_POST['name']);
         $email = mysql_clean($_POST['email']);
     }
     if (empty($eh->error_list)) {
         $attributes = get_message_attributes($comment);
         if (is_array($attributes)) {
             $attributes = json_encode($attributes);
         }
         $fields = array('type' => $type, 'comment' => $comment, 'comment_attributes' => $attributes, 'type_id' => $obj_id, 'userid' => userid(), 'date_added' => now(), 'parent_id' => $reply_to, 'anonym_name' => $name, 'anonym_email' => $email, 'comment_ip' => mysql_clean(client_ip()), 'type_owner_id' => $obj_owner);
         $cid = db_insert(tbl('comments'), $fields);
         $db->update(tbl("users"), array("total_comments"), array("|f|total_comments+1"), " userid='" . userid() . "'");
         e(lang("grp_comment_msg"), "m");
         //$cid = $db->insert_id();
         $own_details = $userquery->get_user_field_only($obj_owner, 'email');
         $username = username();
         $username = $username ? $username : post('name');
         $useremail = $email;
         //Adding Comment Log
         $log_array = array('success' => 'yes', 'action_obj_id' => $cid, 'action_done_id' => $obj_id, 'details' => "made a comment", 'username' => $username, 'useremail' => $useremail);
         insert_log($type . '_comment', $log_array);
         //sending email
         if (SEND_COMMENT_NOTIFICATION == 'yes' && $own_details) {
             global $cbemail;
             $tpl = $cbemail->get_template('user_comment_email');
             $more_var = array('{username}' => $username, '{obj_link}' => $obj_link . '#comment_' . $cid, '{comment}' => $comment, '{obj}' => get_obj_type($type));
             if (!is_array($var)) {
                 $var = array();
             }
             $var = array_merge($more_var, $var);
             $subj = $cbemail->replace($tpl['email_template_subject'], $var);
             $msg = nl2br($cbemail->replace($tpl['email_template'], $var));
             //Now Finally Sending Email
             cbmail(array('to' => $own_details, 'from' => WEBSITE_EMAIL, 'subject' => $subj, 'content' => $msg));
         }
         add_users_mentioned($comment, NULL, $cid);
         return $cid;
     }
     return false;
 }
コード例 #2
0
ファイル: cbfeeds.class.php プロジェクト: yukisky/clipbucket
 /**
  * Adding feed in database...
  */
 function add_feed($array)
 {
     $valid_feed_items = array('userid', 'user', 'content_id', 'content', 'content_type', 'object_id', 'object', 'object_type', 'message', 'message_attributes', 'icon', 'action', 'action_group_id', 'is_activity');
     $new_array = array();
     foreach ($valid_feed_items as $item) {
         $new_array[$item] = $array[$item];
     }
     unset($array);
     $array = $new_array;
     if (!isSectionEnabled('feeds')) {
         return false;
     }
     global $userquery;
     $uid = $array['userid'];
     if (!$uid) {
         return false;
     }
     //Changing status if someone else post on a wall...
     if ($array['action'] == 'added_status' && $uid != $array['object_id']) {
         $array['action'] = 'posted_status';
     }
     //Verifying feed action and object
     $action = $this->action($array['action']);
     $object = $this->getObject($array['object_type']);
     if (!$action || !$object) {
         return false;
     }
     //Setting user feed array
     $feed = $array;
     //Setting content
     $feed['content'] = apply_filters($feed['content'], 'add_feed_content');
     if ($feed['content']) {
         //Get content cached ID
         $cntnt_id = $feed['content_id'];
         $cntnt_type = $feed['content_type'];
         $cntnt = $feed['content'];
         $content_cached_id = $this->add_object_cache($cntnt_id, $cntnt_type, $cntnt);
         if ($content_cached_id) {
             $feed['content_cached_id'] = $content_cached_id;
         }
     }
     $feed['content'] = json_encode($feed['content']);
     //Setting feed object
     $feed['object'] = apply_filters($feed['object'], 'add_feed_object');
     $feed['object'] = json_encode($feed['object']);
     if ($feed['object']) {
         //Get content cached ID
         $obj_id = $feed['object_id'];
         $obj_type = $feed['object_type'];
         $obj = $feed['object'];
         $object_cached_id = $this->add_object_cache($obj_id, $obj_type, $obj);
         if ($content_cached_id) {
             $feed['object_cached_id'] = $object_cached_id;
         }
     }
     //Get User details from message and then add it
     //To message_attributis.
     $message = $feed['message'];
     $message_attributes = get_message_attributes($message);
     //Feed message attributes
     $feed['message_attributes'] = apply_filters($message_attributes, 'add_feed_message_attributes');
     $feed['message_attributes'] = json_encode($feed['message_attributes']);
     //Feed User
     $user_fields = array('username', 'email', 'userid', 'fullname', 'total_videos', 'doj', 'dob');
     $user_fields = apply_filters($user_fields, 'feed_user_fields');
     $user = array();
     foreach ($user_fields as $field) {
         $user[$field] = $feed['user'][$field];
     }
     $feed['user'] = apply_filters($user, 'add_feed_user');
     $feed['user'] = json_encode($user);
     $feed['date_added'] = now();
     $feed['last_updated'] = time();
     $feed['time_added'] = time();
     if (!$this->feed_exists($feed) || 1) {
         unset($feed['content']);
         unset($feed['object']);
         $feed_id = db_insert(tbl('feeds'), $feed);
         //$feed['feed_id'] = $feed_id;
         //return $feed;
         add_users_mentioned($message, $feed_id);
         return $feed_id;
     } else {
         return false;
     }
 }