Exemple #1
1
 /**
  * Create thumbnail for image in specified size
  * @param $objImage
  * @param $intNewWidth
  * @param $intNewHeight
  * @param $intType
  */
 protected function createThumb($objImage, $intNewWidth, $intNewHeight, $intType)
 {
     // Verify that the size doesn't already exist in the db (usually the original which
     // we don't want to overwrite)
     $objImageThumbnail = Images::LoadByRowidSize($objImage->id, $intType);
     if (!is_null($objImageThumbnail)) {
         return;
     }
     //Get our original file from Lightspeed
     $strOriginalFile = $objImage->image_path;
     $strTempThumbnail = Images::GetImageName($strOriginalFile, $intNewWidth, $intNewHeight, 'temp');
     $strNewThumbnail = Images::GetImageName($strOriginalFile, $intNewWidth, $intNewHeight);
     $strOriginalFileWithPath = Images::GetImagePath($strOriginalFile);
     $strTempThumbnailWithPath = Images::GetImagePath($strTempThumbnail);
     $strNewThumbnailWithPath = Images::GetImagePath($strNewThumbnail);
     $image = Yii::app()->image->load($strOriginalFileWithPath);
     $quality = _xls_get_conf('IMAGE_QUALITY', '75');
     $sharpness = _xls_get_conf('IMAGE_SHARPEN', '20');
     if ($sharpness != 0) {
         $image->resize($intNewWidth, $intNewHeight)->quality($quality)->sharpen($sharpness);
     } else {
         $image->resize($intNewWidth, $intNewHeight)->quality($quality);
     }
     if (Images::IsWritablePath($strNewThumbnail)) {
         if (_xls_get_conf('IMAGE_FORMAT', 'jpg') == 'jpg') {
             $strSaveFunc = 'imagejpeg';
             $strLoadFunc = "imagecreatefromjpeg";
         } else {
             $strSaveFunc = 'imagepng';
             $strLoadFunc = "imagecreatefrompng";
         }
         $image->save($strNewThumbnailWithPath);
         //just save normally with no special effects
         //See if we have a thumbnail record in our Images table, create or update
         $objThumbImage = Images::model()->findByAttributes(array('width' => $intNewWidth, 'height' => $intNewHeight, 'index' => $objImage->index, 'parent' => $objImage->id, 'product_id' => $objImage->product_id));
         if (!$objThumbImage instanceof Images) {
             $objThumbImage = new Images();
             Images::model()->deleteAllByAttributes(array('width' => $intNewWidth, 'height' => $intNewHeight, 'parent' => $objImage->id));
             //sanity check to prevent SQL UNIQUE errors
         }
         $objThumbImage->image_path = $strNewThumbnail;
         $objThumbImage->width = $intNewWidth;
         $objThumbImage->height = $intNewHeight;
         $objThumbImage->parent = $objImage->id;
         $objThumbImage->index = $objImage->index;
         $objThumbImage->product_id = $objImage->product_id;
         $objThumbImage->save();
     } else {
         Yii::log("Directory permissions error writing " . $strNewThumbnail, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
 }
 public function run($class_name)
 {
     $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
     $class_name = ucfirst($class_name);
     if ($path && is_dir($path) && is_writable($path)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $pk = pathinfo($filename, PATHINFO_FILENAME);
         $image = Images::model()->findByPk($pk);
         if ($image != null) {
             $image->resize($dir);
         }
     } elseif (class_exists($class_name)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $size = explode('x', $dir);
         $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
         if (YII_DEBUG && !file_exists($path . DIRECTORY_SEPARATOR . $dir)) {
             mkdir($path . DIRECTORY_SEPARATOR . $dir, 0777);
         }
         if ($path !== FALSE && file_exists($path . DIRECTORY_SEPARATOR . $dir) && is_file($path . DIRECTORY_SEPARATOR . $filename) && $size[0] > 0 && $size[1] > 0) {
             Yii::import('ext.iwi.Iwi');
             $image = new Iwi($path . DIRECTORY_SEPARATOR . $filename);
             $image->adaptive($size[0], $size[1]);
             $image->save($path . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $filename, 0644, TRUE);
             $mime = CFileHelper::getMimeType($path . DIRECTORY_SEPARATOR . $filename);
             header('Content-Type: ' . $mime);
             $image->render();
             exit;
         }
     }
     return parent::run($class_name);
 }
 public function run()
 {
     if (!$this->images) {
         $sql = 'SELECT id, file_name, comment, id_object, file_name_modified, is_main FROM {{images}} WHERE id_object=:id ORDER BY sorter';
         $this->images = Images::model()->findAllBySql($sql, array(':id' => $this->objectId));
     }
     $this->render('widgetAdminViewImages', array('images' => $this->images));
 }
 public function loadModel($id)
 {
     $model = Images::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
Exemple #5
0
 public static function getImage($imageOfId, $entityId)
 {
     $model = Images::model()->find('image_of_id=:imageOfId AND entity_id=:entityId', array(':imageOfId' => $imageOfId, ':entityId' => $entityId));
     if ($model) {
         return $model->filename;
     } else {
         return false;
     }
 }
Exemple #6
0
 public function actionIndex()
 {
     $this->pageTitle = $this->dataSystem->title;
     // Dang ky Internet
     $criInternet = new CDBCriteria();
     $criInternet->addCondition("category_news_id = 1");
     $criInternet->order = "id DESC";
     $criInternet->limit = 3;
     $arrInternet = News::model()->findAll($criInternet);
     //Dang ky cap quang
     $criOptical = new CDBCriteria();
     $criOptical->addCondition("category_news_id = 2");
     $criOptical->order = "id DESC";
     $criOptical->limit = 3;
     $arrOptical = News::model()->findAll($criOptical);
     //Store
     $criStore = new CDBCriteria();
     $criStore->addCondition("category_news_id = 6");
     $criStore->order = "id DESC";
     $criStore->limit = 3;
     $arrStore = News::model()->findAll($criStore);
     //CA
     $criCa = new CDBCriteria();
     $criCa->addCondition("category_news_id = 3");
     $criCa->order = "id DESC";
     $criCa->limit = 3;
     $arrCa = News::model()->findAll($criCa);
     //Sim - Card
     $criSimCard = new CDBCriteria();
     $criSimCard->addCondition("category_news_id = 4");
     $criSimCard->order = "id DESC";
     $criSimCard->limit = 3;
     $arrSimCard = News::model()->findAll($criSimCard);
     //TV
     $criTv = new CDBCriteria();
     $criTv->addCondition("category_news_id = 7");
     $criTv->order = "id DESC";
     $criTv->limit = 3;
     $arrTv = News::model()->findAll($criTv);
     /*Pictures*/
     $criPic = new CDbCriteria();
     $criPic->addCondition("album_id = 2");
     $criPic->order = "id DESC";
     $criPic->limit = 10;
     $arrPic = Images::model()->findAll($criPic);
     /*Slider*/
     $criBanner = new CDbCriteria();
     $criBanner->order = "id DESC";
     $criBanner->limit = 5;
     $arrBanner = Slides::model()->findAll($criBanner);
     /*Links web*/
     $arrLink = Links::model()->find();
     $this->render("index", array('arrBanner' => $arrBanner, 'arrInternet' => $arrInternet, 'arrOptical' => $arrOptical, 'arrStore' => $arrStore, 'arrCa' => $arrCa, 'arrSimCard' => $arrSimCard, 'arrTv' => $arrTv, 'arrLink' => $arrLink));
 }
 public function actionDelete($id)
 {
     $model = Images::model()->findByPk($id);
     $name = $model->attributes['image'];
     $this->loadModel($id)->delete();
     unlink(Yii::app()->basePath . '/../upload/images/' . $name);
     Yii::app()->user->setFlash('success', translate('Xóa thành công.'));
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
     }
 }
Exemple #8
0
 public function getImagePreviewByPostId($post_id)
 {
     $criteria = new CDbCriteria();
     $criteria->limit = 1;
     $criteria->condition = "post_id = {$post_id}";
     $data = Images::model()->find($criteria);
     if ($data) {
         $url = $data->img_url;
         return StringHelper::generateUrlImage($url);
         //Yii::app()->request->getBaseUrl(true) . '/' . $url;
     } else {
         return '';
     }
 }
 public function actionIndex()
 {
     $this->pageTitle = "Liên hệ - " . $this->dataSystem->title;
     //Setting
     $criSystem = new CDbCriteria();
     $criSystem->order = "id DESC";
     $arrSystem = System::model()->find($criSystem);
     //partner
     $criPartner = new CDbCriteria();
     $criPartner->addCondition("album_id = 3");
     $criPartner->order = "id DESC";
     $criPartner->limit = 10;
     $arrPartner = Images::model()->findAll($criPartner);
     $this->render('index', array('arrSystem' => $arrSystem, 'arrPartner' => $arrPartner));
 }
Exemple #10
0
 public function getRandomPostOfAlbum($album_id)
 {
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->order = 'RAND()';
     $criteria->condition = "album_id = {$album_id}";
     $criteria->limit = 4;
     $posts = PostAlbum::model()->findAll($criteria);
     $images = array();
     if ($posts) {
         foreach ($posts as $post) {
             $images[] = Images::model()->getImagePreviewByPostId($post->post_id);
         }
     }
     $cnt = count($images);
     if ($cnt < 4) {
         for ($i = 0; $i < 4 - $cnt; $i++) {
             $images[] = '';
         }
     }
     return $images;
 }
Exemple #11
0
 public function run()
 {
     //News
     $criNew = new CDBCriteria();
     $criNew->addCondition("category_news_id = 5");
     $criNew->order = "id DESC";
     $criNew->limit = 5;
     $arrNews = News::model()->findAll($criNew);
     //Support
     $criSupport = new CDbCriteria();
     $criSupport->order = "id DESC";
     $arrSupport = Supports::model()->findAll($criSupport);
     /*Ads Right*/
     $criAds = new CDbCriteria();
     $criAds->addCondition("album_id = 1");
     $criAds->order = "id DESC";
     $arrAds = Images::model()->findAll($criAds);
     /*Pictures*/
     $criPic = new CDbCriteria();
     $criPic->addCondition("album_id = 2");
     $criPic->order = "id DESC";
     $arrPic = Images::model()->findAll($criPic);
     $this->render("widgetRight", array('dataSystem' => $this->dataSystem, 'arrNews' => $arrNews, 'arrSupport' => $arrSupport, 'arrAds' => $arrAds, 'arrPic' => $arrPic));
 }
Exemple #12
0
 /**
  * Before a delete of an Image record, take appropriate action
  * @return bool
  */
 public function beforeDelete()
 {
     // Null all FK references from Product to this Image.
     Product::model()->updateAll(array('image_id' => null), 'image_id = :image_id', array(':image_id' => $this->id));
     // Delete images where this image is the parent.
     if ($this->IsPrimary() === true) {
         $arrChildImages = Images::model()->findAllByAttributes(array('parent' => $this->id));
         foreach ($arrChildImages as $objImage) {
             if ($objImage->id === $this->id) {
                 // For primary images, they are actually their own parent.
                 // Without this check, we'd have an infinite loop.
                 continue;
             }
             $objImage->delete();
         }
     }
     // Delete all ImagesCloud rows that reference this Image to satisfy
     // foreign key constraints.
     $arrImagesCloud = ImagesCloud::model()->findAllByAttributes(array('image_id' => $this->id));
     foreach ($arrImagesCloud as $objImagesCloud) {
         $objImagesCloud->delete();
     }
     // Delete the image from the file system.
     $this->DeleteImage();
     return parent::beforeDelete();
 }
 public function actionDelImage($id, $typeId)
 {
     $model = Images::model()->findByPk($id);
     $name = $model->attributes['image'];
     if ($this->loadModel($id)->delete() && $name != '' && file_exists(Yii::app()->basePath . '/../upload/images/' . $name)) {
         unlink(Yii::app()->basePath . '/../upload/images/' . $name);
     }
     Yii::app()->user->setFlash('success', translate('Xóa thành công.'));
     if ($typeId == Images::$IMAGE_PATNER) {
         $this->redirect(PIUrl::createUrl('/admin/images/patner'));
     } elseif ($typeId == Images::$IMAGE_BANNER) {
         $this->redirect(PIUrl::createUrl('/admin/images/banner'));
     } else {
         $this->redirect(PIUrl::createUrl('/admin/images/index'));
     }
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
     }
 }
    public static function CalculatePages($origing,$cli_id) {

        set_time_limit(200);
        $sum = 0;
        $condition = new CDbCriteria();
        if ($origing != '') $condition->condition = "Origin='" . $origing . "'";
        $condition->addCondition("Client_ID = '" . $cli_id . "'");

        $documents = Documents::model()->findAll($condition);

        require_once(Yii::app()->basePath.'/extensions/Fpdf/fpdf.php');
        require_once(Yii::app()->basePath.'/extensions/Fpdi/fpdi.php');

        foreach($documents as $document) {
            $pages = FileModification::calculatePagesByDocID($document->Document_ID);

            if ($pages > 1)
            {
                $image = Images::model()->findByAttributes(array(
                    'Document_ID'=>$document->Document_ID
                ));
                if ($image ) {
                    $image->Pages_Count = $pages;
                    $image->save();
                }

            }


            $sum += $pages;

        }

        return $sum;

    }
Exemple #15
0
 public static function getImagePrimary($albumId, $w, $h)
 {
     $image = Images::model()->findByAttributes(array('album_id' => $albumId, 'is_primary' => 1));
     if (!empty($image)) {
         return getImage($image->image, $w, $h);
     } else {
         return getImage('', $w, $h);
     }
 }
Exemple #16
0
<?php

if (is_array($model)) {
    foreach ($model as $key => $value) {
        ?>
        <div class="ServiceDetail1 NewsBG">
                <div class="ServiceImg">
                    <a href="<?php 
        echo Yii::app()->createUrl('wUserItem/detailshop', array('id' => $value['id'], 'title' => WFunction::convertToAlias($value['title'])));
        ?>
">
                        <?php 
        if ($value['image']) {
            $arrimage = Images::model()->find('id=:id', array(':id' => $value['image']));
            ?>
                            <img class="Radius" src="<?php 
            echo Yii::app()->params['upload_path'] . $arrimage['image_path'] . $arrimage['image_title'] . '.' . $arrimage['image_ext'];
            ?>
" />
                            <?php 
        } else {
            echo CHtml::image(Yii::app()->request->baseUrl . '/images/noimage.gif');
        }
        ?>
                    </a>
                </div>
                <div class="ServiceInfo">
                    <a href="<?php 
        echo Yii::app()->createUrl('wUserItem/detailshop', array('id' => $value['id'], 'title' => WFunction::convertToAlias($value['title'])));
        ?>
"><b><?php 
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Images::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemple #18
0
    public static function ShowPdf($doc_id,$mode)
    {
        //mode 1- old style output
        //     2 - new style output


        $url = '/documents/getdocumentfile?doc_id='.$doc_id;
        /*$baseUrl = Yii::app()->baseUrl;
        $cs = Yii::app()->getClientScript();
        $cs->registerScriptFile($baseUrl.'/protected/views/filemodification.pdfjs.webvie.js');
        $cs->registerCssFile($baseUrl.'/css/yourcss.css');*/

        if ($mode==2) {
            $result = renderPartial('application.views.filemodification.viewer',array(
                    '$url'=>$url
                ),true
            );
        }

        if ($mode==1) {


            $mime_type = Images::model()->findByAttributes(array(
                'Document_ID'=>$doc_id
            ))->Mime_Type;


            $result = FileController::renderPartial('application.views.filemodification.iframe',array(
                    'mime_type'=>$mime_type,
                    'doc_id'=>$doc_id
                ),true
            );
        }
        return $result;
    }
 public function actionEditBackground()
 {
     Yii::import('ext.iwi.Iwi');
     $id = Yii::app()->user->id;
     if (!$id > 0) {
         throw new CException('Not Found', 404);
     }
     $filev = new FileValidator();
     $filev->types = array('jpg', 'jpeg', 'png', 'gif');
     $filev->sizes = array('min' => 962, 250);
     $upload = Images::model()->uploadFile('avatar', true, $filev);
     if ($upload !== false && !isset($upload['error'])) {
         //$size = getimagesize(Yii::getPathOfAlias('webroot').'/upload/photos/'.$upload['filename'].'.'.$upload['extension']);
         //if($size[0]<962 || $size[1]<250){
         //    echo CJSON::encode(array('message'=>'Размер изображения должен быть не меньше 962 в ширине на 250 по высоте пикселей.','status'=>'ERROR'));
         //    exit();
         //}
         echo CJSON::encode(array('message' => $upload['filename'] . '.' . $upload['extension'], 'status' => 'OK'));
     } else {
         if (isset($upload['error'])) {
             echo CJSON::encode(array('message' => $upload['error'], 'status' => 'ERROR'));
         }
     }
     if (Yii::app()->request->getPost('height') > 0) {
         $post = array('height' => (int) Yii::app()->request->getPost('height'), 'width' => (int) Yii::app()->request->getPost('width'), 'left' => (int) Yii::app()->request->getPost('left'), 'top' => (int) Yii::app()->request->getPost('top'), 'image' => trim(Yii::app()->request->getPost('image', ''), '/'));
         $filename = basename($post['image']);
         $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
         $userpath = $path . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'UserProfile' . DIRECTORY_SEPARATOR;
         $image = new Iwi($path . DIRECTORY_SEPARATOR . $post['image']);
         $image->resize($post['width'], $post['height'])->crop(962, 250, $post['top'], $post['left']);
         if ($image->save($userpath . $filename)) {
             $user = UserProfile::model()->find("user_id=:uid", array('uid' => $id));
             $oldavatar = false;
             if ($user->background != $filename) {
                 $oldavatar = $user->background;
             }
             $user->background = $filename;
             if ($user->save()) {
                 if ($oldavatar != false && $oldavatar != 'userTestBG.png' && is_file($userpath . $oldavatar)) {
                     FileHelper::cleanUpload('UserProfile', $oldavatar);
                 }
                 echo CJSON::encode(array('message' => $filename, 'status' => 'OK'));
             } else {
                 echo CJSON::encode(array('message' => $user->getErrors(), 'status' => 'ERROR'));
             }
             exit;
         } else {
             //System error must be handled by administration.
             Yii::log("Ошибка при создании файла аватара '{$post['image']}'. Пользователь #{$id}", 'email');
             echo CJSON::encode(array('status' => 'ERROR', 'message' => 'Ну удалось сохранить аватар. Попробуйте позже.'));
         }
     }
     //else
     //    echo CJSON::encode(array('status'=>'ERROR','message'=>'Не хватает параметров.'));
     //if(isset($_GET['ajax']))
     exit;
     //$this->render('edit_avatar');
 }
public static function PrepareTempPdfFile($doc_id)
{
    $image= Images::model()->findByAttributes(array('Document_ID'=>$doc_id));
    if($image) {
        $filename = 'protected/data/temp_for_pdf/' . $image->File_Name;
        $infile = stripslashes($image->Img);
        file_put_contents($filename, $infile);

        return $filename;
    }
}
Exemple #21
0
    /**
     * Get PO's BackUP
     * @param int $backupDocumentID
     * @param bool $useSession
     * @return array
     */
    public static function getBackupDoc($backupDocumentID, $useSession = true)
    {
        $backUp = array(
            'document' => false,
            'file' => false,
        );

        if ($backupDocumentID == 0 && isset($_SESSION['last_uploaded_backup']) && $useSession) {
            $backUp['document'] = Documents::model()->findByPk($_SESSION['last_uploaded_backup']);
        } elseif ($backupDocumentID != 0) {
            $backUp['document'] = Documents::model()->findByPk($backupDocumentID);
        }

        if ($backUp['document']) {
            // get document's file
            $condition = new CDbCriteria();
            $condition->select = 'Mime_Type';
            $condition->condition = "Document_ID='" . $backUp['document']->Document_ID . "'";
            $backUp['file'] = Images::model()->find($condition);
        }

        return $backUp;
    }
 public function actionApi()
 {
     $ads = Ads::model()->findAllByAttributes(array('read_status' => 0));
     if ($ads) {
         foreach ($ads as $index => $ad) {
             $images = Images::model()->findAllByAttributes(array('ads_id' => $ad->id));
             if ($images) {
                 foreach ($images as $im) {
                     $ad->images[] = $im->link;
                 }
             }
         }
         echo json_encode(array('ads' => $ads));
     }
 }
Exemple #23
0
    /**
     * Generate or regenerate PDF for AP
     * @param $apId
     * @param bool $approved
     * @deprecated since 26.05.2015
     *
     */
    public static function generatePdf($apId, $approved = false)
    {
        // get AP
        $ap = Aps::model()->with('dists', 'document', 'ck_req_detail')->findByPk($apId);

        $ckReqDet = $ap->ck_req_detail;

        // get PO dists
        $apDists = $ap->dists;

        // get PO formatting
        $poFormatting = PoFormatting::model()->findByAttributes(array(
            'Project_ID' => $ap->document->Project_ID,
        ));

        // get Sign_Requested_By user info
        $signRequestedByUser = Users::model()->with('person')->findByPk($ckReqDet->Sign_Requested_By);

        $aproval_detail_list = Audits::getApprovalDetailList($ap->Document_ID);
        // get current vendor info
        $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($ap->Vendor_ID);

        $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID);
        $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition);

        // get content for pdf
        $content = Yii::app()->controller->renderPartial('application.views.ap.ap_template', array(
            'ap' => $ap,
            'ckReqDet' => $ckReqDet,
            'poFormatting' => $poFormatting,
            'apDists' => $apDists,
            'currentVendor' => $currentVendor,
            'vendorAdmin' => $vendorAdmin,
            'signRequestedByUser' => $signRequestedByUser,

            'aproval_detail_list' => $aproval_detail_list,

            'approved' => $approved,
        ), true);

        $fileName = Helper::createDirectory('generated_po');
        $fileName = $fileName.'/' . Yii::app()->user->userID . '-' . date("Y_m_d_H_i_s") . '.pdf';
        Yii::import('ext.html2pdf.HTML2PDF');
        $html2pdf = new HTML2PDF('P', 'A4', 'en');
        $html2pdf->writeHTML($content);
        $html2pdf->Output($fileName, 'F');

        // insert or update image image
        $image = Images::model()->findByAttributes(array(
            'Document_ID' => $ap->Document_ID,
        ));

        if (!$image) {
            $image = new Images();
        }

        $imageData = addslashes(fread(fopen($fileName,"rb"),filesize($fileName)));
        $image->Document_ID = $ap->Document_ID;
        $image->Img = $imageData;
        $image->File_Name = Yii::app()->user->userID . '-' . date("Y_m_d_H_i_s") . '.pdf';
        $image->Mime_Type = 'application/pdf';
        $image->File_Hash = sha1_file($fileName);
        $image->File_Size = intval(filesize($fileName));
        $image->Pages_Count = FileModification::calculatePagesByPath($fileName);
        $image->save();

        if (file_exists($fileName)) {
            @unlink($fileName);
        }
    }
Exemple #24
0
    public static function fileToDatabase($doc_id,$filepath,$pages_count) {
        // insert or update image image
        $image = Images::model()->findByAttributes(array(
            'Document_ID' => $doc_id,
        ));

        if (!$image) {
            $image = new Images();
        }

        $imageData = addslashes(fread(fopen($filepath,"rb"),filesize($filepath)));
        $image->Document_ID = $doc_id;
        $image->Img = $imageData;
        $image->File_Name = Yii::app()->user->userID . '-' . date("Y_m_d_H_i_s") . '.pdf';
        $image->Mime_Type = 'application/pdf';
        $image->File_Hash = sha1_file($filepath);
        $image->File_Size = intval(filesize($filepath));
        $image->Pages_Count = $pages_count;
        $image->save();

    }
 public function actionSetPrimary()
 {
     if (!empty($_POST['album']) && !empty($_POST['image_id'])) {
         Images::model()->updateAll(array('is_primary' => 0), 'album_id=:album_id', array(':album_id' => $_POST['album']));
         Images::model()->updateByPk($_POST['image_id'], array('is_primary' => 1));
         jsonOut(array('error' => false, 'msg' => 'Chọn hình đại diện thành công.'));
     }
 }
Exemple #26
0
 public function actionViewPost()
 {
     $request = Yii::app()->request;
     try {
         $post_id = StringHelper::filterString($request->getQuery('post_id'));
         if (empty(Yii::app()->session['user_id'])) {
             $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/frontend2/views/layouts";
             $this->layout = 'main_empty_2';
         }
         Yii::app()->clientScript->registerMetaTag("fitme.vn - Khám phá thời trang", null, null, array('property' => 'og:title'));
         Yii::app()->clientScript->registerMetaTag(Images::model()->getImagePreviewByPostId($post_id), null, null, array('property' => 'og:image'));
         Yii::app()->clientScript->registerMetaTag("website", null, null, array('property' => 'og:type'));
         Yii::app()->clientScript->registerMetaTag(Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id)), null, null, array('property' => 'og:url'));
         // $data = Posts::model()->getPostById($post_id, '1');
         $data = Posts::model()->getPostById($post_id, Yii::app()->session['user_id']);
         if ($request->getQuery(Yii::app()->params['REF_API'])) {
             ResponseHelper::JsonReturnSuccess($data, "Success");
         } else {
             $this->render('view', array('data' => $data));
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Exemple #27
0
 /**
  * Delete all the images associated with this product.
  * @return void
  */
 public function deleteImages()
 {
     if (is_null($this->id)) {
         return;
     }
     $arrImage = Images::model()->findAllByAttributes(array('product_id' => $this->id));
     foreach ($arrImage as $objImage) {
         $objImage->delete();
     }
 }
Exemple #28
0
            </div>
        </div>
        <div class="latest_home_content">
            
            <?php 
        $lastestNews = $value['latest_articles'];
        if (is_array($lastestNews)) {
            foreach ($lastestNews as $keys => $news_item) {
                if ($keys == 0) {
                    ?>
	        <div class="latest">
                <div class="new_item_top"></div>
                <div style="background:#3D3D3D;height:128px">
                    <?php 
                    if ($news_item['image_id']) {
                        $arrimage = Images::model()->find('id=:id', array(':id' => $news_item['image_id']));
                        //var_dump($arrimage['image_path']);exit();
                        ?>
	               <a href="<?php 
                        echo Yii::app()->createUrl('wNews/detailnews', array('id' => $news_item['id']));
                        ?>
" title="<?php 
                        echo $news_item['news_title'];
                        ?>
"><img border="0" alt="<?php 
                        echo $news_item['news_title'];
                        ?>
" src="<?php 
                        echo Yii::app()->params['upload_path'] . $arrimage['image_path'] . $arrimage['image_title'] . '.' . $arrimage['image_ext'];
                        ?>
" class="titleincate" /></a>
Exemple #29
0
        <?php 
foreach ($data as $item) {
    ?>
            <div class="card-single" id="<?php 
    echo $item['post_id'];
    ?>
">
                <div class="card-single-inner">
                    <div class="c-image">
                        <div class="post-image">
                            <a href="" class="post-link" data-toggle="modal" data-target="#singlePostModal" data-href="<?php 
    echo Yii::app()->createUrl('post/view', array('post_id' => $item['post_id']));
    ?>
" >
                                <img src="<?php 
    echo Images::model()->getImagePreviewByPostId($item['post_id']);
    ?>
" alt="">
                                <?php 
    if (count($item['images']) > 1) {
        ?>
                                    <span class="more-image">+ <?php 
        echo count($item['images']) - 1;
        ?>
 ảnh</span>
                                <?php 
    }
    ?>
                            </a>
                        </div>				
                    </div>
Exemple #30
0
 public function likeImage($user_id, $image_id)
 {
     $model = Images::model()->findByPk($image_id);
     $model->image_like_count++;
     $like = new Like();
     $like->from = $user_id;
     $like->image_id = $image_id;
     $like->status = 1;
     $like->created_at = time();
     $like->updated_at = time();
     if ($model->save(FALSE) && $like->save(FALSE)) {
         return TRUE;
     }
     return FALSE;
 }