]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
file attachments
[friendica.git] / boot.php
index 0c2c3163b5bd2c803cdac7f06a4681948a562273..25c7fd14d0cbc29919ebe00e8c21fbfe4dc8ac2c 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1,15 +1,27 @@
 <?php
 
 set_time_limit(0);
+ini_set('pcre.backtrack_limit', 250000);
 
-define ( 'FRIENDIKA_VERSION',      '2.1.950' );
+
+define ( 'FRIENDIKA_VERSION',      '2.2.990' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.21'    );
-define ( 'DB_UPDATE_VERSION',      1051      );
+define ( 'DB_UPDATE_VERSION',      1058      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
 define ( 'DOWN_ARROW',             '&#x21e9;'       );
-         
+
+/**
+ *
+ * Image storage quality. Lower numbers save space at cost of image detail.
+ * For ease of upgrade, please do not change here. Change jpeg quality with 
+ * set_config('system','jpeg_quality',n) in .htconfig.php
+ * where n is netween 1 and 100, and with very poor results below about 50 
+ *
+ */
+
+define ( 'JPEG_QUALITY',            100  );         
 
 /**
  * SSL redirection policies
@@ -201,6 +213,7 @@ class App {
        public  $user;
        public  $cid;
        public  $contact;
+       public  $contacts;
        public  $page_contact;
        public  $content;
        public  $data;
@@ -277,7 +290,7 @@ class App {
                $this->argv = explode('/',$this->cmd);
                $this->argc = count($this->argv);
                if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
-                       $this->module = $this->argv[0];
+                       $this->module = str_replace(".", "_", $this->argv[0]);
                }
                else {
                        $this->module = 'home';
@@ -365,9 +378,9 @@ class App {
 
        function init_pagehead() {
                $this->page['title'] = $this->config['sitename'];
-               $tpl = load_view_file('view/head.tpl');
+               $tpl = file_get_contents('view/head.tpl');
                $this->page['htmlhead'] = replace_macros($tpl,array(
-                       '$baseurl' => $this->get_baseurl() . '/',
+                       '$baseurl' => $this->get_baseurl(),
                        '$generator' => 'Friendika' . ' ' . FRIENDIKA_VERSION,
                        '$delitem' => t('Delete this item?'),
                        '$comment' => t('Comment')
@@ -815,7 +828,7 @@ function escape_tags($string) {
 if(! function_exists('login')) {
 function login($register = false) {
        $o = "";
-       $register_tpl = (($register) ? load_view_file("view/register-link.tpl") : "");
+       $register_tpl = (($register) ? get_markup_template("register-link.tpl") : "");
        
        $register_html = replace_macros($register_tpl,array(
                '$title' => t('Create a New Account'),
@@ -839,14 +852,16 @@ function login($register = false) {
        $lostlink = t('Password Reset');
 
        if(local_user()) {
-               $tpl = load_view_file("view/logout.tpl");
+               $tpl = get_markup_template("logout.tpl");
        }
        else {
-               $tpl = load_view_file("view/login.tpl");
+               $tpl = get_markup_template("login.tpl");
 
        }
-       
-       $o = replace_macros($tpl,array(
+
+       $o = '<script type="text/javascript"> $(document).ready(function() { $("#login-name").focus();} );</script>';   
+
+       $o .= replace_macros($tpl,array(
                '$logout'        => t('Logout'),
                '$register_html' => $register_html, 
                '$classname'     => $classname,
@@ -992,6 +1007,13 @@ function notice($s) {
        if($a->interactive)
                $_SESSION['sysmsg'] .= $s;
 }}
+if(! function_exists('info')) {
+function info($s) {
+       $a = get_app();
+       if($a->interactive)
+               $_SESSION['sysmsg_info'] .= $s;
+}}
+
 
 // wrapper around config to limit the text length of an incoming message
 
@@ -1218,6 +1240,7 @@ function set_config($family,$key,$value) {
        global $a;
 
        if(get_config($family,$key,true) === false) {
+               $a->config[$family][$key] = $value;
                $ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
                        dbesc($family),
                        dbesc($key),
@@ -1312,6 +1335,7 @@ function set_pconfig($uid,$family,$key,$value) {
        global $a;
 
        if(get_pconfig($uid,$family,$key,true) === false) {
+               $a->config[$uid][$family][$key] = $value;
                $ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' ) ",
                        intval($uid),
                        dbesc($family),
@@ -1491,6 +1515,8 @@ function lrdd($uri) {
        logger('lrdd: host_meta: ' . $xml, LOGGER_DATA);
 
        $h = parse_xml_string($xml);
+       if(! $h)
+               return array();
 
        $arr = convert_xml_element_to_array($h);
 
@@ -1655,6 +1681,9 @@ function fetch_xrd_links($url) {
 
        logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
        $h = parse_xml_string($xml);
+       if(! $h)
+               return array();
+
        $arr = convert_xml_element_to_array($h);
 
        $links = array();
@@ -1847,6 +1876,8 @@ function allowed_email($email) {
 // wrapper to load a view template, checking for alternate
 // languages before falling back to the default
 
+// obsolete, deprecated.
+
 if(! function_exists('load_view_file')) {
 function load_view_file($s) {
        global $lang, $a;
@@ -1865,6 +1896,37 @@ function load_view_file($s) {
        return file_get_contents($s);
 }}
 
+if(! function_exists('get_intltext_template')) {
+function get_intltext_template($s) {
+       global $lang;
+
+       if(! isset($lang))
+               $lang = 'en';
+
+       if(file_exists("view/$lang/$s"))
+               return file_get_contents("view/$lang/$s");
+       elseif(file_exists("view/en/$s"))
+               return file_get_contents("view/en/$s");
+       else
+               return file_get_contents("view/$s");
+}}
+
+if(! function_exists('get_markup_template')) {
+function get_markup_template($s) {
+
+       $theme = current_theme();
+       
+       if(file_exists("view/theme/$theme/$s"))
+               return file_get_contents("view/theme/$theme/$s");
+       else
+               return file_get_contents("view/$s");
+
+}}
+
+
+
+
+
 // for html,xml parsing - let's say you've got
 // an attribute foobar="class1 class2 class3"
 // and you want to find out if it contains 'class3'.
@@ -1921,15 +1983,15 @@ function get_tags($s) {
        $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
 
        if(preg_match_all('/([@#][^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
-               foreach($match[1] as $match) {
-                       if(strstr($match,"]")) {
+               foreach($match[1] as $mtch) {
+                       if(strstr($mtch,"]")) {
                                // we might be inside a bbcode color tag - leave it alone
                                continue;
                        }
-                       if(substr($match,-1,1) === '.')
-                               $ret[] = substr($match,0,-1);
+                       if(substr($mtch,-1,1) === '.')
+                               $ret[] = substr($mtch,0,-1);
                        else
-                               $ret[] = $match;
+                               $ret[] = $mtch;
                }
        }
 
@@ -2006,7 +2068,7 @@ function contact_block() {
 }}
 
 if(! function_exists('micropro')) {
-function micropro($contact, $redirect = false, $class = '') {
+function micropro($contact, $redirect = false, $class = '', $textmode = false) {
 
        if($class)
                $class = ' ' . $class;
@@ -2025,11 +2087,20 @@ function micropro($contact, $redirect = false, $class = '') {
        $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
        if($click)
                $url = '';
-       return '<div class="contact-block-div' . $class . '"><a class="contact-block-link' . $class . $sparkle 
-               . (($click) ? ' fakelink' : '') . '" '
-               . (($url) ? '" href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="' 
-               . $contact['micro'] . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name'] 
-               . '" /></a></div>' . "\r\n";
+       if($textmode) {
+               return '<div class="contact-block-textdiv' . $class . '"><a class="contact-block-link' . $class . $sparkle 
+                       . (($click) ? ' fakelink' : '') . '" '
+                       . (($url) ? ' href="' . $url . '"' : '') . $click
+                       . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name'] 
+                       . '" >'. $contact['name'] . '</a></div>' . "\r\n";
+       }
+       else {
+               return '<div class="contact-block-div' . $class . '"><a class="contact-block-link' . $class . $sparkle 
+                       . (($click) ? ' fakelink' : '') . '" '
+                       . (($url) ? ' href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="' 
+                       . $contact['micro'] . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name'] 
+                       . '" /></a></div>' . "\r\n";
+       }
 }}
 
 
@@ -2125,7 +2196,7 @@ function smilies($s) {
        $a = get_app();
 
        return str_replace(
-       array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ';-)', ':-(', ':(', ':-P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
+       array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
        array(
                '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
@@ -2135,6 +2206,7 @@ function smilies($s) {
                '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
@@ -2252,8 +2324,15 @@ function profile_sidebar($profile) {
 
        $photo = '<div id="profile-photo-wrapper"><img class="photo" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>';
 
+       // don't show connect link to yourself
+       
        $connect = (($profile['uid'] != local_user()) ? '<li><a id="dfrn-request-link" href="dfrn_request/' . $profile['nickname'] . '">' . t('Connect') . '</a></li>' : '');
+
+       // don't show connect link to authenticated visitors either
+
+       if((remote_user()) && ($_SESSION['visitor_visiting'] == $profile['uid']))
+               $connect = ''; 
+
        if((x($profile,'address') == 1) 
                || (x($profile,'locality') == 1) 
                || (x($profile,'region') == 1) 
@@ -2282,7 +2361,11 @@ function profile_sidebar($profile) {
 
        $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>' : '');
 
-       $tpl = load_view_file('view/profile_vcard.tpl');
+       if($profile['hidewall'] && (! local_user()) && (! remote_user())) {
+               $location = $gender = $marital = $homepage = '';
+       }
+
+       $tpl = get_markup_template('profile_vcard.tpl');
 
        $o .= replace_macros($tpl, array(
                '$fullname' => $fullname,
@@ -2407,28 +2490,34 @@ function get_birthdays() {
                        if(strlen($rr['name']))
                                $total ++;
 
-               $o .= '<div id="birthday-notice" class="birthday-notice fakelink" onclick=openClose(\'birthday-wrapper\'); >' . t('Birthday Reminders') . ' ' . '(' . $total . ')' . '</div>'; 
-               $o .= '<div id="birthday-wrapper" style="display: none;" ><div id="birthday-title">' . t('Birthdays this week:') . '</div>'; 
-               $o .= '<div id="birthday-adjust">' . t("\x28Adjusted for local time\x29") . '</div>';
-               $o .= '<div id="birthday-title-end"></div>';
+               if($total) {
+                       $o .= '<div id="birthday-notice" class="birthday-notice fakelink" onclick=openClose(\'birthday-wrapper\'); >' . t('Birthday Reminders') . ' ' . '(' . $total . ')' . '</div>'; 
+                       $o .= '<div id="birthday-wrapper" style="display: none;" ><div id="birthday-title">' . t('Birthdays this week:') . '</div>'; 
+                       $o .= '<div id="birthday-adjust">' . t("\x28Adjusted for local time\x29") . '</div>';
+                       $o .= '<div id="birthday-title-end"></div>';
 
-               foreach($r as $rr) {
-                       if(! strlen($rr['name']))
-                               continue;
-                       $now = strtotime('now');
-                       $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false); 
-
-                       $o .= '<div class="birthday-list" id="birthday-' . $rr['eid'] . '"><a class="sparkle" href="' 
-                       . $a->get_baseurl() . '/redir/'  . $rr['cid'] . '">' . $rr['name'] . '</a> ' 
-                       . day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ?  ' ' . t('[today]') : '')
-                       . '</div>' ;
+                       foreach($r as $rr) {
+                               if(! strlen($rr['name']))
+                                       continue;
+                               $now = strtotime('now');
+                               $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false); 
+       
+                               $o .= '<div class="birthday-list" id="birthday-' . $rr['eid'] . '"><a class="sparkle" href="' 
+                               . $a->get_baseurl() . '/redir/'  . $rr['cid'] . '">' . $rr['name'] . '</a> ' 
+                               . day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ?  ' ' . t('[today]') : '')
+                               . '</div>' ;
+                       }
+                       $o .= '</div></div>';
                }
-
-               $o .= '</div></div>';
        }
+       return $o;
+}}
 
-  return $o;
 
+if(! function_exists('normalise_link')) {
+function normalise_link($url) {
+       $ret = str_replace(array('https:','//www.'), array('http:','//'), $url);
+       return(rtrim($ret,'/'));
 }}
 
 /**
@@ -2444,17 +2533,48 @@ function get_birthdays() {
 
 if(! function_exists('link_compare')) {
 function link_compare($a,$b) {
-       $a1 = str_replace(array('https:','//www.'), array('http:','//'), $a);
-       $b1 = str_replace(array('https:','//www.'), array('http:','//'), $b);
-       if(strcasecmp($a1,$b1) === 0)
+       if(strcasecmp(normalise_link($a),normalise_link($b)) === 0)
                return true;
        return false;
 }}
 
 
 if(! function_exists('prepare_body')) {
-function prepare_body($item) {
-       return prepare_text($item['body']);
+function prepare_body($item,$attach = false) {
+
+       $s = prepare_text($item['body']);
+       if(! $attach)
+               return $s;
+
+       $arr = explode(',',$item['attach']);
+       $s .= '<div class="body-attach">';
+       if(count($arr)) {
+               foreach($arr as $r) {
+                       $matches = false;
+                       $icon = '';
+                       $cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches);
+                       if($cnt) {
+                               $icontype = strtolower(substr($matches[3],0,strpos($matches[3],'/')));
+                               switch($icontype) {
+                                       case 'video':
+                                       case 'audio':
+                                       case 'image':
+                                       case 'text':
+                                               $icon = '<div class="attachtype type-' . $icontype . '"></div>';
+                                               break;
+                                       default:
+                                               $icon = '<div class="attachtype type-unkn"></div>';
+                                               break;
+                               }
+                               $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1]));
+                               $title .= ' ' . $matches[2] . ' ' . t('bytes');
+
+                               $s .= '<a href="' . strip_tags($matches[1]) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
+                       }
+               }
+       }
+       $s .= '<div class="clear"></div></div>';
+       return $s;
 }}
 
 if(! function_exists('prepare_text')) {
@@ -2506,7 +2626,7 @@ function current_theme(){
        $a = get_app();
        
        $system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
-       $theme_name = ((x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
+       $theme_name = ((is_array($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
        
        if($theme_name && file_exists('view/theme/' . $theme_name . '/style.css'))
                return($theme_name);
@@ -2621,7 +2741,7 @@ if(! function_exists('get_plink')) {
 function get_plink($item) {
        $a = get_app(); 
        $plink = (((x($item,'plink')) && (! $item['private'])) ? '<div class="wall-item-links-wrapper"><a href="' 
-                       . $item['plink'] . '" title="' . t('link to source') . '" target="external-link" ><img src="' . $a->get_baseurl() . '/images/remote-link.gif" alt="' . t('link to source') . '" /></a></div>' : '');
+                       . $item['plink'] . '" title="' . t('link to source') . '" target="external-link" class="icon remote-link"></a></div>' : '');
        return $plink;
 }}
 
@@ -2631,6 +2751,8 @@ function unamp($s) {
 }}
 
 
+
+
 if(! function_exists('lang_selector')) {
 function lang_selector() {
        global $lang;
@@ -2661,7 +2783,16 @@ function parse_xml_string($s) {
        $x = @simplexml_load_string($s2);
        if(count(libxml_get_errors()))
                foreach(libxml_get_errors() as $err)
-                       logger('libxml: parse: ' . $err, LOGGER_DATA);
+                       logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
        libxml_clear_errors();
        return $x;
 }}
+
+if(! function_exists('is_site_admin')) {
+function is_site_admin() {
+       $a = get_app();
+       if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
+               return true;
+       return false;
+}}
+