예제 #1
0
 public function delete()
 {
     // Check for request forgeries.
     JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     // Initialise variables.
     $user = JFactory::getUser();
     $ids = JRequest::getVar('cid', array(), '', 'array');
     // Access checks.
     foreach ($ids as $i => $package) {
         $id = LocaliseHelper::getFileId(JPATH_ROOT . "/media/com_localise/packages/{$package}.xml");
         $model = $this->getModel('Package');
         $model->setState('package.id', $id);
         $item = $model->getItem();
         if (!$item->standalone) {
             // Prune items that you can't delete.
             unset($ids[$i]);
             JError::raiseNotice(403, JText::_('COM_LOCALISE_ERROR_PACKAGES_DELETE'));
         }
         if (!$user->authorise('core.delete', 'com_localise.' . (int) $id)) {
             // Prune items that you can't delete.
             unset($ids[$i]);
             JError::raiseNotice(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
         }
     }
     if (empty($ids)) {
         $msg = JText::_('JERROR_NO_ITEMS_SELECTED');
         $type = 'error';
     } else {
         // Get the model.
         $model = $this->getModel();
         // Remove the items.
         if (!$model->delete($ids)) {
             $msg = implode("<br />", $model->getErrors());
             $type = 'error';
         } else {
             $msg = JText::sprintf('JCONTROLLER_N_ITEMS_DELETED', count($ids));
             $type = 'message';
         }
     }
     $this->setRedirect(JRoute::_('index.php?option=com_localise&view=packages', false), $msg, $type);
 }
예제 #2
0
 private function _getPackages()
 {
     if (!isset($this->packages)) {
         $search = $this->getState('filter.search');
         $this->packages = array();
         $path = JPATH_COMPONENT_ADMINISTRATOR . '/packages';
         if (JFolder::exists($path)) {
             $files = JFolder::files($path, '\\.xml$');
             foreach ($files as $file) {
                 $model = JModelLegacy::getInstance('Package', 'LocaliseModel', array('ignore_request' => true));
                 $id = LocaliseHelper::getFileId("{$path}/{$file}");
                 $model->setState('package.id', $id);
                 $package = $model->getItem();
                 if (empty($search) || preg_match("/{$search}/i", $package->title)) {
                     $this->packages[] = $package;
                 }
             }
         }
         $ordering = $this->getState('list.ordering') ? $this->getState('list.ordering') : 'title';
         JArrayHelper::sortObjects($this->packages, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1);
     }
     return $this->packages;
 }
예제 #3
0
 /**
  * Get all languages (according to filters)
  *
  * @return   array  array of object items
  */
 protected function getLanguages()
 {
     if (!isset($this->languages)) {
         $this->languages = array();
         $client = $this->getState('filter.client');
         $tag = $this->getState('filter.tag');
         $search = $this->getState('filter.search');
         if (empty($client)) {
             $clients = array('site', 'administrator');
             if (LocaliseHelper::hasInstallation()) {
                 $clients[] = 'installation';
             }
         } else {
             $clients = array($client);
         }
         foreach ($clients as $client) {
             if (empty($tag)) {
                 $folders = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides'));
             } else {
                 $folders = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', '^' . $tag . '$', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides'));
             }
             foreach ($folders as $folder) {
                 //move to first
                 $id = LocaliseHelper::getFileId(constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$folder}/{$folder}.xml");
                 //if it was not found a file.
                 if ($id < 1) {
                     continue;
                 }
                 $model = JModelLegacy::getInstance('Language', 'LocaliseModel', array('ignore_request' => true));
                 $model->setState('language.tag', $folder);
                 $model->setState('language.client', $client);
                 $model->setState('language.id', $id);
                 $language = $model->getItem();
                 if (empty($search) || preg_match("/{$search}/i", $language->name)) {
                     $this->languages[] = $language;
                 }
             }
         }
         $ordering = $this->getState('list.ordering') ? $this->getState('list.ordering') : 'name';
         JArrayHelper::sortObjects($this->languages, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1);
     }
     return $this->languages;
 }
