get('sites', "sitename", ["siteid" => getsiteid()]);
if ($echo) {
echo $title;
} else {
return $title;
}
}
/**
* Get the URL of the website.
* @param boolean $echo default true
* @return string
*/
function get_site_url($echo = true) {
$db = getdatabase();
$url = formatsiteurl($db->get('sites', "url", ["siteid" => getsiteid()]));
if ($echo) {
echo $url;
} else {
return $url;
}
}
/**
* Get the page title.
* @param boolean $echo default true
* @return string
*/
function get_page_title($echo = true) {
$db = getdatabase();
$title = $db->get("pages", "title", ["AND" => ["slug" => getpageslug(), "siteid" => getsiteid()]]);
if ($echo) {
echo $title;
} else {
return $title;
}
}
/**
* Get the page title stripped of any HTML.
* @param boolean $echo default true
* @return string
*/
function get_page_clean_title($echo = true) {
$title = strip_tags(get_page_title(false));
if ($echo) {
echo $title;
} else {
return $title;
}
}
/**
* Get the page slug for the current page.
* @param boolean $echo default true
* @return string
*/
function get_page_slug($echo = true) {
if ($echo) {
echo getpageslug();
} else {
return getpageslug();
}
}
/**
* Get a valid minimal URL for a page.
* @param boolean $echo default true
* @param string $slug page slug, or null for current
* @return string
*/
function get_page_clean_url($echo = true, $slug = null) {
if ($slug == null) {
$slug = get_page_slug(false);
}
if (PRETTY_URLS) {
$url = formatsiteurl(get_site_url(false)) . "$slug";
} else {
$url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug";
}
if ($echo) {
echo $url;
} else {
return $url;
}
}
/**
* Get a valid URL for a page.
* @param boolean $echo default true
* @param string $slug page slug, or null for current
* @return string
*/
function get_page_url($echo = true, $slug = null) {
if ($slug == null) {
$slug = get_page_slug(false);
}
$edit = "";
if (isset($_GET['edit'])) {
$edit = "&edit";
}
$theme = "";
if (isset($_GET['theme'])) {
$theme = "&theme=" . preg_replace("/[^A-Za-z0-9]/", '', $_GET['theme']);
}
$template = "";
if (isset($_GET['template'])) {
$template = "&template=" . preg_replace("/[^A-Za-z0-9]/", '', $_GET['template']);
}
$color = "";
if (isset($_GET['color'])) {
$color = "&color=" . preg_replace("/[^A-Za-z0-9]/", '', $_GET['color']);
}
$siteid = "";
if (isset($_GET['siteid'])) {
$siteid = "&siteid=" . preg_replace("/[^0-9]/", '', $_GET['siteid']);
}
$args = "$edit$theme$template$color$siteid";
if (PRETTY_URLS) {
if ($args != "") {
$args = "?$args";
}
$url = formatsiteurl(get_site_url(false)) . "$slug$args";
} else {
$url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug$args";
}
if ($echo) {
echo $url;
} else {
return $url;
}
}
/**
* Echoes or returns the content of a component.
* @param string $name component name
* @param string $context page slug, or null for current
* @param boolean $echo default true
* @param string $default The content to return if the component is empty
* @return string
*/
function get_component($name, $context = null, $echo = true, $default = "") {
$db = getdatabase();
if ($context == null) {
$context = get_page_slug(false);
}
$pageid = $db->get("pages", "pageid", ["AND" => ["slug" => $context, "siteid" => getsiteid()]]);
$content = "";
if ($db->has("components", ["AND" => ["pageid" => $pageid, "name" => $name]])) {
$content = $db->get("components", "content", ["AND" => ["pageid" => $pageid, "name" => $name]]);
}
if ($content == "") {
$content = $default;
}
if ($content == "" && isset($_GET['edit'])) {
$content = "
";
}
if ($echo) {
echo $content;
} else {
return $content;
}
}
/**
* Check if a component is empty of content.
* @param string $name component name
* @param string $context page slug, or null for current
* @return boolean
*/
function is_component_empty($name, $context = null) {
$comp = get_component($name, $context, false);
$comp = strip_tags($comp, "