From b0a59bd21a697b88a491fa454a1856e3f746d92c Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Feb 2012 20:54:02 -0800 Subject: [PATCH] some small improvements to ljpost --- ljpost.tgz | Bin 0 -> 2502 bytes ljpost/ljpost.css | 4 +- ljpost/ljpost.php | 190 +++++++++++++++++++++++----------------------- 3 files changed, 97 insertions(+), 97 deletions(-) create mode 100644 ljpost.tgz mode change 100644 => 100755 ljpost/ljpost.php diff --git a/ljpost.tgz b/ljpost.tgz new file mode 100644 index 0000000000000000000000000000000000000000..2af2a685aa0c8d000186514368467a2b70eb9c60 GIT binary patch literal 2502 zcmV;%2|4y3iwFR(txZn=1MOLDbJ|D}_E+;OCR$$vDL{aY?ZSX7oAo7|axT8axw9^^Tyt`QtQETrxsR49y(%x&e zk4{>xqrFD^xOIHg%d>4A8pT_6CZUal+HSqMJG6#ka~!%Ss09nhb;ju7+O9WstC2(eC<*W$W4=5QCc=UsCn&NK(9bwdS+nayA*2Um)(KK^)<*T&a{)VuYAN0RlYs zaNyl>0jP(@7@P|#kI1;3U0IbHnN?G%A|()?KG)0kKLXje;6>Cg?7HLuIi4LwJwuk& z8rZZ3HZ}TP;?H8J+shf2P{UwhARnrK&yWtlzCH9X6Hw2nSchlOF9yD*fvi3<6Tyt? zh?dQQGr_E|m0b&z>YGB>uZ3<`!6DrqF{AI~cMA>;*F_)}MRe)G$$~N022L3?v&R@k z0h(jv*gl%t_gHXBsURS@M?P^dKVP^x?OLBLyD=wp>P@iinzzEh9`Wx%w%0RKK?agW zrFcOtCyER-3Gt|Ba4P~73zeZA;W%XV3v6N)B@8TN3rqt|u}kcp0p*Tan++PjgunPk zy4$yGd$2br4nyoy*tJbzS0lbL5tQJukT7pX>9&M>-QChdES0gx!&Tut8J=P(g!Eu% z$!mF&BCRNrfqq({qgcfpCl&BpB50M|ZP^p_Xt(vN0P4pv$}K z50@%j@dAo2#3dTRag(|($|bmp-`Wra-y15$6zAlSM-HTBuCx1`lzNe%jP)!hh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m$&k|03FzO`2L%F@%#)j z9{>K|XdJbh^80_|+k>HgGxUXyr`|BAJ$$Au8*(2XiLY}UL!#twLkI# z8xqdLBMQkeCoY|IP^;0HE#Pr#hhyT`pr`MkCLe;ZS77QrP+pz9A_Xesg+D4yzV-Qi zjjb)&{@0Guq)C$|O`0@m(xgd~CQX_&Y0{)glO|1?G-=YLNs}f`nlx$Bq)C$|O`0@m Q(xeIKPsmd({s2$_0I*!jT>t<8 literal 0 HcmV?d00001 diff --git a/ljpost/ljpost.css b/ljpost/ljpost.css index 50a3d4a0..e0494c5c 100755 --- a/ljpost/ljpost.css +++ b/ljpost/ljpost.css @@ -1,11 +1,11 @@ -#ljpost-enable-label, #ljpost-username-label, #ljpost-password-label, #ljpost-blog-label, #ljpost-bydefault-label { +#ljpost-enable-label, #ljpost-username-label, #ljpost-password-label, #ljpost-bydefault-label { float: left; width: 200px; margin-top: 10px; } -#ljpost-checkbox, #ljpost-username, #ljpost-password, #ljpost-blog, #ljpost-bydefault { +#ljpost-checkbox, #ljpost-username, #ljpost-password, #ljpost-bydefault { float: left; margin-top: 10px; } diff --git a/ljpost/ljpost.php b/ljpost/ljpost.php old mode 100644 new mode 100755 index 3b2bbe8b..1ea8dfe5 --- a/ljpost/ljpost.php +++ b/ljpost/ljpost.php @@ -1,43 +1,41 @@ -* Author: Tony Baldwin -*/ + * Name: LiveJournal Post Connector + * Description: Post to LiveJournal + * Version: 1.0 + * Author: Tony Baldwin + * Author: Michael Johnston + */ function ljpost_install() { - register_hook('post_local', 'addon/ljpost/ljpost.php', 'ljpost_post_local'); - register_hook('notifier_normal', 'addon/ljpost/ljpost.php', 'ljpost_send'); - register_hook('jot_networks', 'addon/ljpost/ljpost.php', 'ljpost_jot_nets'); - register_hook('connector_settings', 'addon/ljpost/ljpost.php', 'ljpost_settings'); + register_hook('post_local', 'addon/ljpost/ljpost.php', 'ljpost_post_local'); + register_hook('notifier_normal', 'addon/ljpost/ljpost.php', 'ljpost_send'); + register_hook('jot_networks', 'addon/ljpost/ljpost.php', 'ljpost_jot_nets'); + register_hook('connector_settings', 'addon/ljpost/ljpost.php', 'ljpost_settings'); register_hook('connector_settings_post', 'addon/ljpost/ljpost.php', 'ljpost_settings_post'); } function ljpost_uninstall() { - unregister_hook('post_local', 'addon/ljpost/ljpost.php', 'ljpost_post_local'); - unregister_hook('notifier_normal', 'addon/ljpost/ljpost.php', 'ljpost_send'); - unregister_hook('jot_networks', 'addon/ljpost/ljpost.php', 'ljpost_jot_nets'); - unregister_hook('connector_settings', 'addon/ljpost/ljpost.php', 'ljpost_settings'); + unregister_hook('post_local', 'addon/ljpost/ljpost.php', 'ljpost_post_local'); + unregister_hook('notifier_normal', 'addon/ljpost/ljpost.php', 'ljpost_send'); + unregister_hook('jot_networks', 'addon/ljpost/ljpost.php', 'ljpost_jot_nets'); + unregister_hook('connector_settings', 'addon/ljpost/ljpost.php', 'ljpost_settings'); unregister_hook('connector_settings_post', 'addon/ljpost/ljpost.php', 'ljpost_settings_post'); } - - function ljpost_jot_nets(&$a,&$b) { if(! local_user()) return; $lj_post = get_pconfig(local_user(),'ljpost','post'); if(intval($lj_post) == 1) { - $wp_defpost = get_pconfig(local_user(),'ljpost','post_by_default'); - $selected = ((intval($wp_defpost) == 1) ? ' checked="checked" ' : ''); + $lj_defpost = get_pconfig(local_user(),'ljpost','post_by_default'); + $selected = ((intval($lj_defpost) == 1) ? ' checked="checked" ' : ''); $b .= '
' - . t('Post to Livejournal') . '
'; + . t('Post to LiveJournal') . ''; } } @@ -49,7 +47,7 @@ function ljpost_settings(&$a,&$s) { /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; /* Get the current state of our config variables */ @@ -61,9 +59,8 @@ function ljpost_settings(&$a,&$s) { $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); -$lj_username = get_pconfig(local_user(), 'ljpost', 'lj_username'); -$lj_password = get_pconfig(local_user(), 'ljpost', 'lj_password'); -$lj_blog = get_pconfig(local_user(), 'ljpost', 'lj_blog'); + $lj_username = get_pconfig(local_user(), 'ljpost', 'lj_username'); + $lj_password = get_pconfig(local_user(), 'ljpost', 'lj_password'); /* Add some HTML to the existing form */ @@ -85,14 +82,9 @@ $lj_blog = get_pconfig(local_user(), 'ljpost', 'lj_blog'); $s .= ''; $s .= '
'; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - $s .= '
'; $s .= ''; - $s .= ''; + $s .= ''; $s .= '
'; /* provide a submit button */ @@ -104,37 +96,36 @@ $lj_blog = get_pconfig(local_user(), 'ljpost', 'lj_blog'); function ljpost_settings_post(&$a,&$b) { -if(x($_POST,'ljpost-submit')) { + if(x($_POST,'ljpost-submit')) { -set_pconfig(local_user(),'ljpost','post',intval($_POST['ljpost'])); -set_pconfig(local_user(),'ljpost','post_by_default',intval($_POST['lj_bydefault'])); -set_pconfig(local_user(),'ljpost','lj_username',trim($_POST['lj_username'])); -set_pconfig(local_user(),'ljpost','lj_password',trim($_POST['lj_password'])); -set_pconfig(local_user(),'ljpost','lj_blog',trim($_POST['lj_blog'])); + set_pconfig(local_user(),'ljpost','post',intval($_POST['ljpost'])); + set_pconfig(local_user(),'ljpost','post_by_default',intval($_POST['lj_bydefault'])); + set_pconfig(local_user(),'ljpost','lj_username',trim($_POST['lj_username'])); + set_pconfig(local_user(),'ljpost','lj_password',trim($_POST['lj_password'])); -} + } } function ljpost_post_local(&$a,&$b) { -// This can probably be changed to allow editing by pointing to a different API endpoint + // This can probably be changed to allow editing by pointing to a different API endpoint -if($b['edit']) -return; + if($b['edit']) + return; -if((! local_user()) || (local_user() != $b['uid'])) -return; + if((! local_user()) || (local_user() != $b['uid'])) + return; -if($b['private'] || $b['parent']) -return; + if($b['private'] || $b['parent']) + return; - $lj_post = intval(get_pconfig(local_user(),'ljpost','post')); + $lj_post = intval(get_pconfig(local_user(),'ljpost','post')); -$lj_enable = (($lj_post && x($_REQUEST,'ljpost_enable')) ? intval($_REQUEST['ljpost_enable']) : 0); + $lj_enable = (($lj_post && x($_REQUEST,'ljpost_enable')) ? intval($_REQUEST['ljpost_enable']) : 0); -if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'ljpost','post_by_default'))) -$lj_enable = 1; + if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'ljpost','post_by_default'))) + $lj_enable = 1; if(! $lj_enable) return; @@ -158,59 +149,68 @@ function ljpost_send(&$a,&$b) { if($b['parent'] != $b['id']) return; - -$lj_username = get_pconfig($b['uid'],'ljpost','lj_username'); -$lj_password = get_pconfig($b['uid'],'ljpost','lj_password'); -$lj_blog = get_pconfig($b['uid'],'ljpost','lj_blog'); - -if($lj_username && $lj_password && $lj_blog) { - -require_once('include/bbcode.php'); - -$title = '' . (($b['title']) ? $b['title'] : t('Post from Friendica')) . ''; -$post = $title . bbcode($b['body']); -$post = xmlify($post); - -$year = date('Y'); -$month = date('F'); -$day = date('l'); -$hour = date('H'); -$min = date('i'); - -$xml = <<< EOT - - -LJ.XMLRPC.postevent - - -year$year -mon$month -day$day -hour$hour -min$min -usejournal$lj_blog -event$post -username$lj_username -password$lj_password -subjectfriendica post -lineendingsunix -ver1 -props - -useragentFriendica -taglistfriendica,crosspost - - - + // LiveJournal post in the LJ user's timezone. + // Hopefully the person's Friendica account + // will be set to the same thing. + + $tz = 'UTC'; + + $x = q("select timezone from user where uid = %d limit 1", + intval($b['uid']) + ); + if($x && strlen($x[0]['timezone'])) + $tz = $x[0]['timezone']; + + $lj_username = get_pconfig($b['uid'],'ljpost','lj_username'); + $lj_password = get_pconfig($b['uid'],'ljpost','lj_password'); + $lj_blog = 'http://www.livejournal.com/interface/xmlrpc'; + + if($lj_username && $lj_password && $lj_blog) { + + require_once('include/bbcode.php'); + require_once('include/datetime.php'); + + $title = (($b['title']) ? $b['title'] : t('[no subject]')); + $post = bbcode($b['body']); + $post = xmlify($post); + + $date = datetime_convert('UTC',$tz,$b['created'],'Y-m-d H:i:s'); + $year = intval(substr($date,0,4)); + $mon = intval(substr($date,5,2)); + $day = intval(substr($date,8,2)); + $hour = intval(substr($date,11,2)); + $min = intval(substr($date,14,2)); + + $xml = <<< EOT + + + LJ.XMLRPC.postevent + + + + username$lj_username + password$lj_password + event$post + subject$title + lineendingsunix + year$year + mon$mon + day$day + hour$hour + min$min + + + EOT; -logger('ljpost: data: ' . $xml, LOGGER_DATA); + logger('ljpost: data: ' . $xml, LOGGER_DATA); -if($lj_blog !== 'test') -$x = post_url($lj_blog,$xml); -logger('posted to livejournal: ' . ($x) ? $x : ''); + if($lj_blog !== 'test') + $x = post_url($lj_blog,$xml); + logger('posted to livejournal: ' . ($x) ? $x : '', LOGGER_DEBUG); } } + -- 2.39.5