Add format_special(), theme functions now always return the value regardless of $echo
This commit is contained in:
parent
dba9b96c55
commit
a296420e84
@ -18,9 +18,8 @@ function get_site_name($echo = true) {
|
||||
$title = $db->get('sites', "sitename", ["siteid" => getsiteid()]);
|
||||
if ($echo) {
|
||||
echo $title;
|
||||
} else {
|
||||
return $title;
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,9 +32,8 @@ function get_site_url($echo = true) {
|
||||
$url = formatsiteurl($db->get('sites', "url", ["siteid" => getsiteid()]));
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,9 +46,8 @@ function get_page_title($echo = true) {
|
||||
$title = $db->get("pages", "title", ["AND" => ["slug" => getpageslug(), "siteid" => getsiteid()]]);
|
||||
if ($echo) {
|
||||
echo $title;
|
||||
} else {
|
||||
return $title;
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,9 +59,8 @@ function get_page_clean_title($echo = true) {
|
||||
$title = strip_tags(get_page_title(false));
|
||||
if ($echo) {
|
||||
echo $title;
|
||||
} else {
|
||||
return $title;
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,9 +71,8 @@ function get_page_clean_title($echo = true) {
|
||||
function get_page_slug($echo = true) {
|
||||
if ($echo) {
|
||||
echo getpageslug();
|
||||
} else {
|
||||
return getpageslug();
|
||||
}
|
||||
return getpageslug();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,9 +92,8 @@ function get_page_clean_url($echo = true, $slug = null) {
|
||||
}
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,9 +137,8 @@ function get_page_url($echo = true, $slug = null) {
|
||||
}
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,9 +167,8 @@ function get_component($name, $context = null, $echo = true, $default = "") {
|
||||
}
|
||||
if ($echo) {
|
||||
echo $content;
|
||||
} else {
|
||||
return $content;
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,9 +262,8 @@ function get_escaped_json($json, $echo = true) {
|
||||
$text = htmlspecialchars(json_encode($json), ENT_QUOTES, 'UTF-8');
|
||||
if ($echo) {
|
||||
echo $text;
|
||||
} else {
|
||||
return $text;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,9 +281,8 @@ function get_url_or_slug($str, $echo = true) {
|
||||
}
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -316,9 +306,8 @@ function get_file_url($file, $echo = true) {
|
||||
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,9 +351,8 @@ function get_setting($key, $echo = false) {
|
||||
}
|
||||
if ($echo) {
|
||||
echo $value;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -382,9 +370,8 @@ function get_theme_url($echo = true) {
|
||||
}
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -407,9 +394,8 @@ function get_theme_color_url($echo = true) {
|
||||
$url = get_theme_url(false) . "/colors/" . $site["color"];
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -480,9 +466,8 @@ function get_fontawesome_js($echo = true) {
|
||||
$url = "assets/fontawesome-all.min.js";
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -494,9 +479,8 @@ function get_fontawesome_css($echo = true) {
|
||||
$url = "assets/css/fontawesome-all.min.css";
|
||||
if ($echo) {
|
||||
echo $url;
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -601,3 +585,64 @@ function get_socialmedia_urls() {
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
|
||||
define("SPECIAL_TYPE_NONE", 0);
|
||||
define("SPECIAL_TYPE_PHONE", 1);
|
||||
define("SPECIAL_TYPE_EMAIL", 2);
|
||||
define("SPECIAL_TYPE_LINEBREAKS", 3);
|
||||
define("SPECIAL_TYPE_ADDRESS", 4);
|
||||
/**
|
||||
* Take $text, format it according to $type,
|
||||
* replace [[CONTENT]] in $template with it,
|
||||
* and replace [[TITLE]] with $title (or the unchanged $text if $title is null)
|
||||
*
|
||||
* $type may be one of the following:
|
||||
* <ul>
|
||||
* <li>`SPECIAL_TYPE_PHONE`: `tel:1234567890`</li>
|
||||
* <li>`SPECIAL_TYPE_EMAIL`: `mailto:address@example.com`</li>
|
||||
* <li>`SPECIAL_TYPE_LINEBREAKS`: Replaces `\n` with `<br />\n`</li>
|
||||
* <li>`SPECIAL_TYPE_ADDRESS`: Creates a link to open Google Maps, and runs LINEBREAKS on $title</li>
|
||||
* <li>`SPECIAL_TYPE_NONE`: Does no text manipulation.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $type
|
||||
* @param string $template
|
||||
* @param string $title
|
||||
* @param boolean $echo default true
|
||||
* @param boolean $conditional Act as output_conditional() and not return anything if $text is empty
|
||||
* @return string
|
||||
*/
|
||||
function format_special($text, $type = SPECIAL_TYPE_NONE, $template = "", $title = null, $echo = true, $conditional = true) {
|
||||
if ($text == "") {
|
||||
return "";
|
||||
}
|
||||
if (is_null($title)) {
|
||||
$title = $text;
|
||||
}
|
||||
$val = "";
|
||||
switch ($type) {
|
||||
case SPECIAL_TYPE_PHONE:
|
||||
$val = "tel:" . preg_replace("/[^0-9+]/", "", $text);
|
||||
break;
|
||||
case SPECIAL_TYPE_EMAIL:
|
||||
$val = "mailto:" . $text;
|
||||
break;
|
||||
case SPECIAL_TYPE_LINEBREAKS:
|
||||
$val = str_replace("\n", "<br />\n", $text);
|
||||
break;
|
||||
case SPECIAL_TYPE_ADDRESS:
|
||||
$val = "https://www.google.com/maps/dir/?api=1&destination=" . urlencode(str_replace("\n", " ", $text));
|
||||
$title = str_replace("\n", "<br />\n", $title);
|
||||
break;
|
||||
default:
|
||||
$val = $text;
|
||||
break;
|
||||
}
|
||||
$out = str_replace("[[CONTENT]]", $val, $template);
|
||||
$out = str_replace("[[TITLE]]", $title, $out);
|
||||
if ($echo) {
|
||||
echo $out;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
@ -27,9 +27,9 @@
|
||||
<div class="col-12 col-md-6">
|
||||
<?php output_conditional("<h4>[[VAR]]</h4>", get_setting("businessname")); ?>
|
||||
<?php
|
||||
output_conditional('<div class="d-flex"><div class="mr-2"><i class="fas fa-phone fa-fw"></i></div> <div><a style="font-size: 130%; color: inherit;" href="tel:[[VAR]]">' . get_setting("phone") . '</a></div></div>', preg_replace("/[^0-9+]/", "", get_setting("phone")));
|
||||
output_conditional('<div class="d-flex"><div class="mr-2"><i class="fas fa-map fa-fw"></i></div> <div>[[VAR]]</div></div>', str_replace("\n", "<br />\n", get_setting("address")));
|
||||
output_conditional('<div class="d-flex"><div class="mr-2"><i class="fas fa-envelope fa-fw"></i></div> <div>[[VAR]]</div></div>', get_setting("email"));
|
||||
format_special(get_setting("phone"), SPECIAL_TYPE_PHONE, '<div class="d-flex"><div class="mr-2"><i class="fas fa-phone fa-fw"></i></div> <div><a style="font-size: 130%; color: inherit;" href="[[CONTENT]]">[[TITLE]]</a></div></div>');
|
||||
format_special(get_setting("address"), SPECIAL_TYPE_ADDRESS, '<div class="d-flex"><div class="mr-2"><i class="fas fa-map fa-fw"></i></div> <div><a href="[[CONTENT]]">[[TITLE]]</a></div></div>');
|
||||
format_special(get_setting("email"), SPECIAL_TYPE_EMAIL, '<div class="d-flex"><div class="mr-2"><i class="fas fa-envelope fa-fw"></i></div> <div><a href="[[CONTENT]]">[[TITLE]]</a></div></div>');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -183,9 +183,9 @@ include __DIR__ . "/inc/head.inc.php";
|
||||
<section>
|
||||
<ul class="contact">
|
||||
<?php
|
||||
output_conditional('<li><h3>Address</h3> <span>[[VAR]]</span></li>', str_replace("\n", "<br />\n", get_setting("address")));
|
||||
output_conditional('<li><h3>Email</h3> <a href="mailto:[[VAR]]">[[VAR]]</a></li>', get_setting("email"));
|
||||
output_conditional('<li><h3>Phone</h3> <a href="tel:[[VAR]]">' . get_setting("phone") . '</a></li>', preg_replace("/[^0-9+]/", "", get_setting("phone")));
|
||||
format_special(get_setting("address"), SPECIAL_TYPE_ADDRESS, '<li><h3>Address</h3> <a href="[[CONTENT]]">[[TITLE]]</a></li>');
|
||||
format_special(get_setting("email"), SPECIAL_TYPE_EMAIL, '<li><h3>Email</h3> <a href="[[CONTENT]]">[[TITLE]]</a></li>');
|
||||
format_special(get_setting("phone"), SPECIAL_TYPE_PHONE, '<li><h3>Phone</h3> <a href="[[CONTENT]]">[[TITLE]]</a></li>');
|
||||
?>
|
||||
<?php
|
||||
$social = get_socialmedia_urls();
|
||||
|
@ -21,9 +21,9 @@
|
||||
</section>
|
||||
<section class="split contact">
|
||||
<?php
|
||||
output_conditional('<section class="alt"><h3>Address</h3> <p>[[VAR]]</p></section>', str_replace("\n", "<br />\n", get_setting("address")));
|
||||
output_conditional('<section><h3>Email</h3> <p><a href="mailto:[[VAR]]">[[VAR]]</a></p></section>', get_setting("email"));
|
||||
output_conditional('<section><h3>Phone</h3> <p><a href="tel:[[VAR]]">' . get_setting("phone") . '</a></p></section>', preg_replace("/[^0-9+]/", "", get_setting("phone")));
|
||||
format_special(get_setting("address"), SPECIAL_TYPE_ADDRESS, '<section class="alt"><h3>Address</h3> <p><a href="[[CONTENT]]">[[TITLE]]</a></p></section>');
|
||||
format_special(get_setting("email"), SPECIAL_TYPE_EMAIL, '<section><h3>Email</h3> <p><a href="[[CONTENT]]">[[TITLE]]</a></p></section>');
|
||||
format_special(get_setting("phone"), SPECIAL_TYPE_PHONE, '<section><h3>Phone</h3> <p><a href="[[CONTENT]]">[[TITLE]]</a></p></section>');
|
||||
?>
|
||||
|
||||
<section>
|
||||
|
@ -8,9 +8,11 @@
|
||||
<section class="widget contact">
|
||||
<?php output_conditional("<h3>[[VAR]]</h3>", get_setting("businessname")); ?>
|
||||
<p>
|
||||
<?php output_conditional('<div style="display: flex;"><div style="margin-right: 10px;"><i class="fas fa-phone fa-fw"></i></div> <div style="font-size: 130%;"><a href="tel:[[VAR]]">' . get_setting("phone") . '</a></div></div>', preg_replace("/[^0-9+]/", "", get_setting("phone"))); ?>
|
||||
<?php output_conditional('<div style="display: flex;"><div style="margin-right: 10px;"><i class="fas fa-map fa-fw"></i></div> <div>[[VAR]]</div></div>', str_replace("\n", "<br />\n", get_setting("address"))); ?>
|
||||
<?php output_conditional('<div style="display: flex;"><div style="margin-right: 10px;"><i class="fas fa-envelope fa-fw"></i></div> <div>[[VAR]]</div></div>', get_setting("email")); ?>
|
||||
<?php
|
||||
format_special(get_setting("phone"), SPECIAL_TYPE_PHONE, '<div style="display: flex;"><div style="margin-right: 10px;"><i class="fas fa-phone fa-fw"></i></div> <div style="font-size: 130%;"><a href="[[CONTENT]]">[[TITLE]]</a></div></div>');
|
||||
format_special(get_setting("address"), SPECIAL_TYPE_ADDRESS, '<div style="display: flex;"><div style="margin-right: 10px;"><i class="fas fa-map fa-fw"></i></div> <div><a href="[[CONTENT]]">[[TITLE]]</a></div></div>');
|
||||
format_special(get_setting("email"), SPECIAL_TYPE_EMAIL, '<div style="display: flex;"><div style="margin-right: 10px;"><i class="fas fa-envelope fa-fw"></i></div> <div><a href="[[CONTENT]]">[[TITLE]]</a></div></div>');
|
||||
?>
|
||||
</p>
|
||||
<ul>
|
||||
<?php
|
||||
|
Loading…
x
Reference in New Issue
Block a user