social bookmark API, oexchange enhancements

This commit is contained in:
Friendika 2011-09-20 16:31:45 -07:00
parent deeae7bdb5
commit 1c8e89bd03
2 changed files with 76 additions and 6 deletions

View file

@ -922,3 +922,60 @@ function base64url_decode($s) {
function cc_license() { function cc_license() {
return '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>'; return '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
} }
if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\', $eol = '\n') {
if (is_string($input) && !empty($input)) {
$output = array();
$tmp = preg_split("/".$eol."/",$input);
if (is_array($tmp) && !empty($tmp)) {
while (list($line_num, $line) = each($tmp)) {
if (preg_match("/".$escape.$enclosure."/",$line)) {
while ($strlen = strlen($line)) {
$pos_delimiter = strpos($line,$delimiter);
$pos_enclosure_start = strpos($line,$enclosure);
if (
is_int($pos_delimiter) && is_int($pos_enclosure_start)
&& ($pos_enclosure_start < $pos_delimiter)
) {
$enclosed_str = substr($line,1);
$pos_enclosure_end = strpos($enclosed_str,$enclosure);
$enclosed_str = substr($enclosed_str,0,$pos_enclosure_end);
$output[$line_num][] = $enclosed_str;
$offset = $pos_enclosure_end+3;
} else {
if (empty($pos_delimiter) && empty($pos_enclosure_start)) {
$output[$line_num][] = substr($line,0);
$offset = strlen($line);
} else {
$output[$line_num][] = substr($line,0,$pos_delimiter);
$offset = (
!empty($pos_enclosure_start)
&& ($pos_enclosure_start < $pos_delimiter)
)
?$pos_enclosure_start
:$pos_delimiter+1;
}
}
$line = substr($line,$offset);
}
} else {
$line = preg_split("/".$delimiter."/",$line);
/*
* Validating against pesky extra line breaks creating false rows.
*/
if (is_array($line) && !empty($line[0])) {
$output[$line_num] = $line;
}
}
}
return $output;
} else {
return false;
}
} else {
return false;
}
}
}

View file

@ -3,9 +3,14 @@
require_once('library/HTML5/Parser.php'); require_once('library/HTML5/Parser.php');
require_once('library/HTMLPurifier.auto.php'); require_once('library/HTMLPurifier.auto.php');
function arr_add_hashes(&$item,$k) {
$item = '#' . $item;
}
function parse_url_content(&$a) { function parse_url_content(&$a) {
$text = null; $text = null;
$str_tags = '';
if(x($_GET,'binurl')) if(x($_GET,'binurl'))
$url = trim(hex2bin($_GET['binurl'])); $url = trim(hex2bin($_GET['binurl']));
@ -15,8 +20,16 @@ function parse_url_content(&$a) {
if($_GET['title']) if($_GET['title'])
$title = strip_tags(trim($_GET['title'])); $title = strip_tags(trim($_GET['title']));
if($_GET['desc']) if($_GET['description'])
$text = strip_tags(trim($_GET['desc'])); $text = strip_tags(trim($_GET['description']));
if($_GET['tags']) {
$arr_tags = str_getcsv($_GET['tags']);
if(count($arr_tags)) {
array_walk($arr_tags,'arr_add_hashes');
$str_tags = '<br />' . implode(' ',$arr_tags) . '<br />';
}
}
logger('parse_url: ' . $url); logger('parse_url: ' . $url);
@ -38,7 +51,7 @@ function parse_url_content(&$a) {
$text = '<br /><br /><blockquote>' . $text . '</blockquote><br />'; $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />';
$title = str_replace(array("\r","\n"),array('',''),$title); $title = str_replace(array("\r","\n"),array('',''),$title);
$result = sprintf($template,$url,($title) ? $title : $url,$text); $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
logger('parse_url (unparsed): returns: ' . $result); logger('parse_url (unparsed): returns: ' . $result);
@ -57,7 +70,7 @@ function parse_url_content(&$a) {
logger('parse_url: data: ' . $s, LOGGER_DATA); logger('parse_url: data: ' . $s, LOGGER_DATA);
if(! $s) { if(! $s) {
echo sprintf($template,$url,$url,''); echo sprintf($template,$url,$url,'') . $str_tags;
killme(); killme();
} }
@ -80,7 +93,7 @@ function parse_url_content(&$a) {
$dom = @HTML5_Parser::parse($s); $dom = @HTML5_Parser::parse($s);
if(! $dom) { if(! $dom) {
echo sprintf($template,$url,$url,''); echo sprintf($template,$url,$url,'') . $str_tags;
killme(); killme();
} }
@ -148,7 +161,7 @@ function parse_url_content(&$a) {
$title = str_replace(array("\r","\n"),array('',''),$title); $title = str_replace(array("\r","\n"),array('',''),$title);
$result = sprintf($template,$url,($title) ? $title : $url,$text); $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
logger('parse_url: returns: ' . $result); logger('parse_url: returns: ' . $result);