Skip to content

Commit

Permalink
Work on new management for website module
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 25, 2018
1 parent b4b6e90 commit e6be047
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 43 deletions.
11 changes: 6 additions & 5 deletions htdocs/core/lib/website.lib.php
Expand Up @@ -103,12 +103,13 @@ function dolWebsiteOutput($content)
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current

// Note: This seems never called when page is output inside the website editor (search 'REPLACEMENT OF LINKS When page called by website editor')
if (defined('USEDOLIBARREDITOR'))
if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor
{
// Do nothing
// We remove the <head> part of content
$content = preg_replace('/<head>.*<\/head>/ims', '', $content);

}
elseif (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr server
elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server
{
global $website;

Expand Down Expand Up @@ -142,7 +143,7 @@ function dolWebsiteOutput($content)
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
$content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
}
else // REPLACEMENT OF LINKS When page called from virtual host
else // REPLACEMENT OF LINKS When page called from virtual host
{
$symlinktomediaexists=1;

Expand Down
4 changes: 4 additions & 0 deletions htdocs/install/mysql/migration/8.0.0-9.0.0.sql
Expand Up @@ -74,3 +74,7 @@ ALTER TABLE llx_societe ADD COLUMN twitter varchar(255) after skype;
ALTER TABLE llx_societe ADD COLUMN facebook varchar(255) after skype;
ALTER TABLE llx_socpeople ADD COLUMN twitter varchar(255) after skype;
ALTER TABLE llx_socpeople ADD COLUMN facebook varchar(255) after skype;


ALTER TABLE llx_website CHANGE COLUMN fk_user_create fk_user_creat integer;
ALTER TABLE llx_website_page CHANGE COLUMN fk_user_create fk_user_creat integer;
10 changes: 5 additions & 5 deletions htdocs/install/mysql/tables/llx_website.sql
Expand Up @@ -27,9 +27,9 @@ CREATE TABLE llx_website
status integer DEFAULT 1,
fk_default_home integer,
virtualhost varchar(255),
fk_user_create integer,
fk_user_modif integer,
date_creation datetime,
tms timestamp,
import_key varchar(14) -- import key
fk_user_creat integer,
fk_user_modif integer,
date_creation datetime,
tms timestamp,
import_key varchar(14) -- import key
) ENGINE=innodb;
12 changes: 6 additions & 6 deletions htdocs/install/mysql/tables/llx_website_page.sql
Expand Up @@ -32,10 +32,10 @@ CREATE TABLE llx_website_page
htmlheader text,
content mediumtext, -- text is not enough in size
status integer DEFAULT 1,
grabbed_from varchar(255),
fk_user_create integer,
fk_user_modif integer,
date_creation datetime,
tms timestamp,
import_key varchar(14) -- import key
grabbed_from varchar(255),
fk_user_creat integer,
fk_user_modif integer,
date_creation datetime,
tms timestamp,
import_key varchar(14) -- import key
) ENGINE=innodb;
17 changes: 8 additions & 9 deletions htdocs/website/class/website.class.php
@@ -1,10 +1,9 @@
<?php
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2007-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) ---Put here your own copyright and developer email---
*
* 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
Expand Down Expand Up @@ -158,7 +157,7 @@ public function create(User $user, $notrigger = false)
$sql.= 'status,';
$sql.= 'fk_default_home,';
$sql.= 'virtualhost,';
$sql.= 'fk_user_create,';
$sql.= 'fk_user_creat,';
$sql.= 'date_creation,';
$sql.= 'tms';
$sql .= ') VALUES (';
Expand All @@ -168,7 +167,7 @@ public function create(User $user, $notrigger = false)
$sql .= ' '.(! isset($this->status)?'1':$this->status).',';
$sql .= ' '.(! isset($this->fk_default_home)?'NULL':$this->fk_default_home).',';
$sql .= ' '.(! isset($this->virtualhost)?'NULL':"'".$this->db->escape($this->virtualhost)."'").",";
$sql .= ' '.(! isset($this->fk_user_create)?$user->id:$this->fk_user_create).',';
$sql .= ' '.(! isset($this->fk_user_creat)?$user->id:$this->fk_user_creat).',';
$sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").",";
$sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_creation)."'");
$sql .= ')';
Expand Down Expand Up @@ -227,7 +226,7 @@ public function fetch($id, $ref = null)
$sql .= " t.status,";
$sql .= " t.fk_default_home,";
$sql .= " t.virtualhost,";
$sql .= " t.fk_user_create,";
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif,";
$sql .= " t.date_creation,";
$sql .= " t.tms as date_modification";
Expand All @@ -253,7 +252,7 @@ public function fetch($id, $ref = null)
$this->status = $obj->status;
$this->fk_default_home = $obj->fk_default_home;
$this->virtualhost = $obj->virtualhost;
$this->fk_user_create = $obj->fk_user_create;
$this->fk_user_creat = $obj->fk_user_creat;
$this->fk_user_modif = $obj->fk_user_modif;
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_modification = $this->db->jdate($obj->date_modification);
Expand Down Expand Up @@ -317,7 +316,7 @@ public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, arra
$sql .= " t.status,";
$sql .= " t.fk_default_home,";
$sql .= " t.virtualhost,";
$sql .= " t.fk_user_create,";
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif,";
$sql .= " t.date_creation,";
$sql .= " t.tms as date_modification";
Expand Down Expand Up @@ -357,7 +356,7 @@ public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, arra
$line->status = $obj->status;
$line->fk_default_home = $obj->fk_default_home;
$line->virtualhost = $obj->virtualhost;
$this->fk_user_create = $obj->fk_user_create;
$this->fk_user_creat = $obj->fk_user_creat;
$this->fk_user_modif = $obj->fk_user_modif;
$line->date_creation = $this->db->jdate($obj->date_creation);
$line->date_modification = $this->db->jdate($obj->date_modification);
Expand Down Expand Up @@ -770,7 +769,7 @@ public function initAsSpecimen()
$this->status = '';
$this->fk_default_home = null;
$this->virtualhost = 'http://myvirtualhost';
$this->fk_user_create = $user->id;
$this->fk_user_creat = $user->id;
$this->fk_user_modif = $user->id;
$this->date_creation = dol_now();
$this->tms = dol_now();
Expand Down
23 changes: 11 additions & 12 deletions htdocs/website/class/websitepage.class.php
@@ -1,9 +1,8 @@
<?php
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2007-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) ---Put here your own copyright and developer email---
*
* 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
Expand Down Expand Up @@ -92,8 +91,8 @@ class WebsitePage extends CommonObject
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>501),
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
//'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
//'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>511),
'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>511),
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>1, 'position'=>1000, 'notnull'=>-1),
);
Expand Down Expand Up @@ -159,7 +158,7 @@ public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
$sql .= " t.grabbed_from,";
$sql .= " t.date_creation,";
$sql .= " t.tms as date_modification,";
$sql .= " t.fk_user_create,";
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
//$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
Expand Down Expand Up @@ -202,7 +201,7 @@ public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
$this->grabbed_from = $obj->grabbed_from;
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_modification = $this->db->jdate($obj->date_modification);
$this->fk_user_create = $obj->fk_user_create;
$this->fk_user_creat = $obj->fk_user_creat;
$this->fk_user_modif = $obj->fk_user_modif;
}
$this->db->free($resql);
Expand Down Expand Up @@ -255,7 +254,7 @@ public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $of
$sql .= " t.grabbed_from,";
$sql .= " t.date_creation,";
$sql .= " t.tms as date_modification,";
$sql .= " t.fk_user_create,";
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' WHERE t.fk_website = '.$websiteid;
Expand All @@ -271,11 +270,11 @@ public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $of
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere);
$sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')';
}

