Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Connect_Adminhtml_Extension_CustomController
  • Mage_Connect_Adminhtml_Extension_LocalController
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Form
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Abstract
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Authors
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Contents
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Depends
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Grid
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Load
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Local
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Package
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tab_Release
  • Mage_Connect_Block_Adminhtml_Extension_Custom_Edit_Tabs
  • Mage_Connect_Helper_Data
  • Mage_Connect_Model_Extension
  • Mage_Connect_Model_Extension_Collection
  • Mage_Connect_Model_Session
  • Overview
  • Package
  • Class
  • Tree
  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@magentocommerce.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.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Connect
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Extension model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Connect
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Connect_Model_Extension extends Varien_Object
 36: {
 37:     /**
 38:     * Cache for targets
 39:     *
 40:     * @var array
 41:     */
 42:     protected $_targets;
 43: 
 44:     /**
 45:     * Internal cache for package
 46:     *
 47:     * @var Mage_Connect_Package
 48:     */
 49:     protected $_package;
 50: 
 51:     /**
 52:      * Return package object
 53:      *
 54:      * @return Mage_Connect_Package
 55:      */
 56:     protected function getPackage()
 57:     {
 58:         if (!$this->_package instanceof Mage_Connect_Package) {
 59:             $this->_package = new Mage_Connect_Package();
 60:         }
 61:         return $this->_package;
 62:     }
 63: 
 64:     /**
 65:     * Set package object.
 66:     *
 67:     * @return Mage_Connect_Model_Extension
 68:     */
 69:     public function generatePackageXml()
 70:     {
 71:         Mage::getSingleton('connect/session')
 72:             ->setLocalExtensionPackageFormData($this->getData());
 73: 
 74:         $this->_setPackage()
 75:             ->_setRelease()
 76:             ->_setAuthors()
 77:             ->_setDependencies()
 78:             ->_setContents();
 79:         if (!$this->getPackage()->validate()) {
 80:             $message = $this->getPackage()->getErrors();
 81:             throw Mage::exception('Mage_Core', Mage::helper('connect')->__($message[0]));
 82:         }
 83:         $this->setPackageXml($this->getPackage()->getPackageXml());
 84:         return $this;
 85:     }
 86: 
 87:     /**
 88:     * Set general information.
 89:     *
 90:     * @return Mage_Connect_Model_Extension
 91:     */
 92:     protected function _setPackage()
 93:     {
 94:         $this->getPackage()
 95:             ->setName($this->getData('name'))
 96:             ->setChannel($this->getData('channel'))
 97:             ->setLicense($this->getData('license'), $this->getData('license_uri'))
 98:             ->setSummary($this->getData('summary'))
 99:             ->setDescription($this->getData('description'));
100:         return $this;
101:     }
102: 
103:     /**
104:     * Set release information
105:     *
106:     * @return Mage_Connect_Model_Extension
107:     */
108:     protected function _setRelease()
109:     {
110:         $this->getPackage()
111:             ->setDate(date('Y-m-d'))
112:             ->setTime(date('H:i:s'))
113:             ->setVersion($this->getData('version')?$this->getData('version'):$this->getData('release_version'))
114:             ->setStability($this->getData('stability'))
115:             ->setNotes($this->getData('notes'));
116:         return $this;
117:     }
118: 
119:     /**
120:     * Set authors
121:     *
122:     * @return Mage_Connect_Model_Extension
123:     */
124:     protected function _setAuthors()
125:     {
126:         $authors = $this->getData('authors');
127:         foreach ($authors['name'] as $i => $name) {
128:             $user  = $authors['user'][$i];
129:             $email = $authors['email'][$i];
130:             $this->getPackage()->addAuthor($name, $user, $email);
131:         }
132:         return $this;
133:     }
134: 
135: 
136:     protected function packageFilesToArray($filesString)
137:     {
138:         $packageFiles = array();
139:         if($filesString) {
140:             $filesArray = preg_split("/[\n\r]+/", $filesString);
141:             foreach($filesArray as $file) {
142:                 $file = trim($file, "/");
143:                 $res = explode(DIRECTORY_SEPARATOR, $file, 2);
144:                 array_map('trim', $res);
145:                 if(2 == count($res)) {
146:                     $packageFiles[] = array('target'=>$res[0], 'path'=>$res[1]);
147:                 }
148:             }
149:         }
150:         return $packageFiles;
151:     }
152: 
153:     /**
154:     * Set php, php extensions, another packages dependencies
155:     *
156:     * @return Mage_Connect_Model_Extension
157:     */
158:     protected function _setDependencies()
159:     {
160:         $this->getPackage()
161:             ->clearDependencies()
162:             ->setDependencyPhpVersion($this->getData('depends_php_min'), $this->getData('depends_php_max'));
163: 
164:         foreach ($this->getData('depends') as $deptype=>$deps) {
165:             foreach ($deps['name'] as $i=>$type) {
166:                 if (0===$i) {
167:                     continue;
168:                 }
169:                 $name = $deps['name'][$i];
170:                 $min = !empty($deps['min'][$i]) ? $deps['min'][$i] : false;
171:                 $max = !empty($deps['max'][$i]) ? $deps['max'][$i] : false;
172: 
173:                 $files = !empty($deps['files'][$i]) ? $deps['files'][$i] : false;
174:                 $packageFiles = $this->packageFilesToArray($files);
175: 
176:                 if ($deptype !== 'extension') {
177:                     $channel = !empty($deps['channel'][$i])
178:                         ? $deps['channel'][$i]
179:                         : 'connect.magentocommerce.com/core';
180:                 }
181:                 switch ($deptype) {
182:                     case 'package':
183:                         $this->getPackage()->addDependencyPackage($name, $channel, $min, $max, $packageFiles);
184:                         break;
185: 
186:                     case 'extension':
187:                         $this->getPackage()->addDependencyExtension($name, $min, $max);
188:                         break;
189:                 }
190:             }
191:         }
192:         return $this;
193:     }
194: 
195:     /**
196:     * Set contents. Add file or entire directory.
197:     *
198:     * @return Mage_Connect_Model_Extension
199:     */
200:     protected function _setContents()
201:     {
202:         $this->getPackage()->clearContents();
203:         $contents = $this->getData('contents');
204:         foreach ($contents['target'] as $i=>$target) {
205:             if (0===$i) {
206:                 continue;
207:             }
208:             switch ($contents['type'][$i]) {
209:                 case 'file':
210:                     $this->getPackage()->addContent($contents['path'][$i], $contents['target'][$i]);
211:                     break;
212: 
213:                 case 'dir':
214:                     $target = $contents['target'][$i];
215:                     $path = $contents['path'][$i];
216:                     $include = $contents['include'][$i];
217:                     $ignore = $contents['ignore'][$i];
218:                     $this->getPackage()->addContentDir($target, $path, $ignore, $include);
219:                     break;
220:             }
221:         }
222:         return $this;
223:     }
224: 
225:     /**
226:     * Save package file to var/connect.
227:     *
228:     * @return boolean
229:     */
230:     public function savePackage()
231:     {
232:         if ($this->getData('file_name') != '') {
233:             $fileName = $this->getData('file_name');
234:             $this->unsetData('file_name');
235:         } else {
236:             $fileName = $this->getName();
237:         }
238: 
239:         if (!preg_match('/^[a-z0-9]+[a-z0-9\-\_\.]*([\/\\\\]{1}[a-z0-9]+[a-z0-9\-\_\.]*)*$/i', $fileName)) {
240:             return false;
241:         }
242: 
243:         if (!$this->getPackageXml()) {
244:             $this->generatePackageXml();
245:         }
246:         if (!$this->getPackageXml()) {
247:             return false;
248:         }
249: 
250:         $path = Mage::helper('connect')->getLocalPackagesPath();
251:         if (!@file_put_contents($path . 'package.xml', $this->getPackageXml())) {
252:             return false;
253:         }
254: 
255:         $this->unsPackageXml();
256:         $this->unsTargets();
257:         $xml = Mage::helper('core')->assocToXml($this->getData());
258:         $xml = new Varien_Simplexml_Element($xml->asXML());
259: 
260:         // prepare dir to save
261:         $parts = explode(DS, $fileName);
262:         array_pop($parts);
263:         $newDir = implode(DS, $parts);
264:         if ((!empty($newDir)) && (!is_dir($path . $newDir))) {
265:             if (!@mkdir($path . $newDir, 0777, true)) {
266:                 return false;
267:             }
268:         }
269: 
270:         if (!@file_put_contents($path . $fileName . '.xml', $xml->asNiceXml())) {
271:             return false;
272:         }
273: 
274:         return true;
275:     }
276: 
277:     /**
278:     * Create package file
279:     *
280:     * @return boolean
281:     */
282:     public function createPackage()
283:     {
284:         $path = Mage::helper('connect')->getLocalPackagesPath();
285:         if (!Mage::getConfig()->createDirIfNotExists($path)) {
286:             return false;
287:         }
288:         if (!$this->getPackageXml()) {
289:             $this->generatePackageXml();
290:         }
291:         $this->getPackage()->save($path);
292:         return true;
293:     }
294: 
295:     /**
296:     * Create package file compatible with previous version of Magento Connect Manager
297:     *
298:     * @return boolean
299:     */
300:     public function createPackageV1x()
301:     {
302:         $path = Mage::helper('connect')->getLocalPackagesPathV1x();
303:         if (!Mage::getConfig()->createDirIfNotExists($path)) {
304:             return false;
305:         }
306:         if (!$this->getPackageXml()) {
307:             $this->generatePackageXml();
308:         }
309:         $this->getPackage()->saveV1x($path);
310:         return true;
311:     }
312: 
313:     /**
314:     * Retrieve stability value and name for options
315:     *
316:     * @return array
317:     */
318:     public function getStabilityOptions()
319:     {
320:         return array(
321:             'devel'     => 'Development',
322:             'alpha'     => 'Alpha',
323:             'beta'      => 'Beta',
324:             'stable'    => 'Stable',
325:         );
326:     }
327: 
328:     /**
329:     * Retrieve targets
330:     *
331:     * @return array
332:     */
333:     public function getLabelTargets()
334:     {
335:         if (!is_array($this->_targets)) {
336:             $objectTarget = new Mage_Connect_Package_Target();
337:             $this->_targets = $objectTarget->getLabelTargets();
338:         }
339:         return $this->_targets;
340:     }
341: 
342: }
343: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0