Esempio n. 1
0
 /**
  * Get HTML template for email
  * NOTE: Email needs to be set in config/config.ini when using CLI
  * @param string $path path to template
  * @return string $html
  */
 public function getHtmlTemplate($path = null)
 {
     // Default path
     if (!$path) {
         $template = conf::getMainIni('template');
         $path = conf::getTemplatePath($template) . '/mail/template.html';
     }
     if (!file_exists($path)) {
         log::error('mailer/markdown: path does not exists: ' . $path);
         die;
     }
     $email = file_get_contents($path);
     return $email;
 }
 protected function uploadImage($url)
 {
     // Array ( [name] => Angus_cattle_18.jpg [type] => image/jpeg [tmp_name] => /tmp/php5lPQZT [error] => 0 [size] => 52162 )
     $ary = [];
     $name = file::getFilename($url) . "." . file::getExtension($url);
     $ary['name'] = $name;
     $ary['abstract'] = file::getFilename($url);
     $ary['type'] = file::getMime($url);
     $ary['tmp_name'] = $url;
     $ary['error'] = 0;
     $ary['size'] = 0;
     $i = new \modules\image\uploadBlob();
     $res = $i->insertFileDirect($ary, $this->reference, $this->parentId, $this->userId);
     if ($res) {
         $id = q::lastInsertId();
         $row = $i->getSingleFileInfo($id);
         return $i->getFullWebPath($row);
     } else {
         log::error("Could not upload image: {$name}");
         return false;
     }
 }
 /**
  * Images are stored in database. 
  * @param type $url
  * @return boolean
  */
 public function checkImage($url)
 {
     $id = direct::fragment(2, $url);
     $title = direct::fragment(3, $url);
     $path = "/images/{$id}/{$title}";
     $save_path = conf::getFullFilesPath($path);
     $web_path = conf::getWebFilesPath($path);
     $image_url = conf::getSchemeWithServerName() . $url;
     $code = headers::getReturnCode($image_url);
     if ($code != 200) {
         log::error("Could not get file content (image). Got: {$code} " . $image_url);
         return false;
     }
     return $url;
 }
Esempio n. 4
0
 function findPart($id, $type = 'text/plain')
 {
     $foundPart = null;
     foreach (new RecursiveIteratorIterator($this->mail->getMessage($id)) as $part) {
         try {
             if (strtok($part->contentType, ';') == $type) {
                 $foundPart = $part;
                 return $foundPart;
                 break;
             }
         } catch (Exception $e) {
             log::error($e->getMessage());
         }
     }
 }
 /**
  * Images are stored in database. 
  * @param type $url
  * @return boolean
  */
 public function saveImage($url)
 {
     $id = direct::fragment(2, $url);
     $title = direct::fragment(3, $url);
     $title = rawurlencode($title);
     $path = "/images/{$id}/{$title}";
     $save_path = conf::getFullFilesPath($path);
     $web_path = conf::getSchemeWithServerName() . conf::getWebFilesPath($path);
     $code = headers::getReturnCode($web_path);
     if ($code != '200') {
         log::error("Could not get file content (image). Got: {$code} " . $web_path . ' in ' . __CLASS__);
         return false;
     }
     return $save_path;
 }
Esempio n. 6
0
 public function deleteAll()
 {
     $connect = array('host' => conf::getMainIni('imap_host'), 'port' => conf::getMainIni('imap_port'), 'user' => conf::getMainIni('imap_user'), 'password' => conf::getMainIni('imap_password'), 'ssl' => conf::getMainIni('imap_ssl'));
     $i = new imap();
     $i->connect($connect);
     $c = $i->countMessages();
     log::error("Parse bounces. Num messages: {$c}\n");
     $i->mail->noop();
     // reverse - we start with latest message = $c
     for ($x = $c; $x >= 1; $x--) {
         log::error("Pasing num: {$x}");
         $i->mail->noop();
         // keep alive
         $i->mail->removeMessage($x);
         $i->mail->noop();
         // keep alive
         sleep(1);
     }
 }
