コード例 #1
0
ファイル: log.php プロジェクト: vgalitsky/moze
 static function log($message, $logfile = 'core.log')
 {
     if (!is_string($message)) {
         $message = core_debug::dump($message, false);
     }
     $message = date('[m-d-Y H:i:s]:') . $message;
     $fpath = app::getConfig('dir/sd') . DS . self::LOG_DIR . DS . $logfile;
     core_fs::createDirIfNotExists(dirname($fpath));
     $fh = fopen($fpath, 'a+');
     fputs($fh, $message . "\n");
     fclose($fh);
     return $message;
 }
コード例 #2
0
ファイル: event.php プロジェクト: vgalitsky/git_trade
 public function emailGrab()
 {
     self::$grabtime = time();
     $inbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', '*****@*****.**', 'f.estelkontrol08');
     /* get all new emails. If set to 'ALL' instead
      * of 'NEW' retrieves all the emails, but can be
      * resource intensive, so the following variable,
      * $max_emails, puts the limit on the number of emails downloaded.
      *
      */
     $emails = imap_search($inbox, 'UNSEEN');
     /* useful only if the above search is set to 'ALL' */
     $max_emails = 100;
     /* if any emails found, iterate through each email */
     if ($emails) {
         $count = 1;
         /* put the newest emails on top */
         rsort($emails);
         /* for every email... */
         foreach ($emails as $email_number) {
             /* get information specific to this email */
             $overview = imap_fetch_overview($inbox, $email_number, 0);
             //core_debug::dump($overview);
             /* get mail structure */
             $structure = imap_fetchstructure($inbox, $email_number);
             //core_debug::dump($structure);
             $attachments = array();
             /* if any attachments found... */
             if (isset($structure->parts) && count($structure->parts)) {
                 for ($i = 0; $i < count($structure->parts); $i++) {
                     $bodyText = imap_fetchbody($inbox, $email_number, 1.2);
                     if (!strlen($bodyText) > 0) {
                         $bodyText = imap_fetchbody($inbox, $email_number, 1);
                     }
                     $hinfo = imap_headerinfo($inbox, $email_number);
                     //core_debug::dump($hinfo);
                     $subject = $hinfo->subject;
                     $attachments[$i] = array('email_number' => $email_number, 'is_attachment' => false, 'date' => $hinfo->date, 'filename' => '', 'name' => '', 'attachment' => '', 'subject' => $subject, 'csv' => $bodyText, 'csv_orig' => $bodyText);
                     if ($structure->parts[$i]->ifdparameters) {
                         foreach ($structure->parts[$i]->dparameters as $object) {
                             if (strtolower($object->attribute) == 'filename') {
                                 $attachments[$i]['is_attachment'] = true;
                                 $attachments[$i]['filename'] = $object->value;
                             }
                         }
                     }
                     if ($structure->parts[$i]->ifparameters) {
                         foreach ($structure->parts[$i]->parameters as $object) {
                             if (strtolower($object->attribute) == 'name') {
                                 $attachments[$i]['is_attachment'] = true;
                                 $attachments[$i]['name'] = $object->value;
                             }
                         }
                     }
                     if ($attachments[$i]['is_attachment']) {
                         $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i + 1);
                         //$attachments[$i]['csv'] = imap_fetchbody($inbox, $email_number, $i);
                         /* 3 = BASE64 encoding */
                         if ($structure->parts[$i]->encoding == 3) {
                             $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
                             $attachments[$i]['subject'] = base64_decode($attachments[$i]['subject']);
                             $attachments[$i]['csv'] = base64_decode($attachments[$i]['csv']);
                         } elseif ($structure->parts[$i]->encoding == 4) {
                             $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
                             $attachments[$i]['subject'] = quoted_printable_decode($attachments[$i]['subject']);
                             $attachments[$i]['csv'] = quoted_printable_decode($attachments[$i]['csv']);
                         }
                     }
                 }
             }
             /* iterate through each attachment and save it */
             foreach ($attachments as $attachment) {
                 if ($attachment['is_attachment'] == 1) {
                     $attachment['date'] = date('d.m.Y H:i:s', strtotime($attachment['date']));
                     echo nl2br(core_log::log("START: Processing email [{$attachment['email_number']}]: {$attachment['subject']} ({$attachment['date']})", self::$grabtime . '.event.imap.log'));
                     $filename = $attachment['name'];
                     if (empty($filename)) {
                         $filename = $attachment['filename'];
                     }
                     if (empty($filename)) {
                         $filename = time() . ".dat";
                     }
                     /* prefix the email number to the filename in case two emails
                      * have the attachment with the same file name.
                      */
                     try {
                         $rpath = "event" . DS . "img" . DS . uniqid(time() . '-') . "-" . $filename;
                         $path = app::getConfig("dir/sd") . $rpath;
                         core_fs::createDirIfNotExists(dirname($path));
                         $fp = fopen($path, "w+");
                         fwrite($fp, $attachment['attachment']);
                         fclose($fp);
                         $attachment['full_filename'] = $rpath;
                         $event = $this->_email2event($attachment);
                         echo nl2br(core_log::log("DONE: ID={$event->getId()} ({$path})", self::$grabtime . '.event.imap.log'));
                     } catch (Exception $e) {
                         $a = $attachment;
                         unset($a['attachment']);
                         $data = core_debug::dump($a, false);
                         echo nl2br(core_log::log("ERROR: {$e->getMessage()} ", self::$grabtime . '.event.imap.log'));
                         echo nl2br(core_log::log("DATA: {$data}", self::$grabtime . '.event.imap.log'));
                     }
                 }
             }
             if ($count++ >= $max_emails) {
                 break;
             }
         }
     }
     imap_close($inbox);
 }
