X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=smileybutton%2Fsmileybutton.php;h=593eed8b0912c6b6484379d53dbafc34feb43e99;hb=8237e3cc692aca686b95bf4c1628d420e9227816;hp=d53794b904f8145908d2d28b1a21c62009b7df91;hpb=dfa4cfc7cde6c6f755beae5818fe3eee99724c5c;p=friendica-addons.git diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php old mode 100755 new mode 100644 index d53794b9..593eed8b --- a/smileybutton/smileybutton.php +++ b/smileybutton/smileybutton.php @@ -2,140 +2,105 @@ /** * Name: Smileybutton * Description: Adds a smileybutton to the Inputbox - * Version: 0.1 - * Author: Johannes Schwab + * Version: 0.2 + * Author: Johannes Schwab */ - +use Friendica\Core\Hook; +use Friendica\Core\Logger; function smileybutton_install() { + //Register hooks + Hook::register('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); - /** - * - * 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"); + Logger::log("installed smileybutton"); } function smileybutton_uninstall() { + //Delet registered hooks + Hook::unregister('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button'); - /** - * - * 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"); + Logger::log("removed smileybutton"); } -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 show_button(Friendica\App $a, &$b) { + // Disable if theme is quattro + // TODO add style for quattro + if ($a->getCurrentTheme() == 'quattro') + return; - /** - * - * Prepare the Smilie-Arrays - * - */ + // Disable for mobile because most mobiles have a smiley key for ther own + if ($a->is_mobile || $a->is_tablet) + return; /** * - * I have copied this from /include/text.php, removed dobles - * and some escapes. + * I have copied this from /include/text.php, removed doubles + * and escaped them. * */ - $texts = array( - '<3', - '</3', - ':-)', - ';-)', - ':-(', - ':-P', - ':-X', - ':-D', - ':-O', - '\\\\o/', - 'O_o', - ":\'(", - ":-!", - ":-/", - ":-[", + $texts = [ + '<3', + '</3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-X', + ':-D', + ':-O', + '\\\\o/', + 'O_o', + ":\'(", + ":-!", + ":-/", + ":-[", "8-)", - ':beer', - ':coffee', + ':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"; + ]; + + $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 = "
\n\t"; for($x = 0; $x < count($params['texts']); $x ++) { $icon = $params['icons'][$x]; $icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon); @@ -145,139 +110,57 @@ function show_button($a, &$b) { $s .= "\n\t"; } } - $s .= "\t
\n"; - - /** - * - * Add css to page - * - */ - - $a->page['htmlhead'] .= '' . "\r\n"; - - /** - * - * 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"; - } - - - /** - * - * Write the smileies to an (hidden) div - * - */ - - if ($nobutton) { - $b .= "\t
\n"; - } else { - $b .= "\t
\n"; - } - $b .= $s . "\n"; - $b .= "
\n"; - - /** - * - * Function to show and hide the smiley-list in the hidden div - * - */ - - $b .= "\n"; -} - - - - - -/** - * - * Set the configuration - * - */ - -function smileybutton_settings_post($a,$post) { - if(! local_user()) - return; - if($_POST['smileybutton-submit']) - set_pconfig(local_user(),'smileybutton','nobutton',intval($_POST['smileybutton'])); - -} - - -/** - * - * 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 .= '
'; + $s .= "\t"; + + //Add css to header + $css_file = 'addon/smileybutton/view/' . $a->getCurrentTheme() . '.css'; + if (! file_exists($css_file)) + $css_file = 'addon/smileybutton/view/default.css'; + $css_url = $a->getBaseURL().'/'.$css_file; + + $a->page['htmlhead'] .= ''."\r\n"; + + + //Get the correct image for the theme + $image = 'addon/smileybutton/view/' . $a->getCurrentTheme() . '.png'; + if (! file_exists($image)) + $image = 'addon/smileybutton/view/default.png'; + $image_url = $a->getBaseURL().'/'.$image; + + //Add the hmtl and script to the page + $b = <<< EOT +
+ smiley + +
+ + +EOT; }