예제 #4
0
 /**
  * Todo: description missing
  *
  * @return void
  */
 public function download()
 {
     // Redirect to the export view
     $app = JFactory::getApplication();
     $name = $app->getUserState('com_localise.package.name');
     $path = JPATH_COMPONENT_ADMINISTRATOR . '/packages/' . $name . '.xml';
     $id = LocaliseHelper::getFileId($path);
     // Check if the package exists
     if (empty($id)) {
         $this->setRedirect(JRoute::_('index.php?option=' . $this->_option . '&view=packages', false), JText::sprintf('COM_LOCALISE_ERROR_DOWNLOADPACKAGE_UNEXISTING', $name), 'error');
     } else {
         $model = $this->getModel();
         $package = $model->getItem();
         if (!$package->standalone) {
             $msg = JText::sprintf('COM_LOCALISE_NOTICE_DOWNLOADPACKAGE_NOTSTANDALONE', $name);
             $type = 'notice';
         } else {
             $msg = '';
             $type = 'message';
         }
         setcookie(JApplicationHelper::getHash($this->_context . '.author'), $package->author, time() + 60 * 60 * 24 * 30);
         setcookie(JApplicationHelper::getHash($this->_context . '.copyright'), $package->copyright, time() + 60 * 60 * 24 * 30);
         setcookie(JApplicationHelper::getHash($this->_context . '.email'), $package->email, time() + 60 * 60 * 24 * 30);
         setcookie(JApplicationHelper::getHash($this->_context . '.url'), $package->url, time() + 60 * 60 * 24 * 30);
         setcookie(JApplicationHelper::getHash($this->_context . '.version'), $package->version, time() + 60 * 60 * 24 * 30);
         setcookie(JApplicationHelper::getHash($this->_context . '.license'), $package->license, time() + 60 * 60 * 24 * 30);
         $this->setRedirect(JRoute::_('index.php?option=com_localise&tmpl=component&view=downloadpackage&name=' . $name . '&standalone=' . $package->standalone, false), $msg, $type);
     }
 }
예제 #5
0
 /**
  * Get the parent asset id for the record
  *
  * @return  int
  */
 protected function _getAssetParentId(JTable $table = NULL, $id = NULL)
 {
     // Initialise variables.
     $db = $this->getDbo();
     // Build the query to get the asset id for the parent category.
     $asset = JTable::getInstance('asset');
     $name = basename($this->path);
     $relativePath = substr($this->path, strlen(JPATH_ROOT));
     if (preg_match('/^([^.]*)\\..*\\.ini$/', $name, $matches) || preg_match('/^([^.]*)\\.ini$/', $name, $matches)) {
         $params = JComponentHelper::getParams('com_localise');
         $installation_folder = $params->get('installation', 'installation');
         $tag = $matches[1];
         if (preg_match('#^/(administrator|plugins)#', $relativePath)) {
             $id = LocaliseHelper::getFileId(JPATH_ROOT . "/administrator/language/{$tag}/{$tag}.xml");
         } elseif (preg_match('#^/' . $installation_folder . '#', $relativePath)) {
             $id = LocaliseHelper::getFileId(LOCALISEPATH_INSTALLATION . "/language/{$tag}/{$tag}.xml");
         } else {
             $id = LocaliseHelper::getFileId(JPATH_ROOT . "/language/{$tag}/{$tag}.xml");
         }
         $assetName = "com_localise.{$id}";
         if (!$asset->loadByName($assetName)) {
             $component = JTable::getInstance('asset');
             if (!$component->loadByName('com_localise')) {
                 $root = JTable::getInstance('asset');
                 $root->rebuild();
                 $root->loadByName('root.1');
                 $component->name = 'com_localise';
                 $component->title = 'com_localise';
                 $component->setLocation($root->id, 'last-child');
                 if (!$component->check() || !$component->store()) {
                     $this->setError($component->getError());
                     return false;
                 }
             }
             $asset->name = "com_localise.{$id}";
             $asset->title = $name;
             $asset->setLocation($component->id, 'last-child');
             if (!$asset->check() || !$asset->store()) {
                 $this->setError($asset->getError());
                 return false;
             }
         }
     } else {
         if (!$asset->loadByName('com_localise')) {
             $root = JTable::getInstance('asset');
             $root->loadByName('root.1');
             $asset->name = 'com_localise';
             $asset->title = 'com_localise';
             $asset->setLocation($root->id, 'last-child');
             if (!$asset->check() || !$asset->store()) {
                 $this->setError($asset->getError());
                 return false;
             }
         }
     }
     return $asset->id;
 }
