]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/DirectionDetector/DirectionDetectorPlugin.php
Merge branch 'fixes/private_scope_on_tags' into social-master
[quix0rs-gnu-social.git] / plugins / DirectionDetector / DirectionDetectorPlugin.php
index ac6b43c1f312f9def96388abae7ff3c0c882b4bd..73ea99940804e800b3d304c44725483937e22edc 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * DirectionDetector plugin, detects notices with RTL content & sets RTL
  * style for them.
@@ -37,28 +36,19 @@ class DirectionDetectorPlugin extends Plugin {
      *
      * @param object $notice notice is going to be saved
      */
-    public function onStartNoticeSave($notice){
+    public function onStartNoticeSave(Notice $notice) {
         if(!preg_match('/<span class="rtl">/', $notice->rendered) && self::isRTL($notice->content))
             $notice->rendered = '<span class="rtl">'.$notice->rendered.'</span>';
         return true;
     }
 
-    /**
-     * SN plugin API, here we will add css needed for modifiyed rendered
-     *
-     * @param Action $xml
-     */
-    public function onEndShowStatusNetStyles($xml){
-        $xml->element('style', array('type' => 'text/css'), 'span.rtl {display:block;direction:rtl;text-align:right;float:right;} .notice .author {float:left}');
-    }
-
     /**
      * is passed string a rtl content or not
      *
      * @param string $content
      * @return boolean
      */
-    public static function isRTL($content){
+    public static function isRTL($content) {
         $content = self::getClearText($content);
         $words = explode(' ', $content);
         $rtl = 0;
@@ -81,7 +71,10 @@ class DirectionDetectorPlugin extends Plugin {
      * @param string $str
      * @return boolean
      */
-    public static function startsWithRTLCharacter($str){
+    public static function startsWithRTLCharacter($str ){
+        if (strlen($str) < 1) {
+            return false;
+        }
         if( is_array($cc = self::utf8ToUnicode(mb_substr($str, 0, 1, 'utf-8'))) )
             $cc = $cc[0];
         else
@@ -113,7 +106,7 @@ class DirectionDetectorPlugin extends Plugin {
      * @param string $str
      * @return string
      */
-    private static function getClearText($str){
+    private static function getClearText($str) {
         $str = preg_replace('/@[^ ]+|![^ ]+|#[^ ]+/u', '', $str); // reply, tag, group
         $str = preg_replace('/^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]/u', '', $str); // redent, retweet
         $str = preg_replace("/[ \r\t\n]+/", ' ', trim($str)); // remove spaces
@@ -125,9 +118,9 @@ class DirectionDetectorPlugin extends Plugin {
      *
      * @param Action $action
      */
-    function onEndShowScripts($action){
+    function onEndShowScripts(Action $action){
         if (common_logged_in()) {
-            $action->script('plugins/DirectionDetector/jquery.DirectionDetector.js');
+            $action->script($this->path('jquery.DirectionDetector.js'));
         }
     }
 
@@ -251,11 +244,15 @@ class DirectionDetectorPlugin extends Plugin {
     /**
      * plugin details
      */
-    function onPluginVersion(&$versions){
+    function onPluginVersion(array &$versions){
+        $url = 'http://status.net/wiki/Plugin:DirectionDetector';
+
         $versions[] = array(
             'name' => 'Direction detector',
             'version' => DIRECTIONDETECTORPLUGIN_VERSION,
             'author' => 'Behrooz Shabani',
+            'homepage' => $url,
+            // TRANS: Plugin description.
             'rawdescription' => _m('Shows notices with right-to-left content in correct direction.')
         );
         return true;