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