]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Merge pull request #351 from annando/master
[friendica.git] / boot.php
index 105180c23170a0f9b5c33cb95fd91c1ecef3c8be..be47184aa254e541c5c52c104f88a162b622c814 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -4,14 +4,15 @@ 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');
 
 define ( 'FRIENDICA_PLATFORM',     'Friendica');
-define ( 'FRIENDICA_VERSION',      '2.3.1326' );
+define ( 'FRIENDICA_VERSION',      '3.0.1382' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1139      );
+define ( 'DB_UPDATE_VERSION',      1149      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
@@ -28,6 +29,17 @@ 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  );
+
+
+/**
+ * Not yet used
+ */
+
+define ( 'DEFAULT_DB_ENGINE',  'MyISAM'  );
 
 /**
  * SSL redirection policies
@@ -66,12 +78,12 @@ define ( 'CONTACT_IS_FRIEND',   3);
 
 
 /**
- * Hook array order
+ * DB update return values
  */
 
-define ( 'HOOK_HOOK',      0);
-define ( 'HOOK_FILE',      1);
-define ( 'HOOK_FUNCTION',  2);
+define ( 'UPDATE_SUCCESS', 0);
+define ( 'UPDATE_FAILED',  1);
+
 
 /**
  *
@@ -109,6 +121,8 @@ define ( 'NETWORK_XMPP',             'xmpp');    // XMPP
 define ( 'NETWORK_MYSPACE',          'mysp');    // MySpace
 define ( 'NETWORK_GPLUS',            'goog');    // Google+
 
+define ( 'NETWORK_PHANTOM',          'unkn');    // Place holder
+
 /**
  * These numbers are used in stored permissions
  * and existing allocations MUST NEVER BE CHANGED
@@ -128,6 +142,8 @@ $netgroup_ids = array(
        NETWORK_XMPP     => (-10),
        NETWORK_MYSPACE  => (-11),
        NETWORK_GPLUS    => (-12),
+
+       NETWORK_PHANTOM  => (-127),
 );
 
 
@@ -193,6 +209,8 @@ define ( 'ACTIVITY_REQ_FRIEND',  NAMESPACE_ACTIVITY_SCHEMA . 'request-friend' );
 define ( 'ACTIVITY_UNFRIEND',    NAMESPACE_ACTIVITY_SCHEMA . 'remove-friend' );
 define ( 'ACTIVITY_FOLLOW',      NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
 define ( 'ACTIVITY_UNFOLLOW',    NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
+define ( 'ACTIVITY_JOIN',        NAMESPACE_ACTIVITY_SCHEMA . 'join' );
+
 define ( 'ACTIVITY_POST',        NAMESPACE_ACTIVITY_SCHEMA . 'post' );
 define ( 'ACTIVITY_UPDATE',      NAMESPACE_ACTIVITY_SCHEMA . 'update' );
 define ( 'ACTIVITY_TAG',         NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
@@ -205,6 +223,7 @@ define ( 'ACTIVITY_OBJ_PHOTO',   NAMESPACE_ACTIVITY_SCHEMA . 'photo' );
 define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' );
 define ( 'ACTIVITY_OBJ_ALBUM',   NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' );
 define ( 'ACTIVITY_OBJ_EVENT',   NAMESPACE_ACTIVITY_SCHEMA . 'event' );
+define ( 'ACTIVITY_OBJ_GROUP',   NAMESPACE_ACTIVITY_SCHEMA . 'group' );
 define ( 'ACTIVITY_OBJ_TAGTERM', NAMESPACE_DFRN            . '/tagterm' );
 define ( 'ACTIVITY_OBJ_PROFILE', NAMESPACE_DFRN            . '/profile' );
 
@@ -305,8 +324,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();
@@ -381,9 +409,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;
@@ -406,7 +431,7 @@ 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'];
                        $this->pager['total'] = 0;
@@ -420,22 +445,19 @@ if(! class_exists('App')) {
                                if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL))
                                        $scheme = 'https';
 
-                               //                      We need to populate the $ssl flag across the entire program before turning this on.
-                               //                      Basically, we'll have $ssl = true on any links which can only be seen by a logged in user
-                               //                      (and also the login link). Anything seen by an outsider will have it turned off.
-                               //                      At present, setting SSL_POLICY_SELFSIGN will only force remote contacts to update their
-                               //                      contact links to this site with "http:" if they are currently using "https:"
-
-                               //                      if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
-                               //                              if($ssl)
-                               //                                      $scheme = 'https';
-                               //                              else
-                               //                                      $scheme = 'http';
-                                       //                      }
-               }
+                               //      Basically, we have $ssl = true on any links which can only be seen by a logged in user
+                               //      (and also the login link). Anything seen by an outsider will have it turned off.
 
-                               $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
-                               return $this->baseurl;
+                               if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
+                                       if($ssl)
+                                               $scheme = 'https';
+                                       else
+                                               $scheme = 'http';
+                               }
+                       }
+
+                       $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
+                       return $this->baseurl;
                }
 
                function set_baseurl($url) {
@@ -476,7 +498,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'];
 
                }
@@ -490,6 +512,7 @@ if(! class_exists('App')) {
                        $tpl = file_get_contents('view/head.tpl');
                        $this->page['htmlhead'] = replace_macros($tpl,array(
                                '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
+                               '$local_user' => local_user(),
                                '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
                                '$delitem' => t('Delete this item?'),
                                '$comment' => t('Comment'),
@@ -515,6 +538,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];
+               }
+
 
        }
 }
@@ -658,32 +703,29 @@ if(! function_exists('check_config')) {
 
                                                        // call the specific update
 
-//                                                     global $db;
-//                                                     $db->excep(TRUE);
-//                                                     try {
-//                                                             $db->beginTransaction();
-                                                               $func = 'update_' . $x;
-                                                               $func($a);
-//                                                             $db->commit();
-//                                                     } catch(Exception $ex) {
-//                                                             $db->rollback();
-//                                                             //send the administrator an e-mail
-//                                                             $email_tpl = get_intltext_template("update_fail_eml.tpl");
-//                                                             $email_tpl = replace_macros($email_tpl, array(
-//                                                                     '$sitename' => $a->config['sitename'],
-//                                                                     '$siteurl' =>  $a->get_baseurl(),
-//                                                                     '$update' => $x,
-//                                                                     '$error' => $ex->getMessage()));
-//                                                             $subject=sprintf(t('Update Error at %s'), $a->get_baseurl());
+                                                       $func = 'update_' . $x;
+                                                       $retval = $func();
+                                                       if($retval) {
+                                                               //send the administrator an e-mail
+                                                               $email_tpl = get_intltext_template("update_fail_eml.tpl");
+                                                               $email_msg = replace_macros($email_tpl, array(
+                                                                       '$sitename' => $a->config['sitename'],
+                                                                       '$siteurl' =>  $a->get_baseurl(),
+                                                                       '$update' => $x,
+                                                                       '$error' => sprintf( t('Update %s failed. See error logs.'), $x)
+                                                               ));
+                                                               $subject=sprintf(t('Update Error at %s'), $a->get_baseurl());
                                                                        
-//                                                             mail($a->config['admin_email'], $subject, $text,
-//                                                                             'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
-//                                                                             . 'Content-type: text/plain; charset=UTF-8' . "\n"
-//                                                                             . 'Content-transfer-encoding: 8bit' );
-//                                                             //try the logger
-//                                                             logger('update failed: '.$ex->getMessage().EOL);
-//                                                     }
-//                                                     $db->excep(FALSE);
+                                                               mail($a->config['admin_email'], $subject, $email_msg,
+                                                                       'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
+                                                                       . 'Content-type: text/plain; charset=UTF-8' . "\n"
+                                                                       . 'Content-transfer-encoding: 8bit' );
+                                                               //try the logger
+                                                               logger('CRITICAL: Update Failed: '. $x);
+                                                       }
+                                                       else
+                                                               set_config('database','update_' . $x, 'success');
+                                                               
                                                }
                                        }
                                        set_config('system','build', DB_UPDATE_VERSION);
@@ -725,9 +767,10 @@ if(! function_exists('check_config')) {
                        foreach($installed as $i) {
                                if(! in_array($i['name'],$plugins_arr)) {
                                        uninstall_plugin($i['name']);
-                       }
-                               else
+                               }
+                               else {
                                        $installed_arr[] = $i['name'];
+                               }
                        }
                }
 
@@ -1104,9 +1147,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){
@@ -1304,6 +1347,25 @@ if(! function_exists('proc_run')) {
                $a = get_app();
 
                $args = func_get_args();
+
+               $newargs = array();
+               if(! count($args))
+                       return;
+
+               // expand any arrays
+
+               foreach($args as $arg) {
+                       if(is_array($arg)) {
+                               foreach($arg as $n) {
+                                       $newargs[] = $n;
+                               }
+                       }
+                       else
+                               $newargs[] = $arg;
+               }
+
+               $args = $newargs;
+               
                $arr = array('args' => $args, 'run_cmd' => true);
 
                call_hooks("proc_run", $arr);
@@ -1322,7 +1384,7 @@ 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();
        
@@ -1340,7 +1402,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)));
        
@@ -1463,16 +1525,19 @@ if(! function_exists('profile_tabs')){
                                'label'=>t('Status'),
                                'url' => $url,
                                'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
+                               'title' => t('Status Messages and Posts'),
                        ),
                        array(
                                'label' => t('Profile'),
                                'url'   => $url.'/?tab=profile',
                                'sel'   => ((isset($tab) && $tab=='profile')?'active':''),
+                               'title' => t('Profile Details'),
                        ),
                        array(
                                'label' => t('Photos'),
                                'url'   => $a->get_baseurl() . '/photos/' . $nickname,
                                'sel'   => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
+                               'title' => t('Photo Albums'),
                        ),
                );
        
@@ -1481,11 +1546,13 @@ if(! function_exists('profile_tabs')){
                                'label' => t('Events'),
                                'url'   => $a->get_baseurl() . '/events',
                                'sel'   =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
+                               'title' => t('Events and Calendar'),
                        );
                        $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'),
                        );
                }
 
@@ -1505,6 +1572,15 @@ function get_my_url() {
        return false;
 }
 
+function zrl_init(&$a) {
+       $tmp_str = get_my_url();
+       if(validate_url($tmp_str)) {
+               proc_run('php','include/gprobe.php',bin2hex($tmp_str));
+               $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
+               call_hooks('zrl_init',$arr);
+       }
+}
+
 function zrl($s,$force = false) {
        if(! strlen($s))
                return $s;
@@ -1518,3 +1594,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;    
+}