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