dlg.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. class Dlg extends Handler_Protected {
  3. private $param;
  4. private $params;
  5. function before($method) {
  6. if (parent::before($method)) {
  7. header("Content-Type: text/html"); # required for iframe
  8. $this->param = $this->dbh->escape_string($_REQUEST["param"]);
  9. return true;
  10. }
  11. return false;
  12. }
  13. function importOpml() {
  14. print __("If you have imported labels and/or filters, you might need to reload preferences to see your new data.") . "</p>";
  15. print "<div class=\"prefFeedOPMLHolder\">";
  16. $this->dbh->query("BEGIN");
  17. print "<ul class='nomarks'>";
  18. $opml = new Opml($_REQUEST);
  19. $opml->opml_import($_SESSION["uid"]);
  20. $this->dbh->query("COMMIT");
  21. print "</ul>";
  22. print "</div>";
  23. print "<div align='center'>";
  24. print "<button dojoType=\"dijit.form.Button\"
  25. onclick=\"dijit.byId('opmlImportDlg').execute()\">".
  26. __('Close this window')."</button>";
  27. print "</div>";
  28. print "</div>";
  29. //return;
  30. }
  31. function pubOPMLUrl() {
  32. $url_path = Opml::opml_publish_url();
  33. print __("Your Public OPML URL is:");
  34. print "<div class=\"tagCloudContainer\">";
  35. print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>";
  36. print "</div>";
  37. print "<div align='center'>";
  38. print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">".
  39. __('Generate new URL')."</button> ";
  40. print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
  41. __('Close this window')."</button>";
  42. print "</div>";
  43. //return;
  44. }
  45. function explainError() {
  46. print "<div class=\"errorExplained\">";
  47. if ($this->param == 1) {
  48. print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner.");
  49. $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
  50. print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
  51. }
  52. if ($this->param == 3) {
  53. print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner.");
  54. $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
  55. print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
  56. }
  57. print "</div>";
  58. print "<div align='center'>";
  59. print "<button onclick=\"return closeInfoBox()\">".
  60. __('Close this window')."</button>";
  61. print "</div>";
  62. //return;
  63. }
  64. function printTagCloud() {
  65. print "<div class=\"tagCloudContainer\">";
  66. // from here: http://www.roscripts.com/Create_tag_cloud-71.html
  67. $query = "SELECT tag_name, COUNT(post_int_id) AS count
  68. FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]."
  69. GROUP BY tag_name ORDER BY count DESC LIMIT 50";
  70. $result = $this->dbh->query($query);
  71. $tags = array();
  72. while ($line = $this->dbh->fetch_assoc($result)) {
  73. $tags[$line["tag_name"]] = $line["count"];
  74. }
  75. if(count($tags) == 0 ){ return; }
  76. ksort($tags);
  77. $max_size = 32; // max font size in pixels
  78. $min_size = 11; // min font size in pixels
  79. // largest and smallest array values
  80. $max_qty = max(array_values($tags));
  81. $min_qty = min(array_values($tags));
  82. // find the range of values
  83. $spread = $max_qty - $min_qty;
  84. if ($spread == 0) { // we don't want to divide by zero
  85. $spread = 1;
  86. }
  87. // set the font-size increment
  88. $step = ($max_size - $min_size) / ($spread);
  89. // loop through the tag array
  90. foreach ($tags as $key => $value) {
  91. // calculate font-size
  92. // find the $value in excess of $min_qty
  93. // multiply by the font-size increment ($size)
  94. // and add the $min_size set above
  95. $size = round($min_size + (($value - $min_qty) * $step));
  96. $key_escaped = str_replace("'", "\\'", $key);
  97. echo "<a href=\"javascript:viewfeed({feed:'$key_escaped'}) \" style=\"font-size: " .
  98. $size . "px\" title=\"$value articles tagged with " .
  99. $key . '">' . $key . '</a> ';
  100. }
  101. print "</div>";
  102. print "<div align='center'>";
  103. print "<button dojoType=\"dijit.form.Button\"
  104. onclick=\"return closeInfoBox()\">".
  105. __('Close this window')."</button>";
  106. print "</div>";
  107. }
  108. function generatedFeed() {
  109. $this->params = explode(":", $this->param, 3);
  110. $feed_id = $this->dbh->escape_string($this->params[0]);
  111. $is_cat = (bool) $this->params[1];
  112. $key = get_feed_access_key($feed_id, $is_cat);
  113. $url_path = htmlspecialchars($this->params[2]) . "&key=" . $key;
  114. print "<h2>".__("You can view this feed as RSS using the following URL:")."</h2>";
  115. print "<div class=\"tagCloudContainer\">";
  116. print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>";
  117. print "</div>";
  118. print "<div align='center'>";
  119. print "<button dojoType=\"dijit.form.Button\" onclick=\"return genUrlChangeKey('$feed_id', '$is_cat')\">".
  120. __('Generate new URL')."</button> ";
  121. print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
  122. __('Close this window')."</button>";
  123. print "</div>";
  124. //return;
  125. }
  126. }