/** * Delete a file. * * @return void */ public function delete() { $input = JFactory::getApplication()->input; try { EcrFile::deleteFile(); JFactory::getApplication()->enqueueMessage(jgettext('Template has been deleted.')); } catch (Exception $e) { EcrHtml::message($e); } //try $input->set('view', 'templates'); $input->set('task', 'tplarchive'); parent::display(); }
/** * Delete a zip file. * * @return void */ public function delete() { ob_start(); try { EcrFile::deleteFile(); $this->response->message = jgettext('The file has been deleted'); } catch (Exception $e) { $this->response->debug .= ECR_DEBUG ? nl2br($e) : ''; $this->response->message = $e->getMessage(); $this->response->status = 1; } $buffer = ob_get_clean(); if ($buffer) { $this->response->status = 1; $this->response->debug .= $buffer; } echo $this->response; jexit(); }
/** * Delete a translation by key. * * @param string $lang Language tag e.g. en-GB * @param string $key The key to delete * * @throws Exception * @return boolean */ public function deleteTranslation($lang, $key) { $fileName = $this->getFileName($lang, $this->_scope, $this->project); $origFile = $this->parseFile($fileName); $resultFile = array(); $pos = 1; $found = false; foreach ($origFile as $line) { switch ($line->key) { case '#': case '-': $resultFile[] = $line->value; $pos++; break; default: if ($line->key == $key) { //--Found it $found = true; } else { $resultFile[] = $line->key . '=' . $line->value; } break; } //switch } //foreach if (!$found) { //-- Item to delete has not been found ! throw new Exception(sprintf(jgettext('Key not found: %s'), $key)); } //-- Save a version ? if (JFactory::getApplication()->input->getInt('save_version', '1')) { if (!EcrFile::saveVersion($fileName)) { throw new Exception(jgettext('Can not save version')); } } $contents = implode("\n", $resultFile); if (!JFile::write($fileName, $contents)) { throw new Exception(sprintf(jgettext('Unable to write file %s'), $fileName)); } return true; }
/** * Save a file. * * @return void */ public function save() { $input = JFactory::getApplication()->input; $old_task = $input->get('old_task', null); $task = $old_task ? $old_task : 'stuffer'; $input->set('task', $task); $input->set('view', 'stuffer'); ob_start(); try { EcrFile::saveFile(); $this->response['text'] = jgettext('The file has been saved'); } catch (Exception $e) { $this->response['status'] = 1; $this->response['text'] = $e->getMessage(); } //try $buffer = ob_get_clean(); $this->response['debug'] = $buffer; echo json_encode($this->response); jexit(); }
/** * Convert a language file. * * @return void */ public function do_convert() { $input = JFactory::getApplication()->input; $input->set('task', 'convert'); $options = $input->get('options', array()); $options = JArrayHelper::toObject($options, 'JObject'); //-- Get the project try { $project = EcrProjectHelper::getProject(); } catch (Exception $e) { EcrHtml::message($e); parent::display(); return; } //try $languages = JFactory::getLanguage()->getKnownLanguages(); $converter = new EcrLanguageConverter($options, $project); $selLanguage = $input->get('sel_language'); $selectedFile = $input->get('selected_file'); $fileErrors = $input->get('file_errors', array()); $scope = $input->get('scope'); $selectedErrors = $input->get('selected_errors', array()); /* * Clean language files */ $paths = (array) $project->getLanguagePaths(); foreach ($languages as $tag => $language) { foreach ($paths[$scope] as $path) { $fileName = $path . DS . 'language' . DS . $tag . DS . $tag . '.' . $project->getLanguageFileName($scope); if (!JFile::exists($fileName)) { continue; } $fileContents = JFile::read($fileName); $lines = explode("\n", $fileContents); $newLines = $converter->cleanLines($lines); $newLines = $converter->cleanLangFileErrors($newLines, array_keys($selectedErrors)); $newFileContents = implode("\n", $newLines); EcrFile::saveVersion($fileName); JFile::write($fileName, $newFileContents); } //foreach } //foreach if ($selectedFile && count($selectedErrors)) { /* * Clean PHP file */ $origCode = JFile::read(JPATH_ROOT . DS . $selectedFile); $errors = $converter->findPHPErrors($origCode, array_keys($selectedErrors)); $newCode = $origCode; foreach ($errors as $errorKey => $errorJText) { $newJText = str_replace($errorKey, $converter->cleanKey($errorKey), $errorJText); $newCode = str_replace($errorJText, $newJText, $newCode); } //foreach if ($newCode != $origCode) { EcrFile::saveVersion(JPATH_ROOT . DS . $selectedFile); JFile::write(JPATH_ROOT . DS . $selectedFile, $newCode); } } parent::display(); }