]> git.mjollnir.org Git - s9y.git/commitdiff
Commit Falk's patch to show password forms
authorgarvinhicking <garvinhicking>
Tue, 4 Jul 2006 09:10:57 +0000 (09:10 +0000)
committergarvinhicking <garvinhicking>
Tue, 4 Jul 2006 09:10:57 +0000 (09:10 +0000)
docs/NEWS
plugins/serendipity_event_entryproperties/serendipity_event_entryproperties.php

index 2bc27c0fea6c23c80510b6aaadcedc6c93aa614a..6428da925df4367a273d85714006ff3234ec9f1a 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 1.1-alpha7()
 ------------------------------------------------------------------------
 
+    * Add patch to allow entryproperties plugin to define passwords for
+      specific entries (Falk Döring)
+
     * Made smarty function "serendipity_printComments" accept to new
       parameters: "order" (ASC/DESC) and "limit" (garvinhicking)
 
index 31b7708096a9084ccdec1fce4d56c1f74b4ccfe4..4d230686f8e0aed387f726ef40721925b57f3dd1 100644 (file)
@@ -10,7 +10,7 @@ include dirname(__FILE__) . '/lang_en.inc.php';
 
 class serendipity_event_entryproperties extends serendipity_event
 {
-    var $services;
+    var $services, $showPasswordForm;
     var $title = PLUGIN_EVENT_ENTRYPROPERTIES_TITLE;
 
     function introspect(&$propbag)
@@ -21,7 +21,7 @@ class serendipity_event_entryproperties extends serendipity_event
         $propbag->add('description',   PLUGIN_EVENT_ENTRYPROPERTIES_DESC);
         $propbag->add('stackable',     false);
         $propbag->add('author',        'Garvin Hicking');
-        $propbag->add('version',       '1.10');
+        $propbag->add('version',       '1.11');
         $propbag->add('requirements',  array(
             'serendipity' => '0.8',
             'smarty'      => '2.6.7',
@@ -35,6 +35,7 @@ class serendipity_event_entryproperties extends serendipity_event
             'backend_display'                                   => true,
             'backend_import_entry'                              => true,
             'entry_display'                                     => true,
+            'entries_header'                                    => true,
             'frontend_entryproperties'                          => true,
             'backend_sidebar_entries_event_display_buildcache'  => true,
             'backend_sidebar_entries'                           => true,
@@ -43,7 +44,8 @@ class serendipity_event_entryproperties extends serendipity_event
             'backend_plugins_new_instance'                      => true,
             'frontend_entryproperties_query'                    => true,
             'frontend_entries_rss'                              => true,
-            'backend_entry_presave'                             => true
+            'backend_entry_presave'                             => true,
+            'frontend_configure'                                => true
         ));
         $propbag->add('groups', array('BACKEND_EDITOR'));
         $propbag->add('configuration', array('cache', 'use_groups', 'use_users', 'default_read', 'customfields'));
@@ -136,7 +138,7 @@ class serendipity_event_entryproperties extends serendipity_event
         static $supported_properties = null;
 
         if ($supported_properties === null) {
-            $supported_properties = array('is_sticky', 'access', 'access_groups', 'access_users', 'cache_body', 'cache_extended', 'no_frontpage', 'hiderss');
+            $supported_properties = array('is_sticky', 'access', 'access_groups', 'access_users', 'cache_body', 'cache_extended', 'no_frontpage', 'hiderss', 'password');
 
             $fields = explode(',', trim($this->get_config('customfields')));
             if (is_array($fields) && count($fields) > 0) {
@@ -209,6 +211,21 @@ class serendipity_event_entryproperties extends serendipity_event
         }
     }
 
+    function showPasswordform() {
+        global $serendipity;
+        $url = serendipity_currentURL();
+
+        $out = '
+        <form action="'.$url.'" method="post" id="entrypasswordform">
+            <div>
+                <span><label for="entrypassword">' . PASSWORD . ':</label> <input id="entrypassword" type="password" name="serendipity[entrypassword]" value="" /></span>
+                <span><input type="submit" name="login" value="'.LOGIN.'" /></span>
+            </div>
+        </form>';
+        return $out;
+
+    }
+
     function event_hook($event, &$bag, &$eventData, $addData = null) {
         global $serendipity;
 
@@ -269,6 +286,15 @@ class serendipity_event_entryproperties extends serendipity_event
                     } else {
                         $access_users = array();
                     }
+
+                    if (isset($eventData['properties']['ep_password'])) {
+                        $password = $eventData['properties']['ep_password'];
+                    } elseif (isset($serendipity['POST']['properties']['entrypassword'])) {
+                        $password = $serendipity['POST']['properties']['entrypassword'];
+                    } else {
+                        $password = '';
+                    }
+
 ?>
                     <fieldset style="margin: 5px">
                         <legend><?php echo PLUGIN_EVENT_ENTRYPROPERTIES_TITLE; ?></legend>
@@ -289,6 +315,12 @@ class serendipity_event_entryproperties extends serendipity_event
                                 <label title="<?php echo $radio_title; ?>" for="properties_access_<?php echo $radio_value; ?>">&nbsp;<?php echo $radio_title; ?>&nbsp;&nbsp;</label>
 <?php
                     }
