Can define perms required to view a post... need to plug it on the public interface
[dotclear.git] / widget.post.perms.php
CommitLineData
8c39c698
FB
1<?php
2
3class 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&nbsp;:'
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&nbsp;:'
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 }
82}
83?>