feed editor: allow manual replacement of feed icons

This commit is contained in:
Andrew Dolgov 2010-01-14 12:47:28 +03:00
parent 6ba506224e
commit 7abf159d61
2 changed files with 95 additions and 12 deletions

View File

@ -2248,18 +2248,59 @@ function feedArchiveRemove() {
} }
} }
function uploadIconHandler(iframe) { function uploadIconHandler(rc) {
try { try {
notify_info("Icon changed!"); switch (rc) {
case 0:
alert("Icon changed, blah blah"); notify_info("Upload complete.");
if (inPreferences()) {
updateFeedList();
} else {
setTimeout('updateFeedList(false, false)', 50);
}
break;
case 1:
notify_error("Upload failed: icon is too big.");
break;
case 2:
notify_error("Upload failed.");
break;
}
} catch (e) { } catch (e) {
exception_error("uploadIconHandler", e); exception_error("uploadIconHandler", e);
} }
} }
function removeFeedIcon(id) {
try {
if (confirm(__("Remove stored feed icon?"))) {
var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id);
debug(query);
notify_progress("Removing feed icon...", true);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
notify_info("Feed icon removed.");
if (inPreferences()) {
updateFeedList();
} else {
setTimeout('updateFeedList(false, false)', 50);
}
} });
}
return false;
} catch (e) {
exception_error("uploadFeedIcon", e);
}
}
function uploadFeedIcon() { function uploadFeedIcon() {
try { try {
@ -2268,12 +2309,15 @@ function uploadFeedIcon() {
if (file.value.length == 0) { if (file.value.length == 0) {
alert(__("Please select an image file to upload.")); alert(__("Please select an image file to upload."));
return false;
} else { } else {
notify_progress("Uploading, please wait...", true); if (confirm(__("Upload new icon for this feed?"))) {
return true; notify_progress("Uploading, please wait...", true);
return true;
}
} }
return false;
} catch (e) { } catch (e) {
exception_error("uploadFeedIcon", e); exception_error("uploadFeedIcon", e);
} }

View File

@ -15,9 +15,45 @@
$quiet = $_REQUEST["quiet"]; $quiet = $_REQUEST["quiet"];
$mode = $_REQUEST["mode"]; $mode = $_REQUEST["mode"];
if ($subop == "removeicon") {
$feed_id = db_escape_string($_REQUEST["feed_id"]);
$result = db_query($link, "SELECT id FROM ttrss_feeds
WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
if (db_num_rows($result) != 0) {
unlink(ICONS_DIR . "/$feed_id.ico");
}
return;
}
if ($subop == "uploadicon") { if ($subop == "uploadicon") {
$icon_file = $_FILES['icon_file']['tmp_name'];
$feed_id = db_escape_string($_REQUEST["feed_id"]);
if (is_file($icon_file) && $feed_id) {
if (filesize($icon_file) < 2000) {
$result = db_query($link, "SELECT id FROM ttrss_feeds
WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
if (db_num_rows($result) != 0) {
unlink(ICONS_DIR . "/$feed_id.ico");
move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico");
$rc = 0;
} else {
$rc = 2;
}
} else {
$rc = 1;
}
} else {
$rc = 2;
}
print "<script type=\"text/javascript\">"; print "<script type=\"text/javascript\">";
print "parent.uploadIconHandler(this);"; print "parent.uploadIconHandler($rc);";
print "</script>"; print "</script>";
return; return;
} }
@ -400,7 +436,7 @@
print "<br/>"; print "<br/>";
/* print "<div class=\"dlgSec\">".__("Icon")."</div>"; print "<div class=\"dlgSec\">".__("Icon")."</div>";
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
print "<iframe name=\"icon_upload_iframe\" print "<iframe name=\"icon_upload_iframe\"
@ -409,14 +445,17 @@
print "<form style='display : block' target=\"icon_upload_iframe\" print "<form style='display : block' target=\"icon_upload_iframe\"
enctype=\"multipart/form-data\" method=\"POST\" enctype=\"multipart/form-data\" method=\"POST\"
action=\"backend.php\"> action=\"backend.php\">
<input id=\"icon_file\" name=\"icon_file\" type=\"file\"> <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
<input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
<input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
<input type=\"hidden\" name=\"subop\" value=\"uploadicon\"> <input type=\"hidden\" name=\"subop\" value=\"uploadicon\">
<button onclick=\"return uploadFeedIcon();\" <button onclick=\"return uploadFeedIcon();\"
type=\"submit\">".__('Replace')."</button> type=\"submit\">".__('Replace')."</button>
<button onclick=\"return removeFeedIcon($feed_id);\"
type=\"submit\">".__('Remove')."</button>
</form>"; </form>";
print "</div>"; */ print "</div>";
$title = htmlspecialchars($title, ENT_QUOTES); $title = htmlspecialchars($title, ENT_QUOTES);