]> git.mxchange.org Git - friendica.git/blob - mod/hovercard.php
Move Object\Contact to Model\Contact
[friendica.git] / mod / hovercard.php
1 <?php
2
3 /**
4  * Name: Frio Hovercard
5  * Description: Hovercard addon for the frio theme
6  * Version: 0.1
7  * Author: Rabuzarus <https://github.com/rabuzarus>
8  * License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
9  */
10
11 use Friendica\App;
12 use Friendica\Core\Config;
13 use Friendica\Model\Contact;
14 use Friendica\Model\GlobalContact;
15
16 function hovercard_init(App $a) {
17         // Just for testing purposes
18         $_GET["mode"] = "minimal";
19 }
20
21 function hovercard_content() {
22         $profileurl     =       (x($_REQUEST,'profileurl')      ? $_REQUEST['profileurl']       : "");
23         $datatype       =       (x($_REQUEST,'datatype')        ?$_REQUEST['datatype']          : "json");
24
25         // Get out if the system doesn't have public access allowed
26         if(intval(Config::get('system','block_public')))
27                 http_status_exit(401);
28
29         // Return the raw content of the template. We use this to make templates usable for js functions.
30         // Look at hovercard.js (function getHoverCardTemplate()).
31         // This part should be moved in it's own module. Maybe we could make more templates accessabel.
32         // (We need to discuss possible security lacks before doing this)
33         if ($datatype == "tpl") {
34                 $templatecontent = get_template_content("hovercard.tpl");
35                 echo $templatecontent;
36                 killme();
37         }
38
39         // If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
40         // the contact. So we strip out the contact id from the internal url and look in the contact table for
41         // the real url (nurl)
42         if (local_user() && strpos($profileurl, "redir/") === 0) {
43                 $cid = intval(substr($profileurl, 6));
44                 $r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1));
45                 $profileurl = ($r["nurl"] ? $r["nurl"] : "");
46                 $self = ($r["self"] ? $r["self"] : "");
47         }
48
49         // if it's the url containing https it should be converted to http
50         $nurl = normalise_link(GlobalContact::cleanContactUrl($profileurl));
51         if($nurl) {
52                 // Search for contact data
53                 $contact = Contact::getDetailsByURL($nurl);
54         }
55         if(!is_array($contact))
56                 return;
57
58         // Get the photo_menu - the menu if possible contact actions
59         if(local_user())
60                 $actions = Contact::photoMenu($contact);
61
62
63         // Move the contact data to the profile array so we can deliver it to
64         //
65         $profile = array(
66                 'name' => $contact["name"],
67                 'nick'  => $contact["nick"],
68                 'addr'  => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
69                 'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
70                 'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
71                 'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
72 //              'alias' => $contact["alias"],
73                 'location' => $contact["location"],
74                 'gender' => $contact["gender"],
75                 'about' => $contact["about"],
76                 'network' => format_network_name($contact["network"], $contact["url"]),
77                 'tags' => $contact["keywords"],
78 //              'nsfw' => intval($contact["nsfw"]),
79 //              'server_url' => $contact["server_url"],
80                 'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
81 //              'generation' => $contact["generation"],
82                 'account_type' => Contact::getAccountType($contact),
83                 'actions' => $actions,
84         );
85         if($datatype == "html") {
86                 $t = get_markup_template("hovercard.tpl");
87
88                 $o = replace_macros($t, array(
89                         '$profile' => $profile,
90                 ));
91
92                 return $o;
93
94         } else {
95                 json_return_and_die($profile);
96         }
97 }
98
99 /**
100  * @brief Get the raw content of a template file
101  *
102  * @param string $template The name of the template
103  * @param string $root Directory of the template
104  *
105  * @return string|bool Output the raw content if existent, otherwise false
106  */
107 function get_template_content($template, $root = "") {
108
109         // We load the whole template system to get the filename.
110         // Maybe we can do it a little bit smarter if I get time.
111         $t = get_markup_template($template, $root);
112         $filename = $t->filename;
113
114         // Get the content of the template file
115         if(file_exists($filename)) {
116                 $content = file_get_contents($filename);
117
118                 return $content;
119         }
120
121         return false;
122 }