commit 0e63a3dbd3745f4ec881b8a985641fcf805f96dc
parent 9b6fc0fa89d0dc042131314d6bbedf8c27571ab6
Author: Jan Dankert <devnull@localhost>
Date: Sat, 1 Dec 2018 02:59:28 +0100
Strategie-Muster für den Publisher einsetzen. Dadurch wird vieles einfacher.
Diffstat:
20 files changed, 831 insertions(+), 729 deletions(-)
diff --git a/modules/cms-core/action/FolderAction.class.php b/modules/cms-core/action/FolderAction.class.php
@@ -15,6 +15,7 @@ use cms\model\Link;
use cms\model\Text;
use cms\model\Url;
+use cms\publish\PublishPublic;
use Http;
use Publish;
use Session;
@@ -1591,7 +1592,7 @@ class FolderAction extends ObjectAction
$files = ( $this->hasRequestVar('files' ) );
Session::close();
- $publish = new Publish( $this->projectid );
+ $publish = new PublishPublic( $this->projectid );
$this->folder->publish = &$publish;
$this->folder->publish( $pages,$files,$subdirs );
diff --git a/modules/cms-core/action/PageAction.class.php b/modules/cms-core/action/PageAction.class.php
@@ -80,7 +80,6 @@ class PageAction extends ObjectAction
$value->pageid = Page::getPageIdFromObjectId( $value->objectid );
$value->element = new Element( $elementid );
$value->element->load();
- $value->publish = false;
$value->load();
// Eingegebenen Inhalt aus dem Request lesen
@@ -168,7 +167,6 @@ class PageAction extends ObjectAction
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
$value->number = $this->getRequestVar('number') * pow(10,$value->element->decimals);
@@ -776,7 +774,7 @@ class PageAction extends ObjectAction
$this->page->public = true;
$this->page->publish();
- $this->page->publish->close();
+ $this->page->publisher->close();
// foreach( $this->page->publish->publishedObjects as $o )
// {
@@ -789,7 +787,7 @@ class PageAction extends ObjectAction
OR_NOTICE_OK,
array(),
array_map(function($obj) { return $obj['full_filename'];
- },$this->page->publish->publishedObjects)
+ },$this->page->publisher->publishedObjects)
);
}
diff --git a/modules/cms-core/action/PageelementAction.class.php b/modules/cms-core/action/PageelementAction.class.php
@@ -10,6 +10,7 @@ use cms\model\Template;
use cms\model\Page;
use cms\model\Folder;
use cms\model\BaseObject;
+use cms\publish\PublishPreview;
use Html;
use Http;
use Session;
@@ -81,6 +82,7 @@ class PageelementAction extends Action
{
$this->value = new Value();
+ $this->value->publisher = new PublishPreview();
$id = $this->getRequestVar('id');
$ids = explode('_',$id);
@@ -125,7 +127,6 @@ class PageelementAction extends Action
$this->value->simple = false;
$this->value->element = &$this->element;
$this->value->element->load();
- $this->value->publish = false;
$this->value->load();
$this->setTemplateVar('name' ,$this->value->element->name );
@@ -162,7 +163,6 @@ class PageelementAction extends Action
$this->value->simple = false;
$this->value->element = &$this->element;
$this->value->element->load();
- $this->value->publish = false;
$this->value->load();
$this->setTemplateVar('name' ,$this->value->element->name );
@@ -199,7 +199,6 @@ class PageelementAction extends Action
$this->value->simple = false;
$this->value->element = &$this->element;
$this->value->element->load();
- $this->value->publish = false;
$this->value->load();
if ( $this->value->element->type == 'longtext' && $this->value->element->wiki )
@@ -223,7 +222,7 @@ class PageelementAction extends Action
$this->value->pageid = $this->page->pageid;
$this->value->element = &$this->element;
$this->value->element->load();
- $this->value->publish = false;
+ $this->value->publisher = false;
if ( intval($this->value->valueid)!=0 )
$this->value->loadWithId();
@@ -269,9 +268,6 @@ class PageelementAction extends Action
$this->value->pageid = $this->page->pageid;
$this->value->element = &$this->element;
$this->value->element->load();
- $this->value->publish = false;
- $this->value->public = true;
- $this->value->simple = true;
if ( intval($this->value->valueid)!=0 )
$this->value->loadWithId();
@@ -539,7 +535,6 @@ class PageelementAction extends Action
$this->value->pageid = $this->page->pageid;
$this->value->element = &$this->element;
$this->value->element->load();
- $this->value->publish = false;
$this->value->load();
$this->setTemplateVar('name' ,$this->value->element->name );
@@ -729,7 +724,7 @@ class PageelementAction extends Action
$otherValue->pageid = $this->value->pageid;
$otherValue->element = $this->value->element;
$otherValue->elementid = $this->value->elementid;
- $otherValue->publish = $this->value->publish;
+ $otherValue->publisher = $this->value->publisher;
$otherValue->load();
$this->setTemplateVar('languagetext' ,wordwrap($otherValue->text,100) );
$this->setTemplateVar('languagename' ,$languages[$lid] );
@@ -813,8 +808,6 @@ class PageelementAction extends Action
*/
public function historyView()
{
- $this->page->public = true;
- $this->page->simple = true;
$this->page->load();
$this->value->page = &$this->page;
@@ -976,7 +969,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
if ( $this->hasRequestVar('linkobjectid') )
@@ -1068,7 +1060,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
@@ -1190,7 +1181,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
if ( $this->hasRequestVar('linkobjectid') )
@@ -1232,7 +1222,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
$value->text = $this->getRequestVar('text');
@@ -1259,7 +1248,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
if ( $this->hasRequestVar('linkurl') )
@@ -1301,7 +1289,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
$value->linkToObjectId = intval($this->getRequestVar('linkobjectid'));
@@ -1328,7 +1315,6 @@ class PageelementAction extends Action
$value->element = new Element( $this->getRequestVar('elementid') );
$value->element->load();
- $value->publish = false;
$value->load();
if ( $this->hasRequestVar('linkobjectid') )
@@ -1470,14 +1456,14 @@ class PageelementAction extends Action
$this->page->public = true;
$this->page->publish();
- $this->page->publish->close();
+ $this->page->publisher->close();
$this->addNotice( 'page',
$this->page->fullFilename,
'PUBLISHED',
OR_NOTICE_OK,
array(),
- $this->page->publish->log );
+ $this->page->publisher->log );
}
}
diff --git a/modules/cms-core/action/TemplateAction.class.php b/modules/cms-core/action/TemplateAction.class.php
@@ -604,7 +604,7 @@ class TemplateAction extends Action
$page->public = true;
$page->publish();
- $page->publish->close();
+ $page->publisher->close();
// foreach( $this->page->publish->publishedObjects as $o )
// {
@@ -616,7 +616,7 @@ class TemplateAction extends Action
'PUBLISHED',
OR_NOTICE_OK,
array(),
- $page->publish->log );
+ $page->publisher->log );
}
}
diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php
@@ -19,6 +19,7 @@ namespace cms\model;
// Standard Mime-Type
+use cms\publish\PublishPublic;
use JSqueeze;
use Less_Parser;
use Logger;
@@ -468,7 +469,7 @@ EOF
$this->deleteTmpFile();
if ( ! is_object($this->publish) )
- $this->publish = new \Publish( $this->projectid );
+ $this->publish = new PublishPublic( $this->projectid );
$this->write();
$this->publish->copy( $this->tmpfile(),$this->full_filename(),$this->lastchangeDate );
diff --git a/modules/cms-core/model/Folder.class.php b/modules/cms-core/model/Folder.class.php
@@ -1,29 +1,14 @@
<?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.
+
+use cms\publish\Publish;
/**
- * Darstellen eines Ordners
+ * Darstellen eines Ordners.
*
- * @version $Revision$
- * @author $Author$
- * @package openrat.objects
+ * @author Jan Dankert
*/
class Folder extends BaseObject
{
@@ -33,7 +18,7 @@ class Folder extends BaseObject
var $filenames = true;
/**
- * @var \Publish
+ * @var Publish
*/
public $publish = null;
@@ -41,7 +26,7 @@ class Folder extends BaseObject
function __construct( $objectid='' )
{
parent::__construct( $objectid );
- $this->isImage = true;
+ $this->isFolder = true;
}
@@ -229,8 +214,6 @@ class Folder extends BaseObject
function publish( $withPages,$withFiles,$subdirs = false )
{
set_time_limit(300);
- if ( ! is_object($this->publish) )
- $this->publish = new \Publish( $this->projectid );
foreach( $this->getObjectIds() as $oid )
{
@@ -241,7 +224,7 @@ class Folder extends BaseObject
{
$p = new Page( $oid );
$p->load();
- $p->publish = &$this->publish;
+ $p->publisher = &$this->publish;
$p->publish();
}
@@ -766,5 +749,3 @@ SQL
}
-
-?>-
\ No newline at end of file
diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php
@@ -16,7 +16,7 @@ namespace cms\model;
// 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.
-use cms\publish\PreviewLinkSchema;use cms\publish\PublicLinkSchema;
+use cms\publish\PublishPreview;use cms\publish\PublishPublic;
/**
@@ -34,7 +34,14 @@ class Page extends BaseObject
var $templateid;
var $template;
+ /**
+ * @deprecated
+ */
var $simple = false;
+
+ /**
+ * @deprecated replaced by publish->isPublic()
+ */
var $public = false;
var $el = array();
@@ -66,8 +73,7 @@ class Page extends BaseObject
/**
* @var \Publish
*/
- var $publish = null;
- var $up_path = '';
+ var $publisher;
public $values;
@@ -81,7 +87,9 @@ class Page extends BaseObject
{
parent::__construct( $objectid );
$this->isPage = true;
- }
+
+ $this->publisher = new PublishPreview();
+ }
/**
@@ -159,58 +167,17 @@ class Page extends BaseObject
public function path_to_object( $objectid )
{
if ( ! BaseObject::available( $objectid) )
- return '';
+ return 'about:blank';
- if ( $this->public )
- $linkSchema = new PublicLinkSchema();
- else
- $linkSchema = new PreviewLinkSchema();
-
$to = new BaseObject($objectid);
$to->load();
- $inhalt = $linkSchema->linkToObject( $this, $to);
+ $inhalt = $this->publisher->linkToObject( $this, $to );
return $inhalt;
}
- /**
- * Erzeugt Pr?fix f?r eine relative Pfadangabe
- * Beispiel: Seite liegt in Ordner /pfad/pfad dann '../../'
- *
- * @return String Pfadangabe
- * @access private
- */
- function up_path()
- {
- global $conf;
-
- if ( $conf['filename']['url'] == 'absolute' )
- {
- $this->up_path = '/';
- return $this->up_path;
- }
-
- if ( $this->up_path != '' )
- return $this->up_path;
-
- $folder = new Folder( $this->parentid );
- $folder->load();
- $f = count( $folder->parentObjectFileNames(false,true) );
-
- if ( $f == 0 )
- {
- $this->up_path = './';
- }
- else
- {
- $this->up_path = str_repeat( '../',$f );
- }
-
- return $this->up_path;
- }
-
/**
* Eine Seite hinzufuegen
@@ -241,9 +208,7 @@ SQL
*/
function load()
{
- $db = db_connection();
-
- $sql = $db->sql( 'SELECT * FROM {{page}} '.
+ $sql = db()->sql( 'SELECT * FROM {{page}} '.
' WHERE objectid={objectid}' );
$sql->setInt('objectid',$this->objectid);
$row = $sql->getRow();
@@ -290,7 +255,6 @@ SQL
foreach( $project->getLanguages() as $lid=>$lname )
{
$val = new Value();
- $val->publish = false;
$val->element = new Element( $elementid );
$val->objectid = $otherpageid;
@@ -548,7 +512,7 @@ SQL
{
$this->values = array();
- if ( $this->simple )
+ if ( $this->publisher->isSimplePreview() )
$elements = $this->getWritableElements();
else
$elements = $this->getElements();
@@ -557,13 +521,12 @@ SQL
{
// neues Inhaltobjekt erzeugen
$val = new Value();
- $val->publish = $this->public;
$val->element = $element;
+ $val->publisher = $this->publisher;
$val->objectid = $this->objectid;
$val->pageid = $this->pageid;
$val->languageid = $this->languageid;
- $val->simple = $this->simple;
$val->modelid = $this->modelid;
$val->page = $this;
$val->generate();
@@ -687,8 +650,7 @@ SQL
*/
public function publish()
{
- if ( ! is_object($this->publish) )
- $this->publish = new \Publish( $this->projectid );
+ $this->publisher = new PublishPublic( $this->projectid );
$this->public = true;
@@ -721,9 +683,9 @@ SQL
// Nur wenn eine Datei-Endung vorliegt wird die Seite veroeffentlicht
if ( !empty($t->extension) )
{
- $this->publish->copy( $this->tmpfile(),$this->full_filename() );
+ $this->publisher->copy( $this->tmpfile(),$this->full_filename() );
unlink( $this->tmpfile() );
- $this->publish->publishedObjects[] = $this->getProperties();
+ $this->publisher->publishedObjects[] = $this->getProperties();
}
}
}
@@ -764,8 +726,7 @@ SQL
'o' =>$this->objectid,
'l' =>$this->languageid,
'm' =>$this->modelid,
- 'p' =>intval($this->public),
- 's' =>intval($this->simple) ) );
+ 'p' =>\ClassUtils::getSimpleClassName($this->publisher) ) );
return $filename;
}
diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php
@@ -1,5 +1,6 @@
<?php
namespace cms\model;
+use cms\publish\Publish;
use \ObjectNotFoundException;
use \Logger;
use \Text;
@@ -129,14 +130,18 @@ class Value
var $active;
/**
- * Schalter, ob dieser Inhalt der Inhalt ist, der veroeffentlicht
- * werden soll
- * @type Boolean
+ * @type Publish
*/
- var $publish;
+ public $publisher;
+
+ /**
+ * @type Publish
+ */
+ var $publish = false;
/**
* @type Boolean
+ * @deprecated
*/
public $simple;
@@ -176,7 +181,7 @@ class Value
{
$db = db_connection();
- if ( $this->publish )
+ if ( $this->publisher->isPublic() )
$sql = $db->sql( 'SELECT * FROM {{value}}'.
' WHERE elementid ={elementid}'.
' AND pageid ={pageid}'.
@@ -366,7 +371,6 @@ SQL
*/
function save()
{
- global $SESS;
$db = db_connection();
$sql = $db->sql( 'UPDATE {{value}}'.
@@ -562,7 +566,6 @@ SQL
$v->isLink = true;
$v->pageid = $p->pageid;
$v->page = $p;
- $v->simple = $this->simple;
$v->element = $this->element;
$v->languageid = $this->languageid;
//$v->modelid = $this->modelid;
@@ -590,11 +593,11 @@ SQL
if ( $object->isFolder )
{
- if ( $this->simple )
+ if ( $this->publisher->isSimplePreview() )
{
$f = new Folder( $objectid );
$f->load();
- $inhalt = $f->name;
+ $inhalt = $f->filename;
unset( $f );
}
else
@@ -617,8 +620,7 @@ SQL
case OR_TYPE_PAGE:
$p = new Page( $oid );
$p->enclosingObjectId = $this->page->id;
- $p->public = $this->page->public;
- $p->up_path = $this->page->up_path();
+ $p->public = $this->page->publisher->isPublic();
$p->modelid = $this->page->modelid;
$p->languageid = $this->languageid;
$p->mime_type = $this->page->mimeType();
@@ -638,8 +640,7 @@ SQL
{
$p = new Page( $l->linkedObjectId );
$p->enclosingObjectId = $this->page->id;
- $p->public = $this->page->public;
- $p->up_path = $this->page->up_path();
+ $p->public = $this->page->publisher->isPublic();
$p->modelid = $this->page->modelid;
$p->languageid = $this->languageid;
$p->load();
@@ -668,11 +669,11 @@ SQL
}
elseif ( $object->isPage )
{
- if ( $this->simple )
+ if ( $this->publisher->isSimplePreview() )
{
$p = new Page( $objectid );
$p->load();
- $inhalt = $p->name;
+ $inhalt = $p->filename;
unset( $p );
}
else
@@ -685,8 +686,7 @@ SQL
case 'inline':
$p = new Page( $objectid );
$p->enclosingObjectId = $this->page->id;
- $p->public = $this->page->public;
- $p->up_path = $this->page->up_path();
+ $p->publisher = $this->page->publisher;
$p->modelid = $this->page->modelid;
$p->languageid = $this->languageid;
$p->mime_type = $this->page->mimeType();
@@ -709,7 +709,7 @@ SQL
}
}
- if ( $this->simple )
+ if ( $this->publisher->isSimplePreview() )
{
$inhalt = strip_tags( $inhalt );
$inhalt = str_replace( "\n",'',$inhalt );
@@ -732,13 +732,13 @@ SQL
}
elseif ( ! BaseObject::available($objectid) )
{
- $inhalt = $this->simple?'-':'';
+ $inhalt = $this->publisher->isSimplePreview()?'-':'';
}
- elseif ( $this->simple )
+ elseif ( $this->publisher->isSimplePreview() )
{
$o = new BaseObject( $objectid );
$o->load();
- $inhalt = $o->name;
+ $inhalt = $o->filename;
}
elseif ($this->element->subtype == 'image_data_uri' )
{
@@ -773,7 +773,6 @@ SQL
$linkValue->element = $element;
$linkValue->pageid = $this->pageid;
$linkValue->page = $this->page;
- $linkValue->simple = $this->simple;
$linkValue->languageid = $this->languageid;
$linkValue->load();
@@ -795,7 +794,6 @@ SQL
$targetValue->element->load();
$targetValue->pageid = $linkedPage->pageid;
$targetValue->page = $linkedPage;
- $targetValue->simple = $this->simple;
$targetValue->generate();
$inhalt = $targetValue->value;
@@ -1124,7 +1122,7 @@ SQL
$inhalt = $transformer->text;
}
- if ( $this->page->simple )
+ if ( $this->publisher->isSimplePreview() )
{
$inhalt = strip_tags( $inhalt );
$inhalt = str_replace( "\n",'',$inhalt );
@@ -1182,7 +1180,7 @@ SQL
// Programmcode (PHP)
case 'code':
- if ( $this->page->simple )
+ if ( $this->publisher->isSimplePreview() )
break;
// Die Ausführung von benutzer-erzeugtem PHP-Code kann in der
@@ -1213,7 +1211,7 @@ SQL
// Makros (dynamische Klassen)
case 'dynamic':
- if ( $this->page->simple )
+ if ( $this->publisher->isSimplePreview() )
break;
$this->page->load();
@@ -1271,7 +1269,7 @@ SQL
}
else
{
- if ( !$this->publish )
+ if ( !$this->publisher->isPublic() )
$inhalt .= "WARNING: Unknown parameter $param_name in macro $className\n";
}
}
@@ -1283,7 +1281,7 @@ SQL
{
Logger::warn('element:'.$this->element->name.', '.
'class:'.$className.', no method: execute()');
- if ( !$this->publish )
+ if ( !$this->publisher->isPublic() )
$inhalt = lang('ERROR_IN_ELEMENT').' (missing method: execute())';
}
}
@@ -1291,7 +1289,7 @@ SQL
{
Logger::warn('element:'.$this->element->name.', '.
'class not found:'.$className);
- if ( !$this->publish )
+ if ( !$this->publisher->isPublic() )
$inhalt = lang('ERROR_IN_ELEMENT').' (class not found:'.$className.')';
}
}
@@ -1299,7 +1297,7 @@ SQL
{
Logger::warn('element:'.$this->element->name.', '.
'file not found:'.$fileName);
- if ( !$this->publish )
+ if ( !$this->publisher->isPublic() )
$inhalt = lang('ERROR_IN_ELEMENT').' (file not found:'.$fileName.')';
}
@@ -1314,7 +1312,7 @@ SQL
// Info-Feld als Datum
case 'infodate':
- if ( $this->page->simple )
+ if ( $this->publisher->isSimplePreview() )
break;
switch( $this->element->subtype )
@@ -1337,7 +1335,7 @@ SQL
Logger::warn('element:'.$this->element->name.', '.
'type:'.$this->element->type.', '.
'unknown subtype:'.$this->element->subtype);
- if ( !$this->publish )
+ if ( !$this->publisher->isPublic() )
$inhalt = lang('ERROR_IN_ELEMENT');
}
@@ -1352,7 +1350,7 @@ SQL
// Info-Feld
case 'info':
- if ( $this->page->simple )
+ if ( $this->publisher->isSimplePreview() )
break;
switch( $this->element->subtype )
@@ -1504,7 +1502,7 @@ SQL
default:
// Unbekannte Elementtypen darf es nicht geben.
- if ( !$this->publish )
+ if ( !$this->publisher->isPublic() )
throw new \LogicException( lang('ERROR_IN_ELEMENT').' ('.$this->element->name.':'.
'unknown type:'.$this->element->type.')');
@@ -1658,8 +1656,7 @@ SQL
'el'=>$this->element->elementid,
'la'=>$this->languageid,
'm' =>$this->page->modelid,
- 'pu'=>intval($this->publish),
- 'si'=>intval($this->page->simple) ) );
+ 'pu'=>\ClassUtils::getSimpleClassName($this->publisher) ) );
return $filename;
}
diff --git a/modules/cms-publish/PreviewLinkSchema.class.php b/modules/cms-publish/PreviewLinkSchema.class.php
@@ -1,80 +0,0 @@
-<?php
-
-namespace cms\publish;
-
-use cms\model\BaseObject;
-use cms\model\Link;
-use cms\model\Url;
-
-/**
- * Created by PhpStorm.
- * User: dankert
- * Date: 10.08.18
- * Time: 23:47
- */
-
-class PreviewLinkSchema
-{
- /**
- * @param $from \cms\model\BaseObject
- * @param $to \cms\model\BaseObject
- */
- public function linkToObject( $from, $to )
- {
-
- $param = array(
- 'oid' => '__OID__'.$to->objectid.'__',
- REQ_PARAM_MODEL_ID => $from->modelid ,
- REQ_PARAM_LANGUAGE_ID => $from->languageid ,
- REQ_PARAM_EMBED => '1' );
-
- if ( $from->icons )
- $param['withIcons'] = '1';
-
-
- // Interne Verlinkungen in der Seitenvorschau
- switch( $to->typeid )
- {
- case OR_TYPEID_FILE:
- case OR_TYPEID_IMAGE:
- case OR_TYPEID_TEXT:
- $inhalt = \Html::url('file','show',$to->objectid,$param);
- break;
- case OR_TYPEID_PAGE:
- $inhalt = \Html::url('page','show',$to->objectid,$param);
- break;
-
- case OR_TYPEID_LINK:
- $link = new Link( $to->objectid );
- $link->load();
-
- $linkedObject = new BaseObject( $link->linkedObjectId );
- $linkedObject->objectLoad();
-
- switch( $linkedObject->typeid )
- {
- case OR_TYPEID_FILE:
- $inhalt = \Html::url('file','show',$link->linkedObjectId,$param);
- break;
-
- case OR_TYPEID_PAGE:
- $inhalt = \Html::url('page','show',$link->linkedObjectId,$param);
- break;
- case OR_TYPEID_URL:
- $inhalt = \Html::url('url','show',$link->linkedObjectId,$param);
- break;
- }
- break;
-
- case OR_TYPEID_URL:
- $url = new Url( $to->objectid );
- $url->load();
- $inhalt = $url->url;
-
- break;
- }
-
- return $inhalt;
-
- }
-}-
\ No newline at end of file
diff --git a/modules/cms-publish/PublicLinkSchema.class.php b/modules/cms-publish/PublicLinkSchema.class.php
@@ -1,178 +0,0 @@
-<?php
-
-namespace cms\publish;
-
-use cms\model\BaseObject;
-use cms\model\File;
-use cms\model\Folder;
-use cms\model\Link;
-use cms\model\Page;
-use cms\model\Project;
-use cms\model\Url;
-
-define('OR_LINK_SCHEMA_ABSOLUTE',1);
-define('OR_LINK_SCHEMA_RELATIVE',2);
-
-
-/**
- * User: dankert
- * Date: 10.08.18
- * Time: 23:47
- */
-
-class PublicLinkSchema
-{
- /**
- * @param $from \cms\model\Page
- * @param $to \cms\model\BaseObject
- */
- public function linkToObject( $from, $to ) {
-
- if ( config('publish','url') == 'relative')
- $schema = OR_LINK_SCHEMA_RELATIVE;
- else
- $schema = OR_LINK_SCHEMA_ABSOLUTE;
-
-
- switch( $to->typeid )
- {
- case OR_TYPEID_FILE:
- case OR_TYPEID_IMAGE:
- case OR_TYPEID_TEXT:
-
- $f = new File( $to->objectid );
-
- $p = Project::create( $to->projectid )->load();
- $f->content_negotiation = $p->content_negotiation;
-
- $f->load();
- $filename = $f->filename;
- if ( !empty($f->extension))
- $filename .= '.'.$f->extension;
- break;
-
- case OR_TYPEID_PAGE:
-
- $p = new Page( $to->objectid );
- $p->languageid = $from->languageid;
- $p->modelid = $from->modelid;
- $p->cut_index = $from->cut_index;
- $p->content_negotiation = $from->content_negotiation;
- $p->withLanguage = $from->withLanguage;
- $p->withModel = $from->withModel;
- $p->load();
- $filename = $p->getFilename();
- break;
-
- case OR_TYPEID_LINK:
- $link = new Link( $to->objectid );
- $link->load();
-
- $linkedObject = new BaseObject( $link->linkedObjectId );
- $linkedObject->objectLoad();
-
- switch( $linkedObject->typeid )
- {
- case OR_TYPEID_FILE:
- $f = new File( $link->linkedObjectId );
- $f->load();
- $f->content_negotiation = $from->content_negotiation;
- $filename = $f->filename;
- $to = $f;
- break;
-
- case OR_TYPEID_PAGE:
- $p = new Page( $link->linkedObjectId );
- $p->languageid = $from->languageid;
- $p->modelid = $from->modelid;
- $p->cut_index = $from->cut_index;
- $p->content_negotiation = $from->content_negotiation;
- $p->withLanguage = $from->withLanguage;
- $p->withModel = $from->withModel;
- $p->load();
- $filename = $p->getFilename();
- $to = $p;
- break;
- default:
- throw new \LogicException("Unknown Type ".$linkedObject->getType());
- }
- break;
-
- case OR_TYPEID_URL:
- $url = new Url( $to->objectid );
- $url->load();
- return $url->url;
- default:
- throw new \LogicException("Unknown Type ".$to->typeid);
- }
-
-
- if ( $from->projectid != $to->projectid )
- {
- // Target object is in another project.
- // we have to use absolute URLs.
- $schema = OR_LINK_SCHEMA_ABSOLUTE;
-
- // Target is in another Project. So we have to create an absolute URL.
- $targetProject = Project::create( $to->projectid )->load();
- $prefix = $targetProject->url;
-
- if ( ! strpos($prefix,'//' ) === FALSE ) {
- // No protocol in hostname. So we have to prepend the URL with '//'.
- $prefix = '//'.$prefix;
- }
- }
- else {
- $prefix = '';
- }
-
-
-
-
- if ( $schema == OR_LINK_SCHEMA_RELATIVE )
- {
- $folder = new Folder( $from->parentid );
- $folder->load();
- $fromPathFolders = $folder->parentObjectFileNames(false,true);
-
-
- $folder = new Folder($to->parentid);
-
- $toPathFolders = $folder->parentObjectFileNames(false, true);
-
- // Shorten the relative URL
- // if the actual page is /path/folder1/page1
- // and the target page is /path/folder2/page2
- // we shorten the link from ../../path/folder2/page2
- // to ../folder2/page2
- foreach( $fromPathFolders as $folderId ) {
- if ( count($toPathFolders) >= 1 && array_keys($toPathFolders)[0] == $folderId ) {
- unset( $fromPathFolders[$folderId] );
- unset( $toPathFolders [$folderId] );
- }else {
- break;
- }
-
- }
-
- $path = str_repeat( '../',count($fromPathFolders) );
- $path .= implode('/',$toPathFolders);
- $path .= '/';
- }
- else {
- // Absolute Pfadangaben
- $folder = new Folder($to->parentid);
- $toPathFolders = $folder->parentObjectFileNames(false, true);
-
- $path = implode('/',$toPathFolders);
- $path = '/'.$path.'/';
- }
-
-
- $uri = $prefix . $path . $filename;
-
- if( empty($uri)) $uri = '.';
-
- return $uri;
- }
-}-
\ No newline at end of file
diff --git a/modules/cms-publish/Publish.class.php b/modules/cms-publish/Publish.class.php
@@ -15,328 +15,32 @@
// 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.
+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);
+
/**
- * Diese Klasse kapselt das Veroeffentlichen von Dateien.<br>
- * <br>
- * Hier werden<br>
- * - Dateien in das Zielverzeichnis kopiert<br>
- * - Dateien per FTP veroeffentlicht<br>
- * - Zielverzeichnisse aufgeraeumt<br>
- * - Systembefehle ausgefuehrt.
- *
+ * Strategy-baseclass for generating and publishing content.
+ *
* @author Jan Dankert
- * @package openrat.services
*/
-class Publish
+abstract class Publish
{
- /**
- * Enthaelt bei Bedarf das FTP-Objekt. N�mlich dann, wenn
- * zu einem FTP-Server veroeffentlicht werden soll.
- * @var Object
- */
- public $ftp;
-
- /**
- * Flag, ob in das lokale Dateisystem veroeffentlicht werden soll.
- * @var boolean
- */
- public $with_local = false;
-
- /**
- * Flag, ob zu einem FTP-Server ver�ffentlicht werden soll.
- * @var boolean
- */
- public $with_ftp = false;
-
- public $local_destdir = '';
-
- /**
- * Enthaelt die gleichnamige Einstellung aus dem Projekt.
- * @var boolean
- */
- public $content_negotiation = false;
-
- /**
- * Enthaelt die gleichnamige Einstellung aus dem Projekt.
- * @var boolean
- */
- public $cut_index = false;
-
- /**
- * Enthaelt die gleichnamige Einstellung aus dem Projekt.
- * @var String
- */
- public $cmd_after_publish = '';
-
- /**
- * Enthaelt am Ende der Ver�ffentlichung ein Array mit den ver�ffentlichten Objekten.
- * @var Array
- */
- public $publishedObjects = array();
-
- /**
- * Enthaelt im Fehlerfall (wenn 'ok' auf 'false' steht) eine
- * Fehlermeldung.
- *
- * @var String
- */
- public $log = array();
-
- /**
- * Konstruktor.<br>
- * <br>
- * Oeffnet ggf. Verbindungen.
- *
- * @return Publish
- */
- public function __construct( $projectid )
- {
- $confPublish = config('publish');
-
- if ( config('security','nopublish') )
- {
- Logger::warn('publishing is disabled.');
- return; // this is no error.
- }
-
- $project = new Project( $projectid );
- $project->load();
-
- // Feststellen, ob FTP benutzt wird.
- // Dazu muss FTP aktiviert sein (enable=true) und eine URL vorhanden sein.
- $ftpUrl = '';
- if ( $confPublish['ftp']['enable'] )
- {
- if ( $confPublish['ftp']['per_project'] && !empty($project->ftp_url) )
- $ftpUrl = $project->ftp_url;
- elseif ( !empty($confPublish['ftp']['host']) )
- $ftpUrl = $project->ftp_url;
- }
-
- if ( ! empty($ftpUrl) )
- {
- $this->with_ftp = true;
- $this->ftp = new Ftp($project->ftp_url); // Aufbauen einer FTP-Verbindung
-
- $this->ftp->passive = ( $project->ftp_passive == '1' );
- }
-
- $localDir = rtrim( $project->target_dir,'/' );
-
- if ( $confPublish['filesystem']['per_project'] && (!empty($localDir)) )
- {
- $this->local_destdir = $localDir; // Projekteinstellung verwenden.
- }
- else
- {
- if ( empty( $localDir))
- $localDir = $project->name;
-
- // Konfiguriertes Verzeichnis verwenden.
- $this->local_destdir = $confPublish['filesystem']['directory'].$localDir;
- }
-
-
- // Sofort pruefen, ob das Zielverzeichnis ueberhaupt beschreibbar ist.
- if ( $this->local_destdir != '' )
- {
- if ( !is_writeable( $this->local_destdir ) )
- throw new OpenRatException('ERROR_PUBLISH','directory not writable: '.$this->local_destdir );
-
- $this->with_local = true;
- }
-
- $this->content_negotiation = ( $project->content_negotiation == '1' );
- $this->cut_index = ( $project->cut_index == '1' );
-
- if ( $confPublish['command']['enable'] )
- {
- if ( $confPublish['command']['per_project'] && !empty($project->cmd_after_publish) )
- $this->cmd_after_publish = $project->cmd_after_publish;
- else
- $this->cmd_after_publish = @$confPublish['command']['command'];
- }
-
- // Im Systemkommando Variablen ersetzen
- $this->cmd_after_publish = str_replace('{name}' ,$project->name ,$this->cmd_after_publish);
- $this->cmd_after_publish = str_replace('{dir}' ,$this->local_destdir ,$this->cmd_after_publish);
- $this->cmd_after_publish = str_replace('{dirbase}',basename($this->local_destdir),$this->cmd_after_publish);
- }
-
-
-
- /**
- * Kopieren einer Datei aus dem tempor�ren Verzeichnis in das Zielverzeichnis.<br>
- * Falls notwenig, wird ein Hochladen per FTP ausgef�hrt.
- *
- * @param String $tmp_filename
- * @param String $dest_filename
- */
- public function copy( $tmp_filename,$dest_filename,$lastChangeDate=null )
- {
- global $conf;
- $source = $tmp_filename;
-
- if ( $this->with_local )
- {
- $dest = $this->local_destdir.'/'.$dest_filename;
-
- if (!@copy( $source,$dest ));
- {
- if ( ! $this->mkdirs( dirname($dest) ) )
- return; // Fehler bei Verzeichniserstellung, also abbrechen.
-
- if (!@copy( $source,$dest ))
- throw new OpenRatException('ERROR_PUBLISH','failed copying local file:'."\n".
- 'source : '.$source."\n".
- 'destination: '.$dest);
-
- // Das Änderungsdatum der Datei auch in der Zieldatei setzen.
- if ( $conf['publish']['set_modification_date'] )
- if ( ! is_null($lastChangeDate) )
- @touch( $dest,$lastChangeDate );
-
- Logger::debug("published: $dest");
- }
-
- if (!empty($conf['security']['chmod']))
- {
- // CHMOD auf der Datei ausfuehren.
- if ( ! @chmod($dest,octdec($conf['security']['chmod'])) )
- throw new OpenRatException('ERROR_PUBLISH','Unable to CHMOD file '.$dest);
- }
- }
-
- if ( $this->with_ftp ) // Falls FTP aktiviert
- {
- $dest = $dest_filename;
- $this->ftp->put( $source,$dest );
- }
- }
-
-
-
- /**
- * Rekursives Anlagen von Verzeichnisse
- * Nett gemacht.
- * Quelle: http://de3.php.net/manual/de/function.mkdir.php
- * Thx to acroyear at io dot com
- *
- * @param String Verzeichnis
- * @return boolean
- */
- private function mkdirs( $strPath )
- {
- global $conf;
-
- if ( is_dir($strPath) )
- return true;
-
- $pStrPath = dirname($strPath);
-
- if ( !$this->mkdirs($pStrPath) )
- return false;
-
- if ( ! @mkdir($strPath,0777) )
- throw new OpenRatException('ERROR_PUBLISH','Cannot create directory: '.$strPath);
-
- // CHMOD auf dem Verzeichnis ausgef�hren.
- if (!empty($conf['security']['chmod_dir']))
- {
- if ( ! @chmod($strPath,octdec($conf['security']['chmod_dir'])) )
- throw new OpenRatException('ERROR_PUBLISH','Unable to CHMOD directory: '.$strPath);
- }
-
-
- return true;
- }
-
-
-
- /**
- * Beenden des Ver�ffentlichungs-Vorganges.<br>
- * Eine vorhandene FTP-Verbindung wird geschlossen.<br>
- * Falls entsprechend konfiguriert, wird ein Systemkommando ausgef�hrt.
- */
- public function close()
- {
- if ( $this->with_ftp )
- {
- Logger::debug('Closing FTP connection' );
- $this->ftp->close();
- }
-
- // Ausfuehren des Systemkommandos.
- if ( !empty($this->cmd_after_publish) )
- {
- $ausgabe = array();
- $rc = false;
- Logger::debug('Executing system command: '.$this->cmd_after_publish );
- $user = Session::getUser();
- putenv("CMS_USER_NAME=".$user->name );
- putenv("CMS_USER_ID=" .$user->userid);
- putenv("CMS_USER_MAIL=".$user->mail );
- exec( $this->cmd_after_publish,$ausgabe,$rc );
-
- if ( $rc != 0 ) // Wenn Returncode ungleich 0, dann Fehler melden.
- throw new OpenRatException('ERROR_PUBLISH','System command failed - returncode is '.$rc."\n".
- $ausgabe);
- else
- Logger::debug('System command successful' );
-
- }
- }
-
-
-
- /**
- * Aufraeumen des Zielverzeichnisses.<br><br>
- * Es wird der komplette Zielordner samt Unterverzeichnissen durchsucht. Jede
- * Datei, die laenger existiert als der aktuelle Request alt ist, wird geloescht.<br>
- * Natuerlich darf diese Funktion nur nach einem Gesamt-Veroeffentlichen ausgefuehrt werden.
- */
- public function clean()
- {
- if ( !empty($this->local_destdir) )
- $this->cleanFolder($this->local_destdir);
- }
-
-
+ abstract public function linkToObject( $from, $to );
- /**
- * Aufr�umen eines Verzeichnisses.<br><br>
- * Dateien, die l�nger existieren als der aktuelle Request alt ist, werden gel�scht.<br>
- *
- * @param String Verzeichnis
- */
- private function cleanFolder( $folderName )
- {
- $dh = opendir( $folderName );
+ abstract public function isPublic();
- while( $file = readdir($dh) )
- {
- if ( $file != '.' && $file != '..')
- {
- $fullpath = $folderName.'/'.$file;
+ abstract public function isSimplePreview();
- // Wenn eine Datei beschreibbar und entsprechend alt
- // ist, dann entfernen
- if ( is_file($fullpath) &&
- is_writable($fullpath) &&
- filemtime($fullpath) < START_TIME )
- unlink($fullpath);
+ abstract public function copy($tmp_filename,$dest_filename,$lastChangeDate=null);
- // Bei Ordnern rekursiv absteigen
- if ( is_dir( $fullpath) )
- {
- $this->cleanFolder($fullpath);
- @rmdir($fullpath);
- }
- }
- }
- }
+ abstract public function clean();
+ abstract public function close();
}
diff --git a/modules/cms-publish/PublishEdit.class.php b/modules/cms-publish/PublishEdit.class.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace cms\publish;
+
+use cms\model\BaseObject;
+use cms\model\Link;
+use cms\model\Url;
+
+/**
+ * @author Jan Dankert
+ */
+
+class PublishEdit extends Publish
+{
+ /**
+ * @param $from \cms\model\BaseObject
+ * @param $to \cms\model\BaseObject
+ */
+ public function linkToObject( $from, $to )
+ {
+ return '';
+ }
+
+ public function isPublic()
+ {
+ return false;
+ }
+
+ public function copy($tmp_filename,$dest_filename,$lastChangeDate=null)
+ {
+ // nothing to do.
+ }
+
+ public function clean()
+ {
+ // nothing to do.
+ }
+
+ public function close()
+ {
+ // nothing to do.
+ }
+
+ public function isSimplePreview()
+ {
+ return true;
+ }
+
+}+
\ No newline at end of file
diff --git a/modules/cms-publish/PublishPreview.class.php b/modules/cms-publish/PublishPreview.class.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace cms\publish;
+
+use cms\model\BaseObject;
+use cms\model\Link;
+use cms\model\Url;
+
+/**
+ * Created by PhpStorm.
+ * User: dankert
+ * Date: 10.08.18
+ * Time: 23:47
+ */
+
+class PublishPreview extends Publish
+{
+ /**
+ * @param $from \cms\model\BaseObject
+ * @param $to \cms\model\BaseObject
+ */
+ public function linkToObject( $from, $to )
+ {
+
+ $param = array(
+ 'oid' => '__OID__'.$to->objectid.'__',
+ REQ_PARAM_MODEL_ID => $from->modelid ,
+ REQ_PARAM_LANGUAGE_ID => $from->languageid ,
+ REQ_PARAM_EMBED => '1' );
+
+ if ( $from->icons )
+ $param['withIcons'] = '1';
+
+
+ // Interne Verlinkungen in der Seitenvorschau
+ switch( $to->typeid )
+ {
+ case OR_TYPEID_FILE:
+ case OR_TYPEID_IMAGE:
+ case OR_TYPEID_TEXT:
+ $inhalt = \Html::url('file','show',$to->objectid,$param);
+ break;
+ case OR_TYPEID_PAGE:
+ $inhalt = \Html::url('page','show',$to->objectid,$param);
+ break;
+
+ case OR_TYPEID_LINK:
+ $link = new Link( $to->objectid );
+ $link->load();
+
+ $linkedObject = new BaseObject( $link->linkedObjectId );
+ $linkedObject->objectLoad();
+
+ switch( $linkedObject->typeid )
+ {
+ case OR_TYPEID_FILE:
+ $inhalt = \Html::url('file','show',$link->linkedObjectId,$param);
+ break;
+
+ case OR_TYPEID_PAGE:
+ $inhalt = \Html::url('page','show',$link->linkedObjectId,$param);
+ break;
+ case OR_TYPEID_URL:
+ $inhalt = \Html::url('url','show',$link->linkedObjectId,$param);
+ break;
+ }
+ break;
+
+ case OR_TYPEID_URL:
+ $url = new Url( $to->objectid );
+ $url->load();
+ $inhalt = $url->url;
+
+ break;
+ }
+
+ return $inhalt;
+
+ }
+
+ public function isPublic()
+ {
+ return false;
+ }
+
+ public function copy($tmp_filename,$dest_filename,$lastChangeDate=null)
+ {
+ // nothing to do.
+ }
+
+ public function clean()
+ {
+ // nothing to do.
+ }
+
+ public function close()
+ {
+ // nothing to do.
+ }
+ public function isSimplePreview()
+ {
+ return false;
+ }
+}
diff --git a/modules/cms-publish/PublishPublic.class.php b/modules/cms-publish/PublishPublic.class.php
@@ -0,0 +1,507 @@
+<?php
+
+namespace cms\publish;
+
+use cms\model\BaseObject;
+use cms\model\File;
+use cms\model\Folder;
+use cms\model\Link;
+use cms\model\Page;
+use cms\model\Project;
+use cms\model\Url;
+use Logger;
+
+define('OR_LINK_SCHEMA_ABSOLUTE',1);
+define('OR_LINK_SCHEMA_RELATIVE',2);
+
+
+/**
+ * User: dankert
+ * Date: 10.08.18
+ * Time: 23:47
+ */
+
+class PublishPublic extends Publish
+{
+ /**
+ * @param $from \cms\model\Page
+ * @param $to \cms\model\BaseObject
+ */
+ public function linkToObject( $from, $to ) {
+
+ if ( config('publish','url') == 'relative')
+ $schema = OR_LINK_SCHEMA_RELATIVE;
+ else
+ $schema = OR_LINK_SCHEMA_ABSOLUTE;
+
+
+ switch( $to->typeid )
+ {
+ case OR_TYPEID_FILE:
+ case OR_TYPEID_IMAGE:
+ case OR_TYPEID_TEXT:
+
+ $f = new File( $to->objectid );
+
+ $p = Project::create( $to->projectid )->load();
+ $f->content_negotiation = $p->content_negotiation;
+
+ $f->load();
+ $filename = $f->filename;
+ if ( !empty($f->extension))
+ $filename .= '.'.$f->extension;
+ break;
+
+ case OR_TYPEID_PAGE:
+
+ $p = new Page( $to->objectid );
+ $p->languageid = $from->languageid;
+ $p->modelid = $from->modelid;
+ $p->cut_index = $from->cut_index;
+ $p->content_negotiation = $from->content_negotiation;
+ $p->withLanguage = $from->withLanguage;
+ $p->withModel = $from->withModel;
+ $p->load();
+ $filename = $p->getFilename();
+ break;
+
+ case OR_TYPEID_LINK:
+ $link = new Link( $to->objectid );
+ $link->load();
+
+ $linkedObject = new BaseObject( $link->linkedObjectId );
+ $linkedObject->objectLoad();
+
+ switch( $linkedObject->typeid )
+ {
+ case OR_TYPEID_FILE:
+ $f = new File( $link->linkedObjectId );
+ $f->load();
+ $f->content_negotiation = $from->content_negotiation;
+ $filename = $f->filename;
+ $to = $f;
+ break;
+
+ case OR_TYPEID_PAGE:
+ $p = new Page( $link->linkedObjectId );
+ $p->languageid = $from->languageid;
+ $p->modelid = $from->modelid;
+ $p->cut_index = $from->cut_index;
+ $p->content_negotiation = $from->content_negotiation;
+ $p->withLanguage = $from->withLanguage;
+ $p->withModel = $from->withModel;
+ $p->load();
+ $filename = $p->getFilename();
+ $to = $p;
+ break;
+ default:
+ throw new \LogicException("Unknown Type ".$linkedObject->getType());
+ }
+ break;
+
+ case OR_TYPEID_URL:
+ $url = new Url( $to->objectid );
+ $url->load();
+ return $url->url;
+ default:
+ throw new \LogicException("Unknown Type ".$to->typeid);
+ }
+
+
+ if ( $from->projectid != $to->projectid )
+ {
+ // Target object is in another project.
+ // we have to use absolute URLs.
+ $schema = OR_LINK_SCHEMA_ABSOLUTE;
+
+ // Target is in another Project. So we have to create an absolute URL.
+ $targetProject = Project::create( $to->projectid )->load();
+ $prefix = $targetProject->url;
+
+ if ( ! strpos($prefix,'//' ) === FALSE ) {
+ // No protocol in hostname. So we have to prepend the URL with '//'.
+ $prefix = '//'.$prefix;
+ }
+ }
+ else {
+ $prefix = '';
+ }
+
+
+
+
+ if ( $schema == OR_LINK_SCHEMA_RELATIVE )
+ {
+ $folder = new Folder( $from->parentid );
+ $folder->load();
+ $fromPathFolders = $folder->parentObjectFileNames(false,true);
+
+
+ $folder = new Folder($to->parentid);
+
+ $toPathFolders = $folder->parentObjectFileNames(false, true);
+
+ // Shorten the relative URL
+ // if the actual page is /path/folder1/page1
+ // and the target page is /path/folder2/page2
+ // we shorten the link from ../../path/folder2/page2
+ // to ../folder2/page2
+ foreach( $fromPathFolders as $folderId ) {
+ if ( count($toPathFolders) >= 1 && array_keys($toPathFolders)[0] == $folderId ) {
+ unset( $fromPathFolders[$folderId] );
+ unset( $toPathFolders [$folderId] );
+ }else {
+ break;
+ }
+
+ }
+
+ $path = str_repeat( '../',count($fromPathFolders) );
+ $path .= implode('/',$toPathFolders);
+ $path .= '/';
+ }
+ else {
+ // Absolute Pfadangaben
+ $folder = new Folder($to->parentid);
+ $toPathFolders = $folder->parentObjectFileNames(false, true);
+
+ $path = implode('/',$toPathFolders);
+ $path = '/'.$path.'/';
+ }
+
+
+ $uri = $prefix . $path . $filename;
+
+ if( empty($uri)) $uri = '.';
+
+ return $uri;
+ }
+
+
+
+
+
+ /**
+ * Enthaelt bei Bedarf das FTP-Objekt. N�mlich dann, wenn
+ * zu einem FTP-Server veroeffentlicht werden soll.
+ * @var Object
+ */
+ public $ftp;
+
+ /**
+ * Flag, ob in das lokale Dateisystem veroeffentlicht werden soll.
+ * @var boolean
+ */
+ public $with_local = false;
+
+ /**
+ * Flag, ob zu einem FTP-Server ver�ffentlicht werden soll.
+ * @var boolean
+ */
+ public $with_ftp = false;
+
+ public $local_destdir = '';
+
+ /**
+ * Enthaelt die gleichnamige Einstellung aus dem Projekt.
+ * @var boolean
+ */
+ public $content_negotiation = false;
+
+ /**
+ * Enthaelt die gleichnamige Einstellung aus dem Projekt.
+ * @var boolean
+ */
+ public $cut_index = false;
+
+ /**
+ * Enthaelt die gleichnamige Einstellung aus dem Projekt.
+ * @var String
+ */
+ public $cmd_after_publish = '';
+
+ /**
+ * Enthaelt am Ende der Ver�ffentlichung ein Array mit den ver�ffentlichten Objekten.
+ * @var Array
+ */
+ public $publishedObjects = array();
+
+ /**
+ * Enthaelt im Fehlerfall (wenn 'ok' auf 'false' steht) eine
+ * Fehlermeldung.
+ *
+ * @var String
+ */
+ public $log = array();
+
+ /**
+ * Konstruktor.<br>
+ * <br>
+ * Oeffnet ggf. Verbindungen.
+ *
+ * @return Publish
+ */
+ public function __construct( $projectid )
+ {
+ $confPublish = config('publish');
+
+ if ( config('security','nopublish') )
+ {
+ Logger::warn('publishing is disabled.');
+ return; // this is no error.
+ }
+
+ $project = new Project( $projectid );
+ $project->load();
+
+ // Feststellen, ob FTP benutzt wird.
+ // Dazu muss FTP aktiviert sein (enable=true) und eine URL vorhanden sein.
+ $ftpUrl = '';
+ if ( $confPublish['ftp']['enable'] )
+ {
+ if ( $confPublish['ftp']['per_project'] && !empty($project->ftp_url) )
+ $ftpUrl = $project->ftp_url;
+ elseif ( !empty($confPublish['ftp']['host']) )
+ $ftpUrl = $project->ftp_url;
+ }
+
+ if ( ! empty($ftpUrl) )
+ {
+ $this->with_ftp = true;
+ $this->ftp = new Ftp($project->ftp_url); // Aufbauen einer FTP-Verbindung
+
+ $this->ftp->passive = ( $project->ftp_passive == '1' );
+ }
+
+ $localDir = rtrim( $project->target_dir,'/' );
+
+ if ( $confPublish['filesystem']['per_project'] && (!empty($localDir)) )
+ {
+ $this->local_destdir = $localDir; // Projekteinstellung verwenden.
+ }
+ else
+ {
+ if ( empty( $localDir))
+ $localDir = $project->name;
+
+ // Konfiguriertes Verzeichnis verwenden.
+ $this->local_destdir = $confPublish['filesystem']['directory'].$localDir;
+ }
+
+
+ // Sofort pruefen, ob das Zielverzeichnis ueberhaupt beschreibbar ist.
+ if ( $this->local_destdir != '' )
+ {
+ if ( !is_writeable( $this->local_destdir ) )
+ throw new OpenRatException('ERROR_PUBLISH','directory not writable: '.$this->local_destdir );
+
+ $this->with_local = true;
+ }
+
+ $this->content_negotiation = ( $project->content_negotiation == '1' );
+ $this->cut_index = ( $project->cut_index == '1' );
+
+ if ( $confPublish['command']['enable'] )
+ {
+ if ( $confPublish['command']['per_project'] && !empty($project->cmd_after_publish) )
+ $this->cmd_after_publish = $project->cmd_after_publish;
+ else
+ $this->cmd_after_publish = @$confPublish['command']['command'];
+ }
+
+ // Im Systemkommando Variablen ersetzen
+ $this->cmd_after_publish = str_replace('{name}' ,$project->name ,$this->cmd_after_publish);
+ $this->cmd_after_publish = str_replace('{dir}' ,$this->local_destdir ,$this->cmd_after_publish);
+ $this->cmd_after_publish = str_replace('{dirbase}',basename($this->local_destdir),$this->cmd_after_publish);
+ }
+
+
+
+ /**
+ * Kopieren einer Datei aus dem tempor�ren Verzeichnis in das Zielverzeichnis.<br>
+ * Falls notwenig, wird ein Hochladen per FTP ausgef�hrt.
+ *
+ * @param String $tmp_filename
+ * @param String $dest_filename
+ */
+ public function copy( $tmp_filename,$dest_filename,$lastChangeDate=null )
+ {
+ global $conf;
+ $source = $tmp_filename;
+
+ if ( $this->with_local )
+ {
+ $dest = $this->local_destdir.'/'.$dest_filename;
+
+ if (!@copy( $source,$dest ));
+ {
+ if ( ! $this->mkdirs( dirname($dest) ) )
+ return; // Fehler bei Verzeichniserstellung, also abbrechen.
+
+ if (!@copy( $source,$dest ))
+ throw new OpenRatException('ERROR_PUBLISH','failed copying local file:'."\n".
+ 'source : '.$source."\n".
+ 'destination: '.$dest);
+
+ // Das Änderungsdatum der Datei auch in der Zieldatei setzen.
+ if ( $conf['publish']['set_modification_date'] )
+ if ( ! is_null($lastChangeDate) )
+ @touch( $dest,$lastChangeDate );
+
+ Logger::debug("published: $dest");
+ }
+
+ if (!empty($conf['security']['chmod']))
+ {
+ // CHMOD auf der Datei ausfuehren.
+ if ( ! @chmod($dest,octdec($conf['security']['chmod'])) )
+ throw new OpenRatException('ERROR_PUBLISH','Unable to CHMOD file '.$dest);
+ }
+ }
+
+ if ( $this->with_ftp ) // Falls FTP aktiviert
+ {
+ $dest = $dest_filename;
+ $this->ftp->put( $source,$dest );
+ }
+ }
+
+
+
+ /**
+ * Rekursives Anlagen von Verzeichnisse
+ * Nett gemacht.
+ * Quelle: http://de3.php.net/manual/de/function.mkdir.php
+ * Thx to acroyear at io dot com
+ *
+ * @param String Verzeichnis
+ * @return boolean
+ */
+ private function mkdirs( $strPath )
+ {
+ global $conf;
+
+ if ( is_dir($strPath) )
+ return true;
+
+ $pStrPath = dirname($strPath);
+
+ if ( !$this->mkdirs($pStrPath) )
+ return false;
+
+ if ( ! @mkdir($strPath,0777) )
+ throw new OpenRatException('ERROR_PUBLISH','Cannot create directory: '.$strPath);
+
+ // CHMOD auf dem Verzeichnis ausgef�hren.
+ if (!empty($conf['security']['chmod_dir']))
+ {
+ if ( ! @chmod($strPath,octdec($conf['security']['chmod_dir'])) )
+ throw new OpenRatException('ERROR_PUBLISH','Unable to CHMOD directory: '.$strPath);
+ }
+
+
+ return true;
+ }
+
+
+
+ /**
+ * Beenden des Ver�ffentlichungs-Vorganges.<br>
+ * Eine vorhandene FTP-Verbindung wird geschlossen.<br>
+ * Falls entsprechend konfiguriert, wird ein Systemkommando ausgef�hrt.
+ */
+ public function close()
+ {
+ if ( $this->with_ftp )
+ {
+ Logger::debug('Closing FTP connection' );
+ $this->ftp->close();
+ }
+
+ // Ausfuehren des Systemkommandos.
+ if ( !empty($this->cmd_after_publish) )
+ {
+ $ausgabe = array();
+ $rc = false;
+ Logger::debug('Executing system command: '.$this->cmd_after_publish );
+ $user = Session::getUser();
+ putenv("CMS_USER_NAME=".$user->name );
+ putenv("CMS_USER_ID=" .$user->userid);
+ putenv("CMS_USER_MAIL=".$user->mail );
+ exec( $this->cmd_after_publish,$ausgabe,$rc );
+
+ if ( $rc != 0 ) // Wenn Returncode ungleich 0, dann Fehler melden.
+ throw new OpenRatException('ERROR_PUBLISH','System command failed - returncode is '.$rc."\n".
+ $ausgabe);
+ else
+ Logger::debug('System command successful' );
+
+ }
+ }
+
+
+
+ /**
+ * Aufraeumen des Zielverzeichnisses.<br><br>
+ * Es wird der komplette Zielordner samt Unterverzeichnissen durchsucht. Jede
+ * Datei, die laenger existiert als der aktuelle Request alt ist, wird geloescht.<br>
+ * Natuerlich darf diese Funktion nur nach einem Gesamt-Veroeffentlichen ausgefuehrt werden.
+ */
+ public function clean()
+ {
+ if ( !empty($this->local_destdir) )
+ $this->cleanFolder($this->local_destdir);
+ }
+
+
+
+ /**
+ * Aufr�umen eines Verzeichnisses.<br><br>
+ * Dateien, die l�nger existieren als der aktuelle Request alt ist, werden gel�scht.<br>
+ *
+ * @param String Verzeichnis
+ */
+ private function cleanFolder( $folderName )
+ {
+ $dh = opendir( $folderName );
+
+ while( $file = readdir($dh) )
+ {
+ if ( $file != '.' && $file != '..')
+ {
+ $fullpath = $folderName.'/'.$file;
+
+ // Wenn eine Datei beschreibbar und entsprechend alt
+ // ist, dann entfernen
+ if ( is_file($fullpath) &&
+ is_writable($fullpath) &&
+ filemtime($fullpath) < START_TIME )
+ unlink($fullpath);
+
+ // Bei Ordnern rekursiv absteigen
+ if ( is_dir( $fullpath) )
+ {
+ $this->cleanFolder($fullpath);
+ @rmdir($fullpath);
+ }
+ }
+ }
+ }
+
+
+ public function getTarget()
+ {
+ return OR_PUBLISH_TARGET_PUBLISH;
+ }
+
+
+ public function isSimplePreview()
+ {
+ return false;
+ }
+
+ public function isPublic()
+ {
+ return true;
+ }
+}+
\ No newline at end of file
diff --git a/modules/cms-publish/PublishShow.class.php b/modules/cms-publish/PublishShow.class.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace cms\publish;
+
+use cms\model\BaseObject;
+use cms\model\Link;
+use cms\model\Url;
+
+/**
+ * Created by PhpStorm.
+ * User: dankert
+ * Date: 10.08.18
+ * Time: 23:47
+ */
+
+class PublishShow extends Publish
+{
+ /**
+ * @param $from \cms\model\BaseObject
+ * @param $to \cms\model\BaseObject
+ */
+ public function linkToObject( $from, $to )
+ {
+ return "...";
+ }
+
+ public function isPublic()
+ {
+ return false;
+ }
+
+ public function copy($tmp_filename,$dest_filename,$lastChangeDate=null)
+ {
+ // nothing to do.
+ }
+
+ public function clean()
+ {
+ // nothing to do.
+ }
+
+ public function close()
+ {
+ // nothing to do.
+ }
+
+ public function isSimplePreview()
+ {
+ return false;
+ }
+}+
\ No newline at end of file
diff --git a/modules/cms-publish/require.php b/modules/cms-publish/require.php
@@ -1,6 +1,8 @@
<?php
- require_once( __DIR__.'/'.'Publish.class.php' );
- require_once( __DIR__.'/'.'Ftp.class.php' );
- require_once( __DIR__.'/'.'PreviewLinkSchema.class.php' );
- require_once( __DIR__.'/'.'PublicLinkSchema.class.php' );
+require_once( __DIR__.'/'.'Publish.class.php' );
+require_once(__DIR__ . '/'.'PublishPreview.class.php');
+require_once(__DIR__ . '/'.'PublishEdit.class.php');
+require_once(__DIR__ . '/'.'PublishShow.class.php');
+require_once(__DIR__ . '/'.'PublishPublic.class.php');
+require_once( __DIR__.'/'.'Ftp.class.php' );
diff --git a/modules/cms-ui/themes/default/html/views/file/edit.php b/modules/cms-ui/themes/default/html/views/file/edit.php
@@ -9,7 +9,7 @@
<div class="input">
<br/>
- <input size="40" id="req15436200121299438994_file" type="file" name="file" class="upload" />
+ <input size="40" id="req15436282311082803860_file" type="file" name="file" class="upload" />
<br/>
diff --git a/modules/util/ClassUtils.class.php b/modules/util/ClassUtils.class.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * Class ClassUtils
+ * @author Jan Dankert
+ */
+class ClassUtils {
+
+ public static function getSimpleClassName($object)
+ {
+ $classname = get_class($object);
+ if ($pos = strrpos($classname, '\\')) return substr($classname, $pos + 1);
+ return $pos;
+ }
+}+
\ No newline at end of file
diff --git a/modules/util/GlobalFunctions.class.php b/modules/util/GlobalFunctions.class.php
@@ -34,6 +34,7 @@ class GlobalFunctions
}
+
}
?>
\ 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__.'/'.'ClassUtils.class.php' );
require_once( __DIR__.'/'.'GlobalFunctions.class.php' );
require_once( __DIR__.'/'.'Http.class.php' );
require_once( __DIR__.'/'.'Html.class.php' );