Commit | Line | Data |
---|---|---|
8c39c698 FB |
1 | <?php |
2 | ||
3 | class xorgPostPermsWidget { | |
4 | public static function behavior_adminPostFormSidebar($post) { | |
5 | $choices = array('public' => array('text' => 'Visible par tous', | |
6 | 'selected' => false), | |
7 | 'auth' => array('text' => 'Visible par les X', | |
8 | 'selected' => false)); | |
9 | $pos = 'public'; | |
10 | if (!is_null($post)) { | |
11 | $metas = unserialize($post->field('post_meta')); | |
12 | if (isset($metas['post_xorg_perms'])) { | |
13 | $pos = $metas['post_xorg_perms']; | |
14 | } | |
15 | } else { | |
16 | global $core; | |
17 | $pos = $core->auth->getOption('post_xorg_perms'); | |
18 | if ($pos && !isset($choices[$pos])) { | |
19 | $pos = 'auth'; | |
20 | } | |
21 | } | |
22 | $choices[$pos]['selected'] = true; | |
23 | echo '<p><label>Visibilité du billet :' | |
24 | . ' <select name="post_xorg_perms">'; | |
25 | foreach ($choices as $val => $fields) { | |
26 | echo '<option value="' . $val . '"' . ($fields['selected'] ? ' selected="selected"' : '') . '>' | |
27 | . $fields['text'] . '</option>'; | |
28 | } | |
29 | echo ' </select>' | |
30 | . '</label></p>'; | |
31 | } | |
32 | ||
33 | private static function setPermsMeta(&$cur) { | |
34 | $meta = $cur->getField('post_meta'); | |
35 | if (is_string($meta)) { | |
36 | $meta = unserialize($meta); | |
37 | } | |
38 | if (!is_array($meta)) { | |
39 | $meta = array(); | |
40 | } | |
41 | $meta['post_xorg_perms'] = $_POST['post_xorg_perms']; | |
42 | $cur->setField('post_meta', serialize($meta)); | |
43 | } | |
44 | ||
45 | public static function behavior_adminBeforePostCreate(&$cur) { | |
46 | self::setPermsMeta($cur); | |
47 | } | |
48 | ||
49 | public static function behavior_adminBeforePostUpdate(&$cur, $post_id) { | |
50 | self::setPermsMeta($cur); | |
51 | } | |
52 | ||
53 | ||
54 | public static function behavior_adminPreferencesForm($core) { | |
55 | $levels = array('public' => array('text' => 'Visible par tous', | |
56 | 'selected' => false), | |
57 | 'auth' => array('text' => 'Visible par les X', | |
58 | 'selected' => false), | |
59 | 'group' => array('text' => 'Visible par les membres du groupe (1)', | |
60 | 'selected' => false)); | |
61 | $pos = $core->auth->getOption('post_xorg_perms'); | |
62 | if (!$pos || !isset($levels[$pos])) { | |
63 | $pos = 'public'; | |
64 | } | |
65 | $levels[$pos]['selected'] = true; | |
66 | echo '<p><label>Visibilité nouveaux billets par défaut :' | |
67 | . ' <select name="post_xorg_perms">'; | |
68 | foreach ($levels as $key => $fields) { | |
69 | echo '<option value="' . $key . '"' . ($fields['selected'] ? ' selected="selected"' : '') . '>' | |
70 | . $fields['text'] . '</option>'; | |
71 | } | |
72 | echo '</select>' | |
73 | . '(1) Ne concerne que les blogs de groupes X. Equivaut à "Visible par les X" sur les autres blogs"' | |
74 | . '</label></p>'; | |
75 | } | |
76 | ||
77 | public static function behavior_adminBeforeUserUpdate(&$cur, $user_id) { | |
78 | $opts = $cur->getField('user_options'); | |
79 | $opts['post_xorg_perms'] = $_POST['post_xorg_perms']; | |
80 | $cur->setField('user_options', $opts); | |
81 | } | |
d387689d FB |
82 | |
83 | public static function behavior_coreBlogGetPosts(&$rs) { | |
84 | $rs->extend('xorgPostPermsFilter'); | |
85 | } | |
86 | ||
87 | /* public static function behavior_coreBlogGetComments(&$rs) { | |
88 | $rs->extends('xorgCommentPermsFilter'); | |
89 | }*/ | |
90 | } | |
91 | ||
92 | if (class_exists('rsExtPostPublic')) { | |
93 | ||
94 | class xorgPostPermsFilter extends rsExtPostPublic { | |
95 | private static function canRead(&$rs) { | |
96 | $metas = unserialize($rs->field('post_meta')); | |
97 | global $core; | |
98 | if (!isset($metas['post_xorg_perms'])) { | |
99 | return true; | |
100 | } elseif ($metas['post_xorg_perms'] == 'public') { | |
101 | return true; | |
102 | } elseif ($metas['post_xorg_perms'] == 'auth' && $core->auth->userID()) { | |
103 | return true; | |
104 | } elseif ($metas['post_xorg_perms'] == 'group' && $core->auth->getInfo('xorg_group_member')) { | |
105 | return true; | |
106 | } | |
107 | return false; | |
108 | } | |
109 | ||
110 | public static function getContent(&$rs, $absolute_urls = false) { | |
111 | if (self::canRead($rs)) { | |
112 | return parent::getContent(&$rs, $absolute_urls); | |
113 | } else if (!self::isExtended($rs)) { | |
f33c2acf | 114 | return '<p class="error">Vous n\'avez pas les droits suffisants pour lire ce billet</p>'; |
d387689d FB |
115 | } else { |
116 | return null; | |
117 | } | |
118 | } | |
119 | ||
120 | public static function getExcerpt(&$rs, $absolute_urls = false) { | |
121 | if (self::canRead($rs)) { | |
122 | return parent::getContent(&$rs, $absolute_urls); | |
123 | } else if (self::isExtended($rs)) { | |
f33c2acf | 124 | return '<p class="error">Vous n\'avez pas les droits suffisants pour lire ce billet</p>'; |
d387689d FB |
125 | } else { |
126 | return null; | |
127 | } | |
128 | } | |
129 | ||
130 | public static function commentsActive(&$rs) { | |
131 | return self::canRead($rs) && parent::commentsActive($rs); | |
132 | } | |
133 | ||
134 | public static function trackbacksActive(&$rs) { | |
135 | return self::canRead($rs) && parent::trackbacksActive($rs); | |
136 | } | |
137 | ||
138 | public static function hasComments(&$rs) { | |
139 | return self::canRead($rs) && parent::hasComments($rs); | |
140 | } | |
141 | } | |
8c39c698 FB |
142 | } |
143 | ?> |