ajax.php
author Dan
Sat, 03 Nov 2007 07:40:54 -0400
changeset 228 b0a4d179be85
parent 195 eec079676fe7
parent 227 0eca1498a77b
child 304 e2cb5f1432c8
permissions -rw-r--r--
Merging in fixes and updates from 90b7a52bea45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     1
<?php
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     2
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     3
/*
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     5
 * Version 1.1.1
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     7
 *
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    10
 *
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    13
 */
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    14
 
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    15
  // fillusername should be done without the help of the rest of Enano - all we need is the DBAL
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    16
  if ( isset($_GET['_mode']) && $_GET['_mode'] == 'fillusername' )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    17
  {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    18
    // setup and load a very basic, specialized instance of the Enano API
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    19
    function dc_here($m)     { return false; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    20
    function dc_dump($a, $g) { return false; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    21
    function dc_watch($n)    { return false; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    22
    function dc_start_timer($u) { return false; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    23
    function dc_stop_timer($m) { return false; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    24
    // Determine directory (special case for development servers)
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    25
    if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    26
    {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    27
      $filename = str_replace('/repo/', '/', __FILE__);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    28
    }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    29
    else
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    30
    {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    31
      $filename = __FILE__;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    32
    }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    33
    define('ENANO_ROOT', dirname($filename));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    34
    require(ENANO_ROOT.'/includes/functions.php');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    35
    require(ENANO_ROOT.'/includes/dbal.php');
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    36
    require(ENANO_ROOT.'/includes/json.php');
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    37
    $db = new mysql();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    38
    $db->connect();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    39
    
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    40
    // result is sent using JSON
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    41
    $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    42
    $return = Array(
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    43
        'mode' => 'success',
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    44
        'users_real' => Array()
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    45
      );
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    46
    
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    47
    // should be connected to the DB now
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    48
    $name = (isset($_GET['name'])) ? $db->escape($_GET['name']) : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    49
    if ( !$name )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    50
    {
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    51
      $return = array(
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    52
        'mode' => 'error',
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    53
        'error' => 'Invalid URI'
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    54
      );
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    55
      die( $json->encode($return) );
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    56
    }
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    57
    $allowanon = ( isset($_GET['allowanon']) && $_GET['allowanon'] == '1' ) ? '' : ' AND user_id > 1';
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    58
    $q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE lcase(username) LIKE lcase(\'%'.$name.'%\')' . $allowanon . ' ORDER BY username ASC;');
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    59
    if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    60
    {
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    61
      $return = array(
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    62
        'mode' => 'error',
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    63
        'error' => 'MySQL error selecting username data: '.addslashes(mysql_error())
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    64
      );
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    65
      die( $json->encode($return) );
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    66
    }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    67
    $i = 0;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    68
    while($r = $db->fetchrow())
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    69
    {
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    70
      $return['users_real'][] = $r['username'];
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    71
      $i++;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    72
    }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    73
    $db->free_result();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    74
    
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    75
    // all done! :-)
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    76
    $db->close();
209
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    77
    
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    78
    echo $json->encode( $return );
8a00247d1dee Login page mostly localized
Dan
parents: 204
diff changeset
    79
    
204
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    80
    exit;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    81
  }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    82
 
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    83
  require('includes/common.php');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    84
  
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    85
  global $db, $session, $paths, $template, $plugins; // Common objects
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    86
  if(!isset($_GET['_mode'])) die('This script cannot be accessed directly.');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    87
  
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    88
  $_ob = '';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    89
  
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    90
  switch($_GET['_mode']) {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    91
    case "checkusername":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    92
      echo PageUtils::checkusername($_GET['name']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    93
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    94
    case "getsource":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    95
      $p = ( isset($_GET['pagepass']) ) ? $_GET['pagepass'] : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    96
      echo PageUtils::getsource($paths->page, $p);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    97
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    98
    case "getpage":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
    99
      // echo PageUtils::getpage($paths->page, false, ( (isset($_GET['oldid'])) ? $_GET['oldid'] : false ));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   100
      $revision_id = ( (isset($_GET['oldid'])) ? intval($_GET['oldid']) : 0 );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   101
      $page = new PageProcessor( $paths->cpage['urlname_nons'], $paths->namespace, $revision_id );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   102
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   103
      $pagepass = ( isset($_REQUEST['pagepass']) ) ? $_REQUEST['pagepass'] : '';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   104
      $page->password = $pagepass;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   105
            
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   106
      $page->send();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   107
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   108
    case "savepage":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   109
      $summ = ( isset($_POST['summary']) ) ? $_POST['summary'] : '';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   110
      $minor = isset($_POST['minor']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   111
      $e = PageUtils::savepage($paths->cpage['urlname_nons'], $paths->namespace, $_POST['text'], $summ, $minor);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   112
      if($e=='good')
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   113
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   114
        $page = new PageProcessor($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   115
        $page->send();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   116
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   117
      else
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   118
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   119
        echo '<p>Error saving the page: '.$e.'</p>';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   120
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   121
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   122
    case "protect":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   123
      echo PageUtils::protect($paths->cpage['urlname_nons'], $paths->namespace, (int)$_POST['level'], $_POST['reason']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   124
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   125
    case "histlist":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   126
      echo PageUtils::histlist($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   127
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   128
    case "rollback":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   129
      echo PageUtils::rollback( (int)$_GET['id'] );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   130
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   131
    case "comments":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   132
      $comments = new Comments($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   133
      if ( isset($_POST['data']) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   134
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   135
        $comments->process_json($_POST['data']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   136
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   137
      else
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   138
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   139
        die('{ "mode" : "error", "error" : "No input" }');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   140
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   141
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   142
    case "rename":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   143
      echo PageUtils::rename($paths->cpage['urlname_nons'], $paths->namespace, $_POST['newtitle']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   144
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   145
    case "flushlogs":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   146
      echo PageUtils::flushlogs($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   147
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   148
    case "deletepage":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   149
      $reason = ( isset($_POST['reason']) ) ? $_POST['reason'] : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   150
      if ( empty($reason) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   151
        die('Please enter a reason for deleting this page.');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   152
      echo PageUtils::deletepage($paths->cpage['urlname_nons'], $paths->namespace, $reason);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   153
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   154
    case "delvote":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   155
      echo PageUtils::delvote($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   156
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   157
    case "resetdelvotes":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   158
      echo PageUtils::resetdelvotes($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   159
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   160
    case "getstyles":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   161
      echo PageUtils::getstyles($_GET['id']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   162
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   163
    case "catedit":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   164
      echo PageUtils::catedit($paths->cpage['urlname_nons'], $paths->namespace);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   165
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   166
    case "catsave":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   167
      echo PageUtils::catsave($paths->cpage['urlname_nons'], $paths->namespace, $_POST);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   168
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   169
    case "setwikimode":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   170
      echo PageUtils::setwikimode($paths->cpage['urlname_nons'], $paths->namespace, (int)$_GET['mode']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   171
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   172
    case "setpass":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   173
      echo PageUtils::setpass($paths->cpage['urlname_nons'], $paths->namespace, $_POST['password']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   174
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   175
    case "fillusername":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   176
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   177
    case "fillpagename":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   178
      $name = (isset($_GET['name'])) ? $_GET['name'] : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   179
      if(!$name) die('userlist = new Array(); namelist = new Array(); errorstring=\'Invalid URI\'');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   180
      $nd = RenderMan::strToPageID($name);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   181
      $c = 0;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   182
      $u = Array();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   183
      $n = Array();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   184
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   185
      $name = sanitize_page_id($name);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   186
      $name = str_replace('_', ' ', $name);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   187
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   188
      for($i=0;$i<sizeof($paths->pages)/2;$i++)
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   189
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   190
        if( ( 
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   191
            preg_match('#'.preg_quote($name).'(.*)#i', $paths->pages[$i]['name']) ||
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   192
            preg_match('#'.preg_quote($name).'(.*)#i', $paths->pages[$i]['urlname']) ||
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   193
            preg_match('#'.preg_quote($name).'(.*)#i', $paths->pages[$i]['urlname_nons']) ||
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   194
            preg_match('#'.preg_quote(str_replace(' ', '_', $name)).'(.*)#i', $paths->pages[$i]['name']) ||
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   195
            preg_match('#'.preg_quote(str_replace(' ', '_', $name)).'(.*)#i', $paths->pages[$i]['urlname']) ||
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   196
            preg_match('#'.preg_quote(str_replace(' ', '_', $name)).'(.*)#i', $paths->pages[$i]['urlname_nons'])
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   197
            ) &&
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   198
           ( ( $nd[1] != 'Article' && $paths->pages[$i]['namespace'] == $nd[1] ) || $nd[1] == 'Article' )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   199
            && $paths->pages[$i]['visible']
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   200
           )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   201
        {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   202
          $c++;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   203
          $u[] = $paths->pages[$i]['name'];
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   204
          $n[] = $paths->pages[$i]['urlname'];
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   205
        }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   206
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   207
      if($c > 0)
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   208
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   209
        echo 'userlist = new Array(); namelist = new Array(); errorstring = false; '."\n";
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   210
        for($i=0;$i<sizeof($u);$i++) // Can't use foreach because we need the value of $i and we need to use both $u and $n
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   211
        {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   212
          echo "userlist[$i] = '".addslashes($n[$i])."';\n";
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   213
          echo "namelist[$i] = '".addslashes(htmlspecialchars($u[$i]))."';\n";
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   214
        }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   215
      } else {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   216
        die('userlist = new Array(); namelist = new Array(); errorstring=\'No page matches found.\'');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   217
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   218
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   219
    case "preview":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   220
      echo PageUtils::genPreview($_POST['text']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   221
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   222
    case "pagediff":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   223
      $id1 = ( isset($_GET['diff1']) ) ? (int)$_GET['diff1'] : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   224
      $id2 = ( isset($_GET['diff2']) ) ? (int)$_GET['diff2'] : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   225
      if(!$id1 || !$id2) { echo '<p>Invalid request.</p>'; $template->footer(); break; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   226
      if(!preg_match('#^([0-9]+)$#', (string)$_GET['diff1']) ||
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   227
         !preg_match('#^([0-9]+)$#', (string)$_GET['diff2']  )) { echo '<p>SQL injection attempt</p>'; $template->footer(); break; }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   228
      echo PageUtils::pagediff($paths->cpage['urlname_nons'], $paths->namespace, $id1, $id2);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   229
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   230
    case "jsres":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   231
      die('// ERROR: this section is deprecated and has moved to includes/clientside/static/enano-lib-basic.js.');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   232
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   233
    case "rdns":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   234
      if(!$session->get_permissions('mod_misc')) die('Go somewhere else for your reverse DNS info!');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   235
      $ip = $_GET['ip'];
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   236
      $rdns = gethostbyaddr($ip);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   237
      if($rdns == $ip) echo 'Unable to get reverse DNS information. Perhaps the DNS server is down or the PTR record no longer exists.';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   238
      else echo $rdns;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   239
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   240
    case 'acljson':
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   241
      $parms = ( isset($_POST['acl_params']) ) ? rawurldecode($_POST['acl_params']) : false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   242
      echo PageUtils::acl_json($parms);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   243
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   244
    case "change_theme":
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   245
      if ( !isset($_POST['theme_id']) || !isset($_POST['style_id']) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   246
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   247
        die('Invalid input');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   248
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   249
      if ( !preg_match('/^([a-z0-9_-]+)$/i', $_POST['theme_id']) || !preg_match('/^([a-z0-9_-]+)$/i', $_POST['style_id']) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   250
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   251
        die('Invalid input');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   252
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   253
      if ( !file_exists(ENANO_ROOT . '/themes/' . $_POST['theme_id'] . '/css/' . $_POST['style_id'] . '.css') )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   254
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   255
        die('Can\'t find theme file: ' . ENANO_ROOT . '/themes/' . $_POST['theme_id'] . '/css/' . $_POST['style_id'] . '.css');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   256
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   257
      if ( !$session->user_logged_in )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   258
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   259
        die('You must be logged in to change your theme');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   260
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   261
      // Just in case something slipped through...
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   262
      $theme_id = $db->escape($_POST['theme_id']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   263
      $style_id = $db->escape($_POST['style_id']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   264
      $e = $db->sql_query('UPDATE ' . table_prefix . "users SET theme='$theme_id', style='$style_id' WHERE user_id=$session->user_id;");
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   265
      if ( !$e )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   266
        die( $db->get_error() );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   267
      die('GOOD');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   268
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   269
    case 'get_tags':
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   270
      $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   271
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   272
      $ret = array('tags' => array(), 'user_level' => $session->user_level, 'can_add' => $session->get_permissions('tag_create'));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   273
      $q = $db->sql_query('SELECT t.tag_id, t.tag_name, pg.pg_target IS NOT NULL AS used_in_acl, t.user FROM '.table_prefix.'tags AS t
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   274
        LEFT JOIN '.table_prefix.'page_groups AS pg
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   275
          ON ( ( pg.pg_type = ' . PAGE_GRP_TAGGED . ' AND pg.pg_target=t.tag_name ) OR ( pg.pg_type IS NULL AND pg.pg_target IS NULL ) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   276
        WHERE t.page_id=\'' . $db->escape($paths->cpage['urlname_nons']) . '\' AND t.namespace=\'' . $db->escape($paths->namespace) . '\';');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   277
      if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   278
        $db->_die();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   279
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   280
      while ( $row = $db->fetchrow() )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   281
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   282
        $can_del = true;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   283
        
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   284
        $perm = ( $row['user'] != $session->user_id ) ?
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   285
                'tag_delete_other' :
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   286
                'tag_delete_own';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   287
        
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   288
        if ( $row['user'] == 1 && !$session->user_logged_in )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   289
          // anonymous user trying to delete tag (hardcode blacklisted)
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   290
          $can_del = false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   291
          
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   292
        if ( !$session->get_permissions($perm) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   293
          $can_del = false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   294
        
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   295
        if ( $row['used_in_acl'] == 1 && !$session->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   296
          $can_del = false;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   297
        
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   298
        $ret['tags'][] = array(
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   299
          'id' => $row['tag_id'],
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   300
          'name' => $row['tag_name'],
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   301
          'can_del' => $can_del,
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   302
          'acl' => ( $row['used_in_acl'] == 1 )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   303
        );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   304
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   305
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   306
      echo $json->encode($ret);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   307
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   308
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   309
    case 'addtag':
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   310
      $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   311
      $resp = array(
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   312
          'success' => false,
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   313
          'error' => 'No error',
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   314
          'can_del' => ( $session->get_permissions('tag_delete_own') && $session->user_logged_in ),
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   315
          'in_acl' => false
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   316
        );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   317
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   318
      // first of course, are we allowed to tag pages?
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   319
      if ( !$session->get_permissions('tag_create') )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   320
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   321
        $resp['error'] = 'You are not permitted to tag pages.';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   322
        die($json->encode($resp));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   323
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   324
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   325
      // sanitize the tag name
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   326
      $tag = sanitize_tag($_POST['tag']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   327
      $tag = $db->escape($tag);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   328
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   329
      if ( strlen($tag) < 2 )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   330
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   331
        $resp['error'] = 'Tags must consist of at least 2 alphanumeric characters.';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   332
        die($json->encode($resp));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   333
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   334
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   335
      // check if tag is already on page
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   336
      $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'tags WHERE page_id=\'' . $db->escape($paths->cpage['urlname_nons']) . '\' AND namespace=\'' . $db->escape($paths->namespace) . '\' AND tag_name=\'' . $tag . '\';');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   337
      if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   338
        $db->_die();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   339
      if ( $db->numrows() > 0 )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   340
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   341
        $resp['error'] = 'This page already has this tag.';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   342
        die($json->encode($resp));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   343
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   344
      $db->free_result();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   345
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   346
      // tricky: make sure this tag isn't being used in some page group, and thus adding it could affect page access
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   347
      $can_edit_acl = ( $session->get_permissions('edit_acl') || $session->user_level >= USER_LEVEL_ADMIN );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   348
      $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'page_groups WHERE pg_type=' . PAGE_GRP_TAGGED . ' AND pg_target=\'' . $tag . '\';');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   349
      if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   350
        $db->_die();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   351
      if ( $db->numrows() > 0 && !$can_edit_acl )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   352
      {
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   353
        $resp['error'] = 'This tag is used in an ACL page group, and thus can\'t be added to a page by people without administrator privileges.';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   354
        die($json->encode($resp));
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   355
      }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   356
      $resp['in_acl'] = ( $db->numrows() > 0 );
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   357
      $db->free_result();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   358
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   359
      // we're good
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   360
      $q = $db->sql_query('INSERT INTO '.table_prefix.'tags(tag_name,page_id,namespace,user) VALUES(\'' . $tag . '\', \'' . $db->escape($paths->cpage['urlname_nons']) . '\', \'' . $db->escape($paths->namespace) . '\', ' . $session->user_id . ');');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   361
      if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   362
        $db->_die();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   363
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   364
      $resp['success'] = true;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   365
      $resp['tag'] = $tag;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   366
      $resp['tag_id'] = $db->insert_id();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   367
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   368
      echo $json->encode($resp);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   369
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   370
    case 'deltag':
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   371
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   372
      $tag_id = intval($_POST['tag_id']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   373
      if ( empty($tag_id) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   374
        die('Invalid tag ID');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   375
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   376
      $q = $db->sql_query('SELECT t.tag_id, t.user, t.page_id, t.namespace, pg.pg_target IS NOT NULL AS used_in_acl FROM '.table_prefix.'tags AS t
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   377
  LEFT JOIN '.table_prefix.'page_groups AS pg
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   378
    ON ( pg.pg_id IS NULL OR ( pg.pg_target = t.tag_name AND pg.pg_type = ' . PAGE_GRP_TAGGED . ' ) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   379
  WHERE t.tag_id=' . $tag_id . ';');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   380
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   381
      if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   382
        $db->_die();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   383
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   384
      if ( $db->numrows() < 1 )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   385
        die('Could not find a tag with that ID');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   386
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   387
      $row = $db->fetchrow();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   388
      $db->free_result();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   389
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   390
      if ( $row['page_id'] == $paths->cpage['urlname_nons'] && $row['namespace'] == $paths->namespace )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   391
        $perms =& $session;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   392
      else
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   393
        $perms = $session->fetch_page_acl($row['page_id'], $row['namespace']);
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   394
        
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   395
      $perm = ( $row['user'] != $session->user_id ) ?
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   396
                'tag_delete_other' :
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   397
                'tag_delete_own';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   398
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   399
      if ( $row['user'] == 1 && !$session->user_logged_in )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   400
        // anonymous user trying to delete tag (hardcode blacklisted)
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   401
        die('You are not authorized to delete this tag.');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   402
        
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   403
      if ( !$perms->get_permissions($perm) )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   404
        die('You are not authorized to delete this tag.');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   405
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   406
      if ( $row['used_in_acl'] == 1 && !$perms->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   407
        die('You are not authorized to delete this tag.');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   408
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   409
      // We're good
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   410
      $q = $db->sql_query('DELETE FROM '.table_prefix.'tags WHERE tag_id = ' . $tag_id . ';');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   411
      if ( !$q )
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   412
        $db->_die();
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   413
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   414
      echo 'success';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   415
      
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   416
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   417
    case 'ping':
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   418
      echo 'pong';
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   419
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   420
    default:
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   421
      die('Hacking attempt');
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   422
      break;
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   423
  }
473cc747022a You know what folks, a lot of Mercurial merges failed, and I just now figured out why. So now all changes from stable are permanently synced in.
Dan
parents: 187 194
diff changeset
   424
  
0
902822492a68 Initial population
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   425
?>