예제 #6
0
    /**
     * Get the item
     */
    public function getItem()
    {
        // Get variables
        $packageName = $this->getState('exportpackage.name');
        $packageAuthor = $this->getState('exportpackage.author');
        $packageCopyright = $this->getState('exportpackage.copyright');
        $packageAuthorEmail = $this->getState('exportpackage.email');
        $packageAuthorUrl = $this->getState('exportpackage.url');
        $packageVersion = $this->getState('exportpackage.version');
        $packageLicense = $this->getState('exportpackage.license');
        $path = JPATH_COMPONENT_ADMINISTRATOR . "/packages/{$packageName}.xml";
        $id = LocaliseHelper::getFileId($path);
        // Check if the package exists
        if (empty($id)) {
            $this->setError('COM_LOCALISE_ERROR_EXPORT_UNEXISTING', $packageName);
            return false;
        }
        // Get the package model
        $model = JModelLegacy::getInstance('Package', 'LocaliseModel');
        $model->setState('package.id', $id);
        $model->setState('package.name', $packageName);
        $package = $model->getItem();
        var_dump($package);
        //jexit();
        // Check if the package is correct
        if (count($package->getErrors())) {
            $this->setError(implode('<br />', $package->getErrors()));
            return false;
        }
        // Check if the manifest exists
        $manifest = JPATH_MANIFESTS . '/files/' . $package->manifest . '.xml';
        if (is_file($manifest)) {
            // Get the key name and key description in the manifest
            $xml = simplexml_load_file($manifest);
            if ($xml) {
                $keyName = (string) $xml->name;
                $keyDescription = (string) $xml->description;
                $element = $package->manifest;
            } else {
                $this->setError('COM_LOCALISE_ERROR_EXPORT_MANIFEST', $manifest);
                return false;
            }
        } else {
            // Create the key name and key description
            $keyName = "fil_localise_package_{$packageName}";
            $keyDescription = "fil_localise_package_{$packageName}_desc";
            $element = "localise_package_{$packageName}";
        }
        // Lookup for language files
        $tags = JFolder::folders(JPATH_SITE . '/language', '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides'));
        $files = array();
        foreach ($tags as $i => $tag) {
            $langPath = "language/{$tag}/{$tag}.{$keyName}.ini";
            if (is_file(JPATH_SITE . "/{$langPath}")) {
                $files[$tag] = array();
                $files[$tag]['name'] = $langPath;
                $files[$tag]['data'] = file_get_contents(JPATH_SITE . "/{$langPath}");
                $files[$tag]['time'] = time();
                $files[$tag . '.manage'] = array();
                $files[$tag . '.manage']['name'] = "language/{$tag}/{$tag}.{$keyName}.manage.ini";
                $lang = JLanguage::getInstance($tag);
                $lang->load('com_localise', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('com_localise', JPATH_ADMINISTRATOR . '/components/com_localise', null, false, false) || $lang->load('com_localise', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load('com_localise', JPATH_ADMINISTRATOR . '/components/com_localise', $lang->getDefault(), false, false);
                $files[$tag . '.manage']['data'] = strtoupper($keyName) . '="' . sprintf($lang->_('COM_LOCALISE_NAME_PACKAGE'), $lang->_($package->title)) . "\"\n";
                $files[$tag . '.manage']['data'] .= strtoupper($keyDescription) . '="' . sprintf($lang->_('COM_LOCALISE_DESCRIPTION_PACKAGE'), $lang->_($package->title)) . "\"\n";
                $files[$tag . '.manage']['time'] = time();
            } else {
                unset($tags[$i]);
            }
        }
        $files['package'] = array();
        $files['package']['name'] = "packages/{$packageName}.xml";
        $files['package']['data'] = file_get_contents($path);
        $files['package']['time'] = time();
        $files['manifest'] = array();
        $files['manifest']['name'] = $element . '.xml';
        $files['manifest']['data'] = '<?xml version="1.0" encoding="UTF-8"?>
<extension type="file" version="3.1" method="upgrade">
	<name>' . strtoupper($keyName) . '</name>
	<description>' . strtoupper($keyDescription) . '</description>
	<creationDate>' . JFactory::getDate()->format('F j, Y') . '</creationDate>
	<author>' . $packageAuthor . '</author>
	<copyright>' . $packageCopyright . '</copyright>
	<authorEmail>' . $packageAuthorEmail . '</authorEmail>
	<authorUrl>' . $packageAuthorUrl . '</authorUrl>
	<version>' . $packageVersion . '</version>
	<license>' . $packageLicense . '</license>
	<fileset>
		<files target="media/com_localise">
		<file>packages/' . $packageName . '.xml</file>
	</files>
	</fileset>
	<languages>';
        foreach ($tags as $tag) {
            $files['manifest']['data'] .= '<language tag="' . $tag . '">language/' . $tag . '/' . $tag . '.' . $keyName . '.ini</language>';
            $files['manifest']['data'] .= '<language tag="' . $tag . '">language/' . $tag . '/' . $tag . '.' . $keyName . '.manage.ini</language> ';
        }
        $files['manifest']['data'] .= '</languages></extension>';
        $files['manifest']['time'] = time();
        $ziproot = JPATH_ROOT . '/tmp/' . uniqid('com_localise_') . '.zip';
        // Delete old files
        $delete = JFolder::files(JPATH_ROOT . '/tmp/', 'com_localise_', false, true);
        if (!empty($delete)) {
            if (!JFile::delete($delete)) {
                // JFile::delete throws an error
                $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPDELETE'));
                return false;
            }
        }
        // Run the packager
        if (!($packager = JArchive::getAdapter('zip'))) {
            $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ADAPTER'));
            return false;
        } else {
            if (!$packager->create($ziproot, $files)) {
                $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPCREATE'));
                return false;
            }
        }
        // Create item
        $item = new JObject();
        $item->filename = "fil_localise_{$packageName}_package" . ($packageVersion ? "-{$packageVersion}" : '');
        $item->contents = file_get_contents($ziproot);
        return $item;
    }
예제 #7
0
 /**
  * Method to save data
  *
  * @param  array  the data to save
  * @return  boolean  success or failure
  */
 public function save($data)
 {
     // Get the package name
     $name = $data['name'];
     // Get the package
     $package = $this->getItem();
     $path = JPATH_COMPONENT_ADMINISTRATOR . "/packages/{$name}.xml";
     $manifest = $package->manifest ? $package->manifest : 'fil_localise_package_' . $name;
     $client = $package->client ? $package->client : 'site';
     if ($package->standalone) {
         $title = $package->title ? $package->title : 'fil_localise_package_' . $name;
         $description = $package->description ? $package->description : 'fil_localise_package_' . $name . '_desc';
         // Prepare text to save for the xml package description
         $text = '';
         $text .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
         $text .= '<package>' . "\n";
         $text .= '<title>' . $title . '</title>' . "\n";
         $text .= '<description>' . $description . '</description>' . "\n";
         $text .= '<manifest client="' . $client . '">' . $manifest . '</manifest>' . "\n";
         $text .= '<icon>' . $data['icon'] . '</icon>' . "\n";
         $text .= '<author>' . $data['author'] . '</author>' . "\n";
         $text .= '<copyright>' . $data['copyright'] . '</copyright>' . "\n";
         $text .= '<license>' . $data['license'] . '</license>' . "\n";
         $administrator = array();
         $site = array();
         $installation = array();
         foreach ($data['translations'] as $translation) {
             if (preg_match('/^site_(.*)$/', $translation, $matches)) {
                 $site[] = $matches[1];
             }
             if (preg_match('/^administrator_(.*)$/', $translation, $matches)) {
                 $administrator[] = $matches[1];
             }
             if (preg_match('/^installation_(.*)$/', $translation, $matches)) {
                 $installation[] = $matches[1];
             }
         }
         if (count($site)) {
             $text .= '<site>' . "\n";
             foreach ($site as $translation) {
                 $text .= '<filename>' . $translation . '.ini</filename>' . "\n";
             }
             $text .= '</site>' . "\n";
         }
         if (count($administrator)) {
             $text .= '<administrator>' . "\n";
             foreach ($administrator as $translation) {
                 $text .= '<filename>' . $translation . '.ini</filename>' . "\n";
             }
             $text .= '</administrator>' . "\n";
         }
         if (count($installation)) {
             $text .= '<installation>' . "\n";
             foreach ($installation as $translation) {
                 $text .= '<filename>' . $translation . '.ini</filename>' . "\n";
             }
             $text .= '</installation>' . "\n";
         }
         $text .= '</package>' . "\n";
         // Set FTP credentials, if given.
         JClientHelper::setCredentialsFromRequest('ftp');
         $ftp = JClientHelper::getCredentials('ftp');
         // Try to make the file writeable.
         if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) {
             $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_WRITABLE', $path));
             return false;
         }
         $return = JFile::write($path, $text);
         // Try to make the file unwriteable.
         if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0444')) {
             $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_UNWRITABLE', $path));
             return false;
         } else {
             if (!$return) {
                 $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_FILESAVE', $path));
                 return false;
             }
         }
     }
     // Save the title and the description in the language file
     $translation_path = LocaliseHelper::findTranslationPath($client, JFactory::getLanguage()->getTag(), $manifest);
     $translation_id = LocaliseHelper::getFileId($translation_path);
     $translation_model = JModelLegacy::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true));
     if ($translation_model->checkout($translation_id)) {
         $translation_model->setState('translation.path', $translation_path);
         $translation_model->setState('translation.client', $client);
         $translation = $translation_model->getItem();
         $sections = LocaliseHelper::parseSections($translation_path);
     } else {
     }
     $text = '';
     $text .= strtoupper($title) . '="' . str_replace('"', '"_QQ_"', $data['title']) . "\"\n";
     $text .= strtoupper($description) . '="' . str_replace('"', '"_QQ_"', $data['description']) . "\"\n";
     $tag = JFactory::getLanguage()->getTag();
     $languagePath = JPATH_SITE . "/language/{$tag}/{$tag}.{$manifest}.ini";
     // Try to make the file writeable.
     if ($exists && !$ftp['enabled'] && JPath::isOwner($languagePath) && !JPath::setPermissions($languagePath, '0644')) {
         $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_WRITABLE', $languagePath));
         return false;
     }
     $return = JFile::write($languagePath, $text);
     // Try to make the file unwriteable.
     if (!$ftp['enabled'] && JPath::isOwner($languagePath) && !JPath::setPermissions($languagePath, '0444')) {
         $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_UNWRITABLE', $languagePath));
         return false;
     } else {
         if (!$return) {
             $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_FILESAVE', $languagePath));
             return false;
         }
     }
     $id = LocaliseHelper::getFileId($path);
     $this->setState('package.id', $id);
     // Bind the rules.
     $table = $this->getTable();
     $table->load($id);
     if (isset($data['rules'])) {
         $rules = new JAccessRules($data['rules']);
         $table->setRules($rules);
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     return true;
 }
