]> git.mxchange.org Git - friendica-addons.git/blob - viewsrc/viewsrc.php
10f883593af3ef2efa79a718733aad419e7f23a2
[friendica-addons.git] / viewsrc / viewsrc.php
1 <?php
2 /**
3  * Name: viewsrc
4  * Description: Add "View Source" link to item context
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  *
8  */
9 use Friendica\Core\Hook;
10 use Friendica\DI;
11 use Friendica\Model\Item;
12 use Friendica\Database\DBA;
13
14 function viewsrc_install() {
15         Hook::register('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu');
16         Hook::register('page_end', 'addon/viewsrc/viewsrc.php', 'viewsrc_page_end');
17 }
18
19
20 function viewsrc_uninstall() {
21         Hook::unregister('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu');
22         Hook::unregister('page_end', 'addon/viewsrc/viewsrc.php', 'viewsrc_page_end');
23
24 }
25
26 function viewsrc_page_end(&$a, &$o){
27         DI::page()['htmlhead'] .= <<< EOS
28         <script>
29                 $(function(){
30                         $('a[href*="/viewsrc/"]').each(function() {
31                                 $(this).colorbox($(this).attr('href'));
32                         });
33                 });
34         </script>
35 EOS;
36 }
37
38 function viewsrc_item_photo_menu(&$a, &$b)
39 {
40         if (!local_user()) {
41                 return;
42         }
43
44         if (local_user() != $b['item']['uid']) {
45                 $item = Item::selectFirstForUser(local_user(), ['id'], ['uid' => local_user(), 'guid' => $b['item']['guid']]);
46                 if (!DBA::isResult($item)) {
47                         return;
48                 }
49
50                 $item_id = $item['id'];
51         } else {
52                 $item_id = $b['item']['id'];
53         }
54
55         $b['menu'] = array_merge([DI::l10n()->t('View Source') => DI::baseUrl()->get() . '/viewsrc/'. $item_id], $b['menu']);
56
57         //if((! local_user()) || (local_user() != $b['item']['uid']))
58         //      return;
59
60         //$b['menu'] = array_merge(array(DI::l10n()->t('View Source') => $a->getBaseURL() . '/viewsrc/'. $b['item']['id']), $b['menu']);
61 }