Beispiel #1
0
 function selectfile($directory, $filter, $name, $value = null, $attribs = null)
 {
     // get files
     $options = array(JHTML::_('select.option', '', '- ' . JText::_('Select File') . ' -'));
     $files = YFile::readDirectoryFiles($directory, '', $filter);
     natsort($files);
     foreach ($files as $file) {
         $options[] = JHTML::_('select.option', $file, $file);
     }
     return JHTML::_('select.genericlist', $options, $name, $attribs, 'value', 'text', $value);
 }
Beispiel #2
0
 public static function doInstall(JInstallerComponent &$component)
 {
     // fix joomla 1.5 bug
     $component->parent->getDBO = $component->parent->getDBO();
     // initialize zoo framework
     require_once $component->parent->getPath('source') . '/admin/config.php';
     // sanatize table indexes
     $index_sql_path = $component->parent->getPath('source') . '/admin/installation/index.sql';
     if (JFile::exists($index_sql_path)) {
         $db = YDatabase::getInstance();
         // read index.sql
         $buffer = JFile::read($index_sql_path);
         // Create an array of queries from the sql file
         jimport('joomla.installer.helper');
         $queries = JInstallerHelper::splitSql($buffer);
         if (!empty($queries)) {
             foreach ($queries as $query) {
                 // replace table prefixes
                 $query = $db->replacePrefix($query);
                 // parse table name
                 preg_match('/ALTER\\s*TABLE\\s*`(.*)`/i', $query, $result);
                 if (count($result) < 2) {
                     continue;
                 }
                 $table = $result[1];
                 // get existing indexes
                 $indexes = $db->queryObjectList('SHOW INDEX FROM ' . $table);
                 // drop existing indexes
                 $removed = array();
                 foreach ($indexes as $index) {
                     if (in_array($index->Key_name, $removed)) {
                         continue;
                     }
                     if ($index->Key_name != 'PRIMARY') {
                         $db->query('DROP INDEX ' . $index->Key_name . ' ON ' . $table);
                         $removed[] = $index->Key_name;
                     }
                 }
                 // add new indexes
                 $db->query($query);
             }
         }
     }
     // applications
     if (!JFolder::exists(ZOO_APPLICATION_PATH)) {
         JFolder::create(ZOO_APPLICATION_PATH);
     }
     $applications = array();
     foreach (JFolder::folders($component->parent->getPath('source') . '/applications', '.', false, true) as $folder) {
         try {
             if ($manifest = InstallHelper::findManifest($folder)) {
                 $name = InstallHelper::getName($manifest);
                 $status = InstallHelper::installApplicationFromFolder($folder);
                 $applications[] = compact('name', 'status');
             }
         } catch (YException $e) {
             $name = basename($folder);
             $status = false;
             $applications[] = compact('name', 'status');
         }
     }
     self::displayResults($applications, 'Applications', 'Application');
     // additional extensions
     // init vars
     $error = false;
     $extensions = array();
     // get plugin files
     $plugin_files = array();
     foreach (YFile::readDirectoryFiles(JPATH_PLUGINS, JPATH_PLUGINS . '/', '/\\.php$/', true) as $file) {
         $plugin_files[] = basename($file);
     }
     // get extensions
     if (isset($component->manifest->additional[0])) {
         $add = $component->manifest->additional[0];
         if (count($add->children())) {
             $exts = $add->children();
             foreach ($exts as $ext) {
                 $installer = new JInstaller();
                 $installer->setOverwrite(true);
                 $update = false;
                 if ($ext->name() == 'module' && JFolder::exists(JPATH_ROOT . '/modules/' . $ext->attributes('name')) || $ext->name() == 'plugin' && in_array($ext->attributes('name') . '.php', $plugin_files)) {
                     $update = true;
                 }
                 $folder = $component->parent->getPath('source') . '/' . $ext->attributes('folder');
                 $folder = rtrim($folder, "\\/") . '/';
                 if (JFolder::exists($folder)) {
                     if ($update) {
                         foreach (YFile::readDirectoryFiles($folder, $folder, '/positions\\.config$/', true) as $file) {
                             JFile::delete($file);
                         }
                     }
                     $extensions[] = array('name' => $ext->data(), 'type' => $ext->name(), 'folder' => $folder, 'installer' => $installer, 'status' => false, 'update' => $update);
                 }
             }
         }
     }
     // install additional extensions
     for ($i = 0; $i < count($extensions); $i++) {
         if (is_dir($extensions[$i]['folder'])) {
             if (@$extensions[$i]['installer']->install($extensions[$i]['folder'])) {
                 $extensions[$i]['status'] = $extensions[$i]['update'] ? 2 : 1;
             } else {
                 $error = true;
                 break;
             }
         }
     }
     // rollback on installation errors
     if ($error) {
         $component->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . JText::_('Error'), 'component');
         for ($i = 0; $i < count($extensions); $i++) {
             if ($extensions[$i]['status']) {
                 $extensions[$i]['installer']->abort(JText::_($extensions[$i]['type']) . ' ' . JText::_('Install') . ': ' . JText::_('Error'), $extensions[$i]['type']);
                 $extensions[$i]['status'] = false;
             }
         }
         return false;
     }
     self::displayResults($extensions, 'Extensions', 'Extension');
     // UPGRADES
     // get versions
     $new_version = $component->manifest->getElementByPath('version')->data();
     $version = '';
     // check for old version number
     $version_file_path = $component->parent->getPath('extension_administrator') . '/version.php';
     if (JFile::exists($version_file_path)) {
         require_once $version_file_path;
     }
     // write new version file
     $buffer = "<?php\n\ndefined('_JEXEC') or die('Restricted access');\n\n\$version = '{$new_version}';";
     JFile::write($version_file_path, $buffer);
     // include update script
     require_once $component->parent->getPath('source') . '/admin/installation/update.php';
     return true;
 }
