Skip to content

Commit

Permalink
Debug module websites
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 10, 2017
1 parent 8c287c0 commit be09c91
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion htdocs/admin/websites.php
Expand Up @@ -259,7 +259,7 @@
if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
else { $rowidcol="rowid"; }

$sql = "DELETE from ".MAIN_DB_PREFIX."website_pages WHERE fk_website ='".$rowid."'";
$sql = "DELETE from ".MAIN_DB_PREFIX."website_page WHERE fk_website ='".$rowid."'";
$result = $db->query($sql);

$sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid ='".$rowid."'";
Expand Down
6 changes: 3 additions & 3 deletions htdocs/install/mysql/migration/5.0.0-6.0.0.sql
Expand Up @@ -497,7 +497,7 @@ ALTER TABLE llx_usergroup_rights ADD CONSTRAINT fk_usergroup_rights_fk_usergroup

-- For new module website

CREATE TABLE llx_website_pages
CREATE TABLE llx_website_page
(
rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
fk_website integer NOT NULL,
Expand All @@ -513,9 +513,9 @@ CREATE TABLE llx_website_pages
tms timestamp
) ENGINE=innodb;

ALTER TABLE llx_website_pages ADD UNIQUE INDEX uk_website_pages_url (fk_website,pageurl);
ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website,pageurl);

ALTER TABLE llx_website_pages ADD CONSTRAINT fk_website_pages_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid);
ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid);


-- For new module blockedlog
Expand Down
Expand Up @@ -16,7 +16,7 @@
--
-- ===========================================================================

ALTER TABLE llx_website_pages ADD UNIQUE INDEX uk_website_pages_url (fk_website,pageurl);
ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website, pageurl);

ALTER TABLE llx_website_pages ADD CONSTRAINT fk_website_pages_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid);
ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid);

Expand Up @@ -17,7 +17,7 @@
-- ========================================================================


CREATE TABLE llx_website_pages
CREATE TABLE llx_website_page
(
rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
fk_website integer NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/website.lang
Expand Up @@ -4,6 +4,7 @@ WebsiteSetupDesc=Create here as much entry as number of different websites you n
DeleteWebsite=Delete website
ConfirmDeleteWebsite=Are you sure you want to delete this web site. All its pages and content will also be removed.
WEBSITE_PAGENAME=Page name/alias
WEBSITE_HTML_HEADER=HTML Header
WEBSITE_CSS_URL=URL of external CSS file
WEBSITE_CSS_INLINE=CSS content
PageNameAliasHelp=Name or alias of the page.<br>This alias is also used to forge a SEO URL when website is read from a Virtual host of a Web server (like Apacke, Nginx, ...). Use the button "<strong>%s</strong>" to edit this alias.
Expand Down
2 changes: 1 addition & 1 deletion htdocs/websites/class/websitepage.class.php
Expand Up @@ -129,7 +129,7 @@ public function create(User $user, $notrigger = false)
$sql.= 'content,';
$sql.= 'status,';
$sql.= 'date_creation,';
$sql.= 'date_modification';
$sql.= 'tms';
$sql .= ') VALUES (';
$sql .= ' '.(! isset($this->fk_website)?'NULL':$this->fk_website).',';
$sql .= ' '.(! isset($this->pageurl)?'NULL':"'".$this->db->escape($this->pageurl)."'").',';
Expand Down
62 changes: 44 additions & 18 deletions htdocs/websites/index.php
Expand Up @@ -129,6 +129,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,

global $dolibarr_main_data_root;
$pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website;
$filehtmlheader=$pathofwebsite.'/header.html';
$filecss=$pathofwebsite.'/styles.css.php';
$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
$fileindex=$pathofwebsite.'/index.php';
Expand Down Expand Up @@ -240,25 +241,30 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
// Update css
if ($action == 'updatecss')
{
//$db->begin();

$res = $object->fetch(0, $website);

/*
$res = $object->update($user);
if ($res > 0)
{
$db->commit();
$action='';
}
else
// Html header file
$htmlheadercontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n";
$htmlheadercontent.= '<!-- File generated to save common html header - YOU CAN MODIFY DIRECTLY THIS FILE. Change affects all pages of website. -->'."\n";
$htmlheadercontent.= '<!-- END -->'."\n";
$htmlheadercontent.= GETPOST('WEBSITE_HTML_HEADER');

dol_syslog("Save file css into ".$filehtmlheader);

dol_mkdir($pathofwebsite);
$result = file_put_contents($filehtmlheader, $htmlheadercontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));

if (! $result)
{
$error++;
$db->rollback();
}*/
setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
}

// Css file
$csscontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n";
$csscontent.= '<!-- File generated to wrap the css file - DO NOT MODIFY - It is just a copy of database css content -->'."\n";
$csscontent.= '<!-- File generated to wrap the css file - YOU CAN MODIFY DIRECTLY THIS FILE. Change affects all pages of website. -->'."\n";
$csscontent.= '<?php '."\n";
$csscontent.= "header('Content-type: text/css');\n";
$csscontent.= "?>"."\n";
Expand All @@ -278,6 +284,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
setEventMessages('Failed to write file '.$filecss, null, 'errors');
}


