3 require_once('include/config.php');
4 require_once('include/network.php');
5 require_once('include/plugin.php');
6 require_once('include/text.php');
7 require_once("include/pgettext.php");
10 define ( 'FRIENDIKA_VERSION', '2.2.1079' );
11 define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
12 define ( 'DB_UPDATE_VERSION', 1081 );
14 define ( 'EOL', "<br />\r\n" );
15 define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
20 * Image storage quality. Lower numbers save space at cost of image detail.
21 * For ease of upgrade, please do not change here. Change jpeg quality with
22 * set_config('system','jpeg_quality',n) in .htconfig.php
23 * where n is netween 1 and 100, and with very poor results below about 50
27 define ( 'JPEG_QUALITY', 100 );
30 * SSL redirection policies
33 define ( 'SSL_POLICY_NONE', 0 );
34 define ( 'SSL_POLICY_FULL', 1 );
35 define ( 'SSL_POLICY_SELFSIGN', 2 );
42 define ( 'LOGGER_NORMAL', 0 );
43 define ( 'LOGGER_TRACE', 1 );
44 define ( 'LOGGER_DEBUG', 2 );
45 define ( 'LOGGER_DATA', 3 );
46 define ( 'LOGGER_ALL', 4 );
49 * registration policies
52 define ( 'REGISTER_CLOSED', 0 );
53 define ( 'REGISTER_APPROVE', 1 );
54 define ( 'REGISTER_OPEN', 2 );
60 define ( 'CONTACT_IS_FOLLOWER', 1);
61 define ( 'CONTACT_IS_SHARING', 2);
62 define ( 'CONTACT_IS_FRIEND', 3);
69 define ( 'HOOK_HOOK', 0);
70 define ( 'HOOK_FILE', 1);
71 define ( 'HOOK_FUNCTION', 2);
77 * PAGE_NORMAL is a typical personal profile account
78 * PAGE_SOAPBOX automatically approves all friend requests as CONTACT_IS_SHARING, (readonly)
79 * PAGE_COMMUNITY automatically approves all friend requests as CONTACT_IS_SHARING, but with
80 * write access to wall and comments (no email and not included in page owner's ACL lists)
81 * PAGE_FREELOVE automatically approves all friend requests as full friends (CONTACT_IS_FRIEND).
85 define ( 'PAGE_NORMAL', 0 );
86 define ( 'PAGE_SOAPBOX', 1 );
87 define ( 'PAGE_COMMUNITY', 2 );
88 define ( 'PAGE_FREELOVE', 3 );
91 * Network and protocol family types
94 define ( 'NETWORK_ZOT', 'zot!'); // Zot!
95 define ( 'NETWORK_DFRN', 'dfrn'); // Friendika, Mistpark, other DFRN implementations
96 define ( 'NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations
97 define ( 'NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol
98 define ( 'NETWORK_DIASPORA', 'dspr'); // Diaspora
99 define ( 'NETWORK_MAIL', 'mail'); // IMAP/POP
100 define ( 'NETWORK_FACEBOOK', 'face'); // Facebook API
104 * Maximum number of "people who like (or don't like) this" that we will list by name
107 define ( 'MAX_LIKERS', 75);
110 * Communication timeout
113 define ( 'ZCURL_TIMEOUT' , (-1));
117 * email notification options
120 define ( 'NOTIFY_INTRO', 0x0001 );
121 define ( 'NOTIFY_CONFIRM', 0x0002 );
122 define ( 'NOTIFY_WALL', 0x0004 );
123 define ( 'NOTIFY_COMMENT', 0x0008 );
124 define ( 'NOTIFY_MAIL', 0x0010 );
127 * various namespaces we may need to parse
130 define ( 'NAMESPACE_ZOT', 'http://purl.org/macgirvin/zot' );
131 define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
132 define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' );
133 define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
134 define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
135 define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/' );
136 define ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' );
137 define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
138 define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
139 define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );
140 define ( 'NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0' );
141 define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from' );
142 define ( 'NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0' );
143 define ( 'NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/' );
144 define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
146 * activity stream defines
149 define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
150 define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
151 define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
153 define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
154 define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
155 define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
156 define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
157 define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
158 define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
160 define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
161 define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' );
162 define ( 'ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person' );
163 define ( 'ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo' );
164 define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' );
165 define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' );
166 define ( 'ACTIVITY_OBJ_EVENT', NAMESPACE_ACTIVITY_SCHEMA . 'event' );
169 * item weight for query ordering
172 define ( 'GRAVITY_PARENT', 0);
173 define ( 'GRAVITY_LIKE', 3);
174 define ( 'GRAVITY_COMMENT', 6);
178 * Reverse the effect of magic_quotes_gpc if it is enabled.
179 * Please disable magic_quotes_gpc so we don't have to do this.
180 * See http://php.net/manual/en/security.magicquotes.disabling.php
185 error_reporting(E_ERROR | E_WARNING | E_PARSE);
187 ini_set('pcre.backtrack_limit', 250000);
190 if (get_magic_quotes_gpc()) {
191 $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
192 while (list($key, $val) = each($process)) {
193 foreach ($val as $k => $v) {
194 unset($process[$key][$k]);
196 $process[$key][stripslashes($k)] = $v;
197 $process[] = &$process[$key][stripslashes($k)];
199 $process[$key][stripslashes($k)] = stripslashes($v);
212 * Our main application structure for the life of this page
213 * Primarily deals with the URL that got us here
214 * and tries to make some sense of it, and
215 * stores our page contents and config storage
216 * and anything else that might need to be passed around
217 * before we spit the page out.
221 if(! class_exists('App')) {
224 public $module_loaded = false;
225 public $query_string;
233 public $page_contact;
236 public $error = false;
246 public $interactive = true;
257 private $curl_headers;
259 function __construct() {
261 $this->config = array();
262 $this->page = array();
263 $this->pager= array();
265 $this->query_string = '';
269 $this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
271 if(x($_SERVER,'SERVER_NAME')) {
272 $this->hostname = $_SERVER['SERVER_NAME'];
273 if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
274 $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
276 * Figure out if we are running at the top of a domain
277 * or in a sub-directory and adjust accordingly
280 $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
281 if(isset($path) && strlen($path) && ($path != $this->path))
286 "include/$this->hostname" . PATH_SEPARATOR
287 . 'include' . PATH_SEPARATOR
288 . 'library' . PATH_SEPARATOR
289 . 'library/phpsec' . PATH_SEPARATOR
292 if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=")
293 $this->query_string = substr($_SERVER['QUERY_STRING'],2);
295 $this->cmd = trim($_GET['q'],'/\\');
301 * Break the URL path into C style argc/argv style arguments for our
302 * modules. Given "http://example.com/module/arg1/arg2", $this->argc
303 * will be 3 (integer) and $this->argv will contain:
309 * There will always be one argument. If provided a naked domain
310 * URL, $this->argv[0] is set to "home".
314 $this->argv = explode('/',$this->cmd);
315 $this->argc = count($this->argv);
316 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
317 $this->module = str_replace(".", "_", $this->argv[0]);
321 $this->argv = array('home');
322 $this->module = 'home';
326 * Special handling for the webfinger/lrdd host XRD file
329 if($this->cmd === '.well-known/host-meta') {
331 $this->argv = array('hostxrd');
332 $this->module = 'hostxrd';
336 * See if there is any page number information, and initialise
340 $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
341 $this->pager['itemspage'] = 50;
342 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
343 $this->pager['total'] = 0;
346 function get_baseurl($ssl = false) {
348 $scheme = $this->scheme;
350 if(x($this->config,'ssl_policy')) {
351 if(($ssl) || ($this->config['ssl_policy'] == SSL_POLICY_FULL))
353 if(($this->config['ssl_policy'] == SSL_POLICY_SELFSIGN) && (local_user() || x($_POST,'auth-params')))
357 $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
358 return $this->baseurl;
361 function set_baseurl($url) {
362 $parsed = @parse_url($url);
364 $this->baseurl = $url;
367 $this->scheme = $parsed['scheme'];
369 $this->hostname = $parsed['host'];
370 if(x($parsed,'port'))
371 $this->hostname .= ':' . $parsed['port'];
372 if(x($parsed,'path'))
373 $this->path = trim($parsed['path'],'\\/');
378 function get_hostname() {
379 return $this->hostname;
382 function set_hostname($h) {
383 $this->hostname = $h;
386 function set_path($p) {
387 $this->path = trim(trim($p),'/');
390 function get_path() {
394 function set_pager_total($n) {
395 $this->pager['total'] = intval($n);
398 function set_pager_itemspage($n) {
399 $this->pager['itemspage'] = intval($n);
400 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
404 function init_pagehead() {
405 $this->page['title'] = $this->config['sitename'];
406 $tpl = file_get_contents('view/head.tpl');
407 $this->page['htmlhead'] = replace_macros($tpl,array(
408 '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
409 '$generator' => 'Friendika' . ' ' . FRIENDIKA_VERSION,
410 '$delitem' => t('Delete this item?'),
411 '$comment' => t('Comment')
415 function set_curl_code($code) {
416 $this->curl_code = $code;
419 function get_curl_code() {
420 return $this->curl_code;
423 function set_curl_headers($headers) {
424 $this->curl_headers = $headers;
427 function get_curl_headers() {
428 return $this->curl_headers;
434 // retrieve the App structure
435 // useful in functions which require it but don't get it passed to them
437 if(! function_exists('get_app')) {
444 // Multi-purpose function to check variable state.
445 // Usage: x($var) or $x($array,'key')
446 // returns false if variable/key is not set
447 // if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0.
448 // e.g. x('') or x(0) returns 0;
450 if(! function_exists('x')) {
451 function x($s,$k = NULL) {
453 if((is_array($s)) && (array_key_exists($k,$s))) {
471 // called from db initialisation if db is dead.
473 if(! function_exists('system_unavailable')) {
474 function system_unavailable() {
475 include('system_unavailable.php');
482 function clean_urls() {
484 // if($a->config['system']['clean_urls'])
491 $base = $a->get_baseurl();
499 return $a->get_baseurl();
502 function absurl($path) {
503 if(strpos($path,'/') === 0)
504 return z_path() . $path;
509 // Primarily involved with database upgrade, but also sets the
510 // base url for use in cmdline programs which don't have
511 // $_SERVER variables, and synchronising the state of installed plugins.
514 if(! function_exists('check_config')) {
515 function check_config(&$a) {
517 $build = get_config('system','build');
519 $build = set_config('system','build',DB_UPDATE_VERSION);
521 $url = get_config('system','url');
523 // if the url isn't set or the stored url is radically different
524 // than the currently visited url, store the current value accordingly.
525 // "Radically different" ignores common variations such as http vs https
526 // and www.example.com vs example.com.
528 if((! x($url)) || (! link_compare($url,$a->get_baseurl())))
529 $url = set_config('system','url',$a->get_baseurl());
531 if($build != DB_UPDATE_VERSION) {
532 $stored = intval($build);
533 $current = intval(DB_UPDATE_VERSION);
534 if(($stored < $current) && file_exists('update.php')) {
536 // We're reporting a different version than what is currently installed.
537 // Run any existing update scripts to bring the database up to current.
539 require_once('update.php');
541 // make sure that boot.php and update.php are the same release, we might be
542 // updating right this very second and the correct version of the update.php
543 // file may not be here yet. This can happen on a very busy site.
545 if(DB_UPDATE_VERSION == UPDATE_VERSION) {
547 for($x = $stored; $x < $current; $x ++) {
548 if(function_exists('update_' . $x)) {
549 $func = 'update_' . $x;
553 set_config('system','build', DB_UPDATE_VERSION);
560 * Synchronise plugins:
562 * $a->config['system']['addon'] contains a comma-separated list of names
563 * of plugins/addons which are used on this system.
564 * Go through the database list of already installed addons, and if we have
565 * an entry, but it isn't in the config list, call the uninstall procedure
566 * and mark it uninstalled in the database (for now we'll remove it).
567 * Then go through the config list and if we have a plugin that isn't installed,
568 * call the install procedure and add it to the database.
572 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
576 $installed = array();
578 $plugins = get_config('system','addon');
579 $plugins_arr = array();
582 $plugins_arr = explode(',',str_replace(' ', '',$plugins));
584 $a->plugins = $plugins_arr;
586 $installed_arr = array();
588 if(count($installed)) {
589 foreach($installed as $i) {
590 if(! in_array($i['name'],$plugins_arr)) {
591 uninstall_plugin($i['name']);
594 $installed_arr[] = $i['name'];
598 if(count($plugins_arr)) {
599 foreach($plugins_arr as $p) {
600 if(! in_array($p,$installed_arr)) {
613 function get_guid($size=16) {
614 $exists = true; // assume by default that we don't have a unique guid
616 $s = random_string($size);
617 $r = q("select id from guid where guid = '%s' limit 1", dbesc($s));
621 q("insert into guid ( guid ) values ( '%s' ) ", dbesc($s));
626 // wrapper for adding a login box. If $register == true provide a registration
627 // link. This will most always depend on the value of $a->config['register_policy'].
628 // returns the complete html for inserting into the page
630 if(! function_exists('login')) {
631 function login($register = false) {
633 $register_tpl = (($register) ? get_markup_template("register-link.tpl") : "");
635 $register_html = replace_macros($register_tpl,array(
636 '$title' => t('Create a New Account'),
637 '$desc' => t('Register')
640 $noid = get_config('system','no_openid');
642 $classname = 'no-openid';
643 $namelabel = t('Nickname or Email address: ');
644 $passlabel = t('Password: ');
648 $classname = 'openid';
649 $namelabel = t('Nickname/Email/OpenID: ');
650 $passlabel = t("Password \x28if not OpenID\x29: ");
653 $lostpass = t('Forgot your password?');
654 $lostlink = t('Password Reset');
657 $tpl = get_markup_template("logout.tpl");
660 $tpl = get_markup_template("login.tpl");
664 $o = '<script type="text/javascript"> $(document).ready(function() { $("#login-name").focus();} );</script>';
666 $o .= replace_macros($tpl,array(
667 '$logout' => t('Logout'),
668 '$register_html' => $register_html,
669 '$classname' => $classname,
670 '$namelabel' => $namelabel,
671 '$passlabel' => $passlabel,
673 '$lostpass' => $lostpass,
674 '$lostlink' => $lostlink
680 // Used to end the current process, after saving session state.
682 if(! function_exists('killme')) {
684 session_write_close();
688 // redirect to another URL and terminate this process.
690 if(! function_exists('goaway')) {
691 function goaway($s) {
692 header("Location: $s");
697 // Returns the uid of locally logged in user or false.
699 if(! function_exists('local_user')) {
700 function local_user() {
701 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
702 return intval($_SESSION['uid']);
706 // Returns contact id of authenticated site visitor or false
708 if(! function_exists('remote_user')) {
709 function remote_user() {
710 if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
711 return intval($_SESSION['visitor_id']);
715 // contents of $s are displayed prominently on the page the next time
716 // a page is loaded. Usually used for errors or alerts.
718 if(! function_exists('notice')) {
719 function notice($s) {
722 $_SESSION['sysmsg'] .= $s;
724 if(! function_exists('info')) {
728 $_SESSION['sysmsg_info'] .= $s;
732 // wrapper around config to limit the text length of an incoming message
734 if(! function_exists('get_max_import_size')) {
735 function get_max_import_size() {
737 return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
744 * Function : profile_load
746 * @parameter string $nickname
747 * @parameter int $profile
749 * Summary: Loads a profile into the page sidebar.
750 * The function requires a writeable copy of the main App structure, and the nickname
751 * of a registered local account.
753 * If the viewer is an authenticated remote viewer, the profile displayed is the
754 * one that has been configured for his/her viewing in the Contact manager.
755 * Passing a non-zero profile ID can also allow a preview of a selected profile
758 * Profile information is placed in the App structure for later retrieval.
759 * Honours the owner's chosen theme for display.
763 if(! function_exists('profile_load')) {
764 function profile_load(&$a, $nickname, $profile = 0) {
766 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
767 intval($_SESSION['visitor_id']));
769 $profile = $r[0]['profile-id'];
775 $profile_int = intval($profile);
776 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
777 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
778 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d LIMIT 1",
784 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
785 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
786 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 LIMIT 1",
791 if(($r === false) || (! count($r))) {
792 notice( t('No profile') . EOL );
800 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
801 $_SESSION['theme'] = $a->profile['theme'];
803 if(! (x($a->page,'aside')))
804 $a->page['aside'] = '';
806 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
808 $a->page['aside'] .= profile_sidebar($a->profile, $block);
811 $a->page['aside'] .= contact_block();
819 * Function: profile_sidebar
821 * Formats a profile for display in the sidebar.
822 * It is very difficult to templatise the HTML completely
823 * because of all the conditional logic.
825 * @parameter: array $profile
827 * Returns HTML string stuitable for sidebar inclusion
828 * Exceptions: Returns empty string if passed $profile is wrong type or not populated
833 if(! function_exists('profile_sidebar')) {
834 function profile_sidebar($profile, $block = 0) {
842 if((! is_array($profile)) && (! count($profile)))
845 call_hooks('profile_sidebar_enter', $profile);
847 $fullname = '<div class="fn">' . $profile['name'] . '</div>';
849 $pdesc = '<div class="title">' . $profile['pdesc'] . '</div>';
853 $photo = '<div id="profile-photo-wrapper"><img class="photo" width="175" height="175" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>';
855 // don't show connect link to yourself
856 $connect = (($profile['uid'] != local_user()) ? '<li><a id="dfrn-request-link" href="dfrn_request/' . $profile['nickname'] . '">' . t('Connect') . '</a></li>' : '');
858 // don't show connect link to authenticated visitors either
860 if((remote_user()) && ($_SESSION['visitor_visiting'] == $profile['uid']))
863 if((x($profile,'address') == 1)
864 || (x($profile,'locality') == 1)
865 || (x($profile,'region') == 1)
866 || (x($profile,'postal-code') == 1)
867 || (x($profile,'country-name') == 1))
871 $location .= '<div class="location"><span class="location-label">' . t('Location:') . '</span> <div class="adr">';
872 $location .= ((x($profile,'address') == 1) ? '<div class="street-address">' . $profile['address'] . '</div>' : '');
873 $location .= (((x($profile,'locality') == 1) || (x($profile,'region') == 1) || (x($profile,'postal-code') == 1))
874 ? '<span class="city-state-zip"><span class="locality">' . $profile['locality'] . '</span>'
875 . ((x($profile['locality']) == 1) ? t(', ') : '')
876 . '<span class="region">' . $profile['region'] . '</span>'
877 . ' <span class="postal-code">' . $profile['postal-code'] . '</span></span>' : '');
878 $location .= ((x($profile,'country-name') == 1) ? ' <span class="country-name">' . $profile['country-name'] . '</span>' : '');
879 $location .= '</div></div><div class="profile-clear"></div>';
884 $gender = ((x($profile,'gender') == 1) ? '<div class="mf"><span class="gender-label">' . t('Gender:') . '</span> <span class="x-gender">' . $profile['gender'] . '</span></div><div class="profile-clear"></div>' : '');
886 $pubkey = ((x($profile,'pubkey') == 1) ? '<div class="key" style="display:none;">' . $profile['pubkey'] . '</div>' : '');
888 $marital = ((x($profile,'marital') == 1) ? '<div class="marital"><span class="marital-label"><span class="heart">♥</span> ' . t('Status:') . ' </span><span class="marital-text">' . $profile['marital'] . '</span></div><div class="profile-clear"></div>' : '');
890 $homepage = ((x($profile,'homepage') == 1) ? '<div class="homepage"><span class="homepage-label">' . t('Homepage:') . ' </span><span class="homepage-url">' . linkify($profile['homepage']) . '</span></div><div class="profile-clear"></div>' : '');
892 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
893 $location = $pdesc = $connect = $gender = $marital = $homepage = '';
896 $podloc = $a->get_baseurl();
897 $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' );
898 $nickname = $profile['nickname'];
899 $photo300 = $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg';
900 $photo100 = $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg';
901 $photo50 = $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg';
903 $diaspora_vcard = <<< EOT
905 <div style="display:none;">
906 <dl class='entity_nickname'>
909 <a class="nickname url uid" href="$podloc/" rel="me">$nickname</a>
912 <dl class='entity_fn'>
915 <span class='fn'>$fullname</span>
918 <dl class="entity_url">
921 <a class="url" href="$podloc/" id="pod_location" rel="me">$podloc/</a>
924 <dl class="entity_photo">
927 <img class="photo avatar" height="300px" width="300px" src="$photo300">
930 <dl class="entity_photo_medium">
933 <img class="photo avatar" height="100px" width="100px" src="$photo100">
936 <dl class="entity_photo_small">
939 <img class="photo avatar" height="50px" width="50px" src="$photo50">
942 <dl class="entity_searchable">
945 <span class="searchable">$searchable</span>
951 $tpl = get_markup_template('profile_vcard.tpl');
953 $o .= replace_macros($tpl, array(
954 '$fullname' => $fullname,
958 '$connect' => $connect,
959 '$location' => $location,
960 '$gender' => $gender,
961 '$pubkey' => $pubkey,
962 '$marital' => $marital,
963 '$homepage' => $homepage,
964 '$diaspora' => $diaspora_vcard
968 $arr = array('profile' => &$profile, 'entry' => &$o);
970 call_hooks('profile_sidebar', $arr);
976 if(! function_exists('get_birthdays')) {
977 function get_birthdays() {
985 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
987 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
988 LEFT JOIN `contact` ON `contact`.`id` = `event`.`cid`
989 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
990 ORDER BY `start` DESC ",
991 intval(local_user()),
992 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
993 dbesc(datetime_convert('UTC','UTC','now'))
996 if($r && count($r)) {
999 if(strlen($rr['name']))
1003 $o .= '<div id="birthday-notice" class="birthday-notice fakelink" onclick=openClose(\'birthday-wrapper\'); >' . t('Birthday Reminders') . ' ' . '(' . $total . ')' . '</div>';
1004 $o .= '<div id="birthday-wrapper" style="display: none;" ><div id="birthday-title">' . t('Birthdays this week:') . '</div>';
1005 $o .= '<div id="birthday-adjust">' . t("\x28Adjusted for local time\x29") . '</div>';
1006 $o .= '<div id="birthday-title-end"></div>';
1008 foreach($r as $rr) {
1009 if(! strlen($rr['name']))
1011 $now = strtotime('now');
1012 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
1014 $o .= '<div class="birthday-list" id="birthday-' . $rr['eid'] . '"><a class="sparkle" href="'
1015 . $a->get_baseurl() . '/redir/' . $rr['cid'] . '">' . $rr['name'] . '</a> '
1016 . day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '')
1019 $o .= '</div></div>';
1028 * Wrap calls to proc_close(proc_open()) and call hook
1029 * so plugins can take part in process :)
1032 * $cmd program to run
1033 * next args are passed as $cmd command line
1035 * e.g.: proc_run("ls","-la","/tmp");
1037 * $cmd and string args are surrounded with ""
1040 if(! function_exists('proc_run')) {
1041 function proc_run($cmd){
1045 $args = func_get_args();
1046 $arr = array('args' => $args, 'run_cmd' => true);
1048 call_hooks("proc_run", $arr);
1049 if(! $arr['run_cmd'])
1052 if(count($args) && $args[0] === 'php')
1053 $args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
1054 foreach ($args as $arg){
1055 $arg = escapeshellarg($arg);
1057 $cmdline = implode($args," ");
1058 proc_close(proc_open($cmdline." &",array(),$foo));
1061 if(! function_exists('current_theme')) {
1062 function current_theme(){
1063 $app_base_themes = array('duepuntozero', 'loozah');
1067 $system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
1068 $theme_name = ((is_array($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
1070 if($theme_name && file_exists('view/theme/' . $theme_name . '/style.css'))
1071 return($theme_name);
1073 foreach($app_base_themes as $t) {
1074 if(file_exists('view/theme/' . $t . '/style.css'))
1078 $fallback = glob('view/theme/*/style.css');
1079 if(count($fallback))
1080 return (str_replace('view/theme/','', str_replace("/style.css","",$fallback[0])));
1085 * Return full URL to theme which is currently in effect.
1086 * Provide a sane default if nothing is chosen or the specified theme does not exist.
1088 if(! function_exists('current_theme_url')) {
1089 function current_theme_url() {
1091 $t = current_theme();
1092 return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
1095 if(! function_exists('feed_birthday')) {
1096 function feed_birthday($uid,$tz) {
1100 * Determine the next birthday, but only if the birthday is published
1101 * in the default profile. We _could_ also look for a private profile that the
1102 * recipient can see, but somebody could get mad at us if they start getting
1103 * public birthday greetings when they haven't made this info public.
1105 * Assuming we are able to publish this info, we are then going to convert
1106 * the start time from the owner's timezone to UTC.
1108 * This will potentially solve the problem found with some social networks
1109 * where birthdays are converted to the viewer's timezone and salutations from
1110 * elsewhere in the world show up on the wrong day. We will convert it to the
1111 * viewer's timezone also, but first we are going to convert it from the birthday
1112 * person's timezone to GMT - so the viewer may find the birthday starting at
1113 * 6:00PM the day before, but that will correspond to midnight to the birthday person.
1119 $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
1123 if($p && count($p)) {
1124 $tmp_dob = substr($p[0]['dob'],5);
1125 if(intval($tmp_dob)) {
1126 $y = datetime_convert($tz,$tz,'now','Y');
1127 $bd = $y . '-' . $tmp_dob . ' 00:00';
1128 $t_dob = strtotime($bd);
1129 $now = strtotime(datetime_convert($tz,$tz,'now'));
1131 $bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
1132 $birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME);
1139 if(! function_exists('is_site_admin')) {
1140 function is_site_admin() {
1142 if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
1148 if(! function_exists('load_contact_links')) {
1149 function load_contact_links($uid) {
1155 if(! $uid || x($a->contacts,'empty'))
1158 $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
1163 $url = normalise_link($rr['url']);
1168 $ret['empty'] = true;
1169 $a->contacts = $ret;