openrat-cms

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

commit 4cd714449523f107ee52d5f0599286cd384c3ed7
parent 391c4c6fd8a7461c98c509e08aeab5e847aab355
Author: Jan Dankert <develop@jandankert.de>
Date:   Wed, 11 Dec 2019 22:51:49 +0100

Fix: always setting the typeid. New: Every model object must implement load() and delete().

Diffstat:
modules/cms-core/model/BaseObject.class.php | 13++++++++++++-
modules/cms-core/model/File.class.php | 1+
modules/cms-core/model/Folder.class.php | 1+
modules/cms-core/model/Image.class.php | 495++++++++++++++++++++++++++++++++++++++++---------------------------------------
modules/cms-core/model/Link.class.php | 1+
modules/cms-core/model/ModelBase.class.php | 4++++
modules/cms-core/model/Name.class.php | 10++++++++++
modules/cms-core/model/Page.class.php | 1+
modules/cms-core/model/Text.class.php | 99++++++++++++++++++++++++++++++++++++++++---------------------------------------
modules/cms-core/model/Url.class.php | 1+
modules/cms-macros/macro/LanguageLinksForPage.class.php | 3++-
11 files changed, 331 insertions(+), 298 deletions(-)

diff --git a/modules/cms-core/model/BaseObject.class.php b/modules/cms-core/model/BaseObject.class.php @@ -1009,12 +1009,20 @@ SQL } } + + + public function objectDelete() { + self::delete(); + } + + + /** * Objekt loeschen. Es muss sichergestellt sein, dass auch das Unterobjekt geloeschet wird. * Diese Methode wird daher normalerweise nur vom Unterobjekt augerufen * @access protected */ - public function objectDelete() + public function delete() { $db = db_connection(); @@ -1765,6 +1773,9 @@ SQL { return ""; } + + + } diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php @@ -83,6 +83,7 @@ class File extends BaseObject parent::__construct( $objectid ); $this->isFile = true; + $this->typeid = BaseObject::TYPEID_FILE; } diff --git a/modules/cms-core/model/Folder.class.php b/modules/cms-core/model/Folder.class.php @@ -23,6 +23,7 @@ class Folder extends BaseObject { parent::__construct( $objectid ); $this->isFolder = true; + $this->typeid = BaseObject::TYPEID_FOLDER; } diff --git a/modules/cms-core/model/Image.class.php b/modules/cms-core/model/Image.class.php @@ -1,248 +1,249 @@ -<?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. - - - -/** - * Datei. - * - * @author Jan Dankert - * @package openrat.objects - */ -class Image extends File -{ - /** - * Breite eines Bildes. Ist nur verfuegbar, wenn vorher - * #getImageSize() aufgerufen wurde. - */ - var $width = null; - - /** - * Hoehe eines Bildes. Ist nur verfuegbar, wenn vorher - * #getImageSize() aufgerufen wurde. - */ - var $height = null; - - - /** - * Konstruktor - * - * @param Objekt-Id - */ - function __construct( $objectid='' ) - { - parent::__construct($objectid); - - $this->isImage = true; - $this->isFile = false; - } - - - - - /** - * Ermittelt Breite und H�he des Bildes.<br> - * Die Werte lassen sich anschlie�end �ber die Eigenschaften "width" und "height" ermitteln. - */ - function getImageSize() - { - if ( is_null($this->width) ) - { - $this->write(); // Datei schreiben - - // Bildinformationen ermitteln - $size = getimagesize( $this->getCache()->getFilename() ); - - // Breite und Hoehe des aktuellen Bildes - $this->width = $size[0]; - $this->height = $size[1]; - } - } - - - - /** - * Veraendert die Bildgroesse eines Bildes - * - * Diese Methode sollte natuerlich nur bei Bildern ausgefuehrt werden. - * - * @param Neue Breite - * @param Neue Hoehe - * @param Bildgr��enfaktor - * @param Altes Format als Integer-Konstante IMG_xxx - * @param Neues Format als Integer-Konstante IMG_xxx - * @param Jpeg-Qualitaet (sofern neues Format = Jpeg) - */ - function imageResize( $newWidth,$newHeight,$factor,$oldformat,$newformat,$jpegquality ) - { - global $conf; - - $this->write(); // Datei schreiben - - // Bildinformationen ermitteln - $size = getimagesize( $this->getCache()->getFilename() ); - - // Breite und Hoehe des aktuellen Bildes - $oldWidth = $size[0]; - $oldHeight = $size[1]; - $aspectRatio = $oldHeight / $oldWidth; // Seitenverhaeltnis - - // Wenn Breite und Hoehe fehlen, dann Bildgroesse beibehalten - if ( $newWidth == 0 && $newHeight == 0) - { - if ( $factor != 0 && $factor != 1 ) - { - $newWidth = $oldWidth * $factor; - $newHeight = $oldHeight * $factor; - $resizing = true; - } - else - { - $newWidth = $oldWidth; - $newHeight = $oldHeight; - $resizing = false; - } - } - else - { - $resizing = true; - } - - // Wenn nur Breite oder Hoehe angegeben ist, dann - // das Seitenverhaeltnis beibehalten - if ( $newWidth == 0 ) - $newWidth = $newHeight / $aspectRatio; - - if ( $newHeight == 0 ) - $newHeight = $newWidth * $aspectRatio; - - - switch( $oldformat ) - { - case IMG_GIF: // GIF - - $oldImage = ImageCreateFromGIF( $this->tmpfile ); - break; - - case IMG_JPG: // JPEG - - $oldImage = ImageCreateFromJPEG($this->tmpfile); - break; - - case IMG_PNG: // PNG - - $oldImage = imagecreatefrompng($this->tmpfile); - break; - - default: - throw new \LogicException('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); - } - - // Ab Version 2 der GD-Bibliothek sind TrueColor-Umwandlungen moeglich. - global $conf; - $hasTrueColor = $conf['image']['truecolor']; - - switch( $newformat ) - { - case IMG_GIF: // GIF - - if ( $resizing ) - { - $newImage = ImageCreate($newWidth,$newHeight); - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - else - { - $newImage = &$oldImage; - } - - ImageGIF($newImage, $this->getCache()->getFilename() ); - $this->extension = 'gif'; - - break; - - case IMG_JPG: // JPEG - - if ( !$resizing ) - { - $newImage = &$oldImage; - } - elseif ( $hasTrueColor ) - { - // Verwende TrueColor (GD2) - $newImage = imageCreateTrueColor( $newWidth,$newHeight ); - ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - else - { - // GD Version 1.x unterstuetzt kein TrueColor - $newImage = ImageCreate($newWidth,$newHeight); - - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - - ImageJPEG($newImage, $this->tmpfile,$jpegquality ); - $this->extension = 'jpeg'; - - break; - - case IMG_PNG: // PNG - - if ( !$resizing ) - { - $newImage = &$oldImage; - } - elseif ( $hasTrueColor ) - { - // Verwende TrueColor (GD2) - $newImage = imageCreateTrueColor( $newWidth,$newHeight ); - - ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - else - { - // GD Version 1.x unterstuetzt kein TrueColor - $newImage = ImageCreate($newWidth,$newHeight); - - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - - imagepng( $newImage,$this->getCache()->getFilename() ); - $this->extension = 'png'; - - break; - - default: - throw new \LogicException('unsupported image format "'.$newformat.'", cannot resize'); - } - - $this->getCache()->invalidate(); - - imagedestroy( $oldImage ); - //imagedestroy( $newImage ); - } - -} - +<?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. + + + +/** + * Datei. + * + * @author Jan Dankert + * @package openrat.objects + */ +class Image extends File +{ + /** + * Breite eines Bildes. Ist nur verfuegbar, wenn vorher + * #getImageSize() aufgerufen wurde. + */ + var $width = null; + + /** + * Hoehe eines Bildes. Ist nur verfuegbar, wenn vorher + * #getImageSize() aufgerufen wurde. + */ + var $height = null; + + + /** + * Konstruktor + * + * @param Objekt-Id + */ + function __construct( $objectid='' ) + { + parent::__construct($objectid); + + $this->isImage = true; + $this->isFile = false; + $this->typeid = BaseObject::TYPEID_FILE; + } + + + + + /** + * Ermittelt Breite und H�he des Bildes.<br> + * Die Werte lassen sich anschlie�end �ber die Eigenschaften "width" und "height" ermitteln. + */ + function getImageSize() + { + if ( is_null($this->width) ) + { + $this->write(); // Datei schreiben + + // Bildinformationen ermitteln + $size = getimagesize( $this->getCache()->getFilename() ); + + // Breite und Hoehe des aktuellen Bildes + $this->width = $size[0]; + $this->height = $size[1]; + } + } + + + + /** + * Veraendert die Bildgroesse eines Bildes + * + * Diese Methode sollte natuerlich nur bei Bildern ausgefuehrt werden. + * + * @param Neue Breite + * @param Neue Hoehe + * @param Bildgr��enfaktor + * @param Altes Format als Integer-Konstante IMG_xxx + * @param Neues Format als Integer-Konstante IMG_xxx + * @param Jpeg-Qualitaet (sofern neues Format = Jpeg) + */ + function imageResize( $newWidth,$newHeight,$factor,$oldformat,$newformat,$jpegquality ) + { + global $conf; + + $this->write(); // Datei schreiben + + // Bildinformationen ermitteln + $size = getimagesize( $this->getCache()->getFilename() ); + + // Breite und Hoehe des aktuellen Bildes + $oldWidth = $size[0]; + $oldHeight = $size[1]; + $aspectRatio = $oldHeight / $oldWidth; // Seitenverhaeltnis + + // Wenn Breite und Hoehe fehlen, dann Bildgroesse beibehalten + if ( $newWidth == 0 && $newHeight == 0) + { + if ( $factor != 0 && $factor != 1 ) + { + $newWidth = $oldWidth * $factor; + $newHeight = $oldHeight * $factor; + $resizing = true; + } + else + { + $newWidth = $oldWidth; + $newHeight = $oldHeight; + $resizing = false; + } + } + else + { + $resizing = true; + } + + // Wenn nur Breite oder Hoehe angegeben ist, dann + // das Seitenverhaeltnis beibehalten + if ( $newWidth == 0 ) + $newWidth = $newHeight / $aspectRatio; + + if ( $newHeight == 0 ) + $newHeight = $newWidth * $aspectRatio; + + + switch( $oldformat ) + { + case IMG_GIF: // GIF + + $oldImage = ImageCreateFromGIF( $this->tmpfile ); + break; + + case IMG_JPG: // JPEG + + $oldImage = ImageCreateFromJPEG($this->tmpfile); + break; + + case IMG_PNG: // PNG + + $oldImage = imagecreatefrompng($this->tmpfile); + break; + + default: + throw new \LogicException('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); + } + + // Ab Version 2 der GD-Bibliothek sind TrueColor-Umwandlungen moeglich. + global $conf; + $hasTrueColor = $conf['image']['truecolor']; + + switch( $newformat ) + { + case IMG_GIF: // GIF + + if ( $resizing ) + { + $newImage = ImageCreate($newWidth,$newHeight); + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + $newImage = &$oldImage; + } + + ImageGIF($newImage, $this->getCache()->getFilename() ); + $this->extension = 'gif'; + + break; + + case IMG_JPG: // JPEG + + if ( !$resizing ) + { + $newImage = &$oldImage; + } + elseif ( $hasTrueColor ) + { + // Verwende TrueColor (GD2) + $newImage = imageCreateTrueColor( $newWidth,$newHeight ); + ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + // GD Version 1.x unterstuetzt kein TrueColor + $newImage = ImageCreate($newWidth,$newHeight); + + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + + ImageJPEG($newImage, $this->tmpfile,$jpegquality ); + $this->extension = 'jpeg'; + + break; + + case IMG_PNG: // PNG + + if ( !$resizing ) + { + $newImage = &$oldImage; + } + elseif ( $hasTrueColor ) + { + // Verwende TrueColor (GD2) + $newImage = imageCreateTrueColor( $newWidth,$newHeight ); + + ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + // GD Version 1.x unterstuetzt kein TrueColor + $newImage = ImageCreate($newWidth,$newHeight); + + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + + imagepng( $newImage,$this->getCache()->getFilename() ); + $this->extension = 'png'; + + break; + + default: + throw new \LogicException('unsupported image format "'.$newformat.'", cannot resize'); + } + + $this->getCache()->invalidate(); + + imagedestroy( $oldImage ); + //imagedestroy( $newImage ); + } + +} + ?> \ No newline at end of file diff --git a/modules/cms-core/model/Link.class.php b/modules/cms-core/model/Link.class.php @@ -20,6 +20,7 @@ class Link extends BaseObject { parent::__construct( $objectid ); $this->isLink = true; + $this->typeid = BaseObject::TYPEID_LINK; } diff --git a/modules/cms-core/model/ModelBase.class.php b/modules/cms-core/model/ModelBase.class.php @@ -24,4 +24,8 @@ abstract class ModelBase } public abstract function getName(); + + public abstract function load(); + + public abstract function delete(); } diff --git a/modules/cms-core/model/Name.class.php b/modules/cms-core/model/Name.class.php @@ -131,6 +131,16 @@ SQL } } + + + public function delete() + { + // not necessary, because names are deleted by BaseObject::delete() + + } + + + /** */ public function objectDelete() diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php @@ -92,6 +92,7 @@ class Page extends BaseObject { parent::__construct( $objectid ); $this->isPage = true; + $this->typeid = BaseObject::TYPEID_PAGE; $this->publisher = new PublishPreview(); diff --git a/modules/cms-core/model/Text.class.php b/modules/cms-core/model/Text.class.php @@ -1,50 +1,51 @@ -<?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. - - -/** - * Datei. - * - * @author Jan Dankert - * @package openrat.objects - */ -class Text extends File -{ - /** - * Konstruktor - * - * @param string $objectid - */ - public function __construct( $objectid='' ) - { - - parent::__construct( $objectid ); - - $this->isText = true; - $this->isFile = false; - } - - - public function mimeType() - { - return 'text/plain'; - } -} - +<?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. + + +/** + * Datei. + * + * @author Jan Dankert + * @package openrat.objects + */ +class Text extends File +{ + /** + * Konstruktor + * + * @param string $objectid + */ + public function __construct( $objectid='' ) + { + + parent::__construct( $objectid ); + + $this->isText = true; + $this->isFile = false; + $this->typeid = BaseObject::TYPEID_TEXT; + } + + + public function mimeType() + { + return 'text/plain'; + } +} + ?> \ No newline at end of file diff --git a/modules/cms-core/model/Url.class.php b/modules/cms-core/model/Url.class.php @@ -16,6 +16,7 @@ class Url extends BaseObject { parent::__construct( $objectid ); $this->isUrl = true; + $this->typeid = BaseObject::TYPEID_URL; } diff --git a/modules/cms-macros/macro/LanguageLinksForPage.class.php b/modules/cms-macros/macro/LanguageLinksForPage.class.php @@ -25,7 +25,8 @@ use cms\model\Page; use cms\model\Project; /** - * Erstellen einer Liste von Language-Links auf die selbe Seite + * Erstellen einer Liste von Language-Links auf die selbe Seite. + * * @author Tobias Schoene */ class LanguageLinksForPage extends Macro