[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: serendipity_event_trackexits.php 1695 2007-05-16 14:12:45Z 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_trackexits extends serendipity_event
  17  {
  18      var $title = PLUGIN_EVENT_TRACKBACK_NAME;
  19      var $links;
  20  
  21      function introspect(&$propbag)
  22      {
  23          global $serendipity;
  24  
  25          $propbag->add('name',          PLUGIN_EVENT_TRACKBACK_NAME);
  26          $propbag->add('description',   PLUGIN_EVENT_TRACKBACK_DESC);
  27          $propbag->add('stackable',     false);
  28          $propbag->add('author',        'Serendipity Team');
  29          $propbag->add('version',       '1.9');
  30          $propbag->add('requirements',  array(
  31              'serendipity' => '0.8',
  32              'smarty'      => '2.6.7',
  33              'php'         => '4.1.0'
  34          ));
  35          $propbag->add('cachable_events', array('frontend_display' => true));
  36          $propbag->add('event_hooks',   array('frontend_display' => true, 'frontend_display_cache' => true));
  37          $propbag->add('scrambles_true_content', true);
  38          $propbag->add('groups', array('STATISTICS'));
  39  
  40          $this->markup_elements = array(
  41              array(
  42                'name'     => 'ENTRY_BODY',
  43                'element'  => 'body',
  44              ),
  45              array(
  46                'name'     => 'EXTENDED_BODY',
  47                'element'  => 'extended',
  48              ),
  49              array(
  50                'name'     => 'COMMENT',
  51                'element'  => 'comment',
  52              ),
  53              array(
  54                'name'     => 'HTML_NUGGET',
  55                'element'  => 'html_nugget',
  56              )
  57          );
  58  
  59          $conf_array = array();
  60          foreach($this->markup_elements as $element) {
  61              $conf_array[] = $element['name'];
  62          }
  63          $conf_array[] = 'commentredirection';
  64          $propbag->add('configuration', $conf_array);
  65      }
  66  
  67      function install() {
  68          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  69      }
  70  
  71      function uninstall() {
  72          serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
  73          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  74      }
  75  
  76      function generate_content(&$title) {
  77          $title = $this->title;
  78      }
  79  
  80      function introspect_config_item($name, &$propbag)
  81      {
  82          switch($name) {
  83              case 'commentredirection':
  84                  $propbag->add('type',        'select');
  85                  $propbag->add('select_values', array('none'     => PLUGIN_EVENT_TRACKBACK_COMMENTREDIRECTION_NONE,
  86                                                       's9y'      => PLUGIN_EVENT_TRACKBACK_COMMENTREDIRECTION_S9Y,
  87                                                       'google'   => PLUGIN_EVENT_TRACKBACK_COMMENTREDIRECTION_GOOGLE));
  88                  $propbag->add('name',        PLUGIN_EVENT_TRACKBACK_COMMENTREDIRECTION);
  89                  $propbag->add('description', PLUGIN_EVENT_TRACKBACK_COMMENTREDIRECTION_BLAHBLA);
  90                  $propbag->add('default', 'none');
  91                  break;
  92  
  93              default:
  94                  $propbag->add('type',        'boolean');
  95                  $propbag->add('name',        constant($name));
  96                  $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
  97                  $propbag->add('default', 'true');
  98          }
  99          return true;
 100      }
 101  
 102      function event_hook($event, &$bag, &$eventData, $addData = null) {
 103          global $serendipity;
 104  
 105          $hooks = &$bag->get('event_hooks');
 106  
 107          if (isset($hooks[$event])) {
 108              switch($event) {
 109                  case 'frontend_display':
 110                      if ($bag->get('scrambles_true_content') && is_array($addData) && isset($addData['no_scramble'])) {
 111                          return true;
 112                      }
 113  
 114                  case 'frontend_display_cache':
 115                      $serendipity['encodeExitsCallback_entry_id'] = (int)(isset($eventData['entry_id']) ? $eventData['entry_id'] : $eventData['id']);
 116  
 117                      // Fetch all existing links from the database. They have been inserted there by our trackback-discovery.
 118                      if (empty($serendipity['encodeExitsCallback_entry_id'])) {
 119                          $this->links = array();
 120                      } else {
 121                          #echo "SELECT id, link FROM {$serendipity['dbPrefix']}references WHERE entry_id = {$serendipity['encodeExitsCallback_entry_id']} AND type = ''<br />\n";
 122                          $this->links = serendipity_db_query("SELECT id, link FROM {$serendipity['dbPrefix']}references WHERE entry_id = {$serendipity['encodeExitsCallback_entry_id']} AND (type = '' OR type IS NULL)", false, 'both', false, 'link', 'id');
 123                          #echo "<pre>" . print_r($this->links, true) . "</pre><br />\n";
 124                      }
 125  
 126                      foreach ($this->markup_elements as $temp) {
 127                          if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
 128                              !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
 129                              !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
 130                              $element = $temp['element'];
 131  
 132                              $eventData[$element] = preg_replace_callback(
 133                                  "#<a(.*)href=(\"|')http(s?)://([^\"']+)(\"|')([^>]*)>#isUm",
 134                                  array($this, '_encodeExitsCallback'),
 135                                  $eventData[$element]
 136                              );
 137  
 138                              if ($temp['element'] == 'comment' && !empty($eventData['url'])) {
 139                                  switch(trim($this->get_config('commentredirection'))) {
 140                                      case 's9y':
 141                                          $eventData['url'] = $this->_encodeExitsCallback(
 142                                                                array(
 143                                                                  1 => ' ',
 144                                                                  2 => '"',
 145                                                                  3 => '',
 146                                                                  4 => $eventData['url'],
 147                                                                  5 => '"'
 148                                                                ),
 149                                                                true
 150                                                              );
 151                                          break;
 152  
 153                                      case 'google':
 154                                          $eventData['url'] = 'http://www.google.com/url?sa=D&q=' . $eventData['url'];
 155                                          break;
 156  
 157                                      default:
 158                                          break;
 159                                  }
 160                              }
 161                          }
 162                      }
 163  
 164                      return true;
 165                      break;
 166  
 167                  default:
 168                      return false;
 169              }
 170  
 171          } else {
 172              return false;
 173          }
 174      }
 175  
 176  
 177      /**
 178      * Transforms '<a href="http://url/">' into
 179      * '<a href="exit.php?url=encurl" ...>'.
 180      */
 181      function _encodeExitsCallback($buffer, $url_only = false) {
 182          global $serendipity;
 183  
 184          $entry_id = $serendipity['encodeExitsCallback_entry_id'];
 185          $url      = 'http' . $buffer[3] . '://' . $buffer[4];
 186  
 187          if ($url_only) {
 188              return sprintf(
 189                  '%sexit.php?url=%s%s',
 190                  $serendipity['baseURL'],
 191                  base64_encode($buffer[4]),
 192                  ($entry_id != 0) ? '&amp;entry_id=' . $entry_id : ''
 193              );
 194          }
 195  
 196          $is_title = (stristr($buffer[0], 'title=')       !== false ? true : false);
 197          $is_over  = (stristr($buffer[0], 'onmouseover=') !== false ? true : false);
 198          $is_out   = (stristr($buffer[0], 'onmouseout=')  !== false ? true : false);
 199  
 200          $link     = '<a%shref="%sexit.php?url%s=%s%s" ' . (!$is_title ? 'title="%s" ' : '%s') . (!$is_over ? ' onmouseover="window.status=\'%s\';return true;" ' : '%s') . (!$is_out ? 'onmouseout="window.status=\'\';return true;"' : '') . '%s>';
 201  
 202          if (is_array($this->links) && !empty($this->links[$url])) {
 203              return sprintf(
 204                  $link,
 205                  $buffer[1],
 206                  $serendipity['baseURL'],
 207                  '_id',
 208                  $this->links[$url],
 209                  ($entry_id != 0) ? '&amp;entry_id=' . $entry_id : '',
 210                  (!$is_title ? htmlspecialchars($url) : ''),
 211                  (!$is_over  ? htmlspecialchars($url) : ''),
 212                  $buffer[6]
 213              );
 214          } else {
 215              return sprintf(
 216                  $link,
 217                  $buffer[1],
 218                  $serendipity['baseURL'],
 219                  '',
 220                  base64_encode($url),
 221                  ($entry_id != 0) ? '&amp;entry_id=' . $entry_id : '',
 222                  (!$is_title ? htmlspecialchars($url) : ''),
 223                  (!$is_over  ? htmlspecialchars($url) : ''),
 224                  $buffer[6]
 225              );
 226          }
 227      }
 228  }
 229  
 230  /* vim: set sts=4 ts=4 expandtab : */
 231  ?>


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