MODX Revolution PHP Cross Reference Content Management Systems

Source: /core/model/modx/processors/workspace/packages/rest/getlist.class.php - 123 lines - 4896 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * @package modx
   4   */
   5  class modPackageRemoteGetListProcessor extends modProcessor {
   6      /** @var modTransportProvider $provider */
   7      public $provider;
   8  
   9      public function checkPermissions() {
  10          return $this->modx->hasPermission('packages');
  11      }
  12  
  13      public function getLanguageTopics() {
  14          return array('workspace');
  15      }
  16  
  17      public function initialize() {
  18          $provider = $this->getProperty('provider',false);
  19          if (empty($provider)) return $this->modx->lexicon('provider_err_ns');
  20          $this->provider = $this->modx->getObject('transport.modTransportProvider',$provider);
  21          if (empty($this->provider)) return $this->modx->lexicon('provider_err_nf');
  22  
  23          $loaded = $this->provider->getClient();
  24          if (!$loaded) return $this->modx->lexicon('provider_err_no_client');
  25  
  26          $this->setDefaultProperties(array(
  27              'query' => false,
  28              'tag' => false,
  29              'sorter' => false,
  30              'start' => 0,
  31              'limit' => 10,
  32              'dateFormat' => '%b %d, %Y',
  33              'supportsSeparator' => ', ',
  34          ));
  35          $start = $this->getProperty('start');
  36          $limit = $this->getProperty('limit');
  37          $this->setProperty('page',!empty($start) ? round($start / $limit) : 0);
  38          return true;
  39      }
  40      
  41      public function process() {
  42          $data = $this->getData();
  43          if (!is_array($data)) {
  44              $this->failure($data);
  45          }
  46  
  47          $list = array();
  48          foreach ($data->package as $package) {
  49              if ((string)$package->name == '') continue;
  50              $list[] = $this->prepareRow($package);
  51          }
  52          return $this->outputArray($list,(int)$data['total']);
  53      }
  54  
  55  
  56      public function getData() {
  57          /* get version */
  58          $this->modx->getVersionData();
  59          $productVersion = $this->modx->version['code_name'].'-'.$this->modx->version['full_version'];
  60  
  61          /* send request and process response */
  62          $where = array(
  63              'page' => $this->getProperty('page'),
  64              'supports' => $productVersion,
  65              'sorter' => $this->getProperty('sorter'),
  66          );
  67          
  68          $tag = $this->getProperty('tag');
  69          if (!empty($tag)) $where['tag'] = $tag;
  70  
  71          $query = $this->getProperty('query');
  72          if (!empty($query)) $where['query'] = $query;
  73  
  74          /** @var modRestResponse $response */
  75          $response = $this->provider->request('package','GET',$where);
  76          if ($response->isError()) {
  77              return $this->modx->lexicon('provider_err_connect',array('error' => $response->getError()));
  78          }
  79          return $response->toXml();
  80      }
  81  
  82      public function prepareRow($package) {
  83          $installed = $this->modx->getObject('transport.modTransportPackage',(string)$package->signature);
  84  
  85          $versionCompiled = rtrim((string)$package->version.'-'.(string)$package->release,'-');
  86          $releasedon = strftime($this->getProperty('dateFormat'),strtotime((string)$package->releasedon));
  87  
  88          $supports = '';
  89          foreach ($package->supports as $support) {
  90              $supports .= (string)$support.$this->getProperty('supportsSeparator');
  91          }
  92  
  93          return array(
  94              'id' => (string)$package->id,
  95              'version' => (string)$package->version,
  96              'release' => (string)$package->release,
  97              'signature' => (string)$package->signature,
  98              'author' => (string)$package->author,
  99              'description' => (string)$package->description,
 100              'instructions' => (string)$package->instructions,
 101              'changelog' => (string)$package->changelog,
 102              'createdon' => (string)$package->createdon,
 103              'editedon' => (string)$package->editedon,
 104              'name' => (string)$package->name,
 105              'downloads' => number_format((integer)$package->downloads,0),
 106              'releasedon' => $releasedon,
 107              'screenshot' => (string)$package->screenshot,
 108              'thumbnail' => !empty($package->thumbnail) ? (string)$package->thumbnail : (string)$package->screenshot,
 109              'license' => (string)$package->license,
 110              'minimum_supports' => (string)$package->minimum_supports,
 111              'breaks_at' => (integer)$package->breaks_at != 10000000 ? (string)$package->breaks_at : '',
 112              'supports_db' => (string)$package->supports_db,
 113              'location' => (string)$package->location,
 114              'version-compiled' => $versionCompiled,
 115              'downloaded' => !empty($installed) ? true : false,
 116              'featured' => (boolean)$package->featured,
 117              'audited' => (boolean)$package->audited,
 118              'dlaction-icon' => $installed ? 'package-installed' : 'package-download',
 119              'dlaction-text' => $installed ? $this->modx->lexicon('downloaded') : $this->modx->lexicon('download'),
 120          );
 121      }
 122  }
 123  return 'modPackageRemoteGetListProcessor';

title

Description

title

Description

title

Description

title

title

Body