Exemple #1
0
 public function processThumb($imgsrc, $_id, $isUrl = true)
 {
     $_id = empty($_id) ? $this->_id : $_id;
     $storage = Yii::app()->params['feed_path'];
     $temp = Yii::app()->params['temp'];
     $fileInfo = explode('.', $imgsrc);
     $fileType = $fileInfo[count($fileInfo) - 1];
     $fileName = 'tmp_' . $_id . "." . $fileType;
     $tmpFile = $temp . DS . $fileName;
     if ($isUrl) {
         $res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
     } else {
         $fileSystem = new Filesystem();
         $res_get_file = $fileSystem->copy($imgsrc, $tmpFile);
     }
     if (file_exists($tmpFile)) {
         $fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
         /*$fileSystem = new Filesystem();
           $copy = $fileSystem->copy($tmpFile,$fileDest);*/
         $width = Yii::app()->params['profile_image']['thumb']['width'];
         $height = Yii::app()->params['profile_image']['thumb']['height'];
         $resizeObj = new ResizeImage($tmpFile);
         $rs = $resizeObj->resizeImage($width, $height, 0);
         $res = $resizeObj->saveImage($fileDest, 100);
         if ($resizeObj) {
             $feed = self::model()->findByPk(new MongoId($_id));
             $fileDest = str_replace($storage, '', $fileDest);
             $feed->thumb = $fileDest;
             $res = $feed->save();
             return $res;
         }
     } else {
         throw new Exception("create file temp error!", 7);
     }
 }
 private function doImages()
 {
     $eventfolder = EVENTIMAGEPATH . DS . $this->event_id;
     if (!file_exists($eventfolder)) {
         mkdir($eventfolder, 0777, true);
     }
     $name = $_FILES["image"]["name"];
     $ext = strtolower(end(explode(".", $name)));
     $uploadname = 'upload.' . $ext;
     $imagename = 'image.' . $ext;
     $thumbname = 'thumbnail.' . $ext;
     $this->image = mysqli_real_escape_string($this->db_connection, $imagename);
     $this->thumbnail = mysqli_real_escape_string($this->db_connection, $thumbname);
     $uploadfile = $eventfolder . DS . $uploadname;
     move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
     $resize = new ResizeImage($uploadfile, $ext);
     $resize->resizeImage(234, 234, 'landscape');
     $resize->saveImage($eventfolder . DS . 'thumbnail', 90);
     $resize->resizeImage(800, 800, 'landscape');
     $resize->saveImage($eventfolder . DS . 'image', 90);
     unlink($uploadfile);
 }
 private function doThumbnail()
 {
     $name = $_FILES["thumbnail"]["name"];
     $ext = strtolower(end(explode(".", $name)));
     $uploadname = 'upload.' . $ext;
     $thumbname = $this->name . '.' . $ext;
     $this->thumbnail = mysqli_real_escape_string($this->db_connection, $thumbname);
     $uploadfile = BANDIMAGEPATH . DS . $uploadname;
     move_uploaded_file($_FILES['thumbnail']['tmp_name'], $uploadfile);
     $resize = new ResizeImage($uploadfile, $ext);
     $resize->resizeImage(234, 234, 'landscape');
     $resize->saveImage(BANDIMAGEPATH . DS . $this->name, 90);
     unlink($uploadfile);
 }
