-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-common.php
75 lines (69 loc) · 2.18 KB
/
class-common.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
<?php
namespace photo_express;
if (!class_exists("Common")) {
class Common
{
/**
* Escape quotes to html entinty
*
* @param <type> $str
* @return <type>
*/
static function escape($str)
{
$str = preg_replace('/"/', '"', $str);
$str = preg_replace("/'/", ''', $str);
return $str;
}
/**
* Find tag in content
*
* @param string $content
* @param string $tag
* @param boolean $first Search only first. False by default
* @return bool|string|array content of the found node. false if not found
*/
static function get_item($content, $tag, $first = false)
{
if (!preg_match_all("|<$tag(?:\s[^>]+)?>(.+?)</$tag>|u", $content, $m, PREG_PATTERN_ORDER))
return false;
// echo "$tag: ".count($m[1])."<br/>";
if (count($m[1]) > 1 && !$first) return ($m[1]);
else return ($m[1][0]);
}
/**
* Find tag in content by attribute
*
* @param string $content
* @param string $tag
* @param string $attr
* @return string attribute value or all parameters if not found. false if no tag found
*/
static function get_item_attr($content, $tag, $attr)
{
if (!preg_match("|<$tag\s+([^>]+)/?>|u", $content, $m))
return false;
$a = preg_split("/[\s=]/", $m[1]);
for ($i = 0; $i < count($a); $i += 2) {
if ($a[$i] == $attr) return trim($a[$i + 1], "'\" ");
}
return join(',', $a);
}
/**
* Make the row from parameters for setting tables
*/
static function make_settings_row($title, $content, $description = '', $title_pars = '', $description_pars = '')
{
?>
<tr <?php echo $title_pars; ?>>
<th scope="row"><?php echo $title; ?></th>
<td>
<?php echo $content; ?>
<br/>
<span class="description" <?php echo $description_pars; ?>><?php echo $description; ?></span>
</td>
</tr>
<?php
}
}
}