Protected Member Functions | |
_beforeSave () | |
_prependScopeInfo ($path) | |
_appendScopeInfo ($path) | |
_getAllowedExtensions () |
Definition at line 35 of file Image.php.
_appendScopeInfo | ( | $ | path | ) | [protected] |
Add scope info to path
E.g. 'path/stores/2' , 'path/websites/3', 'path/default'
string | $path |
Definition at line 133 of file Image.php.
00134 { 00135 $path .= '/' . $this->getScope(); 00136 if ('default' != $this->getScope()) { 00137 $path .= '/' . $this->getScopeId(); 00138 } 00139 return $path; 00140 }
_beforeSave | ( | ) | [protected] |
Save uploaded file before saving config value
Add scope info
Take root from config
Add scope info
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 43 of file Image.php.
00044 { 00045 $value = $this->getValue(); 00046 if (is_array($value) && !empty($value['delete'])) { 00047 $this->setValue(''); 00048 } 00049 00050 if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']){ 00051 00052 $fieldConfig = $this->getFieldConfig(); 00053 /* @var $fieldConfig Varien_Simplexml_Element */ 00054 00055 if (empty($fieldConfig->upload_dir)) { 00056 Mage::throwException(Mage::helper('catalog')->__('Base directory to upload image file is not specified')); 00057 } 00058 00059 $uploadDir = (string)$fieldConfig->upload_dir; 00060 00061 $el = $fieldConfig->descend('upload_dir'); 00062 00063 /** 00064 * Add scope info 00065 */ 00066 if (!empty($el['scope_info'])) { 00067 $uploadDir = $this->_appendScopeInfo($uploadDir); 00068 } 00069 00070 /** 00071 * Take root from config 00072 */ 00073 if (!empty($el['config'])) { 00074 $uploadRoot = (string)Mage::getConfig()->getNode((string)$el['config'], $this->getScope(), $this->getScopeId()); 00075 $uploadRoot = Mage::getConfig()->substDistroServerVars($uploadRoot); 00076 $uploadDir = $uploadRoot . '/' . $uploadDir; 00077 } 00078 00079 try { 00080 $file = array(); 00081 $file['tmp_name'] = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']; 00082 $file['name'] = $_FILES['groups']['name'][$this->getGroupId()]['fields'][$this->getField()]['value']; 00083 $uploader = new Varien_File_Uploader($file); 00084 $uploader->setAllowedExtensions($this->_getAllowedExtensions()); 00085 $uploader->setAllowRenameFiles(true); 00086 $uploader->save($uploadDir); 00087 } catch (Exception $e) { 00088 Mage::throwException($e->getMessage()); 00089 return $this; 00090 } 00091 00092 if ($filename = $uploader->getUploadedFileName()) { 00093 00094 /** 00095 * Add scope info 00096 */ 00097 if (!empty($el['scope_info'])) { 00098 $filename = $this->_prependScopeInfo($filename); 00099 } 00100 00101 $this->setValue($filename); 00102 } 00103 } 00104 00105 return $this; 00106 }
_getAllowedExtensions | ( | ) | [protected] |
Reimplemented in Mage_Adminhtml_Model_System_Config_Backend_Image_Pdf.
Definition at line 142 of file Image.php.
00143 { 00144 return array('jpg', 'jpeg', 'gif', 'png'); 00145 }
_prependScopeInfo | ( | $ | path | ) | [protected] |
Prepend path with scope info
E.g. 'stores/2/path' , 'websites/3/path', 'default/path'
string | $path |
Definition at line 116 of file Image.php.
00117 { 00118 $scopeInfo = $this->getScope(); 00119 if ('default' != $this->getScope()) { 00120 $scopeInfo .= '/' . $this->getScopeId(); 00121 } 00122 return $scopeInfo . '/' . $path; 00123 }