]> git.agnieray.net Git - galette.git/blob - galette/includes/functions.inc.php
Fix name (sorry)
[galette.git] / galette / includes / functions.inc.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Utilities functions
7 *
8 * PHP version 5
9 *
10 * Copyright © 2003-2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Functions
28 * @package Galette
29 *
30 * @author Frédéric Jacquot <unknown@unknow.com>
31 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
32 * @author Johan Cwiklinski <johan@x-tnd.be>
33 * @copyright 2003-2014 The Galette Team
34 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
35 * @link http://galette.tuxfamily.org
36 */
37
38 if (!defined('GALETTE_ROOT')) {
39 die("Sorry. You can't access directly to this file");
40 }
41
42 use Analog\Analog;
43
44 /**
45 * Check URL validity
46 *
47 * @param string $url The URL to check
48 *
49 * @return boolean
50 */
51 function isValidWebUrl($url)
52 {
53 return (preg_match(
54 '#^http[s]?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i',
55 $url
56 ));
57 }
58
59 /**
60 * Custom HTML entitiy decode
61 *
62 * @param string $given_html Original HTML
63 * @param int $quote_style Quoting style
64 *
65 * @return string
66 */
67 function custom_html_entity_decode($given_html, $quote_style = ENT_QUOTES)
68 {
69 $trans_table = array_flip(
70 get_html_translation_table(
71 HTML_ENTITIES,
72 $quote_style
73 )
74 );
75 $trans_table['&#39;'] = "'";
76 return strtr($given_html, $trans_table);
77 }
78
79 /**
80 * Get a value sent by a form, either in POST and GET arrays
81 *
82 * @param string $name property name
83 * @param string $defval default rollback value
84 *
85 * @return string value retrieved from :
86 * - GET array if defined and numeric,
87 * - POST array if defined and numéric
88 * - $defval otherwise
89 */
90 function get_form_value($name, $defval)
91 {
92 $val = $defval;
93 if (isset($_GET[$name])) {
94 $val = $_GET[$name];
95 } elseif (isset($_POST[$name])) {
96 $val = $_POST[$name];
97 }
98 return $val;
99 }
100
101 /**
102 * Get a numeric value sent by a form, either in POST and GET arrays
103 *
104 * @param string $name property name
105 * @param string $defval default rollback value
106 *
107 * @return numeric value retrieved from :
108 * - GET array if defined and numeric,
109 * - POST array if defined and numéric
110 * - $defval otherwise
111 */
112 function get_numeric_form_value($name, $defval)
113 {
114 $val = get_form_value($name, $defval);
115 if (!is_numeric($val)) {
116 Analog::log(
117 '[get_numeric_form_value] not a numeric value! (value was: `' .
118 $val . '`)',
119 Analog::INFO
120 );
121 $val = $defval;
122 }
123 return $val;
124 }
125
126 /**
127 * Get a post numeric value
128 *
129 * @param string $name property name
130 * @param string $defval default rollback value
131 *
132 * @return string value retrieved from :
133 * - POST array if defined and numéric
134 * - $defval otherwise
135 */
136 function get_numeric_posted_value($name, $defval)
137 {
138 if (isset($_POST[$name])) {
139 $val = $_POST[$name];
140 if (is_numeric($val)) {
141 return $val;
142 }
143 }
144 return $defval;
145 }