CMS
Version 3.9
site.inc
Go to the documentation of this file.
1
<?php
7
/**************************************************************
8
9
Copyright (c) 2010 Sonjara, Inc
10
11
Permission is hereby granted, free of charge, to any person
12
obtaining a copy of this software and associated documentation
13
files (the "Software"), to deal in the Software without
14
restriction, including without limitation the rights to use,
15
copy, modify, merge, publish, distribute, sublicense, and/or sell
16
copies of the Software, and to permit persons to whom the
17
Software is furnished to do so, subject to the following
18
conditions:
19
20
The above copyright notice and this permission notice shall be
21
included in all copies or substantial portions of the Software.
22
23
Except as contained in this notice, the name(s) of the above
24
copyright holders shall not be used in advertising or otherwise
25
to promote the sale, use or other dealings in this Software
26
without prior written authorization.
27
28
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35
OTHER DEALINGS IN THE SOFTWARE.
36
37
*****************************************************************/
38
39
class
Site
extends
DataItem
40
{
41
private
static
$currentSite =
null
;
42
43
// Fields
44
var
$fields
= array(
"site_id"
=> Number,
45
"site_name"
=> String,
46
"domain"
=> String,
47
"home_page"
=> String,
48
"description"
=> Text,
49
"meta_tag_description"
=> Text,
50
"meta_tag_keyword"
=> String,
51
"theme"
=> String,
52
"default_template"
=> String,
53
"print_template"
=> String,
54
"popup_template"
=> String,
55
"mobile_template"
=> String,
56
"enabled"
=> Boolean,
57
"default_site"
=> Boolean);
58
59
// Relations
60
61
var
$relations
= array(
"Pages"
=>
Page
,
62
"Articles"
=>
Article
,
63
"Events"
=>
Event
,
64
"Fora"
=>
Forum
,
65
"ForumSummaries"
=>
ForumSummary
,
66
"Sections"
=>
Section
);
67
68
function
Pages
(
$constraint
=
""
)
69
{
70
return
$this->getRelatedList(
Page
,
""
,
$constraint
);
71
}
72
73
function
Articles
(
$constraint
=
""
)
74
{
75
return
$this->crossReference(
Article
,
ArticleSiteXref
,
$constraint
);
76
}
77
78
function
Events
(
$constraint
=
""
)
79
{
80
return
$this->crossReference(
Event
,
EventSiteXref
,
$constraint
);
81
}
82
83
function
Fora
(
$constraint
=
""
)
84
{
85
return
$this->crossReference(
Forum
,
ForumSiteXref
,
$constraint
);
86
}
87
88
function
ForumSummaries
(
$constraint
=
""
)
89
{
90
return
$this->crossReference(
ForumSummary
,
ForumSiteXref
,
$constraint
);
91
}
92
93
function
Sections
(
$constraint
=
""
)
94
{
95
return
$this->getRelatedList(
Section
,
""
,
$constraint
);
96
}
97
103
static
function
getSite
()
104
{
105
global
$config
;
106
107
if
(Site::$currentSite)
108
{
109
return
Site::$currentSite;
110
}
111
112
$domain = $_SERVER[
'HTTP_HOST'
];
113
trace(
"Accessed via domain: $domain"
, 3);
114
115
$sites
= Query::create(
Site
,
"WHERE domain=:d and enabled=1 ORDER BY default_site DESC"
)
116
->bind(
":d"
, $domain)
117
->execute();
118
if
(count(
$sites
) > 0)
119
{
120
trace(
"Matching Site record found"
, 3);
121
Site::$currentSite =
$sites
[0];
122
123
// Store in $config
124
$config
[
'http_host'
] =
$sites
[0]->domain;
125
126
return
Site::$currentSite;
127
}
128
129
$sites
= Query::create(
Site
,
"WHERE enabled=1 ORDER BY default_site DESC, site_name ASC"
)->execute();
130
131
if
(count(
$sites
) > 0)
132
{
133
Site::$currentSite =
$sites
[0];
134
trace(
"Using default Site record with domain "
.Site::$currentSite->domain, 3);
135
return
Site::$currentSite;
136
}
137
138
throw
new
FakoliException
(
"No site defined"
);
139
}
140
141
static
function
getSites
()
142
{
143
return
Query::create(
Site
,
"ORDER BY site_name"
)->execute();
144
}
145
146
function
getThemeDirectory
()
147
{
148
return
SiteManager::getThemeDirectory
($this->theme);
149
}
150
151
// Constructor
152
function
Site
()
153
{
154
$this->primary_key =
"site_id"
;
155
$this->table =
"site"
;
156
157
$this->default_format =
"{site_name}"
;
158
$this->DataItem(func_get_args());
159
}
160
}
161
162
?>
$constraint
$constraint
Definition:
activity_report.inc:13
Article
Defines the Article class.
Definition:
article.inc:45
ArticleSiteXref
Definition:
article.inc:309
Event
Defines the Event class.
Definition:
event.inc:43
EventSiteXref
Definition:
event.inc:134
FakoliException
FakoliException is the base exception class for all Fakoli errors.
Definition:
core.inc:53
Forum
Definition:
forum.inc:42
ForumSiteXref
Definition:
forum.inc:141
ForumSummary
Definition:
forum.inc:308
Page
Definition:
page.inc:43
Section
Section DataItem, defining the data model for sections within a site.
Definition:
section.inc:45
Site
Definition:
site.inc:40
Site\ForumSummaries
ForumSummaries($constraint="")
Definition:
site.inc:88
Site\$relations
$relations
Definition:
site.inc:61
Site\Fora
Fora($constraint="")
Definition:
site.inc:83
Site\getThemeDirectory
getThemeDirectory()
Definition:
site.inc:146
Site\getSite
static getSite()
Returns the Site object that describes the currently active site (i.e.
Definition:
site.inc:103
Site\Articles
Articles($constraint="")
Definition:
site.inc:73
Site\Site
Site()
Definition:
site.inc:152
Site\Events
Events($constraint="")
Definition:
site.inc:78
Site\Pages
Pages($constraint="")
Definition:
site.inc:68
Site\$fields
$fields
Definition:
site.inc:44
Site\Sections
Sections($constraint="")
Definition:
site.inc:93
Site\getSites
static getSites()
Definition:
site.inc:141
SiteManager\getThemeDirectory
static getThemeDirectory($theme="")
Definition:
site_manager.inc:78
$sites
$sites
Definition:
event_edit.inc:83
$config
global $config
Definition:
import.inc:4
code
cms.sonjara.com
cms
components
site
datamodel
site.inc
Generated on Tue Mar 23 2021 15:36:14 for CMS by
1.9.1