]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Merge branch 'nightly' of https://git.gnu.io/gnu/gnu-social into nightly
[quix0rs-gnu-social.git] / classes / Notice.php
index 6501a83adb85d675b79e1f303ab1da00152234c0..d5a0e5f6d2588448dc5c775048300e23a9096b41 100644 (file)
@@ -248,10 +248,10 @@ class Notice extends Managed_DataObject
         return common_local_url('shownotice', array('notice' => $this->id), null, null, false);
     }
 
-    public function getTitle()
+    public function getTitle($imply=true)
     {
         $title = null;
-        if (Event::handle('GetNoticeTitle', array($this, &$title))) {
+        if (Event::handle('GetNoticeTitle', array($this, &$title)) && $imply) {
             // TRANS: Title of a notice posted without a title value.
             // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
             $title = sprintf(_('%1$s\'s status on %2$s'),
@@ -336,16 +336,6 @@ class Notice extends Managed_DataObject
         }
     }
 
-    public static function getByUri($uri)
-    {
-        $notice = new Notice();
-        $notice->uri = $uri;
-        if (!$notice->find(true)) {
-            throw new NoResultException($notice);
-        }
-        return $notice;
-    }
-
     /**
      * Extract #hashtags from this notice's content and save them to the database.
      */
@@ -955,10 +945,10 @@ class Notice extends Managed_DataObject
             $act->context = new ActivityContext();
         }
 
-        if (array_key_exists('http://activityschema.org/collection/public', $act->context->attention)) {
+        if (array_key_exists(ActivityContext::ATTN_PUBLIC, $act->context->attention)) {
             $stored->scope = Notice::PUBLIC_SCOPE;
             // TODO: maybe we should actually keep this? if the saveAttentions thing wants to use it...
-            unset($act->context->attention['http://activityschema.org/collection/public']);
+            unset($act->context->attention[ActivityContext::ATTN_PUBLIC]);
         } else {
             $stored->scope = self::figureOutScope($actor, $groups, $scope);
         }
@@ -2133,11 +2123,7 @@ class Notice extends Managed_DataObject
             if (!empty($ns->url)) {
                 $noticeInfoAttr['source_link'] = $ns->url;
                 if (!empty($ns->name)) {
-                    $noticeInfoAttr['source'] =  '<a href="'
-                        . htmlspecialchars($ns->url)
-                        . '" rel="nofollow">'
-                        . htmlspecialchars($ns->name)
-                        . '</a>';
+                    $noticeInfoAttr['source'] = $ns->name;
                 }
             }
         }
@@ -2637,6 +2623,13 @@ class Notice extends Managed_DataObject
         return !empty($this->repeat_of);
     }
 
+    public function isRepeated()
+    {
+        $n = new Notice();
+        $n->repeat_of = $this->getID();
+        return $n->find() && $n->N > 0;
+    }
+
     /**
      * Get the list of hash tags saved with this notice.
      *
@@ -2683,7 +2676,7 @@ class Notice extends Managed_DataObject
     public static function getAsTimestamp($id)
     {
         if (empty($id)) {
-            throw new EmptyIdException('Notice');
+            throw new EmptyPkeyValueException('Notice', 'id');
         }
 
         $timestamp = null;
@@ -3091,6 +3084,44 @@ class Notice extends Managed_DataObject
         $schema = Schema::get();
         $schemadef = $schema->getTableDef($table);
 
+        // 2015-09-04 We move Notice location data to Notice_location
+        // First we see if we have to do this at all
+        if (isset($schemadef['fields']['lat'])
+                && isset($schemadef['fields']['lon'])
+                && isset($schemadef['fields']['location_id'])
+                && isset($schemadef['fields']['location_ns'])) {
+            // Then we make sure the Notice_location table is created!
+            $schema->ensureTable('notice_location', Notice_location::schemaDef());
+
+            // Then we continue on our road to migration!
+            echo "\nFound old $table table, moving location data to 'notice_location' table... (this will probably take a LONG time, but can be aborted and continued)";
+
+            $notice = new Notice();
+            $notice->query(sprintf('SELECT id, lat, lon, location_id, location_ns FROM %1$s ' .
+                                 'WHERE lat IS NOT NULL ' .
+                                    'OR lon IS NOT NULL ' .
+                                    'OR location_id IS NOT NULL ' .
+                                    'OR location_ns IS NOT NULL',
+                                 $schema->quoteIdentifier($table)));
+            print "\nFound {$notice->N} notices with location data, inserting";
+            while ($notice->fetch()) {
+                $notloc = Notice_location::getKV('notice_id', $notice->id);
+                if ($notloc instanceof Notice_location) {
+                    print "-";
+                    continue;
+                }
+                $notloc = new Notice_location();
+                $notloc->notice_id = $notice->id;
+                $notloc->lat= $notice->lat;
+                $notloc->lon= $notice->lon;
+                $notloc->location_id= $notice->location_id;
+                $notloc->location_ns= $notice->location_ns;
+                $notloc->insert();
+                print ".";
+            }
+            print "\n";
+        }
+
         /**
          *  Make sure constraints are met before upgrading, if foreign keys
          *  are not already in use.
@@ -3163,45 +3194,5 @@ class Notice extends Managed_DataObject
                 unset($notice);
             }
         }
-
-        // 2015-09-04 We move Notice location data to Notice_location
-        // First we see if we have to do this at all
-        if (!isset($schemadef['fields']['lat'])
-                && !isset($schemadef['fields']['lon'])
-                && !isset($schemadef['fields']['location_id'])
-                && !isset($schemadef['fields']['location_ns'])) {
-            // We have already removed the location fields, so no need to migrate.
-            return;
-        }
-        // Then we make sure the Notice_location table is created!
-        $schema->ensureTable('notice_location', Notice_location::schemaDef());
-
-        // Then we continue on our road to migration!
-        echo "\nFound old $table table, moving location data to 'notice_location' table... (this will probably take a LONG time, but can be aborted and continued)";
-
-        $notice = new Notice();
-        $notice->query(sprintf('SELECT id, lat, lon, location_id, location_ns FROM %1$s ' .
-                             'WHERE lat IS NOT NULL ' .
-                                'OR lon IS NOT NULL ' .
-                                'OR location_id IS NOT NULL ' .
-                                'OR location_ns IS NOT NULL',
-                             $schema->quoteIdentifier($table)));
-        print "\nFound {$notice->N} notices with location data, inserting";
-        while ($notice->fetch()) {
-            $notloc = Notice_location::getKV('notice_id', $notice->id);
-            if ($notloc instanceof Notice_location) {
-                print "-";
-                continue;
-            }
-            $notloc = new Notice_location();
-            $notloc->notice_id = $notice->id;
-            $notloc->lat= $notice->lat;
-            $notloc->lon= $notice->lon;
-            $notloc->location_id= $notice->location_id;
-            $notloc->location_ns= $notice->location_ns;
-            $notloc->insert();
-            print ".";
-        }
-        print "\n";
     }
 }