예제 #8
0
 private function _getTranslations()
 {
     if (!isset($this->translations)) {
         $filter_state = $this->getState('filter.state') ? $this->getState('filter.state') : '.';
         $filter_tag = $this->getState('filter.tag') ? "^" . $this->getState('filter.tag') . "\$" : '.';
         $cache_controller = JCacheController::getInstance();
         $key = 'translation-' . ($this->getState('filter.client') ? $this->getState('filter.client') . '-' : '') . ($this->getState('filter.storage') ? $this->getState('filter.storage') . '-' : '') . ($this->getState('filter.tag') ? "^(" . $this->getState('translations.reference') . "|" . $this->getState('filter.tag') . ")\$" . '-' : '') . ($this->getState('filter.type') ? $this->getState('filter.type') . '-' : '') . ($this->getState('filter.search') ? $this->getState('filter.search') . '-' : '') . ($this->getState('filter.origin') ? $this->getState('filter.origin') . '-' : '');
         $key = substr($key, 0, strlen($key) - 1);
         $this->translations = $cache_controller->get($key, 'localise');
         if (!is_array($this->translations)) {
             $this->translations = array();
             $this->_scanLocalTranslationsFolders();
             $this->_scanGlobalTranslationsFolders();
             $this->_scanReference();
             $this->_scanOverride();
             $cache_controller->store($this->translations, $key, 'localise');
         }
         foreach ($this->translations as $key => $translation) {
             $model = JModelLegacy::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true));
             $model->setState('translation.id', LocaliseHelper::getFileId($translation->path));
             $model->setState('translation.path', $translation->path);
             $model->setState('translation.refpath', $translation->refpath);
             $model->setState('translation.reference', $this->getState('translations.reference'));
             $model->setState('translation.client', $translation->client);
             $model->setState('translation.tag', $translation->tag);
             $model->setState('translation.filename', $translation->filename);
             $item = $model->getItem();
             $state = count($item->error) ? 'error' : $translation->state;
             if (preg_match("/{$filter_state}/", $state) && preg_match("/{$filter_tag}/", $translation->tag)) {
                 if (count($item->error)) {
                     $item->state = 'error';
                     $item->completed = -count($item->error) - 1000;
                 } elseif ($item->bom != 'UTF-8') {
                     if ($translation->state == 'notinreference') {
                         $item->completed = -500;
                     } else {
                         $item->completed = -400;
                     }
                 } elseif ($translation->state == 'notinreference') {
                     $item->completed = -600;
                 } elseif ($translation->type == 'override') {
                     $item->completed = 101;
                 } elseif ($translation->tag == $this->getState('translations.reference')) {
                     $item->completed = 102;
                 } elseif ($translation->state == 'unexisting') {
                     $item->completed = -($item->total / ($item->total + 1));
                 } elseif ($item->complete) {
                     $item->completed = 100;
                 }
                 $this->translations[$key]->setProperties($item->getProperties());
             } else {
                 unset($this->translations[$key]);
             }
         }
         JArrayHelper::sortObjects($this->translations, $this->getState('list.ordering', 'name'), $this->getState('list.direction') == 'asc' ? 1 : -1);
         $this->translations = array_values($this->translations);
     }
     return $this->translations;
 }
