From 516c678827e1f3e2435d8b0876f33b07f0d5bc85 Mon Sep 17 00:00:00 2001 From: ike Date: Sun, 19 Feb 2012 19:48:09 +0100 Subject: [PATCH 1/3] First commit: Addon for shortening long content and "show more" link. --- showmore.tgz | Bin 0 -> 1872 bytes showmore/README | 3 ++ showmore/showmore.css | 19 +++++++ showmore/showmore.php | 121 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 showmore.tgz create mode 100755 showmore/README create mode 100755 showmore/showmore.css create mode 100755 showmore/showmore.php diff --git a/showmore.tgz b/showmore.tgz new file mode 100644 index 0000000000000000000000000000000000000000..70c4beef90ce33de6c73724a4131aa0bed6202a6 GIT binary patch literal 1872 zcmV-W2e0@aiwFR2FgQ;D1MOICZ`-yO?$`KNoM}cS7q(=_ZZp`i_mX(H1)8>K+!YsV zVbBt73z12Iq~Zj_{`);7B{_U^&v>Z*yRVA+?{vF8&HvrrzW)E5 zQTw(Cd@CU{nlxcEK^d7P`8@nqJD4Y&s6Hfgt_HP(bsVW>AG+;!dWBzCL@Z*~QatTL z$4vcRy8*uDB9hzS+prJd$ZWQXmEKkne3=XSrC>y5xFwe3{nbwYKN{QhpDxp{e8&Ct zuY0|ty#BkI0c`zu_Vxc~jN|Vy-nHPxiyFLuw`4{8U|NDR-4fu`DVC9lQx$X8hZCM8 zB$X6WE|t{FzhG}*mO6f0fB!L4*hTc=EDo0hS>qSJz`w`nydTn75Nt0}f=x#3M|7m+ zi!mdTMv$eP!Q1nnKfzq^6@pw)I3wXA7MC%DpicN=JUGL4y_%;bMG5Scu10ICaLfmjoJYQTxEg{a5=!rim(^Y1W0wAP`RX3 z>1JFlu^6#e2gzYgAtVe|1gpkK<|iR8zW^48)Re|SowP=J&#&%Mt&$}rk^2SwA-Kn; z#TPUgI-64*P}eCPI*MMY0DD6RmV(ZQj_Yfj1yxgByP3e$@ZI1pzu`vLcO87Sh+;By zFq52M(+> zfbYR|p${(PP(vqwa7+r+k(ls(W(beMHNs|}j*#7}LsO!-y>{C*21x6}D87U+AyT3f z^8mDFh=1XX+`&d{*&VsygYsObdyH*jr z*~mFC=VEIOF?`fzY@4$32C#aVeHB$=mS$?#8AY}jm(Tc>0}St!9by>S4CgyKkE)^f zT?n@9&OI6?l%T!G0nSxqb{M_WS`)V1*ptjS+g@fs=Ew?QLXm|_(1IkyDH98Lq!Ub+ zd$VG;?6(RO=A-duLYGF>Xk+1hrr)1&woNWG1V*{GRx`WmRCO;VZz)_%?>=E;iB0Bn zGwU|+n=z?WHwbp>d$U`2ii-G%9Y#Q}@N$s4xd=4T;Wd95M-!5vrG!=MFi%(2DMy@~^zg-IM<3>}_Qc9L*Oz0aGBF91Jd zxL~J5<=nf)Zdt7bkyBk?rsz5~_im;;rkJ0zk$b1Tcbm#Mqt<<8Bucou3#QBjed%Bl zBr#Hv3AULjGRJ&rn8eSgSF)B_o7VX4C&@@ zV{K_5oA$S-4|UnzV~G|uBn32)v;xu1A$ku(bQ^gQ)*~Kj;-YIfeRp=s!)!&F@{B#W zgiSf#XjEL%PfLvDc}hY}%yWWg5AyB$`Zjg>&FQ<7$-m!^L1zfO|M=6J*C*h#g5Xp4 zBnVC?r=WueJ--bTEOQy_bRkI)jNdxo@^v43heh zifqsNgHye=?AEnzzGMHY7pv)Fk@P)akc{nx^OTq(?I&oq zM}#2PUKL&^P8GQcg(i(A + * based upon NSFW from Mike Macgirvin + * + */ + +function showmore_install() { + register_hook('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body'); + register_hook('plugin_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings'); + register_hook('plugin_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); +} + +function showmore_uninstall() { + unregister_hook('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body'); + unregister_hook('plugin_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings'); + unregister_hook('plugin_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); +} + +function showmore_addon_settings(&$a,&$s) { + + if(! local_user()) + return; + + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= ''."\r\n"; + + $enable_checked = (intval(get_pconfig(local_user(),'showmore','disable')) ? '' : ' checked="checked"'); + $chars = get_pconfig(local_user(),'showmore','chars'); + if(!$chars) + $chars = '1100'; + + $s .= '
'; + $s .= '

' . t('"Show more" Settings').'

'; + $s .= '
'; + + $s .= ''; + $s .= ''; + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + $s .= '
'; +// $s .= '
' . t('Use /expression/ to provide regular expressions') . '
'; + + return; +} + +function showmore_addon_settings_post(&$a,&$b) { + + if(! local_user()) + return; + + if($_POST['showmore-submit']) { + set_pconfig(local_user(),'showmore','chars',trim($_POST['showmore-chars'])); + $enable = ((x($_POST,'showmore-enable')) ? intval($_POST['showmore-enable']) : 0); + $disable = 1-$enable; + set_pconfig(local_user(),'showmore','disable', $disable); + info( t('Show More Settings saved.') . EOL); + } +} + +function showmore_prepare_body(&$a,&$b) { + + $words = null; + if(get_pconfig(local_user(),'showmore','disable')) + return; + + $chars = (int)get_pconfig(local_user(),'showmore','chars'); + if(!$chars) + $chars = 1100; + + if (strlen(strip_tags(trim($b['html']))) > $chars) { + $found = true; + $shortened = trim(showmore_cutitem($b['html'], $chars))."..."; + } + + if($found) { + $rnd = random_string(8); + $b['html'] = ''.$shortened." ". + ''.sprintf(t('Show More')).''. + ''; + } +} + +function showmore_cutitem($text, $limit) { + $text = trim($text); + + $text = mb_convert_encoding($text, 'HTML-ENTITIES', "UTF-8"); + + $text = substr($text, 0, $limit); + + $pos1 = strrpos($text, "<"); + $pos2 = strrpos($text, ">"); + $pos3 = strrpos($text, "&"); + $pos4 = strrpos($text, ";"); + + if ($pos1 > $pos3) { + if ($pos1 > $pos2) + $text = substr($text, 0, $pos1); + } else { + if ($pos3 > $pos4) + $text = substr($text, 0, $pos3); + } + + $doc = new DOMDocument(); + $doc->preserveWhiteSpace = false; + + $doctype = ''; + @$doc->loadHTML($doctype."".$text.""); + + $text = $doc->saveHTML(); + $text = str_replace(array("", "", $doctype), array("", "", ""), $text); + + return($text); +} From 5c88bcb1b4de7adcc4735485647e216bba9dcd60 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 20 Feb 2012 11:14:33 +0100 Subject: [PATCH 2/3] Workaround for posts from pages. Not nice - but working :) --- facebook/facebook.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/facebook/facebook.php b/facebook/facebook.php index f155d397..39013402 100755 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -731,7 +731,7 @@ function facebook_post_hook(&$a,&$b) { logger('facebook: postvars: ' . print_r($postvars,true)); // "test_mode" prevents anything from actually being posted. - // Otherwise, let's do it. + // Otherwise, let's do it. if(! get_config('facebook','test_mode')) { $x = post_url($url, $postvars); @@ -952,11 +952,13 @@ function fb_consume_stream($uid,$j,$wall = false) { // don't store post if we don't have a contact if(! x($datarray,'contact-id')) { - logger('no contact: post ignored'); - continue; + // Test: Workaround for page entries + $datarray['contact-id'] = $self[0]['id']; + //logger('no contact: post ignored'); + //continue; } - $datarray['verb'] = ACTIVITY_POST; + $datarray['verb'] = ACTIVITY_POST; if($wall) { $datarray['owner-name'] = $self[0]['name']; $datarray['owner-link'] = $self[0]['url']; From edd22529b0dc443e734bb8b77789cca27d282c55 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 21 Feb 2012 19:26:25 +0100 Subject: [PATCH 3/3] Updated .tgz file --- showmore.tgz | Bin 1872 -> 1894 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/showmore.tgz b/showmore.tgz index 70c4beef90ce33de6c73724a4131aa0bed6202a6..ef095853da395fcca0a0aee3f56d0a3bd6f08124 100644 GIT binary patch literal 1894 zcmV-s2buUEiwFSC;X_XV1MOIQZ`(K$@4xYyfLaY7rRK4MHCKu)xdIjk zAQlTQ@e!ghz632m6(`)<#;;k`QJP4Vg<f3y3Bw^HbOSyn z{(|OA@c`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