commit 855824aa3c4a7667f45d7c1261421650580a3af6
parent db110c93be2a97c40c291e88a974af9386807aad
Author: Jan Dankert <devnull@localhost>
Date: Sat, 22 Dec 2018 22:13:47 +0100
Bei der Filterung nach dem entsprechenden Publish-Typ unterscheiden.
Diffstat:
9 files changed, 133 insertions(+), 104 deletions(-)
diff --git a/modules/cms-core/action/FileAction.class.php b/modules/cms-core/action/FileAction.class.php
@@ -6,6 +6,7 @@ use cms\model\Folder;
use cms\model\BaseObject;
use cms\model\File;
+use cms\publish\PublishPreview;
use Http;
use \Html;
use Upload;
@@ -116,6 +117,7 @@ class FileAction extends ObjectAction
*/
function previewView()
{
+ $this->file->publisher = new PublishPreview();
$url = Html::url($this->file->getType(),'show',$this->file->objectid,array('target'=>'none',REQ_PARAM_EMBED=>'1') );
$this->setTemplateVar('preview_url',$url );
}
@@ -127,6 +129,7 @@ class FileAction extends ObjectAction
*/
function showView()
{
+ $this->file->publisher = new PublishPreview();
$this->lastModified( $this->file->lastchangeDate );
if ( $this->file->extension == 'gz' )
diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php
@@ -19,7 +19,10 @@ namespace cms\model;
// 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;
@@ -365,14 +368,13 @@ EOF
*
* @return String Inhalt der Datei
*/
- function loadValue()
+ public function loadValue()
{
- if ( is_file($this->tmpfile()))
+ // Read from cache, if cache exist and is not too old.
+ if ( is_file($this->tmpfile()) && filemtime($this->tmpfile()>=$this->lastchangeDate))
return implode('',file($this->tmpfile())); // From cache
- $db = db_connection();
-
- $sql = $db->sql( 'SELECT size,value'.
+ $sql = db()->sql( 'SELECT size,value'.
' FROM {{file}}'.
' WHERE objectid={objectid}' );
$sql->setInt( 'objectid',$this->objectid );
@@ -387,8 +389,7 @@ EOF
if ( $this->storeValueAsBase64 )
$this->value = base64_decode( $this->value );
- if ( $this->public )
- $this->filterValue();
+ $this->filterValue();
// Store in cache.
$f = fopen( $this->tmpfile(),'w' );
@@ -528,56 +529,58 @@ EOF
private function filterValue()
{
- $settings = $this->getTotalSettings();
- if ( isset( $settings['filter']) && is_array( $settings['filter'] ) )
+ $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 )
{
- foreach( $settings['filter'] as $filterName )
+ switch( $filterName)
{
- switch( $filterName)
- {
- case 'less':
+ case 'less':
- $parser = new Less_Parser(array(
- 'sourceMap' => false,
- 'indentation' => ' ',
- 'outputSourceFiles' => false,
- //'sourceMapBasepath' => $this->filename()
- //'sourceMapBasepath' => './'
- ));
+ $parser = new Less_Parser(array(
+ 'sourceMap' => false,
+ 'indentation' => ' ',
+ 'outputSourceFiles' => false,
+ //'sourceMapBasepath' => $this->filename()
+ //'sourceMapBasepath' => './'
+ ));
- $parser->parse( $this->value );
- $this->value = $parser->getCss();
+ $parser->parse( $this->value );
+ $this->value = $parser->getCss();
- break;
+ break;
- case 'less-minifier':
+ case 'less-minifier':
- $parser = new Less_Parser(array(
- 'compress' => true,
- 'sourceMap' => false,
- 'indentation' => ''
- ));
+ $parser = new Less_Parser(array(
+ 'compress' => true,
+ 'sourceMap' => false,
+ 'indentation' => ''
+ ));
- $parser->parse( $this->value );
- $this->value = $parser->getCss();
+ $parser->parse( $this->value );
+ $this->value = $parser->getCss();
- break;
+ break;
- case "js-minifier":
- $jz = new JSqueeze();
- $this->value = $jz->squeeze( $this->value);
- break;
+ case "js-minifier":
+ $jz = new JSqueeze();
+ $this->value = $jz->squeeze( $this->value);
+ break;
- default:
- Logger::warn("Filter not found: ".$filterName);
- }
+ default:
+ throw new \LogicException("Filter not found: ".$filterName);
}
-
- // Store in cache.
- $f = fopen( $this->tmpfile(),'w' );
- fwrite( $f,$this->value );
- fclose( $f );
}
+
+ // Store in cache.
+ $f = fopen( $this->tmpfile(),'w' );
+ fwrite( $f,$this->value );
+ fclose( $f );
}
}
diff --git a/modules/cms-core/model/Folder.class.php b/modules/cms-core/model/Folder.class.php
@@ -3,6 +3,7 @@
namespace cms\model;
use cms\publish\Publish;
+use Exception;
/**
@@ -206,54 +207,59 @@ class Folder extends BaseObject
}
- function publish( $withPages,$withFiles,$subdirs = false )
+ public function publish( $withPages,$withFiles,$subdirs = false )
{
set_time_limit(300);
foreach( $this->getObjectIds() as $oid )
{
- $o = new BaseObject( $oid );
- $o->objectLoadRaw();
-
- if ( $o->isPage && $withPages )
- {
- $p = new Page( $oid );
- $p->load();
- $p->publisher = &$this->publisher;
- $p->publish();
- }
-
- if ( $o->isFile && $withFiles )
- {
- $f = new File( $oid );
- $f->load();
- $f->publisher = &$this->publisher;
- $f->publish();
- }
-
- if ( $o->isImage && $withFiles )
- {
- $f = new Image( $oid );
- $f->load();
- $f->publisher = &$this->publisher;
- $f->publish();
- }
-
- if ( $o->isText && $withFiles )
- {
- $f = new Text( $oid );
- $f->load();
- $f->publisher = &$this->publisher;
- $f->publish();
- }
+ try {
+ $o = new BaseObject($oid);
+ $o->objectLoadRaw();
+
+ if ($o->isPage && $withPages) {
+ $p = new Page($oid);
+ $p->load();
+ $p->publisher = &$this->publisher;
+ $p->publish();
+ }
+
+ if ($o->isFile && $withFiles) {
+ $f = new File($oid);
+ $f->load();
+ $f->publisher = &$this->publisher;
+ $f->publish();
+ }
+
+ if ($o->isImage && $withFiles) {
+ $f = new Image($oid);
+ $f->load();
+ $f->publisher = &$this->publisher;
+ $f->publish();
+ }
+
+ if ($o->isText && $withFiles) {
+ $f = new Text($oid);
+ $f->load();
+ $f->publisher = &$this->publisher;
+ $f->publish();
+ }
+
+ if ($o->isFolder && $subdirs) {
+ $f = new Folder($oid);
+ $f->load();
+ $f->publisher = &$this->publisher;
+ $f->publish($withPages, $withFiles, true);
+ }
+ }
+ catch( Exception $e)
+ {
+ // Maybe it is possible to start on with the next one?
+ // But we have to throw an exception here to inform the UI...
- if ( $o->isFolder && $subdirs )
- {
- $f = new Folder( $oid );
- $f->load();
- $f->publisher = &$this->publisher;
- $f->publish( $withPages,$withFiles,true );
- }
+ // Lets wrap it.
+ throw new \LogicException("Could not publish ".$o->__toString().": ".$e->getMessage(),$e->getCode(),$e);
+ }
}
}
diff --git a/modules/cms-publish/Publish.class.php b/modules/cms-publish/Publish.class.php
@@ -17,13 +17,6 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace cms\publish;
-use cms\model\Project;
-
-define('OR_PUBLISH_TARGET_SHOW',1);
-define('OR_PUBLISH_TARGET_PREVIEW',2);
-define('OR_PUBLISH_TARGET_EDIT',3);
-define('OR_PUBLISH_TARGET_PUBLISH',4);
-
/**
* Strategy-baseclass for generating and publishing content.
*
diff --git a/modules/cms-publish/PublishPublic.class.php b/modules/cms-publish/PublishPublic.class.php
@@ -491,12 +491,6 @@ class PublishPublic extends Publish
}
- public function getTarget()
- {
- return OR_PUBLISH_TARGET_PUBLISH;
- }
-
-
public function isSimplePreview()
{
return false;
diff --git a/modules/cms-ui/themes/default/html/views/folder/createurl.php b/modules/cms-ui/themes/default/html/views/folder/createurl.php
@@ -3,7 +3,7 @@
<form name="" target="_self" data-target="view" action="./" data-method="createurl" data-action="folder" data-id="<?php echo OR_ID ?>" method="POST" enctype="application/x-www-form-urlencoded" class="or-form folder" data-async="" data-autosave=""><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="folder" /><input type="hidden" name="<?php echo REQ_PARAM_SUBACTION ?>" value="createurl" /><input type="hidden" name="<?php echo REQ_PARAM_ID ?>" value="<?php echo OR_ID ?>" />
<div class="line">
<div class="label">
- <span class="text"><?php echo nl2br(encodeHtml(htmlentities(lang('URL')))); ?></span>
+ <span><?php echo nl2br(encodeHtml(htmlentities(lang('URL')))); ?></span>
</div>
<div class="input">
@@ -13,7 +13,7 @@
</div>
<div class="line">
<div class="label">
- <span class="text"><?php echo nl2br(encodeHtml(htmlentities(lang('global_NAME')))); ?></span>
+ <span><?php echo nl2br(encodeHtml(htmlentities(lang('global_NAME')))); ?></span>
</div>
<div class="input">
@@ -29,7 +29,7 @@
</div>
<div class="line">
<div class="label">
- <span class="text"><?php echo nl2br(encodeHtml(htmlentities(lang('global_DESCRIPTION')))); ?></span>
+ <span><?php echo nl2br(encodeHtml(htmlentities(lang('global_DESCRIPTION')))); ?></span>
</div>
<div class="input">
diff --git a/modules/cms-ui/themes/default/html/views/url/prop.php b/modules/cms-ui/themes/default/html/views/url/prop.php
@@ -5,7 +5,7 @@
<div class="line">
<div class="label">
<label for="<?php echo REQUEST_ID ?>_name" class="label">
- <span class="text"><?php echo nl2br(encodeHtml(htmlentities(lang('GLOBAL_name')))); ?></span>
+ <span><?php echo nl2br(encodeHtml(htmlentities(lang('GLOBAL_name')))); ?></span>
</label>
</div>
@@ -17,7 +17,7 @@
<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>
+ <span><?php echo nl2br(encodeHtml(htmlentities(lang('GLOBAL_description')))); ?></span>
</label>
</div>
diff --git a/modules/util/ArrayUtils.class.php b/modules/util/ArrayUtils.class.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: dankert
+ * Date: 22.12.18
+ * Time: 21:36
+ */
+
+class ArrayUtils
+{
+
+ public static function getSubArray( $array, $keys ) {
+
+ $a = $array;
+ foreach( $keys as $k )
+ {
+ if ( ! isset($a[$k]) )
+ return array();
+
+ if ( ! is_array($a[$k]) )
+ return array();
+
+ $a = $a[$k];
+ }
+
+ return $a;
+ }
+}+
\ No newline at end of file
diff --git a/modules/util/require.php b/modules/util/require.php
@@ -4,6 +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__.'/'.'ArrayUtils.class.php' );
require_once( __DIR__.'/'.'ClassUtils.class.php' );
require_once( __DIR__.'/'.'GlobalFunctions.class.php' );
require_once( __DIR__.'/'.'Http.class.php' );