예제 #9
0
 public function save($data = array())
 {
     $id = $this->getState('language.id');
     $tag = $data['tag'];
     $client = $data['client'];
     $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.xml";
     $exists = JFile::exists($path);
     if ($exists && !empty($id) || !$exists && empty($id)) {
         $text = '';
         $text .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
         $text .= '<metafile version="3.1" client="' . htmlspecialchars($client, ENT_COMPAT, 'UTF-8') . '">' . "\n";
         $text .= "\t" . '<tag>' . htmlspecialchars($tag, ENT_COMPAT, 'UTF-8') . '</tag>' . "\n";
         $text .= "\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n";
         $text .= "\t" . '<description>' . htmlspecialchars($data['description'], ENT_COMPAT, 'UTF-8') . '</description>' . "\n";
         $text .= "\t" . '<version>' . htmlspecialchars($data['version'], ENT_COMPAT, 'UTF-8') . '</version>' . "\n";
         $text .= "\t" . '<creationDate>' . htmlspecialchars($data['creationDate'], ENT_COMPAT, 'UTF-8') . '</creationDate>' . "\n";
         $text .= "\t" . '<author>' . htmlspecialchars($data['author'], ENT_COMPAT, 'UTF-8') . '</author>' . "\n";
         $text .= "\t" . '<authorEmail>' . htmlspecialchars($data['authorEmail'], ENT_COMPAT, 'UTF-8') . '</authorEmail>' . "\n";
         $text .= "\t" . '<authorUrl>' . htmlspecialchars($data['authorUrl'], ENT_COMPAT, 'UTF-8') . '</authorUrl>' . "\n";
         $text .= "\t" . '<copyright>' . htmlspecialchars($data['joomlacopyright'], ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n";
         $data['copyright'] = explode("\n", $data['copyright']);
         foreach ($data['copyright'] as $copyright) {
             if ($copyright) {
                 $text .= "\t" . '<copyright>' . htmlspecialchars($copyright, ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n";
             }
         }
         $text .= "\t" . '<license>' . htmlspecialchars($data['license'], ENT_COMPAT, 'UTF-8') . '</license>' . "\n";
         if ($tag == 'en-GB') {
             $text .= "\t" . '<files>' . "\n";
             $xml = simplexml_load_file($path);
             foreach ($xml->files->children() as $file) {
                 $text .= "\t\t" . '<filename>' . $file . '</filename>' . "\n";
             }
             $text .= "\t" . '</files>' . "\n";
         } else {
             $text .= "\t" . '<files>' . "\n";
             $xml = simplexml_load_file(constant('LOCALISEPATH_' . strtoupper($client)) . "/language/en-GB/en-GB.xml");
             foreach ($xml->files->children() as $file) {
                 $text .= "\t\t" . '<filename>' . str_replace('en-GB', $tag, $file) . '</filename>' . "\n";
             }
             $text .= "\t" . '</files>' . "\n";
         }
         $text .= "\t" . '<metadata>' . "\n";
         $text .= "\t\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n";
         $text .= "\t\t" . '<tag>' . htmlspecialchars($data['tag'], ENT_COMPAT, 'UTF-8') . '</tag>' . "\n";
         $text .= "\t\t" . '<rtl>' . htmlspecialchars($data['rtl'], ENT_COMPAT, 'UTF-8') . '</rtl>' . "\n";
         $text .= "\t\t" . '<locale>' . htmlspecialchars($data['locale'], ENT_COMPAT, 'UTF-8') . '</locale>' . "\n";
         $text .= "\t\t" . '<firstDay>' . htmlspecialchars($data['firstDay'], ENT_COMPAT, 'UTF-8') . '</firstDay>' . "\n";
         $text .= "\t" . '</metadata>' . "\n";
         $text .= "\t" . '<params />' . "\n";
         $text .= '</metafile>' . "\n";
         // Set FTP credentials, if given.
         JClientHelper::setCredentialsFromRequest('ftp');
         $ftp = JClientHelper::getCredentials('ftp');
         // Try to make the file writeable.
         if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) {
             $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_WRITABLE', $path));
             return false;
         }
         $return = JFile::write($path, $text);
         // Get the Localise parameters
         $params = JComponentHelper::getParams('com_localise');
         // Get the file save permission
         $fileSavePermission = $params->get('filesavepermission', '0444');
         // Try to make the template file unwriteable.
         if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, $fileSavePermission)) {
             $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_UNWRITABLE', $path));
             return false;
         } else {
             if (!$return) {
                 $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILESAVE', $path));
                 return false;
             }
         }
         $id = LocaliseHelper::getFileId($path);
         $this->setState('language.id', $id);
         // Bind the rules.
         $table = $this->getTable();
         $table->load($id);
         if (isset($data['rules'])) {
             $rules = new JAccessRules($data['rules']);
             $table->setRules($rules);
         }
         // Check the data.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Store the data.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
         return true;
     } else {
         $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILERESET', $path));
         return false;
     }
 }
