コード例 #1
0
 public function processPostsV4($posts, $forumid, $tds)
 {
     global $logService;
     $logService->log('TRACE', 'inside processPosts', '', $forumid);
     global $um;
     global $forum_status;
     if (!$posts) {
         return 0;
     }
     //safety
     if ($posts->code == 13) {
         return 13;
     }
     $has_context = true;
     $processRules = true;
     $ts = 0;
     $dirtyWorking = false;
     //dirty flags for sending alerts on new messages to the browser
     $dirtyDeleted = false;
     $dirtyPending = false;
     $dirtyWatch = false;
     $dirtyApproved = false;
     $dirtyRules = false;
     $dirtyHistory = false;
     $sth = $this->prepare("INSERT INTO `qwp_posts`(`qforumid`,`forum`,`id`,\n                `parent`,`message`,`isflagged`,`thread`,`raw_message`,`createdat`,`isedited`,`ishighlighted`,`ipaddress`,\n                `isspam`,`isdeleted`,`likes`,`isapproved`,`dislikes`,`author_username`,`author_name`,`author_url`,\n                `author_profileurl`,`author_emailHash`,`author_avatar_permalink`,`author_avatar_cache`,`author_id`,\n                `author_isanonymous`,`author_email`,`status`,`state`,post_ticketid,watch_ticketid,watch_type,watch_identity,\n                thread_title,thread_url,role,updatedat) \n                    VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,UNIX_TIMESTAMP(now()))");
     $sth1 = $this->prepare("INSERT into qwp_post_actions(postid,forumid,actionid,context,`date`,username,ruleid,status,allow_test) values(?,?,?,?,now(),'disqus',?,0,?)");
     $sth2 = $this->prepare("SELECT id,status,message from `qwp_posts` where id=? and qforumid=?");
     $sth3 = $this->prepare("UPDATE qwp_posts set message=?, updatedat =UNIX_TIMESTAMP(now()) where id=? and qforumid=?");
     $sth5 = $this->prepare("SELECT xid,role from qwp_forum_identities where identity=? and forumid=?");
     $sth6 = $this->prepare("INSERT INTO qwp_forum_identities  (forumid,identity,author_username,author_name,author_url,author_profileurl,author_avatar_permalink,author_avatar_cache,author_id,author_isanonymous,author_email) values(?,?,?,?,?,?,?,?,?,?,?)");
     $sth7 = $this->prepare("SELECT xid from qwp_forum_identity_ips where identity=? and ip=?");
     $sth8 = $this->prepare("UPDATE qwp_forum_identity_ips set last_used=now() where xid=?");
     $sth9 = $this->prepare("INSERT INTO qwp_forum_identity_ips (ip,identity,last_used,first_used) value(?,?,now(),now())");
     //$sth11=$this->prepare("SELECT children, parent FROM qwp_posts where id=?");
     //$sth12=$this->prepare("UPDATE qwp_posts set children=? where id=?");
     $sth13 = $this->prepare("SELECT title,url from qwp_threads where thread=? and forumid=?");
     $s1 = $this->prepare("SELECT * from qwp_rules where identity like ? and thread IS NULL and status=1 and forumid=? order by expiration");
     $s11 = $this->prepare("SELECT * from qwp_rules where identity like ? and thread like ? and status=1 and forumid=? order by expiration");
     $s12 = $this->prepare("UPDATE qwp_rules set status=0 where xid=?");
     $s2 = $this->prepare("INSERT INTO qwp_post_watch (postid,ticketid,forumid,date,username,type) values (?,?,?,now(),'disqus',?)");
     // $s21=$this->prepare("UPDATE qwp_posts set watch_ticketid=?, watch_type=?,watch_identity=? where id=?");
     $s3 = $this->prepare("INSERT into qwp_rules (`status`,identity,action,date_active,duration,apply_back,description,expiration,forumid) values(1,?,?,now(),?,?,?,?,?)");
     //$s4=$this->prepare("SELECT * from qwp_tickets where ip like ?");
     $s5 = $this->prepare("INSERT INTO qwp_rule_actions (ruleid,identity,actionid,date,context,username,forumid) values (?,?,9,now(),?,'auto',?)");
     $s6 = $this->prepare("INSERT INTO qwp_post_index (postid,parentid,has_context,forumid,thread) values(?,?,?,?,?)");
     $s7 = $this->prepare("UPDATE qwp_post_index set has_context=? where postid=? and forumid=?");
     // $s8=$this->prepare("select has_context from qwp_post_index where postid=? and forum=?");
     $s8 = $this->prepare("SELECT postid from qwp_post_index  where postid=? and forumid=?");
     $cached_threads = array();
     //main processing loop:
     if (!is_array($posts->response)) {
         $pp = array(1 => $posts->response);
     } else {
         $pp = $posts->response;
     }
     foreach ($pp as $post) {
         $logService->log('TRACE', 'inside processPostsLoop', $post->message, $forumid);
         $watch = null;
         if (!isset($post->ipAddress)) {
             $post->ipAddress = "0.0.0.0";
         }
         if (!isset($post->author->email)) {
             $i = rand(0, 1000000);
             $post->author->email = 'unknown' . $i . '@disqus.com';
         }
         $post->ipAddress = $this->scramble_ip($post->ipAddress);
         //$logService->log('DBUG&&&','BEGIN PROCESS postid='.$post->id,'','');
         //1. Check if the post is already present
         $sth2->bindParam(1, $post->id, PDO::PARAM_INT);
         $sth2->bindParam(2, $forumid, PDO::PARAM_INT);
         $sth2->execute();
         $rs = $sth2->fetch(PDO::FETCH_ASSOC);
         $logService->log('TRACE', 'inside processPosts11', '', $forumid);
         if ($rs) {
             $logService->log('TRACE', 'inside processPosts12', '', $forumid);
             //existing post
             $postid = $rs['id'];
             $old_message = $rs['message'];
             $status = 1;
             $state = 'working';
             if ($post->isDeleted && $rs['status'] != 3) {
                 $status = 3;
                 $state = 'deleted';
             } else {
                 if ($post->isSpam && $rs['status'] != 2) {
                     $status = 2;
                     $state = 'pending';
                 } else {
                     if ($rs['status'] == 3 && !$post->isDeleted && !$post->isSpam) {
                         $logService->log('TRACE', 'inside processPosts13', '', $forumid);
                         //delete post on disqus
                         $act = 3;
                         $sth1->bindParam(1, $post->id, PDO::PARAM_INT);
                         $sth1->bindParam(2, $forumid, PDO::PARAM_INT);
                         $sth1->bindParam(3, $act, PDO::PARAM_INT);
                         $s = 'delete on sync';
                         $sth1->bindParam(4, $s, PDO::PARAM_STR);
                         $ruleid = 0;
                         $sth1->bindParam(5, $ruleid, PDO::PARAM_STR);
                         $allow_test = 0;
                         $sth1->bindParam(6, $allow_test, PDO::PARAM_INT);
                         //$sth1->execute();
                         $this->beginTransaction();
                         $sth1->execute();
                         $xid = $this->lastInsertId();
                         $table = 'qwp_post_actions';
                         $action = 1;
                         $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                         $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                         $sth61->bindParam(2, $table, PDO::PARAM_STR);
                         $sth61->bindParam(3, $action, PDO::PARAM_INT);
                         $sth61->execute();
                         $this->commit();
                     }
                 }
             }
             if ($post->message !== $old_message) {
                 //update the body of the post with the latest from Disqus
                 $sth3->bindParam(1, $post->message, PDO::PARAM_STR);
                 $sth3->bindParam(2, $postid, PDO::PARAM_INT);
                 $sth3->bindParam(3, $forumid, PDO::PARAM_INT);
                 $sth3->execute();
                 //TODO: should only send the tick to those with tabs containing the postid
             }
             $logService->log('TRACE', 'UPDATE postid=' . $post->id, '', $forumid);
             //update has_context in the index
             //$s7=$this->prepare("UPDATE qwp_post_index set has_context=? where postid=? and forumid=?) values(?,?,?)");
             // Refactored 3/9/2015 to fix old posts without index when doing thread loads
             $s8->bindParam(1, $postid, PDO::PARAM_INT);
             $s8->bindParam(2, $forumid, PDO::PARAM_INT);
             $s8->execute();
             $rs = $s8->fetch(PDO::FETCH_ASSOC);
             if ($rs) {
                 if ($has_context) {
                     $this->beginTransaction();
                     $s91 = $this->prepare("SELECT xid from qwp_post_index where postid=? and forumid=?");
                     $s91->bindParam(1, $postid, PDO::PARAM_INT);
                     $s91->bindParam(2, $forumid, PDO::PARAM_INT);
                     $s91->execute();
                     $xid = $s91->fetch(PDO::FETCH_ASSOC)['xid'];
                     $s7->bindParam(1, $has_context, PDO::PARAM_INT);
                     $s7->bindParam(2, $postid, PDO::PARAM_INT);
                     $s7->bindParam(3, $forumid, PDO::PARAM_INT);
                     $s7->execute();
                     $table = 'qwp_post_index';
                     $action = 2;
                     $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                     $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                     $sth61->bindParam(2, $table, PDO::PARAM_STR);
                     $sth61->bindParam(3, $action, PDO::PARAM_INT);
                     $sth61->execute();
                     $this->commit();
                 }
             } else {
                 $parent = $post->parent;
                 if (empty($parent)) {
                     $parent = -1;
                 }
                 $thread = $post->thread;
                 $s6->bindParam(1, $postid, PDO::PARAM_STR);
                 $s6->bindParam(2, $parent, PDO::PARAM_INT);
                 $s6->bindParam(3, $has_context, PDO::PARAM_INT);
                 $s6->bindParam(4, $forumid, PDO::PARAM_INT);
                 $s6->bindParam(5, $thread, PDO::PARAM_INT);
                 //$s6->execute();
                 try {
                     $this->beginTransaction();
                     $s6->execute();
                     $xid = $this->lastInsertId();
                     $table = 'qwp_post_index';
                     $action = 1;
                     $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                     $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                     $sth61->bindParam(2, $table, PDO::PARAM_STR);
                     $sth61->bindParam(3, $action, PDO::PARAM_INT);
                     $sth61->execute();
                     $this->commit();
                 } catch (Exception $ignore) {
                 }
             }
         } else {
             $logService->log('DBUG&&&', 'NEW postid=' . $post->id, $post->message, $forumid);
             //new post
             $status = 1;
             $state = 'working';
             if ($post->isDeleted) {
                 $status = 3;
                 $state = 'deleted';
                 $dirtyDeleted = true;
             } else {
                 if ($post->isSpam) {
                     $status = 2;
                     $state = 'pending';
                     $dirtyPending = true;
                 } else {
                     $dirtyWorking = true;
                 }
             }
             if (empty($post->author->email) && (empty($post->author->emailHash) || !isset($post->author->emailHash))) {
                 $act = 3;
                 $sth1->bindParam(1, $post->id, PDO::PARAM_INT);
                 $sth1->bindParam(2, $forumid, PDO::PARAM_INT);
                 $sth1->bindParam(3, $act, PDO::PARAM_INT);
                 $s = 'guest posts are not allowed';
                 $sth1->bindParam(4, $s, PDO::PARAM_STR);
                 $ruleid = 0;
                 $sth1->bindParam(5, $ruleid, PDO::PARAM_STR);
                 $allow_test = 0;
                 $sth1->bindParam(6, $allow_test, PDO::PARAM_INT);
                 $sth1->execute();
                 $i = rand(0, 1000000);
                 $post->author->email = 'notallowed' . $i . '@guest.com';
                 $postid = $post->id;
                 $message = "Post has been deleted due to the absense of author's email - guest posting is not allowed on this forum. If you think this is in error, please check your Disqus account settings. @del " . $postid;
                 //respodToPost($token,$postid,$message);
                 if ($forum_status == 2) {
                     $txid = tx(0, 'AutoRespond:' . $message);
                     // $um->respondByDefenderUser($postid,urlencode($message));
                     tx($txid, ' END');
                 }
             } else {
                 if (empty($post->author->username) || !isset($post->author->username)) {
                     $act = 3;
                     $sth1->bindParam(1, $post->id, PDO::PARAM_INT);
                     $sth1->bindParam(2, $forumid, PDO::PARAM_INT);
                     $sth1->bindParam(3, $act, PDO::PARAM_INT);
                     $s = 'guest posts are not allowed';
                     $sth1->bindParam(4, $s, PDO::PARAM_STR);
                     $ruleid = 0;
                     $sth1->bindParam(5, $ruleid, PDO::PARAM_STR);
                     $allow_test = 0;
                     $sth1->bindParam(6, $allow_test, PDO::PARAM_INT);
                     $sth1->execute();
                     $i = rand(0, 1000000);
                     $post->author->email = 'notallowed' . $i . '@guest.com';
                     $postid = $post->id;
                     $message = "Post has been deleted due to the absense of author's username - guest posting is not allowed on this forum. If you think this is in error, please check your Disqus account settings. @del " . $postid;
                     //respodToPost($token,$postid,$message);
                     if ($forum_status == 2) {
                         $txid = tx(0, 'AutoRespond:' . $message);
                         //$um->respondByDefenderUser($postid,urlencode($message));
                         tx($txid, ' END');
                     }
                 }
             }
             if (empty($post->author->email)) {
                 $i = rand(0, 1000000);
                 $post->author->email = 'unknown' . $i . '@guest.com';
             }
             if (!isset($post->author->emailHash)) {
                 $post->author->emailHash = null;
             }
             $emailHash = $post->author->emailHash;
             if (empty($emailHash)) {
                 $emailHash = md5($post->author->email);
                 $post->author->emailHash = $emailHash;
             }
             $identity = $emailHash;
             $c = strtotime($post->createdAt . 'UTC');
             if ($c > $ts) {
                 $ts = $c;
             }
             //date_default_timezone_set('UTC');
             $d = date('Y-m-d H:i:s', $c);
             $sth7->bindParam(1, $emailHash, PDO::PARAM_STR);
             $sth7->bindParam(2, $post->ipAddress, PDO::PARAM_STR);
             $logService->log('DBUG&&&', 'CHECKING THE IDENTITY IP postid=' . $post->id, '', '');
             $sth7->execute();
             $rs = $sth7->fetch(PDO::FETCH_ASSOC);
             if ($rs) {
                 //  $logService->log('DBUG&&&','NEW IDENTITY IP postid='.$post->id,'','');
                 $id = $rs['xid'];
                 $sth8->bindParam(1, $id, PDO::PARAM_INT);
                 //$sth8->execute();
                 $this->beginTransaction();
                 $sth8->execute();
                 $xid = $id;
                 $table = 'qwp_forum_identitiy_ips';
                 $action = 2;
                 $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                 $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                 $sth61->bindParam(2, $table, PDO::PARAM_STR);
                 $sth61->bindParam(3, $action, PDO::PARAM_INT);
                 $sth61->execute();
                 $this->commit();
             } else {
                 $logService->log('DBUG&&&', '111 EXISTING IDENTITY IP postid=' . $post->id, '', '');
                 $sth9->bindParam(1, $post->ipAddress, PDO::PARAM_STR);
                 $sth9->bindParam(2, $emailHash, PDO::PARAM_STR);
                 //slow $$$ $this->correlateOnIP($forumid,$post->ipAddress);
                 //$sth9->execute();
                 $this->beginTransaction();
                 $sth9->execute();
                 $xid = $this->lastInsertId();
                 $table = 'qwp_forum_identity_ips';
                 $action = 1;
                 $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                 $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                 $sth61->bindParam(2, $table, PDO::PARAM_STR);
                 $sth61->bindParam(3, $action, PDO::PARAM_INT);
                 $sth61->execute();
                 $this->commit();
             }
             $logService->log('DBUG&&&', 'DONE IDENTITY IP postid=' . $post->id, '', '');
             //check identity:
             $sth5->bindParam(1, $emailHash, PDO::PARAM_STR);
             $sth5->bindParam(2, $forumid, PDO::PARAM_STR);
             $sth5->execute();
             $role = -1;
             $rs = $sth5->fetch(PDO::FETCH_ASSOC);
             $logService->log('DBUG&&&', '222 CHECK IDENTITY postid=' . $post->id, '', '');
             if (empty($rs)) {
                 $sth6->bindParam(1, $forumid, PDO::PARAM_INT);
                 $sth6->bindParam(2, $emailHash, PDO::PARAM_STR);
                 $sth6->bindParam(3, $post->author->username, PDO::PARAM_STR);
                 $sth6->bindParam(4, $post->author->name, PDO::PARAM_STR);
                 $sth6->bindParam(5, $post->author->url, PDO::PARAM_STR);
                 $sth6->bindParam(6, $post->author->profileUrl, PDO::PARAM_STR);
                 $sth6->bindParam(7, $post->author->avatar->permalink, PDO::PARAM_STR);
                 $sth6->bindParam(8, $post->author->avatar->cache, PDO::PARAM_STR);
                 $sth6->bindParam(9, $post->author->id, PDO::PARAM_STR);
                 $sth6->bindParam(10, $post->author->isAnonynous, PDO::PARAM_STR);
                 $sth6->bindParam(11, $post->author->email, PDO::PARAM_STR);
                 try {
                     //$sth6->execute();
                     $this->beginTransaction();
                     $sth6->execute();
                     $xid = $this->lastInsertId();
                     $table = 'qwp_forum_identities';
                     $action = 1;
                     $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                     $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                     $sth61->bindParam(2, $table, PDO::PARAM_STR);
                     $sth61->bindParam(3, $action, PDO::PARAM_INT);
                     $sth61->execute();
                     $this->commit();
                 } catch (Exception $ex) {
                     //for race conditions
                 }
                 $logService->log('DBUG&&&', 'NEW IDENTITY postid=' . $post->id, '', '');
             } else {
                 $role = $rs['role'];
             }
             /* now process rules. There could be only one active rule at a time for an identity and a thread.
             
                                 1. Get active rules for identity where thread is null
                                 2. If nothing, Get all active rules for identity where thread is the same as post. If none, goto 7
                                 3. For each rule check for expiration. If expired set to inactive and persist.
                                 4. If there is more than one active rule left, chose one that expires earliest. Set others to inactive and persist.
                                 5. if it is approve (1) - check if deleted, than approve. If it is ignore (0) - ignore. If it is watch(12) - put on watch type 3, if delete(3) - if post is not deleted on disqus, delete on disqus
                                 6. QUIT
                                 7. Get all the active rules for the identities that match post's IP for null thread and for this thread.
                                 8. Check currency of the dates and expire if necessery and persist.
                                 9. If there are no delete rules - QUIT.
                                 10. If there are any exclude or approve rules - create an exclude rule for this identity and put a watch(3). QUIT
                                 11. Create delete rule for the identity, delete the post, add watch(1).
             
             
             
                                 V2 algorithm (deprecated)
                                 1. get a ticket(s) for the identity if any => BATCH;  if no go to 5. 
                                 2. IDENTITY MATCH: If there is a ticket matching IP - that's SOURCE ticket. Otherwise any of the BATCH. 
                                 3. if it is approve (1) - check if deleted, than approve. If it is ignore (0) - ignore. If it is watch(12) - put on watch type 3, if delete(3) - if post is not deleted on disqus, delete on disqus
                                 4. if it is IP match: quit.  Otherwise add ticket with type and identity of the SOURCE ticket and new ip. Quit
                                 6. if there are in BATCH any excludes (0) or approves (1) then even if there is a delete for this IP it will not be propagated to new
                                     identity, instead a watch (3) ticket will be created for new identity, otherwise add delete ticket with identity of the SOURCE ticket and new ip
                             ****/
             $logService->log('TRACE', 'inside processPosts2', 'forum_status=' . $forum_status, $forumid);
             $watch = null;
             if ($processRules && $forum_status == 2) {
                 $logService->log('DBUG&&&', 'PROCESS RULES postid=' . $post->id, '', '');
                 $post_ticketid = 0;
                 $ticketid = 0;
                 /**
                                         3/12/15: need some serious thought here. Why _t rules are not expiring if there are any general rules? Why only one rule is considered?
                 
                 
                                     **/
                 //1)
                 $s1->bindParam(1, $emailHash, PDO::PARAM_STR);
                 $s1->bindParam(2, $forumid, PDO::PARAM_INT);
                 $s1->execute();
                 $rs = $s1->fetchAll(PDO::FETCH_ASSOC);
                 $source = NULL;
                 if (empty($rs)) {
                     //2)
                     $s11->bindParam(1, $emailHash, PDO::PARAM_STR);
                     $s11->bindParam(2, $post->thread, PDO::PARAM_STR);
                     $s11->bindParam(3, $forumid, PDO::PARAM_INT);
                     $s11->execute();
                     $rs = $s11->fetchAll(PDO::FETCH_ASSOC);
                 }
                 $r = null;
                 if ($rs) {
                     $logService->log('DBUG&&&', 'PROCESS RULES  2 postid=' . $post->id, '', '');
                     foreach ($rs as $rule) {
                         $logService->log('TRACE', 'inside rule1', 'forum_status=' . $forum_status, $forumid);
                         $expiration_field = $rule['expiration'];
                         if (!empty($expiration_field)) {
                             $expiration = new DateTime($expiration_field);
                             $now = new DateTime(null);
                             $now = $now->getTimestamp();
                             if ($expiration->getTimestamp() < $now) {
                                 //expiring;
                                 $s12->bindParam(1, $rule['xid'], PDO::PARAM_INT);
                                 $s12->execute();
                                 $sql = "INSERT INTO qwp_rule_actions (username,actionid,date,ruleid,context,identity,forumid) values(?,?,now(),?,?,?,?)";
                                 $sth_e = $this->prepare($sql);
                                 $user_name = 'qwiket';
                                 $a = 14;
                                 //expiring
                                 $description = "rule expired";
                                 $sth_e->bindParam(1, $user_name, PDO::PARAM_STR);
                                 $sth_e->bindParam(2, $a, PDO::PARAM_INT);
                                 $sth_e->bindParam(3, $rule['xid'], PDO::PARAM_INT);
                                 $sth_e->bindParam(4, $description, PDO::PARAM_STR);
                                 $sth_e->bindParam(5, $identity, PDO::PARAM_STR);
                                 $sth_e->bindParam(6, $forumid, PDO::PARAM_INT);
                                 $sth_e->execute();
                                 $dirtyRules = true;
                                 $dirtyHistory = true;
                                 tx(0, 'RuleExpired');
                             } else {
                                 $r = $rule;
                                 // expiration in the future
                                 break;
                             }
                         } else {
                             $r = $rule;
                             // no expiration
                             break;
                         }
                     }
                 }
                 if ($r) {
                     //5)
                     $type = $r['action'];
                     $post_ticketid = $r['xid'];
                     $logService->log('TRACE', 'inside rule5', 'rxid=' . $post_ticketid . 'type=' . $type . ':ip=' . $ip, $forumid);
                     $allow_test = 0;
                     if (strstr($r['description'], '#')) {
                         //# indicates this is a test command, should be allowed to go to disqus even in test mode
                         $allow_test = 1;
                     }
                     switch ($type) {
                         case 1:
                             if ($status == 3 || $status == 2) {
                                 $act = 1;
                                 $sth1->bindParam(1, $post->id, PDO::PARAM_INT);
                                 $sth1->bindParam(2, $forumid, PDO::PARAM_INT);
                                 $sth1->bindParam(3, $act, PDO::PARAM_INT);
                                 $s = 'pre-approve ';
                                 $sth1->bindParam(4, $s, PDO::PARAM_STR);
                                 $sth1->bindParam(5, $post_ticketid, PDO::PARAM_STR);
                                 $sth1->bindParam(6, $allow_test, PDO::PARAM_INT);
                                 $sth1->execute();
                                 $dirtyApproved = true;
                                 $dirtyHistory = true;
                             }
                             break;
                         case 2:
                             //$wt=3;
                             /*$s2->bindParam(1,$post->id,PDO::PARAM_INT);
                               $s2->bindParam(2,$r['id'],PDO::PARAM_INT);
                               $s2->bindParam(3,$forumid,PDO::PARAM_INT);
                               $s2->bindParam(4,$wt,PDO::PARAM_INT); //type= suspicions
                               $s2->execute();
                               */
                             $watch = array();
                             $watch['ruleid'] = $r['xid'];
                             $watch['type'] = 3;
                             $watch['identity'] = $r['identity'];
                             $dirtyWatch = true;
                             break;
                         case 3:
                             if ($status != 3) {
                                 $act = 3;
                                 $sth1->bindParam(1, $post->id, PDO::PARAM_INT);
                                 $sth1->bindParam(2, $forumid, PDO::PARAM_INT);
                                 $sth1->bindParam(3, $act, PDO::PARAM_INT);
                                 $s = 'auto-delete';
                                 $sth1->bindParam(4, $s, PDO::PARAM_STR);
                                 $sth1->bindParam(5, $post_ticketid, PDO::PARAM_STR);
                                 $sth1->bindParam(6, $allow_test, PDO::PARAM_INT);
                                 $sth1->execute();
                                 $dirtyDeleted = true;
                                 $dirtyHistory = true;
                                 tx(0, ' AutoDelete' . 'ticketid=' . $post_ticketid . ';postid=' . $post->id);
                             }
                     }
                 } else {
                     //7
                     if ($ip && $ip != '0.0.0.0') {
                         $logService->log('TRACE', 'inside rule7 $ip=' . $ip, 'forum_status=' . $forum_status, $forumid);
                         $ip = $post->ipAddress;
                         $s77 = $this->prepare("SELECT distinct r.*,i.role,i.author_name from  qwp_forum_identity_ips ips\n                            INNER JOIN qwp_forum_identities i on ips.identity=i.identity \n                            LEFT OUTER JOIN qwp_rules r on ips.identity=r.identity and (r.thread is NULL or r.thread=?)\n                            where ips.ip=? ");
                         $s77->bindParam(1, $thread, PDO::PARAM_STR);
                         $s77->bindParam(2, $ip, PDO::PARAM_STR);
                         $s77->execute();
                         $rs = $s77->fetchAll(PDO::FETCH_ASSOC);
                         $del = null;
                         $exl = false;
                         $nowatch = false;
                         if ($rs) {
                             foreach ($rs as $rule) {
                                 if ($rule['action'] == 3 && $r['status'] == 1) {
                                     $del = $rule;
                                 } else {
                                     if ($rule['action'] == 1 && $r['status'] == 1 || $rule['role'] >= 0) {
                                         $exl = true;
                                     } else {
                                         if ($rule['action'] == 2) {
                                             $nowatch = true;
                                         }
                                     }
                                 }
                                 // added to prevent creating another watch, when one was already created before
                                 $expiration_field = $rule['expiration'];
                                 if (!empty($expiration_field)) {
                                     $expiration = new DateTime($expiration_field);
                                     $now = new DateTime(null);
                                     $now = $now->getTimestamp();
                                     if ($expiration->getTimestamp() < $now) {
                                         //expiring;
                                         $s12->bindParam(1, $rule['xid'], PDO::PARAM_INT);
                                         $s12->execute();
                                         $durtyRules = true;
                                         $dirtyHistory = true;
                                     }
                                 }
                             }
                         }
                     }
                     if (!empty($del)) {
                         // if there is a delete rule
                         $logService->log('TRACE', 'inside ruleDel', 'forum_status=' . $forum_status, $forumid);
                         if (!$exl) {
                             // if no exception rules
                             $logService->log('TRACE', 'inside ruleDel 2', 'forum_status=' . $forum_status, $forumid);
                             //create delete rule
                             //$s3=$this->prepare("INSERT into qwp_rules (`status`,username,identity,action,date_created,duration,apply_back,description,expiration) values(1,?,?,?,now(),?,?,?,?")
                             $action = 3;
                             $sname = 'auto';
                             $sdescription = '[propagated from ' . $del['author_name'] . ']' . $del['description'];
                             //$s3->bindParam(1,$s,PDO::PARAM_STR);
                             $s3->bindParam(1, $emailHash, PDO::PARAM_STR);
                             $s3->bindParam(2, $action, PDO::PARAM_INT);
                             $s3->bindParam(3, $del['duration'], PDO::PARAM_STR);
                             $s3->bindParam(4, $del['apply_back'], PDO::PARAM_STR);
                             $s3->bindParam(5, $sdescription, PDO::PARAM_STR);
                             $s3->bindParam(6, $del['expiration'], PDO::PARAM_INT);
                             $s3->bindParam(7, $forumid, PDO::PARAM_INT);
                             $s3->execute();
                             $ruleid = $this->lastInsertId();
                             $scontext = 'propagate delete from ' . $del['author_name'];
                             $s5 = $this->prepare("INSERT INTO qwp_rule_actions (ruleid,identity,actionid,date,context,username,forumid) values (?,?,9,now(),?,'auto',?)");
                             $s5->bindParam(1, $ruleid, PDO::PARAM_INT);
                             $s5->bindParam(2, $emailHash, PDO::PARAM_STR);
                             $s5->bindParam(3, $scontext, PDO::PARAM_STR);
                             $s5->bindParam(4, $forumid, PDO::PARAM_INT);
                             $s5->execute();
                             if ($status != 3) {
                                 $logService->log('TRACE', 'inside ruleDel 3', 'forum_status=' . $forum_status, $forumid);
                                 $a = 3;
                                 $sth1->bindParam(1, $post->id, PDO::PARAM_INT);
                                 $sth1->bindParam(2, $forumid, PDO::PARAM_INT);
                                 $sth1->bindParam(3, $a, PDO::PARAM_INT);
                                 $s = 'auto-delete';
                                 $sth1->bindParam(4, $s, PDO::PARAM_STR);
                                 $sth1->bindParam(5, $ruleid, PDO::PARAM_STR);
                                 $allow_test = 0;
                                 $sth1->bindParam(6, $allow_test, PDO::PARAM_INT);
                                 $sth1->execute();
                                 tx(0, 'AutoDelete ' . 'rule=' . $ruleid . ';postid=' . $post->id);
                             }
                             $wt = 1;
                             //new identity
                             $s2->bindParam(1, $post->id, PDO::PARAM_INT);
                             $s2->bindParam(2, $del['xid'], PDO::PARAM_INT);
                             $s2->bindParam(3, $forumid, PDO::PARAM_INT);
                             $s2->bindParam(4, $wt, PDO::PARAM_INT);
                             //type= new identity
                             $s2->execute();
                             /*$s21->bindParam(1,$del['id'],PDO::PARAM_INT);
                               $s21->bindParam(2,$wt,PDO::PARAM_INT);
                               $s21->bindParam(3,$del['identity'],PDO::PARAM_INT);
                               $s21->bindParam(4,$post->id,PDO::PARAM_INT);
                               $s21->execute();*/
                             $watch = array();
                             $watch['ruleid'] = $del['xid'];
                             $watch['type'] = $wt;
                             $watch['identity'] = $del['identity'];
                             $dirtyRules = true;
                             $dirtyWatch = true;
                             $dirtyHistory = true;
                         } else {
                             if (!$nowatch) {
                                 //create exclusion rule
                                 $action = 2;
                                 //watch
                                 // $s3->bindParam(1,$del['username'],PDO::PARAM_STR);
                                 $s3->bindParam(1, $emailHash, PDO::PARAM_STR);
                                 $s3->bindParam(2, $action, PDO::PARAM_INT);
                                 $s3->bindParam(3, $del['duration'], PDO::PARAM_STR);
                                 $s3->bindParam(4, $del['apply_back'], PDO::PARAM_STR);
                                 $s3->bindParam(5, $del['description'], PDO::PARAM_STR);
                                 $s3->bindParam(6, $del['expiration'], PDO::PARAM_INT);
                                 $s3->bindParam(7, $forumid, PDO::PARAM_INT);
                                 $s3->execute();
                                 $ruleid = $this->lastInsertId();
                                 $scontext = 'propagate watch';
                                 $s5->bindParam(1, $ruleid, PDO::PARAM_INT);
                                 $s5->bindParam(2, $emailHash, PDO::PARAM_STR);
                                 $s5->bindParam(3, $scontext, PDO::PARAM_STR);
                                 $s5->bindParam(4, $forumid, PDO::PARAM_INT);
                                 $s5->execute();
                                 $wt = 1;
                                 $s2->bindParam(1, $post->id, PDO::PARAM_INT);
                                 $s2->bindParam(2, $del['xid'], PDO::PARAM_INT);
                                 $s2->bindParam(3, $forumid, PDO::PARAM_INT);
                                 $s2->bindParam(4, $wt, PDO::PARAM_INT);
                                 //type= watch
                                 $s2->execute();
                                 //$s21=$this->prepare("UPDATE qwp_posts set watch_ticketid=?, watch_type=?,watch_identity=? where id=?");
                                 /*$s21->bindParam(1,$del['id'],PDO::PARAM_INT);
                                   $s21->bindParam(2,$wt,PDO::PARAM_INT);
                                   $s21->bindParam(3,$del['identity'],PDO::PARAM_INT);
                                   $s21->bindParam(4,$post->id,PDO::PARAM_INT);
                                   $s21->execute();*/
                                 $watch = array();
                                 $watch['ruleid'] = $del['xid'];
                                 $watch['type'] = $wt;
                                 $watch['identity'] = $del['identity'];
                                 $dirtyRules = true;
                                 $dirtyWatch = true;
                                 $dirtyHistory = true;
                             }
                         }
                     }
                 }
                 /* Process commands
                        @troll,@spam,@hold,@del,@undo,@info,@comment
                    */
                 $logService->log('TRACE', 'inside ruleCommands', 'forum_status=' . $forum_status, $forumid);
                 if ($status != 3) {
                     $body = $post->raw_message;
                     if (stristr($body, '@del') || !stristr($body, '@comment')) {
                         $logService->log('TRACE', 'inside ruleDel--', 'forum_status=' . $forum_status, $forumid);
                         $command = 0;
                         /*if(stristr($body,'#troll'))
                               $command=1;
                           if(stristr($body,'#spam'))
                               $command=2;
                           if(stristr($body,'#hold'))
                               $command=3;
                           if(stristr($body,'#del'))
                               $command=4;
                           if(stristr($body,'#undo'))
                               $command=5;
                           if(stristr($body,'#info'))
                               $command=6;
                           if(stristr($body,'#unhold'))
                               $command=7;
                           */
                         //$test=preg_match('/#troll\w*\b/i',$body,$matches);
                         //@- production commands, # test commands. Will be saved in description and used to differentiate
                         if (preg_match('/[#@][Tt][Rr][Oo][Ll][Ll]\\w*\\b/i', $body, $matches1)) {
                             $command = 1;
                         }
                         if (preg_match('/[#@][Ss][Pp][Aa][Mm]\\w*\\b/i', $body, $matches2)) {
                             $command = 2;
                         }
                         if (preg_match('/[#@][Hh][Oo][Ll][Dd]\\w*\\b/i', $body, $matches3)) {
                             $command = 3;
                         }
                         if (preg_match('/[#@][Uu][Nn][Hh][Oo][Ll][Dd]\\w*\\b/i', $body, $matches4)) {
                             $command = 4;
                         }
                         if (preg_match('/[#@][Ii][Nn][Ff][Oo]\\w*\\b(.*)/i', $body, $matches5)) {
                             $command = 5;
                         }
                         if (preg_match('/[#@][Hh][Ee][Ll][Pp]\\w*\\b/i', $body, $matches7)) {
                             $command = 7;
                         }
                         if (preg_match('/[#@][Mm][Oo][Dd]\\w*\\b/i', $body, $matches8)) {
                             $command = 8;
                         }
                         if (preg_match('/[#@][Dd][Ee][Ll]\\w*\\b/i', $body, $matches6)) {
                             $command = 6;
                         }
                         $allow_test = !strstr($body, '@');
                         $matches = null;
                         switch ($command) {
                             case 1:
                                 $matches = $matches1;
                                 break;
                             case 2:
                                 $matches = $matches2;
                                 break;
                             case 3:
                                 $matches = $matches3;
                                 break;
                             case 4:
                                 $matches = $matches4;
                                 break;
                             case 5:
                                 $matches = $matches5;
                                 break;
                             case 6:
                                 $matches = $matches6;
                                 break;
                             case 7:
                                 $matches = $matches7;
                                 break;
                             case 8:
                                 $matches = $matches8;
                                 break;
                         }
                         switch ($command) {
                             case 1:
                             case 2:
                                 $watch = $this->processCreateDeleteTicket($post, $emailHash, $forumid, $command, $matches, $allow_test);
                                 $dirtyRules = true;
                                 $dirtyWatch = true;
                                 $dirtyHistory = true;
                                 tx(0, 'CreateDelete ' . 'identity=' . $emailHash . ';body=' . $body);
                                 break;
                             case 3:
                             case 4:
                                 $watch = $this->handleHold($post, $emailHash, $forumid, $command, $matches, $allow_test);
                                 $dirtyRules = true;
                                 $dirtyWatch = true;
                                 $dirtyHistory = true;
                                 tx(0, 'HandleHold ' . 'identity=' . $emailHash . ';body=' . $body);
                                 break;
                             case 5:
                                 $this->handleInfo($post, $forumid, $matches);
                                 tx(0, 'HandleInfo ' . 'identity=' . $emailHash . ';body=' . $body);
                                 //continue;  to be enabled in the future, for now keep them to see the activity
                                 break;
                             case 6:
                                 $this->handleDel($post, $forumid, $matches);
                                 tx(0, 'HandleDel ' . 'identity=' . $emailHash . ';body=' . $body);
                                 //continue;
                                 break;
                             case 7:
                                 $this->handleHelp($post, $forumid, $matches);
                                 tx(0, 'HandleHelp ' . 'identity=' . $emailHash . ';body=' . $body);
                                 //continue;
                                 break;
                             case 8:
                                 $watch = $this->handleMod($post, $forumid, $matches);
                                 tx(0, 'HandleMod ' . 'identity=' . $emailHash . ';body=' . $body);
                                 $dirtyWatch = true;
                                 break;
                         }
                     }
                 }
             }
             // process rules
             /***
                                 Try to set thread title and url if thread is already in the system
                                 $sth13=$this->prepare("SELECT title,url from qwp_threads where thread=? and forumid=?");
             
                             **/
             $logService->log('DBUG', 'PROCESS THREAD postid=' . $post->id, '', '');
             $thread = $post->thread;
             $thread_url = null;
             $thread_title = null;
             if (isset($cached_threads[$thread]['title'])) {
                 $thread_title = $cached_threads[$thread]['title'];
                 $thread_url = $cached_threads[$thread]['url'];
             } else {
                 //  $sth13=$this->prepare("SELECT title,url from qwp_threads where thread=? and forumid=?");
                 $sth13->bindParam(1, $thread, PDO::PARAM_INT);
                 $sth13->bindParam(2, $forumid, PDO::PARAM_INT);
                 $sth13->execute();
                 $rs = $sth13->fetch(PDO::FETCH_ASSOC);
                 if ($rs) {
                     $thread_title = $rs['title'];
                     $thread_url = $rs['url'];
                     $cached_threads[$thread]['title'] = $thread_title;
                     $cached_threads[$thread]['url'] = $thread_url;
                 }
                 /**
                                         Adding keeping track of active threads
                                         1. If thread is present but not active - move it into active
                                         2. Update lastpost timestamp for thread
                                         Note: if new thread - don't worry, the lastpost will be set when thread is created
                                     **/
                 $sta1 = $this->prepare("SELECT status from qwp_threads where thread=? and forumid=?");
                 $sta1->bindParam(1, $thread, PDO::PARAM_INT);
                 $sta1->bindParam(2, $forumid, PDO::PARAM_INT);
                 $sta1->execute();
                 $thread_status = $sta1->fetch(PDO::FETCH_ASSOC)['status'];
                 if ($thread_status == 2) {
                     $this->restoreThread($thread, $forumid);
                     //now could be a situation that the current post about to be inserted actually is just an update to a restored post
                     $postid = $post->id;
                     $sta3 = $this->prepare("select id from qwp_posts where id=? and qforumid=?");
                     $sta3->bindParam(1, $postid, PDO::PARAM_INT);
                     $sta3->bindParam(2, $forumid, PDO::PARAM_INT);
                     $sta3->execute();
                     $present = $sta3->fetch(PDO::FETCH_ASSOC)['id'];
                     if ($present) {
                         $sth3->bindParam(1, $post->message, PDO::PARAM_STR);
                         $sth3->bindParam(2, $postid, PDO::PARAM_INT);
                         $sth3->bindParam(3, $forumid, PDO::PARAM_INT);
                         $sth3->execute();
                         continue;
                     }
                 } else {
                     if ($thread_status == 1) {
                         $this->beginTransaction();
                         $sth61 = $this->prepare("select xid from qwp_threads where thread=? and forumid=?");
                         $sth61->bindParam(1, $thread, PDO::PARAM_INT);
                         $sth61->bindParam(2, $forumid, PDO::PARAM_INT);
                         $sth61->execute();
                         $xid = $sth61->fetch(PDO::FETCH_ASSOC)['xid'];
                         $sta2 = $this->prepare("update qwp_threads set lastpost=now() where thread=? and forumid=?");
                         $sta2->bindParam(1, $thread, PDO::PARAM_INT);
                         $sta2->bindParam(2, $forumid, PDO::PARAM_INT);
                         $sta2->execute();
                         $sta2->execute();
                         $table = 'qwp_threads';
                         $action = 2;
                         $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                         $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                         $sth61->bindParam(2, $table, PDO::PARAM_STR);
                         $sth61->bindParam(3, $action, PDO::PARAM_INT);
                         $sth61->execute();
                         $this->commit();
                     }
                 }
             }
             $logService->log('TRACE', 'inside processPosts3 forumid=' . $forumid . ';c=' . $c . 'state=' . $state . ';status=' . $status . 'post_ticketid=' . $post_ticketid . ';thread_title' . $thread_title . ';thread_url=' . $thread_url . ';role' . $role, var_log($post), '');
             $parent = $post->parent;
             if (empty($parent)) {
                 $parent = -1;
             }
             $sth = $this->prepare("INSERT INTO `qwp_posts`(`qforumid`,`forum`,`id`,\n                `parent`,`message`,`isflagged`,`thread`,`raw_message`,`createdat`,`isedited`,`ishighlighted`,`ipaddress`,\n                `isspam`,`isdeleted`,`likes`,`isapproved`,`dislikes`,`author_username`,`author_name`,`author_url`,\n                `author_profileurl`,`author_emailHash`,`author_avatar_permalink`,`author_avatar_cache`,`author_id`,\n                `author_isanonymous`,`author_email`,`status`,`state`,post_ticketid,watch_ticketid,watch_type,watch_identity,\n                thread_title,thread_url,role,updatedat) \n                    VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,UNIX_TIMESTAMP(now()))");
             $sth->bindParam(1, $forumid, PDO::PARAM_INT);
             $sth->bindParam(2, $post->forum, PDO::PARAM_STR);
             $sth->bindParam(3, $post->id, PDO::PARAM_STR);
             $sth->bindParam(4, $parent, PDO::PARAM_INT);
             $sth->bindParam(5, $post->message, PDO::PARAM_STR);
             $sth->bindParam(6, $post->isFlagged, PDO::PARAM_BOOL);
             $sth->bindParam(7, $post->thread, PDO::PARAM_STR);
             $sth->bindParam(8, $post->raw_message, PDO::PARAM_STR);
             $sth->bindParam(9, $c, PDO::PARAM_INT);
             $sth->bindParam(10, $post->isEdited, PDO::PARAM_BOOL);
             $sth->bindParam(11, $post->isHighlighted, PDO::PARAM_BOOL);
             $sth->bindParam(12, $post->ipAddress, PDO::PARAM_STR);
             $sth->bindParam(13, $post->isSpam, PDO::PARAM_BOOL);
             $sth->bindParam(14, $post->isDeleted, PDO::PARAM_BOOL);
             $sth->bindParam(15, $post->likes, PDO::PARAM_INT);
             $sth->bindParam(16, $post->isApproved, PDO::PARAM_BOOL);
             $sth->bindParam(17, $post->dislikes, PDO::PARAM_INT);
             $sth->bindParam(18, $post->author->username, PDO::PARAM_STR);
             $sth->bindParam(19, $post->author->name, PDO::PARAM_STR);
             $sth->bindParam(20, $post->author->url, PDO::PARAM_STR);
             $sth->bindParam(21, $post->author->profileUrl, PDO::PARAM_STR);
             $sth->bindParam(22, $emailHash, PDO::PARAM_STR);
             $sth->bindParam(23, $post->author->avatar->permalink, PDO::PARAM_STR);
             $sth->bindParam(24, $post->author->avatar->cache, PDO::PARAM_STR);
             $sth->bindParam(25, $post->author->id, PDO::PARAM_INT);
             $sth->bindParam(26, $post->author->isAnonymous, PDO::PARAM_BOOL);
             $sth->bindParam(27, $post->author->email, PDO::PARAM_STR);
             $sth->bindParam(28, $status, PDO::PARAM_INT);
             $sth->bindParam(29, $state, PDO::PARAM_STR);
             $sth->bindParam(30, $post_ticketid, PDO::PARAM_INT);
             $watch_ticketid = 0;
             $watch_type = 0;
             $watch_identity = null;
             if ($watch) {
                 $watch_ticketid = $watch['ruleid'];
                 $watch_type = $watch['type'];
                 $watch_identity = $watch['identity'];
                 $dirtyWatch = true;
             }
             $sth->bindParam(31, $watch_ticketid, PDO::PARAM_INT);
             $sth->bindParam(32, $watch_type, PDO::PARAM_INT);
             $sth->bindParam(33, $watch_identity, PDO::PARAM_INT);
             $sth->bindParam(34, $thread_title, PDO::PARAM_STR);
             $sth->bindParam(35, $thread_url, PDO::PARAM_STR);
             $sth->bindParam(36, $role, PDO::PARAM_INT);
             //  $logService->log('DBUG','BEGIN SAVE postid='.$post->id,'','');
             $go = true;
             while ($go) {
                 $go = false;
                 try {
                     $this->beginTransaction();
                     $r = $sth->execute();
                     $xid = $this->lastInsertId();
                     $table = 'qwp_posts';
                     $action = 1;
                     $sth = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                     $sth->bindParam(1, $xid, PDO::PARAM_INT);
                     $sth->bindParam(2, $table, PDO::PARAM_STR);
                     $sth->bindParam(3, $action, PDO::PARAM_INT);
                     $sth->execute();
                     $this->commit();
                 } catch (Exception $x) {
                     $logService->log('ERROR HANDLED', 'saving new post ' . $post->id, 'V3 body=' . $post->message . ';exception=' . fe($x), $forumid);
                     try {
                         $this->rollBack();
                     } catch (Exception $ignore) {
                     }
                     continue;
                 }
                 // $logService->log('DBUG','DONE SAVE postid='.$post->id,'','');
                 /* if(!$r){ // retry after removing the previous version of the post
                        $d=$this->prepare("DELETE from qwp_posts where id=?");
                        $d->bindParam(1,$post->id);
                        $d->execute();
                        $go=true;
                        continue;
                    }*/
             }
             $postid = $post->id;
             $thread = $post->thread;
             /*$hi=0;
                             if($has_context)
                                 $hi=1;
             
                             $s6->bindParam(1,$post->id,PDO::PARAM_INT);
                             $s6->bindParam(2,$parent,PDO::PARAM_INT);
                             $s6->bindParam(3,$hi,PDO::PARAM_INT);
                             $s6->bindParam(4,$forumid,PDO::PARAM_INT);
                             $s6->bindParam(5,$post->thread,PDO::PARAM_INT);
                             $s6->execute();
                             */
             $s8->bindParam(1, $postid, PDO::PARAM_INT);
             $s8->bindParam(2, $forumid, PDO::PARAM_INT);
             $s8->execute();
             $rs = $s8->fetch(PDO::FETCH_ASSOC);
             if ($rs) {
                 if ($has_context) {
                     $this->beginTransaction();
                     $s91 = $this->prepare("SELECT xid from qwp_post_index where postid=? and forumid=?");
                     $s91->bindParam(1, $postid, PDO::PARAM_INT);
                     $s91->bindParam(2, $forumid, PDO::PARAM_INT);
                     $s91->execute();
                     $xid = $s91->fetch(PDO::FETCH_ASSOC)['xid'];
                     $s7->bindParam(1, $has_context, PDO::PARAM_INT);
                     $s7->bindParam(2, $postid, PDO::PARAM_INT);
                     $s7->bindParam(3, $forumid, PDO::PARAM_INT);
                     $s7->execute();
                     $table = 'qwp_post_index';
                     $action = 2;
                     $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                     $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                     $sth61->bindParam(2, $table, PDO::PARAM_STR);
                     $sth61->bindParam(3, $action, PDO::PARAM_INT);
                     $sth61->execute();
                     $this->commit();
                 }
             } else {
                 $parent = $post->parent;
                 if (empty($parent)) {
                     $parent = -1;
                 }
                 $thread = $post->thread;
                 $s6->bindParam(1, $postid, PDO::PARAM_INT);
                 $s6->bindParam(2, $parent, PDO::PARAM_INT);
                 $s6->bindParam(3, $has_context, PDO::PARAM_INT);
                 $s6->bindParam(4, $forumid, PDO::PARAM_INT);
                 $s6->bindParam(5, $thread, PDO::PARAM_INT);
                 try {
                     $this->beginTransaction();
                     $s6->execute();
                     $xid = $this->lastInsertId();
                     $table = 'qwp_post_index';
                     $action = 1;
                     $sth61 = $this->prepare("INSERT into qwp_xfer (xid,`table`,`action`,`date`) VALUES(?,?,?,now())");
                     $sth61->bindParam(1, $xid, PDO::PARAM_INT);
                     $sth61->bindParam(2, $table, PDO::PARAM_STR);
                     $sth61->bindParam(3, $action, PDO::PARAM_INT);
                     $sth61->execute();
                     $this->commit();
                 } catch (Exception $x) {
                     $logService->log('ERROR HANDLED ', 'post index already present ', 'V3 body=' . $post->message . ';exception=' . fe($x), $forumid);
                 }
             }
             $children = 1;
             // includes myself as in ancestors of my parent that I bring, including myself.
             $parent = $post->parent;
             $id = $post->id;
             if ($parent > 0) {
                 //updating parents with new children count (need to study the cost of this in performance terms)
                 if (!$has_context) {
                     // for old, out of context posts only. Current posts are coming before the children.
                     // $logService->log('DBUG+++','START CHILDREN postid='.$post->id,'','');
                     $children += $this->processChildren($post->id, $forumid);
                     //  $logService->log('DBUG+++','END CHILDREN postid='.$post->id,'','');
                 }
                 // $logService->log('DEBUGC','insert into qwp_newposts'.$post->id,$post->message,'');
                 $s22 = $this->prepare("insert into qwp_newposts (postid,parent,children,forumid) values (?,?,?,?)");
                 $s22->bindParam(1, $id, PDO::PARAM_INT);
                 $s22->bindParam(2, $parent, PDO::PARAM_INT);
                 $s22->bindParam(3, $children, PDO::PARAM_INT);
                 $s22->bindParam(4, $forumid, PDO::PARAM_INT);
                 try {
                     $s22->execute();
                 } catch (Exception $x) {
                     $logService->log('ERROR HANDLED ', 'newpost ', 'V3 body=' . $post->message . ';exception=' . fe($x), $forumid);
                 }
             }
             //TO DO - check if the post belongs in any tabs/contexts based on sources. Dispatch NewPost tick as needed.
         }
     }
     return $ts;
     // the latest post processed
 }
