Exemple #1
0
function pretheme_init(&$a)
{
    if ($_REQUEST['theme']) {
        $theme = $_REQUEST['theme'];
        $info = get_theme_info($theme);
        if ($info) {
            // unfortunately there will be no translation for this string
            $desc = $info['description'] . ' ' . $info['version'];
        } else {
            $desc = '';
        }
        echo json_encode(array('img' => get_theme_screenshot($theme), 'desc' => $desc));
    }
    killme();
}
Exemple #2
0
 function init()
 {
     if ($_REQUEST['theme']) {
         $theme = $_REQUEST['theme'];
         $info = get_theme_info($theme);
         if ($info) {
             // unfortunately there will be no translation for this string
             $desc = $info['description'];
             $version = $info['version'];
             $credits = $info['credits'];
         } else {
             $desc = '';
             $version = '';
             $credits = '';
         }
         echo json_encode(array('img' => get_theme_screenshot($theme), 'desc' => $desc, 'version' => $version, 'credits' => $credits));
     }
     killme();
 }
Exemple #3
0
 function get()
 {
     $theme = argv(1);
     if (!$theme) {
         killme();
     }
     $schemalist = array();
     $theme_config = "";
     if (($themeconfigfile = $this->get_theme_config_file($theme)) != null) {
         require_once $themeconfigfile;
         if (class_exists('\\Zotlabs\\Theme\\' . ucfirst($theme) . 'Config')) {
             $clsname = '\\Zotlabs\\Theme\\' . ucfirst($theme) . 'Config';
             $th_config = new $clsname();
             $schemas = $th_config->get_schemas();
             if ($schemas) {
                 foreach ($schemas as $k => $v) {
                     $schemalist[] = ['key' => $k, 'val' => $v];
                 }
             }
             $theme_config = $th_config->get();
         }
     }
     $info = get_theme_info($theme);
     if ($info) {
         // unfortunately there will be no translation for this string
         $desc = $info['description'];
         $version = $info['version'];
         $credits = $info['credits'];
     } else {
         $desc = '';
         $version = '';
         $credits = '';
     }
     $ret = ['theme' => $theme, 'img' => get_theme_screenshot($theme), 'desc' => $desc, 'version' => $version, 'credits' => $credits, 'schemas' => $schemalist, 'config' => $theme_config];
     json_return_and_die($ret);
 }
Exemple #4
0
 /**
  * @brief Themes admin page.
  *
  * @return string
  */
 function get()
 {
     $allowed_themes_str = get_config('system', 'allowed_themes');
     $allowed_themes_raw = explode(',', $allowed_themes_str);
     $allowed_themes = array();
     if (count($allowed_themes_raw)) {
         foreach ($allowed_themes_raw as $x) {
             if (strlen(trim($x))) {
                 $allowed_themes[] = trim($x);
             }
         }
     }
     $themes = array();
     $files = glob('view/theme/*');
     if ($files) {
         foreach ($files as $file) {
             $f = basename($file);
             $is_experimental = intval(file_exists($file . '/.experimental'));
             $is_supported = 1 - intval(file_exists($file . '/.unsupported'));
             // Is not used yet
             $is_allowed = intval(in_array($f, $allowed_themes));
             $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
         }
     }
     if (!count($themes)) {
         notice(t('No themes found.'));
         return '';
     }
     /*
      * Single theme
      */
     if (\App::$argc == 3) {
         $theme = \App::$argv[2];
         if (!is_dir("view/theme/{$theme}")) {
             notice(t("Item not found."));
             return '';
         }
         if (x($_GET, "a") && $_GET['a'] == "t") {
             check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
             // Toggle theme status
             $this->toggle_theme($themes, $theme, $result);
             $s = $this->rebuild_theme_table($themes);
             if ($result) {
                 info(sprintf('Theme %s enabled.', $theme));
             } else {
                 info(sprintf('Theme %s disabled.', $theme));
             }
             set_config('system', 'allowed_themes', $s);
             goaway(z_root() . '/admin/themes');
         }
         // display theme details
         require_once 'library/markdown.php';
         if ($this->theme_status($themes, $theme)) {
             $status = "on";
             $action = t("Disable");
         } else {
             $status = "off";
             $action = t("Enable");
         }
         $readme = Null;
         if (is_file("view/theme/{$theme}/README.md")) {
             $readme = file_get_contents("view/theme/{$theme}/README.md");
             $readme = Markdown($readme);
         } else {
             if (is_file("view/theme/{$theme}/README")) {
                 $readme = "<pre>" . file_get_contents("view/theme/{$theme}/README") . "</pre>";
             }
         }
         $admin_form = '';
         if (is_file("view/theme/{$theme}/php/config.php")) {
             require_once "view/theme/{$theme}/php/config.php";
             if (function_exists("theme_admin")) {
                 $admin_form = theme_admin($a);
             }
         }
         $screenshot = array(get_theme_screenshot($theme), t('Screenshot'));
         if (!stristr($screenshot[0], $theme)) {
             $screenshot = null;
         }
         $t = get_markup_template('admin_plugins_details.tpl');
         return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Themes'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => z_root(), '$plugin' => $theme, '$status' => $status, '$action' => $action, '$info' => get_theme_info($theme), '$function' => 'themes', '$admin_form' => $admin_form, '$str_author' => t('Author: '), '$str_maintainer' => t('Maintainer: '), '$screenshot' => $screenshot, '$readme' => $readme, '$form_security_token' => get_form_security_token('admin_themes')));
     }
     /*
      * List themes
      */
     $xthemes = array();
     if ($themes) {
         foreach ($themes as $th) {
             $xthemes[] = array($th['name'], $th['allowed'] ? "on" : "off", get_theme_info($th['name']));
         }
     }
     $t = get_markup_template('admin_plugins.tpl');
     return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Themes'), '$submit' => t('Submit'), '$baseurl' => z_root(), '$function' => 'themes', '$plugins' => $xthemes, '$experimental' => t('[Experimental]'), '$unsupported' => t('[Unsupported]'), '$form_security_token' => get_form_security_token('admin_themes')));
 }
