-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path09.php
51 lines (40 loc) · 1.25 KB
/
09.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
<?php
use Symfony\Component\DomCrawler\Crawler;
require __DIR__ . '/vendor/autoload.php';
function first($array) {
return reset($array);
}
function normalizeUrl($url) {
return 'http://yiiframework.ru/forum/'. ltrim($url, './');
}
function getHtml($url) {
return file_get_contents(normalizeUrl($url));
}
function clearUrl($url) {
return preg_replace('#\&sid=.{32}#s', '', $url);
}
function getForumMaxPageNumber($forumUrl) {
echo 'Max page num for ' . clearUrl($forumUrl) . PHP_EOL;
$html = getHtml($forumUrl);
$crawler = new Crawler($html);
return max(
first($crawler
->filter('div.action-bar.bar-top .pagination li:nth-last-of-type(2)')
->each(function (Crawler $link) {
return intval($link->text());
})),
1
);
}
function getForumPages($forumUrl) {
echo 'Forum pages for ' . clearUrl($forumUrl) . PHP_EOL;
$getMaxPageNumber = getForumMaxPageNumber($forumUrl);
$result = [];
foreach (range(1, $getMaxPageNumber) as $number) {
$result[] = $forumUrl . ($number > 1 ? '&start=' . (25 * ($number - 1)) : '');
}
return $result;
}
$forumUrl = './viewforum.php?f=28';
echo clearUrl(print_r(getForumPages($forumUrl), true));
echo PHP_EOL;