예제 #1
0
 protected function populateState()
 {
     $input = JFactory::getApplication()->input;
     // Get the infos
     $client = $input->getCmd('client', '');
     $tag = $input->getCmd('tag', '');
     $filename = $input->getCmd('filename', '');
     $storage = $input->getCmd('storage', '');
     $this->setState('translation.client', !empty($client) ? $client : 'site');
     $this->setState('translation.tag', $tag);
     $this->setState('translation.filename', $filename);
     $this->setState('translation.storage', $storage);
     // Get the id
     $id = $input->getInt('id', '0');
     $this->setState('translation.id', $id);
     // Get the layout
     $layout = $input->getCmd('layout', 'edit');
     $this->setState('translation.layout', $layout);
     // Get the parameters
     $params = JComponentHelper::getParams('com_localise');
     // Get the reference tag
     $ref = $params->get('language.reference', 'en-GB');
     $this->setState('translation.reference', $ref);
     // Get the paths
     $path = LocaliseHelper::getTranslationPath($client, $tag, $filename, $storage);
     if ($filename == 'lib_joomla') {
         $refpath = LocaliseHelper::findTranslationPath('administrator', $ref, $filename);
         if (!JFile::exists($path)) {
             $path2 = LocaliseHelper::getTranslationPath($client == 'administrator' ? 'site' : 'administrator', $tag, $filename, $storage);
             if (JFile::exists($path2)) {
                 $path = $path2;
             }
         }
     } else {
         $refpath = LocaliseHelper::findTranslationPath($client, $ref, $filename);
     }
     $this->setState('translation.path', $path);
     $this->setState('translation.refpath', $refpath);
 }
예제 #2
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;
 }