public function renderDataCellContent($data, $row)
 {
     $imageContent = $this->getImageContent();
     $insertLink = ZurmoHtml::tag('div', array('class' => 'insert-image'), $this->view->getLinkString($data, $this->attribute));
     $layout = $imageContent . '<div class="builder-image-details"><strong>{name}</strong><br />{size} · {dimensions} · ' . $this->getCreatorContent() . ' </div>';
     $imageSummary = ImageFileModelUtil::getImageSummary($data, $layout);
     return $imageSummary . $insertLink;
 }
 protected function makeImages()
 {
     $imagesNamesToImport = array('200x50' => '200x50.gif', '200x200' => '200x200.gif', '580x180' => '580x180.gif', 'googleMaps' => 'staticmap.png');
     foreach ($imagesNamesToImport as $type => $name) {
         $path = Yii::getPathOfAlias('application.modules.emailTemplates.views.assets.images') . DIRECTORY_SEPARATOR . $name;
         $fileUploadData = ImageFileModelUtil::saveImageFromTemporaryFile($path, $type);
         $this->importedImages[$type] = $fileUploadData['id'];
     }
 }
 protected function renderForm()
 {
     $this->renderScripts();
     list($form, $formStart) = $this->controller->renderBeginWidget('ZurmoActiveForm', array('id' => 'image-edit-form', 'enableAjaxValidation' => true, 'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => false, 'beforeValidate' => 'js:$(this).beforeValidateAction', 'afterValidate' => 'js:$(this).afterValidateAjaxAction', 'afterValidateAjax' => $this->renderConfigSaveAjax())));
     $src = ImageFileModelUtil::getUrlForGetImageFromImageFileName($this->model->getImageCacheFileName());
     $content = $formStart;
     $content .= ZurmoHtml::openTag('div', array('class' => 'form-inputs right-column'));
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'cropX');
     $content .= $form->numberField($this->formModel, 'cropX');
     $content .= $form->error($this->formModel, 'cropX');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'cropY');
     $content .= $form->numberField($this->formModel, 'cropY');
     $content .= $form->error($this->formModel, 'cropY');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'cropWidth');
     $content .= $form->numberField($this->formModel, 'cropWidth');
     $content .= $form->error($this->formModel, 'cropWidth');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'cropHeight');
     $content .= $form->numberField($this->formModel, 'cropHeight');
     $content .= $form->error($this->formModel, 'cropHeight');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'imageWidth');
     $content .= $form->numberField($this->formModel, 'imageWidth');
     $content .= $form->error($this->formModel, 'imageWidth');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'imageHeight');
     $content .= $form->numberField($this->formModel, 'imageHeight');
     $content .= $form->error($this->formModel, 'imageHeight');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::openTag('div', array('class' => 'image-resize-field clearfix'));
     $content .= $form->labelEx($this->formModel, 'lockImageProportion');
     $content .= $form->checkBox($this->formModel, 'lockImageProportion');
     $content .= $form->error($this->formModel, 'lockImageProportion');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::tag('div', array('class' => 'left-column'), ZurmoHtml::image($src, '', array('class' => 'crop-and-resize')));
     $linkOptions = array('onclick' => "\$(this).addClass('attachLoadingTarget').closest('form').submit()", 'class' => 'z-button');
     $content .= ZurmoHtml::openTag('div', array('class' => 'view-toolbar-container clearfix'));
     $content .= ZurmoHtml::openTag('div', array('class' => 'form-toolbar'));
     $content .= ZurmoHtml::link(ZurmoHtml::tag('span', array('class' => 'z-label'), Zurmo::t('Core', 'Save')), "#", $linkOptions);
     $content .= ZurmoHtml::closeTag('div');
     $content .= ZurmoHtml::closeTag('div');
     $content .= $this->controller->renderEndWidget();
     return $content;
 }
 protected function renderHtmlContentArea()
 {
     $id = $this->getEditableInputId(static::HTML_CONTENT_INPUT_NAME);
     $htmlOptions = array();
     $htmlContent = $this->model->htmlContent;
     $htmlOptions['id'] = $id;
     $htmlOptions['name'] = $this->getEditableInputName(static::HTML_CONTENT_INPUT_NAME);
     $cClipWidget = new CClipWidget();
     $cClipWidget->beginClip("Redactor");
     // Begin Not Coding Standard
     $cClipWidget->widget('application.core.widgets.Redactor', array('htmlOptions' => $htmlOptions, 'content' => $htmlContent, 'paragraphy' => "false", 'fullpage' => "true", 'deniedTags' => "false", 'plugins' => CJSON::encode($this->resolvePlugins()), 'observeImages' => 'true', 'imageUpload' => ImageFileModelUtil::getUrlForActionUpload(), 'imageGetJson' => ImageFileModelUtil::getUrlForActionGetUploaded(), 'initCallback' => 'function(){
                                 var contentHeight = $(".redactor_box iframe").contents().find("body").outerHeight();
                                 $(".redactor_box iframe").height(contentHeight + 50);
                             }'));
     // End Not Coding Standard
     $cClipWidget->endClip();
     $content = ZurmoHtml::label($this->renderHtmlContentAreaLabel(), $id);
     $content .= $cClipWidget->getController()->clips['Redactor'];
     return $content;
 }
 public function actionModalEdit($id)
 {
     if (!Yii::app()->request->isAjaxRequest) {
         throw new NotSupportedException();
     }
     $form = new ImageEditForm();
     $imageFileModel = ImageFileModel::getById((int) $id);
     Yii::app()->getClientScript()->setToAjaxMode();
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'image-edit-form') {
         $errors = ZurmoActiveForm::validate($form);
         if ($form->hasErrors()) {
             echo $errors;
             Yii::app()->end();
         }
     } elseif (isset($_POST['ImageEditForm'])) {
         $tempFilePath = tempnam(sys_get_temp_dir(), 'edit_image_');
         $form->attributes = $_POST['ImageEditForm'];
         $originalImageFileModel = ImageFileModel::getById((int) $id);
         $contents = WideImage::load($originalImageFileModel->fileContent->content)->resize($form->imageWidth, $form->imageHeight)->crop($form->cropX, $form->cropY, $form->cropWidth, $form->cropHeight)->asString(str_replace('image/', '', $originalImageFileModel->type));
         file_put_contents($tempFilePath, $contents);
         $imageProperties = getimagesize($tempFilePath);
         $fileUploadData = ImageFileModelUtil::saveImageFromTemporaryFile($tempFilePath, ImageFileModelUtil::getImageFileNameWithDimensions($originalImageFileModel->name, (int) $imageProperties[0], (int) $imageProperties[1]));
         echo CJSON::encode($fileUploadData);
     } else {
         $modalListLinkProvider = $this->getModalListLinkProvider();
         $form->id = $imageFileModel->id;
         $form->imageWidth = $imageFileModel->width;
         $form->imageHeight = $imageFileModel->height;
         $form->cropX = 0;
         $form->cropY = 0;
         $form->cropWidth = $imageFileModel->width;
         $form->cropHeight = $imageFileModel->height;
         $form->lockImageProportion = true;
         if ($imageFileModel->isEditableByCurrentUser()) {
             $view = new ImageEditView($this, $form, $imageFileModel, $modalListLinkProvider);
             $view = new ModalView($this, $view);
         } else {
             $view = new AccessFailureView();
         }
         echo $view->render();
     }
 }
 protected function getScriptForClick($model)
 {
     $summary = ImageFileModelUtil::getImageSummary($model);
     $data = CJavaScript::encode(array($this->sourceIdFieldId => $model->id));
     return "javascript:parent.transferModalValues('#{$this->modalId}', {$data});\n                               parent.replaceImageSummary('{$this->sourceNameFieldId}', '{$summary}')";
 }
 public function testSaveImageFromTemporaryFile()
 {
     $id = ImageFileModel::getCount() + 1;
     Yii::app()->user->userModel = User::getByUsername('super');
     $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files');
     $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testImage.png';
     $fileUploadData = ImageFileModelUtil::saveImageFromTemporaryFile($filePath, 'fileNameTest');
     $this->assertEquals($id, $fileUploadData['id']);
     $this->assertEquals('fileNameTest.png', $fileUploadData['name']);
     $this->assertContains('<img data-url=', $fileUploadData['summary']);
     $this->assertEquals('3.25KB', $fileUploadData['size']);
     $this->assertContains("getThumb?fileName={$id}_fileNameTest.png", $fileUploadData['thumbnail_url']);
     // Not Coding Standard
     $this->assertContains("getImage?fileName={$id}_fileNameTest.png", $fileUploadData['filelink']);
     // Not Coding Standard
     $this->assertContains('javascript:parent.transferModalImageValues', $fileUploadData['insert_link']);
 }
 /**
  * @inheritdoc
  */
 protected function renderContent()
 {
     return ZurmoHtml::image(ImageFileModelUtil::getUrlForGetImageFromImageFileName($this->imageFileName));
 }
 public static function saveImageFromTemporaryFile($tempFilePath, $name)
 {
     $fileContent = new FileContent();
     $fileContent->content = file_get_contents($tempFilePath);
     $imageProperties = getimagesize($tempFilePath);
     $imageFileModel = new ImageFileModel();
     static::resolveImageName($name, $imageProperties['mime']);
     $imageFileModel->name = $name;
     $imageFileModel->size = filesize($tempFilePath);
     $imageFileModel->type = $imageProperties['mime'];
     $imageFileModel->width = $imageProperties[0];
     $imageFileModel->height = $imageProperties[1];
     $imageFileModel->fileContent = $fileContent;
     if ($imageFileModel->save()) {
         $imageFileModel->createImageCache();
         $fileUploadData = array('id' => $imageFileModel->id, 'name' => $imageFileModel->name, 'summary' => ImageFileModelUtil::getImageSummary($imageFileModel), 'size' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($imageFileModel->size), 'thumbnail_url' => Yii::app()->createAbsoluteUrl('zurmo/imageModel/getThumb', array('fileName' => $imageFileModel->getImageCacheFileName())), 'filelink' => Yii::app()->createAbsoluteUrl('zurmo/imageModel/getImage', array('fileName' => $imageFileModel->getImageCacheFileName())), 'insert_link' => static::resolveInsertLink($imageFileModel));
     } else {
         $message = Zurmo::t('ZurmoModule', 'Error uploading the image');
         $fileUploadData = array('error' => $message);
     }
     return $fileUploadData;
 }
 protected function renderImage($isThumb = false)
 {
     $altText = '';
     $htmlOptions = array();
     if (!$isThumb) {
         $altText = $this->getAltText();
         $htmlOptions = $this->getHtmlOptions();
     }
     if ($this->image != null) {
         $url = ImageFileModelUtil::getUrlForGetImageFromImageFileName($this->image->getImageCacheFileName(), $isThumb);
     } else {
         $url = PlaceholderImageUtil::resolvePlaceholderImageUrl();
     }
     return ZurmoHtml::image($url, $altText, $htmlOptions);
 }