aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/photos.php10
-rw-r--r--mod/connedit.php2
-rw-r--r--mod/frphotos.php79
-rw-r--r--util/frphotohelper.php72
-rw-r--r--version.inc2
-rw-r--r--view/tpl/frphotos.tpl13
6 files changed, 171 insertions, 7 deletions
diff --git a/include/photos.php b/include/photos.php
index 060a0671d..8bedfd15d 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -5,7 +5,7 @@ require_once('include/items.php');
require_once('include/photo/photo_driver.php');
-function photo_upload($channel, $observer, $args, $local = null) {
+function photo_upload($channel, $observer, $args) {
$ret = array('success' => false);
$channel_id = $channel['channel_id'];
@@ -62,17 +62,17 @@ function photo_upload($channel, $observer, $args, $local = null) {
$str_contact_deny = perms2str(((is_array($args['contact_deny'])) ? $args['contact_deny'] : explode(',',$args['contact_deny'])));
- if($local) {
+ if($args['data']) {
// allow an import from a binary string representing the image.
// This bypasses the upload step and max size limit checking
- $imagedata = $local;
+ $imagedata = $args['data'];
$filename = $args['filename'];
$filesize = strlen($imagedata);
// this is going to be deleted if it exists
$src = '/tmp/deletemenow';
- $filetype = $args['filetype'];
+ $type = $args['type'];
}
else {
$f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
@@ -158,7 +158,7 @@ function photo_upload($channel, $observer, $args, $local = null) {
$smallest = 0;
- $photo_hash = photo_new_resource();
+ $photo_hash = (($args['resource_id']) ? $args['resource_id'] : photo_new_resource());
$visitor = '';
if($channel['channel_hash'] !== $observer['xchan_hash'])
diff --git a/mod/connedit.php b/mod/connedit.php
index b7535550d..b2de42343 100644
--- a/mod/connedit.php
+++ b/mod/connedit.php
@@ -121,7 +121,7 @@ function connedit_post(&$a) {
if($orig_record[0]['abook_profile'] != $profile_id) {
//Update profile photo permissions
- logger('As a new profile was assigned updateing profile photos');
+ logger('As a new profile was assigned updating profile photos');
require_once('mod/profile_photo.php');
profile_photo_set_profile_perms($profile_id);
diff --git a/mod/frphotos.php b/mod/frphotos.php
new file mode 100644
index 000000000..943651aa2
--- /dev/null
+++ b/mod/frphotos.php
@@ -0,0 +1,79 @@
+<?php
+
+
+
+function frphotos_init(&$a) {
+
+ if(! local_user())
+ return;
+
+ if(intval(get_pconfig(local_user(),'frphotos','complete')))
+ return;
+
+ $channel = $a->get_channel();
+
+ $fr_server = $_REQUEST['fr_server'];
+ $fr_username = $_REQUEST['fr_username'];
+ $fr_password = $_REQUEST['fr_password'];
+
+ $cookies = 'store/[data]/frphoto_cookie_' . $channel['channel_address'];
+
+ if($fr_server && $fr_username && $fr_password) {
+
+ $ch = curl_init($fr_server . '/api/friendica/photos/list');
+
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookies);
+ curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookies);
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+ curl_setopt($ch, CURLOPT_USERPWD, $fr_username . ':' . $fr_password);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'RedMatrix');
+
+ $output = curl_exec($ch);
+ curl_close($ch);
+
+ $j = json_decode($output,true);
+
+// echo print_r($j,true);
+
+ $total = 0;
+ if(count($j)) {
+ foreach($j as $jj) {
+ $total ++;
+ proc_run('php','util/frphotohelper.php',$jj, $channel['channel_address'], urlencode($fr_server));
+ sleep(3);
+ }
+ }
+ if($total) {
+ set_pconfig(local_user(),'frphotos','complete','1');
+ }
+ @unlink($cookies);
+ goaway(z_root() . '/photos/' . $channel['channel_address']);
+ }
+}
+
+
+function frphotos_content(&$a) {
+
+ if(! local_user()) {
+ notice( t('Permission denied') . EOL);
+ return;
+ }
+
+ if(intval(get_pconfig(local_user(),'frphotos','complete'))) {
+ info('Friendica photos have already been imported into this channel.');
+ return;
+ }
+
+ $o = replace_macros(get_markup_template('frphotos.tpl'),array(
+ '$header' => t('Friendica Photo Album Import'),
+ '$desc' => t('This will import all your Friendica photo albums to this Red channel.'),
+ '$fr_server' => array('fr_server', t('Friendica Server base URL'),'',''),
+ '$fr_username' => array('fr_username', t('Friendica Login Username'),'',''),
+ '$fr_password' => array('fr_password', t('Friendica Login Password'),'',''),
+ '$submit' => t('Submit'),
+ ));
+ return $o;
+}
diff --git a/util/frphotohelper.php b/util/frphotohelper.php
new file mode 100644
index 000000000..aacfac3e5
--- /dev/null
+++ b/util/frphotohelper.php
@@ -0,0 +1,72 @@
+<?php
+
+require_once('include/cli_startup.php');
+
+cli_startup();
+
+$a = get_app();
+
+
+$photo_id = $argv[1];
+$channel_address = $argv[2];
+$fr_server = urldecode($argv[3]);
+require_once('include/photos.php');
+
+$cookies = 'store/[data]/frphoto_cookie_' . $channel_address;
+
+ $c = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_address = '%s' limit 1",
+ dbesc($channel_address)
+ );
+ if(! $c) {
+ logger('frphotohelper: channel not found');
+ killme();
+ }
+ $channel = $c[0];
+
+
+ $ch = curl_init($fr_server . '/api/friendica/photo?f=&photo_id=' . $photo_id);
+
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookies);
+ curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookies);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'RedMatrix');
+
+ $output = curl_exec($ch);
+ curl_close($ch);
+
+ $j = json_decode($output,true);
+
+// logger('frphotohelper: ' . print_r($j,true));
+
+ $args = array();
+ $args['data'] = base64_decode($j['data']);
+ $args['filename'] = $j['filename'];
+ $args['resource_id'] = $j['resource-id'];
+ $args['scale'] = $j['scale'];
+ $args['album'] = $j['album'];
+ $args['not_visible'] = 1;
+
+ if($j['allow_cid'] || $j['allow_gid'] || $j['deny_cid'] || $j['deny_gid'])
+ $args['contact_allow'] = $channel['channel_hash'];
+
+ $args['type'] = $j['type'];
+
+
+
+ $r = q("select * from photo where resource_id = '%s' and uid = %d limit 1",
+ dbesc($args['resource_id']),
+ intval($channel['channel_id'])
+ );
+ if($r) {
+ logger('frphotohelper: duplicate photo ignored');
+ killme();
+ }
+
+
+ $ret = photo_upload($channel,$channel,$args);
+ logger('photo_import: ' . print_r($ret,true));
+
+ killme();
+
diff --git a/version.inc b/version.inc
index 11d8e067e..5552ee1d9 100644
--- a/version.inc
+++ b/version.inc
@@ -1 +1 @@
-2014-08-11.764
+2014-08-12.765
diff --git a/view/tpl/frphotos.tpl b/view/tpl/frphotos.tpl
new file mode 100644
index 000000000..b8e978825
--- /dev/null
+++ b/view/tpl/frphotos.tpl
@@ -0,0 +1,13 @@
+<h3>{{$header}}</h3>
+
+<p class="descriptive-text">{{$desc}}</p>
+
+<form action="frphotos" method="post" autocomplete="off" >
+
+{{include file="field_input.tpl" field=$fr_server}}
+{{include file="field_input.tpl" field=$fr_username}}
+{{include file="field_password.tpl" field=$fr_password}}
+
+<input type="submit" name="submit" value="{{$submit}}" />
+</form>
+