/[drupal]/contributions/modules/fetchgals/fetchgals.module
ViewVC logotype

Contents of /contributions/modules/fetchgals/fetchgals.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Jul 28 15:16:19 2006 UTC (3 years, 4 months ago) by pobster
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-4-7
Changes since 1.7: +53 -21 lines
File MIME type: text/x-php
ADDED timestamp to logs
FIXED cron cleaning function (of course...  cron runs as anonymous user!  doh!)
ADDED cleaning function to admin screen
1 <?php
2 // $Id$
3
4 define('FG_CWD', dirname(__FILE__).'/fetchgals/');
5 define('FG_MAIN', dirname(__FILE__).'/fetchgals/fetchgals.pl');
6 define('FG_TGPS', dirname(__FILE__).'/fetchgals/findtgps.pl');
7
8 /**
9 * Implementation of hook_help
10 */
11 function fetchgals_help($section) {
12 switch ($section) {
13 case 'admin/modules#description': // This description is shown in the listing at admin/modules.
14 return t('Integration with Fetchgals (http://fetchgals.sourceforge.net) - a webspider to download free porn');
15 case 'admin/fetchgals': // Shown on the main administration screen
16 return t("You *must* run 'Find Galleries' before you can use either of the other two functions.");
17 case 'admin/help#fetchgals': // Some help text
18 return t("<h1><a name=\"introduction\">INTRODUCTION</a></h1>
19 <p>Today, commercial porn sites are advertised like this: somebody puts
20 together a thumbnail gallery, i.e. a web page with small thumbnail
21 pictures linking to free full-size images or movies, and provides a
22 link to the pay site. These thumbnail galleries are listed on central
23 websites called Thumbnail Gallery Posts (TGPs). Unfortunately, many
24 TGPs add a layer of redirects, popups, spyware and viruses. <strong>Fetchgals</strong>
25 is designed to eliminate the TGP middle men, to achieve a satisfying
26 masturbatory experience.</p><p>The <strong>fetchgals</strong> distribution comes with
27 a huge list of TGPs. This list was generated by a separate script
28 called findtgps, which is also included in the distribution. <strong>Fetchgals</strong>
29 visits these TGPs in order to locate thumbnail galleries. The images
30 and movies of these galleries can then be downloaded. Since there's a
31 couple hundred gigabytes of free porn on the internet at any given time,
32 <strong>fetchgals</strong> constantly monitors local disk space to avoid overruns.
33 Alternatively, <strong>fetchgals</strong> can create local HTML pages that link to the
34 known galleries; this minimizes disk and bandwidth usage.</p><hr>
35 <h1><a name=\"description\">DESCRIPTION</a></h1>
36 <p>A <em>TGP</em> (Thumbnail Gallery Post) is a website that links to many
37 <em>thumbnail galleries</em>, sites with free porn. In one kind of TGP, the
38 so-called <em>CJ</em> sites (for ``circle jerk''), the viewer is sometimes
39 redirected to other TGPs rather than to the gallery they intend to
40 visit. Many of these CJ sites also resize and hijack the browser, try
41 to install adware or dialers on the viewer's computer, open consoles
42 and popups, etc.</p>
43 <p><strong>Fetchgals</strong> is designed to work around these annoyances of CJ sites,
44 in order to achieve a satisfying masturbatory experience. It reads
45 TGP URLs from a configuration file, visits the TGPs one by one, and
46 determines gallery URLs as well as a preview thumbnail for each
47 gallery. This information is saved to a file and can then be used in
48 two ways: to download all the pictures from all the galleries to the
49 local computer, or to create local HTML pages with preview thumbnails
50 linking to the galleries.</p><hr>
51 <h1><a name=\"licences + legal\">LICENCES + LEGAL</a></h1>
52 <p><strong>Fetchgals</strong> is in the %link6. This means that <em>\"there are no
53 laws which restrict its use by the public at large\"</em>.</p><p>This
54 module is covered under the %link7. The GPL grants certain rights, most
55 importantly <em>\"the right to run the program, for any desired purpose\"
56 </em>.</p>
57 <p>In view of these licences, there is nothing to stop an admin from charging users to view
58 the results of these programs, but please bear in mind that the content you will gain from
59 using this module and the <strong>Fetchgals</strong> package may have <strong>copyright
60 / Intellectual property rights</strong> and therefore you may be breaking
61 the law by charging for it.</p><p>Neither Drupal.org nor the author of this module are
62 responsible for the use of this module. You should be aware of the legislation applying to
63 your site. <em>You can't charge for something which doesn't belong to you!</em></p><hr>
64 <h1><a name=\"instructions\">INSTRUCTIONS</a></h1>
65 <p>Most users will not need to change any of the settings, everything will
66 work fine just from the defaults. If however you wish to make the porn
67 html directory private (ie. not directly viewable from the web) then
68 simply change the 'HTML Directory' setting to somewhere where normal
69 users cannot access. Of course, ensure that the webserver still has
70 permissions to create files in this new location.</p>
71 <p>To simply use this module to create local HTML pages with preview
72 thumbnails, go to %link1 then click 'Find Galleries' followed
73 by 'Create HTML'. It *will* take a while and you can only run one
74 of these processes at a time (due to the high load they put on the server) but when
75 finished you can view the results on the %link3 page.</p><p>If you wish,
76 you can edit the list of pages where <strong>fetchgals</strong> finds its links. It's
77 recommended not to make the list too long as you'll quickly run out of memory.
78 In the <strong>fetchgals</strong> package directory you'll find a sample file called %link2
79 this contains many more links you can add to your own tgps file. Please bear
80 in mind though that <strong>fetchgals</strong> hasn't been updated in quite a while and therefore some
81 of these links may no longer be valid.</p><p><font size='+1'><strong>AGAIN! DO NOT MAKE
82 YOUR TGPS FILE TOO LONG ELSE YOU *WILL* RUN OUT OF MEMORY!!!</strong></font></p>
83 <hr><h1><a name=\"troubleshooting\">TROUBLESHOOTING</a></h1>
84 <p>Please read the %link4 file carefully. If you still have problems then:</p>
85 <p><ul>
86 <li>Check your logs at: %link5 The first line is the full commandline passed to <strong>fetchgals</strong>
87 and so will greatly help with debugging.</li>
88 <li>If the log tells you:<p><em>\"Reading galleries and preview thumbs from
89 /var/www/localhost/htdocs/modules/fetchgals/fetchgals/galleries Discarding galleries that
90 have already been processed... Done with discarding. No new galleries to process. Run
91 fetchgals -f first\"</em></p><p>This means that all the galleries collected in the ./galleries
92 file have been processed already. <em>\"fetchgals -f\"</em> is just an abbreviated way of
93 telling you to use the 'Find Galleries' function to find new galleries to process.</p></li>
94 <li>The logs will also show if <strong>fetchgals</strong> rejects the arguments passed to it. It will not however
95 show errors if the command cannot be executed. In this case, see the next step:</li>
96 <li>Check your webservers error_log. This will detail any Perl errors.</li>
97 <li>Q: <em>\"Help! My porn_pics directory is completely filling up my hard drive!\"</em><br>
98 A: This is because you clicked 'Download Pictures' without bothering to look at what it
99 actually does... I do agree that the default of <strong>max_disk_usage</strong> is a <em>little</em>
100 on the high side at 95% (yours is set to '%var2%') but I didn't want to change any of the default settings.
101 <p>To stop it, first run:</p><p><strong># ps -e</strong></p><p>You'll see a number of Perl processes running.
102 If this number matches your <strong>num_download_processes</strong> (currently set to '%var1')
103 then simply run:</p><p><strong># killall perl</strong></p></li>
104 <li>Q: <em>\"<strong>Fetchgals</strong> doesn't work for me, it reports 'XXX' error...\"</em><br>A: I didn't write
105 <strong>fetchgals</strong> please consult either the %link8 or the %link9.</li>
106 <li>Q: <em>\"When I first ran <strong>Fetchgals</strong> I got over a 100 pages of galleries. Now
107 when I run 'Create HTML' I only get 30 or so, even when my porn_html directory is empty?\"</em><br>A:
108 <strong>Fetchgals</strong> works by storing processed information in files, this tries to prevent you
109 from reprocessing galleries you've already viewed. If however you wish to <em>'start from scratch'</em>
110 you can purge these files by using the 'Cleaning Operations' in %link1.</li>
111 </ul></p>
112 <p>Take care if you do alter any of the settings and please use a little common sense. If you alter
113 the Gallery Filename for instance, neither 'Download Pictures' nor 'Create HTML' will work until the
114 new gallery file exists. You'll then have to re-run 'Find Galleries' to create a new gallery file
115 (or rename the old one to match the new setting).</p>",
116 array('%link1' => l('admin/fetchgals', 'admin/fetchgals'),
117 '%link2' => l('tgps_huge', drupal_get_path('module', 'fetchgals').'/fetchgals/tgps_huge'),
118 '%link3' => l('fetchgals', 'fetchgals'),
119 '%link4' => l('INSTALL', drupal_get_path('module', 'fetchgals').'/INSTALL.txt'),
120 '%link5' => l('admin/fetchgals/log', 'admin/fetchgals/log'),
121 '%link6' => l('public domain', 'http://en.wikipedia.org/wiki/Public_domain'),
122 '%link7' => l('GPL licence', 'http://en.wikipedia.org/wiki/Gpl'),
123 '%link8' => l('Fetchgals README file', drupal_get_path('module', 'fetchgals').'/fetchgals/README'),
124 '%link9' => l('Fetchgals site', 'http://fetchgals.sourceforge.net'),
125 '%var1' => variable_get('fetchgals_num_download_processes', 8),
126 '%var2' => variable_get('fetchgals_max_disk_usage', 95)
127 )
128 );
129 }
130 return $output;
131 } // fetchgals_help
132
133 /**
134 * Implementation of hook_perm
135 */
136 function fetchgals_perm() {
137 return array('administer fetchgals', 'access fetchgals');
138 } // fetchgals_perm
139
140 /**
141 * Implementation of hook_menu
142 */
143 function fetchgals_menu($may_cache) {
144 $items = array();
145 if ($may_cache) {
146 $items[] = array('path' => 'fetchgals/file',
147 'callback' => 'fetchgals_file_download',
148 'access' => user_access('access fetchgals'),
149 'type' => MENU_CALLBACK
150 );
151 $items[] = array('path' => 'fetchgals/thumb',
152 'callback' => 'fetchgals_show_thumb',
153 'access' => user_access('access fetchgals'),
154 'type' => MENU_CALLBACK
155 );
156 $items[] = array('path' => 'fetchgals/overlay',
157 'callback' => 'fetchgals_overlay',
158 'access' => user_access('access fetchgals'),
159 'type' => MENU_CALLBACK
160 );
161 $items[] = array('path' => 'admin/fetchgals', 'title' => t('fetchgals'),
162 'callback' => 'fetchgals_admin',
163 'access' => user_access('administer fetchgals'),
164 'type' => MENU_NORMAL_ITEM
165 );
166 $items[] = array('path' => 'admin/fetchgals/log', 'title' => t('fetchgals log'),
167 'callback' => 'fetchgals_log',
168 'access' => user_access('administer fetchgals'),
169 'type' => MENU_NORMAL_ITEM
170 );
171 $items[] = array('path' => 'fetchgals', 'title' => t('fetchgals'),
172 'callback' => 'fetchgals_view',
173 'access' => user_access('access fetchgals'),
174 'type' => MENU_NORMAL_ITEM
175 );
176 if (file_check_directory(fetchgals_check(variable_get('fetchgals_pics_dir', './porn_pics')))) {
177 $items[] = array('path' => 'fetchgals/pictures', 'title' => t('fetchgals pics'),
178 'callback' => 'fetchgals_viewpics',
179 'access' => user_access('access fetchgals'),
180 'type' => MENU_SUGGESTED_ITEM
181 );
182 }
183 }
184 return $items;
185 } // fetchgals_menu
186
187 /**
188 * Implementation of hook_init
189 */
190 function fetchgals_init() {
191 unset($flag);
192 $files = array('fetchgals.pl', 'findtgps.pl', 'tgps');
193 foreach ($files as $check) {
194 if (!file_exists(FG_CWD.$check)) {
195 $flag = TRUE;
196 }
197 }
198 if ($flag) {
199 watchdog('fetchgals', t('Fetchgals package is not installed correctly. Please consult fetchgals/INSTALL.txt.'), WATCHDOG_ERROR);
200 }
201 $dir = FG_CWD;
202 if (!file_check_directory($dir, FALSE)) {
203 watchdog('fetchgals', t('Fetchgals directory is not writeable for the webserver. Please consult fetchgals/INSTALL.txt.'), WATCHDOG_ERROR);
204 }
205 return;
206 } // fetchgals_init
207
208 /**
209 * Implementation of hook_settings
210 */
211 function fetchgals_settings() {
212 unset($version);
213 $perl = exec('perl -V:version');
214 $perl = explode("'", $perl);
215 $perl = $perl[1];
216 $form['perl_version'] = array(
217 '#type' => 'item',
218 '#value' => $perl ? t('<strong>Perl version:</strong> %ver', array('%ver' => $perl)) : t('Perl is not installed.'),
219 );
220 $version = exec('perl '.FG_MAIN.' --version');
221 if ($perl) {
222 $form['fg_version'] = array(
223 '#type' => 'item',
224 '#value' => $version ? t('<strong>%ver</strong>', array('%ver' => $version)) : t('Fetchgals package is not installed correctly.'),
225 );
226 }
227 $dir = FG_CWD;
228 if (!file_check_directory($dir, FALSE)) {
229 drupal_set_message(t('Fetchgals directory is not writeable for the webserver.'), 'error');
230 unset($version);
231 }
232 if (!$version) {
233 $form['null'] = array(
234 '#type' => 'item',
235 '#value' => t('Please consult fetchgals/INSTALL.txt.'),
236 );
237 return $form;
238 }
239 $form['cron_settings'] = array(
240 '#type' => 'fieldset',
241 '#title' => t('Cron Settings:'),
242 '#collapsible' => TRUE,
243 '#collapsed' => FALSE,
244 );
245 $form['cron_settings']['fetchgals_cron'] = array(
246 '#type' => 'checkbox',
247 '#title' => t('Use cron to manage fetchgals?'),
248 '#default_value' => variable_get('fetchgals_cron', 0),
249 '#description' => t('Assuming you have your cron set up properly, checking this will automate fetchgals'),
250 );
251 foreach (range('0', '23') as $i) {
252 $time[$i] = date('g:00a', mktime($i));
253 }
254 $form['cron_settings']['fetchgals_timecron'] = array(
255 '#type' => 'select',
256 '#title' => t('Time of day for cron'),
257 '#default_value' => variable_get('fetchgals_timecron', 3),
258 '#options' => $time,
259 '#description' => t("Depending on what you've set below, this setting makes sure the cronjobs only execute at sensible times of the day when the extra load on your server won't affect anyone"),
260 );
261 $form['cron_settings']['fetchgals_fetch'] = array(
262 '#type' => 'select',
263 '#title' => t('How often to fetch'),
264 '#default_value' => variable_get('fetchgals_fetch', 86400),
265 '#options' => array(NULL => 'Never', 86400 => 'Daily', 172800 => 'Every other day', 604800 => 'Weekly'),
266 '#description' => t('Runs both -find_galleries and -create_html (including all your default settings from below) during your scheduled cron job to create a completely new set of galleries'),
267 );
268 $form['cron_settings']['fetchgals_clean'] = array(
269 '#type' => 'select',
270 '#title' => t('How often to empty folder'),
271 '#default_value' => variable_get('fetchgals_clean', 604800),
272 '#options' => array(NULL => 'Never', 86400 => 'Daily', 172800 => 'Every other day', 604800 => 'Weekly'),
273 '#description' => t("Completely removes all html files in folder '%folder' during your scheduled cron job", array('%folder' => variable_get('fetchgals_html_dir', './porn_html'))),
274 );
275 $form['display_settings'] = array(
276 '#type' => 'fieldset',
277 '#title' => t('Display Settings:'),
278 '#collapsible' => TRUE,
279 '#collapsed' => TRUE,
280 );
281 $form['display_settings']['fetchgals_paginate_pics'] = array(
282 '#type' => 'select',
283 '#title' => t('Picture Pagination'),
284 '#default_value' => variable_get('fetchgals_paginate_pics', 50),
285 '#options' => array(5 => '5', 10 => '10', 15 => '15', 25 => '25', 35 => '35', 50 => '50', 75 => '75', NULL => 'All'),
286 '#description' => t("The default amount of results of pictures displayed in %link
287 before they're paginated. You should reduce this to a low number if you're
288 showing them as thumbnails as the images take a little while to display",
289 array('%link' => l('fetchgals pics', 'fetchgals/pictures'))
290 ),
291 );
292 $form['display_settings']['thumbs'] = array(
293 '#type' => 'fieldset',
294 '#collapsed' => FALSE,
295 );
296 $form['display_settings']['thumbs']['fetchgals_show_thumbs'] = array(
297 '#type' => 'checkbox',
298 '#title' => t('Show as thumbnails?'),
299 '#default_value' => variable_get('fetchgals_show_thumbs', 0),
300 '#description' => t("When checked all the links in %link will be shown as thumbnails", array('%link' => l('fetchgals pics', 'fetchgals/pictures'))),
301 );
302 $form['display_settings']['thumbs']['fetchgals_save_thumbs'] = array(
303 '#type' => 'checkbox',
304 '#title' => t('Save thumbnails?'),
305 '#default_value' => variable_get('fetchgals_save_thumbs', 0),
306 '#description' => t("Saves the thumbnails to disk as <em>thumb-xxxfilenamexxx.jpg</em>
307 to save them from having to be resized on the fly every time they're viewed (which
308 takes time).<br><strong>Note:</strong> The thumb files are created the first time
309 they're viewed, although I may consider one day incorporating this function into
310 the cron."
311 ),
312 );
313 $form['display_settings']['thumbs']['fetchgals_thumb_width'] = array(
314 '#type' => 'textfield',
315 '#title' => t('Thumbnail Max Width'),
316 '#default_value' => variable_get('fetchgals_thumb_width', 150),
317 '#size' => 4,
318 '#description' => t('in pixels'),
319 );
320 $form['display_settings']['thumbs']['fetchgals_thumb_height'] = array(
321 '#type' => 'textfield',
322 '#title' => t('Thumbnail Max Height'),
323 '#default_value' => variable_get('fetchgals_thumb_height', 100),
324 '#size' => 4,
325 '#description' => t('in pixels'),
326 );
327 $form['fetchgals_settings'] = array(
328 '#type' => 'fieldset',
329 '#title' => t('Fetchgals Settings:'),
330 '#description' => t("<h1><em>Only change these settings if you absolutely know what you're doing!</em></h1>
331 <br>Note: Any directory prefixed by '<strong>./</strong>' will appear in your <em>%dir</em> directory, other than
332 that please use FULL paths eg. <em>/tmp/porn_pics</em>",
333 array('%dir' => drupal_get_path('module', 'fetchgals').'/fetchgals')
334 ),
335 '#collapsible' => TRUE,
336 '#collapsed' => TRUE,
337 );
338 $form['fetchgals_settings']['fetchgals_tgp_file'] = array(
339 '#type' => 'textfield',
340 '#title' => t('TGP File'),
341 '#default_value' => variable_get('fetchgals_tgp_file', './tgps'),
342 '#size' => 50,
343 '#description' => t("The file that contains URLs of TGPs, one per line; lines starting with
344 # are comments and are ignored. Defaults to <em>./tgps</em>. This option is
345 only needed by the <strong>-find_galleries</strong> action.
346 <p>Two TGP files are distributed with <strong>fetchgals</strong>. Others can be
347 generated with the program <em>findtgps(1)</em>.</p>"
348 ),
349 );
350 $form['fetchgals_settings']['fetchgals_extensive_search'] = array(
351 '#type' => 'checkbox',
352 '#title' => t('Extensive Search'),
353 '#default_value' => variable_get('fetchgals_extensive_search', 0),
354 '#description' => t("This option affects the operation of the <strong>-find_galleries</strong> action.
355 Without it, only links from TGPs are investigated that expose the true
356 location of the gallery in the URL. If <strong>-extensive_search</strong> is
357 switched on, other links are followed as well; they have to be ``tried
358 out'' to find the gallery's location, and often this has to be repeated
359 several times until the gallery's URL is found. The <strong>-find_galleries</strong>
360 action is much slower when <strong>-extensive_search</strong> is switched on, and
361 for most users it is probably not worth it."
362 ),
363 );
364 $form['fetchgals_settings']['fetchgals_attempts_per_link'] = array(
365 '#type' => 'textfield',
366 '#title' => t('Attempts Per Link'),
367 '#default_value' => variable_get('fetchgals_attempts_per_link', 5),
368 '#size' => 5,
369 '#description' => t("The number of times a link to a gallery is followed (default: 5). Many
370 TGPs use CGI scripts as links to the galleries, and these scripts
371 frequently redirect to another TGP rather than to the gallery. If this
372 happens to us, we try the link again, until we find a <em>bona fide</em>
373 gallery or we exceed num attempts. This option only has an effect if
374 <strong>-extensive_search</strong> is being used."
375 ),
376 );
377 $form['fetchgals_settings']['fetchgals_sleep_time'] = array(
378 '#type' => 'textfield',
379 '#title' => t('Sleep Time'),
380 '#default_value' => variable_get('fetchgals_sleep_time', 7),
381 '#size' => 5,
382 '#description' => t("The average time (in seconds) between accesses to the same TGP
383 (default is 7). This is an average; the actual waiting time is
384 randomized. The purpose is to avoid our bot being detected. We cycle
385 through the TGPs so that we don't have to sleep often.
386 <p>This option only affects the <strong>-find_galleries</strong> action if the
387 <strong>-extensive_search</strong> option is switched on. Without
388 <strong>-extensive_search</strong>, we never have to sleep. If you get many ``bot
389 detected'' messages during the <strong>-find_galleries</strong> action, you need to
390 increase the sleep time.</p>"
391 ),
392 );
393 $form['fetchgals_settings']['fetchgals_gallery_file'] = array(
394 '#type' => 'textfield',
395 '#title' => t('Gallery File'),
396 '#default_value' => variable_get('fetchgals_gallery_file', './galleries'),
397 '#size' => 50,
398 '#description' => t("The file that contains URLs of galleries and preview thumbnails, one
399 gallery and one thumbnail per line, separated by a space. Defaults to
400 <em>./galleries</em>. Before the <strong>-find_galleries</strong> action starts to collect
401 galleries, it reads this file so that it won't have to test a
402 previously seen gallery. It then appends newly found galleries. The
403 file is read by the <strong>-create_html</strong> and <strong>-download_pics</strong> actions.
404 <p>If the file doesn't exist, then it will be created.</p>"
405 ),
406 );
407 $form['fetchgals_settings']['fetchgals_use_cookies'] = array(
408 '#type' => 'checkbox',
409 '#title' => t('Use Cookies'),
410 '#default_value' => variable_get('fetchgals_use_cookies', 0),
411 '#description' => t("With this option, <strong>fetchgals</strong> will save the cookies it receives
412 and return them to TGPs and galleries. By default, cookies are not
413 used."
414 ),
415 );
416 $form['fetchgals_settings']['fetchgals_pics_dir'] = array(
417 '#type' => 'textfield',
418 '#title' => t('Pictures Directory'),
419 '#default_value' => variable_get('fetchgals_pics_dir', './porn_pics'),
420 '#size' => 50,
421 '#description' => t("The directory where the <strong>-download_pics</strong> action stores the downloaded
422 images. Defaults to <em>./porn_pics</em>. The directory will be created if it
423 doesn't exist. The pictures receive names indicating their origin and
424 are stored in subdirectories a-z depending on the first letter of
425 their name."
426 ),
427 );
428 $form['fetchgals_settings']['fetchgals_processed_downloads_file'] = array(
429 '#type' => 'textfield',
430 '#title' => t('Processed Downloads File'),
431 '#default_value' => variable_get('fetchgals_processed_downloads_file', './gals_downloaded'),
432 '#size' => 50,
433 '#description' => t("The file where the URLs of downloaded galleries are recorded. Defaults
434 to <em>./gals_downloaded</em>. This is only used by the <strong>-download_pics</strong>
435 action, to avoid repeated downloads of the same gallery. The file will
436 be created if it doesn't exist."
437 ),
438 );
439 $form['fetchgals_settings']['fetchgals_types'] = array(
440 '#type' => 'textfield',
441 '#title' => t('Types'),
442 '#default_value' => variable_get('fetchgals_types', 'jpg|jpeg|gif|png|mpg|mpeg|avi|asf|mov|wmv'),
443 '#size' => 100,
444 '#description' => t("A regular expression matching the extensions of files you want to
445 download. Defaults to jpg|jpeg|gif|png|mpg|mpeg|avi|asf|mov|wmv.
446 The match is case-insensitive, so you don't need to list the
447 upper-case variants. Note that if you want to download videos, you
448 need to increase <strong>-max_img_size</strong>."
449 ),
450 );
451 $form['fetchgals_settings']['fetchgals_min_img_size'] = array(
452 '#type' => 'textfield',
453 '#title' => t('Minimum Image Size'),
454 '#default_value' => variable_get('fetchgals_min_img_size', 15000),
455 '#size' => 10,
456 '#description' => t("The minimum size (in bytes) of image files to download (default:
457 15000). This is only used by the <strong>-download_pics</strong> action; files
458 smaller than this threshold are taken to be thumbnails or advertising
459 banners and not downloaded."
460 ),
461 );
462 $form['fetchgals_settings']['fetchgals_max_img_size'] = array(
463 '#type' => 'textfield',
464 '#title' => t('Maximum Image Size'),
465 '#default_value' => variable_get('fetchgals_max_img_size', 250000),
466 '#size' => 10,
467 '#description' => t("The maximum size (in bytes) of image files to download (default:
468 250000). This is only used by the <strong>-download_pics</strong> action; files
469 larger than this threshold are not downloaded. If you are interested
470 in movies, you want to set this to 10000000."
471 ),
472
473 );
474 $form['fetchgals_settings']['fetchgals_max_disk_usage'] = array(
475 '#type' => 'textfield',
476 '#title' => t('Maximum Disk Usage'),
477 '#default_value' => variable_get('fetchgals_max_disk_usage', 95),
478 '#size' => 4,
479 '#description' => t("The image download is stopped if the disk usage exceeds <em>num</em>%
480 (default: 95). This percentage is based on the total disk space
481 available to non-superusers. Your system may reserve some additional
482 disk space for the super user."
483 ),
484 );
485 $form['fetchgals_settings']['fetchgals_pic_file_template'] = array(
486 '#type' => 'textfield',
487 '#title' => t('Picture File Template'),
488 '#default_value' => variable_get('fetchgals_pic_file_template', '%i/%h-%p-%n%e'),
489 '#size' => 40,
490 '#description' => t("The template to be used for the filenames of the downloaded images. This is a string containing the following special place holdersq:<p>
491 <dl><dt><strong>%h</strong></dt><dd>The host name of the gallery, with leading ``www.'' removed.</dd>
492 <dt><strong>%i</strong></dt><dd>The first letter of the host name, or ``z'' if that is a digit. </dd>
493 <dt><strong>%p</strong></dt><dd>The path of the gallery's URL, with all slashes replaced by hyphens.</dd>
494 <dt><strong>%d</strong></dt><dd>The current date.</dd>
495 <dt><strong>%t</strong></dt><dd>The current time.</dd>
496 <dt><strong>%n</strong></dt><dd>The number of the image within the gallery.</dd>
497 <dt><strong>%c</strong></dt><dd>The filetype: either ``video'' or ``image''. Note that if you want
498 <strong>fetchgals</strong> to download videos, you need to increase the default
499 maximal file size with <strong>-max_img_size</strong>.</dd>
500 <dt><strong>%e</strong></dt><dd>The filename extension giving the file's type. Starts with a period.</dd>
501 <dt><strong>%%</strong></dt><dd>A literal %-sign.</dd></dl></p>
502 <p>The default template is %i/%h-%p-%n%e. Every template should contain %h, %p and %n, or else some images run the risk of being overwritten.</p>"
503 ),
504 );
505 $form['fetchgals_settings']['fetchgals_num_download_processes'] = array(
506 '#type' => 'textfield',
507 '#title' => t('Number of Download Processes'),
508 '#default_value' => variable_get('fetchgals_num_download_processes', 8),
509 '#size' => 4,
510 '#description' => t("The number of parallel processes used to download pictures (default:
511 8). This only affects the <strong>-download_pics</strong> action.
512 <p>We use parallel processes because today's cable and DSL internet
513 connections allow much faster downloads than a single porn host can
514 provide. Experiment with this number until your download speeds
515 approach the bandwidth of your internet connection.</p>"
516 ),
517 );
518 $form['fetchgals_settings']['fetchgals_html_dir'] = array(
519 '#type' => 'textfield',
520 '#title' => t('HTML Directory'),
521 '#default_value' => variable_get('fetchgals_html_dir', './porn_html'),
522 '#size' => 50,
523 '#description' => t("The directory where the <strong>-create_html</strong> action creates the HTML files.
524 Defaults to <em>./porn_html</em>. The directory will be created if it
525 doesn't exist. The file <em>index.html</em> in that directory links to the
526 other created HTML files."
527 ),
528 );
529 $form['fetchgals_settings']['fetchgals_thumbs_per_row'] = array(
530 '#type' => 'textfield',
531 '#title' => t('Thumbs Per Row'),
532 '#default_value' => variable_get('fetchgals_thumbs_per_row', 6),
533 '#size' => 4,
534 '#description' => t("The number of thumbnail pictures that will be put in one horizontal
535 row of the resulting HTML file. Defaults to 6. Only used by the
536 <strong>-create_html</strong> action."
537 ),
538 );
539 $form['fetchgals_settings']['fetchgals_rows_per_file'] = array(
540 '#type' => 'textfield',
541 '#title' => t('Number of Rows Per File'),
542 '#default_value' => variable_get('fetchgals_rows_per_file', 10),
543 '#size' => 4,
544 '#description' => t("The number of rows that we be put in each of the resulting HTML files.
545 Defaults to 10. Only used by the <strong>-create_html</strong> action."
546 ),
547 );
548 $form['fetchgals_settings']['fetchgals_processed_html_file'] = array(
549 '#type' => 'textfield',
550 '#title' => t('Processed HTML File'),
551 '#default_value' => variable_get('fetchgals_processed_html_file', './gals_processed_html'),
552 '#size' => 50,
553 '#description' => t("The file where the URLs of galleries are recorded that have been
554 processed with the <strong>-create_html</strong> action. Defaults to
555 <em>./gals_processed_html</em>. This is only used by the <strong>-download_pics</strong>
556 action, to avoid repeated downloads of the same gallery. The file will
557 be created if it doesn't exist."
558 ),
559 );
560 $form['findtgps_settings'] = array(
561 '#type' => 'fieldset',
562 '#title' => t('FindTGPS Settings:'),
563 '#description' => t("<h1><em>Only change these settings if you absolutely know what you're doing!</em></h1>"),
564 '#collapsible' => TRUE,
565 '#collapsed' => TRUE,
566 );
567 $form['findtgps_settings']['findtgps_in'] = array(
568 '#type' => 'textfield',
569 '#title' => t("'In' File"),
570 '#default_value' => variable_get('findtgps_in', './tgps'),
571 '#size' => 50,
572 '#description' => t("<p>Given a file <em>infile</em> containing URLs of TGPs, one per line,
573 <strong>findtgps</strong> will follow links from those TGPs in order to find others.
574 All found TGPs will be stored in <em>outfile</em>. Both <em>infile</em> and
575 <em>outfile</em> have to be specified; they may be identical, but <em>outfile</em>
576 will be overwritten.</p>
577 <p>Along with the URL, <strong>findtgps</strong> will record three numbers in <em>outfile</em>:
578 the number of gallery links that expose the URL, the number of
579 potential gallery links that go through a CGI script, and the number of direct links to galleries. The links through CGI scripts are the most inconvenient to deal with.</p>
580 <p>The purpose of <strong>findtgps</strong> is to create an input file for <em>fetchgals(1)</em>.</p>"
581 ),
582 );
583 $form['findtgps_settings']['findtgps_out'] = array(
584 '#type' => 'textfield',
585 '#title' => t("'Out' File"),
586 '#default_value' => variable_get('findtgps_out', './tgps'),
587 '#size' => 50,
588 '#description' => t("See above."),
589 );
590 $form['findtgps_settings']['findtgps_known_tgps'] = array(
591 '#type' => 'textfield',
592 '#title' => t('Known TGPS'),
593 '#default_value' => variable_get('findtgps_known_tgps', './tgps'),
594 '#size' => 50,
595 '#description' => t("This is a file of known TGPS, one per line, which don't need to be checked again."),
596 );
597 $form['findtgps_settings']['findtgps_link_threshold'] = array(
598 '#type' => 'textfield',
599 '#title' => t('Link Threshold'),
600 '#default_value' => variable_get('findtgps_link_threshold', 30),
601 '#size' => 4,
602 '#description' => t("The number of external links a page needs to contain before we classify it as a TGP. Default is 30."),
603 );
604 $form['findtgps_settings']['findtgps_fraction_followed'] = array(
605 '#type' => 'textfield',
606 '#title' => t('Fraction Followed'),
607 '#default_value' => variable_get('findtgps_fraction_followed', 6),
608 '#size' => 4,
609 '#description' => t("If we have located a TGP, we will follow every <em>num</em>'th link to find
610 new TGPs. Default is 6. One might be inclined to use
611 <strong>-fraction_followed</strong> 1, but this is not advisable since TGPs usually
612 link (through a CGI script) to only a small number of other TGPs."
613 ),
614 );
615 $form['findtgps_settings']['findtgps_threads'] = array(
616 '#type' => 'textfield',
617 '#title' => t('Threads'),
618 '#default_value' => variable_get('findtgps_threads', 8),
619 '#size' => 4,
620 '#description' => t("The number of parallel threads used for the task. Defaults to 8."),
621 );
622 return $form;
623 } // fetchgals_settings
624
625 /**
626 * Displays the administrating screen.
627 */
628 function fetchgals_admin() {
629 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
630 $form['null'] = array(
631 '#type' => 'item',
632 '#description' => t('<h2>A fetchgals process is currently running.</h2>'),
633 );
634 }
635 $form['clean'] = array(
636 '#type' => 'fieldset',
637 '#title' => t('Cleaning Operations:'),
638 '#collapsible' => TRUE,
639 '#collapsed' => TRUE,
640 );
641 $form['clean']['submit6'] = array(
642 '#type' => 'submit',
643 '#value' => t('Clean Galleries File'),
644 );
645 $form['clean']['submit7'] = array(
646 '#type' => 'submit',
647 '#value' => t('Clean Gals Downloaded File'),
648 );
649 $form['clean']['submit8'] = array(
650 '#type' => 'submit',
651 '#value' => t('Clean Gals Processed File'),
652 );
653 $form['clean']['item1'] = array(
654 '#type' => 'item',
655 '#description' => t("<dl><dt><strong><a name=\"item_%2e%2fgalleries\"><em>%var1</em></a></strong></dt>
656 <dd>This file is created by <strong>fetchgals</strong> and contains gallery URLs and
657 corresponding preview thumbnail URLs and descriptive text, one gallery
658 and one thumbnail and one text per line, separated by '|'. The purpose
659 of the file is to record the galleries that have already been found,
660 so that they are not processed again during a later invocation of
661 <strong>fetchgals</strong>. The file's contents may also be useful for other
662 programs. The default file name can be overridden with the
663 <strong>-gallery_file</strong> option.</dd>
664 <p></p>
665 <dt><strong><a name=\"item_%2e%2fgals_downloaded\"><em>%var2</em></a></strong></dt>
666 <dd>This file contains a list of those galleries whose pictures have been
667 completely downloaded to the local computer. This allows to interrupt
668 a download and resume later. Also, if <strong>fetchgals</strong> is run again and
669 finds new galleries, only those not contained in this file will be
670 downloaded by the <strong>-download_pics</strong> option. The default file name can
671 be overridden with the <strong>-processed_downloads_file</strong> option.</dd>
672 <p></p>
673 <dt><strong><a name=\"item_%2e%2fgals_processed_html\"><em>%var3</em></a></strong></dt>
674 <dd>This file contains a list of those galleries for which HTML pages have
675 been created on the local computer. If <strong>fetchgals</strong> is run again and
676 finds new galleries, only those not contained in this file will be
677 processsed by the <strong>-create_html</strong> option. The default file name can be
678 overridden with the <strong>-processed_html_file</strong> option.</dd></dl>",
679 array('%var1' => variable_get('fetchgals_gallery_file', './galleries'),
680 '%var2' => variable_get('fetchgals_processed_downloads_file', './gals_downloaded'),
681 '%var3' => variable_get('fetchgals_processed_html_file', './gals_processed_html')
682 )
683 ),
684 );
685 $form['clean']['submit9'] = array(
686 '#type' => 'submit',
687 '#value' => t('Purge HTML Directory'),
688 );
689 // $form['clean']['submit10'] = array(
690 // '#type' => 'submit',
691 // '#value' => t('Purge Pictures Directory'),
692 // );
693 $form['clean']['item2'] = array(
694 '#type' => 'item',
695 '#description' => t("<dl><dt><strong><a name=\"item_%2dhtml_dir_dir\"><em>%dir1</em></a></strong></dt>
696 <dd>The directory where the <strong>-create_html</strong> action creates the HTML files.
697 Defaults to <em>./porn_html</em>. The directory will be created if it
698 doesn't exist. The file <em>index.html</em> in that directory links to the
699 other created HTML files.</dd></dl>",
700 array('%dir1' => variable_get('fetchgals_html_dir', './porn_html'),
701 '%dir2' => variable_get('fetchgals_pics_dir', './porn_pics'))
702 ),
703 );
704 $form['find_galleries'] = array(
705 '#type' => 'fieldset',
706 );
707 $form['find_galleries']['submit1'] = array(
708 '#type' => 'submit',
709 '#value' => t('Find Galleries'),
710 );
711 $form['find_galleries']['item'] = array(
712 '#type' => 'item',
713 '#description' => t("Reads a list of TGP URLs from the file specified with <strong>-tgp_file</strong>
714 (default: <em>./tgps</em>) and tries to locate all thumbnail galleries
715 that are linked from these TGPs. The URLs of these galleries, together with
716 URLs for preview thumbnails, are then written to the file specified
717 with <strong>-gallery_file</strong> (default: <em>./galleries</em>)."
718 ),
719 );
720 $form['download_pics'] = array(
721 '#type' => 'fieldset',
722 );
723 $form['download_pics']['submit2'] = array(
724 '#type' => 'submit',
725 '#value' => t('Download Pictures'),
726 );
727 $form['download_pics']['item'] = array(
728 '#type' => 'item',
729 '#description' => t("Reads a list of galleries from the file specified with
730 <strong>-gallery_file</strong> (default: <em>./galleries</em>) and downloads all the
731 pictures linked from those galleries. The pictures are stored in the
732 directory specifed with <strong>-pics_dir</strong> (default: <em>./porn_pics</em>).
733 <p>You need to run <strong>-find_galleries</strong> at least once before you can run
734 <strong>-download_pics</strong>.</p>
735 <p>The URLs of the galleries all of whose pictures have been completely
736 downloaded are recorded in the file specified with
737 <strong>-processed_downloads_file</strong> (default: <em>./gals_downloaded</em>). Because
738 of this, the program never downloads the same gallery twice, and it is
739 able to resume a download after it was interrupted.</p>"
740 ),
741 );
742 $form['create_html'] = array(
743 '#type' => 'fieldset',
744 );
745 $form['create_html']['submit3'] = array(
746 '#type' => 'submit',
747 '#value' => t('Create HTML'),
748 );
749 $form['create_html']['item'] = array(
750 '#type' => 'item',
751 '#description' => t("Reads a list of galleries and associated preview thumbnails from the
752 file specified with <strong>-gallery_file</strong> (default: <em>./galleries</em>) and
753 creates a set of HTML files that link to these galleries. The HTML
754 files are created in the directory specified with <strong>-html_dir</strong>
755 (default: <em>./porn_html</em>). Neither the thumbnails nor the galleries
756 are downloaded, so this actions is much faster than <strong>-download_pics</strong>
757 and uses up only very little local storage space.</p>
758 <p>You need to run <strong>-find_galleries</strong> at least once before you can run
759 <strong>-create_html</strong>.</p>
760 <p>The URLs of the galleries for which local HTML files have been created
761 are recorded in the file specified with <strong>-processed_html_file</strong>
762 (default: <em>./gals_processed_html</em>). This is so that the program only
763 produces HTML files for the most recently found galleries.</p>"
764 ),
765 );
766 $form['tgps'] = array(
767 '#type' => 'fieldset',
768 '#title' => t('TGPS File:'),
769 );
770 $form['tgps']['submit4'] = array(
771 '#type' => 'submit',
772 '#value' => t('Execute FindTGPS'),
773 );
774 $form['tgps']['fetchgals_tgps'] = array(
775 '#type' => 'textarea',
776 '#title' => "The main input file, containing TGP URLs, one per line. The ``http://'' is optional. Lines starting with # are ignored",
777 '#default_value' => file_get_contents(fetchgals_check(variable_get('fetchgals_tgp_file', './tgps'))),
778 '#cols' => 80,
779 '#rows' => 150,
780 '#attributes' => is_writeable(fetchgals_check(variable_get('fetchgals_tgp_file', './tgps'))) ? '' : array('disabled' => TRUE),
781 );
782 if (is_writeable(fetchgals_check(variable_get('fetchgals_tgp_file', './tgps')))) {
783 $form['tgps']['submit5'] = array(
784 '#type' => 'submit',
785 '#value' => t('Edit TGPS'),
786 );
787 }
788 $output .= drupal_get_form('fetchgals_admin', $form);
789 return $output;
790 } // fetchgals_admin
791
792 /**
793 * Submit function for fetchgals_admin form
794 */
795 function fetchgals_admin_submit($form_id, $form) {
796 switch ($_POST['op']) {
797 case "Find Galleries":
798 fetchgals_find_galleries();
799 break;
800 case "Download Pictures":
801 fetchgals_download_pics();
802 break;
803 case "Create HTML":
804 fetchgals_create_html();
805 break;
806 case "Execute FindTGPS":
807 fetchgals_findtgps();
808 break;
809 case "Edit TGPS":
810 fetchgals_edit_tgps($form['fetchgals_tgps']);
811 break;
812 case "Clean Galleries File":
813 fetchgals_clean_file(variable_get('fetchgals_gallery_file', './galleries'));
814 break;
815 case "Clean Gals Downloaded File":
816 fetchgals_clean_file(variable_get('fetchgals_processed_downloads_file', './gals_downloaded'));
817 break;
818 case "Clean Gals Processed File":
819 fetchgals_clean_file(variable_get('fetchgals_processed_html_file', './gals_processed_html'));
820 break;
821 case "Purge HTML Directory":
822 fetchgals_clean_dir('html_dir');
823 break;
824 case "Purge Pictures Directory":
825 fetchgals_clean_dir('porn_pics');
826 break;
827 }
828 return;
829 } // fetchgals_admin_submit
830
831 /**
832 * Function to manually edit TGPS file
833 */
834 function fetchgals_edit_tgps($edit) {
835 $output = file_put_contents(fetchgals_check(variable_get('fetchgals_tgp_file', './tgps')), $edit);
836 if (!$output) {
837 drupal_set_message(t('TGPS file update Failed'));
838 }
839 else {
840 drupal_set_message(t('TGPS file successfully updated'));
841 }
842 return;
843 } // fetchgals_edit_tgps
844
845 /**
846 * Creates and submits the find_galleries function
847 */
848 function fetchgals_find_galleries() {
849 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
850 drupal_set_message(t('Another fetchgals process is currently running, please wait for it to finish'), 'error');
851 return;
852 }
853 if (!file_exists(fetchgals_check(variable_get('fetchgals_tgp_file', './tgps')))) {
854 drupal_set_message(t("'%gal' file is missing or not readable by the server", array('%gal' => variable_get('fetchgals_tgp_file', './tgps'))), 'error');
855 return;
856 }
857 $dir = FG_CWD;
858 if (!file_check_directory($dir, FALSE)) {
859 drupal_set_message(t('Fetchgals directory is not writeable for the webserver. Please consult fetchgals/INSTALL.txt.'), 'error');
860 }
861 fetchgals_clear_log();
862 $args = ' -find_galleries';
863 $args .= ' -tgp_file '.fetchgals_check(variable_get('fetchgals_tgp_file', './tgps'));
864 variable_get('fetchgals_extensive_search', 0) ? $args .= ' -extensive_search' : '';
865 variable_get('fetchgals_extensive_search', 0) ? $args .= ' -attempts_per_link '.variable_get('fetchgals_attempts_per_link', 5) : '';
866 variable_get('fetchgals_extensive_search', 0) ? $args .= ' -sleep_time '.variable_get('fetchgals_sleep_time', 7) : '';
867 $args .= ' -gallery_file '.fetchgals_check(variable_get('fetchgals_gallery_file', './galleries'));
868 variable_get('fetchgals_use_cookies', 0) ? $args .= ' -use_cookies' : '';
869 fetchgals_write_log('\'Find Galleries\' process started: '.date(variable_get('date_format_long', 'l, F j, Y - H:i')).'<br />perl '.FG_MAIN.$args.' >> '.FG_CWD.'log & echo $!');
870 $fetchgals_pid = shell_exec('perl '.FG_MAIN.$args.' >> '.FG_CWD.'log & echo $!');
871 if (!$fetchgals_pid) {
872 drupal_set_message(t('Find Galleries Failed'), 'error');
873 }
874 else {
875 drupal_set_message(t('Find Galleries function started'));
876 variable_set('fetchgals_pid', $fetchgals_pid);
877 }
878 return;
879 } // fetchgals_find_galleries
880
881 /**
882 * Creates and submits the download_pics function
883 */
884 function fetchgals_download_pics() {
885 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
886 drupal_set_message(t('Another fetchgals process is currently running, please wait for it to finish'), 'error');
887 return;
888 }
889 if (!file_exists(fetchgals_check(variable_get('fetchgals_gallery_file', './galleries')))) {
890 drupal_set_message(t("'%gal' file is missing, please run 'Find Galleries' first", array('%gal' => variable_get('fetchgals_gallery_file', './galleries'))), 'error');
891 return;
892 }
893 $dir = FG_CWD;
894 if (!file_check_directory($dir, FALSE)) {
895 drupal_set_message(t('Fetchgals directory is not writeable for the webserver. Please consult fetchgals/INSTALL.txt.'), 'error');
896 }
897 fetchgals_clear_log();
898 $args = ' -download_pics';
899 $args .= ' -gallery_file '.fetchgals_check(variable_get('fetchgals_gallery_file', './galleries'));
900 $args .= ' -pics_dir '.fetchgals_check(variable_get('fetchgals_pics_dir', './porn_pics'));
901 $args .= ' -processed_downloads_file '.fetchgals_check(variable_get('fetchgals_processed_downloads_file', './gals_downloaded'));
902 $args .= ' -types "'.variable_get('fetchgals_types', 'jpg|jpeg|gif|png|mpg|mpeg|avi|asf|mov|wmv').'"';
903 $args .= ' -min_img_size '.variable_get('fetchgals_min_img_size', 15000);
904 $args .= ' -max_img_size '.variable_get('fetchgals_max_img_size', 250000);
905 $args .= ' -max_disk_usage '.variable_get('fetchgals_max_disk_usage', 95);
906 $args .= ' -pic_file_template '.variable_get('fetchgals_pic_file_template', '%i/%h-%p-%n%e');
907 $args .= ' -num_download_processes '.variable_get('fetchgals_num_download_processes', 8);
908 $args .= ' -processed_html_file '.fetchgals_check(variable_get('fetchgals_processed_html_file', './gals_processed_html'));
909 fetchgals_write_log('\'Download Pictures\' process started: '.date(variable_get('date_format_long', 'l, F j, Y - H:i')).'<br />perl '.FG_MAIN.$args.' >> '.FG_CWD.'log & echo $!');
910 $fetchgals_pid = shell_exec('perl '.FG_MAIN.$args.' >> '.FG_CWD.'log & echo $!');
911 if (!$fetchgals_pid) {
912 drupal_set_message(t('Download Pictures Failed'), 'error');
913 }
914 else {
915 drupal_set_message(t('Download Pictures function started'));
916 variable_set('fetchgals_pid', $fetchgals_pid);
917 }
918 return;
919 } // fetchgals_download_pics
920
921 /**
922 * Creates and submits the create_html function
923 */
924 function fetchgals_create_html() {
925 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
926 drupal_set_message(t('Another fetchgals process is currently running, please wait for it to finish'), 'error');
927 return;
928 }
929 if (!file_exists(fetchgals_check(variable_get('fetchgals_gallery_file', './galleries')))) {
930 drupal_set_message(t("'%gal' file is missing, please run 'Find Galleries' first", array('%gal' => variable_get('fetchgals_gallery_file', './galleries'))), 'error');
931 return;
932 }
933 $dir = FG_CWD;
934 if (!file_check_directory($dir, FALSE)) {
935 drupal_set_message(t('Fetchgals directory is not writeable for the webserver. Please consult fetchgals/INSTALL.txt.'), 'error');
936 }
937 fetchgals_clear_log();
938 $args = ' -create_html';
939 $args .= ' -gallery_file '.fetchgals_check(variable_get('fetchgals_gallery_file', './galleries'));
940 $args .= ' -html_dir '.fetchgals_check(variable_get('fetchgals_html_dir', './porn_html'));
941 $args .= ' -thumbs_per_row '.variable_get('fetchgals_thumbs_per_row', 6);
942 $args .= ' -rows_per_file '.variable_get('fetchgals_rows_per_file', 10);
943 $args .= ' -processed_html_file '.fetchgals_check(variable_get('fetchgals_processed_html_file', './gals_processed_html'));
944 fetchgals_write_log('\'Create HTML\' process started: '.date(variable_get('date_format_long', 'l, F j, Y - H:i')).'<br />perl '.FG_MAIN.$args.' >> '.FG_CWD.'log & echo $!');
945 $fetchgals_pid = shell_exec('perl '.FG_MAIN.$args.' >> '.FG_CWD.'log & echo $!');
946 if (!$fetchgals_pid) {
947 drupal_set_message(t('Create HTML Failed'), 'error');
948 }
949 else {
950 drupal_set_message(t('Create HTML function started'));
951 variable_set('fetchgals_pid', $fetchgals_pid);
952 }
953 return;
954 } // fetchgals_create_html
955
956 /**
957 * Replaces ./ with the full path
958 */
959 function fetchgals_check($input) {
960 if (strpos($input, './') === 0) {
961 $input = FG_CWD.substr($input, 2);
962 }
963 return $input;
964 } // fetchgals_check
965
966 /**
967 * Executes the findtgps program
968 */
969 function fetchgals_findtgps() {
970 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
971 drupal_set_message(t('Another fetchgals process is currently running, please wait for it to finish'), 'error');
972 return;
973 }
974 if (!file_exists(fetchgals_check(variable_get('findtgps_in', './tgps')))) {
975 drupal_set_message(t("'%gal' file is missing or not readable by the server", array('%gal' => variable_get('findtgps_in', './tgps'))), 'error');
976 return;
977 }
978 $dir = FG_CWD;
979 if (!file_check_directory($dir, FALSE)) {
980 drupal_set_message(t('Fetchgals directory is not writeable for the webserver. Please consult fetchgals/INSTALL.txt.'), 'error');
981 }
982 fetchgals_clear_log();
983 $args = ' -in '.fetchgals_check(variable_get('findtgps_in', './tgps'));
984 $args .= ' -out '.fetchgals_check(variable_get('findtgps_out', './tgps'));
985 $args .= ' -known_tgps '.fetchgals_check(variable_get('findtgps_known_tgps', './tgps'));
986 $args .= ' -link_threshold '.variable_get('findtgps_link_threshold', 30);
987 $args .= ' -fraction_followed '.variable_get('findtgps_fraction_followed', 6);
988 $args .= ' -threads '.variable_get('findtgps_threads', 8);
989 fetchgals_write_log('\'Find TGPS\' process started: '.date(variable_get('date_format_long', 'l, F j, Y - H:i')).'<br />perl '.FG_TGPS.$args.' >> '.FG_CWD.'log & echo $!');
990 $fetchgals_pid = shell_exec('perl '.FG_TGPS.$args.' >> '.FG_CWD.'log & echo $!');
991 if (!$fetchgals_pid) {
992 drupal_set_message(t('FindTGPS Failed'), 'error');
993 }
994 else {
995 drupal_set_message(t('FindTGPS function started'));
996 variable_set('fetchgals_pid', $fetchgals_pid);
997 }
998 return;
999 } // fetchgals_findtgps
1000
1001 /**
1002 * View the created pages
1003 */
1004 function fetchgals_view($page = '') {
1005 unset($flag);
1006 if (!$page) {
1007 $page = 'index.html';
1008 $flag = TRUE;
1009 }
1010 $output = file_get_contents(fetchgals_check(variable_get('fetchgals_html_dir', './porn_html')).'/'.$page);
1011 if (!$output) {
1012 drupal_set_message(t('Fetchgals HTML files do not exist.'), 'error');
1013 watchdog('fetchgals', t('Fetchgals HTML files do not exist.'), WATCHDOG_ERROR);
1014 return FALSE;
1015 }
1016 if ($flag) {
1017 $output = str_replace('<li><a href="', '<li><a href="fetchgals/', $output);
1018 }
1019 return $output;
1020 } // fetchgals_view
1021
1022 /**
1023 * Empties the log file
1024 */
1025 function fetchgals_clear_log() {
1026 $output = file_put_contents(FG_CWD.'log', '');
1027 return;
1028 } // fetchgals_clear_log
1029
1030 /**
1031 * Writes to the log file
1032 */
1033 function fetchgals_write_log($log) {
1034 $output = file_put_contents(FG_CWD.'log', $log.'<p>');
1035 return;
1036 } // fetchgals_write_log
1037
1038 /**
1039 * Verifies if a process is running in linux
1040 */
1041 function fetchgals_process($PID) {
1042 exec("ps $PID", $ProcessState);
1043 return(count($ProcessState) >= 2);
1044 } // fetchgals_process
1045
1046 /**
1047 * Views the log file
1048 */
1049 function fetchgals_log() {
1050 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
1051 $form['process'] = array(
1052 '#type' => 'item',
1053 '#description' => t('<h2>A fetchgals process is currently running, please refresh your browser to update any changes in your log.</h2>'),
1054 );
1055 }
1056 else {
1057 $form['process'] = array(
1058 '#type' => 'item',
1059 '#description' => t('<h2>No fetchgals processes currently running.</h2>'),
1060 );
1061 }
1062 $form['fetchgals_log'] = array(
1063 '#type' => 'fieldset',
1064 '#title' => t('Log File:'),
1065 );
1066 $form['fetchgals_log']['null'] = array(
1067 '#type' => 'item',
1068 '#description' => file_get_contents(FG_CWD.'log'),
1069 );
1070 return drupal_get_form('fetchgals_log', $form);
1071 } // fetchgals_log
1072
1073 /**
1074 * Implementation of hook_cron().
1075 */
1076 function fetchgals_cron() {
1077 if (!variable_get('fetchgals_cron', 0)) {
1078 return;
1079 }
1080 if (variable_get('fetchgals_clean', 604800)) {
1081 if ((variable_get('fetchgals_updated_clean', 0) + variable_get('fetchgals_clean', 604800)) <= mktime(variable_get('fetchgals_timecron', 3), 0, 0)) {
1082 fetchgals_clean_dir('html_dir');
1083 variable_set('fetchgals_updated_clean', mktime(variable_get('fetchgals_timecron', 3), 0, 0));
1084 }
1085 }
1086 if (variable_get('fetchgals_fetch', 86400)) {
1087 if ((variable_get('fetchgals_updated_fetch', 0) + variable_get('fetchgals_fetch', 86400)) <= mktime(variable_get('fetchgals_timecron', 3), 0, 0)) {
1088 fetchgals_update();
1089 variable_set('fetchgals_updated_fetch', mktime(variable_get('fetchgals_timecron', 3), 0, 0));
1090 }
1091 }
1092 return;
1093 } // fetchgals_cron
1094
1095 /**
1096 * Runs both -find_galleries and -create_html automatically for the cron (if set)
1097 */
1098 function fetchgals_update() {
1099 if (fetchgals_process(variable_get('fetchgals_pid', 0))) {
1100 watchdog('fetchgals', t('Cannot complete cron as another fetchgals process is currently running.'), WATCHDOG_ERROR);
1101 return;
1102 }
1103 if (!file_exists(fetchgals_check(variable_get('fetchgals_tgp_file', './tgps')))) {
1104 watchdog('fetchgals', t("Cannot complete cron as '%gal' file is missing or not readable by the server", array('%gal' => variable_get('fetchgals_tgp_file', './tgps'))), WATCHDOG_ERROR);
1105 return;
1106 }
1107 if (!file_exists(fetchgals_check(variable_get('fetchgals_gallery_file', './galleries')))) {
1108 watchdog('fetchgals', t</