]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Merge pull request #415 from 23n/patch-2
[friendica.git] / boot.php
index b41b8d9a0e93d9d982a2d4fb9f905735de931263..da72b16ef2841ceb85d53b4d5cbbf1daab30247a 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -4,14 +4,16 @@ require_once('include/config.php');
 require_once('include/network.php');
 require_once('include/plugin.php');
 require_once('include/text.php');
+require_once('include/datetime.php');
 require_once('include/pgettext.php');
 require_once('include/nav.php');
 require_once('include/cache.php');
+require_once('library/Mobile_Detect/Mobile_Detect.php');
 
 define ( 'FRIENDICA_PLATFORM',     'Friendica');
-define ( 'FRIENDICA_VERSION',      '3.0.1355' );
+define ( 'FRIENDICA_VERSION',      '3.0.1418' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1144      );
+define ( 'DB_UPDATE_VERSION',      1154      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
@@ -28,6 +30,29 @@ define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
  */
 
 define ( 'JPEG_QUALITY',            100  );
+/**
+ * $a->config['system']['png_quality'] from 0 (uncompressed) to 9
+ */
+define ( 'PNG_QUALITY',             8  );
+
+/**
+ *
+ * An alternate way of limiting picture upload sizes. Specify the maximum pixel
+ * length that pictures are allowed to be (for non-square pictures, it will apply
+ * to the longest side). Pictures longer than this length will be resized to be
+ * this length (on the longest side, the other side will be scaled appropriately).
+ * Modify this value using
+ *
+ *    $a->config['system']['max_image_length'] = n;
+ *
+ * in .htconfig.php
+ *
+ * If you don't want to set a maximum length, set to -1. The default value is
+ * defined by 'MAX_IMAGE_LENGTH' below.
+ *
+ */
+define ( 'MAX_IMAGE_LENGTH',        -1  );
+
 
 /**
  * Not yet used
@@ -71,14 +96,6 @@ define ( 'CONTACT_IS_SHARING',  2);
 define ( 'CONTACT_IS_FRIEND',   3);
 
 
-/**
- * Hook array order
- */
-
-define ( 'HOOK_HOOK',      0);
-define ( 'HOOK_FILE',      1);
-define ( 'HOOK_FUNCTION',  2);
-
 /**
  * DB update return values
  */
@@ -175,15 +192,32 @@ define ( 'NOTIFY_SUGGEST',  0x0020 );
 define ( 'NOTIFY_PROFILE',  0x0040 );
 define ( 'NOTIFY_TAGSELF',  0x0080 );
 define ( 'NOTIFY_TAGSHARE', 0x0100 );
+define ( 'NOTIFY_POKE',     0x0200 );
 
 define ( 'NOTIFY_SYSTEM',   0x8000 );
 
 
+/**
+ * Tag/term types
+ */
+
+define ( 'TERM_UNKNOWN',   0 );
+define ( 'TERM_HASHTAG',   1 );
+define ( 'TERM_MENTION',   2 );   
+define ( 'TERM_CATEGORY',  3 );
+define ( 'TERM_PCATEGORY', 4 );
+define ( 'TERM_FILE',      5 );
+
+define ( 'TERM_OBJ_POST',  1 );
+define ( 'TERM_OBJ_PHOTO', 2 );
+
+
+
 /**
  * various namespaces we may need to parse
  */
 
-define ( 'NAMESPACE_ZOT',             'http://purl.org/macgirvin/zot' );
+define ( 'NAMESPACE_ZOT',             'http://purl.org/zot' );
 define ( 'NAMESPACE_DFRN' ,           'http://purl.org/macgirvin/dfrn/1.0' );
 define ( 'NAMESPACE_THREAD' ,         'http://purl.org/syndication/thread/1.0' );
 define ( 'NAMESPACE_TOMB' ,           'http://purl.org/atompub/tombstones/1.0' );
@@ -218,6 +252,8 @@ define ( 'ACTIVITY_UPDATE',      NAMESPACE_ACTIVITY_SCHEMA . 'update' );
 define ( 'ACTIVITY_TAG',         NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
 define ( 'ACTIVITY_FAVORITE',    NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
 
+define ( 'ACTIVITY_POKE',        NAMESPACE_ZOT . '/activity/poke' );
+
 define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
 define ( 'ACTIVITY_OBJ_NOTE',    NAMESPACE_ACTIVITY_SCHEMA . 'note' );
 define ( 'ACTIVITY_OBJ_PERSON',  NAMESPACE_ACTIVITY_SCHEMA . 'person' );
@@ -326,8 +362,17 @@ if(! class_exists('App')) {
                private $curl_code;
                private $curl_headers;
 
+               private $cached_profile_image;
+               private $cached_profile_picdate;
+                                                       
                function __construct() {
 
+                       global $default_timezone;
+
+                       $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
+
+                       date_default_timezone_set($this->timezone);
+
                        $this->config = array();
                        $this->page = array();
                        $this->pager= array();
@@ -345,6 +390,16 @@ if(! class_exists('App')) {
 
                        if(x($_SERVER,'SERVER_NAME')) {
                                $this->hostname = $_SERVER['SERVER_NAME'];
+
+                               // See bug 437 - this didn't work so disabling it
+                               //if(stristr($this->hostname,'xn--')) {
+                                       // PHP or webserver may have converted idn to punycode, so
+                                       // convert punycode back to utf-8
+                               //      require_once('library/simplepie/idn/idna_convert.class.php');
+                               //      $x = new idna_convert();
+                               //      $this->hostname = $x->decode($_SERVER['SERVER_NAME']);
+                               //}
+
                                if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
                                        $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
                                /**
@@ -362,6 +417,7 @@ if(! class_exists('App')) {
                                        . 'include' . PATH_SEPARATOR
                                        . 'library' . PATH_SEPARATOR
                                        . 'library/phpsec' . PATH_SEPARATOR
+                                       . 'library/langdet' . PATH_SEPARATOR
                                        . '.' );
 
                        if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
@@ -402,9 +458,6 @@ if(! class_exists('App')) {
                        $this->argc = count($this->argv);
                        if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
                                $this->module = str_replace(".", "_", $this->argv[0]);
-                               if(array_key_exists('2',$this->argv)) {
-                                       $this->category = $this->argv[2];
-                               }
                        }
                        else {
                                $this->argc = 1;
@@ -427,9 +480,11 @@ if(! class_exists('App')) {
                         * pagination
                         */
 
-                       $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
+                       $this->pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
                        $this->pager['itemspage'] = 50;
                        $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
+                       if($this->pager['start'] < 0)
+                               $this->pager['start'] = 0;
                        $this->pager['total'] = 0;
                }
 
@@ -494,7 +549,7 @@ if(! class_exists('App')) {
                }
 
                function set_pager_itemspage($n) {
-                       $this->pager['itemspage'] = intval($n);
+                       $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
                        $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
 
                }
@@ -505,7 +560,7 @@ if(! class_exists('App')) {
                                $interval = 40000;
 
                        $this->page['title'] = $this->config['sitename'];
-                       $tpl = file_get_contents('view/head.tpl');
+                       $tpl = get_markup_template('head.tpl');
                        $this->page['htmlhead'] = replace_macros($tpl,array(
                                '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
                                '$local_user' => local_user(),
@@ -518,6 +573,13 @@ if(! class_exists('App')) {
                        ));
                }
 
+               function init_page_end() {
+                       $tpl = get_markup_template('end.tpl');
+                       $this->page['end'] = replace_macros($tpl,array(
+                               '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!!
+                       ));
+               }
+
                function set_curl_code($code) {
                        $this->curl_code = $code;
                }
@@ -534,6 +596,28 @@ if(! class_exists('App')) {
                        return $this->curl_headers;
                }
 
+               function get_cached_avatar_image($avatar_image){
+                       if($this->cached_profile_image[$avatar_image])
+                               return $this->cached_profile_image[$avatar_image];
+
+                       $path_parts = explode("/",$avatar_image);
+                       $common_filename = $path_parts[count($path_parts)-1];
+
+                       if($this->cached_profile_picdate[$common_filename]){
+                               $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename];
+                       } else {
+                               $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like \"%%/%s\"",
+                                       $common_filename);
+                               if(! count($r)){
+                                       $this->cached_profile_image[$avatar_image] = $avatar_image;
+                               } else {
+                                       $this->cached_profile_picdate[$common_filename] = "?rev=" . urlencode($r[0]['picdate']);
+                                       $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename];
+                               }
+                       }
+                       return $this->cached_profile_image[$avatar_image];
+               }
+
 
        }
 }
@@ -671,9 +755,10 @@ if(! function_exists('check_config')) {
                                                        // If the update fails or times-out completely you may need to
                                                        // delete the config entry to try again.
 
-                                                       if(get_config('database','update_' . $x))
+                                                       $t = get_config('database','update_' . $x);
+                                                       if($t !== false)
                                                                break;
-                                                       set_config('database','update_' . $x, '1');
+                                                       set_config('database','update_' . $x, time());
 
                                                        // call the specific update
 
@@ -696,13 +781,14 @@ if(! function_exists('check_config')) {
                                                                        . 'Content-transfer-encoding: 8bit' );
                                                                //try the logger
                                                                logger('CRITICAL: Update Failed: '. $x);
+                                                               break;
                                                        }
-                                                       else
+                                                       else {
                                                                set_config('database','update_' . $x, 'success');
-                                                               
+                                                               set_config('system','build', $x + 1);
+                                                       }                                                               
                                                }
                                        }
