From 8c39c698908b15fccceaed9c7d92dfa2fead8d3e Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Fri, 30 May 2008 23:04:58 +0200 Subject: [PATCH] Can define perms required to view a post... need to plug it on the public interface Signed-off-by: Florent Bruneau --- _admin.php | 12 ++++++++ class.xorg.auth.php | 2 -- widget.post.perms.php | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 widget.post.perms.php diff --git a/_admin.php b/_admin.php index f175526..9007044 100644 --- a/_admin.php +++ b/_admin.php @@ -1,5 +1,17 @@ addBehavior('initWidgets', array('xorgAuthWidget', 'behavior_initWidgets')); + +/* Declare stuff to set permissions on each post */ +$core->addBehavior('adminPostFormSidebar', array('xorgPostPermsWidget', 'behavior_adminPostFormSidebar')); +$core->addBehavior('adminBeforePostCreate', array('xorgPostPermsWidget', 'behavior_adminBeforePostCreate')); +$core->addBehavior('adminBeforePostUpdate', array('xorgPostPermsWidget', 'behavior_adminBeforePostUpdate')); + +/* Stuff to set user preferences about post permissions */ +$core->addBehavior('adminPreferencesForm', array('xorgPostPermsWidget', 'behavior_adminPreferencesForm')); +$core->addBehavior('adminBeforeUserUpdate', array('xorgPostPermsWidget', 'behavior_adminBeforeUserUpdate')); + ?> diff --git a/class.xorg.auth.php b/class.xorg.auth.php index 8cbee75..d7e4391 100644 --- a/class.xorg.auth.php +++ b/class.xorg.auth.php @@ -1,7 +1,5 @@ array('text' => 'Visible par tous', + 'selected' => false), + 'auth' => array('text' => 'Visible par les X', + 'selected' => false)); + $pos = 'public'; + if (!is_null($post)) { + $metas = unserialize($post->field('post_meta')); + if (isset($metas['post_xorg_perms'])) { + $pos = $metas['post_xorg_perms']; + } + } else { + global $core; + $pos = $core->auth->getOption('post_xorg_perms'); + if ($pos && !isset($choices[$pos])) { + $pos = 'auth'; + } + } + $choices[$pos]['selected'] = true; + echo '

'; + } + + private static function setPermsMeta(&$cur) { + $meta = $cur->getField('post_meta'); + if (is_string($meta)) { + $meta = unserialize($meta); + } + if (!is_array($meta)) { + $meta = array(); + } + $meta['post_xorg_perms'] = $_POST['post_xorg_perms']; + $cur->setField('post_meta', serialize($meta)); + } + + public static function behavior_adminBeforePostCreate(&$cur) { + self::setPermsMeta($cur); + } + + public static function behavior_adminBeforePostUpdate(&$cur, $post_id) { + self::setPermsMeta($cur); + } + + + public static function behavior_adminPreferencesForm($core) { + $levels = array('public' => array('text' => 'Visible par tous', + 'selected' => false), + 'auth' => array('text' => 'Visible par les X', + 'selected' => false), + 'group' => array('text' => 'Visible par les membres du groupe (1)', + 'selected' => false)); + $pos = $core->auth->getOption('post_xorg_perms'); + if (!$pos || !isset($levels[$pos])) { + $pos = 'public'; + } + $levels[$pos]['selected'] = true; + echo '

'; + } + + public static function behavior_adminBeforeUserUpdate(&$cur, $user_id) { + $opts = $cur->getField('user_options'); + $opts['post_xorg_perms'] = $_POST['post_xorg_perms']; + $cur->setField('user_options', $opts); + } +} +?> -- 2.1.4