Пример #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);
 }
Пример #2
0
 public function getVideoFormat($source)
 {
     foreach ($this->_getVideoFormats() as $key => $tmp) {
         if (isset($tmp['regex'])) {
             if (preg_match($tmp['regex'], $source, $matches) && isset($matches[1])) {
                 return $key;
             }
         } else {
             if (YFile::getExtension($source) == $key) {
                 return $key;
             }
         }
     }
     return null;
 }
Пример #3
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;
 }
Пример #4
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');
     }
 }
Пример #5
0
 public function doUpload()
 {
     // get the uploaded file information
     $userfile = $this->_data->get('file');
     if (is_array($userfile)) {
         // get file name
         $ext = YFile::getExtension($userfile['name']);
         $base_path = JPATH_ROOT . '/' . $this->_getUploadImagePath() . '/';
         $file = $tmp = $base_path . $userfile['name'];
         $filename = basename($file, '.' . $ext);
         $i = 1;
         while (JFile::exists($tmp)) {
             $tmp = $base_path . $filename . '-' . $i++ . '.' . $ext;
         }
         $file = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $tmp)), '/');
         if (!JFile::upload($userfile['tmp_name'], $file)) {
             throw new YException('Unable to upload file.');
         }
         $this->_data->set('file', $file);
     }
 }
Пример #6
0
 protected function _getGroupMimeTypes($group)
 {
     $mime_types = new YArray(YFile::getMimeMapping());
     $mime_types = $mime_types->flattenRecursive();
     $mime_types = array_filter($mime_types, create_function('$a', 'return preg_match("/^' . $group . '\\//i", $a);'));
     return array_map('strtolower', $mime_types);
 }
Пример #7
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;
 }