Commit 744d2252 authored by speedprogs_de's avatar speedprogs_de

added view helper for documentation link, fixed several file handling and template bugs

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51677 735d13b6-9817-0410-8766-e36946ffe9aa
parent f02eba77
......@@ -77,7 +77,7 @@
$topRatedCount = (!empty($this->settings['topRatedCount']) ? $this->settings['topRatedCount'] : 10);
$topRatedExtensions = $this->extensionRepository->findTopRated($topRatedCount);
$this->view->assign('topRatedExtensions', $topRatedExtensions);
/*
// Get all categories
$categories = $this->categoryRepository->findAll();
$this->view->assign('categories', $categories);
......@@ -85,7 +85,7 @@
// Get all tags
$tags = $this->tagRepository->findAll();
$this->view->assign('tags', $tags);
*/
// Get random authors
$randomAuthorCount = (!empty($this->settings['randomAuthorCount']) ? $this->settings['randomAuthorCount'] : 10);
$randomAuthors = $this->authorRepository->findRandom($randomAuthorCount);
......
......@@ -111,17 +111,18 @@
*/
public function getIconUrl(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$filename = $this->getFileName($version, $fileType);
$localName = $this->imageCachePath . basename($filename);
// Check local cache first
if (Tx_TerFe2_Utility_File::fileExists($this->imageCachePath . $filename)) {
return t3lib_div::locationHeaderUrl($this->imageCachePath . $filename);
if (Tx_TerFe2_Utility_File::fileExists($localName)) {
return Tx_TerFe2_Utility_File::getUrlFromAbsolutePath($localName);
}
// Get icon from concrete extension provider
$iconUrl = $this->getFileUrl($filename);
$iconUrl = $this->getFileUrl($version, $fileType);
// Copy icon to local cache
Tx_TerFe2_Utility_File::copyFile($iconUrl, $this->imageCachePath . $filename);
Tx_TerFe2_Utility_File::copyFile($iconUrl, $localName);
return $iconUrl;
}
......
......@@ -139,7 +139,7 @@
public function getFileName(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$extension = $version->getExtension()->getExtKey();
$version = $version->getVersionString();
$this->generateFileName($extension, $version, $fileType);
return $this->generateFileName($extension, $version, $fileType);
}
......
......@@ -120,7 +120,7 @@
public function getFileName(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$extension = $version->getExtension()->getExtKey();
$version = $version->getVersionString();
$this->generateFileName($extension, $version, $fileType);
return $this->generateFileName($extension, $version, $fileType);
}
......
......@@ -36,7 +36,7 @@
/**
* Initialize the service
*
*
* @return void
*/
public function __construct() {
......
......@@ -88,11 +88,6 @@
*/
protected $authorRepository;
/**
* @var Tx_TerFe2_Service_Documentation
*/
protected $documentationService;
/**
* Initialize task
......@@ -114,7 +109,6 @@
$this->persistenceManager = $this->objectManager->get('Tx_Extbase_Persistence_Manager');
$this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionRepository');
$this->authorRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_AuthorRepository');
$this->documentationService = $this->objectManager->get('Tx_TerFe2_Service_Documentation');
// Set registry name to current provider name
$this->registry->setName(get_class($this) . '_' . $this->providerName);
......@@ -200,12 +194,6 @@
$version->setExtensionProvider($this->providerName);
$modified = TRUE;
// Online documentation
if (!$version->getManual()) {
$documentationUrl = $this->documentationService->getDocumentationUrl($extensionRow['ext_key'], $versionRow['version_string']);
$version->setManual($documentationUrl);
}
// Relations
foreach ($versionRow['relations'] as $relationRow) {
$relation = $this->objectBuilder->create('Tx_TerFe2_Domain_Model_Relation', $relationRow);
......
......@@ -125,14 +125,19 @@
$visibleFileName = basename($filename);
}
// Send headers
header('Cache-Control: no-cache, must-revalidate');
// Send file
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: Sat, 10 Jan 1970 00:00:00 GMT');
header('Pragma: public');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . (string) $visibleFileName);
header('Content-type: x-application/octet-stream');
header('Content-Transfer-Encoding: binary');
// Send file contents
if (self::isAbsolutePath($filename)) {
header('Content-Length: ' . filesize($filename));
}
ob_clean();
flush();
readfile($filename);
exit;
}
......@@ -152,14 +157,17 @@
return FALSE;
}
// Send headers
header('Cache-Control: no-cache, must-revalidate');
// Send file content
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: Sat, 10 Jan 1970 00:00:00 GMT');
header('Pragma: public');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . (string) $fileName);
header('Content-type: x-application/octet-stream');
header('Content-Transfer-Encoding: binary');
// Send file contents
header('Content-Length: ' . strlen($content));
ob_clean();
flush();
echo $content;
exit;
}
......@@ -226,10 +234,21 @@
* @return boolean TRUE if success
*/
public static function copyFile($fromFileName, $toFileName, $overwrite = FALSE) {
if (empty($fromFileName) || empty($toFileName)) {
return FALSE;
}
// Check if target directory exists
if (!self::fileExists(dirname($toFileName))) {
return FALSE;
}
// Get local url
if (self::isLocalUrl($fromFileName)) {
$fromFileName = self::getAbsolutePathFromUrl($fromFileName);
}
// Get file content
$fromFile = t3lib_div::getURL($fromFileName);
// Check files
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.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!
******************************************************************/
/**
* Documentation link view helper
*/
class Tx_TerFe2_ViewHelpers_DocumentationLinkViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Disable the escaping interceptor
*/
protected $escapingInterceptorEnabled = FALSE;
/**
* @var Tx_TerFe2_Service_Documentation
*/
protected $documentationService;
/**
* Inject the documentation service
*
* @param Tx_TerFe2_Service_Documentation $documentationService Service for extension manuals
* @return void
*/
public function injectDocumentationService(Tx_TerFe2_Service_Documentation $documentationService) {
$this->documentationService = $documentationService;
}
/**
* Renders the documentation link for a version object
*
* @param Tx_TerFe2_Domain_Model_Version $version Version object
* @return string Rendered image tag
*/
public function render(Tx_TerFe2_Domain_Model_Version $version = NULL) {
if ($version === NULL) {
$version = $this->renderChildren();
}
$extensionKey = $version->getExtension()->getExtKey();
$versionString = $version->getVersionString();
return $this->documentationService->getDocumentationUrl($extensionKey, $versionString);
}
}
?>
\ No newline at end of file
......@@ -64,7 +64,7 @@
</TCEforms>
<type>array</type>
<el>
</el>
</ROOT>
</sLIST>
......@@ -75,7 +75,7 @@
</TCEforms>
<type>array</type>
<el>
</el>
</ROOT>
</sDETAIL>
......@@ -86,7 +86,7 @@
</TCEforms>
<type>array</type>
<el>
</el>
</ROOT>
</sSEARCH>
......
......@@ -133,6 +133,7 @@
<label index="delete">Delete</label>
<label index="download_t3x">Download T3X file</label>
<label index="download_zip">Download ZIP file</label>
<label index="read_manual">Manual</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<f:for each="{extensions}" as="extension">
<div class="tx_terfe2_extension">
<h3>
<span class="tx_terfe2_icon"><terfe2:extensionIcon version="{extension.lastVersion}" alt="{extension.lastVersion.title}"></terfe2:extensionIcon></span>
<span class="tx_terfe2_icon"><terfe2:extensionIcon version="{extension.lastVersion}" alt="{extension.lastVersion.title}" /></span>
<f:link.action controller="Extension" action="show" arguments="{extension : extension}">{extension.lastVersion.title} ({extension.extKey})</f:link.action>
</h3>
<p class="tx_terfe2_description">{extension.lastVersion.description}</p>
......
{namespace terfe2=Tx_TerFe2_ViewHelpers}
<f:layout name="Default" />
<f:section name="main">
......@@ -5,7 +7,7 @@
<div class="extension">
<h3>
<span class="icon"><terfe2:extensionIcon extension="{extension}" version="{extension.lastVersion}" alt="{extension.lastVersion.title}"></terfe2:extensionIcon></span>
<span class="icon"><terfe2:extensionIcon version="{extension.lastVersion}" alt="{extension.lastVersion.title}" /></span>
{extension.lastVersion.title} ({extension.extKey})
</h3>
<p class="description">{extension.lastVersion.description}</p>
......@@ -19,6 +21,7 @@
<ul>
<li><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion}"><f:translate key="download_t3x"/></f:link.action></li>
<li><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion, format : 'zip'}"><f:translate key="download_zip"/></f:link.action></li>
<li><f:translate key="read_manual"/>: <terfe2:documentationLink version="{extension.lastVersion}" /></li>
</ul>
<ul>
......
......@@ -49,6 +49,7 @@
'tx_terfe2_viewhelpers_cdataviewhelper' => $extensionClassesPath . 'ViewHelpers/CdataViewHelper.php',
'tx_terfe2_viewhelpers_chartviewhelper' => $extensionClassesPath . 'ViewHelpers/ChartViewHelper.php',
'tx_terfe2_viewhelpers_datetimeviewhelper' => $extensionClassesPath . 'ViewHelpers/DateTimeViewHelper.php',
'tx_terfe2_viewhelpers_documentationlinkviewhelper' => $extensionClassesPath . 'ViewHelpers/DocumentationLinkViewHelper.php',
'tx_terfe2_viewhelpers_extensioniconviewhelper' => $extensionClassesPath . 'ViewHelpers/ExtensionIconViewHelper.php',
'tx_terfe2_viewhelpers_rawviewhelper' => $extensionClassesPath . 'ViewHelpers/RawViewHelper.php',
);
......
......@@ -3,7 +3,7 @@
die ('Access denied.');
}
// Make plugin available in Frontend
// Make plugin available in frontend
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'Pi1',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment