]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/featured.php
trac750 Add prefix string option in Facebook app for notice sync
[quix0rs-gnu-social.git] / actions / featured.php
index 01071912d66168ea38731a791d2a1bcc47922f59..2bf8b0b815cf2c8f1e909260b7694fd0ff79cbeb 100644 (file)
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  * GNU Affero General Public License for more details.
  *
  * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * along with this program.     If not, see <http://www.gnu.org/licenses/>.
  */
 
 if (!defined('LACONICA')) { exit(1); }
 
 require_once(INSTALLDIR.'/lib/stream.php');
+require_once(INSTALLDIR.'/lib/profilelist.php');
 
-class FeaturedAction extends StreamAction {
+class FeaturedAction extends StreamAction
+{
 
-       function handle($args) {
-               parent::handle($args);
+    function handle($args)
+    {
+        parent::handle($args);
 
-               $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+        $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
 
-               common_show_header(_('Featured timeline'),
-                                                  array($this, 'show_header'), NULL,
-                                                  array($this, 'show_top'));
+        common_show_header(_('Featured users'),
+                           array($this, 'show_header'), null,
+                           array($this, 'show_top'));
 
-               $this->show_notices($page);
+        $this->show_notices($page);
 
-               common_show_footer();
-       }
+        common_show_footer();
+    }
 
-       function show_top() {
-               if (common_logged_in()) {
-                       common_notice_form('public');
-               }
+    function show_top()
+    {
+        $instr = $this->get_instructions();
+        $output = common_markup_to_html($instr);
+        common_element_start('div', 'instructions');
+        common_raw($output);
+        common_element_end('div');
+        $this->public_views_menu();
+    }
 
-               $this->public_views_menu();
-       }
+    function show_header()
+    {
+    }
 
-       function show_header() {
+    function get_instructions()
+    {
+        return _('Featured users');
+    }
 
-               // XXX need to make the RSS feed for this
+    function show_notices($page)
+    {
 
-               //common_element('link', array('rel' => 'alternate',
-               //                                                       'href' => common_local_url('featuredrss'),
-               //                                                       'type' => 'application/rss+xml',
-               //                                                       'title' => _('Featured Stream Feed')));
+        // XXX: Note I'm doing it this two-stage way because a raw query
+        // with a JOIN was *not* working. --Zach
 
-       }
+        $featured_nicks = common_config('nickname', 'featured');
 
-       function show_notices($page) {
+        if (count($featured_nicks) > 0) {
 
-               $featured = common_config('nickname', 'featured');
+            $quoted = array();
 
-               if (count($featured) > 0) {
+            foreach ($featured_nicks as $nick) {
+                $quoted[] = "'$nick'";
+            }
 
-                       $id_list = array();
+            $user = new User;
+            $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
+            $user->limit(($page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
+            $user->orderBy('user.nickname ASC');
 
-                       foreach($featured as $featuree) {
-                               $profile = Profile::staticGet('nickname', trim($featuree));
-                               array_push($id_list, $profile->id);
-                       }
+            $user->find();
 
-                       // XXX: Show a list of users (people list) instead of shit crap
+            $profile_ids = array();
 
-                       $qry =
-                               'SELECT * ' .
-                               'FROM notice ' .
-                               'WHERE profile_id IN (%s) ';
+            while ($user->fetch()) {
+                $profile_ids[] = $user->id;
+            }
 
-                       $cnt = 0;
+            $profile = new Profile;
+            $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
+            $profile->orderBy('nickname ASC');
 
-                       $notice = Notice::getStream(sprintf($qry, implode($id_list, ',')),
-                               'featured_stream', ($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+            $cnt = $profile->find();
 
-                       if ($notice) {
-                               common_element_start('ul', array('id' => 'notices'));
-                               while ($notice->fetch()) {
-                                       $cnt++;
-                                       if ($cnt > NOTICES_PER_PAGE) {
-                                               break;
-                                       }
-                                       $this->show_notice($notice);
-                               }
-                               common_element_end('ul');
-                       }
+            if ($cnt > 0) {
+                $featured = new ProfileList($profile);
+                $featured->show_list();
+            }
 
-                       common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
-                                                         $page, 'featured');
+            $profile->free();
 
-               }
-       }
+            common_pagination($page > 1, $cnt > PROFILES_PER_PAGE, $page, 'featured');
+        }
+    }
 
 }
\ No newline at end of file