addBreadCrumb(['link' => ADMIN."theme.php".$aidlink, 'title' => self::$locale['theme_1000']]); } /** * Check if a theme widget file exist * * @param $theme_name * * @return bool */ static function theme_widget_exists($theme_name) { return (is_dir(THEMES.$theme_name) && file_exists(THEMES.$theme_name."/widget.php")) ? TRUE : FALSE; } /** * The Theme Editor - Manage UI * * @param $theme_name */ public static function display_theme_editor($theme_name) { $locale = fusion_get_locale(); $aidlink = fusion_get_aidlink(); // sanitize theme exist $theme_name = self::verify_theme($theme_name) ? $theme_name : ""; if (!$theme_name) { redirect(clean_request("", ["aid"], TRUE)); } BreadCrumbs::getInstance()->addBreadCrumb(['link' => FUSION_REQUEST, 'title' => $locale['theme_1018']]); // go with tabs $tab['title'] = [$locale['theme_1022'], $locale['theme_1023'], $locale['theme_1024']]; $tab['id'] = ["dashboard", "widgets", "css"]; $tab['icon'] = ["fa fa-edit fa-fw", "fa fa-cube fa-fw", "fa fa-css3 fa-fw"]; if (isset($_GET['action'])) { $tab['title'][] = $locale['theme_1029']; $tab['id'][] = "close"; $tab['icon'][] = "fa fa-close fa-fw"; } if (isset($_POST['close_theme'])) { redirect(FUSION_SELF.$aidlink); } $_GET['section'] = isset($_GET['section']) && in_array($_GET['section'], $tab['id']) ? $_GET['section'] : "dashboard"; $tab_active = $_GET['section']; $atom = new Atom(); $atom->target_folder = $theme_name; $atom->theme_name = $theme_name; echo opentab($tab, $tab_active, "theme_admin", TRUE, 'nav-tabs m-b-10'); // now include the thing as necessary switch ($_GET['section']) { case "dashboard": /** * Delete preset */ if (isset($_GET['delete_preset']) && isnum($_GET['delete_preset'])) { if (empty($_GET['theme'])) { redirect(FUSION_SELF.$aidlink); } $theme_name = stripinput($_GET['theme']); $file = dbarray(dbquery("SELECT theme_file FROM ".DB_THEME." WHERE theme_name='".$theme_name."' AND theme_id='".intval($_GET['delete_preset'])."'")); if (file_exists(THEMES.$file['theme_file'])) { unlink(THEMES.$file['theme_file']); } dbquery("DELETE FROM ".DB_THEME." WHERE theme_id='".intval($_GET['delete_preset'])."'"); addNotice('success', $locale['theme_success_002']); redirect(clean_request("", ["section", "aid", "action", "theme"], TRUE)); } /** * Set active presets */ if (isset($_POST['load_preset']) && isnum($_POST['load_preset'])) { $result = dbquery("select theme_id FROM ".DB_THEME." WHERE theme_active='1'"); if (dbrows($result) > 0) { $data = dbarray($result); $data = [ "theme_id" => $data['theme_id'], "theme_active" => 0, ]; dbquery_insert(DB_THEME, $data, "update"); } $data = [ "theme_id" => $_POST['load_preset'], "theme_active" => 1, ]; dbquery_insert(DB_THEME, $data, "update"); redirect(clean_request("", ["section", "aid", "action", "theme"], TRUE)); } $atom->display_theme_overview(); break; case "widgets": $atom->display_theme_widgets(); break; case "css": $atom->theme_editor(); break; case "close": redirect(FUSION_SELF.$aidlink); break; default: break; } echo closetab(); } /** * Verify theme exist * * @param $theme_name * * @return bool */ public static function verify_theme($theme_name) { return (is_dir(THEMES.$theme_name) && file_exists(THEMES.$theme_name."/theme.php") && file_exists(THEMES.$theme_name."/styles.css") && fusion_get_settings('theme') == $theme_name) ? TRUE : FALSE; } public static function display_theme_list() { $locale = fusion_get_locale(); $aidlink = fusion_get_aidlink(); $settings = fusion_get_settings(); if (isset($_GET['action']) && $_GET['action'] == "set_active" && isset($_GET['theme']) && $_GET['theme'] !== "") { $theme_name = form_sanitizer($_GET['theme'], ''); if (self::theme_installable($theme_name)) { $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$theme_name."' WHERE settings_name='theme'"); if ($result) { redirect(FUSION_SELF.$aidlink); } } } $data = []; $_dir = makefilelist(THEMES, ".|..|templates|admin_themes", TRUE, "folders"); foreach ($_dir as $folder) { $theme_dbfile = '/theme_db.php'; $status = $settings['theme'] == $folder ? 1 : 0; if (file_exists(THEMES.$folder.$theme_dbfile)) { // 9.00 compatible theme. $theme_folder = ''; include_once THEMES.$folder.$theme_dbfile; $data[$status][$folder] = [ 'readme' => !empty($theme_readme) && file_exists(THEMES.$theme_folder."/".$theme_readme) ? THEMES.$theme_folder."/".$theme_readme : '', 'folder' => isset($theme_folder) && file_exists(THEMES.$theme_folder.'/theme.php') ? THEMES.$theme_folder : '', 'screenshot' => isset($theme_screenshot) && file_exists(THEMES.$theme_folder."/".$theme_screenshot) ? THEMES.$theme_folder."/".$theme_screenshot : IMAGES.'imagenotfound.jpg', 'title' => isset($theme_title) ? $theme_title : '', 'web' => isset($theme_web) ? $theme_web : '', 'author' => isset($theme_author) ? $theme_author : '', 'license' => isset($theme_license) ? $theme_license : '', 'version' => isset($theme_version) ? $theme_version : '', 'description' => isset($theme_description) ? $theme_description : '', 'widgets' => file_exists(THEMES.$theme_folder.'/widget.php') ? TRUE : FALSE ]; } else { // older legacy theme. if (file_exists(THEMES.$folder.'/theme.php')) { $theme_screenshot = '/screenshot.jpg'; $data[$status][$folder] = [ 'readme' => '', 'folder' => THEMES.$folder, 'title' => $folder, 'screenshot' => file_exists(THEMES.$folder.$theme_screenshot) ? THEMES.$folder.$theme_screenshot : IMAGES.'imagenotfound.jpg', 'author' => '', 'license' => '', 'version' => '', 'description' => $locale['theme_1035'] ]; } } } krsort($data); foreach ($data as $status => $themes) { foreach ($themes as $theme_name => $theme_data) { echo "
\n
\n
\n"; echo '
'; echo "
".thumbnail($theme_data['screenshot'], '150px')."
\n"; echo "
\n"; echo "

".($status == TRUE ? "" : "").$theme_data['title']."

"; echo "
\n"; if (!empty($theme_data['description'])) { echo "
".$theme_data['description']."
"; } if (!empty($theme_data['license'])) { echo " ".$theme_data['license']."\n"; } if (!empty($theme_data['readme'])) { echo " ".$locale['theme_1036'].""; } if (!empty($theme_data['version'])) { echo " ".$theme_data['version']."\n"; } if (!empty($theme_data['author'])) { echo " ".$theme_data['author'].""; } if (!empty($theme_data['web'])) { echo " ".$locale['theme_1015'].""; } echo "
\n"; if ($status == TRUE) { echo "".$locale['theme_1006']."
\n"; } if (!empty($theme_data['widgets']) == TRUE) { echo "".$locale['theme_1027'].$locale['yes']."\n"; } echo "
\n"; echo "
\n"; echo "
\n"; echo '
'; echo '
'; echo "
\n"; if ($status == TRUE) { echo " ".$locale['theme_1005']."\n"; } else { echo " ".$locale['theme_1012'].""; } echo "
\n"; echo '
'; echo "
\n
\n
\n"; unset($theme_data); } } } /** * Verify that theme exist and not active * * @param $theme_name * * @return bool */ static function theme_installable($theme_name) { return (is_dir(THEMES.$theme_name) && file_exists(THEMES.$theme_name."/theme.php") && file_exists(THEMES.$theme_name."/styles.css") && fusion_get_settings('theme') !== $theme_name) ? TRUE : FALSE; } public static function theme_uploader() { $defender = \defender::getInstance(); $locale = fusion_get_locale(); $aidlink = fusion_get_aidlink(); if (isset($_POST['upload'])) { require_once INCLUDES."infusions_include.php"; $src_file = 'theme_files'; $target_folder = THEMES; $valid_ext = ',.zip'; $max_size = 5 * 1000 * 1000; $upload = upload_file($src_file, '', $target_folder, $valid_ext, $max_size); if ($upload['error'] != '0') { $defender->stop(); switch ($upload['error']) { case 1: addNotice('danger', sprintf($locale['theme_error_001'], parsebytesize($max_size, 2))); break; case 2: addNotice('danger', $locale['theme_error_002']); break; case 3: addNotice('danger', $locale['theme_error_003']); break; case 4: addNotice('danger', $locale['theme_error_004']); break; default : addNotice('danger', $locale['theme_error_003']); } } else { $target_file = $target_folder.$upload['target_file']; if (is_file($target_file)) { $path = pathinfo(realpath($target_file), PATHINFO_DIRNAME); if (class_exists('ZipArchive')) { $zip = new \ZipArchive(); if ($zip->open($target_file) === TRUE) { // checks if first folder is theme.php if ($zip->locateName('theme.php', \ZipArchive::FL_NODIR) !== FALSE) { // extract it to the path we determined above $zip->extractTo($path); addNotice('success', $locale['theme_success_001']); } else { $defender->stop(); addNotice('danger', $locale['theme_error_009']); } $zip->close(); @unlink($target_file); redirect(FUSION_SELF.$aidlink); } else { addNotice('danger', $locale['theme_error_005']); @unlink($target_file); redirect(FUSION_SELF.$aidlink); } } else { addNotice('warning', $locale['theme_error_006']); @unlink($target_file); redirect(FUSION_SELF.$aidlink); } } } } echo openform('inputform', 'post', FUSION_SELF.$aidlink, ['enctype' => 1, 'max_tokens' => 1]); echo form_fileinput('theme_files', $locale['theme_1007'], '', ['type' => 'object', 'preview_off' => TRUE,]); echo form_button('upload', $locale['theme_1007'], 'upload theme', ['class' => 'btn btn-primary']); echo closeform(); } }