sharepopup: implement assigning labels while sharing

master
Andrew Dolgov 12 years ago
parent 4021d61ada
commit 1b4d1a6b44

@ -439,7 +439,7 @@ class API extends Handler {
$url = db_escape_string(strip_tags($_REQUEST["url"]));
$content = db_escape_string(strip_tags($_REQUEST["content"]));
if (create_published_article($this->link, $title, $url, $content, $_SESSION["uid"])) {
if (create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) {
print $this->wrap(self::STATUS_OK, array("status" => 'OK'));
} else {
print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed'));

@ -383,6 +383,7 @@ class Handler_Public extends Handler {
<title>Tiny Tiny RSS</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
<script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
<script type=\"text/javascript\" src=\"lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls\"></script>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
</head>
<body id='sharepopup'>";
@ -396,8 +397,10 @@ class Handler_Public extends Handler {
$title = db_escape_string(strip_tags($_REQUEST["title"]));
$url = db_escape_string(strip_tags($_REQUEST["url"]));
$content = db_escape_string(strip_tags($_REQUEST["content"]));
$labels = db_escape_string(strip_tags($_REQUEST["labels"]));
create_published_article($this->link, $title, $url, $content, $_SESSION["uid"]);
create_published_article($this->link, $title, $url, $content, $labels,
$_SESSION["uid"]);
print "<script type='text/javascript'>";
print "window.close();";
@ -424,9 +427,23 @@ class Handler_Public extends Handler {
<td><input name='url' value="<?php echo $url ?>"></td></tr>
<tr><td align='right'><?php echo __("Content:") ?></td>
<td><input name='content' value=""></td></tr>
<tr><td align='right'><?php echo __("Labels:") ?></td>
<td><input name='labels' id="labels_value"
placeholder='Alpha, Beta, Gamma' value="">
</td></tr>
<tr><td>
<div class="autocomplete" id="labels_choices"
style="display : block"></div></td></tr>
<script type='text/javascript'>document.forms[0].title.focus();</script>
<script type='text/javascript'>
new Ajax.Autocompleter('labels_value', 'labels_choices',
"backend.php?op=rpc&method=completeLabels",
{ tokens: ',', paramName: "search" });
</script>
<tr><td colspan='2'>
<div style='float : right' class='insensitive-small'>
<?php echo __("Shared article will appear in the Published feed.") ?>

@ -1479,7 +1479,7 @@ class Pref_Feeds extends Handler_Protected {
print "<p>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</p>";
$bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".SELF_URL_PATH."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=200')){l.href=g;}}a();})()");
$bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".SELF_URL_PATH."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()");
print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Share with Tiny Tiny RSS'). "</a>";

@ -2,7 +2,7 @@
class RPC extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "sharepopup");
$csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "completelabels");
return array_search($method, $csrf_ignored) !== false;
}
@ -426,6 +426,23 @@ class RPC extends Handler_Protected {
print json_encode(array("link" => $new_link));
}
function completeLabels() {
$search = db_escape_string($_REQUEST["search"]);
$result = db_query($this->link, "SELECT DISTINCT caption FROM
ttrss_labels2
WHERE owner_uid = '".$_SESSION["uid"]."' AND
LOWER(caption) LIKE LOWER('$search%') ORDER BY caption
LIMIT 5");
print "<ul>";
while ($line = db_fetch_assoc($result)) {
print "<li>" . $line["caption"] . "</li>";
}
print "</ul>";
}
function completeTags() {
$search = db_escape_string($_REQUEST["search"]);

@ -5545,10 +5545,18 @@
}
function create_published_article($link, $title, $url, $content, $owner_uid) {
$guid = sha1($url);
function create_published_article($link, $title, $url, $content, $labels_str,
$owner_uid) {
$guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash
$content_hash = sha1($content);
if ($labels_str != "") {
$labels = explode(",", $labels_str);
} else {
$labels = array();
}
$rc = false;
if (!$title) $title = $url;
@ -5584,6 +5592,12 @@
('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
}
if (count($labels) != 0) {
foreach ($labels as $label) {
label_add_article($link, $ref_id, trim($label), $owner_uid);
}
}
$rc = true;
} else {
@ -5602,6 +5616,12 @@
VALUES
('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
if (count($labels) != 0) {
foreach ($labels as $label) {
label_add_article($link, $ref_id, trim($label), $owner_uid);
}
}
$rc = true;
}
}

@ -151,3 +151,34 @@ body#sharepopup form {
body#sharepopup input {
width : 100%;
}
div.autocomplete {
position : absolute;
width : 250px;
background-color : white;
border :1px solid #778899;
margin : 0px;
padding : 0px;
z-index : 4;
}
div.autocomplete ul {
list-style-type : none;
margin : 0px;
padding : 0px;
font-size : 10px;
}
div.autocomplete ul li.selected {
background-color : #fff7d5;
}
div.autocomplete ul li {
list-style-type : none;
display : block;
margin : 0;
padding : 2px;
height : 32px;
cursor : pointer;
}

Loading…
Cancel
Save