Ejemplo n.º 1
0
 /**
  * Creates and renders a new version of a specific image.
  * @param integer $id the image id.
  * @param string $version the name of the image version.
  * @throws CHttpException if the requested version is not defined.
  */
 public function actionCreate($id, $version)
 {
     $versions = Yii::app()->image->versions;
     if (isset($versions[$version])) {
         $thumb = Yii::app()->image->createImageVersion($id, $version);
         $thumb->render();
     } else {
         throw new CHttpException(404, Img::t('error', 'Failed to create image! Version is unknown.'));
     }
 }
Ejemplo n.º 2
0
<div id="imgInstaller">

	<h1><?php 
echo Img::t('install', 'Error');
?>
</h1>

	<p class="notice"><?php 
echo Img::t('install', 'An error occurred while installing the Image module.');
?>
</p>

	<p><?php 
echo Img::t('install', 'Please try again or consult the documentation.');
?>
</p>

	<p class="last"><?php 
echo CHtml::link(Img::t('install', 'Continue &raquo;'), Yii::app()->homeUrl);
?>
</p>

</div>
Ejemplo n.º 3
0
 /**
  * @return array customized attribute labels (name=>label)
  */
 public function attributeLabels()
 {
     return array('id' => Img::t('core', 'Id'), 'name' => Img::t('core', 'Name'), 'path' => Img::t('core', 'Path'), 'extension' => Img::t('core', 'Extension'), 'filename' => Img::t('core', 'Filename'), 'byteSize' => Img::t('core', 'Byte Size'), 'mimeType' => Img::t('core', 'Mime Type'), 'created' => Img::t('core', 'Created'));
 }
Ejemplo n.º 4
0
<div id="imgInstaller">

	<h1><?php 
echo Img::t('install', 'Install');
?>
</h1>

	<p class="notice"><?php 
echo Img::t('install', 'This will install the Image module.');
?>
</p>

	<p><?php 
echo Img::t('install', 'Do you wish to continue?');
?>
</p>

	<p class="last">
		<?php 
echo CHtml::link(Img::t('install', 'Yes'), array('index', 'confirm' => 1));
?>
 /
		<?php 
echo CHtml::link(Img::t('install', 'No'), Yii::app()->homeUrl);
?>
	</p>

</div>
Ejemplo n.º 5
0
 /**
  * Executes the database schema provided with this module.
  * @throws CException if the schema cannot be read or if one of the queries fails.
  */
 public function executeSchema()
 {
     $db = Yii::app()->getDb();
     // Read the schema file.
     if (($schema = file_get_contents(dirname(__FILE__) . '/../data/schema.sql')) === false) {
         throw new CException(Img::t('error', 'Failed to execute the database schema! File could not be read.'));
     }
     // We need to append the table prefix if necessary.
     $schema = strtr($schema, array($this->_imageTable => $db->tablePrefix . $this->_imageTable));
     // Split the schema into separate SQL-statements.
     $schema = preg_split("/;\\s*/", trim($schema, ';'));
     $trx = $db->beginTransaction();
     try {
         foreach ($schema as $sql) {
             $db->createCommand($sql)->execute();
         }
         // All statements executed successfully.
         $trx->commit();
     } catch (CException $e) {
         // Something went wrong.
         $trx->rollback();
         throw $e;
     }
 }
Ejemplo n.º 6
0
	<h1><?php 
echo Img::t('install', 'Reinstall');
?>
</h1>

	<p class="notice"><?php 
echo Img::t('install', 'The Image module is already installed!');
?>
</p>

	<p><?php 
echo Img::t('install', 'Do you wish to continue?');
?>
</p>

	<p>
		<?php 
echo CHtml::link(Img::t('install', 'Yes'), array('install/index', 'confirm' => 1));
?>
 /
		<?php 
echo CHtml::link(Img::t('install', 'No'), Yii::app()->homeUrl);
?>
	</p>

	<p class="warning last"><?php 
echo Img::t('install', 'WARNING: All your existing data will be lost.');
?>
</p>

</div>
Ejemplo n.º 7
0
 /**
  * Applies the given options onto this image.
  * @param ImgOptions $options the image options.
  */
 public function applyOptions($options)
 {
     if ($options->width !== null && $options->height !== null || $options->resizeMethod !== null) {
         if (isset($options->resizeMethod) === false) {
             $options->resizeMethod = Img::METHOD_RESIZE;
         }
         switch ($options->resizeMethod) {
             case Img::METHOD_RESIZE:
                 if ($options->width !== null && $options->height !== null) {
                     $this->resize($options->width, $options->height);
                 }
                 break;
             case Img::METHOD_ADAPTIVE_RESIZE:
                 if ($options->width !== null && $options->height !== null) {
                     $this->adaptiveResize($options->width, $options->height);
                 }
                 break;
             case Img::METHOD_RESIZE_PERCENT:
                 if ($options->percent !== null) {
                     $this->resizePercent($options->percent);
                 }
                 break;
             default:
                 throw new ImgException(Img::t('error', 'Failed to resize image! Resize method is unknown.'));
         }
     }
     if ($options->cropMethod !== null) {
         switch ($options->cropMethod) {
             case Img::METHOD_CROP:
                 if ($options->cropX !== null && $options->cropY !== null && $options->cropWidth !== null && $options->cropHeight !== null) {
                     $this->crop($options->cropX, $options->cropY, $options->cropWidth, $options->cropHeight);
                 }
                 break;
             case Img::METHOD_CROP_CENTER:
                 if ($options->cropWidth !== null) {
                     $this->cropFromCenter($options->cropWidth, $options->cropHeight);
                 }
                 break;
             default:
                 throw new ImgException(Img::t('error', 'Failed to crop image! Crop method is unknown.'));
         }
     }
     if ($options->rotateMethod !== null) {
         switch ($options->rotateMethod) {
             case Img::METHOD_ROTATE:
                 if ($options->rotateDirection !== null) {
                     $this->rotate($options->rotateDirection);
                 }
                 break;
             case Img::METHOD_ROTATE_DEGREES:
                 if ($options->rotateDegrees !== null) {
                     $this->rotateDegrees($options->rotateDegrees);
                 }
                 break;
             default:
                 throw new ImgException(Img::t('error', 'Failed to rotate image! Rotate method is unknown.'));
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Deletes a specific image version.
  * @param Image $image the image model.
  * @param string $version the image version.
  * @return boolean whether the image was deleted.
  * @throws ImgException if the image cannot be deleted.
  */
 protected function deleteVersion($image, $version)
 {
     if (isset($this->versions[$version])) {
         $path = $this->resolveImageVersionPath($image, $version) . $this->resolveFileName($image);
         if (file_exists($path) !== false && unlink($path) === false) {
             throw new ImgException(Img::t('error', 'Failed to delete the image version! File could not be deleted.'));
         }
     } else {
         throw new ImgException(Img::t('error', 'Failed to delete image version! Version is unknown.'));
     }
 }