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