X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=smileybutton%2Fsmileybutton.php;h=fc20888f1a200b0fbc3ef21522ca1864a10e2765;hb=410613d7a076de0fa699b66a4db17ae9267d13e7;hp=87db098b25ab404d4c45d6cb3d558aeb5fb7417e;hpb=1f8617d37232d608aaefe5fc706501057ac6803f;p=friendica-addons.git diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php old mode 100755 new mode 100644 index 87db098b..fc20888f --- a/smileybutton/smileybutton.php +++ b/smileybutton/smileybutton.php @@ -2,282 +2,143 @@ /** * Name: Smileybutton * Description: Adds a smileybutton to the Inputbox - * Version: 0.1 - * Author: Johannes Schwab + * Version: 1.0 + * Author: Johannes Schwab + * Maintainer: Hypolite Petovan */ +use Friendica\App; +use Friendica\Core\Hook; +use Friendica\DI; -function smileybutton_install() { - - /** - * - * Register hooks for jot_tool and plugin_settings - * - */ - - register_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); - register_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings'); - register_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post'); - - logger("installed smileybutton"); -} - - -function smileybutton_uninstall() { - - /** - * - * Delet registered hooks - * - */ - - unregister_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); - unregister_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings'); - unregister_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post'); - - logger("removed smileybutton"); +function smileybutton_install() +{ + //Register hooks + Hook::register('jot_tool', 'addon/smileybutton/smileybutton.php', 'smileybutton_jot_tool'); } - - -function show_button($a, &$b) { - - /** - * - * Check if it is a local user and he has enabled smileybutton - * - */ - - if(! local_user()) { - $nobutton = false; - } else { - $nobutton = get_pconfig(local_user(), 'smileybutton', 'nobutton'); +function smileybutton_jot_tool(string &$body) +{ + // Disable if theme is quattro + if (DI::app()->getCurrentTheme() == 'quattro') { + return; } - /** - * - * Prepare the Smilie-Arrays - * - */ - - /** - * - * I have copied this from /include/text.php, removed dobles - * and some escapes. - * - */ + // Disable for mobile because they have a smiley key of their own + if (DI::mode()->isMobile() || DI::mode()->isMobile()) { + return; + } - $texts = array( - '<3', - '</3', - ':-)', - ';-)', - ':-(', - ':-P', - ':-X', - ':-D', - ':-O', - '\\\\o/', - 'O_o', - ":\'(", - ":-!", - ":-/", - ":-[", - "8-)", - ':beer', - ':coffee', + $texts = [ + '<3', + '</3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-X', + ':-D', + ':-O', + '\\\\o/', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':coffee', ':facepalm', ':like', ':dislike', - '~friendica', - 'red#' - - ); - - $icons = array( - '<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 = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed - call_hooks('smilie', $params); - - /** - * - * Generate html for smileylist - * - */ - - $s = "\t\n"; - for($x = 0; $x < count($params['texts']); $x ++) { + '~friendica', + 'red#', + ]; + + $icons = [ + '<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 + Hook::callAll('smilie', $params); + + //Generate html for smiley list + $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) % (sqrt(count($params['texts'])) + 1) == 0) { + $s .= ''; } } - $s .= "\t
" . $icon . "
' . $icon . '
\n"; - - /** - * - * Add css to page - * - */ - - $a->page['htmlhead'] .= '' . "\r\n"; + $s .= ''; - /** - * - * Add the button to the Inputbox - * - */ - if (! $nobutton) { - $b = "
\n"; - $b .= "\tget_baseurl() . "/addon/smileybutton/icon.gif\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n"; - $b .= "\t
\n"; + //Add css to header + $css_file = __DIR__ . '/view/' . DI::app()->getCurrentTheme() . '.css'; + if (!file_exists($css_file)) { + $css_file = __DIR__ . '/view/default.css'; } - - /** - * - * Write the smileies to an (hidden) div - * - */ + DI::page()->registerStylesheet($css_file); - if ($nobutton) { - $b .= "\t
\n"; - } else { - $b .= "\t
\n"; + //Get the correct image for the theme + $image = 'addon/smileybutton/view/' . DI::app()->getCurrentTheme() . '.png'; + if (!file_exists($image)) { + $image = 'addon/smileybutton/view/default.png'; } - $b .= $s . "\n"; - $b .= "
\n"; - - /** - * - * Function to show and hide the smiley-list in the hidden div - * - */ - - $b .= "\n"; -} - + $image_url = DI::baseUrl() . '/' . $image; + + //Add the hmtl and script to the page + $body = <<< EOT +
+ +
+ $s +
+
+ + +EOT; } - -/** - * - * Add configuration-dialog to form - * - */ - - -function smileybutton_settings(&$a,&$s) { - - if(! local_user()) - return; - - /* Add our stylesheet to the page so we can make our settings look nice */ - - $a->page['htmlhead'] .= '' . "\r\n"; - - /* Get the current state of our config variable */ - - $nobutton = get_pconfig(local_user(),'smileybutton','nobutton'); - $checked = (($nobutton) ? ' checked="checked" ' : ''); - - /* Add some HTML to the existing form */ - - $s .= '
'; - $s .= '

Smileybutton settings

'; - $s .= '
'; - - $s .= 'You can hide the button and show the smilies directly.

'; - - $s .= ''; - $s .= ''; - - $s .= '
'; - - /* provide a submit button */ - - $s .= '
'; - -}