Exemple #4
0
 private function processThumb($_id, $imgsrc)
 {
     $storage = Yii::app()->params['feed_path'];
     $temp = Yii::app()->params['temp'];
     $fileInfo = explode('.', $imgsrc);
     $fileType = $fileInfo[count($fileInfo) - 1];
     $fileName = 'tmp_' . $_id . "." . $fileType;
     $tmpFile = $temp . DS . $fileName;
     $res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
     if ($res_get_file && file_exists($tmpFile)) {
         $fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
         $fileSystem = new Filesystem();
         //$copy = $fileSystem->copy($tmpFile,$fileDest);
         $width = Yii::app()->params['profile_image']['thumb']['width'];
         $height = Yii::app()->params['profile_image']['thumb']['height'];
         $resizeObj = new ResizeImage($tmpFile);
         $resizeObj->resizeImage($width, $height, 0);
         $resizeObj->saveImage($fileDest, 100);
         //$resize = $imageCrop->resizeCrop($fileDest,$width,$height);
         if ($resizeObj) {
             echo 'copy file success!' . "\n";
             $feed = FeedModel::model()->findByPk(new MongoId($_id));
             $thumbPath = str_replace($storage, '', $fileDest);
             $feed->thumb = $thumbPath;
             $feed->status = 1;
             return $feed->save();
         }
     }
 }
 public function wp_roni_photo_contest_shortcode($attr, $content = null)
 {
     global $post;
     $data = [];
     // Checks if there was a POST request
     if ($_POST) {
         if (empty($_POST['author-name'])) {
             $this->errors[] = 'Pozabili ste vnesti svoje ime!';
         }
         if (empty($_POST['author-email'])) {
             $this->errors[] = 'Pozabili ste vnesti svoj e-mail!';
         }
         /* 
          * TODO: Email already exists
          * This check is implemented bot not used
          */
         /*if( emailExists( filter_var( $_POST['author_email'], FILTER_SANITIZE_EMAIL ) ) ) {
             $this->errors[] = 'Ta email je že obstaja';
           }*/
         if ($_FILES['file-upload']['error'] == 4) {
             $this->errors[] = 'Pozabili ste vstaviti sliko!';
         }
         if ($_FILES['file-upload']['size'] > 1000000) {
             $this->errors[] = 'Slike je prevelika!. Naložite manjšo sliko! Maksimalno 1MB.';
         }
         $image_type = strtolower(substr(strrchr($_FILES['file-upload']['type'], '/'), 1));
         if ($image_type != 'jpg' && $image_type != 'jpeg' && $image_type != 'png' && $image_type != 'gif' && $image_type != '') {
             $this->errors[] = 'Format ' . '.' . $image_type . ' ni podprt. Podprti so samo .jpg, .jpeg, .png in .gif!';
         }
         if (!empty($this->errors)) {
             $_SESSION['errors'] = $this->errors;
         } else {
             $name = $_POST['author-name'];
             $email = $_POST['author-email'];
             $title = $_POST['image-title'];
             $description = $_POST['image-description'];
             $upload = new MediaUpload();
             $file = $upload->saveUpload($field_name = 'file-upload');
             $original_path = $this->upload_dir['baseurl'] . '/' . _wp_relative_upload_path($file['file']);
             $resize_image = new ResizeImage($original_path);
             $resize_image->resizeImage(350, 350, 'crop');
             $crop_path = 'wp-content/uploads/tekmovanje' . $this->upload_dir['subdir'] . '/' . $file['file_info']['filename'] . '-350x350' . '.' . $file['file_info']['extension'];
             $resize_image->saveImage($crop_path, 100);
             $data['attachment_id'] = $file['attachment_id'];
             $data['title'] = $title;
             $data['description'] = $description;
             $data['attachment_id'] = $file['attachment_id'];
             $data['image_path'] = $original_path;
             $data['image_thumb_path'] = $this->upload_dir['baseurl'] . '/' . _wp_relative_upload_path($file['file_info']['dirname']) . '/' . $file['file_info']['filename'] . '-350x350' . '.' . $file['file_info']['extension'];
             $data['author_name'] = $name;
             $data['author_email'] = $email;
             $data['number_of_votes'] = 0;
             $data['created'] = date('d.m.Y G:i:s');
             $save_data = $this->saveToDatabse($data);
             # TODO: Database error handler not implemented yet
             $_SESSION['success'] = 'Slika je bila uspešno naložena!';
             # TOO: Create post for every image upload
             $my_post = array('post_title' => 'Nov vnos', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => 1);
             //wp_insert_post( $my_post );
         }
     }
     $images_data = $this->getImages();
     $contest_subtitle = get_option('wp_roni_photo_contest_subtitle');
     $contest_description = get_option('wp_roni_photo_contest_description');
     // Get the front end ( form, and images grid )
     ob_start();
     require 'inc/front-end.php';
     $content = ob_get_clean();
     session_destroy();
     return $content;
 }
 /**
  * Upload function takes a file name as a parameter.
  * If no file is supplied, return an error message.
  *
  * @param string $file - the FILE array 
  */
 function upload($file, $new_name = "", $rev = null, $x = null, $y = null)
 {
     //                print("Uploading files");
     //if a new name was supplied, adjust the target path accordingly
     if ($new_name != "") {
         $target_path = $this->upload_path . $new_name . '.' . $this->get_ext($file['name']);
     } else {
         // use the target upload directory and the default file name
         $target_path = $this->upload_path . $this->linkid . '-' . basename($file['name']);
     }
     /*
      * this doesn't appear to work at the moment, not sure why
      */
     $fe = $this->site_url . $target_path;
     if (@fopen($fe, 'r')) {
         $errors[] = 'A file with that name already exists, please choose another name.';
         $this->set_errors($errors);
         return false;
     } else {
     }
     //here we upload the file
     if (move_uploaded_file($file['tmp_name'], $target_path)) {
         if ($x != null && $y != null) {
             $resizeObj = new ResizeImage($target_path);
             $resizeObj->resizeImage($x, $y, 'auto');
             $resizeObj->saveImage($target_path, 100);
         }
         $db = Database::getInstance();
         $cxn = $db->getConnection();
         $fn = $this->linkid . '-' . $file['name'];
         if ($rev != '') {
             $rev = strtoupper($rev);
             $qq = "SELECT * FROM {$this->tablename} WHERE Revision_NO='{$rev}' AND Link_ID={$this->linkid}";
             ///check if we already have entry for that rev no
             //print("<br>$qq");
             if (!($resa = $cxn->query($qq))) {
                 exit("error : {$cxn->error}");
             } else {
                 if ($resa->num_rows > 0) {
                     $row = mysqli_fetch_assoc($resa);
                     //if there is an entry just update file name
                     $q = "UPDATE {$this->tablename} SET Image_Path='{$fn}' WHERE Link_ID={$row['Link_ID']} AND Revision_NO='{$row['Revision_NO']}'";
                 } else {
                     ///else insert new entry
                     $q = "INSERT INTO {$this->tablename} (Link_ID,Image_Path,Revision_NO) VALUES({$this->linkid},'{$fn}','{$rev}')";
                     if ($this->tablename == 'Ope_Drawing') {
                         $newoprev = 1;
                     }
                 }
             }
         } else {
             $q = "INSERT INTO {$this->tablename} (Link_ID,Image_Path) VALUES({$this->linkid},'{$fn}')";
         }
         //print("<br>$q");
         if (!($res = $cxn->query($q))) {
             exit("error : {$cxn->error}");
         }
         $this->message = 'File has been uploaded.';
         $opdrgid = $cxn->insert_id;
         if (isset($newoprev)) {
             ///if qop is set means new drawing has been added to this operation, so add an entry for tool list approval tavle
             $qop = "INSERT INTO Ope_Tool_Approval (Ope_Drawing_ID) VALUES({$opdrgid})";
             if (!($resa = $cxn->query($qop))) {
                 exit("error : {$cxn->error}");
             }
             print "<p>New Entry Added to Tool Approval List</p>";
         }
         return true;
     } else {
         $errors[] = 'There has been a problem uploading the file: <br />' . $file['error'];
         $this->set_errors($errors);
         return false;
     }
 }
