]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'remotes/friendica/master' into moveme
authorFabrixxm <fabrix.xm@gmail.com>
Mon, 5 Nov 2012 08:37:58 +0000 (09:37 +0100)
committerFabrixxm <fabrix.xm@gmail.com>
Mon, 5 Nov 2012 08:37:58 +0000 (09:37 +0100)
23 files changed:
.gitignore
boot.php
include/cronhooks.php
include/dba.php
include/delivery.php
include/directory.php
include/expire.php
include/gprobe.php
include/items.php
include/notifier.php
include/onepoll.php
include/poller.php
include/queue.php
include/uimport.php [new file with mode: 0644]
mod/dfrn_notify.php
mod/register.php
mod/uexport.php
mod/uimport.php [new file with mode: 0644]
util/po2php.php
view/atom_relocate.tpl [new file with mode: 0644]
view/register.tpl
view/uexport.tpl [new file with mode: 0644]
view/uimport.tpl [new file with mode: 0644]

index 5fe71a7a87e6916b164cab5500c810b2d2e4bab7..358114a44481357fd2f6e4a8bb4f134fcde35b85 100644 (file)
@@ -1,26 +1,27 @@
-favicon.*
-.htconfig.php
-\#*
-include/jquery-1.4.2.min.js
-*.log
-*.out
-*.version*
-favicon.*
-home.html
-addon
-*~
-
-#ignore documentation, it should be newly built 
-doc/api
-
-#ignore reports, should be generted with every build
-report/
-
-#ignore config files from eclipse, we don't want IDE files in our repository
-.project
-.buildpath
-.externalToolBuilders
-.settings
-#ignore OSX .DS_Store files 
-.DS_Store
-
+favicon.*\r
+.htconfig.php\r
+\#*\r
+include/jquery-1.4.2.min.js\r
+*.log\r
+*.out\r
+*.version*\r
+favicon.*\r
+home.html\r
+addon\r
+*~\r
+\r
+#ignore documentation, it should be newly built \r
+doc/api\r
+\r
+#ignore reports, should be generted with every build\r
+report/\r
+\r
+#ignore config files from eclipse, we don't want IDE files in our repository\r
+.project\r
+.buildpath\r
+.externalToolBuilders\r
+.settings\r
+#ignore OSX .DS_Store files \r
+.DS_Store\r
+\r
+/nbproject/private/
\ No newline at end of file
index 2628c0f3f113fb46de4aa7625f2c82331a56a902..cd309d86552548e4bbd9b314e1ea38b35af9dfcc 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -385,7 +385,7 @@ if(! class_exists('App')) {
                                                        
                function __construct() {
 
-                       global $default_timezone;
+                       global $default_timezone, $argv, $argc;
 
                        $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
 
@@ -428,6 +428,9 @@ if(! class_exists('App')) {
                                if(isset($path) && strlen($path) && ($path != $this->path))
                                        $this->path = $path;
                        }
+                       if (is_array($argv) && $argc>1 && !x($_SERVER,'SERVER_NAME') && substr(end($argv), 0, 4)=="http" ) {
+                               $this->set_baseurl(array_pop($argv) );
+                       }
 
                        set_include_path(
                                        "include/$this->hostname" . PATH_SEPARATOR
@@ -436,6 +439,7 @@ if(! class_exists('App')) {
                                        . 'library/phpsec' . PATH_SEPARATOR
                                        . 'library/langdet' . PATH_SEPARATOR
                                        . '.' );
+            
 
                        if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
                                $this->query_string = substr($_SERVER['QUERY_STRING'],2);
@@ -1501,9 +1505,15 @@ 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');
-               for($x = 0; $x < count($args); $x ++)
+        
+        // add baseurl to args. cli scripts can't construct it
+        $args[] = $a->get_baseurl();
+        
+        for($x = 0; $x < count($args); $x ++)
                        $args[$x] = escapeshellarg($args[$x]);
 
+        
+
                $cmdline = implode($args," ");
                if(get_config('system','proc_windows'))
                        proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__)));
index 37541f013e97abbd9b912459f2b2d461abf8946f..27cf642b22776d238fff3447a061321c6799993d 100644 (file)
@@ -3,7 +3,7 @@
 require_once("boot.php");
 
 
-function cronhooks_run($argv, $argc){
+function cronhooks_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)) {
index 8d224b570f44299c431f087392cc5e735787ef27..9f2dab51915e498f4e092cbd7bc4c9ed011c7470 100644 (file)
@@ -232,8 +232,9 @@ function q($sql) {
 
        if($db && $db->connected) {
                $stmt = vsprintf($sql,$args);
+               //logger("dba: q: $stmt", LOGGER_ALL);
                if($stmt === false)
-                       logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true));
+                       logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG);
                return $db->q($stmt);
        }
 