コード例 #3
0
ファイル: api.php プロジェクト: vgalitsky/git_trade
 public function addTradePointAction()
 {
     try {
         $tpData = array('name' => $this->getRequest()->getParam('spn'), 'address' => $this->getRequest()->getParam('adr'), 'long' => $this->getRequest()->getParam('long'), 'lat' => $this->getRequest()->getParam('lat'), 'contact_person ' => $this->getRequest()->getParam('con'), 'phone' => $this->getRequest()->getParam('tel'), 'personal_count' => $this->getRequest()->getParam('per'), 'rate' => $this->getRequest()->getParam('ppr'), 'web' => $this->getRequest()->getParam('web'), 'email' => $this->getRequest()->getParam('eml'), 'info' => $this->getRequest()->getParam('inf'), 'is_light_box' => $this->getRequest()->getParam('ilb'), 'is_panel' => $this->getRequest()->getParam('ipl'), 'shelf' => $this->getRequest()->getParam('slf'), 'competitor_id' => $this->getRequest()->getParam('competitor_id'));
         $img_64 = $this->getRequest()->getParam('img');
         $uniqid = uniqid('tp');
         $file_path = app::getConfig("dir/sd") . 'tp' . DS . 'img' . DS . date('Y') . DS . date('m') . DS . date('d') . DS . $uniqid . '.jpg';
         $file_url = 'sd' . DS . 'tp' . DS . 'img' . DS . date('Y') . DS . date('m') . DS . date('d') . DS . $uniqid . '.jpg';
         core_fs::createDirIfNotExists(dirname($file_path));
         $this->_saveRequestImage($file_path, $img_64);
         $tpData['image'] = $file_url;
         $trade_point = new manage_model_tradepoint();
         $trade_point->setData($tpData);
         $trade_point->save();
         core_log::log($trade_point->getData(), 'tp/' . date('d-m-Y') . 'trade_points.added.log');
         $request = $_REQUEST;
         unset($request['img']);
         $request['img'] = $file_path;
         core_log::log($request, 'tp/' . date('d-m-Y') . 'trade_point.request.log');
         $this->_xhrOk();
     } catch (Exception $e) {
         $request = $_REQUEST;
         unset($request['img']);
         $request['img'] = $file_path;
         core_log::logException($e);
         core_log::log($request, 'tp/' . date('d-m-Y') . 'trade_point.request.log');
         core_log::log($e->getMessage(), 'tp/' . date('d-m-Y') . 'trade_point.error.log');
         $this->_xhrErr('err: see exception log');
     }
 }