Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2201 lines
60 KiB

11 years ago
10 years ago
8 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
9 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
9 years ago
9 years ago
9 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
9 years ago
9 years ago
11 years ago
9 years ago
9 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
9 years ago
9 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
8 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. require_once('include/config.php');
  3. require_once('include/network.php');
  4. require_once('include/plugin.php');
  5. require_once('include/text.php');
  6. require_once('include/datetime.php');
  7. require_once('include/pgettext.php');
  8. require_once('include/nav.php');
  9. require_once('include/cache.php');
  10. require_once('library/Mobile_Detect/Mobile_Detect.php');
  11. require_once('include/features.php');
  12. define ( 'FRIENDICA_PLATFORM', 'Friendica');
  13. define ( 'FRIENDICA_VERSION', '3.2.1748' );
  14. define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
  15. define ( 'DB_UPDATE_VERSION', 1170 );
  16. define ( 'EOL', "<br />\r\n" );
  17. define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
  18. /**
  19. *
  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. * $a->config['system']['jpeg_quality'] = n;
  23. * in .htconfig.php, where n is netween 1 and 100, and with very poor results
  24. * below about 50
  25. *
  26. */
  27. define ( 'JPEG_QUALITY', 100 );
  28. /**
  29. * $a->config['system']['png_quality'] from 0 (uncompressed) to 9
  30. */
  31. define ( 'PNG_QUALITY', 8 );
  32. /**
  33. *
  34. * An alternate way of limiting picture upload sizes. Specify the maximum pixel
  35. * length that pictures are allowed to be (for non-square pictures, it will apply
  36. * to the longest side). Pictures longer than this length will be resized to be
  37. * this length (on the longest side, the other side will be scaled appropriately).
  38. * Modify this value using
  39. *
  40. * $a->config['system']['max_image_length'] = n;
  41. *
  42. * in .htconfig.php
  43. *
  44. * If you don't want to set a maximum length, set to -1. The default value is
  45. * defined by 'MAX_IMAGE_LENGTH' below.
  46. *
  47. */
  48. define ( 'MAX_IMAGE_LENGTH', -1 );
  49. /**
  50. * Not yet used
  51. */
  52. define ( 'DEFAULT_DB_ENGINE', 'MyISAM' );
  53. /**
  54. * SSL redirection policies
  55. */
  56. define ( 'SSL_POLICY_NONE', 0 );
  57. define ( 'SSL_POLICY_FULL', 1 );
  58. define ( 'SSL_POLICY_SELFSIGN', 2 );
  59. /**
  60. * log levels
  61. */
  62. define ( 'LOGGER_NORMAL', 0 );
  63. define ( 'LOGGER_TRACE', 1 );
  64. define ( 'LOGGER_DEBUG', 2 );
  65. define ( 'LOGGER_DATA', 3 );
  66. define ( 'LOGGER_ALL', 4 );
  67. /**
  68. * registration policies
  69. */
  70. define ( 'REGISTER_CLOSED', 0 );
  71. define ( 'REGISTER_APPROVE', 1 );
  72. define ( 'REGISTER_OPEN', 2 );
  73. /**
  74. * relationship types
  75. */
  76. define ( 'CONTACT_IS_FOLLOWER', 1);
  77. define ( 'CONTACT_IS_SHARING', 2);
  78. define ( 'CONTACT_IS_FRIEND', 3);
  79. /**
  80. * DB update return values
  81. */
  82. define ( 'UPDATE_SUCCESS', 0);
  83. define ( 'UPDATE_FAILED', 1);
  84. /**
  85. *
  86. * page/profile types
  87. *
  88. * PAGE_NORMAL is a typical personal profile account
  89. * PAGE_SOAPBOX automatically approves all friend requests as CONTACT_IS_SHARING, (readonly)
  90. * PAGE_COMMUNITY automatically approves all friend requests as CONTACT_IS_SHARING, but with
  91. * write access to wall and comments (no email and not included in page owner's ACL lists)
  92. * PAGE_FREELOVE automatically approves all friend requests as full friends (CONTACT_IS_FRIEND).
  93. *
  94. */
  95. define ( 'PAGE_NORMAL', 0 );
  96. define ( 'PAGE_SOAPBOX', 1 );
  97. define ( 'PAGE_COMMUNITY', 2 );
  98. define ( 'PAGE_FREELOVE', 3 );
  99. define ( 'PAGE_BLOG', 4 );
  100. define ( 'PAGE_PRVGROUP', 5 );
  101. /**
  102. * Network and protocol family types
  103. */
  104. define ( 'NETWORK_DFRN', 'dfrn'); // Friendica, Mistpark, other DFRN implementations
  105. define ( 'NETWORK_ZOT', 'zot!'); // Zot!
  106. define ( 'NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations
  107. define ( 'NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol
  108. define ( 'NETWORK_DIASPORA', 'dspr'); // Diaspora
  109. define ( 'NETWORK_MAIL', 'mail'); // IMAP/POP
  110. define ( 'NETWORK_MAIL2', 'mai2'); // extended IMAP/POP
  111. define ( 'NETWORK_FACEBOOK', 'face'); // Facebook API
  112. define ( 'NETWORK_LINKEDIN', 'lnkd'); // LinkedIn
  113. define ( 'NETWORK_XMPP', 'xmpp'); // XMPP
  114. define ( 'NETWORK_MYSPACE', 'mysp'); // MySpace
  115. define ( 'NETWORK_GPLUS', 'goog'); // Google+
  116. define ( 'NETWORK_PUMPIO', 'pump'); // pump.io
  117. define ( 'NETWORK_TWITTER', 'twit'); // Twitter
  118. define ( 'NETWORK_DIASPORA2', 'dspc'); // Diaspora connector
  119. define ( 'NETWORK_STATUSNET', 'stac'); // Statusnet connector
  120. define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder
  121. /**
  122. * These numbers are used in stored permissions
  123. * and existing allocations MUST NEVER BE CHANGED
  124. * OR RE-ASSIGNED! You may only add to them.
  125. */
  126. $netgroup_ids = array(
  127. NETWORK_DFRN => (-1),
  128. NETWORK_ZOT => (-2),
  129. NETWORK_OSTATUS => (-3),
  130. NETWORK_FEED => (-4),
  131. NETWORK_DIASPORA => (-5),
  132. NETWORK_MAIL => (-6),
  133. NETWORK_MAIL2 => (-7),
  134. NETWORK_FACEBOOK => (-8),
  135. NETWORK_LINKEDIN => (-9),
  136. NETWORK_XMPP => (-10),
  137. NETWORK_MYSPACE => (-11),
  138. NETWORK_GPLUS => (-12),
  139. NETWORK_PUMPIO => (-13),
  140. NETWORK_TWITTER => (-14),
  141. NETWORK_DIASPORA2 => (-15),
  142. NETWORK_STATUSNET => (-16),
  143. NETWORK_PHANTOM => (-127),
  144. );
  145. /**
  146. * Maximum number of "people who like (or don't like) this" that we will list by name
  147. */
  148. define ( 'MAX_LIKERS', 75);
  149. /**
  150. * Communication timeout
  151. */
  152. define ( 'ZCURL_TIMEOUT' , (-1));
  153. /**
  154. * email notification options
  155. */
  156. define ( 'NOTIFY_INTRO', 0x0001 );
  157. define ( 'NOTIFY_CONFIRM', 0x0002 );
  158. define ( 'NOTIFY_WALL', 0x0004 );
  159. define ( 'NOTIFY_COMMENT', 0x0008 );
  160. define ( 'NOTIFY_MAIL', 0x0010 );
  161. define ( 'NOTIFY_SUGGEST', 0x0020 );
  162. define ( 'NOTIFY_PROFILE', 0x0040 );
  163. define ( 'NOTIFY_TAGSELF', 0x0080 );
  164. define ( 'NOTIFY_TAGSHARE', 0x0100 );
  165. define ( 'NOTIFY_POKE', 0x0200 );
  166. define ( 'NOTIFY_SHARE', 0x0400 );
  167. define ( 'NOTIFY_SYSTEM', 0x8000 );
  168. /**
  169. * Tag/term types
  170. */
  171. define ( 'TERM_UNKNOWN', 0 );
  172. define ( 'TERM_HASHTAG', 1 );
  173. define ( 'TERM_MENTION', 2 );
  174. define ( 'TERM_CATEGORY', 3 );
  175. define ( 'TERM_PCATEGORY', 4 );
  176. define ( 'TERM_FILE', 5 );
  177. define ( 'TERM_SAVEDSEARCH', 6 );
  178. define ( 'TERM_CONVERSATION', 7 );
  179. define ( 'TERM_OBJ_POST', 1 );
  180. define ( 'TERM_OBJ_PHOTO', 2 );
  181. /**
  182. * various namespaces we may need to parse
  183. */
  184. define ( 'NAMESPACE_ZOT', 'http://purl.org/zot' );
  185. define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
  186. define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' );
  187. define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
  188. define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
  189. define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/' );
  190. define ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' );
  191. define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
  192. define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
  193. define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );
  194. define ( 'NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0' );
  195. define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from' );
  196. define ( 'NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0' );
  197. define ( 'NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/' );
  198. define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
  199. /**
  200. * activity stream defines
  201. */
  202. define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
  203. define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
  204. define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
  205. define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
  206. define ( 'ACTIVITY_REQ_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'request-friend' );
  207. define ( 'ACTIVITY_UNFRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'remove-friend' );
  208. define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
  209. define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
  210. define ( 'ACTIVITY_JOIN', NAMESPACE_ACTIVITY_SCHEMA . 'join' );
  211. define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
  212. define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
  213. define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
  214. define ( 'ACTIVITY_FAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
  215. define ( 'ACTIVITY_POKE', NAMESPACE_ZOT . '/activity/poke' );
  216. define ( 'ACTIVITY_MOOD', NAMESPACE_ZOT . '/activity/mood' );
  217. define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
  218. define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' );
  219. define ( 'ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person' );
  220. define ( 'ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo' );
  221. define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' );
  222. define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' );
  223. define ( 'ACTIVITY_OBJ_EVENT', NAMESPACE_ACTIVITY_SCHEMA . 'event' );
  224. define ( 'ACTIVITY_OBJ_GROUP', NAMESPACE_ACTIVITY_SCHEMA . 'group' );
  225. define ( 'ACTIVITY_OBJ_TAGTERM', NAMESPACE_DFRN . '/tagterm' );
  226. define ( 'ACTIVITY_OBJ_PROFILE', NAMESPACE_DFRN . '/profile' );
  227. /**
  228. * item weight for query ordering
  229. */
  230. define ( 'GRAVITY_PARENT', 0);
  231. define ( 'GRAVITY_LIKE', 3);
  232. define ( 'GRAVITY_COMMENT', 6);
  233. /**
  234. *
  235. * Reverse the effect of magic_quotes_gpc if it is enabled.
  236. * Please disable magic_quotes_gpc so we don't have to do this.
  237. * See http://php.net/manual/en/security.magicquotes.disabling.php
  238. *
  239. */
  240. function startup() {
  241. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  242. set_time_limit(0);
  243. // This has to be quite large to deal with embedded private photos
  244. ini_set('pcre.backtrack_limit', 500000);
  245. if (get_magic_quotes_gpc()) {
  246. $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  247. while (list($key, $val) = each($process)) {
  248. foreach ($val as $k => $v) {
  249. unset($process[$key][$k]);
  250. if (is_array($v)) {
  251. $process[$key][stripslashes($k)] = $v;
  252. $process[] = &$process[$key][stripslashes($k)];
  253. } else {
  254. $process[$key][stripslashes($k)] = stripslashes($v);
  255. }
  256. }
  257. }
  258. unset($process);
  259. }
  260. }
  261. /**
  262. *
  263. * class: App
  264. *
  265. * Our main application structure for the life of this page
  266. * Primarily deals with the URL that got us here
  267. * and tries to make some sense of it, and
  268. * stores our page contents and config storage
  269. * and anything else that might need to be passed around
  270. * before we spit the page out.
  271. *
  272. */
  273. if(! class_exists('App')) {
  274. class App {
  275. public $module_loaded = false;
  276. public $query_string;
  277. public $config;
  278. public $page;
  279. public $profile;
  280. public $user;
  281. public $cid;
  282. public $contact;
  283. public $contacts;
  284. public $page_contact;
  285. public $content;
  286. public $data = array();
  287. public $error = false;
  288. public $cmd;
  289. public $argv;
  290. public $argc;
  291. public $module;
  292. public $pager;
  293. public $strings;
  294. public $path;
  295. public $hooks;
  296. public $timezone;
  297. public $interactive = true;
  298. public $plugins;
  299. public $apps = array();
  300. public $identities;
  301. public $is_mobile;
  302. public $is_tablet;
  303. public $performance = array();
  304. public $nav_sel;
  305. public $category;
  306. // Allow themes to control internal parameters
  307. // by changing App values in theme.php
  308. public $sourcename = '';
  309. public $videowidth = 425;
  310. public $videoheight = 350;
  311. public $force_max_items = 0;
  312. public $theme_thread_allow = true;
  313. // An array for all theme-controllable parameters
  314. // Mostly unimplemented yet. Only options 'stylesheet' and
  315. // beyond are used.
  316. public $theme = array(
  317. 'sourcename' => '',
  318. 'videowidth' => 425,
  319. 'videoheight' => 350,
  320. 'force_max_items' => 0,
  321. 'thread_allow' => true,
  322. 'stylesheet' => '',
  323. 'template_engine' => 'smarty3',
  324. );
  325. // array of registered template engines ('name'=>'class name')
  326. public $template_engines = array();
  327. // array of instanced template engines ('name'=>'instance')
  328. public $template_engine_instance = array();
  329. // Used for reducing load to the ostatus completion
  330. public $last_ostatus_conversation_url;
  331. private $ldelim = array(
  332. 'internal' => '',
  333. 'smarty3' => '{{'
  334. );
  335. private $rdelim = array(
  336. 'internal' => '',
  337. 'smarty3' => '}}'
  338. );
  339. private $scheme;
  340. private $hostname;
  341. private $baseurl;
  342. private $db;
  343. private $curl_code;
  344. private $curl_content_type;
  345. private $curl_headers;
  346. private $cached_profile_image;
  347. private $cached_profile_picdate;
  348. function __construct() {
  349. global $default_timezone, $argv, $argc;
  350. if (file_exists(".htpreconfig.php"))
  351. @include(".htpreconfig.php");
  352. $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
  353. date_default_timezone_set($this->timezone);
  354. $this->performance["start"] = microtime(true);
  355. $this->performance["database"] = 0;
  356. $this->performance["network"] = 0;
  357. $this->performance["file"] = 0;
  358. $this->performance["rendering"] = 0;
  359. $this->performance["parser"] = 0;
  360. $this->performance["marktime"] = 0;
  361. $this->performance["markstart"] = microtime(true);
  362. $this->config = array();
  363. $this->page = array();
  364. $this->pager= array();
  365. $this->query_string = '';
  366. startup();
  367. set_include_path(
  368. 'include' . PATH_SEPARATOR
  369. . 'library' . PATH_SEPARATOR
  370. . 'library/phpsec' . PATH_SEPARATOR
  371. . 'library/langdet' . PATH_SEPARATOR
  372. . '.' );
  373. $this->scheme = 'http';
  374. if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS'])
  375. $this->scheme = 'https';
  376. elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443))
  377. $this->scheme = 'https';
  378. if(x($_SERVER,'SERVER_NAME')) {
  379. $this->hostname = $_SERVER['SERVER_NAME'];
  380. // See bug 437 - this didn't work so disabling it
  381. //if(stristr($this->hostname,'xn--')) {
  382. // PHP or webserver may have converted idn to punycode, so
  383. // convert punycode back to utf-8
  384. // require_once('library/simplepie/idn/idna_convert.class.php');
  385. // $x = new idna_convert();
  386. // $this->hostname = $x->decode($_SERVER['SERVER_NAME']);
  387. //}
  388. if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
  389. $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
  390. /**
  391. * Figure out if we are running at the top of a domain
  392. * or in a sub-directory and adjust accordingly
  393. */
  394. $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
  395. if(isset($path) && strlen($path) && ($path != $this->path))
  396. $this->path = $path;
  397. }
  398. if ($hostname != "")
  399. $this->hostname = $hostname;
  400. if (is_array($argv) && $argc>1 && substr(end($argv), 0, 4)=="http" ) {
  401. $this->set_baseurl(array_pop($argv) );
  402. $argc --;
  403. }
  404. set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path());
  405. if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
  406. $this->query_string = substr($_SERVER['QUERY_STRING'],2);
  407. // removing trailing / - maybe a nginx problem
  408. if (substr($this->query_string, 0, 1) == "/")
  409. $this->query_string = substr($this->query_string, 1);
  410. }
  411. if(x($_GET,'q'))
  412. $this->cmd = trim($_GET['q'],'/\\');
  413. // unix style "homedir"
  414. if(substr($this->cmd,0,1) === '~')
  415. $this->cmd = 'profile/' . substr($this->cmd,1);
  416. // Diaspora style profile url
  417. if(substr($this->cmd,0,2) === 'u/')
  418. $this->cmd = 'profile/' . substr($this->cmd,2);
  419. /**
  420. *
  421. * Break the URL path into C style argc/argv style arguments for our
  422. * modules. Given "http://example.com/module/arg1/arg2", $this->argc
  423. * will be 3 (integer) and $this->argv will contain:
  424. * [0] => 'module'
  425. * [1] => 'arg1'
  426. * [2] => 'arg2'
  427. *
  428. *
  429. * There will always be one argument. If provided a naked domain
  430. * URL, $this->argv[0] is set to "home".
  431. *
  432. */
  433. $this->argv = explode('/',$this->cmd);
  434. $this->argc = count($this->argv);
  435. if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
  436. $this->module = str_replace(".", "_", $this->argv[0]);
  437. $this->module = str_replace("-", "_", $this->module);
  438. }
  439. else {
  440. $this->argc = 1;
  441. $this->argv = array('home');
  442. $this->module = 'home';
  443. }
  444. /**
  445. * See if there is any page number information, and initialise
  446. * pagination
  447. */
  448. $this->pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
  449. $this->pager['itemspage'] = 50;
  450. $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
  451. if($this->pager['start'] < 0)
  452. $this->pager['start'] = 0;
  453. $this->pager['total'] = 0;
  454. /**
  455. * Detect mobile devices
  456. */
  457. $mobile_detect = new Mobile_Detect();
  458. $this->is_mobile = $mobile_detect->isMobile();
  459. $this->is_tablet = $mobile_detect->isTablet();
  460. /**
  461. * register template engines
  462. */
  463. $dc = get_declared_classes();
  464. foreach ($dc as $k) {
  465. if (in_array("ITemplateEngine", class_implements($k))){
  466. $this->register_template_engine($k);
  467. }
  468. }
  469. }
  470. function get_basepath() {
  471. $basepath = get_config("system", "basepath");
  472. if ($basepath == "")
  473. $basepath = $_SERVER["DOCUMENT_ROOT"];
  474. if ($basepath == "")
  475. $basepath = $_SERVER["PWD"];
  476. return($basepath);
  477. }
  478. function get_baseurl($ssl = false) {
  479. $scheme = $this->scheme;
  480. if((x($this->config,'system')) && (x($this->config['system'],'ssl_policy'))) {
  481. if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL))
  482. $scheme = 'https';
  483. // Basically, we have $ssl = true on any links which can only be seen by a logged in user
  484. // (and also the login link). Anything seen by an outsider will have it turned off.
  485. if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
  486. if($ssl)
  487. $scheme = 'https';
  488. else
  489. $scheme = 'http';
  490. }
  491. }
  492. $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
  493. return $this->baseurl;
  494. }
  495. function set_baseurl($url) {
  496. $parsed = @parse_url($url);
  497. $this->baseurl = $url;
  498. if($parsed) {
  499. $this->scheme = $parsed['scheme'];
  500. $this->hostname = $parsed['host'];
  501. if(x($parsed,'port'))
  502. $this->hostname .= ':' . $parsed['port'];
  503. if(x($parsed,'path'))
  504. $this->path = trim($parsed['path'],'\\/');
  505. }
  506. }
  507. function get_hostname() {
  508. return $this->hostname;
  509. }
  510. function set_hostname($h) {
  511. $this->hostname = $h;
  512. }
  513. function set_path($p) {
  514. $this->path = trim(trim($p),'/');
  515. }
  516. function get_path() {
  517. return $this->path;
  518. }
  519. function set_pager_total($n) {
  520. $this->pager['total'] = intval($n);
  521. }
  522. function set_pager_itemspage($n) {
  523. $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
  524. $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
  525. }
  526. function set_pager_page($n) {
  527. $this->pager['page'] = $n;
  528. $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
  529. }
  530. function init_pagehead() {
  531. $interval = ((local_user()) ? get_pconfig(local_user(),'system','update_interval') : 40000);
  532. if($interval < 10000)
  533. $interval = 40000;
  534. $this->page['title'] = $this->config['sitename'];
  535. /* put the head template at the beginning of page['htmlhead']
  536. * since the code added by the modules frequently depends on it
  537. * being first
  538. */
  539. if(!isset($this->page['htmlhead']))
  540. $this->page['htmlhead'] = '';
  541. // If we're using Smarty, then doing replace_macros() will replace
  542. // any unrecognized variables with a blank string. Since we delay
  543. // replacing $stylesheet until later, we need to replace it now
  544. // with another variable name
  545. if($this->theme['template_engine'] === 'smarty3')
  546. $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3');
  547. else
  548. $stylesheet = '$stylesheet';
  549. $tpl = get_markup_template('head.tpl');
  550. $this->page['htmlhead'] = replace_macros($tpl,array(
  551. '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
  552. '$local_user' => local_user(),
  553. '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
  554. '$delitem' => t('Delete this item?'),
  555. '$comment' => t('Comment'),
  556. '$showmore' => t('show more'),
  557. '$showfewer' => t('show fewer'),
  558. '$update_interval' => $interval,
  559. '$stylesheet' => $stylesheet
  560. )) . $this->page['htmlhead'];
  561. }
  562. function init_page_end() {
  563. if(!isset($this->page['end']))
  564. $this->page['end'] = '';
  565. $tpl = get_markup_template('end.tpl');
  566. $this->page['end'] = replace_macros($tpl,array(
  567. '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!!
  568. )) . $this->page['end'];
  569. }
  570. function set_curl_code($code) {
  571. $this->curl_code = $code;
  572. }
  573. function get_curl_code() {
  574. return $this->curl_code;
  575. }
  576. function set_curl_content_type($content_type) {
  577. $this->curl_content_type = $content_type;
  578. }
  579. function get_curl_content_type() {
  580. return $this->curl_content_type;
  581. }
  582. function set_curl_headers($headers) {
  583. $this->curl_headers = $headers;
  584. }
  585. function get_curl_headers() {
  586. return $this->curl_headers;
  587. }
  588. function get_cached_avatar_image($avatar_image){
  589. if($this->cached_profile_image[$avatar_image])
  590. return $this->cached_profile_image[$avatar_image];
  591. $path_parts = explode("/",$avatar_image);
  592. $common_filename = $path_parts[count($path_parts)-1];
  593. if($this->cached_profile_picdate[$common_filename]){
  594. $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename];
  595. } else {
  596. $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'",
  597. $common_filename);
  598. if(! count($r)){
  599. $this->cached_profile_image[$avatar_image] = $avatar_image;
  600. } else {
  601. $this->cached_profile_picdate[$common_filename] = "?rev=" . urlencode($r[0]['picdate']);
  602. $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename];
  603. }
  604. }
  605. return $this->cached_profile_image[$avatar_image];
  606. }
  607. /**
  608. * register template engine class
  609. * if $name is "", is used class static property $class::$name
  610. * @param string $class
  611. * @param string $name
  612. */
  613. function register_template_engine($class, $name = '') {
  614. if ($name===""){
  615. $v = get_class_vars( $class );
  616. if(x($v,"name")) $name = $v['name'];
  617. }
  618. if ($name===""){
  619. echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
  620. killme();
  621. }
  622. $this->template_engines[$name] = $class;
  623. }
  624. /**
  625. * return template engine instance. If $name is not defined,
  626. * return engine defined by theme, or default
  627. *
  628. * @param strin $name Template engine name
  629. * @return object Template Engine instance
  630. */
  631. function template_engine($name = ''){
  632. if ($name!=="") {
  633. $template_engine = $name;
  634. } else {
  635. $template_engine = 'smarty3';
  636. if (x($this->theme, 'template_engine')) {
  637. $template_engine = $this->theme['template_engine'];
  638. }
  639. }
  640. if (isset($this->template_engines[$template_engine])){
  641. if(isset($this->template_engine_instance[$template_engine])){
  642. return $this->template_engine_instance[$template_engine];
  643. } else {
  644. $class = $this->template_engines[$template_engine];
  645. $obj = new $class;
  646. $this->template_engine_instance[$template_engine] = $obj;
  647. return $obj;
  648. }
  649. }
  650. echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme();
  651. }
  652. function get_template_engine() {
  653. return $this->theme['template_engine'];
  654. }
  655. function set_template_engine($engine = 'smarty3') {
  656. $this->theme['template_engine'] = $engine;
  657. /*
  658. $this->theme['template_engine'] = 'smarty3';
  659. switch($engine) {
  660. case 'smarty3':
  661. if(is_writable('view/smarty3/'))
  662. $this->theme['template_engine'] = 'smarty3';
  663. break;
  664. default:
  665. break;
  666. }
  667. */
  668. }
  669. function get_template_ldelim($engine = 'smarty3') {
  670. return $this->ldelim[$engine];
  671. }
  672. function get_template_rdelim($engine = 'smarty3') {
  673. return $this->rdelim[$engine];
  674. }
  675. function save_timestamp($stamp, $value) {
  676. $duration = (float)(microtime(true)-$stamp);
  677. $this->performance[$value] += (float)$duration;
  678. $this->performance["marktime"] += (float)$duration;
  679. }
  680. function mark_timestamp($mark) {
  681. //$this->performance["markstart"] -= microtime(true) - $this->performance["marktime"];
  682. $this->performance["markstart"] = microtime(true) - $this->performance["markstart"] - $this->performance["marktime"];
  683. }
  684. }
  685. }
  686. // retrieve the App structure
  687. // useful in functions which require it but don't get it passed to them
  688. if(! function_exists('get_app')) {
  689. function get_app() {
  690. global $a;
  691. return $a;
  692. }
  693. };
  694. // Multi-purpose function to check variable state.
  695. // Usage: x($var) or $x($array,'key')
  696. // returns false if variable/key is not set
  697. // if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0.
  698. // e.g. x('') or x(0) returns 0;
  699. if(! function_exists('x')) {
  700. function x($s,$k = NULL) {
  701. if($k != NULL) {
  702. if((is_array($s)) && (array_key_exists($k,$s))) {
  703. if($s[$k])
  704. return (int) 1;
  705. return (int) 0;
  706. }
  707. return false;
  708. }
  709. else {
  710. if(isset($s)) {
  711. if($s) {
  712. return (int) 1;
  713. }
  714. return (int) 0;
  715. }
  716. return false;
  717. }
  718. }
  719. }
  720. // called from db initialisation if db is dead.
  721. if(! function_exists('system_unavailable')) {
  722. function system_unavailable() {
  723. include('system_unavailable.php');
  724. system_down();
  725. killme();
  726. }
  727. }
  728. function clean_urls() {
  729. global $a;
  730. // if($a->config['system']['clean_urls'])
  731. return true;
  732. // return false;
  733. }
  734. function z_path() {
  735. global $a;
  736. $base = $a->get_baseurl();
  737. if(! clean_urls())
  738. $base .= '/?q=';
  739. return $base;
  740. }
  741. function z_root() {
  742. global $a;
  743. return $a->get_baseurl();
  744. }
  745. function absurl($path) {
  746. if(strpos($path,'/') === 0)
  747. return z_path() . $path;
  748. return $path;
  749. }
  750. function is_ajax() {
  751. return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  752. }
  753. function check_db() {
  754. $build = get_config('system','build');
  755. if(! x($build)) {
  756. set_config('system','build',DB_UPDATE_VERSION);
  757. $build = DB_UPDATE_VERSION;
  758. }
  759. if($build != DB_UPDATE_VERSION)
  760. proc_run('php', 'include/dbupdate.php');
  761. }
  762. // Sets the base url for use in cmdline programs which don't have
  763. // $_SERVER variables
  764. if(! function_exists('check_url')) {
  765. function check_url(&$a) {
  766. $url = get_config('system','url');
  767. // if the url isn't set or the stored url is radically different
  768. // than the currently visited url, store the current value accordingly.
  769. // "Radically different" ignores common variations such as http vs https
  770. // and www.example.com vs example.com.
  771. // We will only change the url to an ip address if there is no existing setting
  772. if(! x($url))
  773. $url = set_config('system','url',$a->get_baseurl());
  774. if((! link_compare($url,$a->get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname)))
  775. $url = set_config('system','url',$a->get_baseurl());
  776. return;
  777. }
  778. }
  779. // Automatic database updates
  780. if(! function_exists('update_db')) {
  781. function update_db(&$a) {
  782. $build = get_config('system','build');
  783. if(! x($build))
  784. $build = set_config('system','build',DB_UPDATE_VERSION);
  785. if($build != DB_UPDATE_VERSION) {
  786. $stored = intval($build);
  787. $current = intval(DB_UPDATE_VERSION);
  788. if(($stored < $current) && file_exists('update.php')) {
  789. load_config('database');
  790. // We're reporting a different version than what is currently installed.
  791. // Run any existing update scripts to bring the database up to current.
  792. require_once('update.php');
  793. // make sure that boot.php and update.php are the same release, we might be
  794. // updating right this very second and the correct version of the update.php
  795. // file may not be here yet. This can happen on a very busy site.
  796. if(DB_UPDATE_VERSION == UPDATE_VERSION) {
  797. for($x = $stored; $x < $current; $x ++) {
  798. if(function_exists('update_' . $x)) {
  799. // There could be a lot of processes running or about to run.
  800. // We want exactly one process to run the update command.
  801. // So store the fact that we're taking responsibility
  802. // after first checking to see if somebody else already has.
  803. // If the update fails or times-out completely you may need to
  804. // delete the config entry to try again.
  805. $t = get_config('database','update_' . $x);
  806. if($t !== false)
  807. break;
  808. set_config('database','update_' . $x, time());
  809. // call the specific update
  810. $func = 'update_' . $x;
  811. $retval = $func();
  812. if($retval) {
  813. //send the administrator an e-mail
  814. $email_tpl = get_intltext_template("update_fail_eml.tpl");
  815. $email_msg = replace_macros($email_tpl, array(
  816. '$sitename' => $a->config['sitename'],
  817. '$siteurl' => $a->get_baseurl(),
  818. '$update' => $x,
  819. '$error' => sprintf( t('Update %s failed. See error logs.'), $x)
  820. ));
  821. $subject=sprintf(t('Update Error at %s'), $a->get_baseurl());
  822. require_once('include/email.php');
  823. $subject = email_header_encode($subject,'UTF-8');
  824. mail($a->config['admin_email'], $subject, $email_msg,
  825. 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
  826. . 'Content-type: text/plain; charset=UTF-8' . "\n"
  827. . 'Content-transfer-encoding: 8bit' );
  828. //try the logger
  829. logger('CRITICAL: Update Failed: '. $x);
  830. break;
  831. }
  832. else {
  833. set_config('database','update_' . $x, 'success');
  834. set_config('system','build', $x + 1);
  835. }
  836. }
  837. }
  838. }
  839. }
  840. }
  841. return;
  842. }
  843. }
  844. if(! function_exists('check_plugins')) {
  845. function check_plugins(&$a) {
  846. /**
  847. *
  848. * Synchronise plugins:
  849. *
  850. * $a->config['system']['addon'] contains a comma-separated list of names
  851. * of plugins/addons which are used on this system.
  852. * Go through the database list of already installed addons, and if we have
  853. * an entry, but it isn't in the config list, call the uninstall procedure
  854. * and mark it uninstalled in the database (for now we'll remove it).
  855. * Then go through the config list and if we have a plugin that isn't installed,
  856. * call the install procedure and add it to the database.
  857. *
  858. */
  859. $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
  860. if(count($r))
  861. $installed = $r;
  862. else
  863. $installed = array();
  864. $plugins = get_config('system','addon');
  865. $plugins_arr = array();
  866. if($plugins)
  867. $plugins_arr = explode(',',str_replace(' ', '',$plugins));
  868. $a->plugins = $plugins_arr;
  869. $installed_arr = array();
  870. if(count($installed)) {
  871. foreach($installed as $i) {
  872. if(! in_array($i['name'],$plugins_arr)) {
  873. uninstall_plugin($i['name']);
  874. }
  875. else {
  876. $installed_arr[] = $i['name'];
  877. }
  878. }
  879. }
  880. if(count($plugins_arr)) {
  881. foreach($plugins_arr as $p) {
  882. if(! in_array($p,$installed_arr)) {
  883. install_plugin($p);
  884. }
  885. }
  886. }
  887. load_hooks();
  888. return;
  889. }
  890. }
  891. function get_guid($size=16) {
  892. $exists = true; // assume by default that we don't have a unique guid
  893. do {
  894. $s = random_string($size);
  895. $r = q("select id from guid where guid = '%s' limit 1", dbesc($s));
  896. if(! count($r))
  897. $exists = false;
  898. } while($exists);
  899. q("insert into guid ( guid ) values ( '%s' ) ", dbesc($s));
  900. return $s;
  901. }
  902. // wrapper for adding a login box. If $register == true provide a registration
  903. // link. This will most always depend on the value of $a->config['register_policy'].
  904. // returns the complete html for inserting into the page
  905. if(! function_exists('login')) {
  906. function login($register = false, $hiddens=false) {
  907. $a = get_app();
  908. $o = "";
  909. $reg = false;
  910. if ($register) {
  911. $reg = array(
  912. 'title' => t('Create a New Account'),
  913. 'desc' => t('Register')
  914. );
  915. }
  916. $noid = get_config('system','no_openid');
  917. $dest_url = $a->get_baseurl(true) . '/' . $a->query_string;
  918. if(local_user()) {
  919. $tpl = get_markup_template("logout.tpl");
  920. }
  921. else {
  922. $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array(
  923. '$baseurl' => $a->get_baseurl(true)
  924. ));
  925. $tpl = get_markup_template("login.tpl");
  926. $_SESSION['return_url'] = $a->query_string;
  927. $a->module = 'login';
  928. }
  929. $o .= replace_macros($tpl, array(
  930. '$dest_url' => $dest_url,
  931. '$logout' => t('Logout'),
  932. '$login' => t('Login'),
  933. '$lname' => array('username', t('Nickname or Email address: ') , '', ''),
  934. '$lpassword' => array('password', t('Password: '), '', ''),
  935. '$lremember' => array('remember', t('Remember me'), 0, ''),
  936. '$openid' => !$noid,
  937. '$lopenid' => array('openid_url', t('Or login using OpenID: '),'',''),
  938. '$hiddens' => $hiddens,
  939. '$register' => $reg,
  940. '$lostpass' => t('Forgot your password?'),
  941. '$lostlink' => t('Password Reset'),
  942. '$tostitle' => t('Website Terms of Service'),
  943. '$toslink' => t('terms of service'),
  944. '$privacytitle' => t('Website Privacy Policy'),
  945. '$privacylink' => t('privacy policy'),
  946. ));
  947. call_hooks('login_hook',$o);
  948. return $o;
  949. }
  950. }
  951. // Used to end the current process, after saving session state.
  952. if(! function_exists('killme')) {
  953. function killme() {
  954. session_write_close();
  955. exit;
  956. }
  957. }
  958. // redirect to another URL and terminate this process.
  959. if(! function_exists('goaway')) {
  960. function goaway($s) {
  961. header("Location: $s");
  962. killme();
  963. }
  964. }
  965. // Returns the uid of locally logged in user or false.
  966. if(! function_exists('local_user')) {
  967. function local_user() {
  968. if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
  969. return intval($_SESSION['uid']);
  970. return false;
  971. }
  972. }
  973. // Returns contact id of authenticated site visitor or false
  974. if(! function_exists('remote_user')) {
  975. function remote_user() {
  976. if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
  977. return intval($_SESSION['visitor_id']);
  978. return false;
  979. }
  980. }
  981. // contents of $s are displayed prominently on the page the next time
  982. // a page is loaded. Usually used for errors or alerts.
  983. if(! function_exists('notice')) {
  984. /**
  985. * Show an error message to user.
  986. *
  987. * This function save text in session, to be shown to the user at next page load
  988. *
  989. * @param string $s - Text of notice
  990. */
  991. function notice($s) {
  992. $a = get_app();
  993. if(! x($_SESSION,'sysmsg')) $_SESSION['sysmsg'] = array();
  994. if($a->interactive)
  995. $_SESSION['sysmsg'][] = $s;
  996. }
  997. }
  998. if(! function_exists('info')) {
  999. /**
  1000. * Show an info message to user.
  1001. *
  1002. * This function save text in session, to be shown to the user at next page load
  1003. *
  1004. * @param string $s - Text of notice
  1005. */
  1006. function info($s) {
  1007. $a = get_app();
  1008. if (local_user() AND get_pconfig(local_user(),'system','ignore_info'))
  1009. return;
  1010. if(! x($_SESSION,'sysmsg_info')) $_SESSION['sysmsg_info'] = array();
  1011. if($a->interactive)
  1012. $_SESSION['sysmsg_info'][] = $s;
  1013. }
  1014. }
  1015. // wrapper around config to limit the text length of an incoming message
  1016. if(! function_exists('get_max_import_size')) {
  1017. function get_max_import_size() {
  1018. global $a;
  1019. return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
  1020. }
  1021. }
  1022. /**
  1023. *
  1024. * Function : profile_load
  1025. * @parameter App $a
  1026. * @parameter string $nickname
  1027. * @parameter int $profile
  1028. *
  1029. * Summary: Loads a profile into the page sidebar.
  1030. * The function requires a writeable copy of the main App structure, and the nickname
  1031. * of a registered local account.
  1032. *
  1033. * If the viewer is an authenticated remote viewer, the profile displayed is the
  1034. * one that has been configured for his/her viewing in the Contact manager.
  1035. * Passing a non-zero profile ID can also allow a preview of a selected profile
  1036. * by the owner.
  1037. *
  1038. * Profile information is placed in the App structure for later retrieval.
  1039. * Honours the owner's chosen theme for display.
  1040. *
  1041. * IMPORTANT: Should only be run in the _init() functions of a module. That ensures that
  1042. * the theme is chosen before the _init() function of a theme is run, which will usually
  1043. * load a lot of theme-specific content
  1044. *
  1045. */
  1046. if(! function_exists('profile_load')) {
  1047. function profile_load(&$a, $nickname, $profile = 0) {
  1048. $user = q("select uid from user where nickname = '%s' limit 1",
  1049. dbesc($nickname)
  1050. );
  1051. if(! ($user && count($user))) {
  1052. logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
  1053. notice( t('Requested account is not available.') . EOL );
  1054. $a->error = 404;
  1055. return;
  1056. }
  1057. if(remote_user() && count($_SESSION['remote'])) {
  1058. foreach($_SESSION['remote'] as $visitor) {
  1059. if($visitor['uid'] == $user[0]['uid']) {
  1060. $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
  1061. intval($visitor['cid'])
  1062. );
  1063. if(count($r))
  1064. $profile = $r[0]['profile-id'];
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. $r = null;
  1070. if($profile) {
  1071. $profile_int = intval($profile);
  1072. $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
  1073. INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
  1074. WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d and `contact`.`self` = 1 LIMIT 1",
  1075. dbesc($nickname),
  1076. intval($profile_int)
  1077. );
  1078. }
  1079. if((! $r) && (! count($r))) {
  1080. $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
  1081. INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
  1082. WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
  1083. dbesc($nickname)
  1084. );
  1085. }
  1086. if(($r === false) || (! count($r))) {
  1087. logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
  1088. notice( t('Requested profile is not available.') . EOL );
  1089. $a->error = 404;
  1090. return;
  1091. }
  1092. // fetch user tags if this isn't the default profile
  1093. if(! $r[0]['is-default']) {
  1094. $x = q("select `pub_keywords` from `profile` where uid = %d and `is-default` = 1 limit 1",
  1095. intval($r[0]['profile_uid'])
  1096. );
  1097. if($x && count($x))
  1098. $r[0]['pub_keywords'] = $x[0]['pub_keywords'];
  1099. }
  1100. $a->profile = $r[0];
  1101. $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
  1102. $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
  1103. $_SESSION['theme'] = $a->profile['theme'];
  1104. $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
  1105. /**
  1106. * load/reload current theme info
  1107. */
  1108. $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
  1109. $theme_info_file = "view/theme/".current_theme()."/theme.php";
  1110. if (file_exists($theme_info_file)){
  1111. require_once($theme_info_file);
  1112. }
  1113. if(! (x($a->page,'aside')))
  1114. $a->page['aside'] = '';
  1115. if(local_user() && local_user() == $a->profile['uid']) {
  1116. $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
  1117. '$editprofile' => t('Edit profile'),
  1118. '$profid' =&g