[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: serendipity_event_livesearch.php 1810 2007-08-04 12:51:11Z garvinhicking $
   2  
   3  if (IN_serendipity !== true) {
   4      die ("Don't hack!");
   5  }
   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_livesearch extends serendipity_event
  17  {
  18      var $title = PLUGIN_EVENT_LIVESEARCH_NAME;
  19  
  20      function introspect(&$propbag)
  21      {
  22          global $serendipity;
  23  
  24          $propbag->add('name',          PLUGIN_EVENT_LIVESEARCH_NAME);
  25          $propbag->add('description',   PLUGIN_EVENT_LIVESEARCH_DESC);
  26          $propbag->add('stackable',     false);
  27          $propbag->add('author',        'Christian Stocker, Garvin Hicking');
  28          $propbag->add('version',       '1.4');
  29          $propbag->add('requirements',  array(
  30              'serendipity' => '0.8',
  31              'smarty'      => '2.6.7',
  32              'php'         => '4.1.0'
  33          ));
  34          $propbag->add('event_hooks',    array(
  35              'external_plugin'    => true,
  36              'frontend_header'    => true,
  37              'css'                => true,
  38              'quicksearch_plugin' => true
  39          ));
  40          $propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
  41      }
  42  
  43      function generate_content(&$title) {
  44          $title = $this->title;
  45      }
  46  
  47      function event_hook($event, &$bag, &$eventData, $addData = null) {
  48          global $serendipity;
  49  
  50          $hooks = &$bag->get('event_hooks');
  51  
  52          if (isset($hooks[$event])) {
  53              switch($event) {
  54                  case 'css':
  55                      if (strpos($eventData, '.serendipity_livesearch_row')) {
  56                          // class exists in CSS, so a user has customized it and we don't need default
  57                          return true;
  58                      }
  59  ?>
  60  #LSResult {
  61      position: absolute;
  62      margin-left: 4px;
  63      margin-top: 4px;
  64         background-color: #fff7e8;
  65  }
  66  
  67  #LSShadow {
  68      position: relative;
  69      bottom: 1px;
  70      right: 1px;
  71      color: inherit;
  72      border-right: 2px solid #ccc;
  73      border-bottom: 2px solid #ccc;
  74  }
  75  
  76  #LSHighlight {
  77      background-color: #bdd2ec;
  78      color: black;
  79  }
  80  
  81  .serendipity_livesearch_row {
  82    margin: 0px;
  83    padding-top: 0.5em;
  84    padding-bottom: 0.5em;
  85    padding-left: 1.5em;
  86    padding-right: 1.5em;
  87    text-indent: -1em;
  88    line-height: 1.4em;
  89  }
  90  
  91  .serendipity_livesearch_result {
  92      position: relative;
  93      bottom: 2px;
  94      border: 1px solid black;
  95      right: 2px;
  96      padding: 2px;
  97  }
  98  <?php
  99                      break;
 100  
 101                  case 'frontend_header':
 102                      if (!$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false) {
 103                          echo '<script type="text/javascript" src="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/ls-js"></script>';
 104                      }
 105                      break;
 106  
 107                  case 'quicksearch_plugin':
 108                      echo '<script type="text/javascript">
 109                      lsbase = "' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/ls' . ($serendipity['rewrite'] == 'none' ? '_&' : '?') . '";
 110                      waittext = "' . PLUGIN_EVENT_LIVESEARCH_WAIT . '";
 111                      notfoundtext = "' . PLUGIN_EVENT_LIVESEARCH_NOTFOUND . '";
 112                      addLoadEvent(liveSearchInit);
 113                      </script>';
 114                      break;
 115  
 116                  case 'external_plugin':
 117                      $uri_parts = explode('?', str_replace('&amp;', '&', $eventData));
 118  
 119                      // Try to get request parameters from eventData name
 120                      if (!empty($uri_parts[1])) {
 121                          $reqs = explode('&', $uri_parts[1]);
 122                          foreach($reqs AS $id => $req) {
 123                              $val = explode('=', $req);
 124                              if (empty($_REQUEST[$val[0]])) {
 125                                  $_REQUEST[$val[0]] = $val[1];
 126                              }
 127                          }
 128                      }
 129  
 130                      $parts     = explode('_', $uri_parts[0]);
 131  
 132                      switch($parts[0]) {
 133                          case 'ls-js':
 134                              header('Content-Type: text/javascript');
 135                              echo file_get_contents(dirname(__FILE__) . '/serendipity_event_livesearch.js');
 136                              break;
 137  
 138                          case 'ls':
 139                              // header('X-Search: ' . htmlspecialchars($eventData) . ' leads to ' . preg_replace('@[^a-z0-9 \.\-_]@i', '', $_REQUEST['s']));
 140                              $res = serendipity_searchEntries($_REQUEST['s']);
 141  
 142                              echo '<?xml version="1.0" encoding="utf-8" ?>';
 143                              echo '<div class="serendipity_livesearch_result">';
 144  
 145                              if (is_array($res) && count($res) > 0) {
 146                                  foreach($res AS $id => $entry) {
 147                                      echo '<div class="serendipity_livesearch_row"><a href="' . serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])) . '">' . htmlspecialchars($entry['title']) . '</a></div>';
 148                                  }
 149                              } else {
 150                                  echo '<div class="serendipity_livesearch_row">' . print_r($res, true) . '</div>';
 151                              }
 152  
 153                              echo '</div>';
 154  
 155                              break;
 156                      }
 157  
 158                      return true;
 159                      break;
 160  
 161                  default:
 162                      return false;
 163                      break;
 164              }
 165          } else {
 166              return false;
 167          }
 168      }
 169  }
 170  
 171  /* vim: set sts=4 ts=4 expandtab : */
 172  ?>


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