├── .gitignore ├── core └── components │ └── modxrepository │ ├── docs │ ├── license.txt │ ├── readme.txt │ └── changelog.txt │ ├── elements │ ├── .gitignore │ └── plugins │ │ └── modxrepository.plugin.php │ ├── templates │ └── default │ │ └── index.tpl │ └── processors │ └── rest │ ├── verify.class.php │ ├── package │ ├── update.class.php │ ├── preparerow.class.php │ └── getpackages.class.php │ ├── download │ └── index.class.php │ ├── home.class.php │ ├── response.class.php │ ├── repository │ ├── getnodes.class.php │ └── getrepositories.class.php │ ├── repository.class.php │ └── package.class.php ├── assets └── components │ └── modxrepository │ └── packages │ └── .gitignore └── _build ├── data ├── transport.plugins.events.php ├── transport.plugins.php ├── transport.settings.php ├── transport.mediasources.php └── transport.templates.php ├── includes └── functions.php ├── build.config.sample.php ├── resolvers └── resolve.update_objects.php ├── build.transport.php └── setup.options.php /.gitignore: -------------------------------------------------------------------------------- 1 | .git 2 | /_build/build.config.php -------------------------------------------------------------------------------- /core/components/modxrepository/docs/license.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /assets/components/modxrepository/packages/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /core/components/modxrepository/elements/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /core/components/modxrepository/templates/default/index.tpl: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /core/components/modxrepository/docs/readme.txt: -------------------------------------------------------------------------------- 1 | modxRepository by Fi1osof 2 | http://community.modx-cms.ru/profile/Fi1osof/ 3 | http://modxstore.ru 4 | ======================================================== 5 | 6 | This MODX Extra allow to create own repository for MODX Revolution packages 7 | -------------------------------------------------------------------------------- /_build/data/transport.plugins.events.php: -------------------------------------------------------------------------------- 1 | newObject('modPluginEvent'); 13 | $events['OnHandleRequest']->fromArray(array( 14 | 'event' => 'OnHandleRequest', 15 | 'priority' => 0, 16 | 'propertyset' => 0, 17 | ),'',true,true); 18 | 19 | return $events; -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/verify.class.php: -------------------------------------------------------------------------------- 1 | '; 10 | 11 | public function process(){ 12 | $result = array( 13 | 'verified' => 1, 14 | ); 15 | 16 | return $this->toXML($result); 17 | } 18 | } 19 | return 'modxRepositoryVerify'; 20 | ?> 21 | -------------------------------------------------------------------------------- /core/components/modxrepository/docs/changelog.txt: -------------------------------------------------------------------------------- 1 | modxRepository-1.2.3-beta 2 | ============================================================= 3 | 1. modxRepositoryProcessor::__construct bugfix 4 | 5 | 6 | modxRepository-1.2.2-beta 7 | ============================================================= 8 | 1. Get packages DB-request bugfix 9 | 10 | 11 | modxRepository-1.2.1-beta 12 | ============================================================= 13 | 1. getRepositories processor optimization 14 | 15 | 16 | modxRepository-1.2.0-beta 17 | ============================================================= 18 | 1. Added multi-contexts solution 19 | 2. Install repository bugfix 20 | 3. Minor bugfix 21 | 22 | 23 | modxRepository-1.1.0-beta 24 | ============================================================= 25 | First release -------------------------------------------------------------------------------- /_build/data/transport.plugins.php: -------------------------------------------------------------------------------- 1 | newObject('modPlugin'); 13 | $plugin->set('id', null); 14 | $plugin->set('name', 'modxRepository'); 15 | $plugin->set('description', ''); 16 | $plugin->set('plugincode', getSnippetContent($sources['source_core'].'/elements/plugins/modxrepository.plugin.php')); 17 | 18 | 19 | /* add plugin events */ 20 | $events = include $sources['data'].'transport.plugins.events.php'; 21 | if (is_array($events) && !empty($events)) { 22 | $plugin->addMany($events, 'PluginEvents'); 23 | $modx->log(xPDO::LOG_LEVEL_INFO,'Packaged in '.count($events).' Plugin Events.'); flush(); 24 | } else { 25 | $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find plugin events!'); 26 | } 27 | 28 | $plugins[] = $plugin; 29 | 30 | return $plugins; 31 | -------------------------------------------------------------------------------- /_build/data/transport.settings.php: -------------------------------------------------------------------------------- 1 | newObject('modSystemSetting'); 14 | $settings['modxRepository.handler_doc_id']->fromArray(array( 15 | 'key' => 'modxRepository.handler_doc_id', 16 | 'value' => '', 17 | 'xtype' => 'textfield', 18 | 'namespace' => 'modxrepository', 19 | 'area' => 'site', 20 | ),'',true,true); 21 | 22 | 23 | $settings['modxRepository.request_path'] = $modx->newObject('modSystemSetting'); 24 | $settings['modxRepository.request_path']->fromArray(array( 25 | 'key' => 'modxRepository.request_path', 26 | 'value' => 'extras/', 27 | 'xtype' => 'textfield', 28 | 'namespace' => 'modxrepository', 29 | 'area' => 'site', 30 | ),'',true,true); 31 | 32 | 33 | return $settings; -------------------------------------------------------------------------------- /_build/data/transport.mediasources.php: -------------------------------------------------------------------------------- 1 | array( 14 | "name" => "basePath", 15 | "desc" => "prop_file.basePath_desc", 16 | "type" => "textfield", 17 | "options" => Array(), 18 | "value" => "assets/components/modxrepository/packages/", 19 | "lexicon" => "core:source", 20 | ), 21 | "baseUrl" => Array 22 | ( 23 | "name" => "baseUrl", 24 | "desc" => "prop_file.baseUrl_desc", 25 | "type" => "textfield", 26 | "options" => Array(), 27 | "value" => "assets/components/modxrepository/packages/", 28 | "lexicon" => "core:source", 29 | ) 30 | ); 31 | 32 | $mediaSource = $modx->newObject('sources.modMediaSource', array( 33 | 'name' => 'Repository Packages', 34 | 'class_key' => 'sources.modFileMediaSource', 35 | 'description' => 'Source for Repository packages', 36 | 'properties' => $params, 37 | )); 38 | 39 | $mediaSources[] = $mediaSource; 40 | 41 | 42 | return $mediaSources; 43 | 44 | ?> 45 | -------------------------------------------------------------------------------- /_build/includes/functions.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * modExtra is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation; either version 2 of the License, or (at your option) any later 10 | * version. 11 | * 12 | * modExtra is distributed in the hope that it will be useful, but WITHOUT ANY 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 14 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * modExtra; if not, write to the Free Software Foundation, Inc., 59 Temple 18 | * Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | * @package modextra 21 | */ 22 | /** 23 | * Helper method for grabbing files 24 | * 25 | * @package modextra 26 | * @subpackage build 27 | */ 28 | 29 | /** 30 | * @param string $filename 31 | * @return mixed|string 32 | */ 33 | function getSnippetContent($filename) { 34 | // print "
Try to open file: {$filename}
\n"; 35 | $o = file_get_contents($filename); 36 | $o = str_replace('','',$o); 38 | $o = trim($o); 39 | return $o; 40 | } -------------------------------------------------------------------------------- /_build/build.config.sample.php: -------------------------------------------------------------------------------- 1 | $root, 28 | 'build' => $root . '_build/', 29 | 'data' => $root . '_build/data/', 30 | 'resolvers' => $root . '_build/resolvers/', 31 | 'chunks' => $root.'core/components/'.PKG_PATH.'/elements/chunks/', 32 | 'snippets' => $root.'core/components/'.PKG_PATH.'/elements/snippets/', 33 | 'plugins' => $root.'core/components/'.PKG_PATH.'/elements/plugins/', 34 | 'lexicon' => $root . 'core/components/'.PKG_PATH.'/lexicon/', 35 | 'docs' => $root.'core/components/'.PKG_PATH.'/docs/', 36 | 'pages' => $root.'core/components/'.PKG_PATH.'/elements/pages/', 37 | 'source_assets' => $root.'assets/components/'.PKG_PATH, 38 | 'source_core' => $root.'core/components/'.PKG_PATH, 39 | 'templates' => $root.'core/components/'.PKG_PATH.'/elements/templates/', 40 | 'model' => $root.'core/components/'.PKG_PATH.'/model/', 41 | ); 42 | unset($root); 43 | 44 | 45 | require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; 46 | require_once $sources['build'] . '/includes/functions.php'; 47 | 48 | $modx= new modX(); 49 | $modx->initialize('mgr'); -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/package/update.class.php: -------------------------------------------------------------------------------- 1 | '; 10 | 11 | function process(){ 12 | if(!$signature = $this->properties['signature']){ 13 | $this->failure('Не была получена подпись пакета'); 14 | return; 15 | } 16 | 17 | $updates = array(); 18 | 19 | 20 | // Получаем список всех более новых версий пакета 21 | if(!$current = $this->modx->getObject('modResource', array( 22 | 'pagetitle' => $signature, 23 | 'published' => true, 24 | 'deleted' => false, 25 | ))){ 26 | $this->failure('Не был получен текущий пакет'); 27 | return; 28 | } 29 | 30 | /* 31 | * Получаем все более новые пакеты 32 | */ 33 | 34 | $response = $this->runProcessor('package/getpackages', array( 35 | 'where' => array( 36 | 'r.parent' => $current->parent, 37 | 'r.id:!=' => $current->id, 38 | 'r.createdon:>' => $current->createdon, 39 | ), 40 | 'sort' => array('r.publishedon, DESC'), 41 | )); 42 | 43 | if($result = $response->getResponse()){ 44 | foreach($result as $r){ 45 | $updates[] = array( 46 | 'package' => $this->preparePackageRow($r), 47 | ); 48 | } 49 | } 50 | return $this->toXML($updates, array( 51 | 'total' => ($result?count($result):0), 52 | )); 53 | } 54 | 55 | 56 | function preparePackageRow($data){ 57 | $response = $this->runProcessor('package/preparerow', $data); 58 | return $response->getResponse(); 59 | } 60 | } 61 | 62 | return 'modxRepositoryPackageUpdate'; 63 | ?> 64 | -------------------------------------------------------------------------------- /core/components/modxrepository/elements/plugins/modxrepository.plugin.php: -------------------------------------------------------------------------------- 1 | context->key == 'mgr') return; 10 | if(!$modx->checkSiteStatus()) return; 11 | if(!$request_path = $modx->getOption('modxRepository.request_path', $scriptProperties, false)){ 12 | return; 13 | } 14 | 15 | $request = new modRequest($modx); 16 | 17 | $resourceIdentifier = $request->getResourceIdentifier("alias"); 18 | 19 | /* 20 | * Check for repository path 21 | */ 22 | 23 | if(strpos($resourceIdentifier, $request_path) !== 0){ 24 | return; 25 | } 26 | 27 | if(!$action = substr($resourceIdentifier, strlen($request_path))){ 28 | return; 29 | } 30 | // Get processors path 31 | if(!$ns = $modx->getObject('modNamespace', 'modxrepository')){ 32 | $modx->log(xPDO::LOG_LEVEL_ERROR, "Не было пролучено пространство имен modxrepository"); 33 | return; 34 | } 35 | $processors_path = $ns->getCorePath().'processors/'; 36 | 37 | $options = array( 38 | 'processors_path' => $processors_path, 39 | 'location' => 'rest', 40 | ); 41 | 42 | if (!isset($_POST)) $_POST = array(); 43 | if (!isset($_GET)) $_GET = array(); 44 | $scriptProperties = array_merge($_GET,$_POST, array( 45 | 'handler_doc_id' => $modx->getOption('modxRepository.handler_doc_id', null, false), 46 | )); 47 | 48 | $actionArray = explode('/', $action); 49 | 50 | if(count($actionArray) > 1){ 51 | switch($actionArray[0]){ 52 | case 'repository':; 53 | $action = 'repository/getnodes'; 54 | $scriptProperties = array_merge($scriptProperties, array( 55 | 'repository_id' => $actionArray[1], 56 | )); 57 | break; 58 | case 'download': 59 | $action = 'download/index'; 60 | break; 61 | default :; 62 | } 63 | } 64 | 65 | if(!$response = $modx->runProcessor($action, $scriptProperties, $options)){ 66 | $modx->log(xPDO::LOG_LEVEL_ERROR, "Не было пролучено пространство имен modxrepository"); 67 | return; 68 | } 69 | 70 | print $response->getResponse(); 71 | exit; -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/download/index.class.php: -------------------------------------------------------------------------------- 1 | properties['getUrl'] == true){ 13 | return $this->getFileUrl($this->properties['id']); 14 | } 15 | return; 16 | } 17 | 18 | function getFileUrl($id){ 19 | if(empty($id)){ 20 | $this->failure('Не был получен ID пакета'); 21 | return; 22 | } 23 | 24 | 25 | $response = $this->runProcessor('package/getpackages', array( 26 | 'where' => array( 27 | 'r_object_id.value' => $id, 28 | ), 29 | 'limit' => 1, 30 | 'group' => array('package_id'), 31 | 'sort' => array('r.publishedon, DESC'), 32 | )); 33 | 34 | if(!$result = $response->getResponse()){ 35 | $this->failure("Не был получен пакет"); 36 | return; 37 | } 38 | 39 | $package = current($result); 40 | 41 | # $this->modx->log(1, print_r($id, 1)); 42 | # $this->modx->log(1, print_r($package, 1)); 43 | 44 | $url = $this->modx->getOption('site_url', null); 45 | 46 | $q = $this->modx->newQuery('modTemplateVar'); 47 | $q->innerJoin('modTemplateVarResource', 'v', 'v.tmplvarid = modTemplateVar.id'); 48 | $q->where(array( 49 | 'v.id' => $package['file_id'], 50 | )); 51 | $tv = $this->modx->getObject('modTemplateVar', $q); 52 | $package_url = $tv->renderOutput($package['r_content_id']); 53 | $package_url = preg_replace('/^\//','',$package_url); 54 | $url .= $package_url; 55 | 56 | 57 | // Count downloads 58 | if( 59 | !empty($package['r_content_id']) 60 | AND $resource = $this->modx->getObject('modResource', $package['r_content_id']) 61 | ){ 62 | $count = (int)$resource->getTVValue('downloads'); 63 | $resource->setTVValue('downloads', $count + 1); 64 | } 65 | 66 | return $url; 67 | } 68 | } 69 | 70 | return 'modxRepositoryDownload'; 71 | ?> 72 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/package/preparerow.class.php: -------------------------------------------------------------------------------- 1 | preparePackageRow($this->properties); 9 | } 10 | 11 | function preparePackageRow($data){ 12 | $varsArray = array(); 13 | $vers = array( 14 | 'version_major', 15 | 'version_minor', 16 | 'version_patch' 17 | ); 18 | foreach($vers as $v){ 19 | if(isset($data[$v]))$varsArray[] = ($data[$v] ? $data[$v] : '0'); 20 | } 21 | $version = implode(".", $varsArray); 22 | 23 | $vrelease = $data['release']. ($data['vrelease_index'] ? "-{$data['vrelease_index']}" : ""); 24 | 25 | return array( 26 | 'id' => $data['release_id'], 27 | 'r_content_id' => $data['r_content_id'], 28 | 'package' => $data['object_id'], 29 | 'display_name' => $data['release_name'], 30 | 'name' => $data['pagetitle'], 31 | 'version' => $version, 32 | 'version_major' => $varsArray[0], 33 | 'version_minor' => $varsArray[1], 34 | 'version_patch' => $varsArray[2], 35 | 'release' => $data['release'], 36 | 'vrelease' => $vrelease, 37 | 'vrelease_index' => $data['vrelease_index'], 38 | 'author' => $data['author'], 39 | 'description' => "{$data['release_description']}", 40 | 'instructions' => "{$data['instructions']}", 41 | 'changelog' => "{$data['changelog']}", 42 | 'createdon' => date('Y-m-d H:i:s', $data['release_createdon']), 43 | 'createdby' => $data['author'], 44 | 'editedon' => date('Y-m-d H:i:s', $data['release_editedon']), 45 | 'approved' => 1, 46 | 'audited' => 1, 47 | 'featured' => 1, 48 | 'deprecated' => '', 49 | 'license' => '', 50 | 'smf_url' => '', 51 | 'repository' => '', 52 | 'supports' => '', 53 | 'supports' => '2.0', 54 | 'location' => $this->modx->getOption('site_url'). $this->modx->getOption('modxRepository.request_path')."download/?id={$data['release_id']}", 55 | 'signature' => $data['release_name'], 56 | 'supports_db' => 'mysql', 57 | 'minimum_supports' => '2.0', 58 | 'breaks_at' => 10000000.0, 59 | 'screenshot' => $data['screenshot'], 60 | 'releasedon' => date('Y-m-d H:i:s', $data['release_createdon']), 61 | 'downloads' => isset($data['downloads']) ? $data['downloads'] : 0, 62 | ); 63 | } 64 | } 65 | 66 | return 'modxRepositoryPackagePrepareRow'; 67 | ?> 68 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/home.class.php: -------------------------------------------------------------------------------- 1 | '; 10 | 11 | public function process(){ 12 | $data = $this->getData(); 13 | 14 | return $this->toXML($data); 15 | } 16 | 17 | public function getData(){ 18 | $result = array( ); 19 | 20 | $url = $this->modx->getOption('site_url', null); 21 | $url .= $this->modx->getOption('modxRepository.request_path', null).'package/'; 22 | $result['url'] = $url; 23 | 24 | // Получаем новейшие пакеты 25 | if($newest = $this->getNewest()){ 26 | foreach($newest as $n){ 27 | $package = $this->preparePackageRow($n); 28 | $result[] = array( 29 | 'newest' => array( 30 | 'id' => $package['id'], 31 | 'name' => "{$package['name']} {$package['version']}-{$package['vrelease']} ", 32 | 'package_name' => $package['name'], 33 | 'releasedon' => $package['releasedon'], 34 | ), 35 | ); 36 | } 37 | } 38 | 39 | 40 | // Получаем самые популярные 41 | if($popular = $this->getPopular()){ 42 | foreach($popular as $n){ 43 | $package = $this->preparePackageRow($n); 44 | $result[] = array( 45 | 'topdownloaded' => array( 46 | 'id' => $package['id'], 47 | 'name' => $package['name'], 48 | 'downloads' => $package['downloads'], 49 | ), 50 | ); 51 | } 52 | } 53 | 54 | 55 | if(!empty($newest)) $result['packages'] = count($newest); 56 | return $result; 57 | } 58 | 59 | function getNewest(){ 60 | $response = $this->runProcessor('package/getpackages', array( 61 | 'where' => array( 62 | ), 63 | 'sort' => array('releasedon, DESC'), 64 | 'group' => array('package_id'), 65 | 'limit' => 10, 66 | 'root' => $this->getProperty('handler_doc_id'), 67 | )); 68 | 69 | if($result = $response->getResponse()){ 70 | foreach($result as $r){ 71 | $updates[] = array( 72 | 'package' => $this->preparePackageRow($r), 73 | ); 74 | } 75 | } 76 | 77 | return $result; 78 | } 79 | 80 | function getPopular(){ 81 | return $this->getNewest(); 82 | } 83 | 84 | function preparePackageRow($data){ 85 | $response = $this->runProcessor('package/preparerow', $data); 86 | return $response->getResponse(); 87 | } 88 | } 89 | return 'modxRepositoryHome'; 90 | ?> 91 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/response.class.php: -------------------------------------------------------------------------------- 1 | getObject('modNamespace', 'modxrepository')){ 15 | $err = "Не было получено пространство имен modxrepository"; 16 | $modx->log(xPDO::LOG_LEVEL_ERROR, $err); 17 | $this->failure($err); 18 | return; 19 | } 20 | 21 | // Get processors params 22 | $this->processorsParams = array( 23 | 'processors_path' => $ns->getCorePath().'processors/', 24 | 'location' => 'rest/', 25 | ); 26 | 27 | /* 28 | * Be sure you set system setting modxRepository.handler_doc_id 29 | */ 30 | if(!$this->parent = $modx->getOption('modxRepository.handler_doc_id', null, false)){ 31 | return $modx->log( xPDO::LOG_LEVEL_ERROR, 'Please, be sure you set system setting modxRepository.handler_doc_id'); 32 | } 33 | } 34 | 35 | public function runProcessor($action, $scriptProperties = array()){ 36 | if(!$this->processorsParams){ 37 | $this->failure("Не были получены данные процессоров"); 38 | return false; 39 | } 40 | return $this->modx->runProcessor($action, $scriptProperties, $this->processorsParams); 41 | } 42 | } 43 | 44 | abstract class modxRepositoryResponse extends modxRepositoryProcessor{ 45 | var $root = ''; 46 | 47 | public function toXML($response, $rootParams = array()){ 48 | header('Content-type:text/xml', 1); 49 | $response = (array)$response; 50 | $xml = new SimpleXMLElement($this->root); 51 | foreach($rootParams as $k => $v){ 52 | $xml->addAttribute($k, $v); 53 | } 54 | $this->array_to_xml($response, $xml); 55 | return $xml->asXML(); 56 | } 57 | 58 | function array_to_xml($arr, & $xml) 59 | { 60 | foreach ($arr as $k => $v) { 61 | if(is_numeric($k)){ 62 | $this->array_to_xml($v, $xml); 63 | } 64 | else if(is_array($v)){ 65 | $this->array_to_xml($v, $xml->addChild($k)); 66 | } 67 | else{ 68 | $node = $xml->addChild($k, $v); 69 | if(is_string($v)){ 70 | $type = 'string'; 71 | } 72 | else if(is_float($v)){ 73 | $type = 'float'; 74 | } 75 | else if(is_numeric($v)){ 76 | $type = 'integer'; 77 | } 78 | else{ 79 | $type = false; 80 | } 81 | if($type) $node->addAttribute('type', $type); 82 | } 83 | } 84 | return $xml; 85 | } 86 | } 87 | 88 | return 'modxRepositoryProcessor'; 89 | ?> 90 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/repository/getnodes.class.php: -------------------------------------------------------------------------------- 1 | '; 10 | var $repository_id = null; 11 | var $TVs = array(); 12 | 13 | function process(){ 14 | 15 | /* 16 | * Получаем ID 17 | */ 18 | if(!$this->repository_id = $this->properties['repository_id']){ 19 | return $this->failure('Не был получен ID репозитория'); 20 | } 21 | 22 | /* 23 | * Получаем текущий репозиторий 24 | */ 25 | if(!$repositories = $this->getRepositories(array( 26 | 'object_id.value' => $this->repository_id, 27 | ))){ 28 | return $this->failure('Не был получен репозиторий'); 29 | } 30 | 31 | if($this->hasErrors()){ 32 | return false; 33 | } 34 | 35 | $repositoryObject = current($repositories); 36 | $repository = $this->prepareRepositoryRow( $repositoryObject->toArray()); 37 | 38 | /* 39 | * Собираем дочерние репы 40 | */ 41 | $repositories = $this->getRepositories(array( 42 | "modResource.parent" => $repositoryObject->id, 43 | )); 44 | if(!$this->hasErrors()){ 45 | foreach($repositories as $r){ 46 | $repository[] = array( 47 | 'tag' => $this->prepareTagRow($r->toArray()), 48 | ); 49 | } 50 | } 51 | 52 | return $this->toXML($repository); 53 | } 54 | 55 | 56 | function prepareTagRow($data){ 57 | /* 58 | * $data 59 | */ 60 | return array( 61 | 'id' => $data['object_id'], 62 | 'name' => $data['pagetitle'], 63 | 'packages' => 0, 64 | 'templated' => !empty($data['templated']) ? $data['templated'] : 0, 65 | ); 66 | } 67 | 68 | 69 | /* 70 | * Получаем информацию по репозиторию 71 | */ 72 | function getRepositories($where = array(), $limit = 0){ 73 | $scriptProperties = array_merge($this->properties, array( 74 | 'where' => $where, 75 | 'limit' => $limit, 76 | )); 77 | 78 | $result = $this->runProcessor('repository/getrepositories', $scriptProperties); 79 | 80 | return $result->getResponse(); 81 | } 82 | 83 | 84 | function prepareRepositoryRow($data){ 85 | return array( 86 | 'description' => "{$data['description']}>", 87 | 'templated' => !empty($data['templated']) ? $data['templated'] : 0, 88 | 'rank' => $data['menuindex'], 89 | 'packages' => 3, 90 | 'createdon' => $data['createdon'], 91 | 'name' => $data['pagetitle'], 92 | 'id' => $data['object_id'], 93 | ); 94 | } 95 | 96 | 97 | 98 | } 99 | return 'modxRepositoryHome'; 100 | ?> 101 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/repository/getrepositories.class.php: -------------------------------------------------------------------------------- 1 | getTVs(); 17 | 18 | if($this->hasErrors()){ 19 | return false; 20 | } 21 | 22 | $where = (array)$this->properties['where']; 23 | $limit = ($this->properties['limit'] ? $this->properties['limit'] : 0); 24 | return $this->getData($where, $limit); 25 | } 26 | 27 | 28 | function getTVs(){ 29 | // Получаем ID TV-шек 30 | $TVsNames = array( 31 | 'templated', 32 | 'object_id' 33 | ); 34 | 35 | if(!$result = $this->modx->getCollection('modTemplateVar', array( 36 | 'name:IN' => $TVsNames, 37 | ))){ 38 | return $this->failure('Не были получены TV-параметры'); 39 | } 40 | 41 | foreach($result as $r){ 42 | $this->TVs[$r->name] = $r->id; 43 | } 44 | return $this->TVs; 45 | } 46 | 47 | function getData($where = array(), $limit = 0){ 48 | $context_key = $this->modx->context->get('key'); 49 | 50 | /* 51 | * If root exists, get repositories parents 52 | */ 53 | $parents = array(); 54 | if($root = $this->getProperty('root')){ 55 | $q = $this->modx->newQuery('modResource'); 56 | $q->select(array('modResource.id')); 57 | $q->where(array( 58 | 'modResource.published' => true, 59 | 'modResource.deleted' => false, 60 | 'modResource.hidemenu' => false, 61 | 'modResource.parent' => $root, 62 | 'context_key' => $context_key, 63 | )); 64 | if(!$q->prepare() OR !$q->stmt->execute() OR !$result = $q->stmt->FetchAll(PDO::FETCH_ASSOC)){ 65 | $this->failure('Failure get repositories parents'); 66 | } 67 | foreach($result as $r){ 68 | $parents[] = $r['id']; 69 | } 70 | } 71 | 72 | /* 73 | * Get Repositories 74 | */ 75 | $q = $this->modx->newQuery('modResource'); 76 | $q->innerJoin('modTemplateVarResource', 'object_id', "object_id.contentid = modResource.id"); 77 | $q->innerJoin('modTemplate', 'tpl', "tpl.id = modResource.template"); 78 | $q->leftJoin('modTemplateVarResource', 'templated', "templated.contentid = modResource.id AND 'templated.tmplvarid' = ". $this->TVs['templated']); 79 | 80 | $q->select(array( 81 | 'modResource.*', 82 | 'object_id.value as object_id', 83 | 'templated.value as templated', 84 | )); 85 | 86 | $where = array_merge(array( 87 | 'published' => 1, 88 | 'deleted' => 0, 89 | 'hidemenu' => 0, 90 | 'object_id.tmplvarid' => $this->TVs['object_id'], 91 | 'tpl.templatename' => 'Repository', 92 | 'context_key' => $context_key, 93 | ), $where); 94 | 95 | if($parents){ 96 | $where['parent:IN'] = $parents; 97 | } 98 | 99 | $q->where($where); 100 | 101 | $q->limit($limit); 102 | 103 | if(!$repositories = $this->modx->getCollection('modResource', $q)){ 104 | $this->failure("Не были получены репозитории"); 105 | return false; 106 | } 107 | 108 | return $repositories; 109 | } 110 | } 111 | 112 | return 'modxRepositoryGetRepositories'; 113 | 114 | ?> 115 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/repository.class.php: -------------------------------------------------------------------------------- 1 | '; 10 | var $parent = null; 11 | 12 | 13 | public function process(){ 14 | 15 | if(!$this->parent = $this->modx->getOption('modxRepository.handler_doc_id', null, false)){ 16 | return $this->failure('Не был получен ID раздела'); 17 | } 18 | 19 | $data = $this->getData(); 20 | 21 | return $this->toXML($data, $this->params); 22 | } 23 | 24 | function getData(){ 25 | $result = array(); 26 | $params = array_merge($this->getProperties(), array( 27 | 'where' => array( 28 | 'parent' => $this->parent, 29 | ) 30 | )); 31 | 32 | $response = $this->runProcessor('repository/getrepositories',$params ); 33 | if(!$repositories = $response->getResponse()){ 34 | $this->failure('Failure get repositories'); 35 | return false; 36 | } 37 | foreach($repositories as $repository){ 38 | $result[] = array( 39 | 'repository' => $this->prepareRow($repository->toArray()), 40 | ); 41 | } 42 | $this->params = array( 43 | 'type' => 'array', 44 | 'of' => '1', 45 | 'page' => '1', 46 | 'total' => count($repositories), 47 | ); 48 | 49 | return $result; 50 | } 51 | 52 | /*public function getData__(){ 53 | $url = $this->modx->getOption('site_url', null); 54 | $url .= $this->modx->getOption('modxRepository.request_path', null).'package/'; 55 | 56 | 57 | // Получаем ID TV-шек 58 | $TVsNames = array( 59 | 'templated', 60 | 'object_id' 61 | ); 62 | 63 | if(!$result = $this->modx->getCollection('modTemplateVar', array( 64 | 'name:IN' => $TVsNames, 65 | ))){ 66 | return $this->failure('Не были получены TV-параметры'); 67 | } 68 | 69 | $TVs = array(); 70 | 71 | foreach($result as $r){ 72 | $TVs[$r->name] = $r->id; 73 | } 74 | 75 | $q = $this->modx->newQuery('modResource'); 76 | $q->innerJoin('modTemplateVarResource', 'object_id', "object_id.contentid = modResource.id"); 77 | $q->leftJoin('modTemplateVarResource', 'templated', 78 | "templated.contentid = modResource.id AND templated.tmplvarid = ". $TVs['templated']); 79 | 80 | $q->select(array( 81 | 'modResource.*', 82 | 'templated.value as templated', 83 | 'object_id.value as object_id', 84 | )); 85 | 86 | $where = array( 87 | 'parent' => $this->parent, 88 | 'published' => 1, 89 | 'deleted' => 0, 90 | 'hidemenu' => 0, 91 | 'object_id.tmplvarid' => $TVs['object_id'], 92 | ); 93 | 94 | $q->where($where); 95 | 96 | if(!$repositories = $this->modx->getCollection('modResource', $q)){ 97 | return $this->failure("Не были получены репозитории"); 98 | } 99 | 100 | $result = array(); 101 | foreach($repositories as $repository){ 102 | $result[] = array( 103 | 'repository' => $this->prepareRow($repository->toArray()), 104 | ); 105 | } 106 | 107 | $this->params = array( 108 | 'type' => 'array', 109 | 'of' => '1', 110 | 'page' => '1', 111 | 'total' => count($repositories), 112 | ); 113 | 114 | return $result; 115 | }*/ 116 | 117 | function prepareRow($data){ 118 | 119 | return array( 120 | 'description' => $data['description'], 121 | 'templated' => $data['templated'], 122 | 'rank' => $data['menuindex'], 123 | 'packages' => 3, 124 | 'createdon' => $data['createdon'], 125 | 'name' => $data['pagetitle'], 126 | 'id' => $data['object_id'], 127 | ); 128 | } 129 | } 130 | return 'modxRepositoryRepository'; 131 | ?> 132 | -------------------------------------------------------------------------------- /_build/resolvers/resolve.update_objects.php: -------------------------------------------------------------------------------- 1 | xpdo) { 11 | $modx =& $object->xpdo; 12 | 13 | switch ($options[xPDOTransport::PACKAGE_ACTION]) { 14 | case xPDOTransport::ACTION_INSTALL: 15 | case xPDOTransport::ACTION_UPGRADE: 16 | 17 | if ($modx instanceof modX) { 18 | /* 19 | * Linked modTemplates and modTemplatesVar 20 | */ 21 | 22 | $templates = array( 23 | 'Repository', 24 | 'Release', 25 | 'Package', 26 | ); 27 | 28 | $tvs = array( 29 | 'object_id' => array( 30 | 'Repository', 31 | 'Release', 32 | 'Package', 33 | ), 34 | 'version_major' => array( 35 | 'Release', 36 | ), 37 | 'version_minor' => array( 38 | 'Release', 39 | ), 40 | 'version_patch' => array( 41 | 'Release', 42 | ), 43 | 'release' => array( 44 | 'Release', 45 | ), 46 | 'vrelease_index' => array( 47 | 'Release', 48 | ), 49 | 'file' => array( 50 | 'Release', 51 | ), 52 | 'changelog' => array( 53 | 'Release', 54 | ), 55 | 'instructions' => array( 56 | 'Release', 57 | ), 58 | 'r_description' => array( 59 | 'Release', 60 | ), 61 | 'templated' => array( 62 | 'Repository', 63 | ), 64 | ); 65 | 66 | foreach($templates as $t){ 67 | $$t = $modx->getObject('modTemplate', array( 68 | 'templatename' => $t, 69 | )); 70 | } 71 | 72 | foreach($tvs as $t => $tpls){ 73 | $$t = $modx->getObject('modTemplateVar', array( 74 | 'name' => $t, 75 | )); 76 | foreach($tpls as $tpl){ 77 | if(!$modx->getObject('modTemplateVarTemplate', array( 78 | 'tmplvarid' => $$t->id, 79 | 'templateid' => $$tpl->id, 80 | ))){ 81 | $tplvar = $modx->newObject('modTemplateVarTemplate'); 82 | $tplvar->addOne($$t); 83 | $tplvar->addOne($$tpl); 84 | $tplvar->save(); 85 | } 86 | } 87 | } 88 | 89 | /* 90 | * Add Media link 91 | */ 92 | 93 | if($media = $modx->getObject('sources.modMediaSource', array( 94 | 'name' => 'Repository Packages', 95 | )) AND !$modx->getObject('sources.modMediaSourceElement', array( 96 | 'source' => $media->id, 97 | 'object' => $file->id, 98 | 'object_class' => 'modTemplateVar', 99 | )) 100 | AND $sl = $modx->newObject('sources.modMediaSourceElement')){ 101 | $sl->set('source', $media->id); 102 | $sl->set('object', $file->id); 103 | $sl->set('object_class', 'modTemplateVar'); 104 | $sl->save(); 105 | } 106 | } 107 | 108 | break; 109 | 110 | case xPDOTransport::ACTION_UNINSTALL: 111 | if ($modx instanceof modX) {} 112 | break; 113 | } 114 | } 115 | return true; -------------------------------------------------------------------------------- /_build/data/transport.templates.php: -------------------------------------------------------------------------------- 1 | newObject('modTemplate', array( 18 | 'templatename' => 'Repository', 19 | 'description' => 'Template for repository', 20 | 'content' => '', 21 | )); 22 | $result[] = $template; 23 | 24 | $template = $modx->newObject('modTemplate', array( 25 | 'templatename' => 'Package', 26 | 'description' => 'Template for package', 27 | 'content' => '', 28 | )); 29 | $result[] = $template; 30 | 31 | $template = $modx->newObject('modTemplate', array( 32 | 'templatename' => 'Release', 33 | 'description' => 'Template for release', 34 | 'content' => '', 35 | )); 36 | 37 | $result[] = $template; 38 | 39 | 40 | /* 41 | * TemplateVars 42 | */ 43 | 44 | $TemplateVar = $modx->newObject('modTemplateVar', array( 45 | 'name' => 'object_id', 46 | 'caption' => 'Object ID', 47 | 'description' => '', 48 | 'type' => 'text', 49 | 'input_properties' => array( 50 | 'allowBlank' => false, 51 | ), 52 | 'rank' => 10, 53 | )); 54 | $result[] = $TemplateVar; 55 | 56 | 57 | $TemplateVar = $modx->newObject('modTemplateVar', array( 58 | 'name' => 'templated', 59 | 'caption' => 'Templated', 60 | 'description' => 'If true, will be thumbnaled packages preview', 61 | 'type' => 'listbox', 62 | 'elements' => '0||1', 63 | 'default_text' => '0', 64 | 'input_properties' => array( 65 | 'allowBlank' => false, 66 | 'typeAhead' => false, 67 | 'typeAheadDelay'=> 250, 68 | 'forceSelection'=> 250, 69 | 'listEmptyText' => '', 70 | ), 71 | 'rank' => 20, 72 | )); 73 | $result[] = $TemplateVar; 74 | 75 | 76 | $TemplateVar = $modx->newObject('modTemplateVar', array( 77 | 'name' => 'version_major', 78 | 'caption' => 'Version major', 79 | 'description' => '', 80 | 'type' => 'number', 81 | 'input_properties' => array( 82 | 'allowBlank' => false, 83 | ), 84 | 'rank' => 30, 85 | )); 86 | $result[] = $TemplateVar; 87 | 88 | $TemplateVar = $modx->newObject('modTemplateVar', array( 89 | 'name' => 'version_minor', 90 | 'caption' => 'Version minor', 91 | 'description' => '', 92 | 'type' => 'number', 93 | 'input_properties' => array( 94 | 'allowBlank' => false, 95 | ), 96 | 'rank' => 40, 97 | )); 98 | $result[] = $TemplateVar; 99 | 100 | $TemplateVar = $modx->newObject('modTemplateVar', array( 101 | 'name' => 'version_patch', 102 | 'caption' => 'Version patch', 103 | 'description' => '', 104 | 'type' => 'number', 105 | 'rank' => 50, 106 | )); 107 | $result[] = $TemplateVar; 108 | 109 | $TemplateVar = $modx->newObject('modTemplateVar', array( 110 | 'name' => 'release', 111 | 'caption' => 'Release', 112 | 'description' => 'pl|beta|rc and etc.', 113 | 'type' => 'text', 114 | 'rank' => 60, 115 | )); 116 | $result[] = $TemplateVar; 117 | 118 | $TemplateVar = $modx->newObject('modTemplateVar', array( 119 | 'name' => 'vrelease_index', 120 | 'caption' => 'vRelease index', 121 | 'description' => '', 122 | 'type' => 'number', 123 | 'rank' => 70, 124 | )); 125 | $result[] = $TemplateVar; 126 | 127 | $TemplateVar = $modx->newObject('modTemplateVar', array( 128 | 'name' => 'file', 129 | 'caption' => 'Package file', 130 | 'description' => '', 131 | 'type' => 'file', 132 | 'input_properties' => array( 133 | 'allowBlank' => false, 134 | ), 135 | 'rank' => 80, 136 | )); 137 | $result[] = $TemplateVar; 138 | 139 | $TemplateVar = $modx->newObject('modTemplateVar', array( 140 | 'name' => 'r_description', 141 | 'caption' => 'Description', 142 | 'description' => '', 143 | 'type' => 'richtext', 144 | 'rank' => 90, 145 | )); 146 | $result[] = $TemplateVar; 147 | 148 | $TemplateVar = $modx->newObject('modTemplateVar', array( 149 | 'name' => 'instructions', 150 | 'caption' => 'Instructions', 151 | 'description' => '', 152 | 'type' => 'richtext', 153 | 'rank' => 100, 154 | )); 155 | $result[] = $TemplateVar; 156 | 157 | $TemplateVar = $modx->newObject('modTemplateVar', array( 158 | 'name' => 'changelog', 159 | 'caption' => 'Changelog', 160 | 'description' => '', 161 | 'type' => 'richtext', 162 | 'rank' => 110, 163 | )); 164 | $result[] = $TemplateVar; 165 | 166 | return $result; -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/package.class.php: -------------------------------------------------------------------------------- 1 | '; 10 | var $category_id = null; 11 | var $params = array(); 12 | 13 | 14 | public function process(){ 15 | 16 | 17 | if($this->category_id = $this->properties['tag']){ 18 | $result = $this->getPackagesByTag(); 19 | } 20 | else if($signature = $this->properties['signature']){ 21 | $this->root = ''; 22 | $result = $this->getPackageBySignature($signature); 23 | } 24 | else if($query = $this->properties['query']){ 25 | $result = $this->getPackagesByQuery($query); 26 | } 27 | 28 | 29 | return $this->toXML($result, $this->params); 30 | } 31 | 32 | /* 33 | * Поиск в репозитории 34 | */ 35 | 36 | function getPackagesByTag(){ 37 | 38 | $scriptProperties = array_merge($this->properties, array( 39 | 'where' => array( 40 | 'object_id.value' => $this->properties['tag'], 41 | ), 42 | 'limit' => 0, 43 | )); 44 | $response = $this->runProcessor('repository/getrepositories', $scriptProperties); 45 | 46 | 47 | if(!$repository = current($response->getResponse())){ 48 | $this->failure("Не были получены данные репозитория"); 49 | return false; 50 | } 51 | 52 | $repository = $repository->toArray(); 53 | 54 | 55 | $resultObject = $this->prepareRepositoryRow($repository); 56 | 57 | // Получаем все пакеты от этого репозитория 58 | $scriptProperties = array_merge($this->properties, array( 59 | 'where' => array( 60 | 'modResource.parent' => $repository['id'], 61 | ), 62 | 'limit' => 0, 63 | 'group' => array('package_id'), 64 | 'sort' => array('r.publishedon, DESC'), 65 | )); 66 | $response = $this->runProcessor('package/getpackages', $scriptProperties); 67 | 68 | if($packagesArray = $response->getResponse()){ 69 | $this->fetchPackages($resultObject, $packagesArray); 70 | } 71 | 72 | 73 | 74 | return $resultObject; 75 | } 76 | 77 | /* 78 | * Поиск в репозитории по запросу 79 | */ 80 | 81 | function getPackagesByQuery($query){ 82 | $scriptProperties = array_merge($this->properties, array( 83 | 'where' => array( 84 | 'modResource.pagetitle:like' => "%{$query}%", 85 | ), 86 | 'limit' => 0, 87 | )); 88 | 89 | $response = $this->runProcessor('package/getpackages', $scriptProperties); 90 | 91 | if($packagesArray = $response->getResponse()){ 92 | $this->fetchPackages($resultObject, $packagesArray); 93 | } 94 | 95 | return $resultObject; 96 | } 97 | 98 | 99 | 100 | function fetchPackages(& $resultObject, & $packagesArray){ 101 | foreach($packagesArray as $p){ 102 | $resultObject[] = array( 103 | 'package' => $this->preparePackageRow($p), 104 | ); 105 | } 106 | } 107 | 108 | function preparePackageRow($data){ 109 | $response = $this->runProcessor('package/preparerow', $data); 110 | return $response->getResponse(); 111 | } 112 | 113 | 114 | function prepareRepositoryRow($data){ 115 | return array( 116 | 'description' => "{$data['description']}", 117 | 'templated' => !empty($data['templated']) ? $data['templated'] : 0, 118 | 'rank' => $data['menuindex'], 119 | 'packages' => 3, 120 | 'createdon' => $data['createdon'], 121 | 'name' => $data['pagetitle'], 122 | 'id' => $data['object_id'], 123 | ); 124 | } 125 | 126 | /* 127 | * Поиск пакета по подписи 128 | */ 129 | 130 | function getPackageBySignature($signature){ 131 | $scriptProperties = array_merge($this->properties, array( 132 | 'where' => array( 133 | 'r.pagetitle' => $this->properties['signature'], 134 | ), 135 | 'limit' => 1, 136 | 'group' => array('package_id'), 137 | 'sort' => array('r.publishedon, DESC'), 138 | )); 139 | $response = $this->runProcessor('package/getpackages', $scriptProperties); 140 | 141 | if(!$r = $response->getResponse() OR !is_array($r) OR !$result = current($r)){ 142 | $this->failure("Не был получен пакет"); 143 | return; 144 | } 145 | 146 | $packArray = $result; 147 | $package = $this->preparePackageRow($packArray); 148 | 149 | // Получаем данные о файле 150 | $url = $this->modx->getOption('site_url', null); 151 | $url .= $this->modx->getOption('modxRepository.request_path', null).'download/?id='; 152 | 153 | $fileData = array( 154 | 'id' => $packArray['file_id'], 155 | 'version' => $packArray['file_id'], 156 | 'filename' => $packArray['file'].".transport.zip", 157 | 'downloads' => 3, 158 | 'lastip' => '', 159 | 'transport' => true, 160 | 'location' => $url.$packArray['file_id'], 161 | ); 162 | 163 | $package[] = array( 164 | 'file' => $fileData, 165 | ); 166 | 167 | return $package; 168 | } 169 | } 170 | return 'modxRepositoryHome'; 171 | ?> 172 | -------------------------------------------------------------------------------- /core/components/modxrepository/processors/rest/package/getpackages.class.php: -------------------------------------------------------------------------------- 1 | getTVs(); 16 | 17 | if($this->hasErrors()){ 18 | return false; 19 | } 20 | $where = (array)$this->properties['where']; 21 | $limit = ($this->properties['limit'] ? $this->properties['limit'] : 0); 22 | $group = (array)$this->properties['group']; 23 | $sort = (array)$this->properties['sort']; 24 | return $this->getData($where, $limit, $group, $sort); 25 | } 26 | 27 | 28 | function getTVs(){ 29 | // Получаем ID TV-шек 30 | $TVsNames = array( 31 | 'object_id', 32 | 'version_major', 33 | 'version_minor', 34 | 'version_patch', 35 | 'release', 36 | 'vrelease_index', 37 | 'r_description', 38 | 'instructions', 39 | 'changelog', 40 | 'file', 41 | 'downloads', 42 | ); 43 | 44 | 45 | if(!$result = $this->modx->getCollection('modTemplateVar', array( 46 | 'name:IN' => $TVsNames, 47 | ))){ 48 | return $this->failure('Не были получены TV-параметры'); 49 | } 50 | 51 | foreach($result as $r){ 52 | $this->TVs[$r->name] = $r->id; 53 | } 54 | return $this->TVs; 55 | } 56 | 57 | function getData($where = array(), $limit = 0, $group = array(), $sort = array()){ 58 | /* 59 | * Get repositories IDs 60 | */ 61 | $parents = array(); 62 | 63 | if($this->getProperty('root')){ 64 | $response = $this->runProcessor('repository/getrepositories', $this->getProperties()); 65 | if(!$repositories = $response->getResponse()){ 66 | $this->failure('Failure get repositories'); 67 | return false; 68 | } 69 | foreach($repositories as $r){ 70 | $parents[] = $r->id; 71 | } 72 | } 73 | 74 | $q = $this->modx->newQuery('modResource'); 75 | $q->innerJoin('modTemplateVarResource', 'object_id', "object_id.contentid = modResource.id"); 76 | $q->innerJoin('modResource', 'r', 'r.parent = modResource.id'); 77 | $q->innerJoin('modTemplateVarResource', 'r_object_id', "r_object_id.contentid = r.id"); 78 | $q->innerJoin('modTemplateVarResource', '`release`', "`release`.contentid = r.id"); 79 | $q->innerJoin('modTemplateVarResource', '`file`', "`file`.contentid = r.id"); 80 | $q->innerJoin('modUser', '`user`', "`user`.id = r.createdby"); 81 | 82 | $q->leftJoin('modTemplateVarResource', 'vrelease_index', 83 | "vrelease_index.contentid = r.id AND vrelease_index.tmplvarid = ". $this->TVs['vrelease_index']); 84 | $q->leftJoin('modTemplateVarResource', 'r_description', 85 | "r_description.contentid = r.id AND r_description.tmplvarid = ". $this->TVs['r_description']); 86 | $q->leftJoin('modTemplateVarResource', 'instructions', 87 | "instructions.contentid = r.id AND instructions.tmplvarid = ". $this->TVs['instructions']); 88 | $q->leftJoin('modTemplateVarResource', 'changelog', 89 | "changelog.contentid = r.id AND changelog.tmplvarid = ". $this->TVs['changelog']); 90 | 91 | $q->leftJoin('modTemplateVarResource', 'version_major', 92 | "version_major.contentid = r.id AND version_major.tmplvarid = ". $this->TVs['version_major']); 93 | $q->leftJoin('modTemplateVarResource', 'version_minor', 94 | "version_minor.contentid = r.id AND version_minor.tmplvarid = ". $this->TVs['version_minor']); 95 | $q->leftJoin('modTemplateVarResource', 'version_patch', 96 | "version_patch.contentid = r.id AND version_patch.tmplvarid = ". $this->TVs['version_patch']); 97 | $q->leftJoin('modTemplateVarResource', 'downloads', 98 | "downloads.contentid = r.id AND downloads.tmplvarid = ". $this->TVs['downloads']); 99 | 100 | $q->select(array( 101 | 'modResource.*', 102 | 'modResource.id as package_id', 103 | 'object_id.value as object_id', 104 | 'r_object_id.value as release_id', 105 | 'r.id as r_content_id', 106 | 'r.pagetitle as release_name', 107 | 'r.createdon as release_createdon', 108 | 'r.editedon as release_editedon', 109 | 'r.publishedon as releasedon', 110 | 'version_major.value as version_major', 111 | 'version_minor.value as version_minor', 112 | 'version_patch.value as version_patch', 113 | '`release`.value as `release`', 114 | 'vrelease_index.value as vrelease_index', 115 | '`user`.username as `author`', 116 | '`user`.username as `r_createdby`', 117 | 'r_description.value as release_description', 118 | 'instructions.value as instructions', 119 | 'changelog.value as changelog', 120 | 'file.value as file', 121 | 'file.id as file_id', 122 | 'downloads.value as downloads', 123 | )); 124 | 125 | 126 | $where = array_merge(array( 127 | 'modResource.published' => 1, 128 | 'modResource.deleted' => 0, 129 | 'modResource.hidemenu' => 0, 130 | 'r.published' => 1, 131 | 'r.deleted' => 0, 132 | 'r.hidemenu' => 0, 133 | 'object_id.tmplvarid' => $this->TVs['object_id'], 134 | 'r_object_id.tmplvarid' => $this->TVs['object_id'], 135 | '`release`.tmplvarid' => $this->TVs['release'], 136 | 'file.tmplvarid' => $this->TVs['file'], 137 | ), $where ); 138 | 139 | if($parents){ 140 | $where['modResource.parent:IN'] = $parents; 141 | } 142 | 143 | $q->where($where); 144 | $q->limit($limit); 145 | 146 | if($sort){ 147 | foreach($sort as $s){ 148 | $arr = explode(",", $s); 149 | $by = trim($arr[0]); 150 | if(!$dir = trim($arr[1])){ 151 | $dir = 'ASC'; 152 | } 153 | $q->sortby($by, $dir); 154 | } 155 | } 156 | 157 | $q->prepare(); 158 | 159 | 160 | // Группируем результат 161 | if($group = (array)$group){ 162 | $sql = $q->toSQL(); 163 | 164 | $sql = "SELECT * from ({$sql}) AS t"; 165 | $sql .= " group by ". implode(", ", $group); 166 | 167 | if($sort){ 168 | $order_arr = array(); 169 | foreach($sort as $s){ 170 | $arr = explode(",", $s); 171 | $by = trim($arr[0]); 172 | if(!$dir = trim($arr[1])){ 173 | $dir = 'ASC'; 174 | } 175 | // remove aliases 176 | $by_arr = explode('.', $by); 177 | if($by_arr[1]){ 178 | $by = $by_arr[1]; 179 | } 180 | $order_arr[] = "t.{$by} {$dir}"; 181 | } 182 | $sql .= " ORDER BY ". implode(", ", $order_arr); 183 | } 184 | 185 | $q->stmt = $this->modx->prepare($sql); 186 | //package_id 187 | } 188 | 189 | if(!$q->stmt->execute() OR !$result = $q->stmt->fetchAll(PDO::FETCH_ASSOC)){ 190 | $this->failure("Не были получены пакеты"); 191 | return false; 192 | } 193 | 194 | return $result; 195 | } 196 | } 197 | 198 | return 'modxRepositoryGetPackagesClass'; 199 | ?> 200 | -------------------------------------------------------------------------------- /_build/build.transport.php: -------------------------------------------------------------------------------- 1 | '; 33 | require_once dirname(__FILE__). '/build.config.php'; 34 | 35 | 36 | $modx->setLogLevel(modX::LOG_LEVEL_INFO); 37 | $modx->setLogTarget('ECHO'); echo '
'; flush();
 38 | 
 39 | $modx->loadClass('transport.modPackageBuilder','',false, true);
 40 | $builder = new modPackageBuilder($modx);
 41 | $builder->createPackage(PKG_NAME_LOWER,PKG_VERSION,PKG_RELEASE);
 42 | $builder->registerNamespace(PKG_NAME_LOWER,false,true,'{core_path}components/'.PKG_NAME_LOWER.'/');
 43 | $modx->getService('lexicon','modLexicon');
 44 | $modx->lexicon->load(PKG_NAME_LOWER.':properties');
 45 | 
 46 | /* load action/menu */
 47 | $attributes = array (
 48 |     xPDOTransport::PRESERVE_KEYS => true,
 49 |     xPDOTransport::UPDATE_OBJECT => true,
 50 |     xPDOTransport::UNIQUE_KEY => 'text',
 51 |     xPDOTransport::RELATED_OBJECTS => true,
 52 |     xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
 53 |         'Action' => array (
 54 |             xPDOTransport::PRESERVE_KEYS => false,
 55 |             xPDOTransport::UPDATE_OBJECT => true,
 56 |             xPDOTransport::UNIQUE_KEY => array ('namespace','controller'),
 57 |         ),
 58 |     ),
 59 | ); 
 60 | 
 61 | 
 62 | /* add namespace */
 63 | $namespace = $modx->newObject('modNamespace');
 64 | $namespace->set('name', NAMESPACE_NAME);
 65 | $namespace->set('path',"{core_path}components/".PKG_NAME_LOWER."/");
 66 | $namespace->set('assets_path',"{assets_path}components/".PKG_NAME_LOWER."/");
 67 | $vehicle = $builder->createVehicle($namespace,array(
 68 |     xPDOTransport::UNIQUE_KEY => 'name',
 69 |     xPDOTransport::PRESERVE_KEYS => true,
 70 |     xPDOTransport::UPDATE_OBJECT => true,
 71 | ));
 72 | $builder->putVehicle($vehicle);
 73 | $modx->log(modX::LOG_LEVEL_INFO,"Packaged in ".NAMESPACE_NAME." namespace."); flush();
 74 | unset($vehicle,$namespace);
 75 |  
 76 | /* create category */
 77 | $category= $modx->newObject('modCategory');
 78 | $category->set('id',1);
 79 | $category->set('category',PKG_NAME);
 80 | $modx->log(modX::LOG_LEVEL_INFO,'Packaged in category.'); flush();
 81 |   
 82 | 
 83 | /* create category vehicle */
 84 | $attr = array(
 85 |     xPDOTransport::UNIQUE_KEY => 'category',
 86 |     xPDOTransport::PRESERVE_KEYS => false,
 87 |     xPDOTransport::UPDATE_OBJECT => true,
 88 |     xPDOTransport::RELATED_OBJECTS => true,
 89 |     xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
 90 |         'Snippets' => array(
 91 |             xPDOTransport::PRESERVE_KEYS => false,
 92 |             xPDOTransport::UPDATE_OBJECT => true,
 93 |             xPDOTransport::UNIQUE_KEY => 'name',
 94 |         ),
 95 |         'Plugins' => array(
 96 |             xPDOTransport::PRESERVE_KEYS => false,
 97 |             xPDOTransport::UPDATE_OBJECT => true,
 98 |             xPDOTransport::UNIQUE_KEY => 'name',
 99 |         ),
100 |         'PluginEvents' => array(
101 |             xPDOTransport::PRESERVE_KEYS => true,
102 |             xPDOTransport::UPDATE_OBJECT => false,
103 |             xPDOTransport::UNIQUE_KEY => array('pluginid','event'),
104 |         ),
105 |         'Templates' => array(
106 |             xPDOTransport::PRESERVE_KEYS => false,
107 |             xPDOTransport::UPDATE_OBJECT => true,
108 |             xPDOTransport::UNIQUE_KEY => 'templatename',
109 |         ),
110 |         'TemplateVars' => array(
111 |             xPDOTransport::PRESERVE_KEYS => false,
112 |             xPDOTransport::UPDATE_OBJECT => true,
113 |             xPDOTransport::UNIQUE_KEY => 'name',
114 |         ),
115 |     )
116 | );
117 | 
118 | 
119 | /* add plugins */
120 | $plugins = include $sources['data'].'transport.plugins.php';
121 | if (!is_array($plugins)) { $modx->log(modX::LOG_LEVEL_FATAL,'Adding plugins failed.'); } 
122 | else{
123 |     $category->addMany($plugins);
124 |     $modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($plugins).' plugins.'); flush();
125 | }
126 | 
127 | unset($plugins,$plugin,$attributes);
128 | 
129 | 
130 | /* Add templates */
131 | $templates = include $sources['data'].'transport.templates.php';
132 | if (!is_array($templates)) { $modx->log(modX::LOG_LEVEL_FATAL,'Adding templates failed.'); } 
133 | else{
134 |     $category->addMany($templates);
135 |     $modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($templates).' templates.'); flush();
136 | }
137 | 
138 | 
139 | /* Create mediaSources */
140 | $mediaSources = include $sources['data'].'transport.mediasources.php';
141 | if (!is_array($mediaSources)) { $modx->log(modX::LOG_LEVEL_ERROR,'Adding MediaSources failed.'); } 
142 | else{
143 |     $vehicleParams = array(
144 |         xPDOTransport::PRESERVE_KEYS => false,
145 |         xPDOTransport::UPDATE_OBJECT => false,
146 |         xPDOTransport::UNIQUE_KEY => 'name',
147 |     );
148 | 
149 |     foreach($mediaSources as & $mediaSource){
150 |         $vehicle = $builder->createVehicle($mediaSource, $vehicleParams);
151 |         $builder->putVehicle($vehicle);
152 |     }
153 |     $modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($mediaSources).' MediaSources.'); flush();
154 | }
155 |  
156 | /* load system settings */
157 | $settings = include_once $sources['data'].'transport.settings.php';
158 | $attributes= array(
159 |     xPDOTransport::UNIQUE_KEY => 'key',
160 |     xPDOTransport::PRESERVE_KEYS => true,
161 |     xPDOTransport::UPDATE_OBJECT => false,
162 | );
163 | if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR,'Adding settings failed.'); }
164 | foreach ($settings as $setting) {
165 |     $vehicle = $builder->createVehicle($setting,$attributes);
166 |     $builder->putVehicle($vehicle);
167 | }
168 | $modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($settings).' system settings.'); flush();
169 | unset($settings,$setting,$attributes);
170 | 
171 | 
172 | /* create main category */
173 | $vehicle = $builder->createVehicle($category,$attr);
174 | $vehicle->resolve('file',array(
175 |     'source' => $sources['source_core'],
176 |     'target' => "return MODX_CORE_PATH . 'components/';",
177 | ));
178 | $modx->log(modX::LOG_LEVEL_INFO,'Packaged in CorePath'); flush();
179 | $vehicle->resolve('file',array(
180 |     'source' => $sources['source_assets'],
181 |     'target' => "return MODX_ASSETS_PATH . 'components/';",
182 | ));
183 | $modx->log(modX::LOG_LEVEL_INFO,'Packaged in AssetsPath'); flush();
184 | 
185 | $vehicle->resolve('php',array(
186 |     'source' => $sources['resolvers'] . 'resolve.update_objects.php',
187 | ));
188 | 
189 | 
190 | $modx->log(modX::LOG_LEVEL_INFO,'Packaged in resolvers.'); 
191 | 
192 | flush();
193 | 
194 | $builder->putVehicle($vehicle);
195 | 
196 | /* now pack in the license file, readme and setup options */
197 | $builder->setPackageAttributes(array(
198 |     'license' => file_get_contents($sources['docs'] . 'license.txt'),
199 |     'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
200 |     'changelog' => file_get_contents($sources['docs'] . 'changelog.txt'), 
201 |     'setup-options' => array(
202 |         'source' => $sources['build'].'setup.options.php',
203 |     ), 
204 | ));
205 | $modx->log(modX::LOG_LEVEL_INFO,'Packaged in package attributes.'); flush();
206 | 
207 | $modx->log(modX::LOG_LEVEL_INFO,'Packing...'); flush();
208 | $builder->pack();
209 | 
210 | $mtime= microtime();
211 | $mtime= explode(" ", $mtime);
212 | $mtime= $mtime[1] + $mtime[0];
213 | $tend= $mtime;
214 | $totalTime= ($tend - $tstart);
215 | $totalTime= sprintf("%2.4f s", $totalTime);
216 | 
217 | $modx->log(modX::LOG_LEVEL_INFO,"\n
Package Built.
\nExecution time: {$totalTime}\n"); 218 | 219 | exit (); 220 | 221 | ?> 222 | -------------------------------------------------------------------------------- /_build/setup.options.php: -------------------------------------------------------------------------------- 1 | Please, don`t forget set Extra_path document ID in system settings after create repository structure.'; 11 | 12 | $img = ""; 13 | 14 | $output .= "

{$img}

"; 15 | 16 | return $output; 17 | 18 | break; 19 | case xPDOTransport::ACTION_UNINSTALL: break; 20 | } 21 | --------------------------------------------------------------------------------