index 613453bc7adec9985087c37b644f759c94b315cc..4280359735c7ab317f1ec484b8f9a9aa6c375adc 100644 (file)
@@ -3,7 +3,7 @@ require_once("boot.php");
 require_once('include/queue_fn.php');
 require_once('include/html2plain.php');
 
-function delivery_run($argv, $argc){
+function delivery_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)){
index 45386183c611c3fdce5470eeecdca1ef9df2fa6b..356118bb08d5ca1dbef2ec824399275732768de2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 require_once("boot.php");
 
-function directory_run($argv, $argc){
+function directory_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)) {
index 755cd2494b94ee108547c45898649d61966a9823..373ebf55fead6df625e33bc716104c4139319bb0 100644 (file)
@@ -2,7 +2,7 @@
 
 require_once("boot.php");
 
-function expire_run($argv, $argc){
+function expire_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)) {
index 5ca42729a701c60159bfd2b0213831ee86bef229..88e6bad4a4f6ccb3329f7aed9e935d29a40f9ebd 100644 (file)
@@ -4,7 +4,7 @@ require_once("boot.php");
 require_once('include/Scrape.php');
 require_once('include/socgraph.php');
 
-function gprobe_run($argv, $argc){
+function gprobe_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)) {
index 939cefc3dd70578635ed5f378dc9217ee845662f..5ad89d8c180d9afeeb3e20706db2e1aeb4651cfd 100755 (executable)
@@ -2168,9 +2168,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
 }
 
 function local_delivery($importer,$data) {
-
        $a = get_app();
 
+    logger(__function__, LOGGER_TRACE);
+
        if($importer['readonly']) {
                // We aren't receiving stuff from this person. But we will quietly ignore them
                // rather than a blatant "go away" message.
@@ -2305,7 +2306,7 @@ function local_delivery($importer,$data) {
        }
 
 
-/*
+
        // Currently unsupported - needs a lot of work
        $reloc = $feed->get_feed_tags( NAMESPACE_DFRN, 'relocate' );
        if(isset($reloc[0]['child'][NAMESPACE_DFRN])) {
@@ -2315,23 +2316,79 @@ function local_delivery($importer,$data) {
                $newloc['cid'] = $importer['id'];
                $newloc['name'] = notags(unxmlify($base['name'][0]['data']));
                $newloc['photo'] = notags(unxmlify($base['photo'][0]['data']));
+               $newloc['thumb'] = notags(unxmlify($base['thumb'][0]['data']));
+               $newloc['micro'] = notags(unxmlify($base['micro'][0]['data']));
                $newloc['url'] = notags(unxmlify($base['url'][0]['data']));
                $newloc['request'] = notags(unxmlify($base['request'][0]['data']));
                $newloc['confirm'] = notags(unxmlify($base['confirm'][0]['data']));
                $newloc['notify'] = notags(unxmlify($base['notify'][0]['data']));
                $newloc['poll'] = notags(unxmlify($base['poll'][0]['data']));
-               $newloc['site-pubkey'] = notags(unxmlify($base['site-pubkey'][0]['data']));
-               $newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
-               $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));
+               $newloc['sitepubkey'] = notags(unxmlify($base['sitepubkey'][0]['data']));
+               /** relocated user must have original key pair */
+               /*$newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
+               $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));*/
+               
+        logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG);
+        
+        // update contact
+        $r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;",
+                    intval($importer['id']),
+                                       intval($importer['importer_uid']));
+               if ($r === false) 
+                       return 1;
+        $old = $r[0];
+        
+        $x = q("UPDATE contact SET
+                        name = '%s',
+                        photo = '%s',
+                        thumb = '%s',
+                        micro = '%s',
+                        url = '%s',
+                        request = '%s',
+                        confirm = '%s',
+                        notify = '%s',
+                        poll = '%s',
+                        `site-pubkey` = '%s'
+                WHERE id=%d AND uid=%d;",
+                    dbesc($newloc['name']),
+                    dbesc($newloc['photo']),
+                    dbesc($newloc['thumb']),
+                    dbesc($newloc['micro']),
+                    dbesc($newloc['url']),
+                    dbesc($newloc['request']),
+                    dbesc($newloc['confirm']),
+                    dbesc($newloc['notify']),
+                    dbesc($newloc['poll']),
+                    dbesc($newloc['sitepubkey']),
+                    intval($importer['id']),
+                                       intval($importer['importer_uid']));
+
+        if ($x === false)
+                       return 1;
+        // update items
+        $fields = array(
+            'owner-link' => array($old['url'], $newloc['url']),
+            'author-link' => array($old['url'], $newloc['url']),
+            'owner-avatar' => array($old['photo'], $newloc['photo']),
+            'author-avatar' => array($old['photo'], $newloc['photo']),
+        );
+        foreach ($fields as $n=>$f){
+            $x = q("UPDATE item SET `%s`='%s' WHERE `%s`='%s' AND uid=%d",
+                        $n, dbesc($f[1]),
+                        $n, dbesc($f[0]),
+                        intval($importer['importer_uid']));
+                       if ($x === false)
+                               return 1;
+               }
                
                // TODO
                // merge with current record, current contents have priority
                // update record, set url-updated
                // update profile photos
                // schedule a scan?