Beispiel #3
0
 public function doExport()
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     $group = $this->application->getGroup();
     require_once JPATH_ROOT . '/administrator/includes/pcl/pclzip.lib.php';
     $filepath = JPATH_ROOT . '/tmp/' . $group . '.zip';
     $read_directory = ZOO_APPLICATION_PATH . '/' . $group . '/';
     $zip = new PclZip($filepath);
     $files = YFile::readDirectoryFiles($read_directory, $read_directory, '', '/^[^\\.]/');
     $zip->create($files, PCLZIP_OPT_ADD_PATH, '../', PCLZIP_OPT_REMOVE_PATH, $read_directory);
     if (is_readable($filepath) && JFile::exists($filepath)) {
         YFile::output($filepath);
         if (!JFile::delete($filepath)) {
             JError::raiseNotice(0, JText::_('Unable to delete file') . ' (' . $filepath . ')');
             $this->setRedirect($this->baseurl . '&task=info');
         }
     } else {
         JError::raiseNotice(0, JText::_('Unable to create file') . ' (' . $filepath . ')');
         $this->setRedirect($this->baseurl . '&task=info');
     }
 }
Beispiel #4
0
 public function renderSubmission($params = array())
 {
     // load js
     JHTML::script('image.js', 'administrator/components/com_zoo/elements/image/assets/js/');
     // init vars
     $image = $this->_data->get('file');
     // is uploaded file
     $image = is_array($image) ? '' : $image;
     // get params
     $params = new YArray($params);
     $trusted_mode = $params->get('trusted_mode');
     // build image select
     $lists = array();
     if ($trusted_mode) {
         $options = array(JHTML::_('select.option', '', '- ' . JText::_('Select Image') . ' -'));
         if (!empty($image) && !$this->_inUploadPath($image)) {
             $options[] = JHTML::_('select.option', $image, '- ' . JText::_('No Change') . ' -');
         }
         $img_ext = str_replace(',', '|', trim(JComponentHelper::getParams('com_media')->get('image_extensions'), ','));
         foreach (YFile::readDirectoryFiles(JPATH_ROOT . '/' . $this->_getUploadImagePath() . '/', $this->_getUploadImagePath() . '/', '/\\.(' . $img_ext . ')$/i', false) as $file) {
             $options[] = JHTML::_('select.option', $file, basename($file));
         }
         $lists['image_select'] = JHTML::_('select.genericlist', $options, 'elements[' . $this->identifier . '][image]', 'class="image"', 'value', 'text', $image);
     } else {
         if (!empty($image)) {
             $image = ZooHelper::resizeImage(JPATH_ROOT . DS . $image, 0, 0);
             $image = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $image)), '/');
         }
     }
     if (!empty($image)) {
         $image = JURI::root() . $image;
     }
     if ($layout = $this->getLayout('submission.php')) {
         return self::renderLayout($layout, array('element' => $this->identifier, 'lists' => $lists, 'image' => $image));
     }
 }
Beispiel #5
0
 public static function findManifest($path)
 {
     $path = rtrim($path, "\\/") . '/';
     foreach (YFile::readDirectoryFiles($path, $path, '/\\.xml$/', false) as $file) {
         if (($xml = YXML::loadFile($file)) && self::isManifest($xml)) {
             return $xml;
         }
     }
     return false;
 }
Beispiel #6
0
 public function renderSubmission($params = array())
 {
     // get params
     $params = new YArray($params);
     $trusted_mode = $params->get('trusted_mode');
     // init vars
     $upload = $this->_data->get('file');
     $download_limit = $this->_data->get('download_limit');
     if (empty($upload) && $trusted_mode) {
         $upload = $this->_data->get('upload');
     }
     // is uploaded file
     $upload = is_array($upload) ? '' : $upload;
     // build upload select
     $lists = array();
     if ($trusted_mode) {
         $options = array(JHTML::_('select.option', '', '- ' . JText::_('Select File') . ' -'));
         if (!empty($upload) && !$this->_inUploadPath($upload)) {
             $options[] = JHTML::_('select.option', $upload, '- ' . JText::_('No Change') . ' -');
         }
         foreach (YFile::readDirectoryFiles(JPATH_ROOT . '/' . $this->_getUploadPath() . '/', $this->_getUploadPath() . '/', false, false) as $file) {
             $options[] = JHTML::_('select.option', $file, basename($file));
         }
         $lists['upload_select'] = JHTML::_('select.genericlist', $options, 'elements[' . $this->identifier . '][upload]', 'class="upload"', 'value', 'text', $upload);
     }
     if (!empty($upload)) {
         $upload = basename($upload);
     }
     if ($layout = $this->getLayout('submission.php')) {
         return self::renderLayout($layout, array('element' => $this->identifier, 'lists' => $lists, 'upload' => $upload, 'trusted_mode' => $trusted_mode, 'download_limit' => $download_limit));
     }
 }