Project

General

Profile

Bug #23995 » 16315__em_splitting_classes_v2.patch

Administrator Admin, 2010-11-10 11:27

View differences:

typo3/sysext/em/classes/database/class.tx_em_database.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
* (c) 2010 Steffen Kamper <info@sk-typo3.de>
* 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!
***************************************************************/
/**
* class.tx_em_database.php
*
* Module: Extension manager - DB access
*
* $Id: class.tx_em_database.php 2082 2010-03-21 17:19:42Z steffenk $
*
* @author Marcus Krause <marcus#exp2010@t3sec.info>
* @author Steffen Kamper <info@sk-typo3.de>
*/
/**
* DB access class for extension manager.
*
* Contains static methods for DB operations.
*
* @author Marcus Krause <marcus#exp2010@t3sec.info>
* @author Steffen Kamper <info@sk-typo3.de>
*
* @since 2010-02-27
* @package TYPO3
* @subpackage EM
*/
final class tx_em_Database {
const MULTI_LINEBREAKS = "\n\n\n";
const TABLE_REPOSITORY = 'sys_ter';
const TABLE_EXTENSION = 'cache_extensions';
/**
* Get the count of extensions in cache_extensions from a repository.
*
* If $repository parameter is obmitted, sum of all extensions will be
* returned.
*
* @access public
* @param integer $repository (optional) repository uid of extensions to count
* @return integer sum of extensions in database
*/
public function getExtensionCountFromRepository($repository = NULL) {
if (is_null($repository)) {
return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
'DISTINCT(extkey)',
self::TABLE_EXTENSION
);
} else {
return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
'DISTINCT(extkey)',
self::TABLE_EXTENSION,
'repository=' . intval($repository)
);
}
}
/**
* Get extension list from cache_extensions
*
* @param $repository
* @param string $andWhere
* @param string $orderBy
* @param string $orderDir
* @param string $limit
* @return array
*/
public function getExtensionListFromRepository($repository, $andWhere = '', $orderBy = '', $orderDir = 'ASC', $limit = '') {
$order = $orderBy ? $orderBy . ' ' . $orderDir : '';
$ret = array();
$temp = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'count(*) count',
'cache_extensions',
'repository=' . intval($repository) . $andWhere,
'extkey'
);
$ret['count'] = count($temp);
$ret['results'] = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'*, count(*) versions, max(intversion) maxintversion',
'cache_extensions',
'repository=' . intval($repository) . $andWhere,
'extkey',
$order,
$limit
);
return $ret;
}
/**
* Get versions of extension
*
* @param int $repository
* @param string $extKey
* @retuen array $versions
*/
public function getExtensionVersionsFromRepository($repository, $extKey) {
$versions = array();
//TODO: implement
return $versions;
}
/**
* Function inserts a repository object into database.
*
* @access public
* @param tx_em_Repository $repository repository object
* @return void
*/
public function updateRepository(tx_em_Repository $repository) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(self::TABLE_REPOSITORY, $repository->getId(),
array(
'title' => $repository->getTitle(),
'description' => $repository->getDescription(),
'wsdl_url' => $repository->getWsdlUrl(),
'mirror_url' => $repository->getMirrorListUrl(),
'lastUpdated' => $repository->getLastUpdate(),
'extCount' => $repository->getExtensionCount(),
));
}
/**
* Function inserts a repository object into database.
*
* @access public
* @param tx_em_Repository $repository repository object
* @return integer UID of the newly inserted repository object
*/
public function insertRepository(tx_em_Repository $repository) {
$GLOBALS['TYPO3_DB']->exec_INSERTquery(self::TABLE_REPOSITORY,
array(
'title' => $repository->getId(),
'description' => $repository->getDescription(),
'wsdl_url' => $repository->getWsdlUrl(),
'mirror_url' => $repository->getMirrorListUrl(),
'lastUpdated' => $repository->getLastUpdate(),
'extCount' => $repository->getExtensionCount(),
));
return $GLOBALS['TYPO3_DB']->sql_insert_id();
}
/**
* Insert version
*
* @param $arrFields
* @return void
*/
public function insertVersion(array $arrFields) {
$GLOBALS['TYPO3_DB']->exec_INSERTquery(self::TABLE_EXTENSION, $arrFields);
}
/**
* Method finds and returns repository fields identified by its UID.
*
* @access public
* @param int $uid repository UID
*/
public function getRepositoryByUID($uid) {
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', self::TABLE_REPOSITORY, 'uid=' . intval($uid));
return $row[0];
}
/**
* Method finds and returns repository identified by its title
*
* @param $title
* @return
*/
public function getRepositoryByTitle($title) {
return $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'*',
self::TABLE_REPOSITORY,
'title=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($title,
self::TABLE_REPOSITORY)
);
}
/**
* Get available repositories
*
* @param string $where
* @return array
*/
public function getRepositories($where = NULL) {
return $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'*',
self::TABLE_REPOSITORY,
$where ? $where : ''
);
}
/**
* Dump table content
* Is DBAL compliant, but the dump format is written as MySQL standard. If the INSERT statements should be imported in a DBMS using other quoting than MySQL they must first be translated. t3lib_sqlengine can parse these queries correctly and translate them somehow.
*
* @param string Table name
* @param array Field structure
* @return string SQL Content of dump (INSERT statements)
*/
function dumpTableContent($table, $fieldStructure) {
// Substitution of certain characters (borrowed from phpMySQL):
$search = array('\\', '\'', "\x00", "\x0a", "\x0d", "\x1a");
$replace = array('\\\\', '\\\'', '\0', '\n', '\r', '\Z');
$lines = array();
// Select all rows from the table:
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, '');
// Traverse the selected rows and dump each row as a line in the file:
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
$values = array();
foreach ($fieldStructure as $field) {
$values[] = isset($row[$field]) ? "'" . str_replace($search, $replace, $row[$field]) . "'" : 'NULL';
}
$lines[] = 'INSERT INTO ' . $table . ' VALUES (' . implode(', ', $values) . ');';
}
// Free DB result:
$GLOBALS['TYPO3_DB']->sql_free_result($result);
// Implode lines and return:
return implode(LF, $lines);
}
/**
* Gets the table and field structure from database.
* Which fields and which tables are determined from the ext_tables.sql file
*
* @param string Array with table.field values
* @return array Array of tables and fields splitted.
*/
function getTableAndFieldStructure($parts) {
// Instance of install tool
$instObj = new t3lib_install();
$dbFields = $instObj->getFieldDefinitions_database(TYPO3_db);
$outTables = array();
foreach ($parts as $table) {
$sub = explode('.', $table);
if ($sub[0] && isset($dbFields[$sub[0]])) {
if ($sub[1]) {
$key = explode('KEY:', $sub[1], 2);
if (count($key) == 2 && !$key[0]) { // key:
if (isset($dbFields[$sub[0]]['keys'][$key[1]])) {
$outTables[$sub[0]]['keys'][$key[1]] = $dbFields[$sub[0]]['keys'][$key[1]];
}
} else {
if (isset($dbFields[$sub[0]]['fields'][$sub[1]])) {
$outTables[$sub[0]]['fields'][$sub[1]] = $dbFields[$sub[0]]['fields'][$sub[1]];
}
}
} else {
$outTables[$sub[0]] = $dbFields[$sub[0]];
}
}
}
return $outTables;
}
/**
* Makes a dump of the tables/fields definitions for an extension
*
* @param array Array with table => field/key definition arrays in
* @return string SQL for the table definitions
* @see dumpStaticTables()
*/
function dumpTableAndFieldStructure($arr) {
$tables = array();
if (count($arr)) {
// Get file header comment:
$tables[] = self::dumpHeader();
// Traverse tables, write each table/field definition:
foreach ($arr as $table => $fieldKeyInfo) {
$tables[] = self::dumpTableHeader($table, $fieldKeyInfo);
}
}
// Return result:
return implode(LF . LF . LF, $tables);
}
/**
* Dump content for static tables
*
* @param string Comma list of tables from which to dump content
* @return string Returns the content
* @see dumpTableAndFieldStructure()
*/
function dumpStaticTables($tableList) {
$instObj = t3lib_div::makeInstance('t3lib_install');
$dbFields = $instObj->getFieldDefinitions_database(TYPO3_db);
$out = '';
$parts = t3lib_div::trimExplode(',', $tableList, TRUE);
// Traverse the table list and dump each:
foreach ($parts as $table) {
if (is_array($dbFields[$table]['fields'])) {
$header = self::dumpHeader();
$tableHeader = self::dumpTableHeader($table, $dbFields[$table], TRUE);
$insertStatements = self::dumpTableContent($table, $dbFields[$table]['fields']);
$out .= $header . self::MULTI_LINEBREAKS .
$tableHeader . self::MULTI_LINEBREAKS .
$insertStatements . self::MULTI_LINEBREAKS;
} else {
throw new RuntimeException(
'TYPO3 Fatal Error: ' . $GLOBALS['LANG']->getLL('dumpStaticTables_table_not_found'),
1270853983
);
}
}
unset($instObj);
return $out;
}
/**
* Header comments of the SQL dump file
*
* @return string Table header
*/
function dumpHeader() {
return trim('
# TYPO3 Extension Manager dump 1.1
#
# Host: ' . TYPO3_db_host . ' Database: ' . TYPO3_db . '
#--------------------------------------------------------
');
}
/**
* Dump CREATE TABLE definition
*
* @param string Table name
* @param array Field and key information (as provided from Install Tool class!)
* @param boolean If true, add "DROP TABLE IF EXISTS"
* @return string Table definition SQL
*/
function dumpTableHeader($table, $fieldKeyInfo, $dropTableIfExists = 0) {
$lines = array();
$dump = '';
// Create field definitions
if (is_array($fieldKeyInfo['fields'])) {
foreach ($fieldKeyInfo['fields'] as $fieldN => $data) {
$lines[] = ' ' . $fieldN . ' ' . $data;
}
}
// Create index key definitions
if (is_array($fieldKeyInfo['keys'])) {
foreach ($fieldKeyInfo['keys'] as $fieldN => $data) {
$lines[] = ' ' . $data;
}
}
// Compile final output:
if (count($lines)) {
$dump = trim('
#
# Table structure for table "' . $table . '"
#
' . ($dropTableIfExists ? 'DROP TABLE IF EXISTS ' . $table . ';
' : '') . 'CREATE TABLE ' . $table . ' (
' . implode(',' . LF, $lines) . '
);');
}
return $dump;
}
}
?>
t3lib/core_autoload.php (revision )
$tslibClasses = require(PATH_typo3 . 'sysext/cms/ext_autoload.php');
$emClasses = array();
$emClasses = require(PATH_typo3 . 'sysext/em/ext_autoload.php');
return array_merge($t3libClasses, $tslibClasses, $emClasses);
return array_merge($t3libClasses, $tslibClasses);
?>
typo3/sysext/em/ext_emconf.php (revision )
'CGLcompliance' => '',
'CGLcompliance_note' => '',
'version' => '1.1.0',
'_md5_values_when_last_written' => 'a:16:{s:12:"ext_icon.gif";s:4:"3a30";s:14:"ext_tables.php";s:4:"6e0d";s:23:"mod1/class.em_index.php";s:4:"4966";s:22:"mod1/class.em_soap.php";s:4:"67b6";s:31:"mod1/class.em_terconnection.php";s:4:"630f";s:23:"mod1/class.em_unzip.php";s:4:"e3a9";s:28:"mod1/class.em_xmlhandler.php";s:4:"8445";s:21:"mod1/class.nusoap.php";s:4:"dfa8";s:14:"mod1/clear.gif";s:4:"cc11";s:13:"mod1/conf.php";s:4:"6ea9";s:17:"mod1/download.png";s:4:"c5b2";s:11:"mod1/em.gif";s:4:"3a30";s:14:"mod1/index.php";s:4:"e8e5";s:16:"mod1/install.gif";s:4:"8d57";s:14:"mod1/oodoc.gif";s:4:"744b";s:18:"mod1/uninstall.gif";s:4:"a77f";}',
'_md5_values_when_last_written' => 'a:16:{s:12:"ext_icon.gif";s:4:"3a30";s:14:"ext_tables.php";s:4:"6e0d";s:23:"mod1/index.php";s:4:"4966";s:22:"mod1/class.tx_em_Connection_Soap.php";s:4:"67b6";s:31:"mod1/class.tx_em_Connection_Ter.php";s:4:"630f";s:23:"mod1/class.tx_em_tools_unzip.php";s:4:"e3a9";s:28:"mod1/class.tx_em_tools_xmlhandler.php";s:4:"8445";s:21:"mod1/class.nusoap.php";s:4:"dfa8";s:14:"mod1/clear.gif";s:4:"cc11";s:13:"mod1/conf.php";s:4:"6ea9";s:17:"mod1/download.png";s:4:"c5b2";s:11:"mod1/em.gif";s:4:"3a30";s:14:"mod1/index.php";s:4:"e8e5";s:16:"mod1/install.gif";s:4:"8d57";s:14:"mod1/oodoc.gif";s:4:"744b";s:18:"mod1/uninstall.gif";s:4:"a77f";}',
'constraints' => array(
'depends' => array(
'cms' => '',
typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Steffen Kamper (info@sk-typo3.de)
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* Module: Extension manager, developer module
*
* This class handles all Ajax calls coming from ExtJS
*
* $Id: class.tx_em_Connection_ExtDirectServer.php 2083 2010-03-22 00:48:31Z steffenk $
*
* @author Steffen Kamper <info@sk-typo3.de>
*/
class tx_em_Connection_ExtDirectServer {
/**
* @var tx_em_Tools_XmlHandler
*/
var $xmlhandler;
/**
* Keeps instance of settings class.
*
* @var tx_em_Settings
*/
static protected $objSettings;
/*********************************************************************/
/* General */
/*********************************************************************/
/**
* Constructor
*
* @return void
*/
public function __construct() {
$GLOBALS['TBE_TEMPLATE'] = t3lib_div::makeInstance('template');
}
/**
* Method returns instance of settings class.
*
* @access protected
* @return em_settings instance of settings class
*/
protected function getSettingsObject() {
if (!is_object(self::$objSettings) && !(self::$objSettings instanceof tx_em_Settings)) {
self::$objSettings = t3lib_div::makeInstance('tx_em_Settings');
}
return self::$objSettings;
}
/*********************************************************************/
/* Local Extension List */
/*********************************************************************/
/**
* Render local extension list
*
* @return string $content
*/
public function getExtensionList() {
$list = t3lib_div::makeInstance('tx_em_Extensions_List');
$extList = $list->getInstalledExtensions(TRUE);
return array(
'length' => count($extList),
'data' => $extList
);
}
/**
* Enter description here...
*
* @return unknown
*/
public function getInstalledExtkeys() {
$list = t3lib_div::makeInstance('tx_em_Extensions_List');
$extList = $list->getInstalledExtensions(TRUE);
$temp = $this->getSettings();
$selectedLanguage = unserialize($temp['selectedLanguages']);
$keys = array();
$i = 0;
foreach ($extList as $ext) {
if ($ext['installed']) {
$keys[$i] = array(
'extkey' => $ext['extkey'],
'icon' => $ext['icon'],
'stype' => $ext['typeShort'],
);
foreach ($selectedLanguage as $language) {
$keys[$i]['lang'][] = $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language);
}
$i++;
}
}
return array(
'length' => count($keys),
'data' => $keys,
);
}
/**
* Render module content
*
* @return string $content
*/
public function getExtensionDetails() {
$list = t3lib_div::makeInstance('tx_em_Extensions_List');
$extList = $list->getInstalledExtensions(TRUE);
return array(
'length' => count($extList),
'data' => $extList
);
}
/**
* Render extension update
*
* @var string $extKey
* @return string $content
*/
public function getExtensionUpdate($extKey) {
if (isset($GLOBALS['TYPO3_LOADED_EXT'][$extKey])) {
$path = t3lib_extMgm::extPath($extKey);
$ext = array();
$install = t3lib_div::makeInstance('tx_em_Install');
$extension = t3lib_div::makeInstance('tx_em_Extensions_List');
$extension->singleExtInfo($extKey, $path, $ext);
$ext = $ext[0];
$update = $install->checkDBupdates($extKey, $ext);
return $update ? $update : 'Extension is up to date.';
} else {
return 'Extension "' . htmlspecialchars($extKey) . '" is not installed.';
}
}
/**
* Render extension configuration
*
* @var string $extKey
* @return string $content
*/
public function getExtensionConfiguration($extKey) {
$extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
list($list,) = $extensionList->getInstalledExtensions();
$install = t3lib_div::makeInstance('tx_em_Install');
$form = $install->updatesForm($extKey, $list[$extKey], 1);
if (!$form) {
return '<p>' . 'This extension has no configuration.' . '</p>';
} else {
return $form;
}
}
/**
* Save extension configuration
*
* @formHandler
* @param array $parameter
* @return array
*/
public function saveExtensionConfiguration($parameter) {
return array(
'success' => true,
'data' => $parameter
);
}
/**
* genereates a file tree
*
* @param object $parameter
* @return array
*/
public function getExtFileTree($parameter) {
$ext = array();
$extKey = $parameter->extkey;
$type = $parameter->typeShort;
$node = strpos($parameter->node, '/') !== FALSE ? $parameter->node : $parameter->baseNode;
$path = PATH_site . $node;
$fileArray = array();
$dirs = t3lib_div::get_dirs($path);
$files = t3lib_div::getFilesInDir($path, '', FALSE, '', '');
$editTypes = explode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']);
$imageTypes = array('gif', 'jpg', 'png');
if (!is_array($files) || !count($files)) {
return array();
}
foreach ($dirs as $dir) {
if ($dir{0} !== '.') {
$fileArray[] = array(
'id' => $node . '/' . $dir,
'text' => htmlspecialchars($dir),
'leaf' => false,
'qtip' => ''
);
}
}
foreach ($files as $key => $file) {
$fileExt = strtolower(substr($file, strrpos($file, '.') + 1));
if (in_array($fileExt, $imageTypes)) {
$cls = 'tree-image';
} elseif (in_array($fileExt, $editTypes)) {
$cls = 'tree-edit';
} else {
$cls = 'tree-unknown';
}
$fileArray[] = array(
'id' => $node . '/' . $file,
'text' => htmlspecialchars($file),
'leaf' => true,
'qtip' => $fileExt . ' - file',
'iconCls' => $cls
);
}
return $fileArray;
}
/**
* Read extension file and send content
*
* @param string $path
* @return string file content
*/
public function readExtFile($path) {
$path = PATH_site . $path;
if (@file_exists($path)) {
//TODO: charset conversion
return t3lib_div::getURL($path);
}
return '';
}
/**
* Save extension file
*
* @param string $file
* @param string $content
* @return boolean success
*/
public function saveExtFile($file, $content) {
$path = PATH_site . $path;
if (@file_exists($path)) {
//TODO: save only if saving was enabled
return t3lib_div::writeFile($path, $content);
}
return FALSE;
}
/**
* Load upload form for extension upload to TER
*
* @formcHandler
* @return array
*/
public function loadUploadExtToTer() {
$settings = $this->getSettings();
return array(
'success' => TRUE,
'data' => array(
'fe_u' => $settings['fe_u'],
'fe_p' => $settings['fe_p']
)
);
}
/**
* Upload extension to TER
*
* @formHandler
*
* @param string $parameter
* @return array
*/
public function uploadExtToTer($parameter) {
return array(
'success' => TRUE,
'fe_p' => $parameter['fe_p'],
'fe_u' => $parameter['fe_u'],
'newversion' => $parameter['newversion'],
'uploadcomment' => $parameter['uploadcomment']
);
}
/**
* Prints developer information
*
* @param string $parameter
* @return array
*/
public function getExtensionDevelopInfo($extKey) {
$extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
list($list,) = $extensionList->getInstalledExtensions();
$extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
return $extensionDetails->extInformationarray($extKey, $list[$extKey]);
}
/*********************************************************************/
/* Remote Extension List */
/*********************************************************************/
/**
* Render remote extension list
*
* @param object $parameters
* @return string $content
*/
public function getRemoteExtensionList($parameters) {
/* @var $repoUtility em_repository_utility */
$repoUtility = t3lib_div::makeInstance('tx_em_Repository_Utility');
$repoUtility->setRepository($this->getSettingsObject()->getSelectedRepository());
$search = $parameters->query;
$limit = $parameters->start . ', ' . $parameters->limit;
$orderBy = $parameters->sort;
$orderDir = $parameters->dir;
if ($search == '*') {
$where = '';
} else {
$quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike(
$GLOBALS['TYPO3_DB']->quoteStr($search, 'cache_extensions'),
'cache_extensions'
);
$where = ' AND (extkey LIKE \'%' . $quotedSearch . '%\' OR title LIKE \'%' . $quotedSearch . '%\')';
}
$list = tx_em_Database::getExtensionListFromRepository(
$repoUtility->getRepositoryUID(),
$where,
$orderBy,
$orderDir,
$limit
);
return array(
'length' => $list['count'],
'data' => $list['results']
);
}
/**
* Loads repositories
*
* @return array
*/
public function repositoryUpdateLoad() {
$settings = $this->getSettings();
$repositories = tx_em_Database::getRepositories();
foreach ($repositories as $uid => $repository) {
$data[] = array(
'title' => $repository['title'],
'value' => $repository['uid'],
'description' => $repository['description'],
'wsdl_url' => $repository['wsdl_url'],
'mirror_url' => $repository['mirror_url'],
'count' => $repository['extCount'],
'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
'selected' => $repository['uid'] === $settings['selectedRepository'],
);
}
return array(
'length' => count($data),
'data' => $data,
);
}
/**
* Edit / Create repository
*
* @formHandler
* @param array $parameter
* @return array
*/
public function repositoryEditFormSubmit($parameter) {
return array(
'success' => TRUE,
'data' => array(
'params' => $parameter
),
);
}
/**
* Update repository
*
* @formHandler
*
* @param array $parameter
* @return array
*/
public function repositoryUpdate($parameter) {
if (!intval($parameter['rep'])) {
return array(
'success' => FALSE,
'errors' => 'no repository choosen'
);
}
$objRepository = t3lib_div::makeInstance('tx_em_Repository', intval($parameter['rep']));
$objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
$count = $objRepositoryUtility->updateExtList();
if ($count) {
$objRepository->setExtensionCount($count);
$objRepository->setLastUpdate(time());
tx_em_Database::updateRepository($objRepository);
return array(
'success' => TRUE,
'data' => array(
'count' => $count
)
);
} else {
return array(
'success' => FALSE,
'errormsg' => 'Your repository is up to date.'
);
}
}
/*********************************************************************/
/* Translation Handling */
/*********************************************************************/
/**
* Enter description here...
*
* @return unknown
*/
public function getLanguages() {
$temp = $this->getSettings();
$selected = unserialize($temp['selectedLanguages']);
$theLanguages = t3lib_div::trimExplode('|', TYPO3_languages);
//drop default
array_shift($theLanguages);
$lang = array();
foreach ($theLanguages as $language) {
$label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language));
$flag = @is_file(PATH_typo3 . 'gfx/flags/' . $language . '.gif') ? 'gfx/flags/' . $language . '.gif' : 'gfx/flags/unknown.gif';
$lang[] = array(
'label' => $label,
'lang' => $language,
'flag' => $flag,
'selected' => in_array($language, $selected) ? 1 : 0
);
}
return array(
'length' => count($lang),
'data' => $lang,
);
}
/**
* Saves language selection
*
* @param array $parameter
* @return string
*/
public function saveLanguageSelection($parameter) {
$this->saveSetting('selectedLanguages', serialize($parameter));
//TODO: use language label
return 'Saved languages: ' . implode(', ', $parameter);
}
/**
* Fetches translation from server
*
* @param string $extkey
* @param string $type
* @param array $selection
* @return array
*/
public function fetchTranslations($extkey, $type, $selection) {
$result = array();
if (is_array($selection) && count($selection)) {
$terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
$this->xmlhandler = t3lib_div::makeInstance('tx_em_Tools_XmlHandler');
$this->xmlhandler->emObj = $this;
$mirrorURL = $this->getSettingsObject()->getMirrorURL();
foreach ($selection as $lang) {
$fetch = $terConnection->fetchTranslationStatus($extkey, $mirrorURL);
$localmd5 = '';
if (!isset($fetch[$lang])) {
//no translation available
$result[0][$lang] = 'N/A';
} else {
$localmd5 = '';
if (is_file(PATH_site . 'typo3temp/' . $extkey . '-l10n-' . $lang . '.zip')) {
$localmd5 = md5_file(PATH_site . 'typo3temp/' . $extkey . '-l10n-' . $lang . '.zip');
}
if ($localmd5 !== $fetch[$lang]['md5']) {
if ($type) {
//fetch translation
$ret = $terConnection->updateTranslation($extkey, $lang, $mirrorURL);
$result[0][$lang] = $ret ? 'updated' : 'failed';
} else {
//translation status
$result[0][$lang] = $localmd5 !== '' ? 'update' : 'new';
}
} else {
//translation is up to date
$result[0][$lang] = 'ok';
}
}
}
}
return $result;
}
/*********************************************************************/
/* Settings */
/*********************************************************************/
/**
* Returns settings object.
*
* @access public
* @return tx_em_Settings instance of settings object
*/
public function getSettings() {
return $this->getSettingsObject()->getSettings();
}
/**
* Enter description here...
*
* @param string $name
* @param mixed $value
* @return boolean
*/
public function saveSetting($name, $value) {
$this->getSettingsObject()->saveSetting($name, $value);
return TRUE;
}
/**
* Load form values for settings form
*
* @return array FormValues
*/
public function settingsFormLoad() {
$settings = $this->getSettings();
return array(
'success' => TRUE,
'data' => array(
'display_unchecked' => $settings['display_unchecked'],
'fe_u' => $settings['fe_u'],
'fe_p' => $settings['fe_p'],
'selectedMirror' => $settings['selectedMirror'],
'selectedRepository' => $settings['selectedRepository'],
)
);
}
/**
* Save settings from form submit
*
* @formHandler
* @param array $parameter
* @return array
*/
public function settingsFormSubmit($parameter) {
$settings = $this->getSettingsObject()->saveSettings(array(
'display_unchecked' => isset($parameter['display_unchecked']),
'fe_u' => $parameter['fe_u'],
'fe_p' => $parameter['fe_p'],
'selectedMirror' => $parameter['selectedMirror'],
'selectedRepository' => $parameter['selectedRepository'],
));
return array(
'success' => TRUE,
'data' => $parameter,
'settings' => $settings
);
}
/*********************************************************************/
/* EM Tools */
/*********************************************************************/
/**
* Upload an extension
*
* @formHandler
*
* @access public
* @param $parameter composed parameter from $POST and $_FILES
* @return array status
*/
public function uploadExtension($parameter) {
$uploadedTempFile = t3lib_div::upload_to_tempfile($parameter['extupload-path']['tmp_name']);
$location = ($parameter['loc'] === 'G' || $parameter['loc'] === 'S') ? $parameter['loc'] : 'L';
$uploadOverwrite = $parameter['uploadOverwrite'] ? TRUE : FALSE;
$install = t3lib_div::makeInstance('tx_em_Install', $this);
$upload = $install->uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite);
if ($upload[0] === FALSE) {
return array(
'success' => FALSE,
'error' => $upload[1]
);
}
$extKey = $upload[1][0]['extKey'];
$result = $install->installExtension($upload[1], $location);
return array(
'success' => TRUE,
'data' => $result,
'extKey' => $extKey
);
}
}
?>
typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlabstractparser.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
* Steffen Kamper <info@sk-typo3.de>
* 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!
***************************************************************/
/**
* class.tx_em_parser_mirrorxmlabstractparser.php
*
* Module: Extension manager - mirror.xml abstract parser
*
* $Id: class.tx_em_parser_mirrorxmlabstractparser.php 1913 2010-02-21 15:47:37Z mkrause $
*
* @author Marcus Krause <marcus#exp2010@t3sec.info>
* @author Steffen Kamper <info@sk-typo3.de>
*/
/**
* Abstract parser for TYPO3's mirror.xml file.
*
* @author Marcus Krause <marcus#exp2010@t3sec.info>
* @author Steffen Kamper <info@sk-typo3.de>
*
* @since 2010-02-09
* @package TYPO3
* @subpackage EM
*/
abstract class tx_em_Parser_MirrorXmlAbstractParser extends tx_em_Parser_XmlAbstractParser {
/**
* Keeps country of currently processed mirror.
*
* @var string
*/
protected $country = NULL;
/**
* Keeps hostname of currently processed mirror.
*
* @var string
*/
protected $host = NULL;
/**
* Keeps path to mirrored TER of currently processed mirror.
*
* @var string
*/
protected $path = NULL;
/**
* Keeps sponsor link of currently processed mirror.
*
* @var string
*/
protected $sponsorlink = NULL;
/**
* Keeps sponsor logo location of currently processed mirror.
*
* @var string
*/
protected $sponsorlogo = NULL;
/**
* Keeps sponsor name of currently processed mirror.
*
* @var string
*/
protected $sponsorname = NULL;
/**
* Keeps title of currently processed mirror.
*
* @var string
*/
protected $title = NULL;
/**
* Returns an assoziative array of all mirror properties.
*
* Valid array keys of returned array are:
* country, host, path, sponsorlink, sponsorlogo, sponsorname, title
*
* @access public
* @return array assoziative array of a mirror's properties
* @see $country, $host, $path, $sponsorlink, $sponsorlogo, $sponsorname, $title
*/
public function getAll() {
$mirrorProperties = array();
$mirrorProperties['title'] = $this->title;
$mirrorProperties['host'] = $this->host;
$mirrorProperties['path'] = $this->path;
$mirrorProperties['country'] = $this->country;
$mirrorProperties['sponsorname'] = $this->sponsorname;
$mirrorProperties['sponsorlink'] = $this->sponsorlink;
$mirrorProperties['sponsorlogo'] = $this->sponsorlogo;
return $mirrorProperties;
}
/**
* Returns country of currently processed mirror.
*
* @access public
* @return string name of country a mirror is located in
* @see $country, getAll()
*/
public function getCountry() {
return $this->country;
}
/**
* Returns host of currently processed mirror.
*
* @access public
* @return string host name
* @see $host, getAll()
*/
public function getHost() {
return $this->host;
}
/**
* Returns path to mirrored TER of currently processed mirror.
*
* @access public
* @return string path name
* @see $path, getAll()
*/
public function getPath() {
return $this->path;
}
/**
* Returns sponsor link of currently processed mirror.
*
* @access public
* @return string URL of a sponsor's website
* @see $sponsorlink, getAll()
*/
public function getSponsorlink() {
return $this->sponsorlink;
}
/**
* Returns sponsor logo location of currently processed mirror.
*
* @access public
* @return string a sponsor's logo location
* @see $sponsorlogo, getAll()
*/
public function getSponsorlogo() {
return $this->sponsorlogo;
}
/**
* Returns sponsor name of currently processed mirror.
*
* @access public
* @return string name of sponsor
* @see $sponsorname, getAll()
*/
public function getSponsorname() {
return $this->sponsorname;
}
/**
* Returns title of currently processed mirror.
*
* @access public
* @return string title of mirror
* @see $title, get All()
*/
public function getTitle() {
return $this->title;
}
/**
* Method resets version class properties.
*
* @access protected
* @return void
* @see $country, $host, $path, $sponsorlink, $sponsorlogo, $sponsorname, $title
*/
protected function resetProperties() {
$this->title = $this->host = $this->path =
$this->country = $this->sponsorname = $this->sponsorlink =
$this->sponsorlogo;
}
/**
* Method provides a wrapper for an exception call
*
* @access protected
* @param string $message the exception message to throw.
* @param integer $code the exception code.
* @return void
*/
protected function throwException($message = "", $code = 0) {
throw new tx_em_MirrorXmlException(get_class($this) . ': ' . $message, $code);
}
}
?>
typo3/sysext/em/classes/import/class.tx_em_import_extensionlistimporter.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
* Steffen Kamper <info@sk-typo3.de>
* 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!
***************************************************************/
/**
* class.tx_em_import_extensionlistimporter.php
*
* Module: Extension manager - Extension list importer
*
* $Id: class.tx_em_import_extensionlistimporter.php 2016 2010-03-14 04:01:47Z mkrause $
*
* @author Marcus Krause <marcus#exp2010@t3sec.info>
* @author Steffen Kamper <info@sk-typo3.de>
*/
/**
* Importer object for extension list
*
* @author Marcus Krause <marcus#exp2010@t3sec.info>
* @author Steffen Kamper <info@sk-typo3.de>
*
* @since 2010-02-10
* @package TYPO3
* @subpackage EM
*/
class tx_em_Import_ExtensionListImporter implements SplObserver {
/**
* Keeps instance of a XML parser.
*
* @var em_xml_abstract_parser
*/
protected $parser;
/**
* Keeps number of processed version records.
*
* @var integer
*/
protected $sumRecords = 0;
/**
* Keeps record values to be inserted into database.
*
* @var array
*/
protected $arrRows = array();
/**
* Keeps fieldnames of cache_extension table.
*
* @var array
*/
static protected $fieldNames = array('extkey', 'version', 'intversion', 'alldownloadcounter', 'downloadcounter', 'title', 'ownerusername', 'authorname', 'authoremail', 'authorcompany', 'lastuploaddate', 't3xfilemd5', 'repository', 'state', 'reviewstate', 'category', 'description', 'dependencies', 'uploadcomment' /*, 'lastversion', 'lastreviewedversion'*/);
/**
* Keeps indexes of fields that should not be quoted.
*
* @var array
*/
static protected $fieldIndicesNoQuote = array(2, 3, 4, 10, 12, 13, 14, 15);
/**
* Keeps repository UID.
*
* The UID is necessary for inserting records.
*
* @var integer
*/
protected $repositoryUID = 1;
/**
* Class constructor.
*
* Method retrieves and initializes extension XML parser instance.
*
* @access public
* @return void
* @throws tx_em_XmlException in case no valid parser instance is available
*/
function __construct() {
// TODO catch parser exception
//$this->parser = em_xml_parser_factory::getParserInstance('extension');
if (!is_object(tx_em_XmlParserFactory::getParserInstance('extension'))) {
throw new tx_em_XmlException(get_class($this) . ': ' . 'No XML parser available.');
}
}
/**
* Gets parser object
*
* @return tx_em_XmlParserFactory
*/
protected function getParser() {
$parser = tx_em_XmlParserFactory::getParserInstance('extension');
$parser->attach($this);
return $parser;
}
/**
* Method initializes parsing of extension.xml.gz file.
*
* @access public
* @param string $localExtListFile absolute path to (gzipped) local extension list xml file
* @param integer $repositoryUID UID of repository to be used when inserting records into DB
* @return integer total number of imported extension versions
*/
public function import($localExtListFile, $repositoryUID = NULL) {
if (!is_null($repositoryUID) && is_int($repositoryUID)) {
$this->repositoryUID = $repositoryUID;
}
$zlibStream = 'compress.zlib://';
$this->sumRecords = 0;
$this->getParser()->parseXML($zlibStream . $localExtListFile);
... This diff was truncated because it exceeds the maximum size that can be displayed.
(2-2/2)