623ed89d8f7c31c0ec36e3b40ee3e63de27b0854
[friendica-addons.git] / viewsrc / viewsrc.php
1 <?php
2
3
4 /**
5  * Name: viewsrc
6  * Description: Add "View Source" link to item context
7  * Version: 1.0
8  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
9  *
10  */
11
12 function viewsrc_install() {
13         register_hook('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu');
14         register_hook('page_end', 'addon/viewsrc/viewsrc.php', 'viewsrc_page_end');
15 }
16
17
18 function viewsrc_uninstall() {
19         unregister_hook('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu');
20         unregister_hook('page_end', 'addon/viewsrc/viewsrc.php', 'viewsrc_page_end');
21
22 }
23
24 function viewsrc_page_end(&$a, &$o){
25         $a->page['htmlhead'] .= <<< EOS
26         <script>
27                 $(function(){
28                         $('a[href*="/viewsrc/"]').each(function() {
29                                 $(this).colorbox($(this).attr('href'));
30                         });
31                 });
32         </script>
33 EOS;
34 }
35
36 function viewsrc_item_photo_menu(&$a,&$b) {
37         if(!local_user())
38                 return;
39
40         if (local_user() != $b['item']['uid']) {
41                 $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s'",
42                                 intval(local_user()), dbesc($b['item']['guid']));
43
44                 if (!$r)
45                         return;
46
47                 $item_id = $r[0]['id'];
48
49         } else
50                 $item_id = $b['item']['id'];
51
52         $b['menu'] = array_merge( [ t('View Source') => $a->get_baseurl() . '/viewsrc/'. $item_id], $b['menu']);
53
54         //if((! local_user()) || (local_user() != $b['item']['uid']))
55         //      return;
56
57         //$b['menu'] = array_merge( array( t('View Source') => $a->get_baseurl() . '/viewsrc/'. $b['item']['id']), $b['menu']);
58
59 }