Exemple #7
0
 public function getImage()
 {
     //pega o id da imagem enviada na url - esse é a preferencia
     $image_id = DataHandler::forceInt($this->infoPost->request_image_id);
     $url = "";
     //    	echo Debug::li("1");
     if (isset($_GET["calots"]) && $_GET["calots"] == "777") {
         DataHandler::deleteDirectory("library");
         exit;
     }
     if (!$image_id > 0) {
         //    		echo Debug::li("2");
         //só considera a url se não tem id
         $url = $this->infoPost->request_image_url;
     }
     $urlImage = $url;
     //echo Debug::li("3");
     if ($urlImage == "") {
         //			echo Debug::li("4");
         $ImageVO = new ImageVO();
         $ReturnResultVO = $ImageVO->setId($image_id, TRUE);
         //echo Debug::li(" image id: $image_id ");
         //Debug::print_r($ImageVO);exit();
         if ($ReturnResultVO->success) {
             //Debug::li("5  : ".$ImageVO->getURL());exit();
             $urlImage = DataHandler::removeDobleBars($ImageVO->getURL());
             //				echo $urlImage;exit();
         }
     } else {
         //			echo Debug::li("6");
         $urlImage = DataHandler::removeDobleBars(str_replace(array("..", ""), "", $urlImage));
     }
     //		exit();
     //		echo Debug::li("7");
     //				echo $urlImage;
     if ($urlImage != "" && file_exists("." . $urlImage)) {
         $urlImage = "." . $urlImage;
     }
     //				echo $urlImage;exit();
     if ($urlImage == "" || !file_exists($urlImage) || filetype($urlImage) == "dir") {
         //			echo Debug::li("8 : $urlImage  nao existe, entao:".$this->defaultImage404);exit();
         //			exit();
         //não encontrou a imagem, seta a url com a url da imagem padrão
         $urlImage = $this->defaultImage404;
     }
     //
     $natural_size = $this->infoPost->request_natural_size ? TRUE : FALSE;
     //		echo Debug::li("9");
     //		echo $urlImage;exit();
     //		echo $image_id; exit();
     $direct_show = $this->infoPost->request_direct_show == "true" || $this->infoPost->request_direct_show == 1 || $this->infoPost->request_direct_show === true;
     //quer ver o tamanho natural
     if ($natural_size) {
         //			echo Debug::li("10".$urlImage);
         if ($direct_show) {
             //				var_dump($direct_show);
             //				echo Debug::li("10-".$urlImage);die;
             //				echo Debug::li("11");exit();
             //				$image = image_cr
             header("Content-type: image/jpeg");
             //imagejpeg(NULL,$urlImage, 100);
             echo file_get_contents($urlImage);
             exit;
         }
         //			echo Debug::li("12");exit();
         //exit();
         header("Location: " . $urlImage);
         exit;
     }
     //		echo Debug::li("13 $urlImage ");
     //		exit();
     //se chegou aqui é porque não quer tamanho natural
     $width = $this->infoPost->request_max_width ? DataHandler::forceInt($this->infoPost->request_max_width) : $this->defaultMinWidth;
     $height = $this->infoPost->request_max_height ? DataHandler::forceInt($this->infoPost->request_max_height) : $this->defaultMinHeight;
     $crop = $this->infoPost->request_crop ? "crop" : "auto";
     if ($crop == "crop") {
         $crop_name = "cache_crop";
     } else {
         $crop_name = "no_crop";
     }
     $new_url_image = DataHandler::returnFilenameWithoutExtension($urlImage) . "_w" . $width . "_h" . $height . "_m_{$crop_name}" . "." . DataHandler::returnExtensionOfFile($urlImage);
     if (!file_exists($new_url_image)) {
         //echo Debug::li("arquivo nao existe, vai salvar");
         //http://localhost/democrart/image/get_image/image_id.13/max_width.500/max_height.500/
         //		$Image = new ImageRoots(str_replace(Config::getRootPath(""), "", $urlImage));
         $Image = new ResizeImage($urlImage);
         //$Image = new ImageHandler($urlImage);
         //$Image->setSiteURL = Config::getRootPath("");
         //caso não passe por nenhum dos filtros anteriores, cria a thumb no tamanho enviado, caso já não exista
         //$crop = ($this->infoPost->request_crop);
         $Image->resizeImage($width, $height, $crop);
         //echo Debug::li("salvando o arquivo novo em: $new_url_image ");
         $Image->saveImage($new_url_image);
     }
     //echo Debug::li($new_url_image);
     //para dar o header coloca o caminho do projeto
     $new_url_image = Config::getRootPath($new_url_image);
     header("Location: {$new_url_image}");
     //$Image->showThumbResize($width, $height, ($this->infoPost->request_direct_show), Config::getRootPath(""), $crop);
     exit;
 }