예제 #10
0
		<?php 
        echo JHtml::_('jgrid.action', $i, '', array('tip' => true, 'inactive_title' => JText::sprintf('COM_LOCALISE_TOOLTIP_TRANSLATIONS_ERROR', substr($item->path, strlen(JPATH_ROOT)), implode(', ', $item->error)), 'inactive_class' => '16-error', 'enabled' => false, 'translate' => false));
        ?>
		<?php 
        echo $item->name;
        ?>
		<?php 
    }
    ?>
	</td>
	<td dir="ltr">
		<?php 
    if ($item->writable && $canEdit) {
        ?>
		<a class="hasTooltip" href="<?php 
        echo JRoute::_('index.php?option=com_localise&task=translation.edit&client=' . $item->client . '&tag=' . $item->tag . '&filename=' . $item->filename . '&storage=' . $item->storage . '&id=' . LocaliseHelper::getFileId(LocaliseHelper::getTranslationPath($item->client, $item->tag, $item->filename, $item->storage)) . '&layout=raw');
        ?>
" title="<?php 
        echo JText::_('COM_LOCALISE_TOOLTIP_TRANSLATIONS_' . ($item->state == 'unexisting' ? 'NEWRAW' : 'EDITRAW'));
        ?>
">
			<?php 
        echo substr($item->path, strlen(JPATH_ROOT));
        ?>
		</a>
		<?php 
    } else {
        ?>
		<?php 
        echo substr($item->path, strlen(JPATH_ROOT));
        ?>