<?php /** * SeekQuarry/Yioop -- * Open Source Pure PHP Search Engine, Crawler, and Indexer * * Copyright (C) 2009 - 2022 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 - 2022 * @filesource */ namespace seekquarry\yioop\views\helpers; /** * This is a helper class is used to draw * icon buttons and links * * @author Chris Pollett */ class IconlinkHelper extends Helper { /** * Types of icons supported by this helper * @var array */ public $icon_possibilities; /** * Initials mapping between names of icons and the actual icons * to be used as links or buttons */ public function __construct() { $this->icon_possibilities = [ "account_home" => [ tl('iconlink_helper_account_home'), 'π '], "account_settings" => [ tl('iconlink_helper_account_settings'),'β'], "add" => [ tl('iconlink_helper_add'), 'β'], "ask_join_group" => [ tl('iconlink_helper_ask_join_group'), "π"], "close" => [ tl('iconlink_helper_close'), 'X'], "create_group" => [ tl('iconlink_helper_create_group'), 'β'], "combined_discussions" => [ tl('iconlink_helper_combined_discussions'), 'π'], "crawls" => [tl('iconlink_helper_manage_crawls'), 'πΈοΈ'], "delete" => [tl('iconlink_helper_delete'), 'ποΈ', tl('iconlink_helper_confirm')], "discuss_page" => [ tl('iconlink_helper_discuss_page'), 'π£οΈ'], "edit" => [ tl('iconlink_helper_edit'), 'βοΈ'], "groups" => [ tl('iconlink_helper_groups'), 'ποΈ'], "group_feed" => [ tl('iconlink_helper_group_discussions'), 'π'], "history" => [tl('iconlink_helper_history'), 'π'], "information" => [tl('iconlink_helper_information'), 'βΉοΈ'], "join_group" => [ tl('iconlink_helper_join_group'), "π¬"], "join_group_fee" => [ tl('iconlink_helper_join_group'), "π¬", 'iconlink_helper_fee_warning'], //note no tl "join_invited_group" => [ tl('iconlink_helper_join_invited_group'), "ποΈ"], "join_groups" => [ tl('iconlink_helper_join_groups'), "π¬"], "leave_group" => [ tl('iconlink_helper_leave_group'), "π«"], "localize" => [ tl('iconlink_helper_localize'), 'π'], "machines" => [tl('iconlink_helper_manage_machines'), 'π€'], "mixes" => [tl('iconlink_helper_manage_mixes'), 'π₯¨'], "messages" => [ tl('iconlink_helper_messages'), 'π¬'], "pages" => [tl('iconlink_helper_group_pages'), 'π'], "pending" => [ tl('iconlink_helper_request_pending'), "β³", tl('iconlink_helper_cancel_request')], "play" => [tl('iconlink_helper_group_play'), 'βΆοΈ'], "query_stats" => [ tl('iconlink_helper_query_stats'), 'π'], "reset" => [ tl('iconlink_helper_reset'), 'X'], "search" => [ tl('iconlink_helper_search'), 'π'], "settings" => [ tl('iconlink_helper_settings'), "<b class='black medium-font'>β</b>"], "statistics" => [ tl('iconlink_helper_statistics'), "π"], "view_read" => [ tl('iconlink_helper_view_read'), 'β©οΈ'], "view_source" => [ tl('iconlink_helper_view_source'), 'ποΈ'], "wiki" => [ tl('iconlink_helper_group_main_page'), 'π'], "wiki_syntax" => [ tl('iconlink_helper_wiki_syntax'), 'π'], ]; } /** * Draws a link button suitable to indicate the activity $type * * @param string $url url that is sent when one clicks and confirms * @param string $type one of "edit", ... * @param bool $as_string whether to return a string or html * @param string $div_classes space separated, additional css classes * to add to outermost div * @param string $anchor_classes space separated, additional css classes * to add to anchor tag * @param bool $replace_css whether to appened css in $div_classes and * $anchor_classes to existing or to replace. * @param string $tab_target whether to open link in a new tab with target * $tab_target * @return mixed either void, or a string of html if $as_string = true */ public function renderButton($url, $type = "edit", $as_string = false, $div_classes = "", $anchor_classes = "", $replace_css = false, $tab_target = "") { if (is_array($url)) { list($id, $url,) = $url; $id_attr = " id='$id' "; } else { $id_attr = ""; } if ($as_string) { ob_start(); } $div_classes = ($replace_css) ? $div_classes : "icon-button-container ". $div_classes; ?><div <?=$id_attr ?> class='<?= $div_classes ?>'><?= $this->renderLink($url, $type, $as_string, $anchor_classes, $replace_css, $tab_target); ?></div><?php if ($as_string) { $button = ob_get_contents(); ob_end_clean(); return $button; } } /** * Draws a button for a form that uses an icon as its main text * @param string $button type value for type attribute of html button * @param string $type of icon one of "edit", ... * @param bool $as_string whether to return a string or html * @param string $anchor_class space separated, additional css classes * to add to anchor * @param string $additional_attibutes a string to enclose with the open * button tag with additional attributes * @return mixed either void, or a string of html if $as_string = true */ public function renderFormButton($button_type = "submit" , $type = "edit", $as_string = false, $anchor_classes = "", $additional_attibutes = "") { $type = (isset($this->icon_possibilities[$type])) ? $type : "submit"; $icon_info = $this->icon_possibilities[$type]; list($icon_text, $icon, ) = $icon_info; if ($as_string) { ob_start(); } ?><button type='<?=$button_type ?>' class='<?=$anchor_classes ?>' <?=$additional_attibutes ?> ><span role='img' aria-label='<?= $icon_text ?>' ><?=$icon ?></span></button><?php if ($as_string) { $button = ob_get_contents(); ob_end_clean(); return $button; } } /** * Draws a link suitable to indicate the activity $type * * @param string $url url that is sent when one clicks and confirms * @param string $type one of "edit", ... * @param bool $as_string whether to return a string or html * @param string $anchor_class space separated, additional css classes * to add to anchor * @param bool $replace_css whether to replace default anchor css or * append to it * @param string $tab_target whether to open link in a new tab with target * $tab_target * @return mixed either void, or a string of html if $as_string = true */ public function renderLink($url, $type = "edit", $as_string = false, $anchor_classes = "", $replace_css = false, $tab_target = "") { $type = (isset($this->icon_possibilities[$type])) ? $type : "edit"; $icon_info = $this->icon_possibilities[$type]; if (empty($tab_target)) { $target = (empty($_REQUEST['noscript'])) ? "" : " target='_parent' rel='noopener' "; } else { $target = " target='$tab_target' rel='noopener' "; } list($icon_text, $icon, ) = $icon_info; $confirm = ""; if (is_array($url) && !empty($url[1]) && !empty($icon_info[2])) { list($url, $translate_aux,) = $url; $icon_info[2] = tl($icon_info[2], $translate_aux); $icon = "<div class='inline align-opposite'>$icon<br />". "<span class='tiny-font' style='position:relative; top: -8px;'". ">$translate_aux</span></div>"; } if (!empty($icon_info[2])) { $confirm = " onclick='javascript:return ". "confirm(\"{$icon_info[2]}\")' "; } if ($as_string) { ob_start(); } $anchor_classes = ($replace_css) ? $anchor_classes : "icon-anchor-button ". $anchor_classes; ?><div class='position-context <?=$anchor_classes ?>'><a <?=$confirm ?> class='<?= $anchor_classes ?>' <?=$target?> href='<?= $url ?>'><span role='img' aria-label='<?= $icon_text ?>' ><?=$icon ?></span></a></div><?php if ($as_string) { $button = ob_get_contents(); ob_end_clean(); return $button; } } }