2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 2000-2009 WS Interactive |
7
// +----------------------------------------------------------------------+
8
// | Automne is subject to version 2.0 or above of the GPL license. |
9
// | The license text is bundled with this package in the file |
10
// | LICENSE-GPL, and is available through the world-wide-web at |
11
// | http://www.gnu.org/copyleft/gpl.html. |
12
// +----------------------------------------------------------------------+
13
// | Author: Antoine Pouch <antoine.pouch@ws-interactive.fr> & |
14
// | Author: S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr> |
15
// +----------------------------------------------------------------------+
17
// $Id: website.php,v 1.1.1.1 2008/11/26 17:12:06 sebastien Exp $
22
* represent a website placed on a page in the tree structure. A websites defines mainly a directory
23
* where the pages files will be placed.
24
* Beware ! Because of the label-to-directory relationship, label should'nt be changeable after the website creation.
25
* This condition is enforced here.
29
* @author Antoine Pouch <antoine.pouch@ws-interactive.fr>
32
class CMS_website extends CMS_grandFather
42
* Label of the website
49
* URL of the website (does NOT start with http://)
63
* Is this website the main website ?
67
protected $_isMain = false;
77
* Default Meta values for website
81
protected $_meta = array(
95
* initializes the website if the id is given.
97
* @param integer $id DB id
101
function __construct($id = 0)
103
static $applicationWebroot;
105
if (($id == 1 && !is_object($applicationWebroot)) || $id != 1) {
106
if (!SensitiveIO::isPositiveInteger($id)) {
107
$this->raiseError("Id is not a positive integer");
118
$q = new CMS_query($sql);
119
if ($q->getNumRows()) {
120
$data = $q->getArray();
122
$this->_label = $data["label_web"];
123
$this->_url = $data["url_web"];
124
$this->_root = new CMS_page($data["root_web"]);
125
$this->_order = $data["order_web"];
126
//the main website has The main page (ID 1) as root
127
if ($data["root_web"] == APPLICATION_ROOT_PAGE_ID) {
128
$this->_isMain = true;
130
$this->_meta['keywords'] = $data["keywords_web"];
131
$this->_meta['description'] = $data["description_web"];
132
$this->_meta['category'] = $data["category_web"];
133
$this->_meta['author'] = $data["author_web"];
134
$this->_meta['replyto'] = $data["replyto_web"];
135
$this->_meta['copyright'] = $data["copyright_web"];
136
$this->_meta['language'] = $data["language_web"];
137
$this->_meta['robots'] = $data["robots_web"];
138
$this->_meta['favicon'] = $data["favicon_web"];
140
$this->raiseError("Unknown ID :".$id);
143
$applicationWebroot = $this;
147
$this->_label = $applicationWebroot->_label;
148
$this->_url = $applicationWebroot->_url;
149
$this->_root = $applicationWebroot->_root;
150
$this->_order = $applicationWebroot->_order;
151
$this->_isMain = $applicationWebroot->_isMain;
152
$this->_meta = $applicationWebroot->_meta;
158
* Gets the DB ID of the instance.
160
* @return integer the DB id
169
* Get a website meta value
171
* @param string $meta The meta name to get
172
* @return string the website meta value
175
function getMeta($meta) {
176
if (!isset($this->_meta[$meta])) {
177
$this->raiseError("Unknown meta to get : ".$meta);
180
return $this->_meta[$meta];
184
* Set a website meta value
186
* @param string $meta The meta name to set
187
* @param string $value The meta value to get
188
* @return boolean true on success, false on failure
191
function setMeta($meta, $value) {
192
if (!isset($this->_meta[$meta])) {
193
$this->raiseError("Unknown meta to set : ".$meta);
196
$this->_meta[$meta] = $value;
201
* Is this the main website ?
208
return $this->_isMain;
214
* @return string The label
219
return $this->_label;
225
* @param string $label The label to set
226
* @return boolean true on success, false on failure.
229
function setLabel($label)
231
//label should'nt be changed once set
233
$this->raiseError("Trying to change the label of a website already existing");
237
$old_label = $this->_label;
238
$this->_label = $label;
240
//now test to see if a directory already exists with that name (Because label must _not_ be moveable once set)
241
if (!$this->_isMain && is_dir($this->getPagesPath(PATH_RELATIVETO_FILESYSTEM))) {
242
$this->_label = $old_label;
243
$this->raiseError("Label to set has same directory for pages than a previously set one.");
249
$this->raiseError("Label can't be empty");
255
* Gets the url (including http://).
257
* @return string the URL
260
function getURL($includeHTTP = true)
263
return (substr($this->_url,0,4) != 'http') ? "http://".$this->_url : $this->_url;
265
return (substr($this->_url,0,4) != 'http') ? $this->_url : substr($this->_url,7);
270
* Sets the url. Can be empty. Will be riden of http://.
272
* @param string $url The url to set
273
* @return boolean true on success, false on failure.
276
function setURL($url)
278
if (substr($url, 0, 7) == "http://") {
279
$url = substr($url, 7);
282
if (substr($url, strlen($url) - 1) == "/") {
283
$url = substr($url, 0, -1);
293
* Gets the root page.
295
* @return CMS_page The Root page
304
* Sets the root page.
306
* @param CMS_page $page The new root page to set.
307
* @return boolean true on success, false on failure
310
function setRoot($page)
312
if (is_a($page, "CMS_page")) {
313
$ws = CMS_tree::getPageWebsite($page);
314
if ($ws->getRoot() == $page && $ws->getID() != $this->_id) {
315
$this->raiseError("Root page to set is already a root page for the website : ".$ws->getLabel());
318
$this->_root = $page;
322
$this->raiseError("Root page to set is not a page");
328
* Gets the pages directory. It's derived from the label
330
* @param string $relativeTo Can be PATH_RELATIVETO_WEBROOT for relative to website root, or PATH_RELATIVETO_FILESYSTEM for relative to filesystem root
331
* @return string The pages directory.
334
function getPagesPath($relativeTo)
337
if (SensitiveIO::isInSet($relativeTo, array(PATH_RELATIVETO_WEBROOT, PATH_RELATIVETO_FILESYSTEM))) {
338
$relative = ($relativeTo == PATH_RELATIVETO_WEBROOT) ? PATH_PAGES_WR : PATH_PAGES_FS;
339
if ($this->_isMain) {
342
return $relative."/".SensitiveIO::sanitizeAsciiString($this->_label);
345
$this->raiseError("Can't give pages path relative to anything other than WR or FS");
354
* Gets the pages directory. It's derived from the label
356
* @param string $relativeTo Can be PATH_RELATIVETO_WEBROOT for relative to website root, or PATH_RELATIVETO_FILESYSTEM for relative to filesystem root
357
* @return string The pages directory.
360
function getHTMLPagesPath($relativeTo)
363
if (SensitiveIO::isInSet($relativeTo, array(PATH_RELATIVETO_WEBROOT, PATH_RELATIVETO_FILESYSTEM))) {
364
$relative = ($relativeTo == PATH_RELATIVETO_WEBROOT) ? PATH_PAGES_HTML_WR : PATH_PAGES_HTML_FS;
365
if ($this->_isMain) {
368
return $relative."/".SensitiveIO::sanitizeAsciiString($this->_label);
371
$this->raiseError("Can't give pages path relative to anything other than WR or FS");
380
* Totally destroys the website, including its directory
381
* After deletion from database, launch a regen of the whole tree.
394
id_web='".$this->_id."'
396
$q = new CMS_query($sql);
398
//deletes the pages and html directory (with all the pages inside)
399
if (!$this->_isMain) {
400
$dir = $this->getPagesPath(PATH_RELATIVETO_FILESYSTEM);
401
if ($opendir = @opendir($dir)) {
402
while (false !== ($readdir = readdir($opendir))) {
403
if($readdir !== '..' && $readdir !== '.') {
404
$readdir = trim($readdir);
405
if (is_file($dir.'/'.$readdir)) {
406
@unlink($dir.'/'.$readdir);
413
$dir = $this->getHTMLPagesPath(PATH_RELATIVETO_FILESYSTEM);
414
if ($opendir = @opendir($dir)) {
415
while (false !== ($readdir = readdir($opendir))) {
416
if($readdir !== '..' && $readdir !== '.') {
417
$readdir = trim($readdir);
418
if (is_file($dir.'/'.$readdir)) {
419
@unlink($dir.'/'.$readdir);
428
//regenerates all the pages
429
CMS_tree::regenerateAllPages(true);
435
* Writes the website into persistence (MySQL for now).
437
* @return boolean true on success, false on failure
440
function writeToPersistence()
442
if (!sensitiveIO::isPositiveInteger($this->_order)) {
446
max(order_web) as order_max
450
$q = new CMS_query($sql);
451
if ($q->hasError() || !$q->getNumRows()) {
452
CMS_grandFather::raiseError('Error to get max order from websites table ... ');
455
$this->_order = ($q->getValue('order_max')+1) ;
458
label_web='".SensitiveIO::sanitizeSQLString($this->_label)."',
459
url_web='".SensitiveIO::sanitizeSQLString($this->_url)."',
460
root_web='".$this->_root->getID()."',
461
keywords_web='".SensitiveIO::sanitizeSQLString($this->_meta['keywords'])."',
462
description_web='".SensitiveIO::sanitizeSQLString($this->_meta['description'])."',
463
category_web='".SensitiveIO::sanitizeSQLString($this->_meta['category'])."',
464
author_web='".SensitiveIO::sanitizeSQLString($this->_meta['author'])."',
465
replyto_web='".SensitiveIO::sanitizeSQLString($this->_meta['replyto'])."',
466
copyright_web='".SensitiveIO::sanitizeSQLString($this->_meta['copyright'])."',
467
language_web='".SensitiveIO::sanitizeSQLString($this->_meta['language'])."',
468
robots_web='".SensitiveIO::sanitizeSQLString($this->_meta['robots'])."',
469
favicon_web='".SensitiveIO::sanitizeSQLString($this->_meta['favicon'])."',
470
order_web='".SensitiveIO::sanitizeSQLString($this->_order)."'
479
id_web='".$this->_id."'
488
$q = new CMS_query($sql);
489
if ($q->hasError()) {
491
} elseif (!$this->_id) {
492
$this->_id = $q->getLastInsertedID();
494
//create the page directory
495
if (!is_dir($this->getPagesPath(PATH_RELATIVETO_FILESYSTEM))) {
496
@mkdir($this->getPagesPath(PATH_RELATIVETO_FILESYSTEM));
497
@chmod($this->getPagesPath(PATH_RELATIVETO_FILESYSTEM), octdec(DIRS_CHMOD));
499
if (!is_dir($this->getHTMLPagesPath(PATH_RELATIVETO_FILESYSTEM))) {
500
//create the html directory
501
@mkdir($this->getHTMLPagesPath(PATH_RELATIVETO_FILESYSTEM));
502
@chmod($this->getHTMLPagesPath(PATH_RELATIVETO_FILESYSTEM), octdec(DIRS_CHMOD));
b'\\ No newline at end of file'