/**
  * Render home banners list xml
  *
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $homeBannersXmlObj Mage_XmlConnect_Model_Simplexml_Element */
     $homeBannersXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<home_banners></home_banners>');
     /** @var $deviceHelper Mage_XmlConnect_Helper_Data */
     $deviceHelper = Mage::helper('xmlconnect');
     /** @var $imagesModel Mage_XmlConnect_Model_Images */
     $imagesModel = Mage::getModel('xmlconnect/images');
     $bannerTypeCollection = $this->getBannerTypeArray();
     $deviceType = $deviceHelper->getDeviceType();
     foreach ($bannerTypeCollection[$deviceType] as $bannerType) {
         $bannerImageCollection = $imagesModel->getDeviceImagesByType($bannerType);
         foreach ($bannerImageCollection as $bannerImage) {
             $itemXmlObj = $homeBannersXmlObj->addCustomChild('item', null, array('entity_id' => $bannerImage['image_id'], 'type' => $bannerType));
             $originalFile = Mage_XmlConnect_Model_Images::getBasePath($bannerImage['image_file']);
             $bannerUrl = $imagesModel->getScreenSizeImageUrlByType($bannerImage['image_file'], $bannerType);
             $itemXmlObj->addCustomChild('image', $bannerUrl, array('modification_time' => filemtime($originalFile)));
             $this->_addImageAction($itemXmlObj, $bannerImage['image_id']);
         }
     }
     return $homeBannersXmlObj->asNiceXml();
 }
Example #2
0
 /**
  * Retrieve custom size image url
  *
  *
  * @param string $imageUrl
  * @param int $width
  * @param int $height
  * @return string|null
  */
 public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
 {
     $screenSize = $width . 'x' . $height;
     $customDir = $this->getMediaPath('custom' . DS . $screenSize);
     $this->_verifyDirExist($customDir);
     $imageUrl = explode('/', $imageUrl);
     $file = array_pop($imageUrl);
     $filePath = Mage_XmlConnect_Model_Images::getBasePath() . DS . $file;
     if (!file_exists($customDir . DS . $file)) {
         $image = new Varien_Image($filePath);
         $widthOriginal = $image->getOriginalWidth();
         $heightOriginal = $image->getOriginalHeight();
         if ($width != $widthOriginal) {
             $widthOriginal = $width;
         }
         if ($height != $heightOriginal) {
             $heightOriginal = $height;
         }
         if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
             $image->keepTransparency(true);
             $image->keepFrame(true);
             $image->keepAspectRatio(true);
             $image->backgroundColor(array(255, 255, 255));
             $image->resize($widthOriginal, $heightOriginal);
             $image->save($customDir, basename($file));
         }
     }
     return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
 }
 /**
  * Upload file controller action
  */
 public function uploadImagesAction()
 {
     $data = $this->getRequest()->getParams();
     if (isset($data['Filename'])) {
         // Add random string to uploaded file new
         $newFileName = Mage::helper('core')->getRandomString(5) . '_' . $data['Filename'];
     }
     try {
         $this->_initApp();
         /** @var $imageModel Mage_XmlConnect_Model_Images */
         $imageModel = Mage::getModel('xmlconnect/images');
         if (isset($data['image_id']) && $data['image_id'] > 0) {
             $imageModel->load($data['image_id']);
         }
         $imageModel->validateAndSetSubmitData($data)->checkType()->checkApplication();
         /** @var $uploader Mage_Core_Model_File_Uploader */
         $uploader = Mage::getModel('core/file_uploader', $imageModel->getImageType());
         $uploader->setAllowRenameFiles(true)->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $result = $uploader->save(Mage_XmlConnect_Model_Images::getBasePath(), $newFileName);
         $result['thumbnail'] = Mage::getModel('xmlconnect/images')->getCustomSizeImageUrl($result['file'], Mage_XmlConnect_Helper_Data::THUMBNAIL_IMAGE_WIDTH, Mage_XmlConnect_Helper_Data::THUMBNAIL_IMAGE_HEIGHT);
         $imageModel->setImageFile($result['file']);
         $imageModel->save();
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain(), 'order' => $imageModel->getOrder(), 'image_id' => $imageModel->getId(), 'file_field' => $imageModel->getImageType());
         $result['image_list'] = $this->getLayout()->addBlock('xmlconnect/adminhtml_mobile_edit_tab_design_images', 'design_images')->getImageList($imageModel->getImageType(), $imageModel->getImageCount());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }