]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/apiaction.php
Rip out user, group and site design customization code
[quix0rs-gnu-social.git] / lib / apiaction.php
index 1dfeea998af12b6a90ab62b6db6f70545935e488..64b4284f6aa1e2eb4e57ddc00efa3e0e88ea7d2b 100644 (file)
@@ -218,30 +218,8 @@ class ApiAction extends Action
         $twitter_user['protected'] = ($user->private_stream) ? true : false;
         $twitter_user['followers_count'] = $profile->subscriberCount();
 
-        $design = null;
-
         // Note: some profiles don't have an associated user
 
-        $defaultDesign = Design::siteDesign();
-
-        if (!empty($user)) {
-            $design = $user->getDesign();
-        }
-
-        if (empty($design)) {
-            $design = $defaultDesign;
-        }
-
-        $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor);
-        $twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue();
-        $color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor);
-        $twitter_user['profile_text_color'] = ($color == null) ? '' : '#'.$color->hexValue();
-        $color = Design::toWebColor(empty($design->linkcolor) ? $defaultDesign->linkcolor : $design->linkcolor);
-        $twitter_user['profile_link_color'] = ($color == null) ? '' : '#'.$color->hexValue();
-        $color = Design::toWebColor(empty($design->sidebarcolor) ? $defaultDesign->sidebarcolor : $design->sidebarcolor);
-        $twitter_user['profile_sidebar_fill_color'] = ($color == null) ? '' : '#'.$color->hexValue();
-        $twitter_user['profile_sidebar_border_color'] = '';
-
         $twitter_user['friends_count'] = $profile->subscriptionCount();
 
         $twitter_user['created_at'] = $this->dateTwitter($profile->created);
@@ -259,15 +237,6 @@ class ApiAction extends Action
 
         $twitter_user['utc_offset'] = $t->format('Z');
         $twitter_user['time_zone'] = $timezone;
-
-        $twitter_user['profile_background_image_url']
-            = empty($design->backgroundimage)
-            ? '' : ($design->disposition & BACKGROUND_ON)
-            ? Design::url($design->backgroundimage) : '';
-
-        $twitter_user['profile_background_tile']
-            = (bool)($design->disposition & BACKGROUND_TILE);
-
         $twitter_user['statuses_count'] = $profile->noticeCount();
 
         // Is the requesting user following this user?
@@ -459,6 +428,32 @@ class ApiAction extends Action
         return $entry;
     }
 
+    function twitterListArray($list)
+    {
+        $profile = Profile::staticGet('id', $list->tagger);
+
+        $twitter_list = array();
+        $twitter_list['id'] = $list->id;
+        $twitter_list['name'] = $list->tag;
+        $twitter_list['full_name'] = '@'.$profile->nickname.'/'.$list->tag;;
+        $twitter_list['slug'] = $list->tag;
+        $twitter_list['description'] = $list->description;
+        $twitter_list['subscriber_count'] = $list->subscriberCount();
+        $twitter_list['member_count'] = $list->taggedCount();
+        $twitter_list['uri'] = $list->getUri();
+
+        if (isset($this->auth_user)) {
+            $twitter_list['following'] = $list->hasSubscriber($this->auth_user);
+        } else {
+            $twitter_list['following'] = false;
+        }
+
+        $twitter_list['mode'] = ($list->private) ? 'private' : 'public';
+        $twitter_list['user'] = $this->twitterUserArray($profile, false);
+
+        return $twitter_list;
+    }
+
     function twitterRssEntryArray($notice)
     {
         $entry = array();
@@ -634,6 +629,20 @@ class ApiAction extends Action
         $this->elementEnd('group');
     }
 