Esempio n. 7
0
 /**
  * checks if if size is allowed
  * @param string $filename the name of the file
  * @param int $maxsize bytes
  * @return boolean $res
  */
 public static function checkMaxSize($file, $maxsize = null)
 {
     if (!$maxsize) {
         $maxsize = self::$options['maxsize'];
     }
     if ($file['size'] > $maxsize) {
         $error = lang::translate('File is too large.') . ' ';
         $error .= lang::translate('Max size is ') . ' ' . bytes::bytesToGreek($maxsize);
         log::error($error);
         self::$errors[] = $error;
         return false;
     }
     return true;
 }
Esempio n. 8
0
function dev_log($options = null)
{
    log::error('Hello world');
}
 /**
  * Checks broken media
  * @param type $url
  * @return boolean
  */
 protected function isImage($url)
 {
     $type = file::getExtension($url);
     if ($type == 'mp4') {
         log::error($url);
         return false;
     }
     return true;
 }
Esempio n. 10
0
 /**
  * Validates a csrf enabled form
  */
 public static function csrfValidate()
 {
     if (class_exists('\\Riimu\\Kit\\CSRF\\CSRFHandler')) {
         $csrf = new \Riimu\Kit\CSRF\CSRFHandler(false);
         try {
             $csrf->validateRequest(true);
         } catch (\Riimu\Kit\CSRF\InvalidCSRFTokenException $ex) {
             log::error($ex->getMessage());
             http::locationHeader('/error/accessdenied', 'Bad request');
             return false;
         }
     }
     return true;
 }
Esempio n. 11
0
 /**
  * Mail using smtp 
  * @param string $to
  * @param string $subject
  * @param string $text
  * @param string $html
  * @param array $attachments filenames
  * @return boolean
  */
 public static function mail($to, $subject, $text = null, $html = null, $attachments = array())
 {
     $mail = self::getPHPMailer();
     $mail->addAddress($to);
     $mail->Subject = $subject;
     if ($html) {
         $mail->isHTML(true);
         $mail->Body = $html;
         if ($text) {
             $mail->AltBody = $text;
         }
     } else {
         $mail->isHTML(false);
         $mail->Body = $text;
     }
     foreach ($attachments as $val) {
         $mail->addAttachment($val);
     }
     if (!$mail->send()) {
         self::$log = $mail->ErrorInfo;
         log::error(self::$log);
         return false;
     } else {
         return true;
     }
 }
 protected function saveImage($url)
 {
     $id = direct::fragment(2, $url);
     $title = direct::fragment(3, $url);
     $path = "/images/{$id}/{$title}";
     $save_path = conf::getFullFilesPath($path);
     $web_path = conf::getWebFilesPath($path);
     $image_url = conf::getSchemeWithServerName() . $url;
     $code = headers::getReturnCode($image_url);
     if ($code != 200) {
         log::error("Could not get file content (image). Got: {$code} " . $image_url);
         return '';
     } else {
         $file = file_get_contents($image_url);
     }
     // make dir
     $dir = dirname($path);
     file::mkdir($dir);
     file_put_contents($save_path, $file);
     return $web_path;
 }
Esempio n. 13
0
 /**
  * method for fetching rows which we created with our query
  * @return array $rows assoc array of rows
  */
 public static function fetch()
 {
     try {
         self::$debug[] = self::$query;
         self::init();
         self::$stmt = self::$dbh->prepare(self::$query);
         self::prepare();
         self::$stmt->execute();
         $rows = self::$stmt->fetchAll(PDO::FETCH_ASSOC);
         if (self::$method == 'select_one') {
             if (!empty($rows)) {
                 $rows = $rows[0];
             }
         }
         self::unsetVars();
     } catch (Exception $e) {
         $message = $e->getTraceAsString();
         log::error($message);
         $last = self::getLastDebug();
         log::error($last);
         die;
     }
     if (self::$method == 'num_rows') {
         return $rows[0]['num_rows'];
     }
     return $rows;
 }
Esempio n. 14
0
 /**
  * remove single file or array of files
  * @param string|array $files
  */
 public static function remove($files)
 {
     if (is_string($files)) {
         unlink($files);
     }
     if (is_array($files)) {
         foreach ($files as $val) {
             $res = unlink($val);
             if (!$res) {
                 log::error("Could not remove file: {$val}");
             }
         }
     }
 }