-                                       set_config('system','build', DB_UPDATE_VERSION);
                                }
                        }
                }
@@ -1121,9 +1207,9 @@ if(! function_exists('profile_sidebar')) {
                        'fullname' => $profile['name'],
                        'firstname' => $firstname,
                        'lastname' => $lastname,
-                       'photo300' => $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
-                       'photo100' => $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
-                       'photo50' => $a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg',
+                       'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
+                       'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
+                       'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg'),
                );
 
                if (!$block){
@@ -1165,6 +1251,12 @@ if(! function_exists('get_birthdays')) {
                if(! local_user())
                        return $o;
 
+               $mobile_detect = new Mobile_Detect();
+               $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
+
+               if($is_mobile)
+                       return $o;
+
                $bd_format = t('g A l F d') ; // 8 AM Friday January 18
                $bd_short = t('F d');
 
@@ -1226,6 +1318,9 @@ if(! function_exists('get_birthdays')) {
                        '$event_reminders' => t('Birthday Reminders'),
                        '$event_title' => t('Birthdays this week:'),
                        '$events' => $r,
+                       '$lbr' => '{',  // raw brackets mess up if/endif macro processing
+                       '$rbr' => '}'
+
                ));
        }
 }
@@ -1241,6 +1336,13 @@ if(! function_exists('get_events')) {
                if(! local_user())
                        return $o;
 
+
+               $mobile_detect = new Mobile_Detect();
+               $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
+
+               if($is_mobile)
+                       return $o;
+
                $bd_format = t('g A l F d') ; // 8 AM Friday January 18
                $bd_short = t('F d');
 
@@ -1348,9 +1450,9 @@ if(! function_exists('proc_run')) {
 
                if(count($args) && $args[0] === 'php')
                        $args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-               foreach ($args as $arg){
-                       $arg = escapeshellarg($arg);
-               }
+               for($x = 0; $x < count($args); $x ++)
+                       $args[$x] = escapeshellarg($args[$x]);
+
                $cmdline = implode($args," ");
                proc_close(proc_open($cmdline." &",array(),$foo));
        }
@@ -1358,13 +1460,22 @@ if(! function_exists('proc_run')) {
 
 if(! function_exists('current_theme')) {
        function current_theme(){
-               $app_base_themes = array('duepuntozero', 'loozah');
+               $app_base_themes = array('duepuntozero', 'dispy', 'quattro');
        
                $a = get_app();
        
-               $system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
-               $theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
+               $mobile_detect = new Mobile_Detect();
+               $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
        
+               if($is_mobile) {
+                       $system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : '');
+                       $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
+               }
+               if(!$is_mobile || ($system_theme === '' && $theme_name === '')) {
+                       $system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
+                       $theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
+               }
+
                if($theme_name &&
                                (file_exists('view/theme/' . $theme_name . '/style.css') ||
                                                file_exists('view/theme/' . $theme_name . '/style.php')))
@@ -1376,7 +1487,7 @@ if(! function_exists('current_theme')) {
                                return($t);
                }
        
-               $fallback = glob('view/theme/*/style.[css|php]');
+               $fallback = array_merge(glob('view/theme/*/style.css'),glob('view/theme/*/style.php'));
                if(count($fallback))
                        return (str_replace('view/theme/','', substr($fallback[0],0,-10)));
        
@@ -1500,18 +1611,21 @@ if(! function_exists('profile_tabs')){
                                'url' => $url,
                                'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
                                'title' => t('Status Messages and Posts'),
+                               'id' => 'status-tab',
                        ),
                        array(
                                'label' => t('Profile'),
                                'url'   => $url.'/?tab=profile',
                                'sel'   => ((isset($tab) && $tab=='profile')?'active':''),
                                'title' => t('Profile Details'),
+                               'id' => 'profile-tab',
                        ),
                        array(
                                'label' => t('Photos'),
                                'url'   => $a->get_baseurl() . '/photos/' . $nickname,
                                'sel'   => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
                                'title' => t('Photo Albums'),
+                               'id' => 'photo-tab',
                        ),
                );
        
@@ -1521,12 +1635,14 @@ if(! function_exists('profile_tabs')){
                                'url'   => $a->get_baseurl() . '/events',
                                'sel'   =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
                                'title' => t('Events and Calendar'),
+                               'id' => 'events-tab',
                        );
                        $tabs[] = array(
                                'label' => t('Personal Notes'),
                                'url'   => $a->get_baseurl() . '/notes',
                                'sel'   =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
                                'title' => t('Only You Can See This'),
+                               'id' => 'notes-tab',
                        );
                }
 
@@ -1568,3 +1684,30 @@ function zrl($s,$force = false) {
                return $s . $achar . 'zrl=' . urlencode($mine);
        return $s;
 }
+
+/**
+* returns querystring as string from a mapped array
+*
+* @param params Array 
+* @return string
+*/
+function build_querystring($params, $name=null) { 
+    $ret = ""; 
+    foreach($params as $key=>$val) {
+        if(is_array($val)) { 
+            if($name==null) {
+                $ret .= build_querystring($val, $key); 
+            } else {
+                $ret .= build_querystring($val, $name."[$key]");    
+            }
+        } else {
+            $val = urlencode($val);
+            if($name!=null) {
+                $ret.=$name."[$key]"."=$val&"; 
+            } else {
+                $ret.= "$key=$val&"; 
+            }
+        } 
+    } 
+    return $ret;    
+}