+*/
+
+// make sure the PATH_SEPARATOR is defined
+ umask(2);
+ if (!defined("PATH_SEPARATOR")) {
+ if (strpos($_ENV["OS"], "Win") !== false) {
+ define("PATH_SEPARATOR", ";");
+ } else {
+ define("PATH_SEPARATOR", ":");
+ }
+ }
+
+ if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html';
+
+ // make sure the document_root is set
+ $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]);
+ if(PHP_SAPI == 'cli'){
+ chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME));
+ $script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]);
+ $dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME));
+ if (file_exists('/project_root.php')) {
+ $path = '/';
+ } else {
+ $i = 1;
+ $path = '';
+ while ($i < count($dirs)) {
+ $path .= '/' . $dirs[$i];
+ if (file_exists($path. '/project_root.php')) {
+ break;
+ }
+ $i++;
+ }
+ }
+ $_SERVER["DOCUMENT_ROOT"] = $path;
+ }else{
+ $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
+ }
+ $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
+// try to detect if a project path is being used
+ if (!defined('PROJECT_PATH')) {
+ if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) {
+ define('PROJECT_PATH', '/fusionpbx');
+ } elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) {
+ define('PROJECT_PATH', '');
+ } else {
+ $dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME)));
+ $i = 1;
+ $path = $_SERVER["DOCUMENT_ROOT"];
+ while ($i < count($dirs)) {
+ $path .= '/' . $dirs[$i];
+ if (file_exists($path. '/project_root.php')) {
+ break;
+ }
+ $i++;
+ }
+ if(!file_exists($path. '/project_root.php')){
+ die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance");
+ }
+ $project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path);
+ define('PROJECT_PATH', $project_path);
+ }
+ $_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH);
+ set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]);
+ }
+
+?>
\ No newline at end of file
diff --git a/resources/fonts/web_font_loader.php b/resources/fonts/web_font_loader.php
new file mode 100644
index 0000000000..39a3e9cdbc
--- /dev/null
+++ b/resources/fonts/web_font_loader.php
@@ -0,0 +1,106 @@
+ 0) {
+ foreach ($_SESSION['theme'] as $subcategory => $type) {
+ if (substr_count($subcategory, '_font') > 0) {
+ $font_string = $type['text'];
+ if ($font_string != '') {
+ if (substr_count($font_string, ',') > 0) {
+ $tmp_array = explode(',', $font_string);
+ }
+ else {
+ $tmp_array[] = $font_string;
+ }
+ foreach ($tmp_array as $font_name) {
+ $font_name = trim($font_name, "'");
+ $font_name = trim($font_name, '"');
+ $font_name = trim($font_name);
+ $fonts[] = $font_name;
+ }
+ }
+ }
+ unset($fonts, $tmp_array);
+ }
+ }
+ //optimize fonts array
+ $fonts = array_unique($fonts);
+ $common_fonts = 'arial,arial black,arial narrow,calibri,'.
+ 'candara,apple gothic,geneva,tahoma,microsoft sans serif,'.
+ 'lucidia,lucidia console,monaco,lucidia sans unicode,'.
+ 'lucidiagrande,consolas,menlo,trebuchet,trebuchet ms,'.
+ 'helvetica,times,times new roman,courier,courier new,'.
+ 'impact,comic sans,comic sans ms,georgia,palatino,'.
+ 'palatino linotype,verdana,franklin gothic,'.
+ 'franklin gothic medium,gill sans,gill sans mt,'.
+ 'brush script,corbel';
+ $common_fonts = array(explode(',', $common_fonts));
+ foreach ($fonts as $index => $font) {
+ if (in_array(strtolower($font), $common_fonts)) {
+ unset($fonts[$index]);
+ }
+ }
+ //load fonts
+ if (is_array($fonts) && sizeof($fonts) > 0) {
+ if ($_SESSION['theme']['font_retrieval']['text'] == 'asynchronous') {
+ ?>
+ WebFontConfig = {
+ google: {
+ families: ['']
+ }
+ };
+ (function(d) {
+ var wf = d.createElement('script'), s = d.scripts[0];
+ wf.src = '//ajax.googleapis.com/ajax/libs/webfont//webfont.js';
+ s.parentNode.insertBefore(wf, s);
+ })(document);
+
+ WebFont.load({
+ google: {
+ families: ['']
+ }
+ });
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/functions.php b/resources/functions.php
index 8816a36bb1..46d2deeb2f 100644
--- a/resources/functions.php
+++ b/resources/functions.php
@@ -1776,4 +1776,136 @@ function number_pad($number,$n) {
//$string = "2089068227)$"; echo $string." ".string_to_regex($string)."\n";
}
+//dynamically load available web fonts
+ if (!function_exists('get_available_fonts')) {
+ function get_available_fonts($sort = 'alpha') {
+ if ($_SESSION['theme']['font_source_key']['text'] != '') {
+ if (!is_array($_SESSION['fonts_available']) || sizeof($_SESSION['fonts_available']) == 0) {
+ /*
+ sort options:
+ alpha - alphabetically
+ date - by date added (most recent font added or updated first)
+ popularity - by popularity (most popular family first)
+ style - by number of styles available (family with most styles first)
+ trending - by families seeing growth in usage (family seeing the most growth first)
+ */
+ $google_api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key='.$_SESSION['theme']['font_source_key']['text'].'&sort='.$sort;
+ $response = file_get_contents($google_api_url);
+ if ($response != '') {
+ $data = json_decode($response, true);
+ $items = $data['items'];
+ foreach ($items as $item) {
+ $fonts[] = $item['family'];
+ }
+ //echo "".print_r($font_list, true)."
";
+ }
+ $_SESSION['fonts_available'] = $fonts;
+ unset($fonts);
+ }
+ return (is_array($_SESSION['fonts_available']) && sizeof($_SESSION['fonts_available']) > 0) ? $_SESSION['fonts_available'] : array();
+ }
+ else {
+ return false;
+ }
+ }
+ }
+
+//dynamically import web fonts (by reading static css file)
+ if (!function_exists('import_fonts')) {
+ function import_fonts($file_to_parse, $line_styles_begin = null) {
+ /*
+ This function reads the contents of $file_to_parse, beginning at $line_styles_begin (if set),
+ and attempts to parse the specified google fonts used. The assumption is that each curly brace
+ will be on its own line, each CSS style (attribute: value;) will be on its own line, a single
+ Google Fonts name will be used per selector, and that it will be surrounded by SINGLE quotes,
+ as shown in the example below:
+
+ .class_name {
+ font-family: 'Google Font';
+ font-weight: 300;
+ font-style: italic;
+ }
+
+ If the CSS styles are formatted as described, the necessary @import string should be generated
+ correctly.
+ */
+
+ $file = file_get_contents($_SERVER["DOCUMENT_ROOT"].$file_to_parse);
+ $lines = explode("\n", $file);
+
+ $style_counter = 0;
+ foreach ($lines as $line_number => $line) {
+ if ($line_styles_begin != '' && $line_number < $line_styles_begin - 1) { continue; }
+ if (substr_count($line, "{") > 0) {
+ $style_lines[$style_counter]['begins'] = $line_number;
+ }
+ if (substr_count($line, "}") > 0) {
+ $style_lines[$style_counter]['ends'] = $line_number;
+ $style_counter++;
+ }
+ }
+ //echo "\n\n".print_r($style_lines, true)."\n\n";
+
+ if (is_array($style_lines) && sizeof($style_lines) > 0) {
+
+ foreach ($style_lines as $index => $style_line) {
+ for ($l = $style_line['begins']+1; $l < $style_line['ends']; $l++) {
+ $tmp[] = $lines[$l];
+ }
+ $style_groups[] = $tmp;
+ unset($tmp);
+ }
+ //echo "\n\n".print_r($style_groups, true)."\n\n";
+
+ if (is_array($style_groups) && sizeof($style_groups) > 0) {
+
+ foreach ($style_groups as $style_group_index => $style_group) {
+ foreach ($style_group as $style_index => $style) {
+ $tmp = explode(':', $style);
+ $attribute = trim($tmp[0]);
+ $value = trim(trim($tmp[1]),';');
+ $style_array[$attribute] = $value;
+ }
+ $style_groups[$style_group_index] = $style_array;
+ unset($style_array);
+ }
+ //echo "\n\n".print_r($style_groups, true)."\n\n";
+
+ foreach ($style_groups as $style_group_index => $style_group) {
+ $style_value = $style_group['font-family'];
+ if (substr_count($style_value, "'") > 0) {
+ //determine font
+ $font_begin = strpos($style_value, "'")+1;
+ $font_end = strpos($style_value, "'", $font_begin);
+ $font_name = substr($style_value, $font_begin, $font_end - $font_begin);
+ //determine modifiers
+ $weight = (is_numeric($style_group['font-weight']) || strtolower($style_group['font-weight']) == 'bold') ? strtolower($style_group['font-weight']) : null;
+ $italic = (strtolower($style_group['font-style']) == 'italic') ? 'italic' : null;
+ //add font to array
+ $fonts[$font_name][] = $weight.$italic;
+ }
+ }
+ //echo "\n\n/*".print_r($fonts, true)."*/\n\n";
+
+ if (is_array($fonts)) {
+ foreach ($fonts as $font_name => $modifiers) {
+ $modifiers = array_unique($modifiers);
+ $import_font_string = str_replace(' ', '+', $font_name);
+ if (is_array($modifiers) && sizeof($modifiers) > 0) {
+ $import_font_string .= ':'.implode(',', $modifiers);
+ }
+ $import_fonts[] = $import_font_string;
+ }
+ //echo "\n\n/*".print_r($import_fonts, true)."*/\n\n";
+ $import_string = "@import url(//fonts.googleapis.com/css?family=".implode('|', $import_fonts).");";
+ echo $import_string."\n";
+ }
+
+ }
+
+ }
+
+ }
+ }
+
?>
\ No newline at end of file
diff --git a/themes/default/app_defaults.php b/themes/default/app_defaults.php
index 5a2efb30d3..b124bab81e 100644
--- a/themes/default/app_defaults.php
+++ b/themes/default/app_defaults.php
@@ -591,7 +591,7 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_category'] = 'theme';
$array[$x]['default_setting_subcategory'] = 'dashboard_heading_text_font';
$array[$x]['default_setting_name'] = 'text';
- $array[$x]['default_setting_value'] = 'Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif';
+ $array[$x]['default_setting_value'] = "Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif";
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_description'] = 'Set the font of the Dashboard block heading text.';
$x++;
@@ -647,7 +647,7 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_category'] = 'theme';
$array[$x]['default_setting_subcategory'] = 'dashboard_number_text_font';
$array[$x]['default_setting_name'] = 'text';
- $array[$x]['default_setting_value'] = 'Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif';
+ $array[$x]['default_setting_value'] = "Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif";
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_description'] = 'Set the font of the Dashboard block number.';
$x++;
@@ -682,7 +682,7 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_category'] = 'theme';
$array[$x]['default_setting_subcategory'] = 'dashboard_number_title_text_font';
$array[$x]['default_setting_name'] = 'text';
- $array[$x]['default_setting_value'] = 'Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif';
+ $array[$x]['default_setting_value'] = "Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif";
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_description'] = 'Set the font of the Dashboard block number title.';
$x++;
@@ -1079,7 +1079,7 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_category'] = 'theme';
$array[$x]['default_setting_subcategory'] = 'button_text_font';
$array[$x]['default_setting_name'] = 'text';
- $array[$x]['default_setting_value'] = 'Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif';
+ $array[$x]['default_setting_value'] = "Candara, Calibri, Segoe, 'Segoe UI', Optima, Arial, sans-serif";
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_description'] = 'Set the font of button text.';
$x++;
@@ -1316,6 +1316,35 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_description'] = 'Set the color (and opacity) of input placeholder text on the login box.';
$x++;
+ $array[$x]['default_setting_category'] = 'theme';
+ $array[$x]['default_setting_subcategory'] = 'font_loader';
+ $array[$x]['default_setting_name'] = 'text';
+ $array[$x]['default_setting_value'] = 'true';
+ $array[$x]['default_setting_enabled'] = 'false';
+ $array[$x]['default_setting_description'] = 'Enables the dynamic loading of web fonts (requires an Internet connection).';
+ $x++;
+ $array[$x]['default_setting_category'] = 'theme';
+ $array[$x]['default_setting_subcategory'] = 'font_loader_version';
+ $array[$x]['default_setting_name'] = 'text';
+ $array[$x]['default_setting_value'] = '1.6.16';
+ $array[$x]['default_setting_enabled'] = 'false';
+ $array[$x]['default_setting_description'] = "Set the web font loader version to use - specific (e.g. '1.6.16') or latest in branch (e.g. '1').";
+ $x++;
+ $array[$x]['default_setting_category'] = 'theme';
+ $array[$x]['default_setting_subcategory'] = 'font_retrieval';
+ $array[$x]['default_setting_name'] = 'text';
+ $array[$x]['default_setting_value'] = 'asynchronous';
+ $array[$x]['default_setting_enabled'] = 'false';
+ $array[$x]['default_setting_description'] = 'Set the retrieval method for the web font loader (default: synchronous).';
+ $x++;
+ $array[$x]['default_setting_category'] = 'theme';
+ $array[$x]['default_setting_subcategory'] = 'font_source_key';
+ $array[$x]['default_setting_name'] = 'text';
+ $array[$x]['default_setting_value'] = '';
+ $array[$x]['default_setting_enabled'] = 'false';
+ $array[$x]['default_setting_description'] = "API key that allows access to the available fonts list.";
+ $x++;
+
//get an array of the default settings
$sql = "select * from v_default_settings ";
@@ -1367,7 +1396,7 @@ if ($domains_processed == 1) {
$sql .= "'".check_str($row['default_setting_enabled'])."', ";
$sql .= "'".check_str($row['default_setting_description'])."' ";
$sql .= ")";
- if ($missing_count != $i) {
+ if ($missing_count != $i) {
$sql .= ",\n";
}
$i++;
diff --git a/themes/default/css.php b/themes/default/css.php
index 56c6eb8a22..3f5da6b439 100644
--- a/themes/default/css.php
+++ b/themes/default/css.php
@@ -6,6 +6,32 @@ header("Content-type: text/css; charset: UTF-8");
$default_login = ($_REQUEST['login'] == 'default') ? true : false;
+//parse fonts (add surrounding single quotes to each font name)
+ if (is_array($_SESSION['theme']) && sizeof($_SESSION['theme']) > 0) {
+ foreach ($_SESSION['theme'] as $subcategory => $type) {
+ if (substr_count($subcategory, '_font') > 0) {
+ $font_string = $type['text'];
+ if ($font_string != '') {
+ if (substr_count($font_string, ',') > 0) {
+ $tmp_array = explode(',', $font_string);
+ }
+ else {
+ $tmp_array[] = $font_string;
+ }
+ foreach ($tmp_array as $font_name) {
+ $font_name = trim($font_name, "'");
+ $font_name = trim($font_name, '"');
+ $font_name = trim($font_name);
+ $fonts[] = $font_name;
+ }
+ if (sizeof($fonts) == 1 && strtolower($fonts[0]) != 'arial') { $fonts[] = 'Arial'; } //fall back font
+ $_SESSION['theme'][$subcategory]['text'] = "'".implode("','", $fonts)."'";
+ }
+ }
+ unset($fonts, $tmp_array);
+ }
+ }
+
//determine which background image/color settings to use (login or standard)
$background_images_enabled = false;
if ($default_login) {
diff --git a/themes/default/template.php b/themes/default/template.php
index 75f370faea..22f851bc3f 100644
--- a/themes/default/template.php
+++ b/themes/default/template.php
@@ -51,6 +51,16 @@
+\n";
+ }
+ echo "\n";
+ }
+?>