Commit 3a1d9f36 authored by Damjan's avatar Damjan
Browse files

[TASK] Renaming "class.tx_lfeditor_mod1_file_xxx.php" files to "FileXxx.php"

and folder renaming: classes\fileService -> classes\Service.
* This commit is addition to previous commit.

Related: forge.typo3.org/issues/31889
parent 18f3818d
<?php
/***************************************************************
* Copyright notice
*
* (c) Stefan Galinski (stefan.galinski@gmail.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* include some general functions only usable for the 'lfeditor' module
*/
abstract class tx_lfeditor_mod1_file {
/**
* @var array
*/
protected $localLang = array();
/**
* @var array
*/
protected $originLang = array();
/**
* @var string
*/
protected $absPath;
/**
* @var string
*/
protected $relFile;
/**
* @var string
*/
protected $absFile;
/**
* @var string
*/
protected $fileType;
/**
* @var string
*/
protected $workspace;
/**#@-*/
/**
* @var array
*/
protected $meta;
/**
* @return mixed
*/
abstract protected function prepareFileContents();
/**
* @return mixed
*/
abstract protected function readFile();
/**
* sets some variables
*
* @param string $file filename or relative path from second param to the language file
* @param string $path absolute path to the extension or language file
* @return void
*/
public function init($file, $path) {
$this->setVar(array('absPath' => $path, 'relFile' => $file));
}
/**
* sets information
*
* structure:
* $infos["absPath"] = absolute path to an extension or file
* $infos["relFile"] = relative path with filename from "absPath"
* $infos["workspace"] = workspace (base or xll)
* $infos["fileType"] = file type (php or xml)
* $infos["localLang"] = language data
* $infos["originLang"] = origin language array
* $infos["meta"] = meta data
*
* @param array $informations
* @return void
*/
public function setVar($informations) {
// path and file information
if (!empty($informations['absPath'])) {
$this->absPath = typo3Lib::fixFilePath($informations['absPath'] . '/');
}
if (!empty($informations['relFile'])) {
$this->relFile = typo3Lib::fixFilePath($informations['relFile']);
}
$this->absFile = $this->absPath . $this->relFile;
// file type and workspace
if (!empty($informations['workspace'])) {
$this->workspace = $informations['workspace'];
}
if (!empty($informations['fileType'])) {
$this->fileType = $informations['fileType'];
}
// data arrays
if (!count($this->localLang) && is_array($informations['localLang'])) {
$this->localLang = $informations['localLang'];
}
if (!count($this->originLang) && is_array($informations['originLang'])) {
$this->originLang = $informations['originLang'];
}
if (!count($this->meta) && is_array($informations['meta'])) {
$this->meta = $informations['meta'];
}
}
/**
* returns requested information
*
* @param $info string
* @return string
*/
public function getVar($info) {
$value = '';
if ($info == 'relFile') {
$value = $this->relFile;
} elseif ($info == 'absPath') {
$value = $this->absPath;
} elseif ($info == 'absFile') {
$value = $this->absFile;
} elseif ($info == 'fileType') {
$value = $this->fileType;
} elseif ($info == 'workspace') {
$value = $this->workspace;
}
return $value;
}
/**
* returns language data
*
* @param string $langKey valid language key
* @return array language data
*/
public function getLocalLangData($langKey = '') {
if (empty($langKey)) {
return $this->localLang;
} elseif (is_array($this->localLang[$langKey])) {
return $this->localLang[$langKey];
} else {
return array();
}
}
/**
* deletes or sets constants in local language data
*
* @param string $constant constant name (if empty an index number will be used)
* @param string $value new value (if empty the constant will be deleted)
* @param string $langKey language shortcut
* @param boolean $forceDel set to true, if you want delete default values too
* @return void
*/
public function setLocalLangData($constant, $value, $langKey, $forceDel = FALSE) {
if (!empty($value) || (($langKey == 'default' && !$forceDel))) {
$this->localLang[$langKey][$constant] = $value;
} elseif (isset($this->localLang[$langKey][$constant])) {
unset($this->localLang[$langKey][$constant]);
}
}
/**
* returns origin
*
* @param string $langKey valid language key
* @return mixed an origin or full array
*/
public function getOriginLangData($langKey = '') {
if (empty($langKey)) {
return $this->originLang;
} else {
return $this->originLang[$langKey];
}
}
/**
* sets new origin of a given language
*
* @param string $origin new origin
* @param string $langKey language shortcut
* @return void
*/
public function setOriginLangData($origin, $langKey) {
if (!empty($origin)) {
$this->originLang[$langKey] = $origin;
}
}
/**
* returns meta data
*
* @param string $metaIndex special meta index
* @return mixed meta data
*/
public function getMetaData($metaIndex = '') {
if (!empty($metaIndex)) {
return $this->meta[$metaIndex];
} else {
return $this->meta;
}
}
/**
* deletes or sets constants in meta data
*
* @param string $metaIndex
* @param string $value new value (if empty the meta index will be deleted)
* @return void
*/
public function setMetaData($metaIndex, $value) {
if (!empty($value)) {
$this->meta[$metaIndex] = $value;
} elseif (isset($this->meta[$metaIndex])) {
unset($this->meta[$metaIndex]);
}
}
/**
* writes language files
*
* @throws LFException raised if a file cant be written
* @return void
*/
public function writeFile() {
// get prepared language files
$languageFiles = $this->prepareFileContents();
// check write permissions of all files
foreach ($languageFiles as $file => $content) {
if (!sgLib::checkWritePerms($file)) {
throw new LFException('failure.file.badPermissions');
}
}
// write files
foreach ($languageFiles as $file => $content) {
if (!t3lib_div::writeFile($file, $content)) {
throw new LFException('failure.file.notWritten');
}
}
}
}
// Default-Code for using XCLASS (dont touch)
if (defined(
'TYPO3_MODE'
) && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lfeditor/classes/fileService/class.tx_lfeditor_mod1_file.php']
) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lfeditor/classes/fileService/class.tx_lfeditor_mod1_file.php']);
}
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) Stefan Galinski (stefan.galinski@gmail.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/** general file functions */
require_once(t3lib_extMgm::extPath('lfeditor') . 'classes/fileService/class.tx_lfeditor_mod1_file.php');
/**
* backup class
*/
class tx_lfeditor_mod1_file_backup extends tx_lfeditor_mod1_file {
/**
* @var string
*/
private $metaFile;
/**
* @var array
*/
private $metaArray = array();
/**
* @var string
*/
private $extName;
/**
* @var string
*/
private $extPath;
/**
* @var string
*/
private $langFile;
/**
* extended init
*
* @throws LFException raised if the meta file cant be correctly read
* @param string $file name of the file (can be a path, if you need this (no check))
* @param string $path path to the file
* @param string $metaFile absolute path to the meta file (includes filename)
* @return void
*/
public function init($file, $path, $metaFile) {
// init
$this->setVar(array('metaFile' => $metaFile));
parent::init($file, $path);
// read meta file
try {
if (is_file($this->metaFile)) {
$this->readMetaFile();
}
} catch (LFException $e) {
throw $e;
}
}
#####################
###### Set/Get ######
#####################
/**
* sets information
*
* structure:
* $infos["metaFile"] = absolute path to the meta file (includes filename)
* $infos["extPath"] = extension path
* $infos["langFile"] = language file
*
* @param array $informations information (see above)
* @return void
*/
public function setVar($informations) {
if (!empty($informations['metaFile'])) {
$this->metaFile = typo3Lib::fixFilePath($informations['metaFile']);
}
if (!empty($informations['extPath'])) {
$this->extPath = typo3Lib::fixFilePath($informations['extPath']);
$this->extName = basename($informations['extPath']);
}
if (!empty($informations['langFile'])) {
$this->langFile = typo3Lib::fixFilePath($informations['langFile']);
}
parent::setVar($informations);
}
/**
* returns requested information
*
* @param string $info
* @return mixed
*/
public function getVar($info) {
if ($info == 'metaFile') {
return $this->metaFile;
} elseif ($info == 'extName') {
return $this->extName;
} elseif ($info == 'extPath') {
return $this->extPath;
} elseif ($info == 'langFile') {
return $this->langFile;
} else {
return parent::getVar($info);
}
}
/**
* returns meta information about backup files
*
* Modes:
* - 0 => full meta information (default)
* - 1 => only meta information of given extension key
* - 2 => only meta information of given extension key and workspace
* - 3 => only meta information of given extension key, workspace and language file
*
* @param integer $mode
* @param string $extName extension Name (default = $this->extName)
* @param string $workspace (default = $this->workspace)
* @param string $langFile language file (default = $this->langFile)
* @return array
*/
public function getMetaInfos($mode = 0, $extName = '', $workspace = '', $langFile = '') {
$extName = empty($extName) ? $this->extName : $extName;
$langFile = empty($langFile) ? $this->langFile : $langFile;
$workspace = empty($workspace) ? $this->workspace : $workspace;
// build return value
if (!$mode) {
return $this->metaArray;
} elseif ($mode == 1) {
return $this->metaArray[$extName];
} elseif ($mode == 2) {
return $this->metaArray[$extName][$workspace];
} elseif ($mode == 3) {
return $this->metaArray[$extName][$workspace][$langFile];
} else {
return array();
}
}
/**
* rewrites current meta information array with the given equivalent
*
* Modes:
* - 0 => full meta information (default)
* - 1 => only meta information of given extension key
* - 2 => only meta information of given extension key and workspace
* - 3 => only meta information of given extension key, workspace and language file
*
* @param array $metaArray meta information
* @param integer $mode
* @param string $extName extension Name (default = $this->extName)
* @param string $workspace (default = $this->workspace)
* @param string $langFile language file (default = $this->langFile)
* @return void
*/
private function setMetaInfos($metaArray, $mode = 0, $extName = '', $workspace = '', $langFile = '') {
$extName = empty($extName) ? $this->extName : $extName;
$langFile = empty($langFile) ? $this->langFile : $langFile;
$workspace = empty($workspace) ? $this->workspace : $workspace;
// build new meta information array
if (is_array($metaArray) && count($metaArray)) {
if (!$mode) {
$this->metaArray = $metaArray;
} elseif ($mode == 1) {
$this->metaArray[$extName] = $metaArray;
} elseif ($mode == 2) {
$this->metaArray[$extName][$workspace] = $metaArray;
} elseif ($mode == 3) {
$this->metaArray[$extName][$workspace][$langFile] = $metaArray;
}
} else {
if (!$mode) {
unset($this->metaArray);
} elseif ($mode == 1) {
unset($this->metaArray[$extName]);
} elseif ($mode == 2) {
unset($this->metaArray[$extName][$workspace]);
} elseif ($mode == 3) {
unset($this->metaArray[$extName][$workspace][$langFile]);
}
}
}
###############################
###### Meta File Methods ######
###############################
/**
* reads the meta information file and parses the content into $this->metaArray
*
* @throws LFException raised if no meta content was generated
* @return void
*/
private function readMetaFile() {
// read file and parse xml to array
$metaArray = t3lib_div::xml2array(file_get_contents($this->metaFile));
if (!is_array($metaArray)) {
throw new LFException('failure.backup.metaFile.notRead');
}
$this->metaArray = $metaArray;
}
/**
* generate meta XML
*
* @return string meta information (xml)
*/
private function genMetaXML() {
// define assocTagNames
$options['parentTagMap'] = array(
'' => 'extKey',
'extKey' => 'workspace',
'workspace' => 'langFile',
'langFile' => 'file',
);
return t3lib_div::array2xml($this->getMetaInfos(), '', 0, 'LFBackupMeta', 0, $options);
}
/**
* writes the meta information file
*
* @throws LFException raised if the meta file cant be written
* @return void
*/
private function writeMetaFile() {
$metaXML = $this->genMetaXML();
if (empty($metaXML)) {
throw new LFException('failure.backup.metaFile.notWritten');
}
if (!t3lib_div::writeFile($this->metaFile, $this->getXMLHeader() . $metaXML)) {
throw new LFException('failure.backup.metaFile.notWritten');
}
}
#################################
###### Backup File Methods ######
#################################
/**
* generates the xml header
*
* @return string xml header
*/
private function getXMLHeader() {
return '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>' . "\n";
}
/**
* removes the meta information entry and the backup file
*
* @param string $filename
* @param string $extName (default = $this->extName)
* @param string $langFile (default = $this->langFile)
* @throws Exception|LFException
* @throws LFException
* @return void
*/
public function deleteSpecFile($filename, $extName = '', $langFile = '') {
// get needed meta information
$extName = empty($extName) ? $this->extName : $extName;
$langFile = empty($langFile) ? $this->langFile : $langFile;
$metaArray = $this->getMetaInfos(3, $extName, '', $langFile);
// check backup file
if (!isset($metaArray[$filename])) {
throw new LFException('failure.backup.notDeleted');
}
// get file
$backupPath = $metaArray[$filename]['pathBackup'];
$file = t3lib_div::fixWindowsFilePath(PATH_site . '/' . $backupPath . '/' . $filename);
// build new meta information file
unset($metaArray[$filename]);
if (!count($metaArray)) {
$metaArray = NULL;
}
$this->setMetaInfos($metaArray, 3, $extName, '', $langFile);
$extMetaArray = $this->getMetaInfos(2, $extName);
if (!count($extMetaArray)) {
$extMetaArray = NULL;
}
$this->setMetaInfos($extMetaArray, 2, $extName);
// write meta information
try {
$this->writeMetaFile();
} catch (LFException $e) {