Location: PHPKode > projects > Slashster > slashster/cron/daily.php
#!/usr/local/bin/php
<?

# Slashster: Open Source Friend of a Friend Software
# Copyright 2004 Mark El-Wakil
# Contact: hide@address.com
# http://seventhcycle.net
#
# This file is part of Slashster.
#
# Slashster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Slashster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Slashster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   set_time_limit(0);

   require("cronpth.php");
   $mpage = new PageClass("sqlonly");


   if ($argv[1])
   {
       $tw = ($argv[2]) ? $argv[2] : "0";
       $debug = 1;
       eval($argv[1] . "($tw);");
       exit;
   }

   UOTD();

   Age();
   ModToday();
   FortuneCookie();

   MailSchedule(2);

function MailSchedule($v)
{
    global $mpage;

    $sql = "select count(Owner) as cnt, UserTable.* from PrivateMessage 
            left join UserTable on UserTable.Id = PrivateMessage.Owner
            where New=1 And MailOften = $v
            AND DateSent > DATE_SUB(NOW(), interval 1 day)
            group by Owner";

    $r = $mpage->DoQuery($sql,1);

    $rg = $mpage->PrintSnippit("Email-$v");
    $headers= "X-Mailer: PHP/" . phpversion() . "\r\n";

    foreach ($r as $s)
    {
         $tp = $rg;

         foreach ($s as $k => $v)
         {
             $tp = str_replace("#$k#", $v, $tp);
         }

         slashmail($s[Email], $mpage->sys[sitename]." Daily New Message Reminder", $tp, $headers,
                   $mpage->sys[sitename]." Bot <robot@".$mpage->sys[sitedomain]
                   . ">", "robot@".$mpage->sys[sitename]."");
    }
  
}  
   
       
function slashmail($to, $subject, $txt, $headers, $from, $retpath)
{  
   global $mpage;

   if ($mpage->sys[chretpath])
      $sendmail = "/usr/sbin/sendmail -t -f " . $mpage->sys[bounceadr];
   else
      $sendmail = "/usr/sbin/sendmail -t";   

   $fd = popen($sendmail, "w");
   fputs($fd, "Reply-To: <$retpath>\r\n");
   fputs($fd, "From: $from\r\n");
   fputs($fd, "To: $to\r\n");
   fputs($fd, "Subject: $subject\r\n");
   fputs($fd, $headers);
   fputs($fd, $txt . "\r\n");
   pclose($fd);
            
}   




function UOTD()
{
    global $mpage;

    $sql = "select userid from uotd where dt < NOW() order by Id desc limit 1";
    $uol = $mpage->DoQuery($sql);
    for ($x = 0; $x < sizeof($uol); $x++) $uol[$x] = $uol[$x][0];

    $sql = "select UserTable.* from uotd
            left join UserTable on UserTable.Id = userid
            where dt = NOW()";
    $uotd  = $mpage->DoQuery($sql,1);

    if (!sizeof($uotd))
    {
      $uol = (sizeof($uol)) ? $uol : array(0);

      $sql = "select * from UserTable where Id NOT IN (". join(",", $uol) .")
              AND Verified = 1
              order by rand() limit 1";

      $uotd = $mpage->DoQuery($sql,1);
      if (!sizeof($uotd)) return;
      $uotd = $uotd[0];

      $sql = "insert into uotd set dt = NOW(), userid = $uotd[Id]";
      $mpage->DoQuery($sql);
    }
    else $uotd = $uotd[0];

    $msg = $mpage->PrintSnippit("UOTD");
    $mpage->MailSchedule(1, $uotd[Id], $mpage->sys[sitename]. " User of the Day", $msg, 1, 1);

}



function Age()
{
   global $mpage;

   $sql = "update UserTable set Age = (YEAR(CURDATE())-YEAR(Birthday)) - (RIGHT(CURDATE(),5)<RIGHT(BirthDay,5))";
   $mpage->DoQuery($sql);
}

function FortuneCookie()
{
   global $mpage;

   $sql = "select count(*) from FortuneCookie";
   $r = $mpage->DoQuery($sql);
   $r = $r[0][0];

   $f = fopen("../html/snippits/CookieNum.txt", "w");
   fwrite($f, $r);
   fclose($f);
}
 

function ModToday()
{
   global $mpage;

   $sql = "update UserTable set ModToday = 10";
   $mpage->DoQuery($sql,1);

}

?>
Return current item: Slashster