[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/plugins/serendipity_event_entryproperties/ -> serendipity_event_entryproperties.php (source)

   1  <?php # $Id: serendipity_event_entryproperties.php 1829 2007-08-08 08:48:37Z garvinhicking $
   2  
   3  
   4  if (IN_serendipity !== true) {
   5      die ("Don't hack!");
   6  }
   7  
   8  // Probe for a language include with constants. Still include defines later on, if some constants were missing
   9  $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
  10  if (file_exists($probelang)) {
  11      include $probelang;
  12  }
  13  
  14  include dirname(__FILE__) . '/lang_en.inc.php';
  15  
  16  class serendipity_event_entryproperties extends serendipity_event
  17  {
  18      var $services, $showPasswordForm;
  19      var $title = PLUGIN_EVENT_ENTRYPROPERTIES_TITLE;
  20  
  21      function introspect(&$propbag)
  22      {
  23          global $serendipity;
  24  
  25          $propbag->add('name',          PLUGIN_EVENT_ENTRYPROPERTIES_TITLE);
  26          $propbag->add('description',   PLUGIN_EVENT_ENTRYPROPERTIES_DESC);
  27          $propbag->add('stackable',     false);
  28          $propbag->add('author',        'Garvin Hicking');
  29          $propbag->add('version',       '1.14');
  30          $propbag->add('requirements',  array(
  31              'serendipity' => '0.8',
  32              'smarty'      => '2.6.7',
  33              'php'         => '4.1.0'
  34          ));
  35          $propbag->add('event_hooks',    array(
  36              'frontend_fetchentries'                             => true,
  37              'frontend_fetchentry'                               => true,
  38              'backend_publish'                                   => true,
  39              'backend_save'                                      => true,
  40              'backend_display'                                   => true,
  41              'backend_import_entry'                              => true,
  42              'entry_display'                                     => true,
  43              'entries_header'                                    => true,
  44              'frontend_entryproperties'                          => true,
  45              'backend_sidebar_entries_event_display_buildcache'  => true,
  46              'backend_sidebar_entries'                           => true,
  47              'backend_cache_entries'                             => true,
  48              'backend_cache_purge'                               => true,
  49              'backend_plugins_new_instance'                      => true,
  50              'frontend_entryproperties_query'                    => true,
  51              'frontend_entries_rss'                              => true,
  52              'backend_entry_presave'                             => true,
  53              'frontend_configure'                                => true
  54          ));
  55          $propbag->add('groups', array('BACKEND_EDITOR'));
  56          $propbag->add('configuration', array('cache', 'use_groups', 'use_users', 'default_read', 'customfields'));
  57      }
  58  
  59      function introspect_config_item($name, &$propbag)
  60      {
  61          switch($name) {
  62              case 'default_read':
  63                  $propbag->add('type',        'radio');
  64                  $propbag->add('name',        USE_DEFAULT . ': ' . PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS);
  65                  $propbag->add('description', '');
  66                  $propbag->add('radio', array(
  67                      'value' => array('private', 'public', 'member'),
  68                      'desc'  => array(PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PRIVATE, PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PUBLIC, PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_MEMBERS)
  69                  ));
  70                  $propbag->add('default',     'public');
  71                  $propbag->add('radio_per_row', '1');
  72  
  73                  break;
  74  
  75              case 'customfields':
  76                  $propbag->add('type',        'text');
  77                  $propbag->add('name',        PLUGIN_EVENT_ENTRYPROPERTIES_CUSTOMFIELDS);
  78                  $propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_CUSTOMFIELDS_DESC2);
  79                  $propbag->add('default',     'CustomField1, CustomField2, CustomField3');
  80                  break;
  81  
  82              case 'use_groups':
  83                  $propbag->add('type',        'boolean');
  84                  $propbag->add('name',        PLUGIN_EVENT_ENTRYPROPERTIES_GROUPS);
  85                  $propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_GROUPS_DESC);
  86                  $propbag->add('default',     'false');
  87                  break;
  88  
  89              case 'use_users':
  90                  $propbag->add('type',        'boolean');
  91                  $propbag->add('name',        PLUGIN_EVENT_ENTRYPROPERTIES_USERS);
  92                  $propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_USERS_DESC);
  93                  $propbag->add('default',     'false');
  94                  break;
  95  
  96              case 'cache':
  97                  $propbag->add('type',        'boolean');
  98                  $propbag->add('name',        PLUGIN_EVENT_ENTRYPROPERTIES_CACHE);
  99                  $propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DESC);
 100                  $propbag->add('default',     'true');
 101                  break;
 102          }
 103          return true;
 104      }
 105  
 106      function generate_content(&$title) {
 107          $title = $this->title;
 108      }
 109  
 110      function install() {
 111          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
 112      }
 113  
 114      function uninstall() {
 115          serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
 116      }
 117  
 118      function &getValidAuthors() {
 119          global $serendipity;
 120  
 121          if (serendipity_checkPermission('adminUsersMaintainOthers')) {
 122              $users = serendipity_fetchUsers('');
 123          } elseif (serendipity_checkPermission('adminUsersMaintainSame')) {
 124              $users = serendipity_fetchUsers('', serendipity_getGroups($serendipity['authorid'], true));
 125          } else {
 126              $users = serendipity_fetchUsers($serendipity['authorid']);
 127          }
 128  
 129          return $users;
 130      }
 131  
 132  
 133      function updateCache(&$entry) {
 134          global $serendipity;
 135  
 136          serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$entry['id'] . " AND property LIKE 'ep_cache_%'");
 137          $addData = array('from' => 'serendipity_event_entryproperties:updateCache');
 138          serendipity_plugin_api::hook_event('frontend_display', $entry, $addData);
 139          serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$entry['id'] . ", 'ep_cache_body', '" . serendipity_db_escape_string($entry['body']) . "')");
 140          serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$entry['id'] . ", 'ep_cache_extended', '" . serendipity_db_escape_string($entry['extended']) . "')");
 141      }
 142  
 143      function getSupportedProperties() {
 144          static $supported_properties = null;
 145  
 146          if ($supported_properties === null) {
 147              $supported_properties = array('is_sticky', 'access', 'access_groups', 'access_users', 'cache_body', 'cache_extended', 'no_frontpage', 'hiderss', 'entrypassword');
 148  
 149              $fields = explode(',', trim($this->get_config('customfields')));
 150              if (is_array($fields) && count($fields) > 0) {
 151                  foreach($fields AS $field) {
 152                      $field = trim($field);
 153                      if (!empty($field)) {
 154                          $supported_properties[] = $field;
 155                      }
 156                  }
 157              }
 158          }
 159  
 160          return $supported_properties;
 161      }
 162  
 163      function returnQueryCondition($is_cache) {
 164          $and = '';
 165          if (!$is_cache) {
 166              $and = " AND property NOT LIKE 'ep_cache_%' ";
 167          }
 168  
 169          return $and;
 170      }
 171  
 172      /*
 173       * This function converts specific property fields so that they are
 174       * available natively to other plugins/templates.
 175       */
 176      function applyProperties(&$properties) {
 177          global $serendipity;
 178  
 179          if (is_array($properties['disable_markups'])) {
 180              foreach($properties['disable_markups'] AS $idx => $instance) {
 181                  $properties['disable_markup_' . $instance] = $instance;
 182              }
 183          }
 184      }
 185  
 186      function addProperties(&$properties, &$eventData) {
 187          global $serendipity;
 188          // Get existing data
 189          $property = serendipity_fetchEntryProperties($eventData['id']);
 190          $supported_properties = serendipity_event_entryproperties::getSupportedProperties();
 191  
 192          // Special case for disable markups.
 193          if (is_array($properties['disable_markups'])) {
 194              $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property LIKE 'ep_disable_markup_%'";
 195              serendipity_db_query($q);
 196  
 197              foreach($properties['disable_markups'] AS $idx => $instance) {
 198                  $supported_properties[] = 'disable_markup_' . $instance;
 199              }
 200          }
 201  
 202          foreach($supported_properties AS $prop_key) {
 203              $prop_val = (isset($properties[$prop_key]) ? $properties[$prop_key] : null);
 204              $prop_key = 'ep_' . $prop_key;
 205  
 206              if (is_array($prop_val)) {
 207                  $prop_val = ";" . implode(';', $prop_val) . ";";
 208              }
 209  
 210              $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($prop_key) . "'";
 211              serendipity_db_query($q);
 212  
 213              if (!empty($prop_val)) {
 214                  $q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$eventData['id'] . ", '" . serendipity_db_escape_string($prop_key) . "', '" . serendipity_db_escape_string($prop_val) . "')";
 215                  serendipity_db_query($q);
 216              }
 217          }
 218      }
 219  
 220      function showPasswordform() {
 221          global $serendipity;
 222          $url = serendipity_currentURL();
 223  
 224          $out = '
 225          <form action="'.$url.'" method="post" id="entrypasswordform">
 226              <div>
 227                  <span><label for="entrypassword">' . PASSWORD . ':</label> <input class="input_textbox" id="entrypassword" type="password" name="serendipity[entrypassword]" value="" /></span>
 228                  <span><input class="serendipityPrettyButton input_button" type="submit" name="login" value="'.LOGIN.'" /></span>
 229              </div>
 230          </form>';
 231          return $out;
 232  
 233      }
 234  
 235      function event_hook($event, &$bag, &$eventData, $addData = null) {
 236          global $serendipity;
 237  
 238          $hooks = &$bag->get('event_hooks');
 239          $is_cache   = serendipity_db_bool($this->get_config('cache', 'true'));
 240          $use_groups = serendipity_db_bool($this->get_config('use_groups'));
 241          $use_users  = serendipity_db_bool($this->get_config('use_users'));
 242  
 243          if (isset($hooks[$event])) {
 244              switch($event) {
 245                  case 'frontend_entryproperties_query':
 246                      $eventData['and'] = $this->returnQueryCondition($is_cache);
 247                      return true;
 248                      break;
 249  
 250                  case 'backend_display':
 251                      $is_sticky =    (isset($eventData['properties']['ep_is_sticky']) && serendipity_db_bool($eventData['properties']['ep_is_sticky']))
 252                                   || (isset($serendipity['POST']['properties']['is_sticky']) && serendipity_db_bool($serendipity['POST']['properties']['is_sticky']))
 253                                 ? 'checked="checked"'
 254                                 : '';
 255  
 256                      $no_frontpage =    (isset($eventData['properties']['ep_no_frontpage']) && serendipity_db_bool($eventData['properties']['ep_no_frontpage']))
 257                                   || (isset($serendipity['POST']['properties']['no_frontpage']) && serendipity_db_bool($serendipity['POST']['properties']['no_frontpage']))
 258                                 ? 'checked="checked"'
 259                                 : '';
 260  
 261                      $hiderss      =     (isset($eventData['properties']['ep_hiderss']) && serendipity_db_bool($eventData['properties']['ep_hiderss']))
 262                                   || (isset($serendipity['POST']['properties']['hiderss']) && serendipity_db_bool($serendipity['POST']['properties']['hiderss']))
 263                                 ? 'checked="checked"'
 264                                 : '';
 265  
 266                      $access_values = array(
 267                          PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PRIVATE => 'private',
 268                          PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_PUBLIC  => 'public',
 269                          PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS_MEMBERS => 'member',
 270                      );
 271  
 272                      if (isset($eventData['properties']['ep_access'])) {
 273                          $access = $eventData['properties']['ep_access'];
 274                      } elseif (isset($serendipity['POST']['properties']['access'])) {
 275                          $access = $serendipity['POST']['properties']['access'];
 276                      } else {
 277                          $access = $this->get_config('default_read', 'public');
 278                      }
 279  
 280                      if (isset($eventData['properties']['ep_access_groups'])) {
 281                          $access_groups = explode(';', $eventData['properties']['ep_access_groups']);
 282                      } elseif (isset($serendipity['POST']['properties']['access_groups'])) {
 283                          $access_groups = $serendipity['POST']['properties']['access_groups'];
 284                      } else {
 285                          $access_groups = array();
 286                      }
 287  
 288                      if (isset($eventData['properties']['ep_access_users'])) {
 289                          $access_users = explode(';', $eventData['properties']['ep_access_users']);
 290                      } elseif (isset($serendipity['POST']['properties']['access_users'])) {
 291                          $access_users = $serendipity['POST']['properties']['access_users'];
 292                      } else {
 293                          $access_users = array();
 294                      }
 295  
 296                      if (isset($eventData['properties']['ep_entrypassword'])) {
 297                          $password = $eventData['properties']['ep_entrypassword'];
 298                      } elseif (isset($serendipity['POST']['properties']['entrypassword'])) {
 299                          $password = $serendipity['POST']['properties']['entrypassword'];
 300                      } else {
 301                          $password = '';
 302                      }
 303  
 304  ?>
 305                      <fieldset style="margin: 5px">
 306                          <legend><?php echo PLUGIN_EVENT_ENTRYPROPERTIES_TITLE; ?></legend>
 307                              <input class="input_checkbox" type="checkbox" name="serendipity[properties][is_sticky]" id="properties_is_sticky" value="true" <?php echo $is_sticky; ?> />
 308                                  <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS; ?>" for="properties_is_sticky">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_STICKYPOSTS; ?>&nbsp;&nbsp;</label><br />
 309                              <input class="input_checkbox" type="checkbox" name="serendipity[properties][no_frontpage]" id="properties_no_frontpage" value="true" <?php echo $no_frontpage; ?> />
 310                                  <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 />
 311                              <input class="input_checkbox" type="checkbox" name="serendipity[properties][hiderss]" id="properties_hiderss" value="true" <?php echo $hiderss; ?> />
 312                                  <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_HIDERSS_DESC; ?>" for="properties_hiderss">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_HIDERSS; ?>&nbsp;&nbsp;</label><br />
 313  
 314                              <br />
 315                              <?php echo PLUGIN_EVENT_ENTRYPROPERTIES_ACCESS; ?>:<br />
 316                              <div style="margin-left: 10px">
 317  <?php
 318                      foreach($access_values AS $radio_title => $radio_value) {
 319  ?>
 320                              <input class="input_radio" type="radio" name="serendipity[properties][access]" id="properties_access_<?php echo $radio_value; ?>" value="<?php echo $radio_value; ?>" <?php echo $radio_value == $access ? 'checked="checked"' : ''; ?> />
 321                                  <label title="<?php echo $radio_title; ?>" for="properties_access_<?php echo $radio_value; ?>">&nbsp;<?php echo $radio_title; ?>&nbsp;&nbsp;</label>
 322  <?php
 323                      }
 324  ?>
 325                      <br /><?php echo PASSWORD; ?>:<br />
 326                      <div style="margin-left: 10px">
 327                              <input class="input_textbox" type="password" name="serendipity[properties][entrypassword]" value="<?php echo htmlspecialchars($password); ?>" />
 328                      </div>
 329  <?php
 330  
 331                      if ($use_groups) {
 332                          $my_groups = serendipity_getGroups($serendipity['authorid']);
 333  ?>
 334                              <br /><select onchange="document.getElementById('properties_access_member').checked = true;" style="margin-left: 5px" multiple="multiple" name="serendipity[properties][access_groups][]" size="4">
 335  <?php
 336                          foreach($my_groups AS $group) {
 337  ?>
 338                                  <option value="<?php echo $group['id']; ?>" <?php echo (in_array($group['id'], $access_groups) ? 'selected="selected"' : ''); ?>><?php echo htmlspecialchars($group['name']); ?></option>
 339  <?php
 340                          }
 341                          echo '</select>';
 342                      }
 343  
 344                      if ($use_users) {
 345  ?>
 346                          <br /><select onchange="document.getElementById('properties_access_member').checked = true;" style="margin-left: 5px" multiple="multiple" name="serendipity[properties][access_users][]" size="4">
 347  <?php
 348                          $users = serendipity_fetchUsers();
 349                          foreach($users AS $user) {
 350  ?>
 351                              <option value="<?php echo $user['authorid']; ?>" <?php echo (in_array($user['authorid'], $access_users) ? 'selected="selected"' : ''); ?>><?php echo htmlspecialchars($user['realname']); ?></option>
 352  <?php
 353                          }
 354                          echo '</select>';
 355                      }
 356  ?>
 357                              </div>
 358                              <br />
 359                              <?php echo AUTHOR; ?>:<br />
 360                              <div style="margin-left: 10px">
 361                                  <select name="serendipity[change_author]">
 362                                  <?php
 363                                  if (isset($serendipity['POST']['change_author'])) {
 364                                      $selected_user = $serendipity['POST']['change_author'];
 365                                  } elseif (!empty($eventData['authorid'])) {
 366                                      $selected_user = $eventData['authorid'];
 367                                  } else {
 368                                      $selected_user = $serendipity['authorid'];
 369                                  }
 370  
 371                                  $avail_users =& $this->getValidAuthors();
 372  
 373                                  foreach($avail_users AS $user) {
 374                                      echo '<option value="' . $user['authorid'] . '" ' . ($selected_user == $user['authorid'] ? ' selected="selected"' : '') . '>' . $user['realname'] . '</option>' . "\n";
 375                                  }
 376                                  ?>
 377                                  </select>
 378                              </div>
 379  
 380                              <br />
 381                              <div class="entryproperties_markup">
 382                              <?php echo PLUGIN_EVENT_ENTRYPROPERTIES_DISABLE_MARKUP; ?><br />
 383                              <div style="margin-left: 10px">
 384                                  <select name="serendipity[properties][disable_markups][]" multiple="multiple" size="4">
 385                                  <?php
 386                                  $plugins = serendipity_plugin_api::get_event_plugins();
 387  
 388                                  if (is_array($plugins)) {
 389                                      // foreach() operates on copies of values, but we want to operate on references, so we use while()
 390                                      @reset($plugins);
 391                                      while(list($plugin, $plugin_data) = each($plugins)) {
 392                                          if (!is_array($plugin_data['p']->markup_elements)) {
 393                                              continue;
 394                                          }
 395  
 396                                          if (isset($serendipity['POST']['properties']['disable_markups']) && in_array($plugin_data['p']->instance, $serendipity['POST']['properties']['disable_markups'])) {
 397                                              $selected = true;
 398                                          } elseif (isset($eventData['properties']['ep_disable_markup_' . $plugin_data['p']->instance])) {
 399                                              $selected = true;
 400                                          } else {
 401                                              $selected = false;
 402                                          }
 403  
 404                                          echo '<option ' . ($selected ? 'selected="selected"' : '') . ' value="' . $plugin_data['p']->instance . '">' . htmlspecialchars($plugin_data['p']->title) . '</option>' . "\n";
 405                                      }
 406                                  }
 407                                  ?>
 408                                  </select>
 409                              </div>
 410                          </div>
 411  
 412                              <?php
 413                                  $fields = trim($this->get_config('customfields'));
 414                                  if (!empty($fields)) {
 415                                      $fields = explode(',', $fields);
 416                                  }
 417                                  if (is_array($fields) && count($fields) > 0) { ?>
 418                              <br />
 419                              <?php echo PLUGIN_EVENT_ENTRYPROPERTIES_CUSTOMFIELDS; ?>:<br />
 420                              <em><?php echo PLUGIN_EVENT_ENTRYPROPERTIES_CUSTOMFIELDS_DESC1 . '<br />' . sprintf(PLUGIN_EVENT_ENTRYPROPERTIES_CUSTOMFIELDS_DESC3, 'serendipity_admin.php?serendipity[adminModule]=plugins&amp;serendipity[plugin_to_conf]=' . $this->instance); ?></em><br />
 421                              <div style="margin-left: 10px">
 422                                  <table id="serendipity_customfields">
 423                              <?php
 424                                      foreach($fields AS $fieldname) {
 425                                          $fieldname = htmlspecialchars(trim($fieldname));
 426  
 427                                          if (isset($serendipity['POST']['properties'][$fieldname])) {
 428                                              $value = $serendipity['POST']['properties'][$fieldname];
 429                                          } elseif (!empty($eventData['properties']['ep_' . $fieldname])) {
 430                                              $value = $eventData['properties']['ep_' . $fieldname];
 431                                          } else {
 432                                              $value = '';
 433                                          }
 434                              ?>
 435                                  <tr>
 436                                      <td class="customfield_<?php echo $fieldname; ?> customfield_name"><strong><?php echo $fieldname; ?></strong></td>
 437                                      <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>
 438                                      <td valign="top"><script type="text/javascript" language="JavaScript">document.write('<input class="serendipityPrettyButton input_button" 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>
 439                                  </tr>
 440                              <?php
 441                                      }
 442                              ?>
 443                                  </table>
 444                              </div>
 445                              <?php
 446                                  }
 447                              ?>
 448                      </fieldset>
 449  <?php
 450                      return true;
 451                      break;
 452  
 453                  case 'backend_sidebar_entries':
 454                      if ($is_cache && $serendipity['userlevel'] >= USERLEVEL_ADMIN) {
 455  ?>
 456                          <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=buildcache"><?php echo PLUGIN_EVENT_ENTRYPROPERTY_BUILDCACHE; ?></a></li>
 457  <?php
 458                      }
 459                      return true;
 460                      break;
 461  
 462                  case 'backend_import_entry':
 463                      //TODO: (ph) Maybe handle caching?
 464                      if (is_array($addData) && !$addData['nl2br']){
 465                          $props = array();
 466                          $props['no_nl2br'] = 'true';
 467                          $this->addProperties($props, $eventData);
 468                      }
 469                  break;
 470  
 471                  case 'backend_sidebar_entries_event_display_buildcache':
 472                      if ($is_cache) {
 473                          $per_fetch = 25;
 474                          $page = (isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1);
 475                          $from = ($page-1)*$per_fetch;
 476                          $to   = ($page)*$per_fetch;
 477                          printf(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNO, $from, $to);
 478                          $entries = serendipity_fetchEntries(
 479                              null,
 480                              true,
 481                              $per_fetch,
 482                              false,
 483                              false,
 484                              'timestamp DESC',
 485                              '',
 486                              true
 487                          );
 488  
 489                          $total = serendipity_getTotalEntries();
 490                          printf(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_TOTAL . '<br />', $total);
 491  
 492                          if (is_array($entries)) {
 493                              foreach($entries AS $idx => $entry) {
 494                                  printf(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_BUILDING . '<br />', $entry['id'], htmlspecialchars($entry['title']));
 495                                  $this->updateCache($entry);
 496                                  echo PLUGIN_EVENT_ENTRYPROPERTIES_CACHED . '<br /><br />';
 497                              }
 498                          }
 499  
 500                          echo '<br />';
 501  
 502                          if ($to < $total) {
 503  ?>
 504                          <script type="text/javascript">
 505                              if (confirm("<?php echo htmlspecialchars(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_FETCHNEXT); ?>")) {
 506                                  location.href = "?serendipity[adminModule]=event_display&serendipity[adminAction]=buildcache&serendipity[page]=<?php echo ($page+1); ?>";
 507                              } else {
 508                                  alert("<?php echo htmlspecialchars(PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_ABORTED); ?>");
 509                              }
 510                          </script>
 511  <?php
 512                          } else {
 513                              echo '<div class="serendipity_msg_notice">' . PLUGIN_EVENT_ENTRYPROPERTIES_CACHE_DONE . '</div>';
 514                          }
 515                      }
 516                      return true;
 517                      break;
 518  
 519                  case 'backend_cache_entries':
 520                      if (!$is_cache) {
 521                          return true;
 522                      }
 523  
 524                      $entries = serendipity_fetchEntries(
 525                          null,
 526                          true,
 527                          $serendipity['fetchLimit'],
 528                          false,
 529                          false,
 530                          'timestamp DESC',
 531                          '',
 532                          true
 533                      );
 534  
 535                      foreach($entries AS $idx => $entry) {
 536                          $this->updateCache($entry);
 537                      }
 538                      return true;
 539                      break;
 540  
 541                  case 'backend_cache_purge':
 542                      if (!$is_cache) {
 543                          return true;
 544                      }
 545  
 546                      serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE property LIKE 'ep_cache_%'");
 547                      break;
 548  
 549                  case 'backend_entry_presave':
 550                      if (is_array($serendipity['POST']['properties'])) {
 551                          $this->applyProperties($serendipity['POST']['properties']);
 552                      }
 553                      break;
 554  
 555                  case 'backend_publish':
 556                  case 'backend_save':
 557                      if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
 558                          return true;
 559                      }
 560  
 561                      if (!empty($serendipity['POST']['change_author']) && $serendipity['POST']['change_author'] != $eventData['id']) {
 562                          // Check again if the POSTed value is an author that the current user has "access" to.
 563                          $avail_users =& $this->getValidAuthors();
 564                          $new_authorid = (int)$serendipity['POST']['change_author'];
 565                          foreach($avail_users AS $user) {
 566                              if ($new_authorid == $user['authorid']) {
 567                                  serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET authorid = " . $new_authorid . " WHERE id = " . (int)$eventData['id']);
 568                              }
 569                          }
 570                      }
 571  
 572                      if ($is_cache) {
 573                          // Previous calls to frontend_display used the "no_scramble" atteribute to not tinker with the data.
 574                          // We now need to call those plugins that have not yet operated before.
 575                          $to_addData = array('from' => 'entryproperties:' . $event);
 576                          serendipity_plugin_api::hook_event('frontend_display_cache', $eventData, $to_addData);
 577                          $serendipity['POST']['properties']['cache_body']     = $eventData['body'];
 578                          $serendipity['POST']['properties']['cache_extended'] = $eventData['extended'];
 579                      }
 580  
 581                      if (is_array($serendipity['POST']['properties']['access_groups']) && $serendipity['POST']['properties']['access'] != 'member') {
 582                          unset($serendipity['POST']['properties']['access_groups']);
 583                      }
 584  
 585                      if (is_array($serendipity['POST']['properties']['access_users']) && $serendipity['POST']['properties']['access'] != 'member') {
 586                          unset($serendipity['POST']['properties']['access_users']);
 587                      }
 588  
 589                      $this->addProperties($serendipity['POST']['properties'], $eventData);
 590  
 591                      return true;
 592                      break;
 593  
 594                  case 'frontend_configure':
 595                      if (isset($serendipity['POST']['id']) && empty($serendipity['GET']['id'])) {
 596                          $serendipity['GET']['id']      = &$serendipity['POST']['id'];
 597                          $serendipity['GET']['subpage'] = &$serendipity['POST']['subpage'];
 598                      }
 599                      break;
 600  
 601                  case 'frontend_entryproperties':
 602                      $and = $this->returnQueryCondition($is_cache);
 603                      $q = "SELECT entryid, property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid IN (" . implode(', ', array_keys($addData)) . ") $and";
 604  
 605                      $properties = serendipity_db_query($q);
 606                      if (!is_array($properties)) {
 607                          return true;
 608                      }
 609  
 610                      foreach($properties AS $idx => $row) {
 611                          $eventData[$addData[$row['entryid']]]['properties'][$row['property']] = $row['value'];
 612                      }
 613                      return true;
 614                      break;
 615  
 616                  case 'entry_display':
 617                      // PH: This is done after Garvins suggestion to patchup $eventData in case an entry
 618                      //     is in the process of being created. This must be done for the extended properties
 619                      //     to be applied in the preview.
 620  
 621                      if (isset($serendipity['GET']['id']) && isset($eventData[0]['properties']['ep_entrypassword'])) {
 622  
 623                          if ($_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']] == md5($eventData[0]['properties']['ep_entrypassword']) || $eventData[0]['properties']['ep_entrypassword'] == $serendipity['POST']['entrypassword']) {
 624                              // Do not show login form again, once we have first enabled it.
 625                              $_SESSION['entrypassword_unlocked'][$serendipity['GET']['id']] = md5($eventData[0]['properties']['ep_entrypassword']);
 626                          } else {
 627                              if (is_array($eventData)) {
 628                                  $eventData['clean_page'] = true;
 629                              } else {
 630                                  $eventData = array('clean_page' => true);
 631                              }
 632                              $this->showPasswordForm = true;
 633                          }
 634                      }
 635  
 636                      if ($addData['preview'] && is_array($serendipity['POST']['properties']) && count($serendipity['POST']['properties']) > 0){
 637                          $parr = array();
 638                          $supported_properties = serendipity_event_entryproperties::getSupportedProperties();
 639                          foreach($supported_properties AS $prop_key) {
 640                              if (isset($serendipity['POST']['properties'][$prop_key]))
 641                                  $eventData[0]['properties']['ep_' . $prop_key] = $serendipity['POST']['properties'][$prop_key];
 642                          }
 643                      }
 644  
 645                      break;
 646  
 647                  case 'entries_header':
 648                      if ($this->showPasswordForm) {
 649                          echo $this->showPasswordform();
 650                      }
 651                      break;
 652  
 653                  case 'frontend_fetchentries':
 654                  case 'frontend_fetchentry':
 655                      $joins = array();
 656                      $conds = array();
 657                      if ($_SESSION['serendipityAuthedUser'] === true) {
 658                          $conds[] = " (ep_access.property IS NULL OR ep_access.value = 'member' OR ep_access.value = 'public' OR (ep_access.value = 'private' AND e.authorid = " . (int)$serendipity['authorid'] . ")) ";
 659  
 660                          if ($use_groups) {
 661                              $mygroups  = serendipity_checkPermission(null, null, true);
 662                              $groupcond = array();
 663                              foreach((array)$mygroups AS $mygroup) {
 664                                  $groupcond[] .= "ep_access_groups.value LIKE '%;$mygroup;%'";
 665                              }
 666                              if (count($groupcond) > 0) {
 667                                  $conds[] = " (ep_access_groups.property IS NULL OR (ep_access.value = 'member' AND (" . implode(' OR ', $groupcond) . ")))";
 668                              }
 669                          }
 670  
 671                          if ($use_users) {
 672                              $conds[] = " (ep_access_users.property IS NULL OR (ep_access.value = 'member' AND (ep_access_users.value LIKE '%;" . (int)$serendipity['authorid'] . ";%' OR e.authorid = " . (int)$serendipity['authorid'] . "))) ";
 673                          }
 674                      } else {
 675                          $conds[] = " (ep_access.property IS NULL OR ep_access.value = 'public')";
 676                      }
 677  
 678                      if (!isset($serendipity['GET']['viewAuthor']) && !isset($serendipity['plugin_vars']['tag']) && !isset($serendipity['GET']['category']) && !isset($serendipity['GET']['adminModule']) && $event == 'frontend_fetchentries' && $addData['source'] != 'search') {
 679                          $conds[] = " (ep_no_frontpage.property IS NULL OR ep_no_frontpage.value != 'true') ";
 680                          $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_no_frontpage
 681                                                    ON (e.id = ep_no_frontpage.entryid AND ep_no_frontpage.property = 'ep_no_frontpage')";
 682                      }
 683  
 684                      if (count($conds) > 0) {
 685                          $cond = implode(' AND ', $conds);
 686                          if (empty($eventData['and'])) {
 687                              $eventData['and'] = " WHERE $cond ";
 688                          } else {
 689                              $eventData['and'] .= " AND $cond ";
 690                          }
 691                      }
 692  
 693                      $conds = array();
 694                      if (!isset($addData['noSticky']) || $addData['noSticky'] !== true) {
 695                          $conds[] = 'ep_sticky.value AS orderkey,';
 696                      } else {
 697                          $conds[] = 'e.isdraft AS orderkey,';
 698                      }
 699  
 700                      if ($is_cache && (!isset($addData['noCache']) || !$addData['noCache'])) {
 701                          $conds[] = 'ep_cache_extended.value AS ep_cache_extended,';
 702                          $conds[] = 'ep_cache_body.value     AS ep_cache_body,';
 703                      }
 704  
 705                      $cond = implode("\n", $conds);
 706                      if (empty($eventData['addkey'])) {
 707                          $eventData['addkey'] = $cond;
 708                      } else {
 709                          $eventData['addkey'] .= $cond;
 710                      }
 711  
 712                      if ($serendipity['dbType'] == 'postgres') {
 713                          // PostgreSQL is a bit weird here. Empty columns with NULL or "" content for
 714                          // orderkey would get sorted on top when using DESC, and only after those
 715                          // the "true" content would be inserted. Thus we order ASC in postgreSQL,
 716                          // and silently wonder. Thanks to Nate Johnston for working this out!
 717                          $cond = 'orderkey ASC';
 718                      } else {
 719                          $cond = 'orderkey DESC';
 720                      }
 721  
 722                      if (empty($eventData['orderby'])) {
 723                          $eventData['orderby'] = $cond;
 724                      } else {
 725                          $eventData['orderby'] = $cond . ', ' . $eventData['orderby'];
 726                      }
 727  
 728                      if ($is_cache && (!isset($addData['noCache']) || !$addData['noCache'])) {
 729                          $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_cache_extended
 730                                                    ON (e.id = ep_cache_extended.entryid AND ep_cache_extended.property = 'ep_cache_extended')";
 731                          $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_cache_body
 732                                                    ON (e.id = ep_cache_body.entryid AND ep_cache_body.property = 'ep_cache_body')";
 733                      }
 734                      $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_access
 735                                                ON (e.id = ep_access.entryid AND ep_access.property = 'ep_access')";
 736                      if ($use_groups) {
 737                          $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_access_groups
 738                                                    ON (e.id = ep_access_groups.entryid AND ep_access_groups.property = 'ep_access_groups')";
 739                      }
 740  
 741                      if ($use_users) {
 742                          $joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_access_users
 743                                                    ON (e.id = ep_access_users.entryid AND ep_access_users.property = 'ep_access_users')";
 744                      }
 745  
 746                      if (!isset($addData['noSticky']) || $addData['noSticky'] !== true) {
 747                          $joins[] = " LEFT JOIN {$serendipity['dbPrefix']}entryproperties ep_sticky
 748                                              ON (e.id = ep_sticky.entryid AND ep_sticky.property = 'ep_is_sticky')";
 749                      }
 750  
 751                      $cond = implode("\n", $joins);
 752                      if (empty($eventData['joins'])) {
 753                          $eventData['joins'] = $cond;
 754                      } else {
 755                          $eventData['joins'] .= $cond;
 756                      }
 757  
 758                      return true;
 759                      break;
 760  
 761                  case 'frontend_entries_rss':
 762                      if (is_array($eventData)) {
 763                          foreach($eventData AS $idx => $entry) {
 764                              if (is_array($entry['properties']) && isset($entry['properties']['ep_hiderss']) && $entry['properties']['ep_hiderss']) {
 765                                  unset($eventData[$idx]['body']);
 766                                  unset($eventData[$idx]['extended']);
 767                                  unset($eventData[$idx]['exflag']);
 768                              }
 769                          }
 770                      }
 771                      return true;
 772                      break;
 773  
 774                  case 'backend_plugins_new_instance':
 775                      // This hook will always push the entryproperties plugin as last in queue.
 776                      // Happens always when a new plugin is added.
 777                      // This is important because of its caching mechanism!
 778  
 779                      // Fetch maximum sort_order value. This will be the new value of our current plugin.
 780                      $q  = "SELECT MAX(sort_order) as sort_order_max FROM {$serendipity['dbPrefix']}plugins WHERE placement = '" . $addData['default_placement'] . "'";
 781                      $rs  = serendipity_db_query($q, true, 'num');
 782  
 783                      // Fetch current sort_order of current plugin.
 784                      $q   = "SELECT sort_order FROM {$serendipity['dbPrefix']}plugins WHERE name = '" . $this->instance . "'";
 785                      $cur = serendipity_db_query($q, true, 'num');
 786  
 787                      // Decrease sort_order of all plugins after current plugin by one.
 788                      $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = sort_order - 1 WHERE placement = '" . $addData['default_placement'] . "' AND sort_order > " . intval($cur[0]);
 789                      serendipity_db_query($q);
 790  
 791                      // Set current plugin as last plugin in queue.
 792                      $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = " . intval($rs[0]) . " WHERE name = '" . $this->instance . "'";
 793                      serendipity_db_query($q);
 794  
 795                      return true;
 796                      break;
 797  
 798                  default:
 799                      return false;
 800                      break;
 801              }
 802          } else {
 803              return false;
 804          }
 805      }
 806  }
 807  
 808  /* vim: set sts=4 ts=4 expandtab : */
 809  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics