]> git.mjollnir.org Git - s9y.git/commitdiff
rename image button to "media"
authorgarvinhicking <garvinhicking>
Mon, 14 Aug 2006 08:53:19 +0000 (08:53 +0000)
committergarvinhicking <garvinhicking>
Mon, 14 Aug 2006 08:53:19 +0000 (08:53 +0000)
plugins/serendipity_event_entryproperties/serendipity_event_entryproperties.php

index 83687c100f7a37e5b0590707ad8421d9bf5885f3..bea749365a318f48ca04fbcd10ec3205716f926a 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.8');
+        $propbag->add('version',       '1.12');
         $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,
@@ -42,7 +43,9 @@ class serendipity_event_entryproperties extends serendipity_event
             'backend_cache_purge'                               => true,
             'backend_plugins_new_instance'                      => true,
             'frontend_entryproperties_query'                    => true,
-            'frontend_entries_rss'                              => true
+            'frontend_entries_rss'                              => 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'));
@@ -135,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_nl2br', 'no_frontpage', 'hiderss');
+            $supported_properties = array('is_sticky', 'access', 'access_groups', 'access_users', 'cache_body', 'cache_extended', 'no_frontpage', 'hiderss', 'entrypassword');
 
             $fields = explode(',', trim($this->get_config('customfields')));
             if (is_array($fields) && count($fields) > 0) {
@@ -160,12 +163,36 @@ class serendipity_event_entryproperties extends serendipity_event
         return $and;
     }
 
+    /*
+     * This function converts specific property fields so that they are
+     * available natively to other plugins/templates.
+     */
+    function applyProperties(&$properties) {
+        global $serendipity;
+
+        if (is_array($properties['disable_markups'])) {
+            foreach($properties['disable_markups'] AS $idx => $instance) {
+                $properties['disable_markup_' . $instance] = $instance;
+            }
+        }
+    }
+
     function addProperties(&$properties, &$eventData) {
         global $serendipity;
         // Get existing data
         $property = serendipity_fetchEntryProperties($eventData['id']);
         $supported_properties = serendipity_event_entryproperties::getSupportedProperties();
 
+        // Special case for disable markups.
+        if (is_array($properties['disable_markups'])) {
+            $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property LIKE 'ep_disable_markup_%'";
+            serendipity_db_query($q);
+
+            foreach($properties['disable_markups'] AS $idx => $instance) {
+                $supported_properties[] = 'disable_markup_' . $instance;
+            }
+        }
+
         foreach($supported_properties AS $prop_key) {
             $prop_val = (isset($properties[$prop_key]) ? $properties[$prop_key] : null);
             $prop_key = 'ep_' . $prop_key;
@@ -184,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;
 
@@ -204,10 +246,6 @@ class serendipity_event_entryproperties extends serendipity_event
                                  || (isset($serendipity['POST']['properties']['is_sticky']) && serendipity_db_bool($serendipity['POST']['properties']['is_sticky']))
                                ? 'checked="checked"'
                                : '';
-                    $nl2br     =    (isset($eventData['properties']['ep_no_nl2br']) && serendipity_db_bool($eventData['properties']['ep_no_nl2br']))
-                                 || (isset($serendipity['POST']['properties']['no_nl2br']) && serendipity_db_bool($serendipity['POST']['properties']['no_nl2br']))
-                               ? 'checked="checked"'
-                               : '';
 
                     $no_frontpage =    (isset($eventData['properties']['ep_no_frontpage']) && serendipity_db_bool($eventData['properties']['ep_no_frontpage']))
                                  || (isset($serendipity['POST']['properties']['no_frontpage']) && serendipity_db_bool($serendipity['POST']['properties']['no_frontpage']))
@@ -248,6 +286,15 @@ class serendipity_event_entryproperties extends serendipity_event
                     } else {
                         $access_users = array();
                     }
+
+                    if (isset($eventData['properties']['ep_entrypassword'])) {
+                        $password = $eventData['properties']['ep_entrypassword'];
+                    } 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>
@@ -255,11 +302,6 @@ class serendipity_event_entryproperties extends serendipity_event
                                 <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS; ?>" for="properties_is_sticky">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS; ?>&nbsp;&nbsp;</label><br />
                             <input type="checkbox" name="serendipity[properties][no_frontpage]" id="properties_no_frontpage" value="true" <?php echo $no_frontpage; ?> />
                                 <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_NO_FRONTPAGE; ?>" for="properties_no_frontpage">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_NO_FRONTPAGE; ?>&nbsp;&nbsp;</label><br />
-<?php if (class_exists('serendipity_event_nl2br')){ ?>
-                            <input type="checkbox" name="serendipity[properties][no_nl2br]" id="properties_no_nl2br" value="true" <?php echo $nl2br; ?> />
-                                <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_NL2BR; ?>" for="properties_no_nl2br">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_NL2BR; ?>&nbsp;&nbsp;</label><br />
-
-<?php } ?>
                             <input type="checkbox" name="serendipity[properties][hiderss]" id="properties_hiderss" value="true" <?php echo $hiderss; ?> />
                                 <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_HIDERSS_DESC; ?>" for="properties_hiderss">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_HIDERSS; ?>&nbsp;&nbsp;</label><br />
 
@@ -273,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']);
@@ -323,6 +371,38 @@ class serendipity_event_entryproperties extends serendipity_event
                                 </select>
                             </div>
 
+                            <br />
+                            <div class="entryproperties_markup">
+                            <?php echo PLUGIN_EVENT_ENTRYPROPERTIES_DISABLE_MARKUP; ?><br />
+                            <div style="margin-left: 10px">
+                                <select name="serendipity[properties][disable_markups][]" multiple="multiple" size="4">
+                                <?php
+                                $plugins = serendipity_plugin_api::get_event_plugins();
+
+                                if (is_array($plugins)) {
+                                    // foreach() operates on copies of values, but we want to operate on references, so we use while()
+                                    @reset($plugins);
+                                    while(list($plugin, $plugin_data) = each($plugins)) {
+                                        if (!is_array($plugin_data['p']->markup_elements)) {
+                                            continue;
+                                        }
+
+                                        if (isset($serendipity['POST']['properties']['disable_markups']) && in_array($plugin_data['p']->instance, $serendipity['POST']['properties']['disable_markups'])) {
+                                            $selected = true;
+                                        } elseif (isset($eventData['properties']['ep_disable_markup_' . $plugin_data['p']->instance])) {
+                                            $selected = true;
+                                        } else {
+                                            $selected = false;
+                                        }
+
+                                        echo '<option ' . ($selected ? 'selected="selected"' : '') . ' value="' . $plugin_data['p']->instance . '">' . htmlspecialchars($plugin_data['p']->title) . '</option>' . "\n";
+                                    }
+                                }
+                                ?>
+                                </select>
+                            </div>
+                        </div>
+
                             <?php
                                 $fields = trim($this->get_config('customfields'));
                                 if (!empty($fields)) {
@@ -349,7 +429,7 @@ class serendipity_event_entryproperties extends serendipity_event
                                 <tr>
                                     <td class="customfield_<?php echo $fieldname; ?> customfield_name"><strong><?php echo $fieldname; ?></strong></td>
                                     <td class="customfield_<?php echo $fieldname; ?> customfield_value"><textarea id="prop<?php echo htmlspecialchars($fieldname); ?>" name="serendipity[properties][<?php echo htmlspecialchars($fieldname); ?>]"><?php echo htmlspecialchars($value); ?></textarea></td>
-                                    <td valign="top"><script type="text/javascript" language="JavaScript">document.write('<input type="button" name="insImage" value="<?php echo IMAGE ; ?>" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[htmltarget]=prop<?php echo htmlspecialchars($fieldname); ?>&amp;serendipity[filename_only]=true\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" class="serendipityPrettyButton" />');</script></td>
+                                    <td valign="top"><script type="text/javascript" language="JavaScript">document.write('<input type="button" name="insImage" value="<?php echo MEDIA ; ?>" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[htmltarget]=prop<?php echo htmlspecialchars($fieldname); ?>&amp;serendipity[filename_only]=true\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" class="serendipityPrettyButton" />');</script></td>
                                 </tr>
                             <?php
                                     }
@@ -372,6 +452,7 @@ class serendipity_event_entryproperties extends serendipity_event
                     }
                     return true;
                     break;
