]> git.mxchange.org Git - friendica.git/commitdiff
There is now a new possibility to update contact data.
authorMichael Vogel <icarus@dabo.de>
Sat, 11 Apr 2015 21:51:47 +0000 (23:51 +0200)
committerMichael Vogel <icarus@dabo.de>
Sat, 11 Apr 2015 21:51:47 +0000 (23:51 +0200)
mod/contacts.php
mod/crepair.php
view/templates/crepair.tpl

index 95b1944dc871f697f159409f98b77bd782f8bc49..05a84279b01270322583c36999ff71ed16060efa 100644 (file)
@@ -3,7 +3,9 @@
 require_once('include/Contact.php');
 require_once('include/socgraph.php');
 require_once('include/contact_selectors.php');
+require_once('include/Scrape.php');
 require_once('mod/proxy.php');
+require_once('include/Photo.php');
 
 function contacts_init(&$a) {
        if(! local_user())
@@ -33,7 +35,7 @@ function contacts_init(&$a) {
                        $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
                                '$name' => $a->data['contact']['name'],
                                '$photo' => $a->data['contact']['photo'],
-                               '$url' => ($a->data['contact']['network'] == 'dfrn') ? $a->get_baseurl()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url']
+                               '$url' => ($a->data['contact']['network'] == 'dfrn') ? $a->get_baseurl()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url']
                        ));
                        $follow_widget = '';
        }
@@ -205,8 +207,64 @@ function contacts_post(&$a) {
 /*contact actions*/
 function _contact_update($contact_id) {
        // pull feed and consume it, which should subscribe to the hub.
-       proc_run('php',"include/poller.php","$contact_id"); 
+       proc_run('php',"include/poller.php","$contact_id");
 }
+
+function _contact_update_profile($contact_id) {
+       $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
+       if (!$r)
+               return;
+
+       $data = probe_url($r[0]["url"]);
+
+       $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
+                               "poco", "network", "alias", "pubkey");
+       $update = array();
+
+       foreach($updatefields AS $field)
+               if (isset($data[$field]) AND ($data[$field] != ""))
+                       $update[$field] = $data[$field];
+
+       $query = "";
+
+       if (isset($data["priority"]) AND ($data["priority"] != 0))
+               $query = "`priority` = ".intval($data["priority"]);
+
+       foreach($update AS $key => $value) {
+               if ($query != "")
+                       $query .= ", ";
+
+               $query .= "`".$key."` = '".dbesc($value)."'";
+       }
+
+       if ($query == "")
+               return;
+
+       $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
+               intval($contact_id),
+               intval(local_user())
+       );
+
+       $photos = import_profile_photo($data['photo'], local_user(), $contact_id);
+
+       $r = q("UPDATE `contact` SET `photo` = '%s',
+                       `thumb` = '%s',
+                       `micro` = '%s',
+                       `name-date` = '%s',
+                       `uri-date` = '%s',
+                       `avatar-date` = '%s'
+                       WHERE `id` = %d",
+                       dbesc($photos[0]),
+                       dbesc($photos[1]),
+                       dbesc($photos[2]),
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       intval($contact_id)
+               );
+
+}
+
 function _contact_block($contact_id, $orig_record) {
        $blocked = (($orig_record['blocked']) ? 0 : 1);
        $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
@@ -284,6 +342,12 @@ function contacts_content(&$a) {
                        // NOTREACHED
                }
 
+               if($cmd === 'updateprofile') {
+                       _contact_update_profile($contact_id);
+                       goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
+                       // NOTREACHED
+               }
+
                if($cmd === 'block') {
                        $r = _contact_block($contact_id, $orig_record[0]);
                        if($r) {
@@ -734,7 +798,7 @@ function contacts_content(&$a) {
                ),
                '$paginate' => paginate($a),
 
-       )); 
-       
+       ));
+
        return $o;
 }
index 400817d6f7e42588e4e18c4a8805714f2d40ffef..670143d35f751b8741f49c59b5edce739f20914f 100644 (file)
@@ -160,8 +160,12 @@ function crepair_content(&$a) {
        else
                $remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
 
+       $update_profile = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DSPR, NETWORK_OSTATUS));
+
        $tpl = get_markup_template('crepair.tpl');
        $o .= replace_macros($tpl, array(
+               '$update_profile' => update_profile,
+               '$udprofilenow' => t('Update profile now'),
                '$label_name' => t('Name'),
                '$label_nick' => t('Account Nickname'),
                '$label_attag' => t('@Tagname - overrides Name/Nickname'),
index a94f1f2d3c2241f6e207f4c3b87e068059d1a72c..5b3a6281ebf8af0dbdaf15c25067d05df356e434 100644 (file)
@@ -2,6 +2,12 @@
 
 <h4>{{$contact_name}}</h4>
 
+<div id="contact-update-profile-wrapper">
+{{if $update_profile}}
+       <span id="contact-update-profile-now" class="button"><a href="contacts/{{$contact_id}}/updateprofile" >{{$udprofilenow}}</a></span>
+{{/if}}
+</div>
+
 <label id="crepair-name-label" class="crepair-label" for="crepair-name">{{$label_name}}</label>
 <input type="text" id="crepair-name" class="crepair-input" name="name" value="{{$contact_name|escape:'html'}}" />
 <div class="clear"></div>