diff options
author | Andrew Dolgov <[email protected]> | 2021-02-16 09:27:58 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-16 09:27:58 +0300 |
commit | 06f8a2fabe245cd6038b0103e77d27dc0c471a1e (patch) | |
tree | 0b93edfdc397c61f54dd0e5cf95934527cfe8ed9 | |
parent | 13acc8e56294ad256654709d968ea54e687dc060 (diff) |
cleanup
-rwxr-xr-x | init.js | 31 | ||||
-rwxr-xr-x | init.php | 119 |
2 files changed, 80 insertions, 70 deletions
@@ -1,28 +1,23 @@ +/* global fox, Plugins, dojo, xhrPost __ */ + Plugins.Af_Img_Phash = { showSimilar: function(elem) { - try { + const url = elem.getAttribute("data-check-url"); - const url = elem.getAttribute("data-check-url"); - const query = "backend.php?op=pluginhandler&plugin=af_img_phash&method=showsimilar¶m=" + encodeURIComponent(url); + const dialog = new fox.SingleUseDialog({ + title: __("Similar images"), + content: __("Loading, please wait..."), + }); - if (dijit.byId("phashSimilarDlg")) - dijit.byId("phashSimilarDlg").destroyRecursive(); + const tmph = dojo.connect(dialog, 'onShow', function () { + dojo.disconnect(tmph); - const dialog = new dijit.Dialog({ - id: "phashSimilarDlg", - title: __("Similar images"), - style: "width: 600px", - execute: function() { - // - }, - href: query, + xhrPost("backend.php", {op: "pluginhandler", plugin: "af_img_phash", method: "showsimilar", url: url}, (transport) => { + dialog.attr('content', transport.responseText); }); + }); - dialog.show(); - - } catch (e) { - exception_error("showSimilar", e); - } + dialog.show(); } }; @@ -534,18 +534,20 @@ class Af_Img_Phash extends Plugin { } function showsimilar() { - $url = $_REQUEST["param"]; - $url_htmlescaped = htmlspecialchars($url); - + $url = $_REQUEST["url"]; $owner_uid = $_SESSION["uid"]; - $similarity = (int) $this->host->get($this, "similarity", $this->default_similarity); - print "<section class='narrow'>"; + ?> + <section class='narrow'> + <img class='trgm-related-thumb pull-right' src="<?= htmlspecialchars($url) ?>"> - print "<img class='trgm-related-thumb pull-right' src=\"$url_htmlescaped\">"; - - print "<fieldset><h2><a target='_blank' href=\"$url_htmlescaped\">".truncate_middle($url_htmlescaped, 48)."</a></h2></fieldset>"; + <fieldset> + <h2><a target='_blank' href="<?= htmlspecialchars($url) ?>"> + <?= truncate_middle(htmlspecialchars($url), 48) ?> + </a></h2> + </fieldset> + <?php $sth = $this->pdo->prepare("SELECT phash FROM ttrss_plugin_img_phash_urls WHERE owner_uid = ? AND @@ -568,43 +570,54 @@ class Af_Img_Phash extends Plugin { $article_title = $this->guid_to_article_title($article_guid, $owner_uid); $created_at = $row['created_at']; - print "<fieldset class='narrow'><label class='inline'>".$this->__( "Perceptual hash:")."</label>". - base_convert($phash, 10, 16) . "</fieldset>"; - print "<fieldset class='narrow'><label class='inline'>".$this->__( "Belongs to:")."</label> - $article_title</fieldset>"; - print "<fieldset class='narrow'><label class='inline'>".$this->__( "Registered:")."</label> - $created_at</fieldset>"; - - $sth = $this->pdo->prepare("SELECT url, article_guid, ".$this->bitcount_func($phash)." AS distance - FROM ttrss_plugin_img_phash_urls WHERE - ".$this->bitcount_func($phash)." <= ? - ORDER BY distance LIMIT 30"); - $sth->execute([$similarity]); - - print "<ul class='panel panel-scrollable list list-unstyled'>"; - - while ($line = $sth->fetch()) { - print "<li>"; - - $url = htmlspecialchars($line["url"]); - $distance = $line["distance"]; - $rel_article_guid = $line["article_guid"]; - $article_title = $this->guid_to_article_title($rel_article_guid, $owner_uid); - - $is_checked = ($rel_article_guid == $article_guid) ? "checked" : ""; - - print "<div><a target='_blank' href=\"$url\">".truncate_middle($url, 48)."</a> ". - "(" . $this->T_sprintf("Distance: %d", $distance) . ")"; - - if ($is_checked) print " <strong>(".$this->__( "Original").")</strong>"; - - print "<br/>$article_title"; - print "<br/><img class='trgm-related-thumb' src=\"$url\"></div>"; - - print "</li>"; - } - - print "</ul>"; + ?> + <fieldset class='narrow'><label><?= $this->__( "Perceptual hash:") ?></label> + <?= base_convert($phash, 10, 16) ?> + </fieldset> + <fieldset class='narrow'><label><?= $this->__( "Belongs to:") ?></label> + <?= $article_title ?> + </fieldset> + <fieldset class='narrow'><label><?= $this->__( "Registered:") ?></label> + <?= $created_at ?> + </fieldset> + + <ul class='panel panel-scrollable list list-unstyled'> + <?php + + $sth = $this->pdo->prepare("SELECT url, article_guid, ".$this->bitcount_func($phash)." AS distance + FROM ttrss_plugin_img_phash_urls WHERE + ".$this->bitcount_func($phash)." <= ? + ORDER BY distance LIMIT 30"); + $sth->execute([$similarity]); + + while ($line = $sth->fetch()) { + $url = htmlspecialchars($line["url"]); + $distance = $line["distance"]; + $rel_article_guid = $line["article_guid"]; + $article_title = $this->guid_to_article_title($rel_article_guid, $owner_uid); + + $is_checked = ($rel_article_guid == $article_guid) ? "checked" : ""; + + ?> + <li> + <div> + <a target='_blank' href="<?= $url ?>"><?= truncate_middle($url, 48) ?></a> + + (<?= $this->T_sprintf("Distance: %d", $distance) ?>) + + <?php if ($is_checked) { ?> + <strong>(<?= $this->__( "Original") ?>)</strong> + <?php } ?> + + <div><?= $article_title ?></div> + <div><img class='trgm-related-thumb' src="<?= $url ?>"></div> + </div> + </li> + <?php + } + ?> + </ul> + <?php } else { print "<div class='text-error'>" . $this->__( "No information found for this URL.") . "</div>"; @@ -613,13 +626,16 @@ class Af_Img_Phash extends Plugin { print "<div class='text-error'>" . $this->__( "No information found for this URL.") . "</div>"; } - print "</section>"; + ?> + </section> - print "<footer class='text-center'> - <button dojoType='dijit.form.Button' onclick=\"dijit.byId('phashSimilarDlg').hide()\">" - .$this->__( 'Close this window')."</button> - </footer>"; + <footer class='text-center'> + <button dojoType='dijit.form.Button' class='alt-primary' type='submit'> + <?= $this->__( 'Close this window') ?> + </button> + </footer> + <?php } private function interval_days($days) { @@ -637,5 +653,4 @@ class Af_Img_Phash extends Plugin { return "bit_count('$phash' ^ phash)"; } } -} -?> +}
\ No newline at end of file |