1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of Newsletter, a plugin for Dotclear. |
---|
4 | # |
---|
5 | # Copyright (c) 2009 Benoit de Marne |
---|
6 | # benoit.de.marne@gmail.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | class newsletterTools |
---|
14 | { |
---|
15 | |
---|
16 | /** |
---|
17 | * encodage en base64 pour une url |
---|
18 | */ |
---|
19 | public static function base64_url_encode($val) |
---|
20 | { |
---|
21 | return strtr(base64_encode($val), '+/=', '-_,'); |
---|
22 | } |
---|
23 | |
---|
24 | /** |
---|
25 | * decodage en base64 pour une url |
---|
26 | */ |
---|
27 | public static function base64_url_decode($val) |
---|
28 | { |
---|
29 | return base64_decode(strtr($val, '-_,', '+/=')); |
---|
30 | } |
---|
31 | |
---|
32 | /** |
---|
33 | * génère un code d'enregistrement |
---|
34 | */ |
---|
35 | public static function regcode() |
---|
36 | { |
---|
37 | return md5(date('Y-m-d H:i:s', strtotime("now")) ); |
---|
38 | } |
---|
39 | |
---|
40 | // use by : NewsletterFormRandom |
---|
41 | public static function getRandom() |
---|
42 | { |
---|
43 | list($usec, $sec) = explode(' ', microtime()); |
---|
44 | $seed = (float) $sec + ((float) $usec * 100000); |
---|
45 | mt_srand($seed); |
---|
46 | return mt_rand(); |
---|
47 | } |
---|
48 | |
---|
49 | // surcharge de la fonction cutString pour avoir un extrait d'un texte |
---|
50 | public static function cutString($str,$maxlength=false) |
---|
51 | { |
---|
52 | if (mb_strlen($str) > $maxlength && $maxlength) { |
---|
53 | return text::cutString($str,$maxlength).'...'; |
---|
54 | } else { |
---|
55 | return $str; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | // redirection |
---|
60 | public static function redirection($module='subscribers',$msg='') |
---|
61 | { |
---|
62 | $redir = 'plugin.php?p=newsletter'; |
---|
63 | |
---|
64 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
65 | { |
---|
66 | $redir = $_POST['redir']; |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | $redir .= '&m='.$module. |
---|
71 | ($_POST['sortby'] ? '&sortby='.$_POST['sortby'] : '' ). |
---|
72 | ($_POST['order'] ? '&order='.$_POST['order'] : '' ). |
---|
73 | ($_POST['page'] ? '&page='.$_POST['page'] : '' ). |
---|
74 | ($_POST['nb'] ? '&nb='.(integer) $_POST['nb'] : '' ). |
---|
75 | '&msg='.rawurldecode($msg); |
---|
76 | } |
---|
77 | http::redirect($redir); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | // recherche si le template existe dans le theme |
---|
82 | public static function requestTemplate(dcCore $core, $filename) |
---|
83 | { |
---|
84 | if (file_exists(path::real($core->blog->themes_path.'/'.$core->blog->settings->theme).'/tpl/'.$filename)) |
---|
85 | $folder = path::real($core->blog->themes_path.'/'.$core->blog->settings->theme).'/tpl/'; |
---|
86 | else |
---|
87 | $folder = path::real(newsletterPlugin::folder().'..').'/default-templates/'; |
---|
88 | return $folder; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | ?> |
---|