X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=smileybutton%2Fsmileybutton.php;h=1df717b72eab12d6deebc594682ae28042b4d89d;hb=668ea972ccb3974ceba4be993a8a39a9734c3cad;hp=2d4a0743e62cf737c8a62317dcf85a2d66e7261e;hpb=3e418dc5a0faf93aa78ff67fb5a2f7476cb9ed1d;p=friendica-addons.git diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php index 2d4a0743..1df717b7 100644 --- a/smileybutton/smileybutton.php +++ b/smileybutton/smileybutton.php @@ -2,46 +2,34 @@ /** * Name: Smileybutton * Description: Adds a smileybutton to the Inputbox - * Version: 0.2 + * Version: 1.0 * Author: Johannes Schwab + * Maintainer: Hypolite Petovan */ -use Friendica\Core\Addon; -function smileybutton_install() { - //Register hooks - Addon::registerHook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); - - logger("installed smileybutton"); -} - - -function smileybutton_uninstall() { - //Delet registered hooks - Addon::unregisterHook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); +use Friendica\App; +use Friendica\Core\Hook; +use Friendica\DI; - logger("removed smileybutton"); +function smileybutton_install() +{ + //Register hooks + Hook::register('jot_tool', 'addon/smileybutton/smileybutton.php', 'smileybutton_jot_tool'); } - - -function show_button($a, &$b) { +function smileybutton_jot_tool(string &$body) +{ // Disable if theme is quattro - // TODO add style for quattro - if (current_theme() == 'quattro') + if (DI::app()->getCurrentTheme() == 'quattro') { return; + } - // Disable for mobile because most mobiles have a smiley key for ther own - if ($a->is_mobile || $a->is_tablet) + // Disable for mobile because they have a smiley key of their own + if (DI::mode()->isMobile() || DI::mode()->isMobile()) { return; + } - /** - * - * I have copied this from /include/text.php, removed doubles - * and escaped them. - * - */ - - $texts = [ + $texts = [ '<3', '</3', ':-)', @@ -53,84 +41,82 @@ function show_button($a, &$b) { ':-O', '\\\\o/', 'O_o', - ":\'(", - ":-!", - ":-/", - ":-[", - "8-)", + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', ':beer', ':coffee', ':facepalm', ':like', ':dislike', - '~friendica', - 'red#' - + '~friendica', + 'red#', ]; $icons = [ - '<3', - '</3', - ':-)', - ';-)', - ':-(', - ':-P', - ':-X', - ':-D', - ':-O', - '\\o/', - 'O_o', - ':\'(', - ':-!', - ':-/', - ':-[', - '8-)', - ':beer', - ':coffee', - ':facepalm', - ':like', - ':dislike', - '~friendica', - 'red' + '<3', + '</3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-X', + ':-D', + ':-O', + '\\o/', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica', + 'red' ]; // Call hooks to get aditional smileies from other addons - $params = ['texts' => $texts, 'icons' => $icons, 'string' => ""]; //changed - Addon::callHooks('smilie', $params); + $params = ['texts' => $texts, 'icons' => $icons, 'string' => '']; //changed + Hook::callAll('smilie', $params); //Generate html for smiley list - $s = "\n\t"; - for($x = 0; $x < count($params['texts']); $x ++) { + $s = '
'; + for ($x = 0; $x < count($params['texts']); $x++) { $icon = $params['icons'][$x]; - $icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon); - $icon = str_replace('class="smiley"', 'class="smiley_preview"', $icon); - $s .= ""; - if (($x+1) % (sqrt(count($params['texts']))+1) == 0) { - $s .= "\n\t"; + $s .= ''; + if (($x + 1) % (floor(sqrt(count($params['texts']))) + 1) == 0) { + $s .= ''; } } - $s .= "\t
" . $icon . "
' . $icon . '
"; + $s .= ''; //Add css to header - $css_file = 'addon/smileybutton/view/'.current_theme().'.css'; - if (! file_exists($css_file)) - $css_file = 'addon/smileybutton/view/default.css'; - $css_url = $a->get_baseurl().'/'.$css_file; - - $a->page['htmlhead'] .= ''."\r\n"; + $css_file = __DIR__ . '/view/' . DI::app()->getCurrentTheme() . '.css'; + if (!file_exists($css_file)) { + $css_file = __DIR__ . '/view/default.css'; + } + DI::page()->registerStylesheet($css_file); //Get the correct image for the theme - $image = 'addon/smileybutton/view/'.current_theme().'.png'; - if (! file_exists($image)) + $image = 'addon/smileybutton/view/' . DI::app()->getCurrentTheme() . '.png'; + if (!file_exists($image)) { $image = 'addon/smileybutton/view/default.png'; - $image_url = $a->get_baseurl().'/'.$image; + } + + $image_url = DI::baseUrl() . '/' . $image; //Add the hmtl and script to the page - $b = <<< EOT -
- smiley -