c79655ea229d87fb2c6e2ed31423275583beaf19
[scuttle] / templates / bookmarks.tpl.php
1 <?php
2 $userservice     =& ServiceFactory::getServiceInstance('UserService');
3 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
4
5 $logged_on_userid = $userservice->getCurrentUserId();
6 $this->includeTemplate($GLOBALS['top_include']);
7
8 include 'search.inc.php';
9 if (count($bookmarks) > 0) {
10 ?>
11
12 <p id="sort">
13   <?php echo T_("Sort by:"); ?>
14   <a href="?sort=date_desc"><?php echo T_("Date"); ?></a><span> / </span>
15   <a href="?sort=title_asc"><?php echo T_("Title"); ?></a><span> / </span>
16   <?php if (!isset($hash)): ?>
17     <a href="?sort=url_asc"><?php echo T_("URL"); ?></a>
18   <?php endif; ?>
19 </p>
20 <ol<?php echo ($start > 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
21
22     <?php
23     foreach(array_keys($bookmarks) as $key) {
24         $row =& $bookmarks[$key];
25         switch ($row['bStatus']) {
26             case 0:
27                 $access = '';
28                 break;
29             case 1:
30                 $access = ' shared';
31                 break;
32             case 2:
33                 $access = ' private';
34                 break;
35         }
36
37         $cats = '';
38         $tags = $row['tags'];
39         foreach(array_keys($tags) as $key) {
40             $tag =& $tags[$key];
41             $cats .= '<a href="'. sprintf($cat_url, filter($user, 'url'), filter($tag, 'url')) .'" rel="tag">'. filter($tag) .'</a>, ';
42         }
43         $cats = substr($cats, 0, -2);
44         if ($cats != '') {
45             $cats = ' to '. $cats;
46         }
47
48         // Edit and delete links
49         $edit = '';
50         if ($bookmarkservice->editAllowed($row['bId'])) {
51             $edit = ' - <a href="'. createURL('edit', $row['bId']) .'">'. T_('Edit') .'</a><script type="text/javascript">document.write(" - <a href=\"#\" onclick=\"deleteBookmark(this, '. $row['bId'] .'); return false;\">'. T_('Delete') .'<\/a>");</script>';
52         }
53
54         // User attribution
55         $copy = '';
56         if (!isset($user) || isset($watched)) {
57             $copy = ' '. T_('by') .' <a href="'. createURL('bookmarks', $row['username']) .'">'. $row['username'] .'</a>';
58         }
59
60         // Udders!
61         if (!isset($hash)) {
62             $others = $bookmarkservice->countOthers($row['bAddress']);
63             $ostart = '<a href="'. createURL('history', $row['bHash']) .'">';
64             $oend = '</a>';
65             switch ($others) {
66                 case 0:
67                     break;
68                 case 1:
69                     $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend);
70                     break;
71                 default:
72                     $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend);
73             }
74         }
75
76         // Copy link
77         if ($userservice->isLoggedOn() && ($logged_on_userid != $row['uId'])) {
78             // Get the username of the current user
79             $currentUser = $userservice->getCurrentUser();
80             $currentUsername = $currentUser[$userservice->getFieldName('username')];
81             $copy .= ' - <a href="'. createURL('bookmarks', $currentUsername .'?action=add&amp;address='. urlencode($row['bAddress']) .'&amp;title='. urlencode($row['bTitle'])) .'">'. T_('Copy') .'</a>';   
82         }
83
84         // Nofollow option
85         $rel = '';
86         if ($GLOBALS['nofollow']) {
87             $rel = ' rel="nofollow"';
88         }
89
90         $address = filter($row['bAddress']);
91         
92         // Redirection option
93         if ($GLOBALS['useredir']) {
94             $address = $GLOBALS['url_redir'] . $address;
95         }
96         
97         // Output
98         echo '<li class="xfolkentry'. $access .'">'."\n";
99         echo '<div class="link"><a href="'. $address .'"'. $rel .' class="taggedlink">'. filter($row['bTitle']) ."</a></div>\n";
100         if ($row['bDescription'] != '') {
101             echo '<div class="description">'. filter($row['bDescription']) ."</div>\n";
102         }
103         echo '<div class="meta">'. date($GLOBALS['shortdate'], strtotime($row['bDatetime'])) . $cats . $copy . $edit ."</div>\n";
104         echo "</li>\n";
105     }
106     ?>
107
108 </ol>
109
110     <?php
111     // PAGINATION
112     
113     // Ordering
114     $sortOrder = '';
115     if (isset($_GET['sort'])) {
116         $sortOrder = 'sort='. $_GET['sort'];
117     }
118     
119     $sortAmp = (($sortOrder) ? '&amp;'. $sortOrder : '');
120     $sortQue = (($sortOrder) ? '?'. $sortOrder : '');
121     
122     // Previous
123     $perpage = getPerPageCount();
124     if (!$page || $page < 2) {
125         $page = 1;
126         $start = 0;
127         $bfirst = '<span class="disable">'. T_('First') .'</span>';
128         $bprev = '<span class="disable">'. T_('Previous') .'</span>';
129     } else {
130         $prev = $page - 1;
131         $prev = 'page='. $prev;
132         $start = ($page - 1) * $perpage;
133         $bfirst= '<a href="'. sprintf($nav_url, $user, $currenttag, '') . $sortQue .'">'. T_('First') .'</a>';
134         $bprev = '<a href="'. sprintf($nav_url, $user, $currenttag, '?') . $prev . $sortAmp .'">'. T_('Previous') .'</a>';
135     }
136     
137     // Next
138     $next = $page + 1;
139     $totalpages = ceil($total / $perpage);
140     if (count($bookmarks) < $perpage || $perpage * $page == $total) {
141         $bnext = '<span class="disable">'. T_('Next') .'</span>';
142         $blast = '<span class="disable">'. T_('Last') .'</span>';
143     } else {
144         $bnext = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $next . $sortAmp .'">'. T_('Next') .'</a>';
145         $blast = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $totalpages . $sortAmp .'">'. T_('Last') .'</a>';
146     }
147     echo '<p class="paging">'. $bfirst .'<span> / </span>'. $bprev .'<span> / </span>'. $bnext .'<span> / </span>'. $blast .'<span> / </span>'. sprintf(T_('Page %d of %d'), $page, $totalpages) .'</p>';
148 } else {
149 ?>
150
151     <p class="error"><?php echo T_('No bookmarks available'); ?>.</p>
152
153 <?php
154 }
155 $this->includeTemplate('sidebar.tpl');
156 $this->includeTemplate($GLOBALS['bottom_include']);
157 ?>

Benjamin Mako Hill || Want to submit a patch?