diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index e25878b3aaa..bab1cc0f80f 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -133,7 +133,7 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha')) $fieldnamekey=$listfield[$f]; setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors'); } - if ($value == 'ref' && ! preg_match('/^[a-z0-9]+$/i', $_POST[$value])) + if ($value == 'ref' && ! preg_match('/^[a-z0-9_\-\.]+$/i', $_POST[$value])) { $ok=0; $fieldnamekey=$listfield[$f]; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 51fb61c58d5..1c516078dd4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3994,7 +3994,7 @@ abstract class CommonObject $arrayofrecords = array(); // The write_file of templates of adherent class need this $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); } - else + else { $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); } @@ -4014,13 +4014,13 @@ abstract class CommonObject $upload_dir = dirname($destfull); $destfile = basename($destfull); $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); - + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir { $filename = basename($destfile); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($this->db); $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); @@ -4935,7 +4935,7 @@ abstract class CommonObject else { $queryarray[$field] = (int) price2num($this->{$field}); - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be rest to null later if property 'nullifempty' is on for this field. + if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. } } else if($this->isFloat($info)) @@ -4949,7 +4949,7 @@ abstract class CommonObject } if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); - if (! empty($info['nullifempty']) && empty($queryarray[$field])) $queryarray[$field] = null; + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; } return $queryarray; @@ -5039,7 +5039,7 @@ abstract class CommonObject $fieldvalues = $this->set_save_query(); if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; - unset($fieldvalues['rowid']); // We suppose the field rowid is reserved field for autoincrement field. + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. $keys=array(); $values = array(); @@ -5056,7 +5056,7 @@ abstract class CommonObject $sql.= ' ('.implode( ", ", $keys ).')'; $sql.= ' VALUES ('.implode( ", ", $values ).')'; - $res = $this->db->query( $sql ); + $res = $this->db->query($sql); if ($res===false) { $error++; $this->errors[] = $this->db->lasterror(); diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql index 45c72bd9cc8..b027f560aa0 100644 --- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql +++ b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql @@ -28,9 +28,11 @@ ALTER TABLE llx_facture_fourn ADD COLUMN date_pointoftax date DEFAULT NULL; ALTER TABLE llx_facture_fourn ADD COLUMN date_valid date; +ALTER TABLE llx_website MODIFY COLUMN ref varchar(128); ALTER TABLE llx_website_page MODIFY COLUMN pageurl varchar(255); ALTER TABLE llx_website_page ADD COLUMN lang varchar(6); ALTER TABLE llx_website_page ADD COLUMN fk_page integer; +ALTER TABLE llx_website_page ADD COLUMN grabbed_from varchar(255); ALTER TABLE llx_website_page MODIFY COLUMN status INTEGER DEFAULT 1; UPDATE llx_website_page set status = 1 WHERE status IS NULL; @@ -187,4 +189,4 @@ ALTER TABLE llx_user ADD COLUMN default_c_exp_tax_cat integer; ALTER TABLE llx_extrafields ADD COLUMN fk_user_author integer; ALTER TABLE llx_extrafields ADD COLUMN fk_user_modif integer; ALTER TABLE llx_extrafields ADD COLUMN datec datetime; -ALTER TABLE llx_extrafields ADD COLUMN tms timestamp; \ No newline at end of file +ALTER TABLE llx_extrafields ADD COLUMN tms timestamp; diff --git a/htdocs/install/mysql/tables/llx_website.sql b/htdocs/install/mysql/tables/llx_website.sql index 7773aa469c5..64f72142add 100644 --- a/htdocs/install/mysql/tables/llx_website.sql +++ b/htdocs/install/mysql/tables/llx_website.sql @@ -21,7 +21,7 @@ CREATE TABLE llx_website ( rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY, entity integer DEFAULT 1, - ref varchar(24) NOT NULL, + ref varchar(128) NOT NULL, description varchar(255), status integer, fk_default_home integer, diff --git a/htdocs/install/mysql/tables/llx_website_page.sql b/htdocs/install/mysql/tables/llx_website_page.sql index ec662e451f8..f3d1cca4786 100644 --- a/htdocs/install/mysql/tables/llx_website_page.sql +++ b/htdocs/install/mysql/tables/llx_website_page.sql @@ -29,6 +29,7 @@ CREATE TABLE llx_website_page fk_page integer, 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, diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 9e0ded40602..25fb63af508 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -43,4 +43,6 @@ PageIsANewTranslation=The new page is a translation of the current page ? LanguageMustNotBeSameThanClonedPage=You clone a page as a translation. The language of the new page must be different than language of source page. ParentPageId=Parent page ID WebsiteId=Website ID - +CreateByFetchingExternalPage=Create page/container by fetching page from external URL... +OrEnterPageInfoManually=Or create empty page from scratch... +FetchAndCreate=Fetch and Create diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 49aa42ad96d..fc8ecd1adf7 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -59,11 +59,15 @@ class MyObject extends CommonObject /** - * 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed, - * 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed) - * 'notnull' if not null in database, 'index' if we want an index in database - * 'position' is the sort order of field - * 'searchall' is 1 if we want to search in this field when making a search from the quick search button + * 'type' if the field format. + * 'label' the translation key. + * 'enabled' is a condition when the filed must be managed. + * 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed). + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). + * 'index' if we want an index in database. + * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). + * 'position' is the sort order of field. + * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). * 'comment' is not used. You can store here any text of your choice. */ @@ -73,19 +77,19 @@ class MyObject extends CommonObject * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. */ public $fields=array( - 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'index'=>true, 'position'=>1, 'comment'=>'Id'), - 'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>true, 'index'=>true, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), - 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>true, 'index'=>true, 'position'=>20), + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), + 'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'index'=>1, 'position'=>20), 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1), 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'searchall'=>0, 'isameasure'=>1), - 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000), - 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), - 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), + 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>1, 'position'=>1000), + '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'=>500), //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>500), - 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), - 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>500), + 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500), + 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'notnull'=>-1, 'position'=>500), //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'position'=>500), - 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'notnull'=>-1, 'index'=>1, 'position'=>1000), ); // END MODULEBUILDER PROPERTIES diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 5636f31d525..ffb64573cdb 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -62,23 +62,24 @@ class WebsitePage extends CommonObject * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. */ public $fields=array( - 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'index'=>true, 'position'=>1, 'comment'=>'Id'), - 'pageurl' =>array('type'=>'varchar(16)', 'label'=>'WEBSITE_PAGENAME', 'enabled'=>1, 'visible'=>1, 'notnull'=>true, 'index'=>true, 'position'=>10, 'searchall'=>1, 'comment'=>'Alias of page'), + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), + 'pageurl' =>array('type'=>'varchar(16)', 'label'=>'WEBSITE_PAGENAME', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Alias of page'), 'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1), 'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1), 'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0), 'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0), 'lang' =>array('type'=>'varchar(6)', 'label'=>'Lang', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0), //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000), - 'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'searchall'=>0), - 'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0), - 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), - 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), - //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>500), + 'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'), + 'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'), + 'grabbed_from' =>array('type'=>'varchar(255)', 'label'=>'GrabbedFrom', 'enabled'=>1, 'visible'=>1, 'index'=>1, 'position'=>400, 'comment'=>'URL page content was grabbed from'), + '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'=>500), + //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>500), //'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), //'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>500), //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'position'=>500), - 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>1, 'position'=>1000, 'notnull'=>-1), ); // END MODULEBUILDER PROPERTIES @@ -98,109 +99,11 @@ class WebsitePage extends CommonObject * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - $now=dol_now(); - - // Clean parameters - if (isset($this->fk_website)) { - $this->fk_website = trim($this->fk_website); - } - if (isset($this->pageurl)) { - $this->pageurl = trim($this->pageurl); - } - if (isset($this->title)) { - $this->title = trim($this->title); - } - if (isset($this->description)) { - $this->description = trim($this->description); - } - if (isset($this->keywords)) { - $this->keywords = trim($this->keywords); - } - if (isset($this->content)) { - $this->content = trim($this->content); - } - if (isset($this->status)) { - $this->status = trim($this->status); - } - if (empty($this->date_creation)) { - $this->date_creation = $now; - } - if (empty($this->date_modification)) { - $this->date_modification = $now; - } - - // Check parameters - // Put here code to add control on parameters values - - // Insert request - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - $sql.= 'fk_website,'; - $sql.= 'pageurl,'; - $sql.= 'title,'; - $sql.= 'description,'; - $sql.= 'keywords,'; - $sql.= 'content,'; - $sql.= 'lang,'; - $sql.= 'fk_page,'; - $sql.= 'status,'; - $sql.= 'date_creation,'; - $sql.= 'tms'; - $sql .= ') VALUES ('; - $sql .= ' '.(! isset($this->fk_website)?'NULL':$this->fk_website).','; - $sql .= ' '.(! isset($this->pageurl)?'NULL':"'".$this->db->escape($this->pageurl)."'").','; - $sql .= ' '.(! isset($this->title)?'NULL':"'".$this->db->escape($this->title)."'").','; - $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; - $sql .= ' '.(! isset($this->keywords)?'NULL':"'".$this->db->escape($this->keywords)."'").','; - $sql .= ' '.(! isset($this->content)?'NULL':"'".$this->db->escape($this->content)."'").','; - $sql .= ' '.(! isset($this->lang)?'NULL':"'".$this->db->escape($this->lang)."'").','; - $sql .= ' '.(empty($this->fk_page)?'NULL':$this->db->escape($this->fk_page)).','; - $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; - $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?"'".$this->db->idate($now)."'":"'".$this->db->idate($this->date_creation)."'").','; - $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); - $sql .= ')'; - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (! $resql) { - $error++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - } - - if (! $error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action to call a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_CREATE',$user); - //if ($result < 0) $error++; - //// End call triggers - } - } - - // Commit or rollback - if ($error) - { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return $this->id; - } + return $this->createCommon($user, $notrigger); } /** @@ -465,53 +368,13 @@ class WebsitePage extends CommonObject /** * Delete object in database * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false) { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - $this->db->begin(); - - if (!$error) { - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_DELETE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - } - } - - if (!$error) { - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; - $sql .= ' WHERE rowid=' . $this->id; - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return 1; - } + return $this->deleteCommon($user, $trigger); } /** diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index f9eb48518e8..2093adb4cb9 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -163,30 +163,85 @@ if ($action == 'add') $db->begin(); $objectpage->fk_website = $object->id; - - $objectpage->title = GETPOST('WEBSITE_TITLE'); - $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); - $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); - $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS'); - $objectpage->lang = GETPOST('WEBSITE_LANG'); - - if (empty($objectpage->pageurl)) + if (GETPOST('fetchexternalurl','alpha')) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); - $error++; - $action='create'; + $urltograb=GETPOST('externalurl','alpha'); } - else if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl)) + + if ($urltograb) { - setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors'); - $error++; - $action='create'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; + + $tmp = getURLContent($urltograb); + if ($tmp['curl_error_no']) + { + $error++; + setEventMessages($tmp['curl_error_msg'], null, 'errors'); + $action='create'; + } + else + { + preg_match('/(.*)<\/head>/is', $tmp['content'], $reg); + $head = $reg[1]; + + $urltograbwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograbwithoutdomain); + $objectpage->pageurl = basename($urltograbwithoutdomain); + if (empty($objectpage->pageurl)) $objectpage->pageurl='home'; + + if (preg_match('/(.*)<\/title>/ims', $head, $regtmp)) + { + $objectpage->title = $regtmp[1]; + } + if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp)) + { + $objectpage->description = $regtmp[1]; + } + if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp)) + { + $objectpage->keywords = $regtmp[1]; + } + if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp)) + { + $tmplang=explode('-', $regtmp[1]); + $objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : ''); + } + + $objectpage->content = $tmp['content']; + $objectpage->content = preg_replace('/^.*<body[^>]*>/ims', '', $objectpage->content); + $objectpage->content = preg_replace('/<\/body[^>]*>.*$/ims', '', $objectpage->content); + + $objectpage->grabbed_from = $urltograb; + } } - if (empty($objectpage->title)) + else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors'); - $error++; - $action='create'; + $objectpage->title = GETPOST('WEBSITE_TITLE'); + $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); + $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); + $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS'); + $objectpage->lang = GETPOST('WEBSITE_LANG'); + } + + if (! $error) + { + if (empty($objectpage->pageurl)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); + $error++; + $action='create'; + } + else if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl)) + { + setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors'); + $error++; + $action='create'; + } + if (empty($objectpage->title)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors'); + $error++; + $action='create'; + } } if (! $error) @@ -212,7 +267,7 @@ if ($action == 'add') if (! $error) { $action = 'preview'; - $id = $objectpage->id; + $pageid = $objectpage->id; } } @@ -875,7 +930,7 @@ if (count($object->records) > 0) print '</a>'; } - if (in_array($action, array('editcss','editmenu','create'))) + if (in_array($action, array('editcss','editmenu'))) { if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">'; if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">'; @@ -887,9 +942,9 @@ if (count($object->records) > 0) // ***** Part for pages - if ($website) + if ($website && ! in_array($action, array('editcss','editmenu'))) { - print '</div>'; + print '</div>'; // Close current websitebar to open a new one $array=$objectpage->fetchAll($object->id); if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); @@ -984,9 +1039,9 @@ if (count($object->records) > 0) print '   '; + print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">'; print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageSource")).'" name="editsource">'; print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">'; - print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">'; if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">'; else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">'; print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">'; @@ -994,7 +1049,7 @@ if (count($object->records) > 0) } } - print '</div>'; + print '</div>'; // end website selection print '<div class="websitetools">'; @@ -1032,7 +1087,7 @@ if (count($object->records) > 0) if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">'; } - print '</div>'; + print '</div>'; // end websitetools print '<div class="websitehelp">'; if (GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha')) @@ -1040,7 +1095,7 @@ if (count($object->records) > 0) $htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource"); print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 0, 2, 'tooltipsubstitution'); } - print '</div>'; + print '</div>'; // end websitehelp @@ -1093,7 +1148,7 @@ else } -print '</div>'; +print '</div>'; // end current websitebar $head = array(); @@ -1224,19 +1279,21 @@ if ($action == 'editmeta' || $action == 'create') if ($action == 'create') { - print ' * '.$langs->trans("CreateByFetchingExternalPage").'<br>'; + print '<br>'; + + print ' * '.$langs->trans("CreateByFetchingExternalPage").'<br><hr>'; print '<table class="border" width="100%">'; print '<tr><td class="titlefieldcreate">'; print $langs->trans("URL"); print '</td><td>'; - print '<input class="flat minwidth300" type="text" name="externalurl" value="" placeholder="http://externalsite/pagetofetch"> '; - print '<input class="button" type="submit" name="fetchexternalurl" value="'.$langs->trans("FetchAndCreate").'">'; + print '<input class="flat minwidth300" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl','alpha')).'" placeholder="http://externalsite/pagetofetch"> '; + print '<input class="button" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">'; print '</td></tr>'; print '</table>'; print '<br>'; - print ' * '.$langs->trans("OrEnterPageInfoManually").'<br>'; + print ' * '.$langs->trans("OrEnterPageInfoManually").'<br><hr>'; } print '<table class="border" width="100%">'; @@ -1291,6 +1348,18 @@ if ($action == 'editmeta' || $action == 'create') print '</td></tr>'; print '</table>'; + + if ($action == 'create') + { + print '<div class="center">'; + + print '<input class="button" type="submit" name="add" value="'.$langs->trans("Create").'">'; + print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">'; + + print '</div>'; + } + + //print '</div>'; //dol_fiche_end(); @@ -1369,12 +1438,12 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa // REPLACEMENT OF LINKS When page called by website editor $out.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers - $out.=dolWebsiteReplacementOfLinks($csscontent); + $out.=dolWebsiteReplacementOfLinks($object, $csscontent); $out.='</style>'."\n"; $out.='<div id="bodywebsite" class="bodywebsite">'."\n"; - $out.=dolWebsiteReplacementOfLinks($objectpage->content)."\n"; + $out.=dolWebsiteReplacementOfLinks($object, $objectpage->content)."\n"; $out.='</div>'; @@ -1423,18 +1492,19 @@ $db->close(); /** * Save content of a page on disk * + * @param Website $website Web site object * @param string $content Content to replace * @return boolean True if OK */ -function dolWebsiteReplacementOfLinks($content) +function dolWebsiteReplacementOfLinks($website, $content) { - // Replace php code. Note $objectpage->content come from database and does not contains body tags. + // Replace php code. Note $content may come from database and does not contains body tags. $content = preg_replace('/<\?php[^\?]+\?>\n*/ims', '<span style="background: #ddd; border: 1px solid #ccc; border-radius: 4px;">...php...</span>', $content); // Replace relative link / with dolibarr URL - $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$object->ref.'&pageid='.$object->fk_default_home.'"', $content, -1, $nbrep); + $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); // Replace relative link /xxx.php with dolibarr URL - $content = preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$object->ref.'&pageref=\2"', $content, -1, $nbrep); + $content = preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); $content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);