PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/XmlConnect/Helper/Image.php

https://gitlab.com/blingbang2016/shop
PHP | 810 lines | 466 code | 62 blank | 282 comment | 85 complexity | 7ea6c71a3110a562e7c174cbaef8cc0c MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_XmlConnect
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * XmlConnect image helper
  28. *
  29. * @category Mage
  30. * @package Mage_XmlConnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Helper_Image extends Mage_Core_Helper_Abstract
  34. {
  35. /**
  36. * Xml connect glue
  37. *
  38. * @deprecated will delete in the next version
  39. */
  40. const XMLCONNECT_GLUE = Mage_XmlConnect_Model_ImageLimits::SCREEN_SIZE_UPDATE_TYPE_GLUE;
  41. /**
  42. * Image limits for content
  43. *
  44. * @deprecated will delete in the next version
  45. * @var array|null
  46. */
  47. protected $_content = null;
  48. /**
  49. * Image limits for interface
  50. *
  51. * @deprecated will delete in the next version
  52. * @var array|null
  53. */
  54. protected $_interface = null;
  55. /**
  56. * Array of interface image paths in xmlConfig
  57. *
  58. * @deprecated will delete in the next version
  59. * @var array
  60. */
  61. protected $_interfacePath = array();
  62. /**
  63. * Image limits array
  64. *
  65. * @deprecated will delete in the next version
  66. * @var array
  67. */
  68. protected $_imageLimits = array();
  69. /**
  70. * Images paths in the config
  71. *
  72. * @deprecated will delete in the next version
  73. * @var array|null
  74. */
  75. protected $_confPaths = null;
  76. /**
  77. * Process uploaded file
  78. * setup file names to the configuration
  79. *
  80. * @deprecated will delete in the next version
  81. * @param string $field
  82. * @return string
  83. */
  84. public function handleUpload($field)
  85. {
  86. $uploadedFilename = '';
  87. $uploadDir = $this->getOriginalSizeUploadDir();
  88. try {
  89. $this->_forcedConvertPng($field);
  90. /** @var $uploader Mage_Core_Model_File_Uploader */
  91. $uploader = Mage::getModel('core/file_uploader', $field);
  92. $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
  93. $uploader->setAllowRenameFiles(true);
  94. $uploader->save($uploadDir);
  95. $uploadedFilename = $uploader->getUploadedFileName();
  96. $uploadedFilename = $this->_getResizedFilename($field, $uploadedFilename, true);
  97. } catch (Exception $e) {
  98. /**
  99. * Hard coded exception catch
  100. */
  101. if (!strlen($_FILES[$field]['tmp_name'])) {
  102. Mage::throwException(Mage::helper('xmlconnect')->__('File can\'t be uploaded.'));
  103. } elseif ($e->getMessage() == 'Disallowed file type.') {
  104. $filename = $_FILES[$field]['name'];
  105. Mage::throwException(
  106. Mage::helper('xmlconnect')->__('Error while uploading file "%s". Disallowed file type. Only "jpg", "jpeg", "gif", "png" are allowed.', $filename)
  107. );
  108. } else {
  109. Mage::logException($e);
  110. }
  111. }
  112. return basename($uploadedFilename);
  113. }
  114. /**
  115. * Return current screen_size parameter
  116. *
  117. * @deprecated will delete in the next version
  118. * @return string
  119. */
  120. protected function _getScreenSize()
  121. {
  122. return $this->filterScreenSize(Mage::helper('xmlconnect')->getApplication()->getScreenSize());
  123. }
  124. /**
  125. * Return correct system filename for current screenSize
  126. *
  127. * @deprecated will delete in the next version
  128. * @throws Mage_Core_Exception
  129. * @param string $fieldPath
  130. * @param string $fileName
  131. * @param bool $default
  132. * @return string
  133. */
  134. protected function _getResizedFilename($fieldPath, $fileName, $default = false)
  135. {
  136. $fileName = basename($fileName);
  137. if ($default) {
  138. $dir = $this->getDefaultSizeUploadDir();
  139. } else {
  140. $dir = $this->getCustomSizeUploadDir($this->_getScreenSize());
  141. }
  142. $customSizeFileName = $dir . DS . $fileName;
  143. $originalSizeFileName = $this->getOriginalSizeUploadDir(). DS . $fileName;
  144. /**
  145. * Compatibility with old versions of XmlConnect
  146. */
  147. if (!file_exists($originalSizeFileName)) {
  148. $oldFileName = $this->getOldUploadDir() . DS . $fileName;
  149. if (file_exists($oldFileName)) {
  150. if (!(copy($oldFileName, $originalSizeFileName) && (is_readable($customSizeFileName)
  151. || chmod($customSizeFileName, 0644))
  152. )) {
  153. Mage::throwException(
  154. Mage::helper('xmlconnect')->__('Error while processing file "%s".', $fileName)
  155. );
  156. }
  157. } else {
  158. Mage::throwException(Mage::helper('xmlconnect')->__('No such file "%s".', $fileName));
  159. }
  160. }
  161. $isCopied = copy($originalSizeFileName, $customSizeFileName);
  162. clearstatcache();
  163. if ($isCopied && (is_readable($customSizeFileName) || chmod($customSizeFileName, 0644))) {
  164. $this->_handleResize($fieldPath, $customSizeFileName);
  165. } else {
  166. $fileName = '';
  167. if (isset($_FILES[$fieldPath]) && is_array($_FILES[$fieldPath]) && isset($_FILES[$fieldPath]['name'])) {
  168. $fileName = $_FILES[$fieldPath]['name'];
  169. }
  170. Mage::throwException(Mage::helper('xmlconnect')->__('Error while uploading file "%s".', $fileName));
  171. }
  172. return $customSizeFileName;
  173. }
  174. /**
  175. * Resize uploaded file
  176. *
  177. * @deprecated will delete in the next version
  178. * @param string $fieldPath
  179. * @param string $file
  180. * @return null
  181. */
  182. protected function _handleResize($fieldPath, $file)
  183. {
  184. $nameParts = explode('/', $fieldPath);
  185. array_shift($nameParts);
  186. $conf = $this->getInterfaceImageLimits();
  187. while (count($nameParts)) {
  188. $next = array_shift($nameParts);
  189. if (isset($conf[$next])) {
  190. $conf = $conf[$next];
  191. } else {
  192. /**
  193. * No config data - nothing to resize
  194. */
  195. return;
  196. }
  197. }
  198. $image = new Varien_Image($file);
  199. $width = $image->getOriginalWidth();
  200. $height = $image->getOriginalHeight();
  201. if (isset($conf['widthMax']) && ($conf['widthMax'] < $width)) {
  202. $width = $conf['widthMax'];
  203. } elseif (isset($conf['width'])) {
  204. $width = $conf['width'];
  205. }
  206. if (isset($conf['heightMax']) && ($conf['heightMax'] < $height)) {
  207. $height = $conf['heightMax'];
  208. } elseif (isset($conf['height'])) {
  209. $height = $conf['height'];
  210. }
  211. if (($width != $image->getOriginalWidth()) || ($height != $image->getOriginalHeight())) {
  212. $image->keepTransparency(true);
  213. $image->keepFrame(true);
  214. $image->keepAspectRatio(true);
  215. $image->backgroundColor(array(255, 255, 255));
  216. $image->resize($width, $height);
  217. $image->save(null, basename($file));
  218. }
  219. }
  220. /**
  221. * Convert uploaded file to PNG
  222. *
  223. * @deprecated will delete in the next version
  224. * @param string $field
  225. */
  226. protected function _forcedConvertPng($field)
  227. {
  228. $file =& $_FILES[$field];
  229. $dotPosition = strrpos($file['name'], '.');
  230. if ($dotPosition !== false) {
  231. $file['name'] = substr($file['name'], 0 , $dotPosition);
  232. }
  233. $file['name'] .= '.png';
  234. // We can't use exif extension, because magento doesn't require it.
  235. // $fileType = exif_imagetype($file['tmp_name']);
  236. list($unnecessaryVar, $unnecessaryVar, $fileType) = getimagesize($file['tmp_name']);
  237. unset($unnecessaryVar);
  238. if ($fileType != IMAGETYPE_PNG) {
  239. switch ($fileType) {
  240. case IMAGETYPE_GIF:
  241. $img = imagecreatefromgif($file['tmp_name']);
  242. imagealphablending($img, false);
  243. imagesavealpha($img, true);
  244. break;
  245. case IMAGETYPE_JPEG:
  246. $img = imagecreatefromjpeg($file['tmp_name']);
  247. break;
  248. case IMAGETYPE_WBMP:
  249. $img = imagecreatefromwbmp($file['tmp_name']);
  250. break;
  251. case IMAGETYPE_XBM:
  252. $img = imagecreatefromxbm($file['tmp_name']);
  253. break;
  254. default:
  255. return;
  256. }
  257. imagepng($img, $file['tmp_name']);
  258. imagedestroy($img);
  259. }
  260. }
  261. /**
  262. * Retrieve xmlconnect images skin url
  263. *
  264. * @param string $name
  265. * @return string
  266. */
  267. public function getSkinImagesUrl($name = null)
  268. {
  269. return Mage::getDesign()->getSkinUrl('images/xmlconnect/' . $name);
  270. }
  271. /**
  272. * Return CustomSizeDirPrefix
  273. *
  274. * @deprecated will delete in the next version
  275. * @return string
  276. */
  277. public function getCustomSizeDirPrefix()
  278. {
  279. return $this->_getScreenSize() . DS . 'custom';
  280. }
  281. /**
  282. * Return FileDefaultSizeSuffixAsUrl
  283. *
  284. * @todo get rid of this method
  285. * @deprecated will delete in the next version
  286. * @param string $fileName
  287. * @return string
  288. */
  289. public function getFileDefaultSizeSuffixAsUrl($fileName)
  290. {
  291. return 'custom' . '/' . $this->_getScreenSize() . '/' . basename($fileName);
  292. }
  293. /**
  294. * Return getFileCustomDirSuffixAsUrl
  295. *
  296. * @deprecated will delete in the next version
  297. * @param string $confPath
  298. * @param string $fileName
  299. * @return string
  300. */
  301. public function getFileCustomDirSuffixAsUrl($confPath, $fileName)
  302. {
  303. return 'custom' . '/' . $this->_getScreenSize() . '/'
  304. . basename($this->_getResizedFilename($confPath, $fileName));
  305. }
  306. /**
  307. * Return correct size for given $imageName and device screen_size
  308. *
  309. * @deprecated will delete in the next version
  310. * @param string $imageName
  311. * @return int
  312. */
  313. public function getImageSizeForContent($imageName)
  314. {
  315. if (!isset($this->_content)) {
  316. $imageLimits = $this->getImageLimits($this->_getScreenSize());
  317. if (($imageLimits['content']) && is_array($imageLimits['content'])) {
  318. $this->_content = $imageLimits['content'];
  319. } else {
  320. $this->_content = array();
  321. }
  322. }
  323. $size = isset($this->_content[$imageName]) ? (int) $this->_content[$imageName] : 0;
  324. return $size;
  325. }
  326. /**
  327. * Return setting for interface images (image size limits)
  328. *
  329. * @deprecated will delete in the next version
  330. * @return array
  331. */
  332. public function getInterfaceImageLimits()
  333. {
  334. if (!isset($this->_interface)) {
  335. $imageLimits = $this->getImageLimits($this->_getScreenSize());
  336. $this->_interface = $imageLimits['interface'];
  337. }
  338. return $this->_interface;
  339. }
  340. /**
  341. * Return correct size for given $imageName and device screen_size
  342. *
  343. * @deprecated will delete in the next version
  344. * @param string $imagePath
  345. * @return int
  346. */
  347. public function getImageSizeForInterface($imagePath)
  348. {
  349. if (!isset($this->_interfacePath[$imagePath])) {
  350. /** @var $app Mage_XmlConnect_Model_Application */
  351. $app = Mage::helper('xmlconnect')->getApplication();
  352. if (!$app) {
  353. return 0;
  354. } else {
  355. $imageLimits = $this->getImageLimits($this->_getScreenSize());
  356. $size = $this->findPath($imageLimits, $imagePath);
  357. $this->_interfacePath[$imagePath] = $size;
  358. }
  359. }
  360. $size = isset($this->_interfacePath[$imagePath]) ? (int) $this->_interfacePath[$imagePath] : 0;
  361. return $size;
  362. }
  363. /**
  364. * Return the filesystem path to XmlConnect media files
  365. *
  366. * @param string $path Right part of the path
  367. * @return string
  368. */
  369. public function getMediaPath($path = '')
  370. {
  371. $path = trim($path);
  372. $result = Mage::getBaseDir('media') . DS . 'xmlconnect';
  373. if ($path) {
  374. if (strpos($path, DS) !== 0) {
  375. $path = DS . $path;
  376. }
  377. $result .= $path;
  378. }
  379. return $result;
  380. }
  381. /**
  382. * Return Url for media image
  383. *
  384. * @param string $image
  385. * @return string
  386. */
  387. public function getMediaUrl($image = '')
  388. {
  389. $image = trim($image);
  390. $result = Mage::getBaseUrl('media') . 'xmlconnect';
  391. if ($image) {
  392. if (strpos($image, '/') !== 0) {
  393. $image = '/' . $image;
  394. }
  395. $result .= $image;
  396. }
  397. return $result;
  398. }
  399. /**
  400. * Return URL for default design image
  401. *
  402. * @param string $image
  403. * @return string
  404. */
  405. public function getDefaultDesignUrl($image = '')
  406. {
  407. return $this->getSkinImagesUrl($this->getDefaultDesignSuffixAsUrl($image));
  408. }
  409. /**
  410. * Return suffix as URL for default design image
  411. *
  412. * @param string $image
  413. * @return string
  414. */
  415. public function getDefaultDesignSuffixAsUrl($image = '')
  416. {
  417. return 'design_default/' . trim(ltrim($image, '/'));
  418. }
  419. /**
  420. * Retrieve custom size image url
  421. *
  422. *
  423. * @param string $imageUrl
  424. * @param int $width
  425. * @param int $height
  426. * @return string|null
  427. */
  428. public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
  429. {
  430. $screenSize = $width . 'x' . $height;
  431. $customDir = $this->getMediaPath('custom' . DS . $screenSize);
  432. $this->_verifyDirExist($customDir);
  433. $imageUrl = explode('/', $imageUrl);
  434. $file = array_pop($imageUrl);
  435. $filePath = Mage_XmlConnect_Model_Images::getBasePath() . DS . $file;
  436. if (!file_exists($customDir . DS . $file)) {
  437. $image = new Varien_Image($filePath);
  438. $widthOriginal = $image->getOriginalWidth();
  439. $heightOriginal = $image->getOriginalHeight();
  440. if ($width != $widthOriginal) {
  441. $widthOriginal = $width;
  442. }
  443. if ($height != $heightOriginal) {
  444. $heightOriginal = $height;
  445. }
  446. if (($widthOriginal != $image->getOriginalWidth()) ||
  447. ($heightOriginal != $image->getOriginalHeight()) ) {
  448. $image->keepTransparency(true);
  449. $image->keepFrame(true);
  450. $image->keepAspectRatio(true);
  451. $image->backgroundColor(array(255, 255, 255));
  452. $image->resize($widthOriginal, $heightOriginal);
  453. $image->save($customDir, basename($file));
  454. }
  455. }
  456. return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
  457. }
  458. /**
  459. * Ensure correct $screenSize value
  460. *
  461. * @deprecated will delete in the next version
  462. * @param string $screenSize
  463. * @return string
  464. */
  465. public function filterScreenSize($screenSize)
  466. {
  467. $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize);
  468. if (isset($this->_imageLimits[$screenSize])) {
  469. return $screenSize;
  470. }
  471. $screenSizeExplodeArray = explode(self::XMLCONNECT_GLUE, $screenSize);
  472. $version = '';
  473. switch (count($screenSizeExplodeArray)) {
  474. case 2:
  475. $version = $screenSizeExplodeArray[1];
  476. case 1:
  477. $resolution = $screenSizeExplodeArray[0];
  478. break;
  479. default:
  480. $resolution = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
  481. break;
  482. }
  483. $sourcePath = empty($version) ? Mage_XmlConnect_Model_Application::APP_SCREEN_SOURCE_DEFAULT : $version;
  484. $xmlPath = 'screen_size/' . self::XMLCONNECT_GLUE . $resolution . '/' . $sourcePath . '/source';
  485. $source = Mage::getStoreConfig($xmlPath);
  486. if (!empty($source)) {
  487. $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE . $version);
  488. } else {
  489. $screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
  490. }
  491. return $screenSize;
  492. }
  493. /**
  494. * Return correct size array for given device screen_size(320x480/640x960_a)
  495. *
  496. * @deprecated will delete in the next version
  497. * @param string $screenSize
  498. * @return array
  499. */
  500. public function getImageLimits($screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT)
  501. {
  502. $defaultScreenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
  503. $defaultScreenSource = Mage_XmlConnect_Model_Application::APP_SCREEN_SOURCE_DEFAULT;
  504. $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize);
  505. if (isset($this->_imageLimits[$screenSize])) {
  506. return $this->_imageLimits[$screenSize];
  507. }
  508. $screenSizeExplodeArray = explode(self::XMLCONNECT_GLUE, $screenSize);
  509. $version = '';
  510. switch (count($screenSizeExplodeArray)) {
  511. case 2:
  512. $version = $screenSizeExplodeArray[1];
  513. case 1:
  514. $resolution = $screenSizeExplodeArray[0];
  515. break;
  516. default:
  517. $resolution = $defaultScreenSize;
  518. break;
  519. }
  520. $sourcePath = empty($version) ? $defaultScreenSource : $version;
  521. $xmlPath = 'screen_size/' . self::XMLCONNECT_GLUE . $resolution . '/' . $sourcePath;
  522. $root = Mage::getStoreConfig($xmlPath);
  523. $updates = array();
  524. if (!empty($root)) {
  525. $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE . $version);
  526. $source = !empty($root['source']) ? $root['source'] : $defaultScreenSource;
  527. $updates = isset($root['updates']) && is_array($root['updates']) ? $root['updates'] : array();
  528. } else {
  529. $screenSize = $defaultScreenSize;
  530. $source = $defaultScreenSource;
  531. }
  532. $imageLimits = Mage::getStoreConfig('screen_size/' . $source);
  533. if (!is_array($imageLimits)) {
  534. $imageLimits = Mage::getStoreConfig('screen_size/default');
  535. }
  536. foreach ($updates as $update) {
  537. $path = $update['path'];
  538. $function = $update['function'];
  539. switch ($function) {
  540. case 'zoom':
  541. $data = $update['data'];
  542. $target =& $this->findPath($imageLimits, $path);
  543. if (is_array($target)) {
  544. array_walk_recursive($target, array($this, '_zoom'), $data);
  545. } else {
  546. $this->_zoom($target, null, $data);
  547. }
  548. break;
  549. case 'update':
  550. $data = $update['data'];
  551. $target =& $this->findPath($imageLimits, $path);
  552. $target = $data;
  553. break;
  554. case 'insert':
  555. $data = $update['data'];
  556. $target =& $this->findPath($imageLimits, $path);
  557. if (($target !== null) && (is_array($target)) && (is_array($data))) {
  558. foreach ($data as $key => $val) {
  559. $target[$key] = $val;
  560. }
  561. }
  562. break;
  563. case 'delete':
  564. $data = $update['data'];
  565. $target =& $this->findPath($imageLimits, $path);
  566. if (isset($target[$data])) {
  567. unset($target[$data]);
  568. }
  569. break;
  570. default:
  571. break;
  572. }
  573. }
  574. if (!is_array($imageLimits)) {
  575. $imageLimits = array();
  576. }
  577. $this->_imageLimits[$screenSize] = $imageLimits;
  578. return $imageLimits;
  579. }
  580. /**
  581. * Return reference to the $path in $array
  582. *
  583. * @deprecated will delete in the next version
  584. * @param array &$array
  585. * @param string $path
  586. * @return mixed reference
  587. */
  588. public function &findPath(&$array, $path)
  589. {
  590. $target =& $array;
  591. if ($path !== '/') {
  592. $pathArray = explode('/', $path);
  593. foreach ($pathArray as $node) {
  594. if (is_array($target) && isset($target[$node])) {
  595. $target =& $target[$node];
  596. } else {
  597. return null;
  598. }
  599. }
  600. }
  601. return $target;
  602. }
  603. /**
  604. * Multiply given $item by $value if non array
  605. *
  606. * @deprecated will delete in the next version
  607. * @param mixed $item (argument to change)
  608. * @param mixed $key (used with array_walk_recursive function as a key of given array)
  609. * @param string $value (contains float)
  610. * @return null
  611. */
  612. protected function _zoom(&$item, $key, $value)
  613. {
  614. if (is_string($item)) {
  615. $item = (int) round($item * $value);
  616. }
  617. }
  618. /**
  619. * Ensure $dir exists (if not then create one)
  620. *
  621. * @param string $dir
  622. * @throw Mage_Core_Exception
  623. */
  624. protected function _verifyDirExist($dir)
  625. {
  626. try {
  627. $ioFile = new Varien_Io_File();
  628. $ioFile->checkAndCreateFolder($dir);
  629. } catch (Exception $e) {
  630. Mage::throwException($e->getMessage());
  631. }
  632. }
  633. /**
  634. * Return customSizeUploadDir path
  635. *
  636. * @deprecated will delete in the next version
  637. * @param string $screenSize
  638. * @return string
  639. */
  640. public function getCustomSizeUploadDir($screenSize)
  641. {
  642. $screenSize = $this->filterScreenSize($screenSize);
  643. $customDir = $this->getMediaPath('custom' . DS . $screenSize);
  644. $this->_verifyDirExist($customDir);
  645. return $customDir;
  646. }
  647. /**
  648. * Return originalSizeUploadDir path
  649. *
  650. * @deprecated will delete in the next version
  651. * @return string
  652. */
  653. public function getOriginalSizeUploadDir()
  654. {
  655. $dir = $this->getMediaPath('original');
  656. $this->_verifyDirExist($dir);
  657. return $dir;
  658. }
  659. /**
  660. * Return oldUpload dir path (media/xmlconnect)
  661. *
  662. * @deprecated from 1.6.1.0
  663. * @return string
  664. */
  665. public function getOldUploadDir()
  666. {
  667. $dir = $this->getMediaPath();
  668. $this->_verifyDirExist($dir);
  669. return $dir;
  670. }
  671. /**
  672. * Return default size upload dir path
  673. *
  674. * @deprecated will delete in the next version
  675. * @return string
  676. */
  677. public function getDefaultSizeUploadDir()
  678. {
  679. return $this->getCustomSizeUploadDir(Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT);
  680. }
  681. /**
  682. * Return array for interface images paths in the config
  683. *
  684. * @deprecated will delete in the next version
  685. * @return array
  686. */
  687. public function getInterfaceImagesPathsConf()
  688. {
  689. if (!isset($this->_confPaths)) {
  690. $this->_confPaths = array();
  691. $paths = $this->getInterfaceImagesPaths();
  692. if (is_array($paths)) {
  693. $len = strlen('conf/native/');
  694. while (list($path,) = each($paths)) {
  695. $this->_confPaths[$path] = substr($path, $len);
  696. }
  697. }
  698. }
  699. return $this->_confPaths;
  700. }
  701. /**
  702. * Return
  703. * - default interface image path for specified $imagePath
  704. * - array of image paths
  705. *
  706. * @deprecated will delete in the next version
  707. * @param string $imagePath
  708. * @return array|string
  709. */
  710. public function getInterfaceImagesPaths($imagePath = null)
  711. {
  712. $paths = array (
  713. 'conf/native/navigationBar/icon' => 'smallIcon_1_6.png',
  714. 'conf/native/body/bannerImage' => 'banner_1_2.png',
  715. 'conf/native/body/bannerIpadLandscapeImage' => 'banner_ipad_l.png',
  716. 'conf/native/body/bannerIpadImage' => 'banner_ipad.png',
  717. 'conf/native/body/bannerAndroidImage' => 'banner_android.png',
  718. 'conf/native/body/backgroundImage' => 'accordion_open.png',
  719. 'conf/native/body/backgroundIpadLandscapeImage' => 'accordion_open_ipad_l.png',
  720. 'conf/native/body/backgroundIpadPortraitImage' => 'accordion_open_ipad_p.png',
  721. 'conf/native/body/backgroundAndroidLandscapeImage' => 'accordion_open_android_l.png',
  722. 'conf/native/body/backgroundAndroidPortraitImage' => 'accordion_open_android_p.png',
  723. );
  724. if ($imagePath == null) {
  725. return $paths;
  726. } else if (isset($paths[$imagePath])) {
  727. return $paths[$imagePath];
  728. } else {
  729. return null;
  730. }
  731. }
  732. /**
  733. * Check image and get full file path
  734. *
  735. * @deprecated will delete in the next version
  736. * @param string &$icon
  737. * @return bool
  738. */
  739. public function checkAndGetImagePath(&$icon)
  740. {
  741. $icon = basename($icon);
  742. if (is_file($this->getDefaultSizeUploadDir() . DS . $icon)) {
  743. $icon = $this->getDefaultSizeUploadDir() . DS . $icon;
  744. return true;
  745. }
  746. return false;
  747. }
  748. }