-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmozila_get_extension_info.php
executable file
·85 lines (71 loc) · 2.22 KB
/
mozila_get_extension_info.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
#!/usr/bin/php -q
<?
include_once('Debug/debug.php');
include_once('Vars/Consts/consts.php');
if (empty($argv[1])){
exit ("Необходимо имя файла (URL) для обработки!\n");
}
$iFILE = $argv[1];
#$iFILE='test.htm';
#$iFILE='info.first.htm.ORIG';
#$oFILE='test.phpres.htm';
$t = new tidy($iFILE, array("wrap" => 0), 'utf8');
$t->cleanRepair();
#Search: <div class="addon-feature-text">
$tBodyNode = $t->body();
//dump::c($tBodyNode);
//c_dump($tBodyNode->child);
//c_dump(consts::get_regexp('tidy', '#TIDY_NODETYPE#'));
//c_dump(consts::get_regexp('tidy', '#TIDY_TAG#'));
//c_dump(consts::get('TIDY_TAG_DIV')); #30
//exit();
/**
* As prototype gets get_nodes2 from comments: http://ru2.php.net/manual/ru/function.tidy-node-get-nodes.php
* Modified.
* array $attributes - array of 'Key' => value attribitus, which must be in tag
**/
function tidy_get_nodes_recursive($node, $type, array $attributes, &$result){
if($node != null){
if (
@$node->id == $type
and ! empty ($attributes)
and count ($attributes) == count (array_intersect_assoc ($attributes, (array)$node->attribute))
) $result[] = $node;
if ($node->child != null){
foreach($node->child as $child){
tidy_get_nodes_recursive($child, $type, $attributes, $result);
}
}
}
}
//get_nodes_recursive($tBodyNode, TIDY_TAG_DIV, array('name' => 'test'), $divs);
#Предполагаем что это addons.mozilla.org
//tidy_get_nodes_recursive($tBodyNode, TIDY_TAG_DIV, array('class' => 'addon-feature-text'), $divs);
tidy_get_nodes_recursive($tBodyNode, TIDY_TAG_P, array('class' => 'desc'), $divs);
//c_dump($divs);
#>0 if found
//c_dump(count($divs));
//c_dump($divs[0]->value);
if (empty($divs)){//Пердположим тогда что forum.mozilla-russia.org
tidy_get_nodes_recursive($tBodyNode, TIDY_TAG_DIV, array('class' => 'postmsg'), $divs);
}
if (! empty($divs) ){#Found
echo(
preg_replace(
array('#<br.*?>#i', '#<.*?>#')
,array('', '')
,$divs[0]->value
)
);
}
else{
exit('Упппс. Требуемого блока не найдено!');
}
//$img_nodes = $tBodyNode->getNodes(TIDY_TAG_DIV);
/*
if ($t->errorBuffer) {
echo "The following errors were detected:\n";
echo $t->errorBuffer;
}
*/
?>