if (! $error)
{
setEventMessages($langs->trans("Saved"), null, 'mesgs');
Expand Down Expand Up @@ -310,7 +317,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
dol_delete_file($fileindex);

$indexcontent = '<?php'."\n";
$indexcontent.= '// File generated to wrap the home page - DO NOT MODIFY - It is just an include'."\n";
$indexcontent.= '// File generated to provide a shortcut to the Home Page - DO NOT MODIFY - It is just an include.'."\n";
$indexcontent.= "include_once './".basename($filetpl)."'\n";
$indexcontent.= '?>'."\n";
$result = file_put_contents($fileindex, $indexcontent);
Expand Down Expand Up @@ -406,6 +413,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
$tplcontent.= '<?php require "./master.inc.php"; ?>'."\n";
$tplcontent.= '<html>'."\n";
$tplcontent.= '<header>'."\n";
$tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n";
$tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
$tplcontent.= '<meta name="robots" content="index, follow" />'."\n";
$tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=0.8">'."\n";
Expand All @@ -414,8 +422,10 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
$tplcontent.= '<meta name="title" content="'.dol_escape_htmltag($objectpage->title).'" />'."\n";
$tplcontent.= '<meta name="description" content="'.dol_escape_htmltag($objectpage->description).'" />'."\n";
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n";
$tplcontent.= '<!-- Include link to CSS file -->'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
$tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n";
$tplcontent.= '<!-- Include common page header file -->'."\n";
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/header.html"); ?>'."\n";
$tplcontent.= '</header>'."\n";

$tplcontent.= '<body>'."\n";
Expand Down Expand Up @@ -561,15 +571,18 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
$tplcontent.= "// END PHP ?>\n";
$tplcontent.= '<html>'."\n";
$tplcontent.= '<header>'."\n";
$tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n";
$tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
$tplcontent.= '<meta name="robots" content="index, follow" />'."\n";
$tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=0.8">'."\n";
$tplcontent.= '<meta name="keywords" content="'.join(', ', explode(',',$objectpage->keywords)).'" />'."\n";
$tplcontent.= '<meta name="title" content="'.dol_escape_htmltag($objectpage->title).'" />'."\n";
$tplcontent.= '<meta name="description" content="'.dol_escape_htmltag($objectpage->description).'" />'."\n";
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
$tplcontent.= '<title>'.dol_escape_htmltag($objectpage->title).'</title>'."\n";
$tplcontent.= '<!-- Include link to CSS file -->'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
$tplcontent.= '<!-- Include common page header file -->'."\n";
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/header.html"); ?>'."\n";
$tplcontent.= '</header>'."\n";

$tplcontent.= '<body>'."\n";
Expand Down Expand Up @@ -940,6 +953,11 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,

print '<br>';

$htmlheader = @file_get_contents($filehtmlheader);
// Clean the php css file to remove php code and get only html part
$htmlheader = preg_replace('/<!-- BEGIN DOLIBARR.*END -->/s', '', $htmlheader);


$csscontent = @file_get_contents($filecss);
// Clean the php css file to remove php code and get only css part
$csscontent = preg_replace('/<!-- BEGIN DOLIBARR.*END -->/s', '', $csscontent);
Expand All @@ -958,11 +976,19 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
print '<tr><td class="tdtop">';
print $langs->trans('WEBSITE_CSS_INLINE');
print '</td><td>';
print '<textarea class="flat centpercent" rows="32" name="WEBSITE_CSS_INLINE">';
print '<textarea class="flat centpercent" rows="20" name="WEBSITE_CSS_INLINE">';
print $csscontent;
print '</textarea>';
print '</td></tr>';

print '<tr><td class="tdtop">';
print $langs->trans('WEBSITE_HTML_HEADER');
print '</td><td>';
print '<textarea class="flat centpercent" rows="20" name="WEBSITE_HTML_HEADER">';
print $htmlheader;
print '</textarea>';
print '</td></tr>';

/*print '<tr><td>';
print $langs->trans('WEBSITE_CSS_URL');
print '</td><td>';
Expand Down

0 comments on commit be09c91

Please sign in to comment.