]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
076223a48c721b5199f701909315016dcbd1f121
[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
11 //change css on network and profilepages
12 $cssFile = null;
13
14
15 /**
16  * prints last community activity
17  */
18
19
20  
21 function diabook_community_info(){
22         $a = get_app();
23         //right_aside at networkpages
24
25         // last 12 users
26         $aside['$lastusers_title'] = t('Last users');
27         $aside['$lastusers_items'] = array();
28         $sql_extra = "";
29         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
30         $order = " ORDER BY `register_date` DESC ";
31
32         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
33                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
34                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
35                 0,
36                 9
37         );
38         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
39         if(count($r)) {
40                 $photo = 'thumb';
41                 foreach($r as $rr) {
42                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
43                         $entry = replace_macros($tpl,array(
44                                 '$id' => $rr['id'],
45                                 '$profile-link' => $profile_link,
46                                 '$photo' => $rr[$photo],
47                                 '$alt-text' => $rr['name'],
48                         ));
49                         $aside['$lastusers_items'][] = $entry;
50                 }
51         }
52         
53         
54         // last 10 liked items
55         $aside['$like_title'] = t('Last likes');
56         $aside['$like_items'] = array();
57         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
58                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
59                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
60                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
61                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
62                         GROUP BY `uri`
63                         ORDER BY `T1`.`created` DESC
64                         LIMIT 0,5",
65                         $a->get_baseurl(),$a->get_baseurl()
66                         );
67
68         foreach ($r as $rr) {
69                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
70                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
71                 
72                 //var_dump($rr['verb'],$rr['object-type']); killme();
73                 switch($rr['verb']){
74                         case 'http://activitystrea.ms/schema/1.0/post':
75                                 switch ($rr['object-type']){
76                                         case 'http://activitystrea.ms/schema/1.0/event':
77                                                 $post_type = t('event');
78                                                 break;
79                                         default:
80                                                 $post_type = t('status');
81                                 }
82                                 break;
83                         default:
84                                 if ($rr['resource-id']){
85                                         $post_type = t('photo');
86                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
87                                         $rr['plink'] = $m[1];
88                                 } else {
89                                         $post_type = t('status');
90                                 }
91                 }
92                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
93
94                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
95                 
96         }
97         
98         
99         // last 12 photos
100         $aside['$photos_title'] = t('Last photos');
101         $aside['$photos_items'] = array();
102         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
103                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
104                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
105                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
106                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
107                                 `user` 
108                                 WHERE `user`.`uid` = `photo`.`uid`
109                                 AND `user`.`blockwall`=0
110                                 AND `user`.`hidewall`=0
111                                 ORDER BY `photo`.`edited` DESC
112                                 LIMIT 0, 9",
113                                 dbesc(t('Contact Photos')),
114                                 dbesc(t('Profile Photos'))
115                                 );
116                 if(count($r)) {
117                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
118                 foreach($r as $rr) {
119                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
120                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
121                 
122                         $entry = replace_macros($tpl,array(
123                                 '$id' => $rr['id'],
124                                 '$profile-link' => $photo_page,
125                                 '$photo' => $photo_url,
126                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
127                         ));
128
129                         $aside['$photos_items'][] = $entry;
130                 }
131         }
132         
133         $fostitJS = "javascript: (function() {
134                                         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));
135                                                 a_funct = function() {
136                                                         if (!window.open(the_url, 'fpostit', 'location=yes,links=no,scrollbars=no,toolbar=no,width=600,height=300')) location.href = the_url};
137                                                         if (/Firefox/.test(navigator.userAgent)) {setTimeout(a_funct, 0)} 
138                                                         else {a_funct()}})()" ;
139   
140    $aside['$fostitJS'] = $fostitJS;
141    
142    //right_aside FIND FRIENDS
143         if(local_user()) {
144         $nv = array();
145         $nv['directory'] = Array('directory', t('Directory'), "", "");
146         $nv['match'] = Array('match', t('Similar Interests'), "", "");
147         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
148         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
149         
150         $aside['$nv'] = $nv;
151         };
152    
153    //Community Page
154    if(local_user()) {
155    $page = '<div id="page-sidebar-right_aside" class="widget">
156                         <div class="title tool">
157                         <h3>'.t("Community Pages").'<a id="close_pages_icon"  onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
158                         <div id="sidebar-page-list"><ul>';
159
160         $pagelist = array();
161
162         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
163                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d",
164                         intval($a->user['uid'])
165         );
166
167         $pageD = array();
168
169         // Look if the profile is a community page
170         foreach($contacts as $contact) {
171                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
172         };
173         
174
175         $contacts = $pageD;
176
177         foreach($contacts as $contact) {
178                 $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">'.
179                                 $contact["name"]."</a></li>";
180         }
181         $page .= '</ul></div></div>';
182         //if (sizeof($contacts) > 0)
183                 
184                 $aside['$page'] = $page;        
185         }
186   //END Community Page          
187      
188    
189    $url = $a->get_baseurl($ssl_state);   
190    $aside['$url'] = $url;
191
192         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
193         $a->page['right_aside'] = replace_macros($tpl, $aside);
194         
195         
196         
197         
198 }
199
200
201 //profile_side at networkpages
202 if ($a->argv[0] === "network" && local_user()){
203
204         // USER MENU
205         if(local_user()) {
206                 
207                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
208                                 
209                 $userinfo = array(
210                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
211                                         'name' => $a->user['username'],
212                                 );      
213                 $ps = array('usermenu'=>array());
214                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
215                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
216                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                                
217                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
218                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
219                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
220                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
221                 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
222
223                 $tpl = get_markup_template('profile_side.tpl');
224
225                 $a->page['aside'] .= replace_macros($tpl, array(
226                                 '$userinfo' => $userinfo,
227                                 '$ps' => $ps,
228                         ));
229
230         }
231         
232         $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_postit'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
233         
234         if($ccCookie != "8") {
235         // COMMUNITY
236         diabook_community_info();
237         
238         // CUSTOM CSS
239         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-network.css";
240         }
241 }
242
243
244
245 //right_aside at profile pages
246 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
247         if($ccCookie != "8") {
248         // COMMUNITY
249         diabook_community_info();
250         
251         // CUSTOM CSS
252         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-profile.css";
253         
254         
255         }
256 }
257
258 // custom css
259 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
260
261 //load jquery.cookie.js
262 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-blue/js/jquery.cookie.js";
263 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" />', $cookieJS);
264
265 //js scripts
266
267 $a->page['htmlhead'] .= <<< EOT
268
269 <script>
270  $(function() {
271         $('a.lightbox').fancybox(); // Select all links with lightbox class
272  });
273   
274  </script>
275
276 <script>
277
278 $("right_aside").ready(function(){
279         
280         if($.cookie('close_pages') == '1') 
281                 {
282                 document.getElementById( "close_pages" ).style.display = "none";
283                         };
284         
285         if($.cookie('close_helpers') == '1') 
286                 {
287                 document.getElementById( "close_helpers" ).style.display = "none";
288                         };
289                         
290         if($.cookie('close_services') == '1') 
291                 {
292                 document.getElementById( "close_services" ).style.display = "none";
293                         };
294                         
295         if($.cookie('close_friends') == '1') 
296                 {
297                 document.getElementById( "close_friends" ).style.display = "none";
298                         };
299         
300         if($.cookie('close_postit') == '1') 
301                 {
302                 document.getElementById( "close_postit" ).style.display = "none";
303                         };
304                         
305         if($.cookie('close_lastusers') == '1') 
306                 {
307                 document.getElementById( "close_lastusers" ).style.display = "none";
308                         };
309                         
310         if($.cookie('close_lastphotos') == '1') 
311                 {
312                 document.getElementById( "close_lastphotos" ).style.display = "none";
313                         };
314                         
315         if($.cookie('close_lastlikes') == '1') 
316                 {
317                 document.getElementById( "close_lastlikes" ).style.display = "none";
318                         };}
319
320 );
321
322 function close_pages(){
323  document.getElementById( "close_pages" ).style.display = "none";
324  $.cookie('close_pages','1', { expires: 365, path: '/' });
325  };
326  
327 function close_helpers(){
328  document.getElementById( "close_helpers" ).style.display = "none";
329   $.cookie('close_helpers','1', { expires: 365, path: '/' });
330  };
331
332 function close_services(){
333  document.getElementById( "close_services" ).style.display = "none";
334  $.cookie('close_services','1', { expires: 365, path: '/' });
335  };
336  
337 function close_friends(){
338  document.getElementById( "close_friends" ).style.display = "none";
339  $.cookie('close_friends','1', { expires: 365, path: '/' });
340  };
341
342 function close_postit(){
343  document.getElementById( "close_postit" ).style.display = "none";
344  $.cookie('close_postit','1', { expires: 365, path: '/' });
345  };
346  
347 function close_lastusers(){
348  document.getElementById( "close_lastusers" ).style.display = "none";
349  $.cookie('close_lastusers','1', { expires: 365, path: '/' });
350  };
351
352 function close_lastphotos(){
353  document.getElementById( "close_lastphotos" ).style.display = "none";
354  $.cookie('close_lastphotos','1', { expires: 365, path: '/' });
355  };
356  
357 function close_lastlikes(){
358  document.getElementById( "close_lastlikes" ).style.display = "none";
359  $.cookie('close_lastlikes','1', { expires: 365, path: '/' });
360  };
361  
362  
363
364 function restore_boxes(){
365         $.cookie('close_pages','2', { expires: 365, path: '/' });
366         $.cookie('close_helpers','2', { expires: 365, path: '/' });
367         $.cookie('close_services','2', { expires: 365, path: '/' });
368         $.cookie('close_friends','2', { expires: 365, path: '/' });
369         $.cookie('close_postit','2', { expires: 365, path: '/' });
370         $.cookie('close_lastusers','2', { expires: 365, path: '/' });
371         $.cookie('close_lastphotos','2', { expires: 365, path: '/' });
372         $.cookie('close_lastlikes','2', { expires: 365, path: '/' });
373         alert('Right-hand column was restored');
374   };
375
376  
377 </script>
378  
379  
380 EOT;
381