]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'rewrites-master/type-hints-asserts' into rewrites-nightly/type-hints... rewrites-nightly/type-hints-asserts
authorRoland Haeder <roland@mxchange.org>
Fri, 27 Mar 2015 21:24:37 +0000 (22:24 +0100)
committerRoland Haeder <roland@mxchange.org>
Fri, 27 Mar 2015 21:24:37 +0000 (22:24 +0100)
Conflicts:
classes/Notice.php
lib/docfile.php
lib/framework.php

Signed-off-by: Roland Haeder <roland@mxchange.org>
12 files changed:
actions/invite.php
actions/replies.php
classes/Notice.php
lib/activity.php
lib/docfile.php
lib/framework.php
lib/inviteform.php
lib/profileaction.php
plugins/EmailRegistration/EmailRegistrationPlugin.php
plugins/EmailReminder/EmailReminderPlugin.php
plugins/Favorite/classes/Fave.php
plugins/SubMirror/SubMirrorPlugin.php

index c3464efb5407ccbbf8bacadbe6c158f815c5dc60..0deb7a76ee2d997a5dd66236fc5fc1774e31e1cc 100644 (file)
@@ -74,6 +74,7 @@ class InviteAction extends Action
             $bestname = $profile->getBestName();
             $sitename = common_config('site', 'name');
             $personal = $this->trimmed('personal');
+            $language = $this->trimmed('language');
 
             $addresses = explode("\n", $this->trimmed('addresses'));
             foreach ($addresses as $email) {
@@ -128,7 +129,7 @@ class InviteAction extends Action
                 } catch (NoSuchUserException $e) {
                     // If email was not known, let's send an invite!
                     $this->sent[] = $email;
-                    $this->sendInvitation($email, $user, $personal);
+                    $this->sendInvitation($email, $user, $personal, $language);
                 }
             }
 
@@ -248,7 +249,7 @@ class InviteAction extends Action
         }
     }
 
-    function sendInvitation($email, $user, $personal)
+    function sendInvitation($email, $user, $personal, $language)
     {
         $profile = $user->getProfile();
         $bestname = $profile->getBestName();
@@ -284,7 +285,7 @@ class InviteAction extends Action
         $title = (empty($personal)) ? 'invite' : 'invitepersonal';
 
         // @todo FIXME: i18n issue.
-        $inviteTemplate = DocFile::forTitle($title, DocFile::mailPaths());
+        $inviteTemplate = DocFile::forTitle($title, DocFile::mailPaths(), $language);
 
         $body = $inviteTemplate->toHTML(array('inviter' => $bestname,
                                               'inviterurl' => $profile->profileurl,
index 5bf2f8edc429bb4829f0966c82053fccb7576045..ce65fef7a9fbe497aef387b80c1507da0b2d067e 100644 (file)
@@ -74,26 +74,6 @@ class RepliesAction extends ManagedAction
             // TRANS: Client error when page not found (404)
             $this->clientError(_('No such page.'), 404);
         }
-<<<<<<< HEAD
-
-        return true;
-    }
-
-    /**
-     * Handle a request
-     *
-     * Just show the page. All args already handled.
-     *
-     * @param array $args $_REQUEST data
-     *
-     * @return void
-     */
-    function handle(array $args=array())
-    {
-        parent::handle($args);
-        $this->showPage();
-=======
->>>>>>> 1442ca16b410d327d7ec6269944144dfa075ff17
     }
 
     /**
index 65190da8906e5da3169d4f3645ccc76fa8d230fa..5c18f03500f1de2625ad9b57ad67a484d1faf3b3 100644 (file)
@@ -552,8 +552,7 @@ class Notice extends Managed_DataObject
                 throw new ClientException(_('You cannot repeat your own notice.'));
             }
 
-            if ($repeat->scope != Notice::SITE_SCOPE &&
-                $repeat->scope != Notice::PUBLIC_SCOPE) {
+            if ($repeat->isPrivateScope()) {
                 // TRANS: Client error displayed when trying to repeat a non-public notice.
                 throw new ClientException(_('Cannot repeat a private notice.'), 403);
             }
@@ -2505,6 +2504,41 @@ class Notice extends Managed_DataObject
      */
     public function getTags()
     {
+        // Check default scope (non-private notices)
+        $inScope = (!$this->isPrivateScope());
+
+        // Get current user
+        $user = common_current_user();
+
+        // Is the general scope check okay and the user in logged in?
+        /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . ']: inScope=' . intval($inScope) . ',user[]=' . gettype($user));
+        if (($inScope === TRUE) && ($user instanceof User)) {
+            // Get profile from it
+            $profile = $user->getProfile();
+            /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . ']: inScope=' . intval($inScope) . ',profile[]=' . gettype($profile));
+
+            /*
+             * Check scope, else a privacy leaks happens this way:
+             *
+             * 1) Bob and Alice follow each other and write private notices
+             *    (this->scope=2) to each other.
+             * 2) Bob uses tags in his private notice to alice (which she can
+             *    read from him).
+             * 3) Alice adds that notice (with tags) to her favorites
+             *    ("faving") it.
+             * 4) The tags from Bob's private notice becomes visible in Alice's
+             *    profile.
+             *
+             * This has the simple background that the scope is not being
+             * re-checked. This has to be done here at this point because given
+             * above scenario is a privacy leak as the tags may be *really*
+             * private (nobody else shall see them) such as initmate words or
+             * very political words.
+             */
+            $inScope = $this->inScope($profile);
+            /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . ']: inScope=' . intval($inScope) . ' - After inScope() has been called.');
+        }
+
         $tags = array();
 
         $keypart = sprintf('notice:tags:%d', $this->id);
