commit 2516ff22d41feeb71b448a49ffd3b3d0dde2c598
parent da2ec22df2fdba4632b7c1e3856de370092dceee
Author: Jan Dankert <devnull@localhost>
Date: Fri, 2 Nov 2018 22:34:05 +0100
Neu: Filter für Text-Objekte definierbar.
Diffstat:
6 files changed, 184 insertions(+), 97 deletions(-)
diff --git a/modules/cms-core/action/FileAction.class.php b/modules/cms-core/action/FileAction.class.php
@@ -38,8 +38,10 @@ class FileAction extends ObjectAction
{
public $security = SECURITY_USER;
- var $file;
- var $defaultSubAction = 'show';
+ /**
+ * @var File
+ */
+ protected $file;
/**
* Konstruktor
@@ -81,17 +83,6 @@ class FileAction extends ObjectAction
$this->addNotice($this->file->getType(),$this->file->name,'VALUE_SAVED','ok');
}
-
- public function valuePost()
- {
- $this->file->value = $this->getRequestVar('value',OR_FILTER_RAW);
- $this->file->saveValue();
-
- $this->addNotice($this->file->getType(),$this->file->name,'VALUE_SAVED','ok');
- $this->file->setTimestamp();
- }
-
-
/**
* Abspeichern der Eigenschaften zu dieser Datei.
*
diff --git a/modules/cms-core/action/TextAction.class.php b/modules/cms-core/action/TextAction.class.php
@@ -1,15 +1,16 @@
<?php
-namespace cms\action;
+namespace {
-use cms\model\Folder;
-use cms\model\BaseObject;
-use cms\model\File;
+ define('OR_FILE_FILTER_LESS',1);
+}
+
+namespace cms\action
+{
+ use cms\model\BaseObject;
-use cms\model\Text;
-use Http;
-use \Html;
-use Upload;
+ use cms\model\Text;
+ use \Html;
// OpenRat Content Management System
// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
@@ -29,35 +30,104 @@ use Upload;
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-/**
- * Action-Klasse zum Bearbeiten einer Datei
- * @author Jan Dankert
- * @package openrat.actions
- */
-class TextAction extends FileAction
-{
- public $security = SECURITY_USER;
+ /**
+ * Action-Klasse zum Bearbeiten einer Datei
+ * @author Jan Dankert
+ * @package openrat.actions
+ */
+ class TextAction extends FileAction
+ {
+ public $security = SECURITY_USER;
- var $text;
+ var $text;
- /**
- * Konstruktor
- */
- function __construct()
- {
- parent::__construct();
- }
+ /**
+ * Konstruktor
+ */
+ function __construct()
+ {
+ parent::__construct();
+ }
- public function init()
- {
+ public function init()
+ {
- $this->text = new Text( $this->getRequestId() );
- $this->text->load();
+ $this->text = new Text($this->getRequestId());
+ $this->text->load();
- $this->file = $this->text;
- }
+ $this->file = $this->text;
+ }
-}
-?>-
\ No newline at end of file
+ public function valuePost()
+ {
+ $this->file->value = $this->getRequestVar('value', OR_FILTER_RAW);
+ $this->file->saveValue();
+
+ $this->addNotice($this->file->getType(), $this->file->name, 'VALUE_SAVED', 'ok');
+ $this->file->setTimestamp();
+ }
+
+
+ function propView()
+ {
+
+ global $conf;
+
+ if ($this->file->filename == $this->file->objectid)
+ $this->file->filename = '';
+
+ // Eigenschaften der Datei uebertragen
+ $this->setTemplateVars($this->file->getProperties());
+
+ $this->setTemplateVar('size', number_format($this->file->size / 1000, 0, ',', '.') . ' kB');
+ $this->setTemplateVar('full_filename', $this->file->full_filename());
+
+ if (is_file($this->file->tmpfile())) {
+ $this->setTemplateVar('cache_filename', $this->file->tmpfile());
+ $this->setTemplateVar('cache_filemtime', @filemtime($this->file->tmpfile()));
+ }
+
+ // Alle Seiten mit dieser Datei ermitteln
+ $pages = $this->file->getDependentObjectIds();
+
+ $list = array();
+ foreach ($pages as $id) {
+ $o = new BaseObject($id);
+ $o->load();
+ $list[$id] = array();
+ $list[$id]['url'] = Html::url('main', 'page', $id);
+ $list[$id]['name'] = $o->name;
+ }
+ asort($list);
+ $this->setTemplateVar('pages', $list);
+ $this->setTemplateVar('edit_filename', $conf['filename']['edit']);
+
+ $this->setTemplateVar('filterlist', array(
+ OR_FILE_FILTER_LESS => 'less'
+ ));
+ }
+
+
+ /**
+ * Abspeichern der Eigenschaften zu dieser Datei.
+ *
+ */
+ function propPost()
+ {
+ // Eigenschaften speichern
+ $this->file->filename = $this->getRequestVar('filename', OR_FILTER_FILENAME);
+ $this->file->name = $this->getRequestVar('name', OR_FILTER_FULL);
+ $this->file->extension = $this->getRequestVar('extension', OR_FILTER_FILENAME);
+ $this->file->desc = $this->getRequestVar('description', OR_FILTER_FULL);
+ $this->file->filterid = $this->getRequestVar('filterid', OR_FILTER_NUMBER);
+
+ $this->file->save();
+ $this->file->setTimestamp();
+ $this->addNotice($this->file->getType(), $this->file->name, 'PROP_SAVED', 'ok');
+ }
+
+
+ }
+}
diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php
@@ -39,9 +39,9 @@ class File extends BaseObject
var $fullFilename = '';
var $publish = null;
var $mime_type = '';
-
+
var $tmpfile;
-
+
var $content_negotiation = false;
@@ -53,9 +53,10 @@ class File extends BaseObject
*/
var $storeValueAsBase64 = false;
+ public $filterid;
- /**
+ /**
* Konstruktor
*
* @param Objekt-Id
@@ -63,7 +64,7 @@ class File extends BaseObject
function __construct( $objectid='' )
{
global $conf;
-
+
$db = \Session::getDatabase();
$this->storeValueAsBase64 = $db->conf['base64'];
@@ -87,7 +88,7 @@ class File extends BaseObject
if ( $this->content_negotiation && config('publish','negotiation','file_negotiate_type' ) )
{
- // Link auf Datei: Extension bleibt aufgrund Content-Negotiation leer
+ // Link auf Datei: Extension bleibt aufgrund Content-Negotiation leer
}
else
{
@@ -128,6 +129,7 @@ class File extends BaseObject
array('full_filename'=>$this->fullFilename,
'extension' =>$this->extension,
'size' =>$this->size,
+ 'filterid' =>$this->filterid,
'mimetype' =>$this->mimetype() ) );
}
@@ -140,7 +142,7 @@ class File extends BaseObject
{
global $SESS;
$db = db_connection();
-
+
$sqlquery = 'SELECT * FROM {{object}} ';
if ( $extension != '' )
@@ -158,7 +160,7 @@ class File extends BaseObject
$sql = $db->sql( $sqlquery );
$sql->setInt( 'projectid',$SESS['projectid'] );
-
+
return $sql->getCol();
}
@@ -173,13 +175,13 @@ class File extends BaseObject
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();
}
@@ -188,7 +190,7 @@ class File extends BaseObject
/**
* Ermittelt den Mime-Type zu dieser Datei
*
- * @return String Mime-Type
+ * @return String Mime-Type
*/
function mimeType()
{
@@ -197,9 +199,9 @@ class File extends BaseObject
global $conf;
$mime_types = $conf['mime-types'];
-
-
+
+
$ext = strtolower( $this->getRealExtension() );
if ( !empty($mime_types[$ext]) )
@@ -207,34 +209,35 @@ class File extends BaseObject
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.
*/
- function load()
+ public function load()
{
$db = db_connection();
- $sql = $db->sql( 'SELECT id,extension,size'.
+ $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;
@@ -254,12 +257,12 @@ class File extends BaseObject
' 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
*/
@@ -268,11 +271,11 @@ class File extends BaseObject
return substr($this->mimeType(),0,6)=='image/';
}
-
+
/**
* Ermittelt die Datei-Endung.
- *
+ *
* @return String Datei-Endung
*/
function extension()
@@ -287,7 +290,7 @@ class File extends BaseObject
/**
* Einen Dateinamen in Dateiname und Extension aufteilen.
- * @param filename Dateiname
+ * @param filename Dateiname
*/
function parse_filename($filename)
{
@@ -310,14 +313,14 @@ class File extends BaseObject
/**
* Speichert die Datei-Informationen in der Datenbank.
*/
- function save()
+ public function save()
{
- global $SESS;
$db = db_connection();
-
+
$sql = $db->sql( <<<EOF
UPDATE {{file}} SET
size = {size},
+ filterid = {filterid},
extension = {extension}
WHERE objectid={objectid}
EOF
@@ -325,8 +328,9 @@ 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();
}
@@ -345,7 +349,7 @@ EOF
/**
* Lesen des Inhaltes der Datei aus der Datenbank.
- *
+ *
* @return String Inhalt der Datei
*/
function loadValue()
@@ -360,7 +364,7 @@ EOF
' WHERE objectid={objectid}' );
$sql->setInt( 'objectid',$this->objectid );
$row = $sql->getRow();
-
+
if ( count($row) != 0 )
{
$this->value = $row['value'];
@@ -374,7 +378,7 @@ EOF
$f = fopen( $this->tmpfile(),'w' );
fwrite( $f,$this->value );
fclose( $f );
-
+
return $this->value;
}
@@ -395,7 +399,7 @@ EOF
' 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
@@ -423,7 +427,7 @@ EOF
$db = db_connection();
$this->objectAdd();
-
+
$sql = $db->sql('SELECT MAX(id) FROM {{file}}');
$this->fileid = intval($sql->getOne())+1;
@@ -435,9 +439,9 @@ EOF
$sql->setString('extension',$this->extension );
$sql->query();
-
+
$this->saveValue();
- }
+ }
function publish()
@@ -447,10 +451,10 @@ EOF
$this->write();
$this->publish->copy( $this->tmpfile(),$this->full_filename(),$this->lastchangeDate );
-
+
$this->publish->publishedObjects[] = $this->getProperties();
}
-
+
/**
* Ermittelt einen tempor�ren Dateinamen f�r diese Datei.
@@ -465,30 +469,30 @@ EOF
return $this->tmpfile;
}
-
+
/**
* Setzt den Zeitstempel der Datei auf die aktuelle Zeit.
- *
+ *
* @see objectClasses/Object#setTimestamp()
*/
-
+
function setTimestamp()
{
@unlink( $this->tmpfile() );
-
+
parent::setTimestamp();
}
-
-
+
+
/**
* Ermittelt die wirksame Datei-Endung. Diese kann sich
* in der Extra-Dateiendung, aber auch direkt im Dateiname
* befinden.
- *
+ *
* @return Dateiendung
*/
- function getRealExtension()
+ function getRealExtension()
{
if ( !empty($this->extension))
{
diff --git a/modules/cms-ui/themes/default/html/views/text/prop.php b/modules/cms-ui/themes/default/html/views/text/prop.php
@@ -1,8 +1,8 @@
- <div class="headermenu"><div class="toolbar-icon clickable"><a href="javascript:void(0);" title="<?php echo lang('MENU_SIZE') ?>" data-type="dialog" data-name="<?php echo lang('MENU_SIZE') ?>" data-method="size"><img src="./themes/default/images/icon/action/size.svg" title="<?php echo lang('MENU_size_DESC') ?>" /><?php echo lang('MENU_size') ?></a></div><div class="toolbar-icon clickable"><a href="javascript:void(0);" title="<?php echo lang('MENU_COMPRESS') ?>" data-type="dialog" data-name="<?php echo lang('MENU_COMPRESS') ?>" data-method="compress"><img src="./themes/default/images/icon/action/compress.svg" title="<?php echo lang('MENU_compress_DESC') ?>" /><?php echo lang('MENU_compress') ?></a></div><div class="toolbar-icon clickable"><a href="javascript:void(0);" title="<?php echo lang('MENU_UNCOMPRESS') ?>" data-type="dialog" data-name="<?php echo lang('MENU_UNCOMPRESS') ?>" data-method="uncompress"><img src="./themes/default/images/icon/action/uncompress.svg" title="<?php echo lang('MENU_uncompress_DESC') ?>" /><?php echo lang('MENU_uncompress') ?></a></div><div class="toolbar-icon clickable"><a href="javascript:void(0);" title="<?php echo lang('MENU_EXTRACT') ?>" data-type="dialog" data-name="<?php echo lang('MENU_EXTRACT') ?>" data-method="extract"><img src="./themes/default/images/icon/action/extract.svg" title="<?php echo lang('MENU_extract_DESC') ?>" /><?php echo lang('MENU_extract') ?></a></div></div>
- <form name="" target="_self" action="<?php echo OR_ACTION ?>" data-method="<?php echo OR_METHOD ?>" data-action="<?php echo OR_ACTION ?>" data-id="<?php echo OR_ID ?>" method="POST" enctype="application/x-www-form-urlencoded" class="<?php echo OR_ACTION ?>" data-async="" data-autosave=""><input type="submit" class="invisible" /><input type="hidden" name="<?php echo REQ_PARAM_TOKEN ?>" value="<?php echo token() ?>" /><input type="hidden" name="<?php echo REQ_PARAM_ACTION ?>" value="<?php echo OR_ACTION ?>" /><input type="hidden" name="<?php echo REQ_PARAM_SUBACTION ?>" value="<?php echo OR_METHOD ?>" /><input type="hidden" name="<?php echo REQ_PARAM_ID ?>" value="<?php echo OR_ID ?>" />
+
+ <form name="" target="_self" data-target="view" action="./" data-method="prop" data-action="text" data-id="<?php echo OR_ID ?>" method="POST" enctype="application/x-www-form-urlencoded" class="or-form text" data-async="" data-autosave=""><input type="submit" class="invisible" /><input type="hidden" name="<?php echo REQ_PARAM_EMBED ?>" value="1" /><input type="hidden" name="<?php echo REQ_PARAM_TOKEN ?>" value="<?php echo token() ?>" /><input type="hidden" name="<?php echo REQ_PARAM_ACTION ?>" value="text" /><input type="hidden" name="<?php echo REQ_PARAM_SUBACTION ?>" value="prop" /><input type="hidden" name="<?php echo REQ_PARAM_ID ?>" value="<?php echo OR_ID ?>" />
<div class="line">
<div class="label">
<label for="<?php echo REQUEST_ID ?>_name" class="label">
@@ -11,7 +11,7 @@
</label>
</div>
<div class="input">
- <div class="inputholder"><input<?php if ('') echo ' disabled="true"' ?> id="<?php echo REQUEST_ID ?>_name" name="name<?php if ('') echo '_disabled' ?>" type="text" maxlength="256" class="name" value="<?php echo Text::encodeHtml(@$name) ?>" /><?php if ('') { ?><input type="hidden" name="name" value="<?php $name ?>"/><?php } ?></div>
+ <div class="inputholder"><input id="<?php echo REQUEST_ID ?>_name" name="name<?php if ('') echo '_disabled' ?>" type="text" maxlength="256" class="name" value="<?php echo Text::encodeHtml(@$name) ?>" /><?php if ('') { ?><input type="hidden" name="name" value="<?php $name ?>"/><?php } ?></div>
</div>
</div>
@@ -23,7 +23,7 @@
</label>
</div>
<div class="input">
- <div class="inputholder"><input<?php if ('') echo ' disabled="true"' ?> id="<?php echo REQUEST_ID ?>_filename" name="filename<?php if ('') echo '_disabled' ?>" type="text" maxlength="256" class="filename" value="<?php echo Text::encodeHtml(@$filename) ?>" /><?php if ('') { ?><input type="hidden" name="filename" value="<?php $filename ?>"/><?php } ?></div>
+ <div class="inputholder"><input id="<?php echo REQUEST_ID ?>_filename" name="filename<?php if ('') echo '_disabled' ?>" type="text" maxlength="150" class="filename" value="<?php echo Text::encodeHtml(@$filename) ?>" /><?php if ('') { ?><input type="hidden" name="filename" value="<?php $filename ?>"/><?php } ?></div>
</div>
</div>
@@ -35,12 +35,24 @@
</label>
</div>
<div class="input">
- <div class="inputholder"><input<?php if ('') echo ' disabled="true"' ?> id="<?php echo REQUEST_ID ?>_extension" name="extension<?php if ('') echo '_disabled' ?>" type="text" maxlength="256" class="extension" value="<?php echo Text::encodeHtml(@$extension) ?>" /><?php if ('') { ?><input type="hidden" name="extension" value="<?php $extension ?>"/><?php } ?></div>
+ <div class="inputholder"><input id="<?php echo REQUEST_ID ?>_extension" name="extension<?php if ('') echo '_disabled' ?>" type="text" maxlength="256" class="extension" value="<?php echo Text::encodeHtml(@$extension) ?>" /><?php if ('') { ?><input type="hidden" name="extension" value="<?php $extension ?>"/><?php } ?></div>
</div>
</div>
<div class="line">
<div class="label">
+ <label for="<?php echo REQUEST_ID ?>_filterid" class="label">
+ <span class="text"><?php echo nl2br(encodeHtml(htmlentities(lang('filter')))); ?></span>
+
+ </label>
+ </div>
+ <div class="input">
+ <div class="inputholder"><select id="<?php echo REQUEST_ID ?>_filterid" name="filterid" title="" class="" size=1"><?php include_once( 'modules/template-engine/components/html/selectbox/component-select-box.php') ?><?php component_select_option_list($filterlist,$filterid,1,1) ?><?php if (count($filterlist)==0) { ?><input type="hidden" name="filterid" value="" /><?php } ?><?php if (count($filterlist)==1) { ?><input type="hidden" name="filterid" value="<?php echo array_keys($filterlist)[0] ?>" /><?php } ?>
+ </select></div>
+ </div>
+ </div>
+ <div class="line">
+ <div class="label">
<label for="<?php echo REQUEST_ID ?>_description" class="label">
<span class="text"><?php echo nl2br(encodeHtml(htmlentities(lang('global_description')))); ?></span>
@@ -51,5 +63,5 @@
</div>
</div>
- <div class="bottom"><div class="command "><input type="button" class="submit ok" value="OK" /></div></div></form>
+ <div class="bottom"><div class="command "><input type="submit" class="submit ok" value="OK" /></div></div></form>
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/text/prop.tpl.src.xml b/modules/cms-ui/themes/default/html/views/text/prop.tpl.src.xml
@@ -34,6 +34,16 @@
</part>
<part class="line">
<part class="label">
+ <label for="filterid">
+ <text text="filter"></text>
+ </label>
+ </part>
+ <part class="input">
+ <selectbox name="filterid" size="1" list="filterlist" addempty="true" lang="true"></selectbox>
+ </part>
+ </part>
+ <part class="line">
+ <part class="label">
<label for="description">
<text text="global_description"></text>
</label>
diff --git a/modules/template-engine/components/html/selectbox/Selectbox.class.php b/modules/template-engine/components/html/selectbox/Selectbox.class.php
@@ -57,7 +57,8 @@ class SelectboxComponent extends Component
echo ' title="'.$this->htmlvalue($this->title).'"';
echo ' class="'.$this->htmlvalue($this->class).'"';
- echo '<?php if (count($'.$this->varname($this->list).')<=1)'." echo ' disabled=\"disabled\"'; ?>";
+ if (! $this->addempty )
+ echo '<?php if (count($'.$this->varname($this->list).')<=1)'." echo ' disabled=\"disabled\"'; ?>";
if($this->multiple)