summaryrefslogtreecommitdiff
path: root/modules/pref-feed-browser.php
blob: 6e4abce3652462e21571536b7a7a939b4572c0cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
	function module_pref_feed_browser($link) {

		if (!ENABLE_FEED_BROWSER) {
			print __("Feed browser is administratively disabled.");
			return;
		}

		$subop = $_REQUEST["subop"];

		if ($subop == "details") {
			$id = db_escape_string($_GET["id"]);

			print "<div class=\"browserFeedInfo\">";
			print "<b>".__('Feed information:')."</b>";

			$result = db_query($link, "SELECT 
					feed_url,site_url,
					SUBSTRING(last_updated,1,19) AS last_updated 
				FROM ttrss_feeds WHERE id = '$id' AND
					auth_login = '' AND auth_pass = ''");

			if (db_num_rows($result) == 1) {

				print "<div class=\"detailsPart\">";

				$feed_url = db_fetch_result($result, 0, "feed_url");
				$site_url = db_fetch_result($result, 0, "site_url");
				$last_updated = db_fetch_result($result, 0, "last_updated");
	
				if (get_pref($link, 'HEADLINES_SMART_DATE')) {
					$last_updated = smart_date_time(strtotime($last_updated));
				} else {
					$short_date = get_pref($link, 'SHORT_DATE_FORMAT');
					$last_updated = date($short_date, strtotime($last_updated));
				}
	
				print __("Site:")." <a target=\"_new\" href='$site_url'>$site_url</a> ".
					"(<a target=\"_new\" href='$feed_url'>feed</a>), ".
					__("Last updated:")." $last_updated";
	
				print "</div>";
	
				$result = db_query($link, "SELECT 
						ttrss_entries.title,
						content,link,
						substring(date_entered,1,19) as date_entered,
						substring(updated,1,19) as updated
					FROM ttrss_entries,ttrss_user_entries
					WHERE	ttrss_entries.id = ref_id AND feed_id = '$id'
					ORDER BY updated DESC LIMIT 5");
	
				if (db_num_rows($result) > 0) {
					
					print "<b>".__('Last headlines:')."</b><br>";
					
					print "<div class=\"detailsPart\">";
					print "<ul class=\"compact\">";
					while ($line = db_fetch_assoc($result)) {
	
						if (get_pref($link, 'HEADLINES_SMART_DATE')) {
							$entry_dt = smart_date_time(strtotime($line["updated"]));
						} else {
							$short_date = get_pref($link, 'SHORT_DATE_FORMAT');
							$entry_dt = date($short_date, strtotime($line["updated"]));
						}				
			
						print "<li><a target=\"_new\" href=\"" . $line["link"] . "\">" . $line["title"] . "</a>" .
							"&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";	
					}		
					print "</ul></div>";
				}
			} else {
				print "<p>".__("Feed not found.")."</p>";
			}

			print "</div>";
				
			return;
		}

		set_pref($link, "_PREFS_ACTIVE_TAB", "feedBrowser");

		print "<div>".__('This panel shows feeds subscribed by other users of this system, just in case you are interested in them too.')."</div>";

		$limit = db_escape_string($_GET["limit"]);

		if (!$limit) $limit = 25;

		$owner_uid = $_SESSION["uid"];
			
		$result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
	  		FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf 
				WHERE tf.feed_url = ttrss_feeds.feed_url 
					AND owner_uid = '$owner_uid') GROUP BY feed_url 
						ORDER BY subscribers DESC LIMIT $limit");

		print "<br/>";
			
		print "<div style=\"float : right\">
			".__('Top')." <select id=\"feedBrowserLimit\">";

		foreach (array(25, 50, 100) as $l) {
			$issel = ($l == $limit) ? "selected" : "";
			print "<option $issel>$l</option>";
		}
			
		print "</select>
			<input type=\"submit\" class=\"button\"
				onclick=\"updateBigFeedBrowser()\" value=\"".__('Show')."\">
		</div>";

		print "<div id=\"fbrOpToolbar\">
			<input type='submit' class='button' onclick=\"feedBrowserSubscribe()\" 
			disabled=\"true\" value=\"".__('Subscribe')."\"></div>";

		print "<ul class='nomarks' id='browseBigFeedList'>";

		$feedctr = 0;
		
		while ($line = db_fetch_assoc($result)) {
			$feed_url = $line["feed_url"];
			$subscribers = $line["subscribers"];
		
			$det_result = db_query($link, "SELECT site_url,title,id 
				FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");

			$details = db_fetch_assoc($det_result);
		
			$icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";

			if (file_exists($icon_file) && filesize($icon_file) > 0) {
					$feed_icon = "<img class=\"tinyFeedIcon\"	src=\"" . ICONS_URL . 
						"/".$details["id"].".ico\">";
			} else {
				$feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
			}

			$check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB' 
				type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";

			$class = ($feedctr % 2) ? "even" : "odd";

			print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
				"$feed_icon ";
				
			print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" . 
				$details["title"] ."</a>&nbsp;" .
				"<span class='subscribers'>($subscribers)</span>";
			
			print "<div class=\"browserDetails\" style=\"display : none\" id=\"BRDET-" . $details["id"] . "\">";
			print "</div>";
				
			print "</li>";

				++$feedctr;
		}

		if ($feedctr == 0) {
			print "<li>".__('No feeds found to subscribe.')."</li>";
		}

		print "</ul>";

		print "</div>";
	}
?>