]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
Merge branch 'master', remote-tracking branch 'remotes/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 $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 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                 12
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,10",
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, 12",
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
134         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
135         $a->page['right_aside'] = replace_macros($tpl, $aside);
136         
137 }
138
139
140 //profile_side at networkpages
141 if ($a->argv[0] === "network"){
142
143         // USER MENU
144         if(local_user()) {
145                 
146                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
147                                 
148                 $userinfo = array(
149                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
150                                         'name' => $a->user['username'],
151                                 );      
152                 $ps = array('usermenu'=>array());
153                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
154                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
155                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
156                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
157                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
158                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
159                 $ps['usermenu']['pgroups'] = Array('http://dir.friendika.com/directory/forum', t('Public Groups'), "", "");
160
161                 $tpl = get_markup_template('profile_side.tpl');
162
163                 $a->page['aside'] .= replace_macros($tpl, array(
164                                 '$userinfo' => $userinfo,
165                                 '$ps' => $ps,
166                         ));
167
168         }
169         
170         // COMMUNITY
171         diabook_community_info();
172         
173         // CUSTOM CSS
174         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-network.css";
175         
176 }
177
178
179
180 //right_aside at profile pages
181 if ($a->argv[0] === "profile"){
182         
183         // COMMUNITY
184         diabook_community_info();
185         
186         // CUSTOM CSS
187         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-profile.css";
188         
189 }
190
191
192 // custom css
193 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
194
195 //js scripts
196
197 $a->page['htmlhead'] .= <<< EOT
198
199 <script>
200  $(function() {
201         $('a.lightbox').fancybox(); // Select all links with lightbox class
202  });
203  </script>
204 EOT;
205