Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class p5xCronController extends p5xClassHolder {
- private $output;
- private $url;
- private $startTime = null;
- private $endTime = null;
- public function init() {
- parent::init();
- }
- public function execute() {
- parent::execute();
- $this->_p->ctrl->noOutput = true;
- }
- public function timerStart() {
- $mtime = microtime ();
- $mtime = explode (' ', $mtime);
- $mtime = $mtime [1] + $mtime [0];
- $this->startTime = $mtime;
- }
- public function timerStop() {
- $mtime = microtime ();
- $mtime = explode (' ', $mtime);
- $mtime = $mtime [1] + $mtime [0];
- $this->endTime = $mtime;
- $totaltime = round ( ($this->endTime - $this->startTime), 5 );
- return $totaltime;
- }
- public function reminderAction(){
- $this->_p->ctrl->noOutput = true;
- $this->_p->ctrl->appendTime = true;
- $this->timerStart();
- $query = "SELECT u.`id`, u.`fullname`, u.`email`, u.`hash`, s.`timezone`
- FROM `users` u
- LEFT JOIN `reminders` rm ON rm.`user_id` = u.`id` AND rm.`date` = CURDATE()
- LEFT JOIN `settings` s ON s.`user_id` = u.`id`
- LEFT JOIN `posts` p ON p.`user_id` = u.`id` AND p.`date` = DATE(CONVERT_TZ(UTC_TIMESTAMP, 'UTC', s.`timezone`))
- WHERE HOUR(CONVERT_TZ(UTC_TIMESTAMP, 'UTC', s.`timezone`)) = s.`notify_hour`
- AND s.`notify` = 1 AND u.`active` = 1 AND rm.`id` IS NULL AND p.`id` IS NULL
- GROUP BY u.`id` LIMIT 0,200";
- $users = $this->_p->db->getResult($query);
- $time = $this->timerStop();
- $i = 0;
- foreach($users as $k => $v){
- $this->_p->tpl->assign("user", $v);
- $email = $this->_p->tpl->fetch('emails/remindEmail.html');
- $reply = substr($v->hash, 0, 8) . '_' . date('Y-m-d') . '@' . $this->_p->conf->mail_domain;
- $subject = "یادآوری نوشتن در ۳۱ شب - " . $this->_p->date->date("j F", false, true);
- $hdrs = array(
- 'Reply-To' => $reply
- );
- if( $this->_p->mailer->send($v->email, $subject, $email, $hdrs) ){
- $this->_p->db->execute("INSERT INTO `reminders` (`user_id`, `date`) VALUES(?,CURDATE())", $v->id);
- $i++;
- }
- }
- echo "Email Reminder has been sent to " .$i. " People - $time Seconds";
- }
- public function display() {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement