openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 3f0838253e06b7810d447783984a87384bd36498
parent dd7997f6ca754e55d11c9cf1a52cceb2beb75bdc
Author: Jan Dankert <develop@jandankert.de>
Date:   Mon, 13 May 2019 23:35:07 +0200

Einfache Umbenennung.

Diffstat:
modules/cms-core/model/File.class.php | 1140++++++++++++++++++++++++++++++++++++++++----------------------------------------
modules/cms-core/model/Page.class.php | 6+++---
modules/cms-core/model/Value.class.php | 6+++---
modules/util/cache/FileCache.class.php | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/util/cache/LoaderCache.class.php | 87-------------------------------------------------------------------------------
modules/util/require.php | 2+-
6 files changed, 664 insertions(+), 664 deletions(-)

diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php @@ -1,571 +1,571 @@ -<?php -namespace cms\model; -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program 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. -// -// This program 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. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -// Standard Mime-Type -use cms\publish\PublishEdit; -use cms\publish\PublishPreview; -use cms\publish\PublishPublic; -use cms\publish\PublishShow; -use JSqueeze; -use Less_Parser; -use Logger; -use util\LoaderCache; - -define('OR_FILE_DEFAULT_MIMETYPE','application/octet-stream'); - - -/** - * Datei. - * - * @author Jan Dankert - * @package openrat.objects - */ -class File extends BaseObject -{ - var $fileid; - - var $size = 0; - var $value = ''; - var $extension = ''; - var $log_filenames = array(); - var $fullFilename = ''; - - /** - * @var \Publish - */ - var $publish = null; - - var $mime_type = ''; - - var $tmpfile; - - var $content_negotiation = false; - - - - /** - * Um Probleme mit BLOB-Feldern und Datenbank-Besonderheiten zu vermeiden, - * kann der Binaerinhalt BASE64-kodiert gespeichert werden. - * @type Boolean - */ - var $storeValueAsBase64 = false; - - public $filterid; - - public $public = false ; - - /** - * Konstruktor - * - * @param Objekt-Id - */ - function __construct( $objectid='' ) - { - $this->storeValueAsBase64 = db()->conf['base64']; - - parent::__construct( $objectid ); - $this->isFile = true; - } - - - /** - * @return LoaderCache - */ - public function getCache() { - $cacheKey = array('db'=>db()->id,'file'=>$this->objectid,'publish'=>\ClassUtils::getSimpleClassName($this->publisher)); - - return new LoaderCache( $cacheKey,function() { - return $this->loadValueFromDatabase(); - } ); - } - - /** - * Ermitteln des Dateinamens dieser Datei - * - * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' - */ - function full_filename() - { - if ( !empty($this->fullFilename) ) - return $this->fullFilename; - - $filename = parent::full_filename(); - - if ( $this->content_negotiation && config('publish','negotiation','file_negotiate_type' ) ) - { - // Link auf Datei: Extension bleibt aufgrund Content-Negotiation leer - } - else - { - // Nein, wurde bereits in filename() ergänzt. - //if ( !empty($this->extension) ) - // $filename .= '.'.$this->extension; - } - - $this->fullFilename = $filename; - return $filename; - } - - - - /** - * Ermitteln des Dateinamens dieser Datei (ohne Pfadangabe) - * - * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' - */ - public function filename() - { - if ( !empty( $this->extension ) ) - return parent::filename().'.'.$this->extension; - else - return parent::filename(); - - } - - - - /** - * Ermitteln aller Eigenschaften. - * - * @return array - */ - function getProperties() - { - return array_merge( parent::getProperties(), - array('full_filename'=>$this->fullFilename, - 'extension' =>$this->extension, - 'size' =>$this->size, - 'filterid' =>$this->filterid, - 'mimetype' =>$this->mimetype() ) ); - } - - - - /** - * @deprecated - */ - function getFileObjectIdsByExtension( $extension ) - { - global $SESS; - $db = db_connection(); - - $sqlquery = 'SELECT * FROM {{object}} '; - - if ( $extension != '' ) - { - $sqlquery .= " WHERE extension='"; - - $ext = explode(',',$extension); - $sqlquery .= implode( "' OR extension='",$ext ); - $sqlquery .= "' AND typeid=".BaseObject::TYPEID_FILE." AND projectid={projectid}"; - } - else - { - $sqlquery .= " WHERE typeid=".BaseObject::TYPEID_FILE." AND projectid={projectid}"; - } - - $sql = $db->sql( $sqlquery ); - $sql->setInt( 'projectid',$SESS['projectid'] ); - - return $sql->getCol(); - } - - - - /** - * Es werden Objekte zu einer Dateierweiterung ermittelt - * - * @param String Dateierweiterung ohne fuehrenden Punkt (z.B. 'jpeg') - * @return array Liste der gefundenen Objekt-IDs - */ - public static function getObjectIdsByExtension( $extension ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT {{file}}.objectid FROM {{file}} '. - ' LEFT JOIN {{object}} '. - ' ON {{object}}.id={{file}}.objectid'. - ' WHERE {{file}}.extension={extension}' ); - $sql->setString( 'extension',$extension ); - - return $sql->getCol(); - } - - - - /** - * Ermittelt den Mime-Type zu dieser Datei - * - * @return String Mime-Type - */ - public function mimeType() - { - if ( !empty( $this->mime_type ) ) - return $this->mime_type; - - global $conf; - $mime_types = $conf['mime-types']; - - - - $ext = strtolower( $this->getRealExtension() ); - - if ( !empty($mime_types[$ext]) ) - $this->mime_type = $mime_types[$ext]; - else - // Wenn kein Mime-Type gefunden, dann Standartwert setzen - $this->mime_type = OR_FILE_DEFAULT_MIMETYPE; - - return( $this->mime_type ); - } - - - /** - * Lesen der Datei aus der Datenbank. - * - * Es werden nur die Meta-Daten (Erweiterung, Gr��e) gelesen. Zum Lesen des - * Datei-Inhaltes muss #loadValue() aufgerufen werden. - */ - public function load() - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT id,extension,size,filterid'. - ' FROM {{file}}'. - ' WHERE objectid={objectid}' ); - $sql->setInt( 'objectid',$this->objectid ); - $row = $sql->getRow(); - - if ( count($row)!=0 ) - { - $this->fileid = $row['id' ]; - $this->extension = $row['extension']; - $this->size = $row['size' ]; - $this->filterid = $row['filterid' ]; - } - - $this->objectLoad(); - - return $this; - } - - - - /** - * Unwiderrufliches L�schen der Datei aus der Datenbank. - */ - function delete() - { - $db = db_connection(); - - // Datei l?schen - $sql = $db->sql( 'DELETE FROM {{file}} '. - ' WHERE objectid={objectid}' ); - $sql->setInt( 'objectid',$this->objectid ); - $sql->query(); - - $this->objectDelete(); - } - - - - /** - * Stellt anhand der Dateiendung fest, ob es sich bei dieser Datei um ein Bild handelt - */ - function isImage() - { - return substr($this->mimeType(),0,6)=='image/'; - } - - - - /** - * Ermittelt die Datei-Endung. - * - * @return String Datei-Endung - */ - function extension() - { - if ($this->extension != '') - return $this->extension; - - $this->load(); - return $this->extension; - } - - - /** - * Einen Dateinamen in Dateiname und Extension aufteilen. - * @param filename Dateiname - */ - function parse_filename($filename) - { - $filename = basename($filename); - - $p = strrpos($filename, '.'); - if ($p !== false) - { - $this->extension = substr($filename, $p +1); - $this->filename = substr($filename, 0, $p); - } - else - { - $this->extension = ''; - $this->filename = $filename; - } - } - - - /** - * Speichert die Datei-Informationen in der Datenbank. - */ - public function save() - { - $db = db_connection(); - - $sql = $db->sql( <<<EOF -UPDATE {{file}} SET - size = {size}, - filterid = {filterid}, - extension = {extension} - WHERE objectid={objectid} -EOF -); - $sql->setString('size' ,$this->size ); - $sql->setString('extension',$this->extension ); - $sql->setString('objectid' ,$this->objectid ); - $sql->setInt ('filterid' ,$this->filterid ); - $sql->query(); - - $this->objectSave(); - } - - - /** - * Kopieren des Inhaltes von einer anderen Datei - * @param ID der Datei, von der der Inhalt kopiert werden soll - */ - function copyValueFromFile( $otherfileid ) - { - $of = new File( $otherfileid ); - $this->value = $of->loadValue(); - $this->saveValue(); - } - - - public function loadValue() - { - if ( filemtime($this->getCache()->getFilename() < $this->lastchangeDate)) - $this->getCache()->invalidate(); - - return $this->getCache()-get(); - } - - - /** - * Lesen des Inhaltes der Datei aus der Datenbank. - * - * @return String Inhalt der Datei - */ - private function loadValueFromDatabase() - { - // Read from cache, if cache exist and is not too old. - - $sql = db()->sql( 'SELECT size,value'. - ' FROM {{file}}'. - ' WHERE objectid={objectid}' ); - $sql->setInt( 'objectid',$this->objectid ); - $row = $sql->getRow(); - - if ( count($row) != 0 ) - { - $this->value = $row['value']; - $this->size = $row['size' ]; - } - - if ( $this->storeValueAsBase64 ) - $this->value = base64_decode( $this->value ); - - $this->filterValue(); - - return $this->value; - } - - - /** - * Speichert den Inhalt in der Datenbank. - */ - function saveValue( $value = '' ) - { - $this->getCache()->invalidate(); - - $db = db_connection(); - - $sql = $db->sql( 'UPDATE {{file}}'. - ' SET value={value}, '. - ' size={size} '. - ' WHERE objectid={objectid}' ); - $sql->setString( 'objectid' ,$this->objectid ); - $sql->setInt ( 'size' ,strlen($this->value) ); - - if ( $this->storeValueAsBase64 ) - $sql->setString( 'value',base64_encode($this->value) ); - else - $sql->setString( 'value',$this->value ); - - $sql->query(); - } - - - /** - * Lesen der Datei aus der Datenbank und schreiben in temporaere Datei - */ - function write() - { - $this->getCache()->load(); - } - - - /** - * F�gt die Datei der Datenbank hinzu. - */ - function add() - { - parent::add(); - - $sql = db()->sql('SELECT MAX(id) FROM {{file}}'); - $this->fileid = intval($sql->getOne())+1; - - $sql = db()->sql('INSERT INTO {{file}}'. - ' (id,objectid,extension,size,value)'. - " VALUES( {fileid},{objectid},{extension},0,'' )" ); - $sql->setInt ('fileid' ,$this->fileid ); - $sql->setInt ('objectid' ,$this->objectid ); - $sql->setString('extension',$this->extension ); - - $sql->query(); - - $this->saveValue(); - } - - - public function publish() - { - $this->write(); - $this->publisher->copy( $this->getCache()->getFilename(),$this->full_filename(),$this->lastchangeDate ); - - $this->publisher->publishedObjects[] = $this->getProperties(); - } - - - /** - * Setzt den Zeitstempel der Datei auf die aktuelle Zeit. - * - * @see objectClasses/Object#setTimestamp() - */ - - function setTimestamp() - { - $this->getCache()->invalidate(); - - parent::setTimestamp(); - } - - - - /** - * Ermittelt die wirksame Datei-Endung. Diese kann sich - * in der Extra-Dateiendung, aber auch direkt im Dateiname - * befinden. - * - * @return Dateiendung - */ - function getRealExtension() - { - if ( !empty($this->extension)) - { - return $this->extension; - } - else - { - $pos = strrpos($this->filename,'.'); - if ( $pos === false ) - return ''; - else - return substr($this->filename,$pos+1); - } - } - - private function filterValue() - { - $filterType = ''; - if ( $this->publisher instanceof PublishEdit ) $filterType = 'edit'; - if ( $this->publisher instanceof PublishPublic ) $filterType = 'public'; - if ( $this->publisher instanceof PublishPreview ) $filterType = 'preview'; - if ( $this->publisher instanceof PublishShow ) $filterType = 'show'; - - foreach(\ArrayUtils::getSubArray($this->getTotalSettings(), array( 'publish', $filterType, 'filter')) as $filterName ) - { - switch( $filterName) - { - case 'less': - - $parser = new Less_Parser(array( - 'sourceMap' => false, - 'indentation' => ' ', - 'outputSourceFiles' => false, - //'sourceMapBasepath' => $this->filename() - //'sourceMapBasepath' => './' - )); - - $parser->parse( $this->value ); - $this->value = $parser->getCss(); - - break; - - case 'less-minifier': - - $parser = new Less_Parser(array( - 'compress' => true, - 'sourceMap' => false, - 'indentation' => '' - )); - - $parser->parse( $this->value ); - $this->value = $parser->getCss(); - - break; - - case "js-minifier": - $jz = new JSqueeze(); - $this->value = $jz->squeeze( $this->value); - break; - - default: - throw new \LogicException("Filter not found: ".$filterName); - } - } - - // Store in cache. - $this->getCache()->invalidate(); - } -} - +<?php +namespace cms\model; +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program 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. +// +// This program 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +// Standard Mime-Type +use cms\publish\PublishEdit; +use cms\publish\PublishPreview; +use cms\publish\PublishPublic; +use cms\publish\PublishShow; +use JSqueeze; +use Less_Parser; +use Logger; +use util\FileCache; + +define('OR_FILE_DEFAULT_MIMETYPE','application/octet-stream'); + + +/** + * Datei. + * + * @author Jan Dankert + * @package openrat.objects + */ +class File extends BaseObject +{ + var $fileid; + + var $size = 0; + var $value = ''; + var $extension = ''; + var $log_filenames = array(); + var $fullFilename = ''; + + /** + * @var \Publish + */ + var $publish = null; + + var $mime_type = ''; + + var $tmpfile; + + var $content_negotiation = false; + + + + /** + * Um Probleme mit BLOB-Feldern und Datenbank-Besonderheiten zu vermeiden, + * kann der Binaerinhalt BASE64-kodiert gespeichert werden. + * @type Boolean + */ + var $storeValueAsBase64 = false; + + public $filterid; + + public $public = false ; + + /** + * Konstruktor + * + * @param Objekt-Id + */ + function __construct( $objectid='' ) + { + $this->storeValueAsBase64 = db()->conf['base64']; + + parent::__construct( $objectid ); + $this->isFile = true; + } + + + /** + * @return FileCache + */ + public function getCache() { + $cacheKey = array('db'=>db()->id,'file'=>$this->objectid,'publish'=>\ClassUtils::getSimpleClassName($this->publisher)); + + return new FileCache( $cacheKey,function() { + return $this->loadValueFromDatabase(); + } ); + } + + /** + * Ermitteln des Dateinamens dieser Datei + * + * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' + */ + function full_filename() + { + if ( !empty($this->fullFilename) ) + return $this->fullFilename; + + $filename = parent::full_filename(); + + if ( $this->content_negotiation && config('publish','negotiation','file_negotiate_type' ) ) + { + // Link auf Datei: Extension bleibt aufgrund Content-Negotiation leer + } + else + { + // Nein, wurde bereits in filename() ergänzt. + //if ( !empty($this->extension) ) + // $filename .= '.'.$this->extension; + } + + $this->fullFilename = $filename; + return $filename; + } + + + + /** + * Ermitteln des Dateinamens dieser Datei (ohne Pfadangabe) + * + * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' + */ + public function filename() + { + if ( !empty( $this->extension ) ) + return parent::filename().'.'.$this->extension; + else + return parent::filename(); + + } + + + + /** + * Ermitteln aller Eigenschaften. + * + * @return array + */ + function getProperties() + { + return array_merge( parent::getProperties(), + array('full_filename'=>$this->fullFilename, + 'extension' =>$this->extension, + 'size' =>$this->size, + 'filterid' =>$this->filterid, + 'mimetype' =>$this->mimetype() ) ); + } + + + + /** + * @deprecated + */ + function getFileObjectIdsByExtension( $extension ) + { + global $SESS; + $db = db_connection(); + + $sqlquery = 'SELECT * FROM {{object}} '; + + if ( $extension != '' ) + { + $sqlquery .= " WHERE extension='"; + + $ext = explode(',',$extension); + $sqlquery .= implode( "' OR extension='",$ext ); + $sqlquery .= "' AND typeid=".BaseObject::TYPEID_FILE." AND projectid={projectid}"; + } + else + { + $sqlquery .= " WHERE typeid=".BaseObject::TYPEID_FILE." AND projectid={projectid}"; + } + + $sql = $db->sql( $sqlquery ); + $sql->setInt( 'projectid',$SESS['projectid'] ); + + return $sql->getCol(); + } + + + + /** + * Es werden Objekte zu einer Dateierweiterung ermittelt + * + * @param String Dateierweiterung ohne fuehrenden Punkt (z.B. 'jpeg') + * @return array Liste der gefundenen Objekt-IDs + */ + public static function getObjectIdsByExtension( $extension ) + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT {{file}}.objectid FROM {{file}} '. + ' LEFT JOIN {{object}} '. + ' ON {{object}}.id={{file}}.objectid'. + ' WHERE {{file}}.extension={extension}' ); + $sql->setString( 'extension',$extension ); + + return $sql->getCol(); + } + + + + /** + * Ermittelt den Mime-Type zu dieser Datei + * + * @return String Mime-Type + */ + public function mimeType() + { + if ( !empty( $this->mime_type ) ) + return $this->mime_type; + + global $conf; + $mime_types = $conf['mime-types']; + + + + $ext = strtolower( $this->getRealExtension() ); + + if ( !empty($mime_types[$ext]) ) + $this->mime_type = $mime_types[$ext]; + else + // Wenn kein Mime-Type gefunden, dann Standartwert setzen + $this->mime_type = OR_FILE_DEFAULT_MIMETYPE; + + return( $this->mime_type ); + } + + + /** + * Lesen der Datei aus der Datenbank. + * + * Es werden nur die Meta-Daten (Erweiterung, Gr��e) gelesen. Zum Lesen des + * Datei-Inhaltes muss #loadValue() aufgerufen werden. + */ + public function load() + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT id,extension,size,filterid'. + ' FROM {{file}}'. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $row = $sql->getRow(); + + if ( count($row)!=0 ) + { + $this->fileid = $row['id' ]; + $this->extension = $row['extension']; + $this->size = $row['size' ]; + $this->filterid = $row['filterid' ]; + } + + $this->objectLoad(); + + return $this; + } + + + + /** + * Unwiderrufliches L�schen der Datei aus der Datenbank. + */ + function delete() + { + $db = db_connection(); + + // Datei l?schen + $sql = $db->sql( 'DELETE FROM {{file}} '. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $sql->query(); + + $this->objectDelete(); + } + + + + /** + * Stellt anhand der Dateiendung fest, ob es sich bei dieser Datei um ein Bild handelt + */ + function isImage() + { + return substr($this->mimeType(),0,6)=='image/'; + } + + + + /** + * Ermittelt die Datei-Endung. + * + * @return String Datei-Endung + */ + function extension() + { + if ($this->extension != '') + return $this->extension; + + $this->load(); + return $this->extension; + } + + + /** + * Einen Dateinamen in Dateiname und Extension aufteilen. + * @param filename Dateiname + */ + function parse_filename($filename) + { + $filename = basename($filename); + + $p = strrpos($filename, '.'); + if ($p !== false) + { + $this->extension = substr($filename, $p +1); + $this->filename = substr($filename, 0, $p); + } + else + { + $this->extension = ''; + $this->filename = $filename; + } + } + + + /** + * Speichert die Datei-Informationen in der Datenbank. + */ + public function save() + { + $db = db_connection(); + + $sql = $db->sql( <<<EOF +UPDATE {{file}} SET + size = {size}, + filterid = {filterid}, + extension = {extension} + WHERE objectid={objectid} +EOF +); + $sql->setString('size' ,$this->size ); + $sql->setString('extension',$this->extension ); + $sql->setString('objectid' ,$this->objectid ); + $sql->setInt ('filterid' ,$this->filterid ); + $sql->query(); + + $this->objectSave(); + } + + + /** + * Kopieren des Inhaltes von einer anderen Datei + * @param ID der Datei, von der der Inhalt kopiert werden soll + */ + function copyValueFromFile( $otherfileid ) + { + $of = new File( $otherfileid ); + $this->value = $of->loadValue(); + $this->saveValue(); + } + + + public function loadValue() + { + if ( filemtime($this->getCache()->getFilename() < $this->lastchangeDate)) + $this->getCache()->invalidate(); + + return $this->getCache()-get(); + } + + + /** + * Lesen des Inhaltes der Datei aus der Datenbank. + * + * @return String Inhalt der Datei + */ + private function loadValueFromDatabase() + { + // Read from cache, if cache exist and is not too old. + + $sql = db()->sql( 'SELECT size,value'. + ' FROM {{file}}'. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $row = $sql->getRow(); + + if ( count($row) != 0 ) + { + $this->value = $row['value']; + $this->size = $row['size' ]; + } + + if ( $this->storeValueAsBase64 ) + $this->value = base64_decode( $this->value ); + + $this->filterValue(); + + return $this->value; + } + + + /** + * Speichert den Inhalt in der Datenbank. + */ + function saveValue( $value = '' ) + { + $this->getCache()->invalidate(); + + $db = db_connection(); + + $sql = $db->sql( 'UPDATE {{file}}'. + ' SET value={value}, '. + ' size={size} '. + ' WHERE objectid={objectid}' ); + $sql->setString( 'objectid' ,$this->objectid ); + $sql->setInt ( 'size' ,strlen($this->value) ); + + if ( $this->storeValueAsBase64 ) + $sql->setString( 'value',base64_encode($this->value) ); + else + $sql->setString( 'value',$this->value ); + + $sql->query(); + } + + + /** + * Lesen der Datei aus der Datenbank und schreiben in temporaere Datei + */ + function write() + { + $this->getCache()->load(); + } + + + /** + * F�gt die Datei der Datenbank hinzu. + */ + function add() + { + parent::add(); + + $sql = db()->sql('SELECT MAX(id) FROM {{file}}'); + $this->fileid = intval($sql->getOne())+1; + + $sql = db()->sql('INSERT INTO {{file}}'. + ' (id,objectid,extension,size,value)'. + " VALUES( {fileid},{objectid},{extension},0,'' )" ); + $sql->setInt ('fileid' ,$this->fileid ); + $sql->setInt ('objectid' ,$this->objectid ); + $sql->setString('extension',$this->extension ); + + $sql->query(); + + $this->saveValue(); + } + + + public function publish() + { + $this->write(); + $this->publisher->copy( $this->getCache()->getFilename(),$this->full_filename(),$this->lastchangeDate ); + + $this->publisher->publishedObjects[] = $this->getProperties(); + } + + + /** + * Setzt den Zeitstempel der Datei auf die aktuelle Zeit. + * + * @see objectClasses/Object#setTimestamp() + */ + + function setTimestamp() + { + $this->getCache()->invalidate(); + + parent::setTimestamp(); + } + + + + /** + * Ermittelt die wirksame Datei-Endung. Diese kann sich + * in der Extra-Dateiendung, aber auch direkt im Dateiname + * befinden. + * + * @return Dateiendung + */ + function getRealExtension() + { + if ( !empty($this->extension)) + { + return $this->extension; + } + else + { + $pos = strrpos($this->filename,'.'); + if ( $pos === false ) + return ''; + else + return substr($this->filename,$pos+1); + } + } + + private function filterValue() + { + $filterType = ''; + if ( $this->publisher instanceof PublishEdit ) $filterType = 'edit'; + if ( $this->publisher instanceof PublishPublic ) $filterType = 'public'; + if ( $this->publisher instanceof PublishPreview ) $filterType = 'preview'; + if ( $this->publisher instanceof PublishShow ) $filterType = 'show'; + + foreach(\ArrayUtils::getSubArray($this->getTotalSettings(), array( 'publish', $filterType, 'filter')) as $filterName ) + { + switch( $filterName) + { + case 'less': + + $parser = new Less_Parser(array( + 'sourceMap' => false, + 'indentation' => ' ', + 'outputSourceFiles' => false, + //'sourceMapBasepath' => $this->filename() + //'sourceMapBasepath' => './' + )); + + $parser->parse( $this->value ); + $this->value = $parser->getCss(); + + break; + + case 'less-minifier': + + $parser = new Less_Parser(array( + 'compress' => true, + 'sourceMap' => false, + 'indentation' => '' + )); + + $parser->parse( $this->value ); + $this->value = $parser->getCss(); + + break; + + case "js-minifier": + $jz = new JSqueeze(); + $this->value = $jz->squeeze( $this->value); + break; + + default: + throw new \LogicException("Filter not found: ".$filterName); + } + } + + // Store in cache. + $this->getCache()->invalidate(); + } +} + ?> \ No newline at end of file diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php @@ -19,7 +19,7 @@ namespace cms\model; use cms\mustache\Mustache; use cms\publish\PublishPreview;use cms\publish\PublishPublic; use Logger; -use util\LoaderCache; +use util\FileCache; /** @@ -94,7 +94,7 @@ class Page extends BaseObject /** - * @return LoaderCache + * @return FileCache */ public function getCache() { $cacheKey = array('db'=>db()->id, @@ -103,7 +103,7 @@ class Page extends BaseObject 'model' =>$this->modelid, 'publish' =>\ClassUtils::getSimpleClassName($this->publisher) ); - return new LoaderCache( $cacheKey,function() { + return new FileCache( $cacheKey,function() { return $this->generateValue(); } ); diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php @@ -8,7 +8,7 @@ use \Html; use \Http; use \Transformer; use \Code; -use util\LoaderCache; +use util\FileCache; // OpenRat Content Management System // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de @@ -541,7 +541,7 @@ SQL /** * - * @return LoaderCache + * @return FileCache */ public function getCache() { @@ -552,7 +552,7 @@ SQL 'language'=>$this->languageid, 'model' =>is_object($this->page)?$this->page->modelid:0, 'publish'=>\ClassUtils::getSimpleClassName($this->publisher) ); - return new LoaderCache( $cacheKey,function() { + return new FileCache( $cacheKey,function() { return $this->generateValue(); } ); } diff --git a/modules/util/cache/FileCache.class.php b/modules/util/cache/FileCache.class.php @@ -0,0 +1,86 @@ +<?php + +namespace util; + +use FileUtils; + + +/** + * Simple Cache for caching of generated content. + * + * @package util + */ +class FileCache +{ + /** + * @var Callable + */ + private $loader; + + /** + * @var string + */ + private $filename; + + /** + * Creates a new Cache entry. + * + * @param $key array Cache-Key + * @param $loader Callable + */ + public function __construct( $key, $loader ) + { + $filename = FileUtils::getTempDir() . '/'. 'openrat-cache'; + + if ( is_array($key)) + foreach ($key as $a => $w) + $filename .= '.' . $a .'-'. $w; + else + $filename .= strval($key); + + $filename .= '.tmp'; + + $this->filename = $filename; + $this->loader = $loader; + } + + + /** + * Invalidates a cache entry. + */ + public function invalidate() { + + if ( is_file($this->filename)) + unlink( $this->filename); + } + + + /** + * Get the content. + */ + public function get() { + + if ( ! is_file($this->filename)) { + file_put_contents($this->filename,call_user_func($this->loader) ); + } + + return file_get_contents($this->filename); + } + + + /** + * Get the content. + */ + public function load() { + + if ( ! is_file($this->filename)) { + file_put_contents($this->filename,call_user_func($this->loader) ); + } + } + + + public function getFilename() { + return $this->filename; + } + +}+ \ No newline at end of file diff --git a/modules/util/cache/LoaderCache.class.php b/modules/util/cache/LoaderCache.class.php @@ -1,86 +0,0 @@ -<?php - -namespace util; - -use FileUtils; - - -/** - * Simple Cache for caching of generated content. - * - * @package util - */ -class LoaderCache -{ - /** - * @var Callable - */ - private $loader; - - /** - * @var string - */ - private $filename; - - /** - * Creates a new Cache entry. - * - * @param $key array Cache-Key - * @param $loader Callable - */ - public function __construct( $key, $loader ) - { - $filename = FileUtils::getTempDir() . '/'. 'openrat-cache'; - - if ( is_array($key)) - foreach ($key as $a => $w) - $filename .= '.' . $a .'-'. $w; - else - $filename .= strval($key); - - $filename .= '.tmp'; - - $this->filename = $filename; - $this->loader = $loader; - } - - - /** - * Invalidates a cache entry. - */ - public function invalidate() { - - if ( is_file($this->filename)) - unlink( $this->filename); - } - - - /** - * Get the content. - */ - public function get() { - - if ( ! is_file($this->filename)) { - file_put_contents($this->filename,call_user_func($this->loader) ); - } - - return file_get_contents($this->filename); - } - - - /** - * Get the content. - */ - public function load() { - - if ( ! is_file($this->filename)) { - file_put_contents($this->filename,call_user_func($this->loader) ); - } - } - - - public function getFilename() { - return $this->filename; - } - -}- \ No newline at end of file diff --git a/modules/util/require.php b/modules/util/require.php @@ -4,7 +4,7 @@ require_once( __DIR__.'/'.'exception/ValidationException.class.php' ); require_once( __DIR__.'/'.'exception/OpenRatException.class.php' ); require_once( __DIR__.'/'.'exception/SecurityException.class.php' ); -require_once( __DIR__.'/'.'cache/LoaderCache.class.php' ); +require_once( __DIR__.'/'.'cache/FileCache.class.php' ); require_once( __DIR__.'/'.'ArrayUtils.class.php' ); require_once( __DIR__.'/'.'ClassUtils.class.php' );