Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

31shab

By: a guest on Oct 11th, 2011  |  syntax: PHP  |  size: 2.69 KB  |  views: 75  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class p5xCronController extends p5xClassHolder {
  4.  
  5.     private $output;
  6.     private $url;
  7.     private $startTime = null;
  8.     private $endTime = null;
  9.  
  10.     public function init() {
  11.         parent::init();
  12.     }
  13.  
  14.     public function execute() {
  15.         parent::execute();
  16.         $this->_p->ctrl->noOutput = true;
  17.     }
  18.    
  19.     public function timerStart() {
  20.         $mtime = microtime ();
  21.         $mtime = explode (' ', $mtime);
  22.         $mtime = $mtime [1] + $mtime [0];
  23.         $this->startTime = $mtime;
  24.     }
  25.    
  26.     public function timerStop() {
  27.         $mtime = microtime ();
  28.         $mtime = explode (' ', $mtime);
  29.         $mtime = $mtime [1] + $mtime [0];
  30.         $this->endTime = $mtime;
  31.         $totaltime = round ( ($this->endTime - $this->startTime), 5 );
  32.         return $totaltime;
  33.     }
  34.    
  35.     public function reminderAction(){
  36.    
  37.         $this->_p->ctrl->noOutput = true;
  38.         $this->_p->ctrl->appendTime = true;
  39.        
  40.         $this->timerStart();
  41.        
  42.         $query = "SELECT u.`id`, u.`fullname`, u.`email`, u.`hash`, s.`timezone`
  43.                  FROM `users` u
  44.                  LEFT JOIN `reminders` rm ON rm.`user_id` = u.`id` AND rm.`date` = CURDATE()
  45.                  LEFT JOIN `settings` s ON s.`user_id` = u.`id`
  46.                  LEFT JOIN `posts` p ON p.`user_id` = u.`id` AND p.`date` = DATE(CONVERT_TZ(UTC_TIMESTAMP, 'UTC', s.`timezone`))
  47.                  WHERE HOUR(CONVERT_TZ(UTC_TIMESTAMP, 'UTC', s.`timezone`)) = s.`notify_hour`
  48.                  AND s.`notify` = 1 AND u.`active` = 1 AND rm.`id` IS NULL AND p.`id` IS NULL
  49.                  GROUP BY u.`id` LIMIT 0,200";
  50.                  
  51.         $users = $this->_p->db->getResult($query);
  52.         $time  = $this->timerStop();
  53.        
  54.         $i = 0;
  55.        
  56.         foreach($users as $k => $v){
  57.            
  58.             $this->_p->tpl->assign("user", $v);
  59.             $email   = $this->_p->tpl->fetch('emails/remindEmail.html');
  60.             $reply   = substr($v->hash, 0, 8) . '_' . date('Y-m-d') . '@' . $this->_p->conf->mail_domain;
  61.             $subject = "یادآوری نوشتن در ۳۱ شب - " . $this->_p->date->date("j F", false, true);
  62.             $hdrs    = array(
  63.                 'Reply-To' => $reply
  64.             );
  65.  
  66.             if( $this->_p->mailer->send($v->email, $subject, $email, $hdrs) ){
  67.                 $this->_p->db->execute("INSERT INTO `reminders` (`user_id`, `date`) VALUES(?,CURDATE())", $v->id);
  68.                 $i++;
  69.             }
  70.            
  71.         }
  72.        
  73.         echo "Email Reminder has been sent to " .$i. " People - $time Seconds";
  74.        
  75.     }
  76.    
  77.     public function display() {
  78.         return null;
  79.     }
  80.    
  81. }
  82.