@@ -2516,7 +2550,9 @@ class Notice extends Managed_DataObject
         } else {
             $tag = new Notice_tag();
             $tag->notice_id = $this->id;
-            if ($tag->find()) {
+
+            // Check scope for privacy-leak protection (see some lines above why)
+            if (($inScope === TRUE) && ($tag->find())) {
                 while ($tag->fetch()) {
                     $tags[] = $tag->tag;
                 }
@@ -2941,4 +2977,15 @@ class Notice extends Managed_DataObject
             $notice->_setRepeats($repeats);
         }
     }
+
+    /**
+     * Checks whether this notice is in "private scope" (non-public notice)
+     *
+     * @return $isPrivate Whether this notice is private
+     */
+    public function isPrivateScope ()
+    {
+        return ($this->scope != Notice::SITE_SCOPE &&
+                $this->scope != Notice::PUBLIC_SCOPE);
+    }
 }
index 2d3930df0d85ec46207e6ff63fa9790556f3f664..6b3ccf3519dd496b98b95dafe6107eeea1772bb5 100644 (file)
@@ -107,6 +107,7 @@ class Activity
     public $selfLink; // <link rel='self' type='application/atom+xml'>
     public $editLink; // <link rel='edit' type='application/atom+xml'>
     public $generator; // ActivityObject representing the generating application