-
+        return 0;
        }
-*/
+
 
        // handle friend suggestion notification
 
index a999c3297b4c55cc3096f723c55b5302a9d2d23a..c58a8a854f60420b501606c8e426e60acbba2c82 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 require_once("boot.php");
 require_once('include/queue_fn.php');
 require_once('include/html2plain.php');
@@ -43,7 +42,7 @@ require_once('include/html2plain.php');
  */
 
 
-function notifier_run($argv, $argc){
+function notifier_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)){
@@ -89,6 +88,7 @@ function notifier_run($argv, $argc){
        $expire = false;
        $mail = false;
        $fsuggest = false;
+    $relocate = false;
        $top_level = false;
        $recipients = array();
        $url_recipients = array();
@@ -148,8 +148,12 @@ function notifier_run($argv, $argc){
                }
                return;
        }
+    elseif($cmd === 'relocate') {
+        $normal_mode = false;
+               $relocate = true;
+        $uid = $item_id;
+    }
        else {
-
                // find ancestors
                $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
                        intval($item_id)
@@ -214,7 +218,7 @@ function notifier_run($argv, $argc){
        // fill this in with a single salmon slap if applicable
        $slap = '';
 
-       if(! ($mail || $fsuggest)) {
+       if(! ($mail || $fsuggest || $relocate)) {
 
                require_once('include/group.php');
 
@@ -418,6 +422,45 @@ function notifier_run($argv, $argc){
                );
 
        }
+    elseif($relocate) {
+        $public_message = false;  // suggestions are not public
+
+               $sugg_template = get_markup_template('atom_relocate.tpl');
+
+               /* get site pubkey. this could be a new installation with no site keys*/
+               $pubkey = get_config('system','site_pubkey');
+               if(! $pubkey) {
+                       $res = new_keypair(1024);
+                       set_config('system','site_prvkey', $res['prvkey']);
+                       set_config('system','site_pubkey', $res['pubkey']);
+               }
+               
+               $rp = q("SELECT `resource-id` , `scale`, type FROM `photo` 
+                                               WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
+               $photos = array();
+               $ext = Photo::supportedTypes();
+               foreach($rp as $p){
+                       $photos[$p['scale']] = $a->get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
+               }
+               unset($rp, $ext);
+               
+        $atom .= replace_macros($sugg_template, array(
+            '$name' => xmlify($owner['name']),
+            '$photo' => xmlify($photos[4]),
+            '$thumb' => xmlify($photos[5]),
+            '$micro' => xmlify($photos[6]),
+            '$url' => xmlify($owner['url']),
+            '$request' => xmlify($owner['request']),
+            '$confirm' => xmlify($owner['confirm']),
+            '$notify' => xmlify($owner['notify']),
+            '$poll' => xmlify($owner['poll']),
+            '$sitepubkey' => xmlify(get_config('system','site_pubkey')),
+            //'$pubkey' => xmlify($owner['pubkey']),
+            //'$prvkey' => xmlify($owner['prvkey']),
+               )); 
+        $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d  AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
+               unset($photos);
+    }
        else {
                if($followup) {
                        foreach($items as $item) {  // there is only one item
@@ -493,9 +536,12 @@ function notifier_run($argv, $argc){
        else
                $recip_str = implode(', ', $recipients);
 
-       $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
-               dbesc($recip_str)
-       );
+    if ($relocate)
+        $r = $recipients_relocate;
+    else
+        $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
+            dbesc($recip_str)
+        );
 
 
        require_once('include/salmon.php');
@@ -507,7 +553,7 @@ function notifier_run($argv, $argc){
        if(count($r)) {
 
                foreach($r as $contact) {
-                       if((! $mail) && (! $fsuggest) && (! $followup) && (! $contact['self'])) {
+                       if((! $mail) && (! $fsuggest) && (! $followup) && (!$relocate) && (! $contact['self'])) {
                                if(($contact['network'] === NETWORK_DIASPORA) && ($public_message))
                                        continue;
                                q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
@@ -544,7 +590,7 @@ function notifier_run($argv, $argc){
                        // potentially more than one recipient. Start a new process and space them out a bit.
                        // we will deliver single recipient types of message and email recipients here. 
                
-                       if((! $mail) && (! $fsuggest) && (! $followup)) {
+                       if((! $mail) && (! $fsuggest) && (!$relocate) && (! $followup)) {
 
                                $this_batch[] = $contact['id'];
 
@@ -559,7 +605,7 @@ function notifier_run($argv, $argc){
 
                        $deliver_status = 0;
 
-                       logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest");
+                       logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest relocate=$relocate");
 
                        switch($contact['network']) {
                                case NETWORK_DFRN:
@@ -916,6 +962,7 @@ function notifier_run($argv, $argc){
        return;
 }
 
+
 if (array_search(__file__,get_included_files())===0){
   notifier_run($argv,$argc);
   killme();
index 9fbef168c6fa4d594f1fc875ce430794c616b959..019455e820350cd98b996784286a4e13e281e558 100644 (file)
@@ -2,7 +2,7 @@
 
 require_once("boot.php");
 
-function onepoll_run($argv, $argc){
+function onepoll_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)) {
index 1af23eb13bae095b7422121b3667557e07aa55e8..d5efa36a832b42544b9840ba134589d14286c75b 100644 (file)
@@ -3,7 +3,7 @@
 require_once("boot.php");
 
 
-function poller_run($argv, $argc){
+function poller_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)) {
index ba3babe70dd3c4538876dc691dba385edebfafc6..b703f930b6b80fcef848608dd0826636a5ad8f28 100644 (file)
@@ -2,7 +2,7 @@
 require_once("boot.php");
 require_once('include/queue_fn.php');
 
-function queue_run($argv, $argc){
+function queue_run(&$argv, &$argc){
        global $a, $db;
 
        if(is_null($a)){
diff --git a/include/uimport.php b/include/uimport.php
new file mode 100644 (file)
index 0000000..e43f331
--- /dev/null
@@ -0,0 +1,237 @@
+<?php\r
+/**\r
+ * import account file exported from mod/uexport\r
+ * args:\r
+ *  $a       App     Friendica App Class\r
+ *  $file   Array   array from $_FILES\r
+ */\r
+require_once("include/Photo.php");\r
+define("IMPORT_DEBUG", False);\r
+\r
+function last_insert_id(){\r
+    global $db; \r
+    if (IMPORT_DEBUG) return 1;\r
+    if($db->mysqli){\r
+        $thedb = $db->getdb();\r
+        return $thedb->insert_id;\r
+    } else {\r
+        return mysql_insert_id();\r
+    }\r
+ }\r
\r
+ function last_error(){\r
+    global $db; \r
+    return $db->error;\r
+ }\r
\r
+ function db_import_assoc($table, $arr){\r
+    if (IMPORT_DEBUG) return true;\r
+    if (isset($arr['id'])) unset($arr['id']);\r
+    $cols = implode("`,`", array_map('dbesc', array_keys($arr)));\r
+    $vals = implode("','", array_map('dbesc', array_values($arr)));\r
+    $query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')";\r
+    logger("uimport: $query",LOGGER_TRACE);\r
+    return q($query);\r
+ }\r
+\r
+function import_cleanup($newuid) {\r
+    q("DELETE FROM `user` WHERE uid = %d", $newuid);\r
+    q("DELETE FROM `contact` WHERE uid = %d", $newuid);\r
+    q("DELETE FROM `profile` WHERE uid = %d", $newuid);\r
+    q("DELETE FROM `photo` WHERE uid = %d", $newuid);\r
+    q("DELETE FROM `group` WHERE uid = %d", $newuid);\r
+    q("DELETE FROM `group_member` WHERE uid = %d", $newuid);\r
+    q("DELETE FROM `pconfig` WHERE uid = %d", $newuid);\r
+\r
+}\r
+\r
+function import_account(&$a, $file) {\r
+    logger("Start user import from ".$file['tmp_name']);\r
+    /*\r
+        STEPS\r
+        1. checks\r
+        2. replace old baseurl with new baseurl\r
+        3. import data (look at user id and contacts id)\r
+        4. archive non-dfrn contacts\r
+        5. send message to dfrn contacts\r
+     */\r
+\r
+    $account = json_decode(file_get_contents($file['tmp_name']), true);\r
+    if ($account===null) {\r
+        notice(t("Error decoding account file"));\r
+        return;\r
+    }\r
+       \r
+\r
+    if (!x($account, 'version')) { \r
+        notice(t("Error! No version data in file! This is not a Friendica account file?"));\r
+        return;\r
+    }\r
+   \r
+    if ($account['schema'] != DB_UPDATE_VERSION) {\r
+        notice(t("Error! I can't import this file: DB schema version is not compatible."));\r
+        return;\r
+    }\r
+   \r
+\r
+    $oldbaseurl  = $account['baseurl'];\r
+    $newbaseurl = $a->get_baseurl();\r
+    $olduid = $account['user']['uid'];\r
+  \r
+    unset($account['user']['uid']);\r
+    foreach($account['user'] as $k => &$v) {\r
+        $v = str_replace($oldbaseurl, $newbaseurl, $v);\r
+    }\r
+\r
+    \r
+    // import user\r
+    $r = db_import_assoc('user', $account['user']);\r
+    if ($r===false) {\r
+        //echo "<pre>"; var_dump($r, $query, mysql_error()); killme();\r
+        logger("uimport:insert user : ERROR : ".last_error(), LOGGER_NORMAL);\r
+        notice(t("User creation error"));\r
+        return;\r
+    }\r
+    $newuid = last_insert_id();\r
+    //~ $newuid = 1;\r
+    \r
+\r
+\r
+    foreach($account['profile'] as &$profile) {\r
+        foreach($profile as $k=>&$v) {\r
+            $v = str_replace($oldbaseurl, $newbaseurl, $v);\r
+            foreach(array("profile","avatar") as $k)\r
+                $v = str_replace($newbaseurl."/photo/".$k."/".$olduid.".jpg", $newbaseurl."/photo/".$k."/".$newuid.".jpg", $v);\r
+        }\r
+        $profile['uid'] = $newuid;\r
+        $r = db_import_assoc('profile', $profile);\r
+        if ($r===false) {\r
+            logger("uimport:insert profile ".$profile['profile-name']." : ERROR : ".last_error(), LOGGER_NORMAL);\r
+            info(t("User profile creation error"));\r
+            import_cleanup($newuid);\r
+            return;\r
+        }\r
+    }\r
+\r
+    $errorcount=0;\r
+    foreach($account['contact'] as &$contact) {\r
+        if ($contact['uid'] == $olduid && $contact['self'] == '1'){\r
+            foreach($contact as $k=>&$v) {\r
+                $v = str_replace($oldbaseurl, $newbaseurl, $v);\r
+                foreach(array("profile","avatar","micro") as $k)\r
+                    $v = str_replace($newbaseurl."/photo/".$k."/".$olduid.".jpg", $newbaseurl."/photo/".$k."/".$newuid.".jpg", $v);\r
+            }\r
+        }\r
+         if ($contact['uid'] == $olduid && $contact['self'] == '0') {\r
+            switch ($contact['network']){\r
+                case NETWORK_DFRN:\r
+                    //  send relocate message (below)\r
+                    break;\r
+                case NETWORK_ZOT:\r
+                    // TODO handle zot network\r
+                    break;\r
+                case NETWORK_MAIL2:\r
+                    // TODO ?\r
+                    break;\r
+                case NETWORK_FEED:\r
+                case NETWORK_MAIL:\r
+                    // Nothing to do\r
+                    break;\r
+                default:\r
+                    // archive other contacts\r
+                    $contact['archive'] = "1";\r
+            }\r
+        }\r
+        $contact['uid'] = $newuid;\r
+        $r = db_import_assoc('contact', $contact);\r
+        if ($r===false) {\r
+            logger("uimport:insert contact ".$contact['nick'].",".$contact['network']." : ERROR : ".last_error(), LOGGER_NORMAL);\r
+            $errorcount++;\r
+        } else {\r
+            $contact['newid'] = last_insert_id();\r
+        }\r
+    }\r
+    if ($errorcount>0) {\r
+        notice( sprintf(tt("%d contact not imported", "%d contacts not imported", $errorcount), $errorcount) );\r
+    }\r
+\r
+    foreach($account['group'] as &$group) {\r
+        $group['uid'] = $newuid;\r
+        $r = db_import_assoc('group', $group);\r
+        if ($r===false) {\r
+            logger("uimport:insert group ".$group['name']." : ERROR : ".last_error(), LOGGER_NORMAL);\r
+        } else {\r
+            $group['newid'] = last_insert_id();\r
+        }\r
+    }\r
+\r
+    foreach($account['group_member'] as &$group_member) {\r
+        $group_member['uid'] = $newuid;\r
+        \r
+        $import = 0;\r
+        foreach($account['group'] as $group) {\r
+            if ($group['id'] == $group_member['gid'] && isset($group['newid'])) {\r
+                $group_member['gid'] = $group['newid'];\r
+                $import++;\r
+                break;\r
+            }\r
+        }\r
+        foreach($account['contact'] as $contact) {\r
+            if ($contact['id'] == $group_member['contact-id'] && isset($contact['newid'])) {\r
+                $group_member['contact-id'] = $contact['newid'];\r
+                $import++;\r
+                break;\r
+            }\r
+        }\r
+        if ($import==2) {\r
+            $r = db_import_assoc('group_member', $group_member);\r
+            if ($r===false) {\r
+                logger("uimport:insert group member ".$group_member['id']." : ERROR : ".last_error(), LOGGER_NORMAL);\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+\r
+    \r
+    \r
+    foreach($account['photo'] as &$photo) {\r
+        $photo['uid'] = $newuid;\r
+        $photo['data'] = hex2bin($photo['data']);\r
+        \r
+        $p = new Photo($photo['data'], $photo['type']);\r
+        $r = $p->store(\r
+            $photo['uid'],\r
+            $photo['contact-id'], //0\r
+            $photo['resource-id'],\r
+            $photo['filename'],\r
+            $photo['album'],\r
+            $photo['scale'],\r
+            $photo['profile'], //1\r
+            $photo['allow_cid'],\r
+            $photo['allow_gid'],\r
+            $photo['deny_cid'],\r
+            $photo['deny_gid']\r
+        );\r
+        \r
+        if ($r===false) {\r
+            logger("uimport:insert photo ".$photo['resource-id'].",". $photo['scale']. " : ERROR : ".last_error(), LOGGER_NORMAL);\r
+        }\r
+    } \r
+    \r
+    foreach($account['pconfig'] as &$pconfig) {\r
+        $pconfig['uid'] = $newuid;\r
+        $r = db_import_assoc('pconfig', $pconfig);\r
+        if ($r===false) {\r
+            logger("uimport:insert pconfig ".$pconfig['id']. " : ERROR : ".last_error(), LOGGER_NORMAL);\r
+        }\r
+    } \r
+    \r
+    // send relocate messages\r
+    //proc_run('php', 'include/notifier.php', 'relocate' , $newuid);\r
+    \r
+    info(t("Done. You can now login with your username and password"));\r
+    goaway( $a->get_baseurl() ."/login");\r
+    \r
+    \r
+}\r
index 476212b7afdb17624ac4a2090836915322101160..44761be153855ab5f23b4557d0897091352bc9e7 100644 (file)
@@ -6,7 +6,7 @@ require_once('include/event.php');
 
 
 function dfrn_notify_post(&$a) {
-
+    logger(__function__, LOGGER_TRACE);
        $dfrn_id      = ((x($_POST,'dfrn_id'))      ? notags(trim($_POST['dfrn_id']))   : '');
        $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version']    : 2.0);
        $challenge    = ((x($_POST,'challenge'))    ? notags(trim($_POST['challenge'])) : '');
index a8fa100c8f9c7109552405e9ea1369f187f8ee63..208f97bcb66fa51fa3836238ce4535517aab5ec8 100644 (file)
@@ -42,6 +42,7 @@ function register_post(&$a) {
                $verified = 0;
                break;
        }
+    
 
        require_once('include/user.php');
 
@@ -234,7 +235,7 @@ function register_content(&$a) {
                        '$yes_selected' => ' checked="checked" ',
                        '$no_selected'  => '',
                        '$str_yes'      => t('Yes'),
-                       '$str_no'       => t('No')
+                       '$str_no'       => t('No'),
                ));
        }
 
@@ -275,7 +276,8 @@ function register_content(&$a) {
                '$email'     => $email,
                '$nickname'  => $nickname,
                '$license'   => $license,
-               '$sitename'  => $a->get_hostname()
+               '$sitename'  => $a->get_hostname(),
+      
        ));
        return $o;
 
index e1fb22855a6066fa8b99336b837f29ef9ebbb0ea..f216f551fa191f412bc66bdf408cb45933e2afea 100644 (file)
 <?php
 
-function uexport_init(&$a) {
 
+function uexport_init(&$a){
        if(! local_user())
                killme();
-
-       $user = array();
-       $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-               local_user()
+        
+       $tabs = array(
+               array(
+                       'label' => t('Account settings'),
+                       'url'   => $a->get_baseurl(true).'/settings',
+                       'selected'      => '',
+               ),      
+               array(
+                       'label' => t('Display settings'),
+                       'url'   => $a->get_baseurl(true).'/settings/display',
+                       'selected'      =>'',
+               ),      
+               
+               array(
+                       'label' => t('Connector settings'),
+                       'url'   => $a->get_baseurl(true).'/settings/connectors',
+                       'selected'      => '',
+               ),
+               array(
+                       'label' => t('Plugin settings'),
+                       'url'   => $a->get_baseurl(true).'/settings/addon',
+                       'selected'      => '',
+               ),
+               array(
+                       'label' => t('Connected apps'),
+                       'url' => $a->get_baseurl(true) . '/settings/oauth',
+                       'selected' => '',
+               ),
+               array(
+                       'label' => t('Export personal data'),
+                       'url' => $a->get_baseurl(true) . '/uexport',
+                       'selected' => 'active'
+               ),
+               array(
+                       'label' => t('Remove account'),
+                       'url' => $a->get_baseurl(true) . '/removeme',
+                       'selected' => ''
+               )
        );
+       
+       $tabtpl = get_markup_template("generic_links_widget.tpl");
+       $a->page['aside'] = replace_macros($tabtpl, array(
+               '$title' => t('Settings'),
+               '$class' => 'settings-widget',
+               '$items' => $tabs,
+       ));
+}
+
+function uexport_content(&$a){
+    
+    if ($a->argc > 1) {
+        header("Content-type: application/json");
+        header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
+        switch($a->argv[1]) {
+            case "backup": uexport_all($a); killme(); break;
+            case "account": uexport_account($a); killme(); break;
+            default:
+                killme();
+        }
+    }
+
+    /**
+      * options shown on "Export personal data" page
+      * list of array( 'link url', 'link text', 'help text' )
+      */
+    $options = array(
+            array('/uexport/account',t('Export account'),t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')),
+            array('/uexport/backup',t('Export all'),t('Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account (photos are not exported)')),
+    );
+    call_hooks('uexport_options', $options);
+        
+    $tpl = get_markup_template("uexport.tpl");
+    return replace_macros($tpl, array(
+        '$baseurl' => $a->get_baseurl(),
+        '$title' => t('Export personal data'),
+        '$options' => $options
+    ));
+    
+    
+}
+
+function _uexport_multirow($query) {
+       $result = array();
+       $r = q($query);
        if(count($r)) {
-               foreach($r as $rr)
+               foreach($r as $rr){
+            $p = array();
                        foreach($rr as $k => $v)
-                               $user[$k] = $v;
-
+                               $p[$k] = $v;
+            $result[] = $p;
+        }
        }
-       $contact = array();
-       $r = q("SELECT * FROM `contact` WHERE `uid` = %d ",
-               intval(local_user())
-       );
+    return $result;
+}
+
+function _uexport_row($query) {
+       $result = array();
+       $r = q($query);
        if(count($r)) {
                foreach($r as $rr)
                        foreach($rr as $k => $v)
-                               $contact[][$k] = $v;
+                               $result[$k] = $v;
 
        }
+    return $result;
+}
 
-       $profile = array();
-       $r = q("SELECT * FROM `profile` WHERE `uid` = %d ",
-               intval(local_user())
+
+function uexport_account($a){
+
+       $user = _uexport_row(
+        sprintf( "SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()) )
        );
-       if(count($r)) {
-               foreach($r as $rr)
-                       foreach($rr as $k => $v)
-                               $profile[][$k] = $v;
-       }
+    
+       $contact = _uexport_multirow(
+        sprintf( "SELECT * FROM `contact` WHERE `uid` = %d ",intval(local_user()) )
+       );
+
+
+       $profile =_uexport_multirow(
+        sprintf( "SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user()) )
+       );
+
+    $photo = _uexport_multirow(
+        sprintf( "SELECT * FROM photo WHERE uid = %d AND profile = 1", intval(local_user()) )
+    );
+    foreach ($photo as &$p) $p['data'] = bin2hex($p['data']);
 
-       $output = array('user' => $user, 'contact' => $contact, 'profile' => $profile );
+    $pconfig = _uexport_multirow(
+        sprintf( "SELECT * FROM pconfig WHERE uid = %d",intval(local_user()) )
+    );
 
-       header("Content-type: application/json");
+    $group = _uexport_multirow(
+        sprintf( "SELECT * FROM group WHERE uid = %d",intval(local_user()) )
+    );
+    
+    $group_member = _uexport_multirow(
+        sprintf( "SELECT * FROM group_member WHERE uid = %d",intval(local_user()) )
+    );
+
+       $output = array(
+        'version' => FRIENDICA_VERSION,
+        'schema' => DB_UPDATE_VERSION,
+        'baseurl' => $a->get_baseurl(),
+        'user' => $user, 
+        'contact' => $contact, 
+        'profile' => $profile, 
+        'photo' => $photo,
+        'pconfig' => $pconfig,
+        'group' => $group,
+        'group_member' => $group_member,
+    );
+
+    //echo "<pre>"; var_dump(json_encode($output)); killme();
        echo json_encode($output);
 
+}
+
+/**
+ * echoes account data and items as separated json, one per line
+ */
+function uexport_all(&$a) {
+    
+    uexport_account($a);
+
        $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
                intval(local_user())
        );
@@ -66,7 +194,4 @@ function uexport_init(&$a) {
                echo json_encode($output);
        }
 
-
-       killme();
-
 }
\ No newline at end of file
diff --git a/mod/uimport.php b/mod/uimport.php
new file mode 100644 (file)
index 0000000..f5f7366
--- /dev/null
@@ -0,0 +1,50 @@
+<?php\r
+/**\r
+ * View for user import\r
+ */\r
+\r
+require_once("include/uimport.php");\r
+\r
+function uimport_post(&$a) {\r
+       switch($a->config['register_policy']) {\r
+        case REGISTER_OPEN:\r
+            $blocked = 0;\r
+            $verified = 1;\r
+            break;\r
+\r
+        case REGISTER_APPROVE:\r
+            $blocked = 1;\r
+            $verified = 0;\r
+            break;\r
+\r
+        default:\r
+        case REGISTER_CLOSED:\r
+            if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {\r
+                notice( t('Permission denied.') . EOL );\r
+                return;\r
+            }\r
+            $blocked = 1;\r
+            $verified = 0;\r
+            break;\r
+       }\r
+    \r
+    if (x($_FILES,'accountfile')){\r
+        // TODO: pass $blocked / $verified, send email to admin on REGISTER_APPROVE\r
+        import_account($a, $_FILES['accountfile']);\r
+        return;\r
+    }\r
+}\r
+\r
+function uimport_content(&$a) {\r
+    $tpl = get_markup_template("uimport.tpl");\r
+    return replace_macros($tpl, array(\r
+        '$regbutt' => t('Import'),\r
+        '$import' => array(\r
+            'title' => t("Move account"),\r
+            'text' => t("You can move here an account from another Friendica server. <br>\r
+                            You need to export your account form the old server and upload it here. We will create here your old account with all your contacts. We will try also to inform you friends that you moved here.<br>\r
+                            <b>This feature is experimental. We can't move here contacts from ostatus network (statusnet/identi.ca) or from diaspora"),\r
+            'field' => array('accountfile', t('Account file'),'<input id="id_accountfile" name="accountfile" type="file">', t('To export your accont, go to "Settings->Export your porsonal data" and select "Export account"')),\r
+        ),  \r
+    ));\r
+}\r
index c703172af76acedc30ab5d87928af5d8282e9090..f29980d6ac3c0cf5b22e976c1db7f2fe9c9960d2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 
-function po2php_run($argv, $argc) {
+function po2php_run(&$argv, &$argc) {
 
        if ($argc!=2) {
                print "Usage: ".$argv[0]." <file.po>\n\n";
diff --git a/view/atom_relocate.tpl b/view/atom_relocate.tpl
new file mode 100644 (file)
index 0000000..f7db934
--- /dev/null
@@ -0,0 +1,17 @@
+
+<dfrn:relocate>
+
+       <dfrn:url>$url</dfrn:url>
+       <dfrn:name>$name</dfrn:name>
+       <dfrn:photo>$photo</dfrn:photo>
+       <dfrn:thumb>$thumb</dfrn:thumb>
+       <dfrn:micro>$micro</dfrn:micro>
+       <dfrn:request>$request</dfrn:request>
+       <dfrn:confirm>$confirm</dfrn:confirm>
+       <dfrn:notify>$notify</dfrn:notify>
+       <dfrn:poll>$poll</dfrn:poll>
+       <dfrn:sitepubkey>$sitepubkey</dfrn:sitepubkey>
+
+
+</dfrn:relocate>
+
index 8ce1d20acbae31def0f1364f1fbe3fd01ddc2561..7cf11881adfa476893a2e7fe8170fabb0ecf9d80 100644 (file)
@@ -55,6 +55,7 @@
                <input type="submit" name="submit" id="register-submit-button" value="$regbutt" />
        </div>
        <div id="register-submit-end" ></div>
+    
 </form>
 
 $license
diff --git a/view/uexport.tpl b/view/uexport.tpl
new file mode 100644 (file)
index 0000000..30d11d5
--- /dev/null
@@ -0,0 +1,9 @@
+<h3>$title</h3>\r
+\r
+\r
+{{ for $options as $o }}\r
+<dl>\r
+    <dt><a href="$baseurl/$o.0">$o.1</a></dt>\r
+    <dd>$o.2</dd>\r
+</dl>\r
+{{ endfor }}
\ No newline at end of file
diff --git a/view/uimport.tpl b/view/uimport.tpl
new file mode 100644 (file)
index 0000000..fb34add
--- /dev/null
@@ -0,0 +1,11 @@
+<form action="uimport" method="post" id="uimport-form" enctype="multipart/form-data">\r
+<h1>$import.title</h1>\r
+    <p>$import.text</p>\r
+     {{inc field_custom.tpl with $field=$import.field }}{{ endinc }}\r
+     \r
+     \r
+       <div id="register-submit-wrapper">\r
+               <input type="submit" name="submit" id="register-submit-button" value="$regbutt" />\r
+       </div>\r
+       <div id="register-submit-end" ></div>    \r
+</form>
\ No newline at end of file