Last commit for src/views/elements/AppearanceElement.php: 2addb500315b7393a90fe66431d7832b1e7386c7

Adjust copyrights years

Chris Pollett [2024-01-03 21:Jan:rd]
Adjust copyrights years
<?php
/**
 * SeekQuarry/Yioop --
 * Open Source Pure PHP Search Engine, Crawler, and Indexer
 *
 * Copyright (C) 2009 - 2023 Chris Pollett chris@pollett.org
 *
 * LICENSE:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * END LICENSE
 *
 * @author Chris Pollett chris@pollett.org
 * @license https://www.gnu.org/licenses/ GPL3
 * @link https://www.seekquarry.com/
 * @copyright 2009 - 2023
 * @filesource
 */
namespace seekquarry\yioop\views\elements;

use seekquarry\yioop as B;
use seekquarry\yioop\configs as C;

/**
 * Element responsible for drawing the screen used to set up the search engine
 * appearance.
 *
 * @author Chris Pollett
 */
class AppearanceElement extends Element
{
    /**
     * Draws the forms used to modify the search engine appearance.
     *
     * This element has a form to set foreground, background appearance and
     * icons used in the display of the Yioop web app. It can also be used to
     * configure if the main landing page should be the main wiki page
     *
     * @param array $data holds data on the profile elements related to site
     *      appearance
     */
    public function render($data)
    {
        $admin_url = htmlentities(B\controllerUrl('admin', true));
        $appearance_url = $admin_url . 'a=appearance&amp;'.
            C\CSRF_TOKEN."=".$data[C\CSRF_TOKEN];
        $search_page_url = $admin_url . 'a=pageOptions&amp;' .
            'option_type=search_time&amp;' .
            C\CSRF_TOKEN."=".$data[C\CSRF_TOKEN];
        ?>
        <div class="current-activity bold">
        <form id="appearanceForm" method="post"
            action='<?=$appearance_url ?>'
            enctype='multipart/form-data' <?php
            if (!empty($data['USE_THEME_FORM'])) { ?>
                onsubmit="
                    var caret_pos = elt('caret-pos');
                    var scroll_top = elt('scroll-top');
                    var auxiliary_css = elt('auxiliary-css');
                    if (caret_pos && scroll_top && auxiliary_css) {
                        caret_pos.value =
                            (auxiliary_css.selectionStart) ?
                            auxiliary_css.selectionStart : 0;
                        scroll_top.value = (auxiliary_css.scrollTop) ?
                        auxiliary_css.scrollTop : 0;
                    }" <?php
            } ?> >
        <input type="hidden" name="c" value="admin" >
        <input type="hidden" name="<?= C\CSRF_TOKEN ?>" value="<?=
            $data[C\CSRF_TOKEN] ?>" >
        <input type="hidden" name="a" value="appearance" >
        <input type="hidden" name="arg" value="profile" >
        <input type="hidden" name="caret" id="caret-pos" >
        <input type="hidden" name="scroll_top" id="scroll-top" >
        <div class="top-margin">
        <?php
        if (empty($data['USE_THEME_FORM'])) {
            $this->renderMainAppearanceForm($data);
        } else {
            $this->renderThemeForm($data);
        }
        ?>
        <div class="top-margin center">
        <button class="button-box" type="submit"><?=
            tl('appearance_element_save') ?></button>
        </div>
        </div>
        </form>
        </div>
    <?php
    }
    /**
     * Used to draw general appearance controls for a Yioop site
     * such as for setting the background color, site logo, etc.
     * Has a drop down for setting the current theme, but does not
     * show the edit/add theme forms.
     *
     * @param array $data from the AdminController/SystemComponent with
     *    the current values for appearance settings.
     */
    public function renderMainAppearanceForm($data)
    {
        $admin_url = htmlentities(B\controllerUrl('admin', true));
        $appearance_url = $admin_url . 'a=appearance&amp;'.
            C\CSRF_TOKEN."=".$data[C\CSRF_TOKEN];
        $search_page_url = $admin_url . 'a=pageOptions&amp;' .
            'option_type=search_time&amp;' .
            C\CSRF_TOKEN."=".$data[C\CSRF_TOKEN];
        $icon_helper = $this->view->helper('iconlink');
        ?>
        <div class="top-margin"><label for="landing-page"><?=
            tl('appearance_element_use_wiki_landing') ?></label>
        <input type="checkbox" id="landing-page"
            name="LANDING_PAGE" value='true' <?php
            if ($data['LANDING_PAGE'] == true) {
                e("checked='checked'");} ?>/></div>
        <div class="top-margin">[<a href="<?=$search_page_url ?>"><?=
            tl('appearance_element_search_page_components') ?></a>]
            [<a href="<?= $appearance_url . '&amp;arg=reset' ?>"><?=
                tl('appearance_element_reset_customizations') ?></a>]
        </div>
        <div class="top-margin"><label for="theme"><?=
            tl('appearance_element_themes') ?></label><?php
            $this->view->helper("options")->render(
                "themes", "AUXILIARY_CSS_NAME", $data['themes'],
                $data['AUXILIARY_CSS_NAME'] ?? -1, true,
                ["class" => 'theme-dropdown']);
            e(" ");
            if (!empty($data['AUXILIARY_CSS_NAME']) &&
                $data['AUXILIARY_CSS_NAME'] != -1) {
                $icon_helper->renderButton("$appearance_url" .
                    "&amp;edit_theme=true", "edit", "", false,
                    "source-anchor-button");
            }
            e(" ");
            $icon_helper->renderButton("$appearance_url" .
                "&amp;add_theme=true&amp;AUXILIARY_CSS=", "add", "", false,
                "source-anchor-button");?>
        </div>
        <div class="top-margin"><label for="back-color"><?=
            tl('appearance_element_background_color') ?></label>
        <input type="color" id="back-color"
            name="BACKGROUND_COLOR" class="narrow-field" value='<?=
            $data["BACKGROUND_COLOR"] ?>' ></div>
        <div class="top-margin">
        <table><tr>
        <td><label for="back-image"><?=
            tl('appearance_element_background_image')
            ?></label></td><td class="user-icon-td"><?php
            $image = (isset($data['BACKGROUND_IMAGE']) &&
            $data['BACKGROUND_IMAGE']) ? $data['BACKGROUND_IMAGE'] :
                C\SHORT_BASE_URL."/resources/drag.png";
        ?><img id='current-back-image' class="user-icon"
            src="<?= $image ?>" alt="<?=
            tl('appearance_element_background_image') ?>" ><?php
        $this->view->helper("fileupload")->render(
            'current-back-image',
            'BACKGROUND_IMAGE', 'back-image', C\THUMB_SIZE, 'image',
            ['image/png', 'image/gif', 'image/jpeg', 'image/x-icon']);
        ?></td></tr></table>
        </div>
        <div class="top-margin"><label for="fore-color"><?=
            tl('appearance_element_foreground_color') ?></label>
        <input type="color" id="fore-color"
            name="FOREGROUND_COLOR" class="narrow-field" value='<?=
            $data["FOREGROUND_COLOR"] ?>' ></div>
        <div class="top-margin"><label for="top-color"><?=
            tl('appearance_element_topbar_color') ?></label>
        <input type="color" id="top-color"
            name="TOPBAR_COLOR" class="narrow-field" value='<?=
            $data["TOPBAR_COLOR"]?>' ></div>
        <div class="top-margin"><label for="side-color"><?=
            tl('appearance_element_sidebar_color') ?></label>
        <input type="color" id="side-color"
            name="SIDEBAR_COLOR" class="narrow-field" value='<?=
            $data["SIDEBAR_COLOR"] ?>' ></div><?php
        foreach (['large' => tl('appearance_element_large_logo'),
            'medium' => tl('appearance_element_medium_logo'),
            'small' => tl('appearance_element_small_logo')] as
            $size => $label_size) {
            $upper_size = mb_strtoupper($size);
            $size_logo = $size . '-logo'; ?>
            <div class="top-margin">
            <table><tr>
            <td><label for="<?=$size_logo ?>"><?=$label_size
                ?></label></td><td class="user-icon-td"><?php
            $logo_field = 'LOGO_' . $upper_size;
            $current_logo = 'current-'. $size_logo;
            $image = (isset($data[$logo_field]) &&
                $data[$logo_field]) ? $data[$logo_field] :
                    C\SHORT_BASE_URL . "/resources/drag.png";
            ?><img id='<?= $current_logo ?>' class="user-icon"
                src="<?=$image ?>" alt="<?=$label_size ?>" ><?php
            $this->view->helper("fileupload")->render(
                $current_logo,
                $logo_field, $size_logo, C\THUMB_SIZE, 'image',
                ['image/png', 'image/gif', 'image/jpeg', 'image/x-icon']);
            ?></td></tr></table>
            </div><?php
        } ?>
        <div class="top-margin">
        <table><tr>
        <td><label for="favicon"><?=tl('appearance_element_favicon')
            ?></label></td><td class="user-icon-td"><?php
        $image = (isset($data['FAVICON']) &&
            $data['FAVICON']) ? $data['FAVICON'] :
                C\SHORT_BASE_URL . "/resources/drag.png";
        ?><img id='current-favicon' class="user-icon"
            src="<?=$data['FAVICON'] ?>" alt="<?=
            tl('appearance_element_favicon') ?>" ><?php
        $this->view->helper("fileupload")->render(
            'current-favicon',
            'FAVICON', 'favicon',  C\THUMB_SIZE, 'image',
            ['image/png', 'image/gif', 'image/jpeg', 'image/x-icon']);
        ?></td></tr></table>
        </div>
        <div class="top-margin"><table><tr>
        <td><label for="toolbar"><?=tl('appearance_element_toolbar')
            ?></label></td><td class="user-icon-td"><?php
        ?><div id="current-toolbar" class="upload-file"
        >&nbsp;</div><?php
        $this->view->helper("fileupload")->render(
            'current-toolbar',
            'SEARCHBAR_PATH', 'toolbar',
            1000000, 'text', ["text/xml"]);
        ?></td></tr></table>
        </div>
        <?php
    }
    /**
     * Used to draw the create/edit theme forms for the Appearance Acitivity
     *
     * @param array $data from the AdminController/SystemComponent with
     *    the code for the theme being edited
     */
    public function renderThemeForm($data)
    {
        $admin_url = htmlentities(B\controllerUrl('admin', true));
        $appearance_url = $admin_url . 'a=appearance&amp;'.
            C\CSRF_TOKEN."=".$data[C\CSRF_TOKEN];
        $this->view->helper("close")->render($appearance_url);
        $icon_helper = $this->view->helper('iconlink');
        if ($data['LANDING_PAGE'] == true) {?>
            <input type="hidden" name="LANDING_PAGE" value='true' ><?php
        }
        ?>
        <div class="top-margin"><input type="hidden" name="edit_theme"
            value="true" ><label for="auxiliary-css-name"><?=
            tl('appearance_element_auxiliary_css_name') ?></label>
        <input type="text" name="AUXILIARY_CSS_NAME" maxlength="<?=C\NAME_LEN?>"
            placeholder="<?=tl('appearance_element_theme_name') ?>"
            <?=!empty($data['AUXILIARY_CSS_NAME']) ? ' style="' .
            'pointer-events:none; color: gray;" ' .
            'value="'. $data['AUXILIARY_CSS_NAME'] . '" ' :
            "" ?>/> <?php
        if (empty($data['ADD_THEME'])) {
            $icon_helper->renderLink("$appearance_url" .
                "&amp;arg=delete&amp;AUXILIARY_CSS_NAME=".
                urlencode($data['AUXILIARY_CSS_NAME']), "delete", "", false);
        }?></div>
        <div class="top-margin"><label for="auxiliary-css"><?=
            tl('appearance_element_css_code') ?></label>
        <textarea class="tall-text-area" id="auxiliary-css"
            name="AUXILIARY_CSS" ><?=
            (!empty($data['AUXILIARY_CSS_NAME']) ||
            !empty($data['ADD_THEME'])) ?
                $data['AUXILIARY_CSS'] : "" ?></textarea>
        </div><?php
    }
}
ViewGit