From: Andrew Dolgov Date: Thu, 14 Jan 2010 09:47:28 +0000 (+0300) Subject: feed editor: allow manual replacement of feed icons X-Git-Tag: 1.4.0~47 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=7abf159d61a933106b9b7a704cf3e549a3b4ab01;p=tt-rss.git feed editor: allow manual replacement of feed icons --- diff --git a/functions.js b/functions.js index f0135f76..bcb462c4 100644 --- a/functions.js +++ b/functions.js @@ -2248,15 +2248,56 @@ function feedArchiveRemove() { } } -function uploadIconHandler(iframe) { +function uploadIconHandler(rc) { try { - notify_info("Icon changed!"); + switch (rc) { + case 0: + 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) { + 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); - alert("Icon changed, blah blah"); + 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("uploadIconHandler", e); + exception_error("uploadFeedIcon", e); } } @@ -2268,12 +2309,15 @@ function uploadFeedIcon() { if (file.value.length == 0) { alert(__("Please select an image file to upload.")); - return false; } else { - notify_progress("Uploading, please wait...", true); - return true; + if (confirm(__("Upload new icon for this feed?"))) { + notify_progress("Uploading, please wait...", true); + return true; + } } + return false; + } catch (e) { exception_error("uploadFeedIcon", e); } diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 85d1e3f7..bfb178c2 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -15,9 +15,45 @@ $quiet = $_REQUEST["quiet"]; $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") { + $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 ""; return; } @@ -400,7 +436,7 @@ print "
"; -/* print "
".__("Icon")."
"; + print "
".__("Icon")."
"; print "
"; print "