+
     /**
      * Turns a regular old Atom <entry> into a magical activity
      *
index 316aebb8726304430f411ff8489174d3f9eab660..583f7ebc9b3190353763ca2439f9d42f1815511c 100644 (file)
@@ -55,12 +55,8 @@ class DocFile
         $this->filename = $filename;
     }
 
-    static function forTitle($title, $paths)
+    static function forTitle($title, array $paths, $language=null)
     {
-        if (!is_array($paths)) {
-            $paths = array($paths);
-        }
-
         $filename = null;
 
         if (Event::handle('StartDocFileForTitle', array($title, &$paths, &$filename))) {
@@ -80,7 +76,7 @@ class DocFile
                 }
 
                 if (!empty($lang) || !empty($def)) {
-                    $filename = self::negotiateLanguage($lang, $def);
+                    $filename = self::negotiateLanguage($lang, $def, $language);
                     break;
                 }
             }
@@ -95,12 +91,8 @@ class DocFile
         }
     }
 
-    function toHTML(array $args=null)
+    function toHTML(array $args=array())
     {
-        if (is_null($args)) {
-            $args = array();
-        }
-
         if (empty($this->contents)) {
             $this->contents = file_get_contents($this->filename);
         }
@@ -114,7 +106,7 @@ class DocFile
                        INSTALLDIR.'/doc-src/');
 
         $site = GNUsocial::currentSite();
-        
+
         if (!empty($site)) {
             array_unshift($paths, INSTALLDIR.'/local/doc-src/'.$site.'/');
         }
@@ -128,7 +120,7 @@ class DocFile
                        INSTALLDIR.'/mail-src/');
 
         $site = GNUsocial::currentSite();
-        
+
         if (!empty($site)) {
             array_unshift($paths, INSTALLDIR.'/local/mail-src/'.$site.'/');
         }
@@ -136,12 +128,20 @@ class DocFile
         return $paths;
     }
 
-    static function negotiateLanguage($filenames, $defaultFilename=null)
+    private static function negotiateLanguage(array $filenames, $defaultFilename=null, $language = null)
     {
-        // XXX: do this better
-
+        // Default is current language
         $langcode = common_language();
 
+        // Is a language set?
+        if (!empty($language)) {
+            // And is it valid?
+            if (common_valid_language($language)) {
+                // Use this as language (e.g. from form)
+                $langcode = strval($language);
+            }
+        }
+
         foreach ($filenames as $filename) {
             if (preg_match('/\.'.$langcode.'$/', $filename)) {
                 return $filename;
index 6fe6028f6e229699a1cfbf1152b51a1cf3ccf1ac..c534bebd04d4d90928b184a950aea8ee2bc7487d 100644 (file)
@@ -27,7 +27,7 @@ define('GNUSOCIAL_LIFECYCLE', 'dev'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc
 
 define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
 
-define('GNUSOCIAL_CODENAME', 'Not decided yet');
+define('GNUSOCIAL_CODENAME', 'Only a fixed bug is a good bug.');
 
 define('AVATAR_PROFILE_SIZE', 96);
 define('AVATAR_STREAM_SIZE', 48);
index 364ca75b9b32217b05ff245e195286ca6f9db1c2..be4dc163b059c56257b601f53188e08396f415e1 100644 (file)
@@ -93,6 +93,7 @@ class InviteForm extends Form
     function formData()
     {
         $this->out->elementStart('ul', 'form_data');
+
         $this->out->elementStart('li');
         $this->out->textarea(
             'addresses',
@@ -103,6 +104,7 @@ class InviteForm extends Form
             _('Addresses of friends to invite (one per line).')
         );
         $this->out->elementEnd('li');
+
         $this->out->elementStart('li');
         $this->out->textarea(
             // TRANS: Field label for a personal message to send to invitees.
@@ -112,6 +114,16 @@ class InviteForm extends Form
             _('Optionally add a personal message to the invitation.')
         );
         $this->out->elementEnd('li');
+
+        $language = common_language();
+
+        $this->out->elementStart('li');
+        $this->out->dropdown('language', _('Language'),
+            // TRANS: Tooltip for dropdown list label in form for profile settings.
+            get_nice_language_list(), _('Preferred language.'),
+            false, $language);
+        $this->out->elementEnd('li');
+
         $this->out->elementEnd('ul');
     }
 
index 79008f3bfcb2397d6b13fdba0448732fc243a39d..2ec94da8181551d270035caab6e9391e37b272cc 100644 (file)
@@ -209,20 +209,19 @@ class ProfileAction extends ManagedAction
         // TRANS: H2 text for user statistics.
         $this->element('h2', null, _('Statistics'));
 
-        $profile = $this->target;
-        $actionParams = array('nickname' => $profile->nickname);
+        $actionParams = array('nickname' => $this->target->nickname);
         $stats = array(
             array(
                 'id' => 'user-id',
                 // TRANS: Label for user statistics.
                 'label' => _('User ID'),
-                'value' => $profile->id,
+                'value' => $this->target->id,
             ),
             array(
                 'id' => 'member-since',
                 // TRANS: Label for user statistics.
                 'label' => _('Member since'),
-                'value' => date('j M Y', strtotime($profile->created))
+                'value' => date('j M Y', strtotime($this->target->created))
             ),
             array(
                 'id' => 'notices',
@@ -240,7 +239,7 @@ class ProfileAction extends ManagedAction
         );
 
         // Give plugins a chance to add stats entries
-        Event::handle('ProfileStats', array($profile, &$stats));
+        Event::handle('ProfileStats', array($this->target, &$stats));
 
         foreach ($stats as $row) {
             $this->showStatsRow($row);
index 330f72b15b06981ac3f312a42c1615741693a539..77ac763bd030df7a2a942afef7ec97c457dca1c6 100644 (file)
@@ -72,7 +72,7 @@ class EmailRegistrationPlugin extends Plugin
         $dir = dirname(__FILE__);
 
         // @todo FIXME: i18n issue.
-        $docFile = DocFile::forTitle($title, $dir.'/doc-src/');
+        $docFile = DocFile::forTitle($title, array($dir . '/doc-src/'));
 
         if (!empty($docFile)) {
             $output = $docFile->toHTML();
@@ -163,7 +163,7 @@ class EmailRegistrationPlugin extends Plugin
         mail_send($recipients, $headers, $body);
     }
 
-    function onEndDocFileForTitle($title, $paths, &$filename)
+    function onEndDocFileForTitle($title, array $paths, &$filename)
     {
         if ($title == 'confirmemailreg' && empty($filename)) {
             $filename = dirname(__FILE__).'/mail-src/'.$title;
index a415865ab95a5a7dea067cb71992eacd803220e7..9ba3d125e11b0281279ab3a83d2fdffb7c34e27c 100644 (file)
@@ -77,7 +77,7 @@ class EmailReminderPlugin extends Plugin
         return true;
     }
 
-    function onEndDocFileForTitle($title, $paths, &$filename)
+    function onEndDocFileForTitle($title, array $paths, &$filename)
     {
         if (empty($filename)) {
             $filename = dirname(__FILE__) . '/mail-src/' . $title;
@@ -127,6 +127,7 @@ class EmailReminderPlugin extends Plugin
      * Send a real live email reminder
      *
      * @todo This would probably be better as two or more sep functions
+     * @todo Add language support?
      *
      * @param string $type      type of reminder
      * @param mixed  $object    Confirm_address or Invitation object
index 48ed3ba93bcb3d4a8accae430e4c054e2a0ef9f2..4869d02d8595eab2a529b53b10b4cccdb364185d 100644 (file)
@@ -250,7 +250,7 @@ class Fave extends Managed_DataObject
      *
      * @return array Array of Fave objects
      */
-    static public function byNotice($notice)
+    static public function byNotice(Notice $notice)
     {
         if (!isset(self::$_faves[$notice->id])) {
             self::fillFaves(array($notice->id));
index 13a8a9fd71633151a8dad946602fc675c927cc1e..60560b4afc5bc4cef2d62174736ede7f382e0e7a 100644 (file)
@@ -155,7 +155,7 @@ class SubMirrorPlugin extends Plugin
      * @param array $stats
      * @return boolean hook return value
      */
-    function onProfileStats($profile, &$stats)
+    function onProfileStats(Profile $profile, array &$stats)
     {
         $cur = common_current_user();
         if (!empty($cur) && $cur->id == $profile->id) {