+
                 case 'backend_import_entry':
                     //TODO: (ph) Maybe handle caching?
                     if (is_array($addData) && !$addData['nl2br']){
@@ -380,6 +461,7 @@ class serendipity_event_entryproperties extends serendipity_event
                         $this->addProperties($props, $eventData);
                     }
                 break;
+
                 case 'backend_sidebar_entries_event_display_buildcache':
                     if ($is_cache) {
                         $per_fetch = 25;
@@ -458,6 +540,12 @@ class serendipity_event_entryproperties extends serendipity_event
                     serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE property LIKE 'ep_cache_%'");
                     break;
 
+                case 'backend_entry_presave':
+                    if (is_array($serendipity['POST']['properties'])) {
+                        $this->applyProperties($serendipity['POST']['properties']);
+                    }
+                    break;
+
                 case 'backend_publish':
                 case 'backend_save':
                     if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
@@ -497,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";
@@ -516,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();
@@ -524,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_entrypassword'])) {
+
+                        if (isset($_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']]) || $eventData[0]['properties']['ep_entrypassword'] == $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':
@@ -551,7 +669,7 @@ class serendipity_event_entryproperties extends serendipity_event
                         $conds[] = " (ep_access.property IS NULL OR ep_access.value = 'public')";
                     }
 
-                    if (!isset($serendipity['GET']['category']) && !isset($serendipity['GET']['adminModule']) && $event == 'frontend_fetchentries') {
+                    if (!isset($serendipity['GET']['category']) && !isset($serendipity['GET']['adminModule']) && $event == 'frontend_fetchentries' && $addData['source'] != 'search') {
                         $conds[] = " (ep_no_frontpage.property IS NULL OR ep_no_frontpage.value != 'true') ";
                         $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_no_frontpage
                                                   ON (e.id = ep_no_frontpage.entryid AND ep_no_frontpage.property = 'ep_no_frontpage')";