+    function showTwitterXmlList($twitter_list)
+    {
+        $this->elementStart('list');
+        foreach($twitter_list as $element => $value) {
+            if($element == 'user') {
+                $this->showTwitterXmlUser($value, 'user');
+            }
+            else {
+                $this->element($element, null, $value);
+            }
+        }
+        $this->elementEnd('list');
+    }
+
     function showTwitterXmlUser($twitter_user, $role='user', $namespaces=false)
     {
         $attrs = array();
@@ -1111,6 +1120,65 @@ class ApiAction extends Action
         $this->endDocument('xml');
     }
 
+    function showXmlLists($list, $next_cursor=0, $prev_cursor=0)
+    {
+
+        $this->initDocument('xml');
+        $this->elementStart('lists_list');
+        $this->elementStart('lists', array('type' => 'array'));
+
+        if (is_array($list)) {
+            foreach ($list as $l) {
+                $twitter_list = $this->twitterListArray($l);
+                $this->showTwitterXmlList($twitter_list);
+            }
+        } else {
+            while ($list->fetch()) {
+                $twitter_list = $this->twitterListArray($list);
+                $this->showTwitterXmlList($twitter_list);
+            }
+        }
+
+        $this->elementEnd('lists');
+
+        $this->element('next_cursor', null, $next_cursor);
+        $this->element('previous_cursor', null, $prev_cursor);
+
+        $this->elementEnd('lists_list');
+        $this->endDocument('xml');
+    }
+
+    function showJsonLists($list, $next_cursor=0, $prev_cursor=0)
+    {
+        $this->initDocument('json');
+
+        $lists = array();
+
+        if (is_array($list)) {
+            foreach ($list as $l) {
+                $twitter_list = $this->twitterListArray($l);
+                array_push($lists, $twitter_list);
+            }
+        } else {
+            while ($list->fetch()) {
+                $twitter_list = $this->twitterListArray($list);
+                array_push($lists, $twitter_list);
+            }
+        }
+
+        $lists_list = array(
+            'lists' => $lists,
+            'next_cursor' => $next_cursor,
+            'next_cursor_str' => strval($next_cursor),
+            'previous_cursor' => $prev_cursor,
+            'previous_cursor_str' => strval($prev_cursor)
+        );
+
+        $this->showJsonObjects($lists_list);
+
+        $this->endDocument('json');
+    }
+
     function showTwitterXmlUsers($user)
     {
         $this->initDocument('xml');
@@ -1172,6 +1240,22 @@ class ApiAction extends Action
         $this->endDocument('xml');
     }
 
+    function showSingleJsonList($list)
+    {
+        $this->initDocument('json');
+        $twitter_list = $this->twitterListArray($list);
+        $this->showJsonObjects($twitter_list);
+        $this->endDocument('json');
+    }
+
+    function showSingleXmlList($list)
+    {
+        $this->initDocument('xml');
+        $twitter_list = $this->twitterListArray($list);
+        $this->showTwitterXmlList($twitter_list);
+        $this->endDocument('xml');
+    }
+
     function dateTwitter($dt)
     {
         $dateStr = date('d F Y H:i:s', strtotime($dt));
@@ -1465,6 +1549,40 @@ class ApiAction extends Action
         }
     }
 
+    function getTargetList($user=null, $id=null)
+    {
+        $tagger = $this->getTargetUser($user);
+        $list = null;
+
+        if (empty($id)) {
+            $id = $this->arg('id');
+        }
+
+        if($id) {
+            if (is_numeric($id)) {
+                $list = Profile_list::staticGet('id', $id);
+
+                // only if the list with the id belongs to the tagger
+                if(empty($list) || $list->tagger != $tagger->id) {
+                    $list = null;
+                }
+            }
+            if (empty($list)) {
+                $tag = common_canonical_tag($id);
+                $list = Profile_list::getByTaggerAndTag($tagger->id, $tag);
+            }
+
+            if (!empty($list) && $list->private) {
+                if ($this->auth_user->id == $list->tagger) {
+                    return $list;
+                }
+            } else {
+                return $list;
+            }
+        }
+        return null;
+    }
+
     /**
      * Returns query argument or default value if not found. Certain
      * parameters used throughout the API are lightly scrubbed and