Example #1
0
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * 
  * @return array
  */
 protected function _getFields()
 {
     $strTableName = strtolower(get_class($this));
     $arrResult = App_Db::read("SHOW FIELDS FROM {$strTableName}")->fetchAll(PDO::FETCH_ASSOC);
     $arrField = [];
     foreach ($arrResult as $arrRow) {
         array_push($arrField, $arrRow['Field']);
     }
     return $arrField;
 }
Example #3
0
 public function image($request_name, $extensions, $size, $throw = false)
 {
     $file_source = isset($_FILES[$request_name]) ? $_FILES[$request_name] : null;
     if ($file_source == null) {
         return false;
     }
     list($width, $height, $type) = getimagesize($file_source['tmp_name']);
     if (isset($type) && !in_array($type, self::$image_types)) {
         return false;
     }
     $ext = explode(".", $file_source["name"]);
     $file_extension = strtolower(end($ext));
     if (in_array($file_extension, $extensions) == false) {
         return false;
     }
     if ($file_source['size'] > $size * 1024 * 1024) {
         return false;
     }
     $file_name = $this->getRandomName();
     $destination = self::UPLOADS_DIRECTORY . '/' . $file_name . '.' . $file_extension;
     move_uploaded_file($file_source['tmp_name'], $destination);
     if ($_GET['channel'] == self::CHANNEL_APP) {
         $compression_type = Imagick::COMPRESSION_JPEG;
         $thumbnail = new Imagick($destination);
         $thumbnail->setImageCompression($compression_type);
         $thumbnail->setImageCompressionQuality(75);
         $thumbnail->stripImage();
         $image_width = $thumbnail->getImageWidth();
         $width = min($image_width, 800);
         $thumbnail->thumbnailImage($width, null);
         App_Controller_Site_Images::delete($destination);
         $thumbnail->writeImage($destination);
     }
     $time = date('Y-m-d H:i:s');
     $ip = $_SERVER['REMOTE_ADDR'];
     $channel = self::CHANNEL_WEB;
     if (isset($_GET['channel']) && ($_GET['channel'] == self::CHANNEL_APP || $_GET['channel'] == self::CHANNEL_WEB)) {
         $channel = $_GET['channel'];
     }
     $query = "INSERT INTO `uploads` (`src`,`upload_time`,`token`,`ip`,`channel`) VALUES ('{$destination}','{$time}','{$file_name}','{$ip}','{$channel}')";
     App_Db::getInstance()->getConn()->query($query);
     return $file_name;
 }
Example #4
0
 public function indexAction()
 {
     $token = $_GET['file_token'];
     if (preg_match('/^([A-Z0-9a-z]{7})$/i', $token) == false) {
         App_Headers::redirect(array());
     }
     $query = "SELECT * FROM `uploads` WHERE `token` = '{$token}'";
     $result = App_Db::getInstance()->getConn()->query($query);
     $imageModel = $result->fetchObject();
     if (empty($imageModel) || !empty($imageModel) && $imageModel->is_deleted) {
         return null;
     }
     $time = date('Y-m-d H:i:s');
     $query = "UPDATE `uploads` SET `is_deleted` = '1',`time_open`='{$time}' WHERE id = '{$imageModel->id}'";
     $result = App_Db::getInstance()->getConn()->query($query);
     $imageData = base64_encode(file_get_contents($imageModel->src));
     $src = 'data: ' . $this->getMimeType($imageModel->src) . ';base64,' . $imageData;
     self::delete($imageModel->src);
     $this->_view->image_src = $src;
 }
Example #5
0
 public function __construct()
 {
     $this->_oDbAdapter = App_Db::getInstance()->getAdapter();
 }
Example #6
0
 public function patch()
 {
     App_Db::connect(include __DIR__ . '/../config/db.php');
     if (class_exists('Patch')) {
         (new Patch())->run();
     }
 }
Example #7
0
 public function getCount()
 {
     return App_Db::getInstance()->getConn()->query("SELECT COUNT(`id`) as `counter` FROM {$this->tableName}")->fetchObject()->counter;
 }
Example #8
0
 public function markMessageAllRead(User $objSender)
 {
     App_Db::write("UPDATE message SET unread=0 WHERE sender_id = :sender_id AND recipient_id = :recipient_id", [':recipient_id' => $this->getId(), ':sender_id' => $objSender->getId()]);
 }
Example #9
0
 public function __construct()
 {
     parent::connect();
     return $this;
 }
Example #10
0
 public function run()
 {
     App::debug(['Drop table user']);
     App_Db::write('DROP TABLE IF EXISTS `user`');
     App::debug(['Creating table user']);
     App_Db::write('CREATE TABLE `user` (
         `id` int(11) NOT NULL AUTO_INCREMENT,
         `login` varchar(50) NOT NULL DEFAULT \'\',
         `first_name` varchar(100) NOT NULL DEFAULT \'\',
         `last_name` varchar(100) NOT NULL DEFAULT \'\',
         `admin` TINYINT(1) NOT NULL DEFAULT 0,
         `ban` TINYINT(1) NOT NULL DEFAULT 0,
         `password` varchar(50) DEFAULT NULL,
         PRIMARY KEY (`id`)
     ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8');
     App::debug(["Add users"]);
     App_Db::write('INSERT INTO `user` VALUES 
         (
             1,
             "admin",
             "John",
             "Doe",
             1,
             0,
             "admin"
         ),
         (
             2,
             "james_g",
             "James",
             "Grisham",
             0,
             0,
             "john_g"
         ),
         (
             3,
             "robin_c",
             "Robin",
             "Cook",
             0,
             1,
             "robin_c"
         )');
     App::debug(['Drop table message']);
     App_Db::write('DROP TABLE IF EXISTS `message`');
     App::debug(['Creating table message']);
     App_Db::write('
         CREATE TABLE `message` (
             `id` int(11) NOT NULL AUTO_INCREMENT,
             `sender_id` int(11) NOT NULL,
             `recipient_id` int(11) NOT NULL,
             `unread` TINYINT(1) NOT NULL DEFAULT 1,
             `message` text NOT NULL,
             `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
             KEY `i_sender_id` (`sender_id`),
             KEY `i_recipient_id` (`recipient_id`),
             PRIMARY KEY (`id`)
         ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8');
     App::debug(["Add messages"]);
     App_Db::write('INSERT INTO `message` VALUES 
         (
             1,
             1,
             2,
             1,
             "Test message 1",
             CURRENT_TIMESTAMP
         ),
         (
             2,
             2,
             1,
             1,
             "Test message 2",
             CURRENT_TIMESTAMP
         ),
         (
             3,
             1,
             2,
             1,
             "Test message 3",
             CURRENT_TIMESTAMP
         )');
 }