]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
small fix
[friendica.git] / view / theme / diabook / theme.php
1 <?php
2
3 /*
4  * Name: Diabook
5  * Description: Diabook: report bugs and request here: http://pad.toktan.org/p/diabook or contact me : thomas_bierey@friendica.eu
6  * Version: 
7  * Author: 
8  */
9
10 $a->theme_info = array(
11   'extends' => 'diabook',
12 );
13
14 //change css on network and profilepages
15 $cssFile = null;
16
17
18 /**
19  * prints last community activity
20  */
21
22
23  
24 function diabook_community_info(){
25         $a = get_app();
26         //right_aside at networkpages
27
28         // last 12 users
29         $aside['$lastusers_title'] = t('Last users');
30         $aside['$lastusers_items'] = array();
31         $sql_extra = "";
32         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
33         $order = " ORDER BY `register_date` DESC ";
34
35         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
36                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
37                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
38                 0,
39                 9
40         );
41         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
42         if(count($r)) {
43                 $photo = 'thumb';
44                 foreach($r as $rr) {
45                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
46                         $entry = replace_macros($tpl,array(
47                                 '$id' => $rr['id'],
48                                 '$profile-link' => $profile_link,
49                                 '$photo' => $rr[$photo],
50                                 '$alt-text' => $rr['name'],
51                         ));
52                         $aside['$lastusers_items'][] = $entry;
53                 }
54         }
55         
56         
57         // last 10 liked items
58         $aside['$like_title'] = t('Last likes');
59         $aside['$like_items'] = array();
60         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
61                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
62                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
63                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
64                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
65                         GROUP BY `uri`
66                         ORDER BY `T1`.`created` DESC
67                         LIMIT 0,5",
68                         $a->get_baseurl(),$a->get_baseurl()
69                         );
70
71         foreach ($r as $rr) {
72                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
73                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
74                 
75                 //var_dump($rr['verb'],$rr['object-type']); killme();
76                 switch($rr['verb']){
77                         case 'http://activitystrea.ms/schema/1.0/post':
78                                 switch ($rr['object-type']){
79                                         case 'http://activitystrea.ms/schema/1.0/event':
80                                                 $post_type = t('event');
81                                                 break;
82                                         default:
83                                                 $post_type = t('status');
84                                 }
85                                 break;
86                         default:
87                                 if ($rr['resource-id']){
88                                         $post_type = t('photo');
89                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
90                                         $rr['plink'] = $m[1];
91                                 } else {
92                                         $post_type = t('status');
93                                 }
94                 }
95                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
96
97                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
98                 
99         }
100         
101         
102         // last 12 photos
103         $aside['$photos_title'] = t('Last photos');
104         $aside['$photos_items'] = array();
105         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
106                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
107                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
108                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
109                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
110                                 `user` 
111                                 WHERE `user`.`uid` = `photo`.`uid`
112                                 AND `user`.`blockwall`=0
113                                 AND `user`.`hidewall`=0
114                                 ORDER BY `photo`.`edited` DESC
115                                 LIMIT 0, 9",
116                                 dbesc(t('Contact Photos')),
117                                 dbesc(t('Profile Photos'))
118                                 );
119                 if(count($r)) {
120                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
121                 foreach($r as $rr) {
122                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
123                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
124                 
125                         $entry = replace_macros($tpl,array(
126                                 '$id' => $rr['id'],
127                                 '$profile-link' => $photo_page,
128                                 '$photo' => $photo_url,
129                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
130                         ));
131
132                         $aside['$photos_items'][] = $entry;
133                 }
134         }
135         
136         $fostitJS = "javascript: (function() {
137                                         the_url = '".$a->get_baseurl($ssl_state)."/view/theme/diabook/fpostit/fpostit.php?url=' + encodeURIComponent(window.location.href) + '&title=' + encodeURIComponent(document.title) + '&text=' + encodeURIComponent(''+(window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text));
138                                                 a_funct = function() {
139                                                         if (!window.open(the_url, 'fpostit', 'location=yes,links=no,scrollbars=no,toolbar=no,width=600,height=300')) location.href = the_url};
140                                                         if (/Firefox/.test(navigator.userAgent)) {setTimeout(a_funct, 0)} 
141                                                         else {a_funct()}})()" ;
142   
143    $aside['$fostitJS'] = $fostitJS;
144    
145    //Community Page
146    $page = '<div id="page-sidebar-right_aside" class="widget">
147                         <div class="title tool">
148                         <h3>'.t("Community Pages").'</h3></div>
149                         <div id="sidebar-page-list"><ul>';
150
151         $pagelist = array();
152
153         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
154                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d",
155                         intval($a->user['uid'])
156         );
157
158         $pageD = array();
159
160         // Look if the profile is a community page
161         foreach($contacts as $contact) {
162                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
163         };
164         
165
166         $contacts = $pageD;
167
168         foreach($contacts as $contact) {
169                 $page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" style="float: left; margin-right: 3px;" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" style="margin-top: 2px;" title="' . $contact['url'] . '" class="label" target="external-link">'.
170                                 $contact["name"]."</a></li>";
171         }
172         $page .= '</ul></div></div>';
173         if (sizeof($contacts) > 0)
174                 
175                 $aside['$page'] = $page;
176   //END Community Page          
177      
178    
179    $url = $a->get_baseurl($ssl_state);   
180    $aside['$url'] = $url;
181
182         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
183         $a->page['right_aside'] = replace_macros($tpl, $aside);
184         
185         
186         
187         
188 }
189
190
191 //profile_side at networkpages
192 if ($a->argv[0] === "network" && local_user()){
193
194         // USER MENU
195         if(local_user()) {
196                 
197                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
198                                 
199                 $userinfo = array(
200                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
201                                         'name' => $a->user['username'],
202                                 );      
203                 $ps = array('usermenu'=>array());
204                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
205                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
206                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
207                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
208                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
209                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
210                 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Public Groups'), "", "");
211
212                 $tpl = get_markup_template('profile_side.tpl');
213
214                 $a->page['aside'] .= replace_macros($tpl, array(
215                                 '$userinfo' => $userinfo,
216                                 '$ps' => $ps,
217                         ));
218
219         }
220         
221         // COMMUNITY
222         diabook_community_info();
223         
224         // CUSTOM CSS
225         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-network.css";
226         
227 }
228
229
230
231 //right_aside at profile pages
232 if ($a->argv[0] === "profile"){
233         
234         // COMMUNITY
235         diabook_community_info();
236         
237         // CUSTOM CSS
238         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-profile.css";
239         
240 }
241
242
243 // custom css
244 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
245
246 //js scripts
247
248 $a->page['htmlhead'] .= <<< EOT
249
250 <script>
251  $(function() {
252         $('a.lightbox').fancybox(); // Select all links with lightbox class
253  });
254  
255  
256  
257  </script>
258 EOT;
259