+?>
+                    <br /><?php echo PASSWORD; ?>:<br />
+                    <div style="margin-left: 10px">
+                            <input type="password" name="serendipity[properties][entrypassword]" value="<?php echo htmlspecialchars($password); ?>" />
+                    </div>
+<?php
 
                     if ($use_groups) {
                         $my_groups = serendipity_getGroups($serendipity['authorid']);
@@ -553,6 +585,13 @@ class serendipity_event_entryproperties extends serendipity_event
                     return true;
                     break;
 
+                case 'frontend_configure':
+                    if (isset($serendipity['POST']['id']) && empty($serendipity['GET']['id'])) {
+                        $serendipity['GET']['id']      = &$serendipity['POST']['id'];
+                        $serendipity['GET']['subpage'] = &$serendipity['POST']['subpage'];
+                    }
+                    break;
+
                 case 'frontend_entryproperties':
                     $and = $this->returnQueryCondition($is_cache);
                     $q = "SELECT entryid, property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid IN (" . implode(', ', array_keys($addData)) . ") $and";
@@ -572,6 +611,7 @@ class serendipity_event_entryproperties extends serendipity_event
                     // PH: This is done after Garvins suggestion to patchup $eventData in case an entry
                     //     is in the process of being created. This must be done for the extended properties
                     //     to be applied in the preview.
+
                     if (is_array($serendipity['POST']['properties']) && count($serendipity['POST']['properties']) > 0){
                         $parr = array();
                         $supported_properties = serendipity_event_entryproperties::getSupportedProperties();
@@ -580,6 +620,28 @@ class serendipity_event_entryproperties extends serendipity_event
                                 $eventData[0]['properties']['ep_' . $prop_key] = $serendipity['POST']['properties'][$prop_key];
                         }
                     }
+
+                    if (isset($serendipity['GET']['id']) && isset($eventData[0]['properties']['ep_password'])) {
+                        
+                        if (isset($_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']]) || $eventData[0]['properties']['ep_password'] == $serendipity['POST']['entrypassword']) {
+                            // Do not show login form again, once we have first enabled it.
+                            $_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']] = true;
+                        } else {
+                            if (is_array($eventData)) {
+                                $eventData['clean_page'] = true;
+                            } else {
+                                $eventData = array('clean_page' => true);
+                            }
+                            $this->showPasswordForm = true;
+                        }
+                    }
+
+                    break;
+
+                case 'entries_header':
+                    if ($this->showPasswordForm) {
+                        echo $this->showPasswordform();
+                    }
                     break;
 
                 case 'frontend_fetchentries':