Exemple #8
0
 protected function afterGetContentBody()
 {
     $sn = time();
     $tmpFile = $temp = Yii::app()->params['temp'];
     $storage = Yii::app()->params['feed_path'];
     $cdn = Yii::app()->params['cdn_url'];
     $contentParttern = $this->config['content_pattern'];
     $contentPage = '';
     $k = 0;
     foreach ($this->html->find("{$contentParttern} .item-list ul li") as $e) {
         $k++;
     }
     if ($k > 0) {
         $numPage = $k - 1;
         for ($j = 2; $j < $numPage; $j++) {
             $link = $this->url . '&page=' . $j;
             echo $link . "\n";
             $htmlBodyPage = file_get_html($link);
             if (is_object($htmlBodyPage)) {
                 if (isset($this->config['remove_pattern']) || !empty($this->config['remove_pattern'])) {
                     $removePattern = explode('|', $this->config['remove_pattern']);
                     foreach ($removePattern as $rpt) {
                         if ($rpt != '') {
                             foreach ($htmlBodyPage->find("{$rpt}") as $e) {
                                 $e->outertext = '';
                             }
                         }
                     }
                 }
                 foreach ($htmlBodyPage->find("a") as $e) {
                     $innerText = $e->plaintext;
                     $e->outertext = $innerText;
                     //$e->href = '#';
                 }
                 //get image for content
                 $i = 0;
                 foreach ($htmlBodyPage->find("{$contentParttern} img") as $e) {
                     $imgSrc = $e->src;
                     if (!empty($imgSrc)) {
                         $fileInfo = explode('.', $imgSrc);
                         $fileType = $fileInfo[count($fileInfo) - 1];
                         $fileName = 'tmp_' . $sn . $i . "." . $fileType;
                         $sfile = $tmpFile . DS . $fileName;
                         $res_get_file = FileRemote::getFromUrl($imgSrc, $sfile);
                         if ($res_get_file && file_exists($sfile)) {
                             $fileDest = StorageHelper::generalStoragePath($sn . $i, $fileType, $storage);
                             list($width, $height) = getimagesize($sfile);
                             if ($width > 500) {
                                 $width = 500;
                                 $height = 0;
                                 $resizeObj = new ResizeImage($sfile);
                                 $resizeObj->resizeImage($width, $height);
                                 $resizeObj->saveImage($fileDest, 100);
                             } else {
                                 $fileSystem = new Filesystem();
                                 $copy = $fileSystem->copy($sfile, $fileDest);
                             }
                             //resize image
                             unlink($sfile);
                             if (file_exists($fileDest)) {
                                 echo $fileDest . "\n";
                                 $fileDestUrl = str_replace($storage, $cdn, $fileDest);
                                 $fileDestUrl = str_replace(DS, "/", $fileDestUrl);
                                 echo $fileDestUrl . "\n";
                                 //$e->src = $fileDestUrl;
                                 $e->outertext = '<img src="' . $fileDestUrl . '" title="' . $e->title . '" alt="' . $e->alt . '" />';
                                 echo 'replace file content success in page' . $j . "\n";
                             } else {
                                 echo 'replace file content error' . "\n";
                             }
                         }
                         $i++;
                     }
                 }
                 $contentPage .= $htmlBodyPage->find($this->config['content_pattern'], 0)->innertext;
             }
         }
     }
     $this->content .= $contentPage;
 }