]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User_group.php
Inbox::streamNotices() with deletion compensation: inbox paging should more or less...
[quix0rs-gnu-social.git] / classes / User_group.php
index e6e79ca6a3daa066c7e253d2124bea8a86d64917..c86eadf8fa7fff1e21ca9cb2f496d4aa4ce9acb4 100644 (file)
@@ -34,7 +34,7 @@ class User_group extends Memcached_DataObject
         static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
                                   AVATAR_STREAM_SIZE => 'stream',
                                   AVATAR_MINI_SIZE => 'mini');
-        return theme_path('default-avatar-'.$sizenames[$size].'.png');
+        return Theme::path('default-avatar-'.$sizenames[$size].'.png');
     }
 
     function homeUrl()
@@ -313,4 +313,107 @@ class User_group extends Memcached_DataObject
         $desclimit = self::maxDescription();
         return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
     }
+
+    function asAtomEntry($namespace=false, $source=false)
+    {
+        $xs = new XMLStringer(true);
+
+        if ($namespace) {
+            $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
+                           'xmlns:thr' => 'http://purl.org/syndication/thread/1.0');
+        } else {
+            $attrs = array();
+        }
+
+        $xs->elementStart('entry', $attrs);
+
+        if ($source) {
+            $xs->elementStart('source');
+            $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
+            $xs->element('link', array('href' => $this->permalink()));
+        }
+
+        if ($source) {
+            $xs->elementEnd('source');
+        }
+
+        $xs->element('title', null, $this->nickname);
+        $xs->element('summary', null, $this->description);
+
+        $xs->element('link', array('rel' => 'alternate',
+                                   'href' => $this->permalink()));
+
+        $xs->element('id', null, $this->permalink());
+
+        $xs->element('published', null, common_date_w3dtf($this->created));
+        $xs->element('updated', null, common_date_w3dtf($this->modified));
+
+        $xs->element('content', array('type' => 'html'), $this->description);
+
+        $xs->elementEnd('entry');
+
+        return $xs->getString();
+    }
+
+    static function register($fields) {
+
+        // MAGICALLY put fields into current scope
+
+        extract($fields);
+
+        $group = new User_group();
+
+        $group->query('BEGIN');
+
+        $group->nickname    = $nickname;
+        $group->fullname    = $fullname;
+        $group->homepage    = $homepage;
+        $group->description = $description;
+        $group->location    = $location;
+        $group->created     = common_sql_now();
+
+        $result = $group->insert();
+
+        if (!$result) {
+            common_log_db_error($group, 'INSERT', __FILE__);
+            $this->serverError(
+                _('Could not create group.'),
+                500,
+                $this->format
+            );
+            return;
+        }
+        $result = $group->setAliases($aliases);
+
+        if (!$result) {
+            $this->serverError(
+                _('Could not create aliases.'),
+                500,
+                $this->format
+            );
+            return;
+        }
+
+        $member = new Group_member();
+
+        $member->group_id   = $group->id;
+        $member->profile_id = $userid;
+        $member->is_admin   = 1;
+        $member->created    = $group->created;
+
+        $result = $member->insert();
+
+        if (!$result) {
+            common_log_db_error($member, 'INSERT', __FILE__);
+            $this->serverError(
+                _('Could not set group membership.'),
+                500,
+                $this->format
+            );
+            return;
+        }
+
+        $group->query('COMMIT');
+        return $group;
+    }
 }