]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
de003b27d5664d5a3f0f6909066242bbcaa273bd
[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: (Version: 1.025)
7  * Author: 
8  */
9
10 $a = get_app();
11 $a->theme_info = array(
12     'family' => 'diabook',
13         'version' => '1.025'
14 );
15
16 function diabook_init(&$a) {
17         
18 //print diabook-version for debugging
19 $diabook_version = "Diabook (Version: 1.025)";
20 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
21
22 //change css on network and profilepages
23 $cssFile = null;
24
25 $resolution=false;
26 $resolution = get_pconfig(local_user(), "diabook", "resolution");
27 if ($resolution===false) $resolution="normal";
28
29 $color = false;
30 $site_color = get_config("diabook", "color" );
31 if (local_user()) {$color = get_pconfig(local_user(), "diabook", "color");}
32 if ($color===false) $color=$site_color;
33 if ($color===false) $color="diabook";
34
35 if ($color=="diabook") $color_path = "/";
36 if ($color=="aerith") $color_path = "/diabook-aerith/";
37 if ($color=="blue") $color_path = "/diabook-blue/";
38 if ($color=="red") $color_path = "/diabook-red/";
39 if ($color=="pink") $color_path = "/diabook-pink/";
40 if ($color=="green") $color_path = "/diabook-green/";
41 if ($color=="dark") $color_path = "/diabook-dark/";
42
43
44         //profile_side at networkpages
45         if ($a->argv[0] === "network" && local_user()){
46
47         // USER MENU
48         if(local_user()) {
49                 
50                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
51                                 
52                 $userinfo = array(
53                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
54                                         'name' => $a->user['username'],
55                                 );      
56                 $ps = array('usermenu'=>array());
57                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
58                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
59                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                                
60                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
61                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
62                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
63                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
64                 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
65
66                 $tpl = get_markup_template('profile_side.tpl');
67
68                 $a->page['aside'] = replace_macros($tpl, array(
69                                 '$userinfo' => $userinfo,
70                                 '$ps' => $ps,
71                         )).$a->page['aside'];
72
73         }
74         
75         $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_profiles'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_twitter'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
76         
77         if($ccCookie != "9") {
78         // COMMUNITY
79         diabook_community_info();
80
81         // CUSTOM CSS
82         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
83         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
84         }
85         }
86
87
88
89         //right_aside at profile pages
90         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
91         if($ccCookie != "9") {
92         // COMMUNITY
93         diabook_community_info();
94         
95         // CUSTOM CSS
96         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
97         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
98         
99         }
100         }
101         
102         //js scripts
103         //load jquery.cookie.js
104         $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
105         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
106         
107         //load jquery.ae.image.resize.js
108         $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
109         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
110         
111         //load jquery.twitter.search.js
112         $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
113         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $twitterJS);
114                 
115         $a->page['htmlhead'] .= '
116         <script>
117         
118          $(function() {
119                 $("a.lightbox").fancybox(); // Select all links with lightbox class
120                 $("#twitter").twitterSearch({               
121                 term: "friendica",
122                 animInSpeed: 250,
123                 bird:    false, 
124                 avatar:  false, 
125                 colorExterior: "#fff",
126                 title: "Last Tweets",
127                 timeout: 10000          });
128          });
129            
130          $(window).load(function() {
131                 var footer_top = $(document).height() - 30;
132                 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
133          });
134         </script>';
135         //check if community_home-plugin is activated and change css
136         $nametocheck = "communityhome";
137         $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
138         if(count($r) == "1") {
139         
140         $a->page['htmlhead'] .= '
141         <script>
142         $(document).ready(function() {
143         $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
144         });
145         </script>';     
146         }
147         //comment-edit-wrapper on photo_view
148         if ($a->argv[0].$a->argv[2] === "photos"."image"){
149         $a->page['htmlhead'] .= '
150         <script>
151                 $(function(){
152                 $(".comment-edit-form").css("display","table");
153                         });
154     </script>';
155         }
156         //restore right hand col at settingspage
157         if($a->argv[0] === "settings" && local_user()) {
158         $a->page['htmlhead'] .= ' 
159         <script>
160         function restore_boxes(){
161         $.cookie("close_pages","2", { expires: 365, path: "/" });
162         $.cookie("close_helpers","2", { expires: 365, path: "/" });
163         $.cookie("close_profiles","2", { expires: 365, path: "/" });
164         $.cookie("close_services","2", { expires: 365, path: "/" });
165         $.cookie("close_friends","2", { expires: 365, path: "/" });
166         $.cookie("close_twitter","2", { expires: 365, path: "/" });
167         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
168         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
169         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
170         alert("Right-hand column was restored. Please refresh your browser");
171    }
172         </script>';}
173         
174         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
175         $a->page['htmlhead'] .= '
176         <script>
177
178         $(function() {
179         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
180         });
181         </script>';
182         
183         if($ccCookie != "9") {
184         $a->page['htmlhead'] .= '
185         <script>
186         $("right_aside").ready(function(){
187         
188         if($.cookie("close_pages") == "1") 
189                 {
190                 document.getElementById( "close_pages" ).style.display = "none";
191                         };
192                         
193         if($.cookie("close_profiles") == "1") 
194                 {
195                 document.getElementById( "close_profiles" ).style.display = "none";
196                         };
197         
198         if($.cookie("close_helpers") == "1") 
199                 {
200                 document.getElementById( "close_helpers" ).style.display = "none";
201                         };
202                         
203         if($.cookie("close_services") == "1") 
204                 {
205                 document.getElementById( "close_services" ).style.display = "none";
206                         };
207                         
208         if($.cookie("close_friends") == "1") 
209                 {
210                 document.getElementById( "close_friends" ).style.display = "none";
211                         };
212         
213         if($.cookie("close_twitter") == "1") 
214                 {
215                 document.getElementById( "twitter" ).style.display = "none";
216                         };      
217                         
218         if($.cookie("close_lastusers") == "1") 
219                 {
220                 document.getElementById( "close_lastusers" ).style.display = "none";
221                         };
222                         
223         if($.cookie("close_lastphotos") == "1") 
224                 {
225                 document.getElementById( "close_lastphotos" ).style.display = "none";
226                         };
227                         
228         if($.cookie("close_lastlikes") == "1") 
229                 {
230                 document.getElementById( "close_lastlikes" ).style.display = "none";
231                         };}
232
233         );
234
235         function close_pages(){
236          document.getElementById( "close_pages" ).style.display = "none";
237         $.cookie("close_pages","1", { expires: 365, path: "/" });
238         };
239  
240         function close_profiles(){
241         document.getElementById( "close_profiles" ).style.display = "none";
242         $.cookie("close_profiles","1", { expires: 365, path: "/" });
243         };
244  
245         function close_helpers(){
246         document.getElementById( "close_helpers" ).style.display = "none";
247         $.cookie("close_helpers","1", { expires: 365, path: "/" });
248         };
249
250         function close_services(){
251         document.getElementById( "close_services" ).style.display = "none";
252         $.cookie("close_services","1", { expires: 365, path: "/" });
253         };
254  
255         function close_friends(){
256          document.getElementById( "close_friends" ).style.display = "none";
257          $.cookie("close_friends","1", { expires: 365, path: "/" });
258          };
259  
260         function close_twitter(){
261         document.getElementById( "twitter" ).style.display = "none";
262          $.cookie("close_twitter","1", { expires: 365, path: "/" });
263         };
264  
265         function close_lastusers(){
266          document.getElementById( "close_lastusers" ).style.display = "none";
267         $.cookie("close_lastusers","1", { expires: 365, path: "/" });
268          };
269
270         function close_lastphotos(){
271         document.getElementById( "close_lastphotos" ).style.display = "none";
272          $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
273          };
274  
275         function close_lastlikes(){
276          document.getElementById( "close_lastlikes" ).style.display = "none";
277          $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
278          };
279         </script>';}
280         }
281         //end js scripts
282
283         // custom css
284         if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
285
286         //footer
287         $tpl = get_markup_template('footer.tpl');
288         $a->page['footer'] .= replace_macros($tpl, array());
289         
290         //
291         js_in_foot();
292 }
293
294
295  function diabook_community_info() {
296         $a = get_app();
297         // comunity_profiles
298         $aside['$comunity_profilest_title'] = t('Community Profiles');
299         $aside['$comunity_profiles_items'] = array();
300         $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id 
301                           where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
302         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
303         if(count($r)) {
304                 $photo = 'photo';
305                 foreach($r as $rr) {
306                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
307                         $entry = replace_macros($tpl,array(
308                                 '$id' => $rr['id'],
309                                 '$profile-link' => zrl($rr['url']),
310                                 '$photo' => $rr[$photo],
311                                 '$alt-text' => $rr['name'],
312                         ));
313                         $aside['$comunity_profiles_items'][] = $entry;
314                 }
315         }
316
317         // last 12 users
318         $aside['$lastusers_title'] = t('Last users');
319         $aside['$lastusers_items'] = array();
320         $sql_extra = "";
321         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
322         $order = " ORDER BY `register_date` DESC ";
323
324         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
325                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
326                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
327                 0,
328                 9
329         );
330         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
331         if(count($r)) {
332                 $photo = 'thumb';
333                 foreach($r as $rr) {
334                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
335                         $entry = replace_macros($tpl,array(
336                                 '$id' => $rr['id'],
337                                 '$profile-link' => $profile_link,
338                                 '$photo' => $rr[$photo],
339                                 '$alt-text' => $rr['name'],
340                         ));
341                         $aside['$lastusers_items'][] = $entry;
342                 }
343         }
344         
345         
346         // last 10 liked items
347         $aside['$like_title'] = t('Last likes');
348         $aside['$like_items'] = array();
349         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
350                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
351                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
352                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
353                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
354                         GROUP BY `uri`
355                         ORDER BY `T1`.`created` DESC
356                         LIMIT 0,5",
357                         $a->get_baseurl(),$a->get_baseurl()
358                         );
359
360         foreach ($r as $rr) {
361                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
362                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
363                 
364                 //var_dump($rr['verb'],$rr['object-type']); killme();
365                 switch($rr['verb']){
366                         case 'http://activitystrea.ms/schema/1.0/post':
367                                 switch ($rr['object-type']){
368                                         case 'http://activitystrea.ms/schema/1.0/event':
369                                                 $post_type = t('event');
370                                                 break;
371                                         default:
372                                                 $post_type = t('status');
373                                 }
374                                 break;
375                         default:
376                                 if ($rr['resource-id']){
377                                         $post_type = t('photo');
378                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
379                                         $rr['plink'] = $m[1];
380                                 } else {
381                                         $post_type = t('status');
382                                 }
383                 }
384                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
385
386                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
387                 
388         }
389         
390         
391         // last 12 photos
392         $aside['$photos_title'] = t('Last photos');
393         $aside['$photos_items'] = array();
394         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
395                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
396                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
397                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
398                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
399                                 `user` 
400                                 WHERE `user`.`uid` = `photo`.`uid`
401                                 AND `user`.`blockwall`=0
402                                 AND `user`.`hidewall`=0
403                                 ORDER BY `photo`.`edited` DESC
404                                 LIMIT 0, 9",
405                                 dbesc(t('Contact Photos')),
406                                 dbesc(t('Profile Photos'))
407                                 );
408                 if(count($r)) {
409                 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
410                 foreach($r as $rr) {
411                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
412                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
413                 
414                         $entry = replace_macros($tpl,array(
415                                 '$id' => $rr['id'],
416                                 '$profile-link' => $photo_page,
417                                 '$photo' => $photo_url,
418                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
419                         ));
420
421                         $aside['$photos_items'][] = $entry;
422                 }
423         }
424         
425    
426    //right_aside FIND FRIENDS
427         if(local_user()) {
428         $nv = array();
429         $nv['title'] = Array("", t('Find Friends'), "", "");
430         $nv['directory'] = Array('directory', t('Local Directory'), "", "");
431         $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
432         $nv['match'] = Array('match', t('Similar Interests'), "", "");
433         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
434         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
435         
436         $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
437                                                 <span class="sbox_l"></span>
438                                                 <span class="sbox">
439                                                 <input type="text" name="search" size="13" maxlength="50">
440                                                 </span>
441                                                 <span class="sbox_r" id="srch_clear"></span>';
442         
443         $aside['$nv'] = $nv;
444         };
445    
446    //Community_Pages at right_aside
447    if(local_user()) {
448    $page = '<div id="" >
449                         <h3 style="margin-top:0px;">'.t("Community Pages").'<a id="close_pages_icon"  onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
450                         <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
451
452         $pagelist = array();
453
454         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
455                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
456                         ORDER BY `name` ASC",
457                         intval($a->user['uid'])
458         );
459
460         $pageD = array();
461
462         // Look if the profile is a community page
463         foreach($contacts as $contact) {
464                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
465         };
466         
467
468         $contacts = $pageD;
469
470         foreach($contacts as $contact) {
471                 $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; word-wrap: break-word; width: 132px;" title="' . $contact['url'] . '" class="label" target="external-link">'.
472                                 $contact["name"]."</a></li>";
473         }
474         $page .= '</ul></div></div>';
475         //if (sizeof($contacts) > 0)
476                 $aside['$page'] = $page;        
477         }
478   //END Community Page  
479   //helpers
480    $helpers = array();
481         $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
482         $aside['$helpers'] = $helpers;
483    //end helpers
484    //connectable services
485    $con_services = array();
486         $con_services['title'] = Array("", t('Connect Services'), "", "");
487         $aside['$con_services'] = $con_services;
488    //end connectable services
489    //get_baseurl
490    $url = $a->get_baseurl($ssl_state);   
491    $aside['$url'] = $url;
492         //print right_aside
493         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
494         $a->page['right_aside'] = replace_macros($tpl, $aside);
495         
496  }
497
498  function js_in_foot() {
499         /** @purpose insert stuff in bottom of page
500          */
501         $a = get_app();
502         $baseurl = $a->get_baseurl($ssl_state);
503         $bottom['$baseurl'] = $baseurl;
504         $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
505         $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);
506  }
507
508
509
510
511
512
513
514  
515  
516
517  
518