-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
181 lines (143 loc) · 4.48 KB
/
index.php
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/*
6005_cw1_2012 - the Simple PHP RSS Reader for INFO6005
Author: University of Southamoton, Electronics and Computer Science
Published: 30th Jan 2012
This is part of a coursework for Students on the INFO6005 course at the University of Southampton.
In this course students are expected to package some code for distribution on the debian/ubuntu platform
Usage:
php index.php --help (for help)
This library can either read from a config file, or from stdin.
Basic Coursework Specification:
* Student MUST use an appropiate source code control repository for managing both the exemplar code and other related resources.
* Students MUST package this code to be installed on the latest available LTS version of ubuntu available from http://www.ubuntu.com/download/ubuntu/download
* The package MUST install on the latest ubuntu LTS release with a dpkg -i command.
* The LTS install used will be the desktop version with no optional software installed!
* The code MUST be installed in an appriate place in the operating system, e.g. /usr/share/package_name
Extensions to get more marks (Source Code Control):
* Tags
* Changelog both for code and package
Extensions to get more marks (Package)
* Man pages
* Central OS controlled config which is conpatible with core software upgrades, e.g. user is prompted by package installer before any config is overwritten
* Examples
* Web Front End
* Individual user config files in users home directories
* Other package based features...
Candidates can also customise/fix and extend the code itself, this may help them fill the changelog with items.
No marks are awarded for any complex customisations unless these are directly related to making a better package.
Candidates are encorages to record their changes (maybe as a changelog or in the package documentation) and submit these along with the completed package.
*/
# Read config from STDIN
if ($argc > 1) {
$config = parse_args($argv);
}
# Read config from file
if (@!$config) {
$config_file = '/usr/share/cw1-6005-pp6g11/feeds.conf';
if (file_exists($config_file)) {
$config = conf_from_file($config_file);
}
}
if (@$config["help"]) {
print_help();
exit(1);
}
if (@count($config["feeds"]) < 1) {
echo "No Feeds Specified\n";
exit(1);
}
if (@count($config["items"]) > 0) {
$items = $config["items"][0];
} else {
$items = 1;
}
process_request($config);
function process_request($config) {
# GOT THE FEEDS, PROCESS AND OUTPUT
require_once('rss_php.php');
$rss = new rss_php;
# SET DEFAULT ITEM COUNT, IN CASE ONE NOT SPECIFIED
$count = $config["items"][0];
if (@!$count) {
$count = 1;
}
$feeds = $config["feeds"];
for ($i=0;$i<count($feeds);$i++) {
$url = $feeds[$i];
$rss->load($url);
$items = $rss->getItems();
echo "Items From $url \n";
echo "===========";
for ($j=0;$j<strlen($url);$j++) {
echo "=";
}
echo "\n\n";
if (!$items) {
echo "FAILED TO LOAD ANY ITEMS\n\n";
} else {
for ($k=0;$k<$count;$k++) {
if ($items[$k]) {
echo " * " . $items[$k]["title"] . "\n";
}
}
echo "\n\n";
}
}
}
function print_help() {
echo "usage: command [options]\n";
echo "\n";
echo "Options\n";
echo "=======\n";
echo "\n";
echo " --feeds feed1,feed2,feed3\n";
echo " list of urls to read from\n";
echo "\n";
echo " --items n\n";
echo " number of items to read\n";
echo "\n";
}
function parse_args($args) {
$current_tag = "";
for ($i=1;$i<count($args);$i++) {
$arg = $args[$i];
if (substr($arg,0,2) == "--") {
$current_tag = substr($arg,2,strlen($arg));
$config[$current_tag] = "set";
} else {
$things = explode(",",$arg);
$config[$current_tag] = $things;
}
}
return $config;
}
function conf_from_file($config_file) {
$handle = fopen($config_file,"r");
if (!$handle) {
return;
}
$current_tag = "";
while (!feof($handle)) {
$line = trim(fgets($handle));
if (substr($line,0,1) == "<" and substr($line,strlen($line)-1,strlen($line)) == ">") {
$tag = $line;
$tag = str_replace("<","",$tag);
$tag = str_replace(">","",$tag);
if ($current_tag != "") {
if ("/" . $current_tag == $tag) {
$current_tag = "";
} else {
echo "Tag Mismatch in Config File\n";
exit(0);
}
} else {
$current_tag = $tag;
}
} elseif ($current_tag != "") {
$conf[$current_tag][] = $line;
}
}
return $conf;
}
?>