if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield,$sortorder);
$sql .= $this->db->order($sortfield, $sortorder);
}
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
Expand Down Expand Up @@ -305,7 +304,7 @@ public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $of
$record->grabbed_from = $obj->grabbed_from;
$record->date_creation = $this->db->jdate($obj->date_creation);
$record->date_modification = $this->db->jdate($obj->date_modification);
$record->fk_user_create = $obj->fk_user_create;
$record->fk_user_creat = $obj->fk_user_creat;
$record->fk_user_modif = $obj->fk_user_modif;
//var_dump($record->id);
$records[$record->id] = $record;
Expand Down Expand Up @@ -401,7 +400,7 @@ public function createFromClone(User $user, $fromid, $newref, $newlang='', $istr
$object->ref = $newref;
$object->pageurl = $newref;
$object->aliasalt = '';
$object->fk_user_create = $user->id;
$object->fk_user_creat = $user->id;
$object->title = ($keeptitleunchanged ? '' : $langs->trans("CopyOf").' ').$object->title;
if (! empty($newlang)) $object->lang=$newlang;
if ($istranslation) $object->fk_page = $fromid;
Expand Down Expand Up @@ -555,6 +554,6 @@ public function initAsSpecimen()
$this->grabbed_from = '';
$this->date_creation = $now - (24 * 30 * 3600);
$this->date_modification = $now - (24 * 7 * 3600);
$this->fk_user_create = $user->id;
$this->fk_user_creat = $user->id;
}
}
13 changes: 7 additions & 6 deletions htdocs/website/index.php
Expand Up @@ -388,7 +388,7 @@
// Remove comments
$tmp['content'] = removeHtmlComment($tmp['content']);

preg_match('/<head>(.*)<\/head>/is', $tmp['content'], $reg);
preg_match('/<head>(.*)<\/head>/ims', $tmp['content'], $reg);
$head = $reg[1];

$objectpage->type_container = 'page';
Expand Down Expand Up @@ -1327,7 +1327,7 @@
$objectpage->content = GETPOST('PAGE_CONTENT','none');

// Clean data. We remove all the head section.
$objectpage->content = preg_replace('/<head>.*<\/head>/s', '', $objectpage->content);
$objectpage->content = preg_replace('/<head>.*<\/head>/ims', '', $objectpage->content);
/* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */


Expand Down Expand Up @@ -1690,7 +1690,8 @@
print '</div>';


// Toolbar for website
// Toolbar for websites

print '<div class="websitetools">';

if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
Expand Down Expand Up @@ -1790,7 +1791,7 @@
$out.='<option value="'.$key.'"';
if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value
$out.='>';
$out.='['.$valpage->type_container.' '.$valpage->id.'] ';
$out.='['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).'] ';
$out.=$valpage->pageurl.' - '.$valpage->title;
if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
$out.='</option>';
Expand Down Expand Up @@ -2665,8 +2666,8 @@

// Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
// so editable will be available only from container created from scratch
//$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
$out.='<div id="bodywebsite" class="bodywebsite">'."\n";
//$out.='<div id="divbodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
$out.='<div id="divbodywebsite" class="bodywebsite">'."\n";

$newcontent = $objectpage->content;

Expand Down

0 comments on commit e6be047

Please sign in to comment.