Exemple #5
0
/**
 * Themes admin page
 *
 * @param App $a
 * @return string
 */
function admin_page_themes(&$a)
{
    $allowed_themes_str = get_config('system', 'allowed_themes');
    $allowed_themes_raw = explode(',', $allowed_themes_str);
    $allowed_themes = array();
    if (count($allowed_themes_raw)) {
        foreach ($allowed_themes_raw as $x) {
            if (strlen(trim($x))) {
                $allowed_themes[] = trim($x);
            }
        }
    }
    $themes = array();
    $files = glob('view/theme/*');
    /* */
    if ($files) {
        foreach ($files as $file) {
            $f = basename($file);
            $is_experimental = intval(file_exists($file . '/experimental'));
            $is_supported = 1 - intval(file_exists($file . '/unsupported'));
            $is_allowed = intval(in_array($f, $allowed_themes));
            if ($is_allowed or $is_supported or get_config("system", "show_unsupported_themes")) {
                $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
            }
        }
    }
    if (!count($themes)) {
        notice(t('No themes found.'));
        return '';
    }
    /**
     * Single theme
     */
    if ($a->argc == 3) {
        $theme = $a->argv[2];
        if (!is_dir("view/theme/{$theme}")) {
            notice(t("Item not found."));
            return '';
        }
        if (x($_GET, "a") && $_GET['a'] == "t") {
            check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
            // Toggle theme status
            toggle_theme($themes, $theme, $result);
            $s = rebuild_theme_table($themes);
            if ($result) {
                install_theme($theme);
                info(sprintf('Theme %s enabled.', $theme));
            } else {
                uninstall_theme($theme);
                info(sprintf('Theme %s disabled.', $theme));
            }
            set_config('system', 'allowed_themes', $s);
            goaway($a->get_baseurl(true) . '/admin/themes');
            return '';
            // NOTREACHED
        }
        // display theme details
        require_once 'library/markdown.php';
        if (theme_status($themes, $theme)) {
            $status = "on";
            $action = t("Disable");
        } else {
            $status = "off";
            $action = t("Enable");
        }
        $readme = Null;
        if (is_file("view/theme/{$theme}/README.md")) {
            $readme = file_get_contents("view/theme/{$theme}/README.md");
            $readme = Markdown($readme);
        } else {
            if (is_file("view/theme/{$theme}/README")) {
                $readme = "<pre>" . file_get_contents("view/theme/{$theme}/README") . "</pre>";
            }
        }
        $admin_form = "";
        if (is_file("view/theme/{$theme}/config.php")) {
            function __get_theme_admin_form(&$a, $theme)
            {
                $orig_theme = $a->theme;
                $orig_page = $a->page;
                $orig_session_theme = $_SESSION['theme'];
                require_once "view/theme/{$theme}/theme.php";
                require_once "view/theme/{$theme}/config.php";
                $_SESSION['theme'] = $theme;
                $init = $theme . "_init";
                if (function_exists($init)) {
                    $init($a);
                }
                if (function_exists("theme_admin")) {
                    $admin_form = theme_admin($a);
                }
                $_SESSION['theme'] = $orig_session_theme;
                $a->theme = $orig_theme;
                $a->page = $orig_page;
                return $admin_form;
            }
            $admin_form = __get_theme_admin_form($a, $theme);
        }
        $screenshot = array(get_theme_screenshot($theme), t('Screenshot'));
        if (!stristr($screenshot[0], $theme)) {
            $screenshot = null;
        }
        $t = get_markup_template("admin_plugins_details.tpl");
        return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Themes'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(true), '$plugin' => $theme, '$status' => $status, '$action' => $action, '$info' => get_theme_info($theme), '$function' => 'themes', '$admin_form' => $admin_form, '$str_author' => t('Author: '), '$str_maintainer' => t('Maintainer: '), '$screenshot' => $screenshot, '$readme' => $readme, '$form_security_token' => get_form_security_token("admin_themes")));
    }
    // reload active themes
    if (x($_GET, "a") && $_GET['a'] == "r") {
        check_form_security_token_redirectOnErr($a->get_baseurl() . '/admin/themes', 'admin_themes', 't');
        if ($themes) {
            foreach ($themes as $th) {
                if ($th['allowed']) {
                    uninstall_theme($th['name']);
                    install_theme($th['name']);
                }
            }
        }
        info("Themes reloaded");
        goaway($a->get_baseurl() . '/admin/themes');
    }
    /**
     * List themes
     */
    $xthemes = array();
    if ($themes) {
        foreach ($themes as $th) {
            $xthemes[] = array($th['name'], $th['allowed'] ? "on" : "off", get_theme_info($th['name']));
        }
    }
    $t = get_markup_template("admin_plugins.tpl");
    return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Themes'), '$submit' => t('Save Settings'), '$reload' => t('Reload active themes'), '$baseurl' => $a->get_baseurl(true), '$function' => 'themes', '$plugins' => $xthemes, '$experimental' => t('[Experimental]'), '$unsupported' => t('[Unsupported]'), '$form_security_token' => get_form_security_token("admin_themes")));
}