diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..e1850648d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,24 @@
+favicon.*
+.htconfig.php
+\#*
+*.log
+*.out
+*.version*
+favicon.*
+*~
+
+#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
+
+/nbproject/private/
+
+#ignore smarty cache
+/view/smarty3/compiled/
\ No newline at end of file
diff --git a/INSTALL.txt b/INSTALL.txt
new file mode 100644
index 000000000..ec9372e84
--- /dev/null
+++ b/INSTALL.txt
@@ -0,0 +1,18 @@
+*********************
+* Install Using Git *
+*********************
+
+To install all addons using git, cd into your top level Friendica directory and
+
+git clone https://github.com/friendica/friendica-addons.git addon
+
+This will clone the entire repository in a directory called addon. They can now be activated in the plugins section of your admin panel.
+
+********************
+* Install Manually *
+********************
+
+1. Download the archive (AddonName.tgz) containing the addon you want to install.
+2. Unzip the contents of the archive to your harddrive.
+3. Upload the extracted directory and all it's contents to /path/to/friendica/addon. You will need to create the addon directory if this is the first addon you have installed.
+4. Activate the addon in the plugins section of your admin panel.
diff --git a/altpager.tgz b/altpager.tgz
new file mode 100644
index 000000000..fbfd55949
Binary files /dev/null and b/altpager.tgz differ
diff --git a/altpager/altpager.php b/altpager/altpager.php
index 65f9c0d83..c6f537bd4 100755
--- a/altpager/altpager.php
+++ b/altpager/altpager.php
@@ -61,6 +61,10 @@ function altpager_settings(&$a,&$s) {
if(! local_user())
return;
+ $global = get_config("alt_pager", "global");
+ if($global == 1)
+ return;
+
/* Add our stylesheet to the page so we can make our settings look nice */
$a->page['htmlhead'] .= '' . "\r\n";
@@ -87,3 +91,19 @@ function altpager_settings(&$a,&$s) {
$s .= '
';
}
+
+function altpager_plugin_admin(&$a, &$o){
+ $t = get_markup_template( "admin.tpl", "addon/altpager/" );
+ $o = replace_macros($t, array(
+ '$submit' => t('Submit'),
+ '$global' => array('altpagerchoice', t('Global'), 1, t('Force global use of the alternate pager'), get_config('alt_pager', 'global') == 1),
+ '$individual' => array('altpagerchoice', t('Individual'), 2, t('Each user chooses whether to use the alternate pager'), get_config('alt_pager', 'global') == 0)
+ ));
+}
+
+function altpager_plugin_admin_post(&$a){
+ $choice = ((x($_POST,'altpagerchoice')) ? notags(trim($_POST['altpagerchoice'])) : '');
+ set_config('alt_pager','global',($choice == 1 ? 1 : 0));
+ info( t('Settings updated.'). EOL );
+}
+
diff --git a/altpager/view/admin.tpl b/altpager/view/admin.tpl
new file mode 100644
index 000000000..605588084
--- /dev/null
+++ b/altpager/view/admin.tpl
@@ -0,0 +1,3 @@
+{{ inc field_radio.tpl with $field=$global }}{{ endinc }}
+{{ inc field_radio.tpl with $field=$individual }}{{ endinc }}
+
diff --git a/altpager/view/admin.tpl.old b/altpager/view/admin.tpl.old
new file mode 100755
index 000000000..605588084
--- /dev/null
+++ b/altpager/view/admin.tpl.old
@@ -0,0 +1,3 @@
+{{ inc field_radio.tpl with $field=$global }}{{ endinc }}
+{{ inc field_radio.tpl with $field=$individual }}{{ endinc }}
+
diff --git a/altpager/view/smarty3/admin.tpl b/altpager/view/smarty3/admin.tpl
new file mode 100644
index 000000000..e67afd737
--- /dev/null
+++ b/altpager/view/smarty3/admin.tpl
@@ -0,0 +1,3 @@
+{{include file="field_radio.tpl" field=$global}}
+{{include file="field_radio.tpl" field=$individual}}
+
diff --git a/blackout.tgz b/blackout.tgz
index 4b5a5d312..6d081dc4a 100644
Binary files a/blackout.tgz and b/blackout.tgz differ
diff --git a/blackout/blackout.php b/blackout/blackout.php
index 2cb7c041d..834956114 100644
--- a/blackout/blackout.php
+++ b/blackout/blackout.php
@@ -93,8 +93,9 @@ function blackout_plugin_admin(&$a, &$o) {
if (! is_string($myend)) { $myend = "YYYY-MM-DD:hhmm"; }
$myurl = get_config('blackout','url');
if (! is_string($myurl)) { $myurl = "http://www.example.com"; }
- $t = file_get_contents( dirname(__file__)."/admin.tpl" );
- $o = replace_macros($t, array(
+ $t = get_markup_template( "admin.tpl", "addon/blackout/" );
+
+ $o = replace_macros($t, array(
'$submit' => t('Submit'),
'$rurl' => array("rurl", "Redirect URL", $myurl, "all your visitors from the web will be redirected to this URL"),
'$startdate' => array("startdate", "Begin of the Blackout (YYYY-MM-DD hh:mm)", $mystart, "format is YYYY year, MM month, DD day, hh hour and mm minute"),
diff --git a/blackout/admin.tpl b/blackout/view/admin.tpl
similarity index 100%
rename from blackout/admin.tpl
rename to blackout/view/admin.tpl
diff --git a/blackout/view/smarty3/admin.tpl b/blackout/view/smarty3/admin.tpl
new file mode 100644
index 000000000..11a4d9140
--- /dev/null
+++ b/blackout/view/smarty3/admin.tpl
@@ -0,0 +1,11 @@
+{{include file="field_input.tpl" field=$startdate}}
+{{include file="field_input.tpl" field=$enddate}}
+{{include file="field_input.tpl" field=$rurl}}
+
+
Note: The redirect will be active from the moment you
+press the submit button. Users currently logged in will not be
+thrown out but can't login again after logging out should the blackout is
+still in place.
+
+
diff --git a/buglink.tgz b/buglink.tgz
index 171a17e9c..f66558f24 100755
Binary files a/buglink.tgz and b/buglink.tgz differ
diff --git a/buglink/buglink.php b/buglink/buglink.php
index faa97a0cd..9cd35ccdf 100755
--- a/buglink/buglink.php
+++ b/buglink/buglink.php
@@ -12,4 +12,4 @@ function buglink_install() { register_hook('page_end', 'addon/buglink/buglink.ph
function buglink_uninstall() { unregister_hook('page_end', 'addon/buglink/buglink.php', 'buglink_active'); }
-function buglink_active(&$a,&$b) { $b .= '
'; }
+function buglink_active(&$a,&$b) { $b .= '
'; }
diff --git a/communityhome.tgz b/communityhome.tgz
index 129081b61..ab251425b 100755
Binary files a/communityhome.tgz and b/communityhome.tgz differ
diff --git a/communityhome/README.md b/communityhome/README.md
index 3cf610ec1..21f2a9465 100755
--- a/communityhome/README.md
+++ b/communityhome/README.md
@@ -9,3 +9,26 @@ choosed to be in site directory), last ten public photos and last ten
In main content is shown the community stream. This plugin doesn't
honour your community page visibility site setting: the community
stream is shown also if you have choose to not show the community page.
+
+If 'home.html' is found in your friendica root, its content is inserted
+before community stream
+
+Each elements can be show or not. At the moment, there is no admin page
+for settings, so this settings must be added to yout .htconfig.php
+
+
+ $a->config['communityhome']['showcommunitystream'] = true;
+ $a->config['communityhome']['showlastlike'] = true;
+ $a->config['communityhome']['showlastphotos'] = true;
+ $a->config['communityhome']['showactiveusers'] = true;
+ $a->config['communityhome']['showlastusers'] = true;
+
+If you don't want to show something, set it to false.
+
+Note:
+-----
+
+- Default is "false". With no settings in .htconfig.php, nothing is
+shown, except login form and content of 'home.html'
+
+- Active users query can be heavy for db, and on some system don't work
diff --git a/communityhome/communityhome.css b/communityhome/communityhome.css
index 2efb6ebd5..45a655374 100755
--- a/communityhome/communityhome.css
+++ b/communityhome/communityhome.css
@@ -39,4 +39,5 @@ aside .directory-photo-img { max-width: 48px; max-height: 48px; }
aside #likes { margin: 0px; padding: 0px; list-style: none; }
-aside #login-extra-links { overflow: auto; width: 100%; padding-top:120px;}
+aside #div_id_remember { overflow: auto; width: 100%; padding-top:120px;}
+#login_openid input { width: 160px; }
diff --git a/communityhome/communityhome.php b/communityhome/communityhome.php
index 2b14fd338..ba2af6de6 100755
--- a/communityhome/communityhome.php
+++ b/communityhome/communityhome.php
@@ -2,7 +2,7 @@
/**
* Name: Community home
* Description: Show last community activity in homepage
- * Version: 1.0
+ * Version: 2.0
* Author: Fabio Comuni
*/
@@ -35,151 +35,166 @@ function communityhome_home(&$a, &$o){
$aside['$login_form'] = login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
// last 12 users
- $aside['$lastusers_title'] = t('Latest users');
- $aside['$lastusers_items'] = array();
- $sql_extra = "";
- $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
- $order = " ORDER BY `register_date` DESC ";
+ if (get_config('communityhome','showlastusers')===true){
+ $aside['$lastusers_title'] = t('Latest users');
+ $aside['$lastusers_items'] = array();
+ $sql_extra = "";
+ $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
+ $order = " ORDER BY `register_date` DESC ";
- $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
- FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
- WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
- 0,
- 12
- );
- $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
- if(count($r)) {
- $photo = 'thumb';
- foreach($r as $rr) {
- $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
- $entry = replace_macros($tpl,array(
- '$id' => $rr['id'],
- '$profile-link' => $profile_link,
- '$photo' => $a->get_cached_avatar_image($rr[$photo]),
- '$alt-text' => $rr['name'],
- ));
- $aside['$lastusers_items'][] = $entry;
+ $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
+ FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
+ WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
+ 0,
+ 12
+ );
+ # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
+ $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
+ if(count($r)) {
+ $photo = 'thumb';
+ foreach($r as $rr) {
+ $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
+ $entry = replace_macros($tpl,array(
+ '$id' => $rr['id'],
+ '$profile_link' => $profile_link,
+ '$photo' => $a->get_cached_avatar_image($rr[$photo]),
+ '$alt_text' => $rr['name'],
+ ));
+ $aside['$lastusers_items'][] = $entry;
+ }
}
}
-
// 12 most active users (by posts and contacts)
// this query don't work on some mysql versions
- $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
- (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
- (SELECT COUNT(`id`) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`,
- (
- SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
- UNION ALL
- SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
- ) AS `uni`, `user`, `profile`
- WHERE `uni`.`uid`=`user`.`uid`
- AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
- GROUP BY `uid`
- ORDER BY `items` DESC,`contacts` DESC
- LIMIT 0,10");
- if($r && count($r)) {
- $aside['$activeusers_title'] = t('Most active users');
- $aside['$activeusers_items'] = array();
-
- $photo = 'thumb';
- foreach($r as $rr) {
- $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
- $entry = replace_macros($tpl,array(
- '$id' => $rr['id'],
- '$profile-link' => $profile_link,
- '$photo' => $rr[$photo],
- '$alt-text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
- ));
- $aside['$activeusers_items'][] = $entry;
+ if (get_config('communityhome','showactiveusers')===true){
+ $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
+ (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
+ (SELECT COUNT(`id`) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`,
+ (
+ SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
+ UNION ALL
+ SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
+ ) AS `uni`, `user`, `profile`
+ WHERE `uni`.`uid`=`user`.`uid`
+ AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
+ GROUP BY `uid`
+ ORDER BY `items` DESC,`contacts` DESC
+ LIMIT 0,10");
+ if($r && count($r)) {
+ $aside['$activeusers_title'] = t('Most active users');
+ $aside['$activeusers_items'] = array();
+
+ $photo = 'thumb';
+ foreach($r as $rr) {
+ $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
+ $entry = replace_macros($tpl,array(
+ '$id' => $rr['id'],
+ '$profile_link' => $profile_link,
+ '$photo' => $rr[$photo],
+ '$alt_text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
+ ));
+ $aside['$activeusers_items'][] = $entry;
+ }
}
}
-
// last 12 photos
- $aside['$photos_title'] = t('Latest photos');
- $aside['$photos_items'] = array();
- $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
- (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
- WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
- AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
- INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
- `user`
- WHERE `user`.`uid` = `photo`.`uid`
- AND `user`.`blockwall`=0
- ORDER BY `photo`.`edited` DESC
- LIMIT 0, 12",
- dbesc(t('Contact Photos')),
- dbesc(t('Profile Photos'))
- );
+ if (get_config('communityhome','showlastphotos')===true){
+ $aside['$photos_title'] = t('Latest photos');
+ $aside['$photos_items'] = array();
+ $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
+ (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
+ WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
+ AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
+ INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
+ `user`
+ WHERE `user`.`uid` = `photo`.`uid`
+ AND `user`.`blockwall`=0
+ AND `user`.`hidewall` = 0
+ ORDER BY `photo`.`edited` DESC
+ LIMIT 0, 12",
+ dbesc(t('Contact Photos')),
+ dbesc(t('Profile Photos'))
+ );
-
- if(count($r)) {
- $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
- foreach($r as $rr) {
- $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
- $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
-
- $entry = replace_macros($tpl,array(
- '$id' => $rr['id'],
- '$profile-link' => $photo_page,
- '$photo' => $photo_url,
- '$alt-text' => $rr['username']." : ".$rr['desc'],
- ));
+
+ if(count($r)) {
+ # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
+ $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
+ foreach($r as $rr) {
+ $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
+ $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
+
+ $entry = replace_macros($tpl,array(
+ '$id' => $rr['id'],
+ '$profile_link' => $photo_page,
+ '$photo' => $photo_url,
+ '$alt_text' => $rr['username']." : ".$rr['desc'],
+ ));
- $aside['$photos_items'][] = $entry;
+ $aside['$photos_items'][] = $entry;
+ }
}
}
// last 10 liked items
- $aside['$like_title'] = t('Latest likes');
- $aside['$like_items'] = array();
- $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
- (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
- FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
- INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
- WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
- GROUP BY `uri`
- ORDER BY `T1`.`created` DESC
- LIMIT 0,10",
- $a->get_baseurl(),$a->get_baseurl()
- );
+ if (get_config('communityhome','showlastlike')===true){
+ $aside['$like_title'] = t('Latest likes');
+ $aside['$like_items'] = array();
+ $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
+ (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
+ FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
+ INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
+ WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
+ GROUP BY `uri`
+ ORDER BY `T1`.`created` DESC
+ LIMIT 0,10",
+ $a->get_baseurl(),$a->get_baseurl()
+ );
- foreach ($r as $rr) {
- $author = '' . $rr['liker'] . '';
- $objauthor = '' . $rr['author-name'] . '';
-
- //var_dump($rr['verb'],$rr['object-type']); killme();
- switch($rr['verb']){
- case 'http://activitystrea.ms/schema/1.0/post':
- switch ($rr['object-type']){
- case 'http://activitystrea.ms/schema/1.0/event':
- $post_type = t('event');
- break;
- default:
+ foreach ($r as $rr) {
+ $author = '' . $rr['liker'] . '';
+ $objauthor = '' . $rr['author-name'] . '';
+
+ //var_dump($rr['verb'],$rr['object-type']); killme();
+ switch($rr['verb']){
+ case 'http://activitystrea.ms/schema/1.0/post':
+ switch ($rr['object-type']){
+ case 'http://activitystrea.ms/schema/1.0/event':
+ $post_type = t('event');
+ break;
+ default:
+ $post_type = t('status');
+ }
+ break;
+ default:
+ if ($rr['resource-id']){
+ $post_type = t('photo');
+ $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
+ $rr['plink'] = $m[1];
+ } else {
$post_type = t('status');
- }
- break;
- default:
- if ($rr['resource-id']){
- $post_type = t('photo');
- $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
- $rr['plink'] = $m[1];
- } else {
- $post_type = t('status');
- }
- }
- $plink = '' . $post_type . '';
+ }
+ }
+ $plink = '' . $post_type . '';
- $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
-
+ $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
+
+ }
}
- $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
+# $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
+ $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
$a->page['aside'] = replace_macros($tpl, $aside);
$o = '
';
+
+ $appid = get_config('facebook', 'appid' );
+ $appsecret = get_config('facebook', 'appsecret' );
+
+ $ret1 = q("SELECT `v` FROM `config` WHERE `cat` = 'facebook' AND `k` = 'appid' LIMIT 1");
+ $ret2 = q("SELECT `v` FROM `config` WHERE `cat` = 'facebook' AND `k` = 'appsecret' LIMIT 1");
+ if ((count($ret1) > 0 && $ret1[0]['v'] != $appid) || (count($ret2) > 0 && $ret2[0]['v'] != $appsecret)) $o .= t('Error: it appears that you have specified the App-ID and -Secret in your .htconfig.php file. As long as they are specified there, they cannot be set using this form.
+Simply locate the matching tiles and find a way to clear them from the board as quickly as possible.
+A timer at the top of the screen keeps track of how you are doing.
+
+EOT;
+
+return $o;
+}
diff --git a/mahjongg/mahjongg.swf b/mahjongg/mahjongg.swf
new file mode 100755
index 000000000..79f8c9e3a
Binary files /dev/null and b/mahjongg/mahjongg.swf differ
diff --git a/mathjax.tgz b/mathjax.tgz
index bb591e1d3..a340aee47 100644
Binary files a/mathjax.tgz and b/mathjax.tgz differ
diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php
index 7105772ba..e57d69bf5 100644
--- a/mathjax/mathjax.php
+++ b/mathjax/mathjax.php
@@ -66,11 +66,12 @@ function mathjax_plugin_admin_post (&$a) {
info( t('Settings updated.'). EOL);
}
function mathjax_plugin_admin (&$a, &$o) {
- $t = file_get_contents( dirname(__file__)."/admin.tpl");
- if (get_config('mathjax','baseurl','') == '') {
- set_config('mathjax','baseurl','http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
- }
- $o = replace_macros( $t, array(
+ $t = get_markup_template( "admin.tpl", "addon/mathjax/" );
+ if (get_config('mathjax','baseurl','') == '') {
+ set_config('mathjax','baseurl','http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
+ }
+
+ $o = replace_macros( $t, array(
'$baseurl' => array('baseurl', t('MathJax Base URL'), get_config('mathjax','baseurl' ), t('The URL for the javascript file that should be included to use MathJax. Can be either the MathJax CDN or another installation of MathJax.')),
- ));
+ ));
}
diff --git a/mathjax/admin.tpl b/mathjax/view/admin.tpl
similarity index 100%
rename from mathjax/admin.tpl
rename to mathjax/view/admin.tpl
diff --git a/mathjax/view/smarty3/admin.tpl b/mathjax/view/smarty3/admin.tpl
new file mode 100644
index 000000000..f6ec03e0d
--- /dev/null
+++ b/mathjax/view/smarty3/admin.tpl
@@ -0,0 +1,2 @@
+{{include file="field_input.tpl" field=$baseurl}}
+
diff --git a/morepokes.tgz b/morepokes.tgz
new file mode 100644
index 000000000..7999b719f
Binary files /dev/null and b/morepokes.tgz differ
diff --git a/morepokes/morepokes.php b/morepokes/morepokes.php
index bdbd7dcf3..717643ec1 100644
--- a/morepokes/morepokes.php
+++ b/morepokes/morepokes.php
@@ -19,9 +19,8 @@ function morepokes_poke_verbs($a,&$b) {
$b['bitchslap'] = array('bitchslapped', t('bitchslap'), t('bitchslapped'));
$b['shag'] = array('shag', t('shag'), t('shagged'));
$b['somethingobscenelybiological'] = array('something obscenely biological', t('do something obscenely biological to'), t('did something obscenely biological to'));
- $b['newpokefeature'] = array('pointed out the new poke feature to', t('point out the new poke feature to'), t('pointed out the new poke feature to'));
+ $b['newpokefeature'] = array('pointed out the poke feature to', t('point out the poke feature to'), t('pointed out the poke feature to'));
$b['declareundyinglove'] = array('declared undying love for', t('declare undying love for'), t('declared undying love for'));
- $b['setfireto'] = array('set fire to', t('set fire to'), t('set fire to'));
$b['patent'] = array('patented', t('patent'), t('patented'));
$b['strokebeard'] = array('stroked their beard at', t('stroke beard'), t('stroked their beard at'));
$b['bemoan'] = array('bemoaned the declining standards of modern secondary and tertiary education to', t('bemoan the declining standards of modern secondary and tertiary education to'), t('bemoans the declining standards of modern secondary and tertiary education to'));
@@ -35,4 +34,4 @@ function morepokes_poke_verbs($a,&$b) {
$b['giggleandfawn'] = array('giggled and fawned at', t('giggle and fawn at'), t('giggled and fawned at'));
$b['doubt'] = array('doubted', t('doubt'), t('doubted'));
$b['glare'] = array('glared at', t('glare'), t('glared at'));
-;}
\ No newline at end of file
+;}
diff --git a/nsfw.tgz b/nsfw.tgz
index 73870dc3f..a35ec568c 100755
Binary files a/nsfw.tgz and b/nsfw.tgz differ
diff --git a/nsfw/nsfw.php b/nsfw/nsfw.php
index 60ab45813..96e1a9bf8 100755
--- a/nsfw/nsfw.php
+++ b/nsfw/nsfw.php
@@ -24,6 +24,37 @@ function nsfw_uninstall() {
}
+// This function isn't perfect and isn't trying to preserve the html structure - it's just a
+// quick and dirty filter to pull out embedded photo blobs because 'nsfw' seems to come up
+// inside them quite often. We don't need anything fancy, just pull out the data blob so we can
+// check against the rest of the body.
+
+function nsfw_extract_photos($body) {
+
+ $new_body = '';
+
+ $img_start = strpos($body,'src="data:');
+ $img_end = (($img_start !== false) ? strpos(substr($body,$img_start),'>') : false);
+
+ $cnt = 0;
+
+ while($img_end !== false) {
+ $img_end += $img_start;
+ $new_body = $new_body . substr($body,0,$img_start);
+
+ $cnt ++;
+ $body = substr($body,0,$img_end);
+
+ $img_start = strpos($body,'src="data:');
+ $img_end = (($img_start !== false) ? strpos(substr($body,$img_start),'>') : false);
+
+ }
+
+ if(! $cnt)
+ return $body;
+
+ return $new_body;
+}
@@ -77,6 +108,7 @@ function nsfw_addon_settings_post(&$a,&$b) {
function nsfw_prepare_body(&$a,&$b) {
+
$words = null;
if(get_pconfig(local_user(),'nsfw','disable'))
return;
@@ -93,19 +125,22 @@ function nsfw_prepare_body(&$a,&$b) {
$found = false;
if(count($arr)) {
+
+ $body = nsfw_extract_photos($b['html']);
+
foreach($arr as $word) {
$word = trim($word);
if(! strlen($word)) {
continue;
}
if(strpos($word,'/') === 0) {
- if(preg_match($word,$b['html'])) {
+ if(preg_match($word,$body)) {
$found = true;
break;
}
}
else {
- if(stristr($b['html'],$word)) {
+ if(stristr($body,$word)) {
$found = true;
break;
}
@@ -115,6 +150,7 @@ function nsfw_prepare_body(&$a,&$b) {
}
}
}
+
}
if($found) {
$rnd = random_string(8);
diff --git a/openstreetmap.tgz b/openstreetmap.tgz
index 34f4bd6b1..562115c7c 100644
Binary files a/openstreetmap.tgz and b/openstreetmap.tgz differ
diff --git a/openstreetmap/openstreetmap.js b/openstreetmap/openstreetmap.js
new file mode 100644
index 000000000..479e769cf
--- /dev/null
+++ b/openstreetmap/openstreetmap.js
@@ -0,0 +1,41 @@
+var toolserver = 'http://toolserver.org/~kolossos/openlayers/kml-on-ol.php';
+var startTag = '';
+
+jQuery(document).ready(function($) {
+
+ $('.wall-item-content-wrapper').each(function(index) {
+ var link = $(this).find('.wall-item-location .OSMMapLink');
+ link.toggle(addIframe, removeIframe);
+ });
+});
+
+function addIframe(ev) {
+ var coordinate = $(ev.target).attr('title');
+
+ var newTag = startTag + convertCoordinateString(coordinate) + endTag;
+ $(ev.target).parents('.wall-item-content-wrapper').append(newTag);
+}
+
+function removeIframe(ev) {
+ $(ev.target).parents('.wall-item-content-wrapper').find('iframe').remove();
+
+}
+
+function convertCoordinateString(coordinate) {
+ var locstring = coordinate.split(' ');
+ var northSouth;
+ var westEast;
+
+ if (locstring[0] < 0) {
+ northSouth = '_S_';
+ }else{
+ northSouth = '_N_';
+ }
+ if (locstring[1] < 0) {
+ westEast = '_W';
+ }else{
+ westEast = '_E';
+ }
+ return Math.abs(locstring[0]) + northSouth + Math.abs(locstring[1]) + westEast;
+}
\ No newline at end of file
diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php
index fda29905d..2c5975ebd 100755
--- a/openstreetmap/openstreetmap.php
+++ b/openstreetmap/openstreetmap.php
@@ -10,24 +10,33 @@
function openstreetmap_install() {
register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
+ register_hook('page_header', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_alterheader');
logger("installed openstreetmap");
}
function openstreetmap_uninstall() {
unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
+ unregister_hook('page_header', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_alterheader');
logger("removed openstreetmap");
}
+function openstreetmap_alterheader($a, &$navHtml) {
+ $addScriptTag='' . "\r\n";
+ $a->page['htmlhead'] .= $addScriptTag;
+}
function openstreetmap_location($a, &$item) {
+
+ //
+
if(! (strlen($item['location']) || strlen($item['coord'])))
- return;
+ return;
/*
* Get the configuration variables from the .htconfig file.
- */
+ */
$tmsserver = get_config('openstreetmap','tmsserver');
if(! $tmsserver)
$tmsserver = 'http://openstreetmap.org';
@@ -38,12 +47,27 @@ function openstreetmap_location($a, &$item) {
$location = '';
$coord = '';
+
+ if($item['location'] && !$item['coord'] && true){ //if only a location is given, find the lat-lon
+ $geo_account='demo';
+
+ $s = fetch_url('http://api.geonames.org/search?maxRows=1&fuzzy=0.8&q=' . $item['location'] . '&username=' . $geo_account);
+
+ if($s){
+ $xml = parse_xml_string($s);
+
+ if($xml->geoname->lat && $xml->geoname->lng){
+ $item['coord'] = $xml->geoname->lat . ' ' . $xml->geoname->lng;
+ }
+ }
+ }
+
$location = (($item['location']) ? '' . $item['location'] . '' : '');
if($item['coord']) {
$coords = explode(' ', $item['coord']);
if(count($coords) > 1) {
- $coord = '' . $item['coord'] . '' ;
+ $coord = ' Map ' ;
}
}
if(strlen($coord)) {
@@ -58,7 +82,7 @@ function openstreetmap_location($a, &$item) {
function openstreetmap_plugin_admin (&$a, &$o) {
- $t = file_get_contents( dirname(__file__)."/admin.tpl");
+ $t = get_markup_template( "admin.tpl", "addon/openstreetmap/" );
$tmsserver = get_config('openstreetmap','tmsserver');
if(! $tmsserver)
$tmsserver = 'http://openstreetmap.org';
@@ -67,9 +91,9 @@ function openstreetmap_plugin_admin (&$a, &$o) {
$zoom = 17;
$o = replace_macros( $t, array(
- '$submit' => t('Submit'),
- '$tmsserver' => array('tmsserver', t('Tile Server URL'), $tmsserver, t('A list of public tile servers')),
- '$zoom' => array('zoom', t('Default zoom'), $zoom, t('The default zoom level. (1:world, 18:highest)')),
+ '$submit' => t('Submit'),
+ '$tmsserver' => array('tmsserver', t('Tile Server URL'), $tmsserver, t('A list of public tile servers')),
+ '$zoom' => array('zoom', t('Default zoom'), $zoom, t('The default zoom level. (1:world, 18:highest)')),
));
}
function openstreetmap_plugin_admin_post (&$a) {
diff --git a/openstreetmap/admin.tpl b/openstreetmap/view/admin.tpl
similarity index 100%
rename from openstreetmap/admin.tpl
rename to openstreetmap/view/admin.tpl
diff --git a/openstreetmap/view/smarty3/admin.tpl b/openstreetmap/view/smarty3/admin.tpl
new file mode 100644
index 000000000..6ee07174b
--- /dev/null
+++ b/openstreetmap/view/smarty3/admin.tpl
@@ -0,0 +1,3 @@
+{{include file="field_input.tpl" field=$tmsserver}}
+{{include file="field_input.tpl" field=$zoom}}
+
diff --git a/page.tgz b/page.tgz
index d300a3e2d..c9610e28b 100644
Binary files a/page.tgz and b/page.tgz differ
diff --git a/page/page.php b/page/page.php
index 3f0f04190..21a83e16d 100755
--- a/page/page.php
+++ b/page/page.php
@@ -1,7 +1,7 @@
* based on pages plugin by
@@ -38,6 +38,7 @@ function page_getpage($uid,$showhidden = true,$randomise = false) {
$contacts = q("SELECT `id`, `url`, `name`, `micro` FROM `contact`
WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
+ and blocked = 0 and hidden = 0 and pending = 0 and archive = 0
$order ",
intval($uid)
);
diff --git a/piwik.tgz b/piwik.tgz
index 080dd9e32..a5bd437aa 100755
Binary files a/piwik.tgz and b/piwik.tgz differ
diff --git a/piwik/piwik.php b/piwik/piwik.php
index 9ba15db63..3501b2c8c 100755
--- a/piwik/piwik.php
+++ b/piwik/piwik.php
@@ -84,7 +84,7 @@ function piwik_analytics($a,&$b) {
}
}
function piwik_plugin_admin (&$a, &$o) {
- $t = file_get_contents( dirname(__file__)."/admin.tpl");
+ $t = get_markup_template( "admin.tpl", "addon/piwik/" );
$o = replace_macros( $t, array(
'$submit' => t('Submit'),
'$baseurl' => array('baseurl', t('Piwik Base URL'), get_config('piwik','baseurl' ), t('Absolute path to your Piwik installation. (without protocol (http/s), with trailing slash)')),
diff --git a/piwik/admin.tpl b/piwik/view/admin.tpl
old mode 100755
new mode 100644
similarity index 100%
rename from piwik/admin.tpl
rename to piwik/view/admin.tpl
diff --git a/piwik/view/smarty3/admin.tpl b/piwik/view/smarty3/admin.tpl
new file mode 100644
index 000000000..bfe04aa31
--- /dev/null
+++ b/piwik/view/smarty3/admin.tpl
@@ -0,0 +1,5 @@
+{{include file="field_input.tpl" field=$baseurl}}
+{{include file="field_input.tpl" field=$siteid}}
+{{include file="field_checkbox.tpl" field=$optout}}
+{{include file="field_checkbox.tpl" field=$async}}
+
diff --git a/pledgie/pledgie.php b/pledgie/pledgie.php
new file mode 100644
index 000000000..8f6228f69
--- /dev/null
+++ b/pledgie/pledgie.php
@@ -0,0 +1,16 @@
+
+ * */
+
+
+function pledgie_install() { register_hook('page_end', 'addon/pledgie/pledgie.php', 'pledgie_active'); }
+
+
+function pledgie_uninstall() { unregister_hook('page_end', 'addon/pledgie/pledgie.php', 'pledgie_active'); }
+
+function pledgie_active(&$a,&$b) { $b .= '
'; }
+
diff --git a/privacy_image_cache.tgz b/privacy_image_cache.tgz
index b4c100804..45444a683 100644
Binary files a/privacy_image_cache.tgz and b/privacy_image_cache.tgz differ
diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php
index f4ada61e1..b0909e814 100644
--- a/privacy_image_cache/privacy_image_cache.php
+++ b/privacy_image_cache/privacy_image_cache.php
@@ -9,6 +9,7 @@
define("PRIVACY_IMAGE_CACHE_DEFAULT_TIME", 86400); // 1 Day
require_once('include/security.php');
+require_once("include/Photo.php");
function privacy_image_cache_install() {
register_hook('prepare_body', 'addon/privacy_image_cache/privacy_image_cache.php', 'privacy_image_cache_prepare_body_hook');
@@ -30,48 +31,85 @@ function privacy_image_cache_uninstall() {
function privacy_image_cache_module() {}
-
function privacy_image_cache_init() {
- global $a;
+ global $a, $_SERVER;
- if ($a->config["system"]["db_log"] != "")
- $stamp1 = microtime(true);
+ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
+ header('HTTP/1.1 304 Not Modified');
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
+ header('Etag: '.$_SERVER['HTTP_IF_NONE_MATCH']);
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
+ header("Cache-Control: max-age=31536000");
+ if(function_exists('header_remove')) {
+ header_remove('Last-Modified');
+ header_remove('Expires');
+ header_remove('Cache-Control');
+ }
+ exit;
+ }
if(function_exists('header_remove')) {
header_remove('Pragma');
header_remove('pragma');
}
+ $thumb = false;
+
+ // Look for filename in the arguments
+ if (isset($a->argv[1]) OR isset($a->argv[2]) OR isset($a->argv[3])) {
+ if (isset($a->argv[3]))
+ $url = $a->argv[3];
+ elseif (isset($a->argv[2]))
+ $url = $a->argv[2];
+ else
+ $url = $a->argv[1];
+
+ $pos = strrpos($url, "=.");
+ if ($pos)
+ $url = substr($url, 0, $pos+1);
+
+ $url = str_replace(array(".jpg", ".jpeg", ".gif", ".png"), array("","","",""), $url);
+
+ $url = base64_decode(strtr($url, '-_', '+/'), true);
+
+ if ($url)
+ $_REQUEST['url'] = $url;
+ $thumb = (isset($a->argv[3]) and ($a->argv[3] == "thumb"));
+ }
+
$urlhash = 'pic:' . sha1($_REQUEST['url']);
// Double encoded url - happens with Diaspora
$urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url']));
- $cache = get_config('system','itemcache');
- if (($cache != '') and is_dir($cache)) {
- $cachefile = $cache."/".hash("md5", $_REQUEST['url']);
+ $cachefile = get_cachefile(hash("md5", $_REQUEST['url']));
+ if ($cachefile != '') {
if (file_exists($cachefile)) {
$img_str = file_get_contents($cachefile);
-
$mime = image_type_to_mime_type(exif_imagetype($cachefile));
header("Content-type: $mime");
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
- header("Cache-Control: max-age=" . (3600*24));
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
+ header('Etag: "'.md5($img_str).'"');
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
+ header("Cache-Control: max-age=31536000");
+
+ // reduce quality - if it isn't a GIF
+ if ($mime != "image/gif") {
+ $img = new Photo($img_str, $mime);
+ if($img->is_valid())
+ $img_str = $img->imageString();
+ }
echo $img_str;
- if ($a->config["system"]["db_log"] != "") {
- $stamp2 = microtime(true);
- $duration = round($stamp2-$stamp1, 3);
- if ($duration > $a->config["system"]["db_loglimit"])
- @file_put_contents($a->config["system"]["db_log"], $duration."\t".strlen($img_str)."\t".$_REQUEST['url']."\n", FILE_APPEND);
- }
+ if (is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache"))
+ file_put_contents($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache/".privacy_image_cache_cachename($_REQUEST['url'], true), $img_str);
killme();
}
}
- require_once("Photo.php");
+ $valid = true;
$r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2);
if (count($r)) {
@@ -79,21 +117,14 @@ function privacy_image_cache_init() {
$mime = $r[0]["desc"];
if ($mime == "") $mime = "image/jpeg";
- // Test
- //if ($mime == "image/jpeg") {
- // $img = new Photo($img_str);
- // if($img->is_valid()) {
- // $img->scaleImage(1000);
- // $img_str = $img->imageString();
- // }
- //}
} else {
// It shouldn't happen but it does - spaces in URL
$_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']);
- $img_str = fetch_url($_REQUEST['url'],true);
+ $redirects = 0;
+ $img_str = fetch_url($_REQUEST['url'],true, $redirects, 10);
- $tempfile = tempnam("", "cache");
+ $tempfile = tempnam(get_config("system","temppath"), "cache");
file_put_contents($tempfile, $img_str);
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
unlink($tempfile);
@@ -102,7 +133,13 @@ function privacy_image_cache_init() {
if ((substr($a->get_curl_code(), 0, 1) == "4") or (!$img_str)) {
$img_str = file_get_contents("images/blank.png");
$mime = "image/png";
- //} else if (substr($img_str, 0, 6) == "GIF89a") {
+ $cachefile = ""; // Clear the cachefile so that the dummy isn't stored
+ $valid = false;
+ $img = new Photo($img_str, "image/png");
+ if($img->is_valid()) {
+ $img->scaleImage(10);
+ $img_str = $img->imageString();
+ }
} else if ($mime != "image/jpeg") {
$image = @imagecreatefromstring($img_str);
@@ -126,34 +163,75 @@ function privacy_image_cache_init() {
);
} else {
- $img = new Photo($img_str);
+ $img = new Photo($img_str, $mime);
if($img->is_valid()) {
$img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
- //$img->scaleImage(1000); // Test
+ if ($thumb)
+ $img->scaleImage(200); // Test
$img_str = $img->imageString();
}
- $mime = "image/jpeg";
+ //$mime = "image/jpeg";
}
}
+ // reduce quality - if it isn't a GIF
+ if ($mime != "image/gif") {
+ $img = new Photo($img_str, $mime);
+ if($img->is_valid())
+ $img_str = $img->imageString();
+ }
- // Writing in cachefile
- if (isset($cachefile) && ($cachefile != '') and (file_exists($cachefile)) and (exif_imagetype($cachefile) > 0))
+ // If there is a real existing directory then put the cache file there
+ // advantage: real file access is really fast
+ // Otherwise write in cachefile
+ if ($valid AND is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache"))
+ file_put_contents($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache/".privacy_image_cache_cachename($_REQUEST['url'], true), $img_str);
+ elseif ($cachefile != '')
file_put_contents($cachefile, $img_str);
header("Content-type: $mime");
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
- header("Cache-Control: max-age=" . (3600*24));
+
+ // Only output the cache headers when the file is valid
+ if ($valid) {
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
+ header('Etag: "'.md5($img_str).'"');
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
+ header("Cache-Control: max-age=31536000");
+ }
echo $img_str;
- if ($a->config["system"]["db_log"] != "") {
- $stamp2 = microtime(true);
- $duration = round($stamp2-$stamp1, 3);
- if ($duration > $a->config["system"]["db_loglimit"])
- @file_put_contents($a->config["system"]["db_log"], $duration."\t".strlen($img_str)."\t".$_REQUEST['url']."\n", FILE_APPEND);
+ killme();
+}
+
+function privacy_image_cache_cachename($url, $writemode = false) {
+ global $_SERVER;
+
+ $pos = strrpos($url, ".");
+ if ($pos) {
+ $extension = strtolower(substr($url, $pos+1));
+ $pos = strpos($extension, "?");
+ if ($pos)
+ $extension = substr($extension, 0, $pos);
}
- killme();
+ $basepath = $_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache";
+
+ $path = substr(hash("md5", $url), 0, 2);
+
+ if (is_dir($basepath) and $writemode)
+ if (!is_dir($basepath."/".$path)) {
+ mkdir($basepath."/".$path);
+ chmod($basepath."/".$path, 0777);
+ }
+
+ $path .= "/".strtr(base64_encode($url), '+/', '-_');
+
+ $extensions = array("jpg", "jpeg", "gif", "png");
+
+ if (in_array($extension, $extensions))
+ $path .= ".".$extension;
+
+ return($path);
}
/**
@@ -161,13 +239,21 @@ function privacy_image_cache_init() {
* @return boolean
*/
function privacy_image_cache_is_local_image($url) {
- if ($url[0] == '/') return true;
+ if ($url[0] == '/') return true;
+
if (strtolower(substr($url, 0, 5)) == "data:") return true;
+ // Check if the cached path would be longer than 255 characters - apache doesn't like it
+ if (is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")) {
+ $cachedurl = get_app()->get_baseurl()."/privacy_image_cache/". privacy_image_cache_cachename($url);
+ if (strlen($url) > 150)
+ return true;
+ }
+
// links normalised - bug #431
- $baseurl = normalise_link(get_app()->get_baseurl());
+ $baseurl = normalise_link(get_app()->get_baseurl());
$url = normalise_link($url);
- return (substr($url, 0, strlen($baseurl)) == $baseurl);
+ return (substr($url, 0, strlen($baseurl)) == $baseurl);
}
/**
@@ -175,11 +261,23 @@ function privacy_image_cache_is_local_image($url) {
* @return string
*/
function privacy_image_cache_img_cb($matches) {
+
+ // if the picture seems to be from another picture cache then take the original source
+ $queryvar = privacy_image_cache_parse_query($matches[2]);
+ if ($queryvar['url'] != "")
+ $matches[2] = urldecode($queryvar['url']);
+
+ // if fetching facebook pictures don't fetch the thumbnail but the big one
+ if (strpos($matches[2], ".fbcdn.net/") and (substr($matches[2], -6) == "_s.jpg"))
+ $matches[2] = substr($matches[2], 0, -6)."_n.jpg";
+
// following line changed per bug #431
if (privacy_image_cache_is_local_image($matches[2]))
return $matches[1] . $matches[2] . $matches[3];
- return $matches[1] . get_app()->get_baseurl() . "/privacy_image_cache/?url=" . addslashes(rawurlencode(htmlspecialchars_decode($matches[2]))) . $matches[3];
+ //return $matches[1] . get_app()->get_baseurl() . "/privacy_image_cache/?url=" . addslashes(rawurlencode(htmlspecialchars_decode($matches[2]))) . $matches[3];
+
+ return $matches[1].get_app()->get_baseurl()."/privacy_image_cache/". privacy_image_cache_cachename(htmlspecialchars_decode($matches[2])).$matches[3];
}
/**
@@ -207,9 +305,14 @@ function privacy_image_cache_bbcode_hook(&$a, &$o) {
function privacy_image_cache_display_item_hook(&$a, &$o) {
if (isset($o["output"])) {
if (isset($o["output"]["thumb"]) && !privacy_image_cache_is_local_image($o["output"]["thumb"]))
- $o["output"]["thumb"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["thumb"])));
+ $o["output"]["thumb"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["thumb"]);
+ //$o["output"]["thumb"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["thumb"])));
if (isset($o["output"]["author-avatar"]) && !privacy_image_cache_is_local_image($o["output"]["author-avatar"]))
- $o["output"]["author-avatar"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["author-avatar"])));
+ $o["output"]["author-avatar"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["author-avatar"]);
+ //$o["output"]["author-avatar"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["author-avatar"])));
+ if (isset($o["output"]["owner-avatar"]) && !privacy_image_cache_is_local_image($o["output"]["owner-avatar"]))
+ $o["output"]["owner-avatar"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["owner-avatar"]);
+ //$o["output"]["owner-avatar"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["owner-avatar"])));
}
}
@@ -220,7 +323,8 @@ function privacy_image_cache_display_item_hook(&$a, &$o) {
*/
function privacy_image_cache_ping_xmlize_hook(&$a, &$o) {
if ($o["photo"] != "" && !privacy_image_cache_is_local_image($o["photo"]))
- $o["photo"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["photo"])));
+ $o["photo"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["photo"]);
+ //$o["photo"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["photo"])));
}
@@ -238,12 +342,12 @@ function privacy_image_cache_cron(&$a = null, &$b = null) {
logger("Purging old Cache of the Privacy Image Cache", LOGGER_DEBUG);
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
+
+ clear_cache($a->get_basepath(), $a->get_basepath()."/privacy_image_cache");
+
set_config('pi_cache', 'last_delete', $time);
}
-
-
-
/**
* @param App $a
* @param null|object $o
@@ -289,3 +393,22 @@ function privacy_image_cache_plugin_admin_post(&$a = null, &$o = null){
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%"');
}
}
+
+function privacy_image_cache_parse_query($var) {
+ /**
+ * Use this function to parse out the query array element from
+ * the output of parse_url().
+ */
+ $var = parse_url($var, PHP_URL_QUERY);
+ $var = html_entity_decode($var);
+ $var = explode('&', $var);
+ $arr = array();
+
+ foreach($var as $val) {
+ $x = explode('=', $val);
+ $arr[$x[0]] = $x[1];
+ }
+
+ unset($val, $x, $var);
+ return $arr;
+}
diff --git a/procrunner.tgz b/procrunner.tgz
new file mode 100644
index 000000000..fec9dfa72
Binary files /dev/null and b/procrunner.tgz differ
diff --git a/procrunner/procrunner.php b/procrunner/procrunner.php
new file mode 100755
index 000000000..4c6f64b68
--- /dev/null
+++ b/procrunner/procrunner.php
@@ -0,0 +1,53 @@
+
+ * Author: Mike Macgirvin
+ */
+
+function procrunner_install() {
+
+ $addons = get_config('system','addon');
+ if(strstr('poormancron',$addons)) {
+ logger('procrunner incompatible with poormancron. Not installing procrunner.');
+ return;
+ }
+
+ // check for command line php
+ $a = get_app();
+ $ex = Array();
+ $ex[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
+ $ex[1] = dirname(dirname(dirname(__file__)))."/testargs.php";
+ $ex[2] = "test";
+ $out = exec(implode(" ", $ex));
+ if ($out==="test") {
+ logger('procrunner not required on this system. Not installing.');
+ return;
+ } else {
+ register_hook('proc_run', 'addon/procrunner/procrunner.php','procrunner_procrun');
+ logger("installed procrunner");
+ }
+
+}
+
+function procrunner_uninstall() {
+ unregister_hook('proc_run', 'addon/procrunner/procrunner.php','procrunner_procrun');
+ logger("removed procrunner");
+}
+
+
+
+function procrunner_procrun(&$a, &$arr) {
+
+ $argv = $arr['args'];
+ $arr['run_cmd'] = false;
+ logger("procrunner procrun ".implode(", ",$argv));
+ array_shift($argv);
+ $argc = count($argv);
+ logger("procrunner procrun require_once ".basename($argv[0]));
+ require_once(basename($argv[0]));
+ $funcname=str_replace(".php", "", basename($argv[0]))."_run";
+ $funcname($argv, $argc);
+}
diff --git a/randplace.tgz b/randplace.tgz
index 7ab5f0db9..bdad8bafb 100755
Binary files a/randplace.tgz and b/randplace.tgz differ
diff --git a/remote_permissions.tgz b/remote_permissions.tgz
new file mode 100644
index 000000000..fef4f39bf
Binary files /dev/null and b/remote_permissions.tgz differ
diff --git a/remote_permissions/README.md b/remote_permissions/README.md
new file mode 100644
index 000000000..b9e385825
--- /dev/null
+++ b/remote_permissions/README.md
@@ -0,0 +1,8 @@
+The Remote Permissions plugin enables recipients of private posts to see who else has received the post. This can be beneficial on community servers where people may want to modify the way they speak depending on who can see their comments to the post.
+
+Note that since Friendica is federated, the local hub may have posts that originated elsewhere. In that case, the plugin has no way of knowing all the recipients of the post, and it must settle for finding out who else can see it on the local hub.
+
+The hub admin can specify one of two behaviors for this plugin:
+
+* **Global:** every private post on the local hub will show all recipients (or at least the ones it can discover) of the post to any other users on the local hub
+* **Individual:** only private posts from those users on the local hub who "opt-in" will show the post recipients. None of the private posts that originated elsewhere will show even partial lists of post recipients
diff --git a/remote_permissions/remote_permissions.php b/remote_permissions/remote_permissions.php
new file mode 100644
index 000000000..8955130f8
--- /dev/null
+++ b/remote_permissions/remote_permissions.php
@@ -0,0 +1,207 @@
+
+ *
+ */
+
+
+function remote_permissions_install() {
+ register_hook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
+ register_hook('plugin_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
+ register_hook('plugin_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
+}
+
+function remote_permissions_uninstall() {
+ unregister_hook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
+ unregister_hook('plugin_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
+ unregister_hook('plugin_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
+}
+
+function remote_permissions_settings(&$a,&$o) {
+
+ if(! local_user())
+ return;
+
+ $global = get_config("remote_perms", "global");
+ if($global == 1)
+ return;
+
+ /* Add our stylesheet to the page so we can make our settings look nice */
+
+ $a->page['htmlhead'] .= '' . "\r\n";
+
+ /* Get the current state of our config variable */
+
+ $remote_perms = get_pconfig(local_user(),'remote_perms','show');
+
+ /* Add some HTML to the existing form */
+
+// $t = file_get_contents("addon/remote_permissions/settings.tpl" );
+ $t = get_markup_template("settings.tpl", "addon/remote_permissions/" );
+ $o .= replace_macros($t, array(
+ '$remote_perms_title' => t('Remote Permissions Settings'),
+ '$remote_perms_label' => t('Allow recipients of your private posts to see the other recipients of the posts'),
+ '$checked' => (($remote_perms == 1) ? 'checked="checked"' : ''),
+ '$submit' => t('Submit')
+ ));
+
+}
+
+function remote_permissions_settings_post($a,$post) {
+ if(! local_user() || (! x($_POST,'remote-perms-submit')))
+ return;
+
+ set_pconfig(local_user(),'remote_perms','show',intval($_POST['remote-perms']));
+ info( t('Remote Permissions settings updated.') . EOL);
+}
+
+function remote_permissions_content($a, $item_copy) {
+
+ if($item_copy['uid'] != local_user())
+ return;
+
+ if(get_config('remote_perms','global') == 0) {
+ // Admin has set Individual choice. We need to find
+ // the original poster. First, get the contact's info
+ $r = q("SELECT nick, url FROM contact WHERE id = %d LIMIT 1",
+ intval($item_copy['contact-id'])
+ );
+ if(! $r)
+ return;
+
+ // Find out if the contact lives here
+ $baseurl = $a->get_baseurl();
+ $baseurl = substr($baseurl, strpos($baseurl, '://') + 3);
+ if(strpos($r[0]['url'], $baseurl) === false)
+ return;
+
+ // The contact lives here. Get his/her user info
+ $nick = $r[0]['nick'];
+ $r = q("SELECT uid FROM user WHERE nickname = '%s' LIMIT 1",
+ dbesc($nick)
+ );
+ if(! $r)
+ return;
+
+ if(get_pconfig($r[0]['uid'],'remote_perms','show') == 0)
+ return;
+ }
+
+ if(($item_copy['private'] == 1) && (! strlen($item_copy['allow_cid'])) && (! strlen($item_copy['allow_gid']))
+ && (! strlen($item_copy['deny_cid'])) && (! strlen($item_copy['deny_gid']))) {
+
+ $allow_names = array();
+
+ // Check for the original post here -- that's the only way
+ // to definitely get all of the recipients
+
+ if($item_copy['uri'] === $item_copy['parent-uri']) {
+ // Lockview for a top-level post
+ $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s' AND type = 'wall' LIMIT 1",
+ dbesc($item_copy['uri'])
+ );
+ }
+ else {
+ // Lockview for a comment
+ $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s'
+ AND parent = ( SELECT id FROM item WHERE uri = '%s' AND type = 'wall' ) LIMIT 1",
+ dbesc($item_copy['uri']),
+ dbesc($item_copy['parent-uri'])
+ );
+ }
+ if($r) {
+
+ $item = $r[0];
+
+ $allowed_users = expand_acl($item['allow_cid']);
+ $allowed_groups = expand_acl($item['allow_gid']);
+ $deny_users = expand_acl($item['deny_cid']);
+ $deny_groups = expand_acl($item['deny_gid']);
+
+ $o = t('Visible to:') . ' ';
+ $allow = array();
+ $deny = array();
+
+ if(count($allowed_groups)) {
+ $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
+ dbesc(implode(', ', $allowed_groups))
+ );
+ foreach($r as $rr)
+ $allow[] = $rr['contact-id'];
+ }
+ $allow = array_unique($allow + $allowed_users);
+
+ if(count($deny_groups)) {
+ $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
+ dbesc(implode(', ', $deny_groups))
+ );
+ foreach($r as $rr)
+ $deny[] = $rr['contact-id'];
+ }
+ $deny = $deny + $deny_users;
+
+ if($allow)
+ {
+ $r = q("SELECT name FROM contact WHERE id IN ( %s )",
+ dbesc(implode(', ', array_diff($allow, $deny)))
+ );
+ foreach($r as $rr)
+ $allow_names[] = $rr['name'];
+ }
+ }
+ else {
+ // We don't have the original post. Let's try for the next best thing:
+ // checking who else has the post on our own server. Note that comments
+ // that were sent to Diaspora and were relayed to others on our server
+ // will have different URIs than the original. We can match the GUID for
+ // those
+ $r = q("SELECT `uid` FROM item WHERE uri = '%s' OR guid = '%s'",
+ dbesc($item_copy['uri']),
+ dbesc($item_copy['guid'])
+ );
+ if(! $r)
+ return;
+
+ $allow = array();
+ foreach($r as $rr)
+ $allow[] = $rr['uid'];
+
+ $r = q("SELECT username FROM user WHERE uid IN ( %s )",
+ dbesc(implode(', ', $allow))
+ );
+ if(! $r)
+ return;
+
+ $o = t('Visible to') . ' (' . t('may only be a partial list') . '): ';
+
+ foreach($r as $rr)
+ $allow_names[] = $rr['username'];
+ }
+
+ // Sort the names alphabetically, case-insensitive
+ natcasesort($allow_names);
+ echo $o . implode(', ', $allow_names);
+ killme();
+ }
+
+ return;
+}
+
+function remote_permissions_plugin_admin(&$a, &$o){
+ $t = get_markup_template( "admin.tpl", "addon/remote_permissions/" );
+ $o = replace_macros($t, array(
+ '$submit' => t('Submit'),
+ '$global' => array('remotepermschoice', t('Global'), 1, t('The posts of every user on this server show the post recipients'), get_config('remote_perms', 'global') == 1),
+ '$individual' => array('remotepermschoice', t('Individual'), 2, t('Each user chooses whether his/her posts show the post recipients'), get_config('remote_perms', 'global') == 0)
+ ));
+}
+
+function remote_permissions_plugin_admin_post(&$a){
+ $choice = ((x($_POST,'remotepermschoice')) ? notags(trim($_POST['remotepermschoice'])) : '');
+ set_config('remote_perms','global',($choice == 1 ? 1 : 0));
+ info( t('Settings updated.'). EOL );
+}
+
diff --git a/remote_permissions/settings.css b/remote_permissions/settings.css
new file mode 100644
index 000000000..ef6051d2f
--- /dev/null
+++ b/remote_permissions/settings.css
@@ -0,0 +1,16 @@
+
+
+
+#remote-perms-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 25px;
+ margin-right: 20px;
+ text-align: justify;
+}
+
+#remote-perms {
+ float: left;
+}
+
+
diff --git a/remote_permissions/view/admin.tpl b/remote_permissions/view/admin.tpl
new file mode 100644
index 000000000..605588084
--- /dev/null
+++ b/remote_permissions/view/admin.tpl
@@ -0,0 +1,3 @@
+{{ inc field_radio.tpl with $field=$global }}{{ endinc }}
+{{ inc field_radio.tpl with $field=$individual }}{{ endinc }}
+
diff --git a/remote_permissions/view/settings.tpl b/remote_permissions/view/settings.tpl
new file mode 100644
index 000000000..9fd98957f
--- /dev/null
+++ b/remote_permissions/view/settings.tpl
@@ -0,0 +1,8 @@
+
';
+ $s .= '';
+ $s .= ' ';
+ $s .= '';
$s .= '';
} else {
/***
@@ -342,6 +359,15 @@ function statusnet_settings(&$a,&$s) {
$s .= '';
$s .= '';
$s .= '';
+
+ $s .= '';
+ $s .= '';
+ $s .= '';
+
+ $s .= '';
+ $s .= '';
+ $s .= '';
+
$s .= '';
$s .= '';
$s .= '';
@@ -404,6 +430,131 @@ function short_link($url) {
return $slinky->short();
} };
+function statusnet_shortenmsg($b, $max_char) {
+ require_once("include/bbcode.php");
+ require_once("include/html2plain.php");
+
+ // Looking for the first image
+ $image = '';
+ if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches))
+ $image = $matches[3];
+
+ if ($image == '')
+ if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches))
+ $image = $matches[1];
+
+ $multipleimages = (strpos($b['body'], "[img") != strrpos($b['body'], "[img"));
+
+ // When saved into the database the content is sent through htmlspecialchars
+ // That means that we have to decode all image-urls
+ $image = htmlspecialchars_decode($image);
+
+ $body = $b["body"];
+ if ($b["title"] != "")
+ $body = $b["title"]."\n\n".$body;
+
+ if (strpos($body, "[bookmark") !== false) {
+ // splitting the text in two parts:
+ // before and after the bookmark
+ $pos = strpos($body, "[bookmark");
+ $body1 = substr($body, 0, $pos);
+ $body2 = substr($body, $pos);
+
+ // Removing all quotes after the bookmark
+ // they are mostly only the content after the bookmark.
+ $body2 = preg_replace("/\[quote\=([^\]]*)\](.*?)\[\/quote\]/ism",'',$body2);
+ $body2 = preg_replace("/\[quote\](.*?)\[\/quote\]/ism",'',$body2);
+ $body = $body1.$body2;
+ }
+
+ // Add some newlines so that the message could be cut better
+ $body = str_replace(array("[quote", "[bookmark", "[/bookmark]", "[/quote]"),
+ array("\n[quote", "\n[bookmark", "[/bookmark]\n", "[/quote]\n"), $body);
+
+ // remove the recycle signs and the names since they aren't helpful on twitter
+ // recycle 1
+ $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
+ $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
+ // recycle 2 (Test)
+ $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
+ $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
+
+ // remove the share element
+ $body = preg_replace("/\[share(.*?)\](.*?)\[\/share\]/ism","\n\n$2\n\n",$body);
+
+ // At first convert the text to html
+ $html = bbcode($body, false, false);
+
+ // Then convert it to plain text
+ //$msg = trim($b['title']." \n\n".html2plain($html, 0, true));
+ $msg = trim(html2plain($html, 0, true));
+ $msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
+
+ // Removing multiple newlines
+ while (strpos($msg, "\n\n\n") !== false)
+ $msg = str_replace("\n\n\n", "\n\n", $msg);
+
+ // Removing multiple spaces
+ while (strpos($msg, " ") !== false)
+ $msg = str_replace(" ", " ", $msg);
+
+ // Removing URLs
+ $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
+
+ $msg = trim($msg);
+
+ $link = '';
+ // look for bookmark-bbcode and handle it with priority
+ if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches))
+ $link = $matches[1];
+
+ $multiplelinks = (strpos($b['body'], "[bookmark") != strrpos($b['body'], "[bookmark"));
+
+ // If there is no bookmark element then take the first link
+ if ($link == '') {
+ $links = collecturls($html);
+ if (sizeof($links) > 0) {
+ reset($links);
+ $link = current($links);
+ }
+ $multiplelinks = (sizeof($links) > 1);
+ }
+
+ $msglink = "";
+ if ($multiplelinks)
+ $msglink = $b["plink"];
+ else if ($link != "")
+ $msglink = $link;
+ else if ($multipleimages)
+ $msglink = $b["plink"];
+ else if ($image != "")
+ $msglink = $image;
+
+ if (($msglink == "") and strlen($msg) > $max_char)
+ $msglink = $b["plink"];
+
+ if (strlen($msglink) > 20)
+ $msglink = short_link($msglink);
+
+ if (strlen(trim($msg." ".$msglink)) > $max_char) {
+ $msg = substr($msg, 0, $max_char - (strlen($msglink)));
+ $lastchar = substr($msg, -1);
+ $msg = substr($msg, 0, -1);
+ $pos = strrpos($msg, "\n");
+ if ($pos > 0)
+ $msg = substr($msg, 0, $pos);
+ else if ($lastchar != "\n")
+ $msg = substr($msg, 0, -3)."...";
+ }
+ $msg = str_replace("\n", " ", $msg);
+
+ // Removing multiple spaces - again
+ while (strpos($msg, " ") !== false)
+ $msg = str_replace(" ", " ", $msg);
+
+ return(array("msg"=>trim($msg." ".$msglink), "image"=>$image));
+}
+
function statusnet_post_hook(&$a,&$b) {
/**
@@ -416,105 +567,136 @@ function statusnet_post_hook(&$a,&$b) {
if(! strstr($b['postopts'],'statusnet'))
return;
+ // if posts comes from statusnet don't send it back
+ if($b['app'] == "StatusNet")
+ return;
+
+ logger('statusnet post invoked');
+
load_pconfig($b['uid'], 'statusnet');
-
+
$api = get_pconfig($b['uid'], 'statusnet', 'baseapi');
- $ckey = get_pconfig($b['uid'], 'statusnet', 'consumerkey' );
- $csecret = get_pconfig($b['uid'], 'statusnet', 'consumersecret' );
- $otoken = get_pconfig($b['uid'], 'statusnet', 'oauthtoken' );
- $osecret = get_pconfig($b['uid'], 'statusnet', 'oauthsecret' );
+ $ckey = get_pconfig($b['uid'], 'statusnet', 'consumerkey');
+ $csecret = get_pconfig($b['uid'], 'statusnet', 'consumersecret');
+ $otoken = get_pconfig($b['uid'], 'statusnet', 'oauthtoken');
+ $osecret = get_pconfig($b['uid'], 'statusnet', 'oauthsecret');
+ $intelligent_shortening = get_pconfig($b['uid'], 'statusnet', 'intelligent_shortening');
+
+ // Global setting overrides this
+ if (get_config('statusnet','intelligent_shortening'))
+ $intelligent_shortening = get_config('statusnet','intelligent_shortening');
if($ckey && $csecret && $otoken && $osecret) {
require_once('include/bbcode.php');
$dent = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret);
$max_char = $dent->get_maxlength(); // max. length for a dent
- // we will only work with up to two times the length of the dent
+ // we will only work with up to two times the length of the dent
// we can later send to StatusNet. This way we can "gain" some
// information during shortening of potential links but do not
// shorten all the links in a 200000 character long essay.
- if (! $b['title']=='') {
- $tmp = $b['title'].": \n".$b['body'];
-// $tmp = substr($tmp, 0, 4*$max_char);
- } else {
- $tmp = $b['body']; // substr($b['body'], 0, 3*$max_char);
- }
- // if [url=bla][img]blub.png[/img][/url] get blub.png
- $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\]\[img\](\\w+.*?)\\[\\/img\]\\[\\/url\]/i', '$2', $tmp);
- // preserve links to images, videos and audios
- $tmp = preg_replace( '/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism', '$3', $tmp);
- $tmp = preg_replace( '/\[\\/?img(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?video(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?youtube(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?vimeo(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?audio(\\s+.*?\]|\])/i', '', $tmp);
- $linksenabled = get_pconfig($b['uid'],'statusnet','post_taglinks');
- // if a #tag is linked, don't send the [url] over to SN
- // that is, don't send if the option is not set in the
- // connector settings
- if ($linksenabled=='0') {
- // #-tags
- $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp);
- // @-mentions
- $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp);
- // recycle 1
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
- // recycle 2 (test)
- $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
- $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
- }
- // preserve links to webpages
- $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp);
- $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp);
- // find all http or https links in the body of the entry and
- // apply the shortener if the link is longer then 20 characters
- if (( strlen($tmp)>$max_char ) && ( $max_char > 0 )) {
- preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls );
- foreach ($allurls as $url) {
- foreach ($url as $u) {
- if (strlen($u)>20) {
- $sl = short_link($u);
- $tmp = str_replace( $u, $sl, $tmp );
- }
- }
- }
- }
- // ok, all the links we want to send out are save, now strip
- // away the remaining bbcode
- //$msg = strip_tags(bbcode($tmp, false, false));
- $msg = bbcode($tmp, false, false);
- $msg = str_replace(array(' ',' '),"\n",$msg);
- $msg = strip_tags($msg);
- // quotes not working - let's try this
- $msg = html_entity_decode($msg);
+ $tempfile = "";
+ $intelligent_shortening = get_config('statusnet','intelligent_shortening');
+ if (!$intelligent_shortening) {
+ if (! $b['title']=='') {
+ $tmp = $b['title'].": \n".$b['body'];
+ // $tmp = substr($tmp, 0, 4*$max_char);
+ } else {
+ $tmp = $b['body']; // substr($b['body'], 0, 3*$max_char);
+ }
+ // if [url=bla][img]blub.png[/img][/url] get blub.png
+ $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\]\[img\](\\w+.*?)\\[\\/img\]\\[\\/url\]/i', '$2', $tmp);
+ // preserve links to images, videos and audios
+ $tmp = preg_replace( '/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism', '$3', $tmp);
+ $tmp = preg_replace( '/\[\\/?img(\\s+.*?\]|\])/i', '', $tmp);
+ $tmp = preg_replace( '/\[\\/?video(\\s+.*?\]|\])/i', '', $tmp);
+ $tmp = preg_replace( '/\[\\/?youtube(\\s+.*?\]|\])/i', '', $tmp);
+ $tmp = preg_replace( '/\[\\/?vimeo(\\s+.*?\]|\])/i', '', $tmp);
+ $tmp = preg_replace( '/\[\\/?audio(\\s+.*?\]|\])/i', '', $tmp);
+ $linksenabled = get_pconfig($b['uid'],'statusnet','post_taglinks');
+ // if a #tag is linked, don't send the [url] over to SN
+ // that is, don't send if the option is not set in the
+ // connector settings
+ if ($linksenabled=='0') {
+ // #-tags
+ $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp);
+ // @-mentions
+ $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp);
+ // recycle 1
+ $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
+ $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
+ // recycle 2 (test)
+ $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
+ $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
+ }
+ // preserve links to webpages
+ $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp);
+ $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp);
+ // find all http or https links in the body of the entry and
+ // apply the shortener if the link is longer then 20 characters
+ if (( strlen($tmp)>$max_char ) && ( $max_char > 0 )) {
+ preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls );
+ foreach ($allurls as $url) {
+ foreach ($url as $u) {
+ if (strlen($u)>20) {
+ $sl = short_link($u);
+ $tmp = str_replace( $u, $sl, $tmp );
+ }
+ }
+ }
+ }
+ // ok, all the links we want to send out are save, now strip
+ // away the remaining bbcode
+ //$msg = strip_tags(bbcode($tmp, false, false));
+ $msg = bbcode($tmp, false, false);
+ $msg = str_replace(array(' ',' '),"\n",$msg);
+ $msg = strip_tags($msg);
- if (( strlen($msg) > $max_char) && $max_char > 0) {
- $shortlink = short_link( $b['plink'] );
- // the new message will be shortened such that "... $shortlink"
- // will fit into the character limit
- $msg = nl2br(substr($msg, 0, $max_char-strlen($shortlink)-4));
- $msg = str_replace(array(' ',' '),' ',$msg);
- $e = explode(' ', $msg);
- // remove the last word from the cut down message to
- // avoid sending cut words to the MicroBlog
- array_pop($e);
- $msg = implode(' ', $e);
- $msg .= '... ' . $shortlink;
+ // quotes not working - let's try this
+ $msg = html_entity_decode($msg);
+
+ if (( strlen($msg) > $max_char) && $max_char > 0) {
+ $shortlink = short_link( $b['plink'] );
+ // the new message will be shortened such that "... $shortlink"
+ // will fit into the character limit
+ $msg = nl2br(substr($msg, 0, $max_char-strlen($shortlink)-4));
+ $msg = str_replace(array(' ',' '),' ',$msg);
+ $e = explode(' ', $msg);
+ // remove the last word from the cut down message to
+ // avoid sending cut words to the MicroBlog
+ array_pop($e);
+ $msg = implode(' ', $e);
+ $msg .= '... ' . $shortlink;
+ }
+
+ $msg = trim($msg);
+ $postdata = array('status' => $msg);
+ } else {
+ $msgarr = statusnet_shortenmsg($b, $max_char);
+ $msg = $msgarr["msg"];
+ $image = $msgarr["image"];
+ if ($image != "") {
+ $imagedata = file_get_contents($image);
+ $tempfile = tempnam(get_config("system","temppath"), "upload");
+ file_put_contents($tempfile, $imagedata);
+ $postdata = array("status"=>$msg, "media"=>"@".$tempfile);
+ } else
+ $postdata = array("status"=>$msg);
}
- $msg = trim($msg);
-
// and now dent it :-)
if(strlen($msg)) {
- $result = $dent->post('statuses/update', array('status' => $msg));
+ //$result = $dent->post('statuses/update', array('status' => $msg));
+ $result = $dent->post('statuses/update', $postdata);
logger('statusnet_post send, result: ' . print_r($result, true).
- "\nmessage: ".$msg, LOGGER_DEBUG."\nOriginal post: ".print_r($b));
+ "\nmessage: ".$msg, LOGGER_DEBUG."\nOriginal post: ".print_r($b, true)."\nPost Data: ".print_r($postdata, true));
if ($result->error) {
logger('Send to StatusNet failed: "' . $result->error . '"');
}
}
+ if ($tempfile != "")
+ unlink($tempfile);
}
}
@@ -527,6 +709,7 @@ function statusnet_plugin_admin_post(&$a){
$apiurl=trim($_POST['apiurl'][$id]);
$secret=trim($_POST['secret'][$id]);
$key=trim($_POST['key'][$id]);
+ $applicationname = ((x($_POST, 'applicationname')) ? notags(trim($_POST['applicationname'][$id])):'');
if ($sitename!="" &&
$apiurl!="" &&
$secret!="" &&
@@ -537,7 +720,8 @@ function statusnet_plugin_admin_post(&$a){
'sitename' => $sitename,
'apiurl' => $apiurl,
'consumersecret' => $secret,
- 'consumerkey' => $key
+ 'consumerkey' => $key,
+ 'applicationname' => $applicationname
);
}
}
@@ -557,6 +741,7 @@ function statusnet_plugin_admin(&$a, &$o){
'apiurl' => Array("apiurl[$id]", "Api url", $s['apiurl'], ""),
'secret' => Array("secret[$id]", "Secret", $s['consumersecret'], ""),
'key' => Array("key[$id]", "Key", $s['consumerkey'], ""),
+ 'applicationname' => Array("applicationname[$id]", "Application name", $s['applicationname'], ""),
'delete' => Array("delete[$id]", "Delete", False , "Check to delete this preset"),
);
}
@@ -568,16 +753,126 @@ function statusnet_plugin_admin(&$a, &$o){
'apiurl' => Array("apiurl[$id]", t("API URL"), "", ""),
'secret' => Array("secret[$id]", t("Consumer Secret"), "", ""),
'key' => Array("key[$id]", t("Consumer Key"), "", ""),
+ 'applicationname' => Array("applicationname[$id]", t("Application name"), "", ""),
);
-
- $t = file_get_contents( dirname(__file__). "/admin.tpl" );
+ $t = get_markup_template( "admin.tpl", "addon/statusnet/" );
$o = replace_macros($t, array(
'$submit' => t('Submit'),
-
'$sites' => $sitesform,
-
));
-
-
}
+
+function statusnet_cron($a,$b) {
+ $last = get_config('statusnet','last_poll');
+
+ $poll_interval = intval(get_config('statusnet','poll_interval'));
+ if(! $poll_interval)
+ $poll_interval = STATUSNET_DEFAULT_POLL_INTERVAL;
+
+ if($last) {
+ $next = $last + ($poll_interval * 60);
+ if($next > time()) {
+ logger('statusnet: poll intervall not reached');
+ return;
+ }
+ }
+ logger('statusnet: cron_start');
+
+ $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() ");
+ if(count($r)) {
+ foreach($r as $rr) {
+ logger('statusnet: fetching for user '.$rr['uid']);
+ statusnet_fetchtimeline($a, $rr['uid']);
+ }
+ }
+
+ logger('statusnet: cron_end');
+
+ set_config('statusnet','last_poll', time());
+}
+
+function statusnet_fetchtimeline($a, $uid) {
+ $ckey = get_pconfig($uid, 'statusnet', 'consumerkey');
+ $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
+ $api = get_pconfig($uid, 'statusnet', 'baseapi');
+ $otoken = get_pconfig($uid, 'statusnet', 'oauthtoken');
+ $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+ $lastid = get_pconfig($uid, 'statusnet', 'lastid');
+
+ // get the application name for the SN app
+ // 1st try personal config, then system config and fallback to the
+ // hostname of the node if neither one is set.
+ $application_name = get_pconfig( $uid, 'statusnet', 'application_name');
+ if ($application_name == "")
+ $application_name = get_config('statusnet', 'application_name');
+ if ($application_name == "")
+ $application_name = $a->get_hostname();
+
+ $connection = new StatusNetOAuth($api, $ckey,$csecret,$otoken,$osecret);
+
+ $parameters = array("exclude_replies" => true, "trim_user" => true, "contributor_details" => false, "include_rts" => false);
+
+ $first_time = ($lastid == "");
+
+ if ($lastid <> "")
+ $parameters["since_id"] = $lastid;
+
+ $items = $connection->get('statuses/user_timeline', $parameters);
+
+ if (!is_array($items))
+ return;
+
+ $posts = array_reverse($items);
+
+ if (count($posts)) {
+ foreach ($posts as $post) {
+ if ($post->id > $lastid)
+ $lastid = $post->id;
+
+ if ($first_time)
+ continue;
+
+ if (is_object($post->retweeted_status))
+ continue;
+
+ if ($post->in_reply_to_status_id != "")
+ continue;
+
+ if (!strpos($post->source, $application_name)) {
+ $_SESSION["authenticated"] = true;
+ $_SESSION["uid"] = $uid;
+
+ $_REQUEST["type"] = "wall";
+ $_REQUEST["api_source"] = true;
+ $_REQUEST["profile_uid"] = $uid;
+ $_REQUEST["source"] = "StatusNet";
+
+ //$_REQUEST["date"] = $post->created_at;
+
+ $_REQUEST["body"] = $post->text;
+ if (is_string($post->place->name))
+ $_REQUEST["location"] = $post->place->name;
+
+ if (is_string($post->place->full_name))
+ $_REQUEST["location"] = $post->place->full_name;
+
+ if (is_array($post->geo->coordinates))
+ $_REQUEST["coord"] = $post->geo->coordinates[0]." ".$post->geo->coordinates[1];
+
+ if (is_array($post->coordinates->coordinates))
+ $_REQUEST["coord"] = $post->coordinates->coordinates[1]." ".$post->coordinates->coordinates[0];
+
+ //print_r($_REQUEST);
+ if ($_REQUEST["body"] != "") {
+ logger('statusnet: posting for user '.$uid);
+
+ require_once('mod/item.php');
+ item_post($a);
+ }
+ }
+ }
+ }
+ set_pconfig($uid, 'statusnet', 'lastid', $lastid);
+}
+
diff --git a/statusnet/admin.tpl b/statusnet/view/admin.tpl
old mode 100755
new mode 100644
similarity index 88%
rename from statusnet/admin.tpl
rename to statusnet/view/admin.tpl
index b40adf35a..686a4c792
--- a/statusnet/admin.tpl
+++ b/statusnet/view/admin.tpl
@@ -3,6 +3,7 @@
{{ inc field_input.tpl with $field=$s.apiurl }}{{ endinc }}
{{ inc field_input.tpl with $field=$s.secret }}{{ endinc }}
{{ inc field_input.tpl with $field=$s.key }}{{ endinc }}
+ {{ inc field_input.tpl with $field=$s.applicationname }}{{ endinc }}
{{ if $s.delete }}
{{ inc field_checkbox.tpl with $field=$s.delete }}{{ endinc }}
diff --git a/statusnet/view/smarty3/admin.tpl b/statusnet/view/smarty3/admin.tpl
new file mode 100644
index 000000000..f8d14c696
--- /dev/null
+++ b/statusnet/view/smarty3/admin.tpl
@@ -0,0 +1,17 @@
+{{foreach $sites as $s}}
+ {{include file="field_input.tpl" field=$s.sitename}}
+ {{include file="field_input.tpl" field=$s.apiurl}}
+ {{include file="field_input.tpl" field=$s.secret}}
+ {{include file="field_input.tpl" field=$s.key}}
+ {{include file="field_input.tpl" field=$s.applicationname}}
+ {{if $s.delete}}
+ {{include file="field_checkbox.tpl" field=$s.delete}}
+
+ {{else}}
+
Fill this form to add a new site
+ {{/if}}
+
+{{/foreach}}
+
+
+
diff --git a/tumblr.tgz b/tumblr.tgz
index fe0389554..b4f6ff9b7 100755
Binary files a/tumblr.tgz and b/tumblr.tgz differ
diff --git a/tumblr/README b/tumblr/README
new file mode 100644
index 000000000..62d7fd045
--- /dev/null
+++ b/tumblr/README
@@ -0,0 +1,9 @@
+Define in your .htconfig.php:
+$a->config['tumblr']['consumer_key'] = "your-consumer-key";
+$a->config['tumblr']['consumer_secret'] = "your-consumer-secret";
+
+You can get it here:
+http://www.tumblr.com/oauth/apps
+
+Tumblr-OAuth-Library:
+https://groups.google.com/d/msg/tumblr-api/g6SeIBWvsnE/gnWqT9jFSlEJ
diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php
index eeb51348b..4bbae8e6c 100755
--- a/tumblr/tumblr.php
+++ b/tumblr/tumblr.php
@@ -7,6 +7,9 @@
* Author: Mike Macgirvin
*/
+require_once('library/OAuth1.php');
+require_once('addon/tumblr/tumblroauth/tumblroauth.php');
+
function tumblr_install() {
register_hook('post_local', 'addon/tumblr/tumblr.php', 'tumblr_post_local');
register_hook('notifier_normal', 'addon/tumblr/tumblr.php', 'tumblr_send');
@@ -23,6 +26,125 @@ function tumblr_uninstall() {
unregister_hook('connector_settings_post', 'addon/tumblr/tumblr.php', 'tumblr_settings_post');
}
+function tumblr_module() {}
+
+function tumblr_content(&$a) {
+
+ if(! local_user()) {
+ notice( t('Permission denied.') . EOL);
+ return '';
+ }
+
+ if (isset($a->argv[1]))
+ switch ($a->argv[1]) {
+ case "connect":
+ $o = tumblr_connect($a);
+ break;
+ case "callback":
+ $o = tumblr_callback($a);
+ break;
+ default:
+ $o = print_r($a->argv, true);
+ break;
+ }
+ else
+ $o = tumblr_connect($a);
+
+ return $o;
+}
+
+function tumblr_connect($a) {
+ // Start a session. This is necessary to hold on to a few keys the callback script will also need
+ session_start();
+
+ // Include the TumblrOAuth library
+ //require_once('addon/tumblr/tumblroauth/tumblroauth.php');
+
+ // Define the needed keys
+ $consumer_key = get_config('tumblr','consumer_key');
+ $consumer_secret = get_config('tumblr','consumer_secret');
+
+ // The callback URL is the script that gets called after the user authenticates with tumblr
+ // In this example, it would be the included callback.php
+ $callback_url = $a->get_baseurl()."/tumblr/callback";
+
+ // Let's begin. First we need a Request Token. The request token is required to send the user
+ // to Tumblr's login page.
+
+ // Create a new instance of the TumblrOAuth library. For this step, all we need to give the library is our
+ // Consumer Key and Consumer Secret
+ $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret);
+
+ // Ask Tumblr for a Request Token. Specify the Callback URL here too (although this should be optional)
+ $request_token = $tum_oauth->getRequestToken($callback_url);
+
+ // Store the request token and Request Token Secret as out callback.php script will need this
+ $_SESSION['request_token'] = $token = $request_token['oauth_token'];
+ $_SESSION['request_token_secret'] = $request_token['oauth_token_secret'];
+
+ // Check the HTTP Code. It should be a 200 (OK), if it's anything else then something didn't work.
+ switch ($tum_oauth->http_code) {
+ case 200:
+ // Ask Tumblr to give us a special address to their login page
+ $url = $tum_oauth->getAuthorizeURL($token);
+
+ // Redirect the user to the login URL given to us by Tumblr
+ header('Location: ' . $url);
+
+ // That's it for our side. The user is sent to a Tumblr Login page and
+ // asked to authroize our app. After that, Tumblr sends the user back to
+ // our Callback URL (callback.php) along with some information we need to get
+ // an access token.
+
+ break;
+ default:
+ // Give an error message
+ $o = 'Could not connect to Tumblr. Refresh the page or try again later.';
+ }
+ return($o);
+}
+
+function tumblr_callback($a) {
+
+ // Start a session, load the library
+ session_start();
+ //require_once('addon/tumblr/tumblroauth/tumblroauth.php');
+
+ // Define the needed keys
+ $consumer_key = get_config('tumblr','consumer_key');
+ $consumer_secret = get_config('tumblr','consumer_secret');
+
+ // Once the user approves your app at Tumblr, they are sent back to this script.
+ // This script is passed two parameters in the URL, oauth_token (our Request Token)
+ // and oauth_verifier (Key that we need to get Access Token).
+ // We'll also need out Request Token Secret, which we stored in a session.
+
+ // Create instance of TumblrOAuth.
+ // It'll need our Consumer Key and Secret as well as our Request Token and Secret
+ $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $_SESSION['request_token'], $_SESSION['request_token_secret']);
+
+ // Ok, let's get an Access Token. We'll need to pass along our oauth_verifier which was given to us in the URL.
+ $access_token = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier']);
+
+ // We're done with the Request Token and Secret so let's remove those.
+ unset($_SESSION['request_token']);
+ unset($_SESSION['request_token_secret']);
+
+ // Make sure nothing went wrong.
+ if (200 == $tum_oauth->http_code) {
+ // good to go
+ } else {
+ return('Unable to authenticate');
+ }
+
+ // What's next? Now that we have an Access Token and Secret, we can make an API call.
+ set_pconfig(local_user(), "tumblr", "oauth_token", $access_token['oauth_token']);
+ set_pconfig(local_user(), "tumblr", "oauth_token_secret", $access_token['oauth_token_secret']);
+
+ $o = t("You are now authenticated to tumblr.");
+ $o .= ' '.t("return to the connector page").'';
+ return($o);
+}
function tumblr_jot_nets(&$a,&$b) {
if(! local_user())
@@ -57,34 +179,55 @@ function tumblr_settings(&$a,&$s) {
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
- $tmbl_username = get_pconfig(local_user(), 'tumblr', 'tumblr_username');
- $tmbl_password = get_pconfig(local_user(), 'tumblr', 'tumblr_password');
-
-
/* Add some HTML to the existing form */
$s .= '