コード例 #2
0
ファイル: layout.php プロジェクト: maslosoft/whitelist
		</div>
		<?php 
echo $this->renderMessages();
?>
		<?php 
$bind = Yii::app()->controller->id == 'page' && Yii::app()->controller->action->id == 'update';
?>
		<?php 
$hideBreadcrumbs = Yii::app()->controller->id == 'page' && Yii::app()->controller->action->id == 'view' && PageItem::model()->findByPk($_GET['id'])->url === '/';
?>
		<?php 
if (!$hideBreadcrumbs) {
    ?>
			<div class="layout">
				<?php 
    $this->widget(Breadcrumbs::class, array('homeLink' => [tx('Home page') => (string) Yii::app()->baseUrl . '/'], 'links' => $this->breadcrumbs, 'encodeLabel' => false, 'separator' => ' <i class="fa fa-angle-right"></i> '));
    ?>
			</div>
		<?php 
}
?>
		<div id="contentBg" class="layout">
			<div id="content" class="row">
				<?php 
echo $content;
?>
			</div>
		</div>
		<footer id="bottomBg" class="layout">
			<div>
				<div class="row">
コード例 #3
0
ファイル: SpriteInstaller.php プロジェクト: maslosoft/sprite
 public function install()
 {
     $sprite = new Generator();
     $sprite->generate();
     $this->installer->success(tx('Rebuild sprite', 'Maslosoft.Sprite.Installer'));
 }
コード例 #4
0
ファイル: gallery.php プロジェクト: maslosoft/gallery
"></a>
				<a href="#" class="maslosoft-gallery-t" rel="tooltip" data-html="true" data-placement="top" title="<?php 
echo txp('Tweet it', '<big>&rarr;</big>');
?>
"></a>

				<a href="#" class="maslosoft-gallery-in" rel="tooltip" data-html="true" data-placement="top" title="<?php 
echo txp('Post to LinkedIn', '<big>&rarr;</big>');
?>
"></a>
				<a href="#" class="maslosoft-gallery-plus" rel="tooltip" data-html="true" data-placement="top" title="<?php 
echo txp('Post too Google+', '<big>&rarr;</big>');
?>
"></a>


			</div>
<!--			<h1 style="margin: auto;
display: block;
z-index: 1000000;
position: absolute;
top: 50%;
left: 0px;
right: 0px;
font-size: 1400%;"><?php 
echo tx('Finish');
?>
</h1>-->
		</div>
	</div>
</div>