plugins/SpecialPageFuncs.php
changeset 1227 bdac73ed481e
parent 1208 438f36013432
child 1244 ba80cfffb673
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
     1 <?php
     1 <?php
     2 /**!info**
     2 /**!info**
     3 {
     3 {
     4   "Plugin Name"  : "plugin_specialpagefuncs_title",
     4 	"Plugin Name"  : "plugin_specialpagefuncs_title",
     5   "Plugin URI"   : "http://enanocms.org/",
     5 	"Plugin URI"   : "http://enanocms.org/",
     6   "Description"  : "plugin_specialpagefuncs_desc",
     6 	"Description"  : "plugin_specialpagefuncs_desc",
     7   "Author"       : "Dan Fuhry",
     7 	"Author"       : "Dan Fuhry",
     8   "Version"      : "1.1.6",
     8 	"Version"      : "1.1.6",
     9   "Author URI"   : "http://enanocms.org/"
     9 	"Author URI"   : "http://enanocms.org/"
    10 }
    10 }
    11 **!*/
    11 **!*/
    12 
    12 
    13 /*
    13 /*
    14  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    14  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    25 
    25 
    26 // $plugins->attachHook('session_started', 'SpecialPageFuncs_paths_init();');
    26 // $plugins->attachHook('session_started', 'SpecialPageFuncs_paths_init();');
    27 
    27 
    28 function SpecialPageFuncs_paths_init()
    28 function SpecialPageFuncs_paths_init()
    29 {
    29 {
    30   register_special_page('CreatePage', 'specialpage_create_page');
    30 	register_special_page('CreatePage', 'specialpage_create_page');
    31   register_special_page('AllPages', 'specialpage_all_pages');
    31 	register_special_page('AllPages', 'specialpage_all_pages');
    32   register_special_page('SpecialPages', 'specialpage_special_pages');
    32 	register_special_page('SpecialPages', 'specialpage_special_pages');
    33   register_special_page('About_Enano', 'specialpage_about_enano');
    33 	register_special_page('About_Enano', 'specialpage_about_enano');
    34   register_special_page('GNU_General_Public_License', 'specialpage_gnu_gpl');
    34 	register_special_page('GNU_General_Public_License', 'specialpage_gnu_gpl');
    35   register_special_page('TagCloud', 'specialpage_tag_cloud');
    35 	register_special_page('TagCloud', 'specialpage_tag_cloud');
    36   register_special_page('Autofill', 'specialpage_autofill', false);
    36 	register_special_page('Autofill', 'specialpage_autofill', false);
    37 }
    37 }
    38 
    38 
    39 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    39 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    40 
    40 
    41 function page_Special_CreatePage()
    41 function page_Special_CreatePage()
    42 {
    42 {
    43   global $db, $session, $paths, $template, $plugins; // Common objects
    43 	global $db, $session, $paths, $template, $plugins; // Common objects
    44   global $lang;
    44 	global $lang;
    45   
    45 	
    46   $whitelist_ns = array('Article', 'User', 'Help', 'Template', 'Category', 'Project');
    46 	$whitelist_ns = array('Article', 'User', 'Help', 'Template', 'Category', 'Project');
    47   if ( $session->user_level >= USER_LEVEL_ADMIN )
    47 	if ( $session->user_level >= USER_LEVEL_ADMIN )
    48   {
    48 	{
    49     $whitelist_ns[] = 'System';
    49 		$whitelist_ns[] = 'System';
    50   }
    50 	}
    51   $code = $plugins->setHook('page_create_ns_whitelist');
    51 	$code = $plugins->setHook('page_create_ns_whitelist');
    52   foreach ( $code as $cmd )
    52 	foreach ( $code as $cmd )
    53   {
    53 	{
    54     eval($cmd);
    54 		eval($cmd);
    55   }
    55 	}
    56   
    56 	
    57   $errors = array();
    57 	$errors = array();
    58   
    58 	
    59   switch ( isset($_POST['page_title']) )
    59 	switch ( isset($_POST['page_title']) )
    60   {
    60 	{
    61     case true:
    61 		case true:
    62       // "Create page" was clicked
    62 			// "Create page" was clicked
    63       
    63 			
    64       //
    64 			//
    65       // VALIDATION CODE
    65 			// VALIDATION CODE
    66       //
    66 			//
    67       
    67 			
    68       // Check namespace
    68 			// Check namespace
    69       $namespace = ( isset($_POST['namespace']) ) ? $_POST['namespace'] : 'Article';
    69 			$namespace = ( isset($_POST['namespace']) ) ? $_POST['namespace'] : 'Article';
    70       if ( !in_array($namespace, $whitelist_ns) )
    70 			if ( !in_array($namespace, $whitelist_ns) )
    71       {
    71 			{
    72         $errors[] = $lang->get('pagetools_create_err_invalid_namespace');
    72 				$errors[] = $lang->get('pagetools_create_err_invalid_namespace');
    73       }
    73 			}
    74       
    74 			
    75       // Check title and figure out urlname
    75 			// Check title and figure out urlname
    76       $title = $_POST['page_title'];
    76 			$title = $_POST['page_title'];
    77       $urlname = $_POST['page_title'];
    77 			$urlname = $_POST['page_title'];
    78       if ( @$_POST['custom_url'] === 'yes' && isset($_POST['urlname']) )
    78 			if ( @$_POST['custom_url'] === 'yes' && isset($_POST['urlname']) )
    79       {
    79 			{
    80         $urlname = $_POST['urlname'];
    80 				$urlname = $_POST['urlname'];
    81       }
    81 			}
    82       $urlname = sanitize_page_id($urlname);
    82 			$urlname = sanitize_page_id($urlname);
    83       if ( $urlname == '.00' || empty($urlname) )
    83 			if ( $urlname == '.00' || empty($urlname) )
    84       {
    84 			{
    85         $errors[] = $lang->get('pagetools_create_err_invalid_urlname');
    85 				$errors[] = $lang->get('pagetools_create_err_invalid_urlname');
    86       }
    86 			}
    87       
    87 			
    88       // Validate page existence
    88 			// Validate page existence
    89       $pathskey = $paths->nslist[$namespace] . $urlname;
    89 			$pathskey = $paths->nslist[$namespace] . $urlname;
    90       if ( isPage($pathskey) )
    90 			if ( isPage($pathskey) )
    91       {
    91 			{
    92         $errors[] = $lang->get('pagetools_create_err_already_exists');
    92 				$errors[] = $lang->get('pagetools_create_err_already_exists');
    93       }
    93 			}
    94       
    94 			
    95       // Validate permissions
    95 			// Validate permissions
    96       $perms = $session->fetch_page_acl($urlname, $namespace);
    96 			$perms = $session->fetch_page_acl($urlname, $namespace);
    97       if ( !$perms->get_permissions('create_page') )
    97 			if ( !$perms->get_permissions('create_page') )
    98       {
    98 			{
    99         $errors[] = $lang->get('pagetools_create_err_no_permission');
    99 				$errors[] = $lang->get('pagetools_create_err_no_permission');
   100       }
   100 			}
   101       
   101 			
   102       // Run hooks
   102 			// Run hooks
   103       $code = $plugins->setHook('page_create_request');
   103 			$code = $plugins->setHook('page_create_request');
   104       foreach ( $code as $cmd )
   104 			foreach ( $code as $cmd )
   105       {
   105 			{
   106         eval($cmd);
   106 				eval($cmd);
   107       }
   107 			}
   108       
   108 			
   109       // Create the page
   109 			// Create the page
   110       if ( count($errors) < 1 )
   110 			if ( count($errors) < 1 )
   111       {
   111 			{
   112         $page = new PageProcessor($urlname, $namespace);
   112 				$page = new PageProcessor($urlname, $namespace);
   113         $page->create_page($title);
   113 				$page->create_page($title);
   114         if ( $error = $page->pop_error() )
   114 				if ( $error = $page->pop_error() )
   115         {
   115 				{
   116           do
   116 					do
   117           {
   117 					{
   118             $errors[] = $error;
   118 						$errors[] = $error;
   119           }
   119 					}
   120           while ( $error = $page->pop_error() );
   120 					while ( $error = $page->pop_error() );
   121         }
   121 				}
   122         else
   122 				else
   123         {
   123 				{
   124           redirect(makeUrlNS($namespace, $urlname) . '#do:edit', '', '', 0);
   124 					redirect(makeUrlNS($namespace, $urlname) . '#do:edit', '', '', 0);
   125           return true;
   125 					return true;
   126         }
   126 				}
   127       }
   127 			}
   128       
   128 			
   129       break;
   129 			break;
   130   }
   130 	}
   131   
   131 	
   132   $template->header();
   132 	$template->header();
   133   
   133 	
   134   echo $lang->get('pagetools_create_blurb');
   134 	echo $lang->get('pagetools_create_blurb');
   135   
   135 	
   136   if ( count($errors) > 0 )
   136 	if ( count($errors) > 0 )
   137   {
   137 	{
   138     echo '<div class="error-box">' . implode("<br />\n        ", $errors) . '</div>';
   138 		echo '<div class="error-box">' . implode("<br />\n        ", $errors) . '</div>';
   139   }
   139 	}
   140   
   140 	
   141   ?>
   141 	?>
   142   <enano:no-opt>
   142 	<enano:no-opt>
   143   <script type="text/javascript">
   143 	<script type="text/javascript">
   144     window.cpGenPreviewUrl = function()
   144 		window.cpGenPreviewUrl = function()
   145     {
   145 		{
   146       if ( typeof(load_component) != 'function' )
   146 			if ( typeof(load_component) != 'function' )
   147         return false;
   147 				return false;
   148       
   148 			
   149       var frm = document.forms['create_form'];
   149 			var frm = document.forms['create_form'];
   150       var radio_custom = frm.getElementsByTagName('input')[2];
   150 			var radio_custom = frm.getElementsByTagName('input')[2];
   151       var use_custom_url = radio_custom.checked;
   151 			var use_custom_url = radio_custom.checked;
   152       if ( use_custom_url )
   152 			if ( use_custom_url )
   153       {
   153 			{
   154         var title_src = frm.urlname.value;
   154 				var title_src = frm.urlname.value;
   155       }
   155 			}
   156       else
   156 			else
   157       {
   157 			{
   158         var title_src = frm.page_title.value;
   158 				var title_src = frm.page_title.value;
   159       }
   159 			}
   160       var url = window.location.protocol + '//' + window.location.hostname + contentPath + namespace_list[frm.namespace.value] + sanitize_page_id(title_src);
   160 			var url = window.location.protocol + '//' + window.location.hostname + contentPath + namespace_list[frm.namespace.value] + sanitize_page_id(title_src);
   161       document.getElementById('createpage_url_preview').firstChild.nodeValue = url;
   161 			document.getElementById('createpage_url_preview').firstChild.nodeValue = url;
   162     }
   162 		}
   163   </script>
   163 	</script>
   164   </enano:no-opt>
   164 	</enano:no-opt>
   165   <?php
   165 	<?php
   166   
   166 	
   167   echo '<form action="' . makeUrlNS('Special', 'CreatePage') . '" method="post" name="create_form">';
   167 	echo '<form action="' . makeUrlNS('Special', 'CreatePage') . '" method="post" name="create_form">';
   168   
   168 	
   169   echo '<p>';
   169 	echo '<p>';
   170     echo $lang->get('pagetools_create_field_title');
   170 		echo $lang->get('pagetools_create_field_title');
   171     echo ' <input onkeyup="cpGenPreviewUrl();" type="text" name="page_title" size="40" tabindex="1" />';
   171 		echo ' <input onkeyup="cpGenPreviewUrl();" type="text" name="page_title" size="40" tabindex="1" />';
   172     echo '</p>';
   172 		echo '</p>';
   173     
   173 		
   174   echo '<p>';
   174 	echo '<p>';
   175     echo $lang->get('pagetools_create_field_namespace');
   175 		echo $lang->get('pagetools_create_field_namespace');
   176     echo ' <select onchange="cpGenPreviewUrl();" name="namespace" tabindex="2">';
   176 		echo ' <select onchange="cpGenPreviewUrl();" name="namespace" tabindex="2">';
   177     foreach ( $paths->nslist as $ns => $ns_prefix )
   177 		foreach ( $paths->nslist as $ns => $ns_prefix )
   178     {
   178 		{
   179       if ( !in_array($ns, $whitelist_ns) )
   179 			if ( !in_array($ns, $whitelist_ns) )
   180         continue;
   180 				continue;
   181       $lang_string = 'onpage_lbl_page_' . strtolower($ns);
   181 			$lang_string = 'onpage_lbl_page_' . strtolower($ns);
   182       $str = $lang->get($lang_string);
   182 			$str = $lang->get($lang_string);
   183       if ( $str == $lang_string )
   183 			if ( $str == $lang_string )
   184         $str = $ns;
   184 				$str = $ns;
   185       
   185 			
   186       echo '<option value="' . $ns . '">' . ucwords($str) . '</option>';
   186 			echo '<option value="' . $ns . '">' . ucwords($str) . '</option>';
   187     }
   187 		}
   188     echo '</select>';
   188 		echo '</select>';
   189     echo '</p>';
   189 		echo '</p>';
   190     
   190 		
   191   echo '<fieldset enano:expand="closed">';
   191 	echo '<fieldset enano:expand="closed">';
   192   echo '<legend>' . $lang->get('pagetools_create_group_advanced') . '</legend>';
   192 	echo '<legend>' . $lang->get('pagetools_create_group_advanced') . '</legend>';
   193   
   193 	
   194   echo '<p>';
   194 	echo '<p>';
   195     echo '<label><input tabindex="3" type="radio" name="custom_url" value="no" checked="checked" onclick="cpGenPreviewUrl(); document.getElementById(\'createpage_custom_url\').style.display = \'none\';" /> ' . $lang->get('pagetools_create_field_url_auto') . '</label>';
   195 		echo '<label><input tabindex="3" type="radio" name="custom_url" value="no" checked="checked" onclick="cpGenPreviewUrl(); document.getElementById(\'createpage_custom_url\').style.display = \'none\';" /> ' . $lang->get('pagetools_create_field_url_auto') . '</label>';
   196     echo '</p>';
   196 		echo '</p>';
   197   
   197 	
   198   echo '<p>';
   198 	echo '<p>';
   199     echo '<label><input tabindex="3" type="radio" name="custom_url" value="yes" onclick="cpGenPreviewUrl(); document.getElementById(\'createpage_custom_url\').style.display = \'block\';" /> ' . $lang->get('pagetools_create_field_url_manual') . '</label>';
   199 		echo '<label><input tabindex="3" type="radio" name="custom_url" value="yes" onclick="cpGenPreviewUrl(); document.getElementById(\'createpage_custom_url\').style.display = \'block\';" /> ' . $lang->get('pagetools_create_field_url_manual') . '</label>';
   200     echo '</p>';
   200 		echo '</p>';
   201   
   201 	
   202   echo '<p id="createpage_custom_url" style="display: none; margin-left: 2em;">';
   202 	echo '<p id="createpage_custom_url" style="display: none; margin-left: 2em;">';
   203     echo $lang->get('pagetools_create_field_url');
   203 		echo $lang->get('pagetools_create_field_url');
   204     echo ' <input onkeyup="cpGenPreviewUrl();" tabindex="4" type="text" name="urlname" value="" size="40" />';
   204 		echo ' <input onkeyup="cpGenPreviewUrl();" tabindex="4" type="text" name="urlname" value="" size="40" />';
   205     echo '</p>';
   205 		echo '</p>';
   206     
   206 		
   207   echo '<p>';
   207 	echo '<p>';
   208     echo $lang->get('pagetools_create_field_preview') . ' <tt id="createpage_url_preview"> </tt><br />';
   208 		echo $lang->get('pagetools_create_field_preview') . ' <tt id="createpage_url_preview"> </tt><br />';
   209     echo '<small>' . $lang->get('pagetools_create_field_preview_hint') . '</small>';
   209 		echo '<small>' . $lang->get('pagetools_create_field_preview_hint') . '</small>';
   210     echo '</p>';
   210 		echo '</p>';
   211   
   211 	
   212   echo '</fieldset>';
   212 	echo '</fieldset>';
   213   
   213 	
   214   echo '<p>';
   214 	echo '<p>';
   215     echo '<input tabindex="5" type="submit" value="' . $lang->get('pagetools_create_btn_create') . '" />';
   215 		echo '<input tabindex="5" type="submit" value="' . $lang->get('pagetools_create_btn_create') . '" />';
   216     echo '</p>';
   216 		echo '</p>';
   217     
   217 		
   218   echo '</form>';
   218 	echo '</form>';
   219   
   219 	
   220   echo '<script type="text/javascript">addOnloadHook(cpGenPreviewUrl); addOnloadHook(function(){load_component(\'expander\')});</script>';
   220 	echo '<script type="text/javascript">addOnloadHook(cpGenPreviewUrl); addOnloadHook(function(){load_component(\'expander\')});</script>';
   221   
   221 	
   222   $template->footer();
   222 	$template->footer();
   223 }
   223 }
   224 
   224 
   225 function PagelistingFormatter($id, $row)
   225 function PagelistingFormatter($id, $row)
   226 {
   226 {
   227   global $db, $session, $paths, $template, $plugins; // Common objects
   227 	global $db, $session, $paths, $template, $plugins; // Common objects
   228   static $rowtracker = 0;
   228 	static $rowtracker = 0;
   229   static $tdclass = 'row2';
   229 	static $tdclass = 'row2';
   230   static $per_row = 2;
   230 	static $per_row = 2;
   231   static $first = true;
   231 	static $first = true;
   232   $return = '';
   232 	$return = '';
   233   if ( $id === false && $row === false )
   233 	if ( $id === false && $row === false )
   234   {
   234 	{
   235     $rowtracker = 0;
   235 		$rowtracker = 0;
   236     $first = true;
   236 		$first = true;
   237     return false;
   237 		return false;
   238   }
   238 	}
   239   $rowtracker++;
   239 	$rowtracker++;
   240   if ( $rowtracker == $per_row || $first )
   240 	if ( $rowtracker == $per_row || $first )
   241   {
   241 	{
   242     $rowtracker = 0;
   242 		$rowtracker = 0;
   243     $tdclass = ( $tdclass == 'row2' ) ? 'row1' : 'row2';
   243 		$tdclass = ( $tdclass == 'row2' ) ? 'row1' : 'row2';
   244   }
   244 	}
   245   if ( $rowtracker == 0 && !$first )
   245 	if ( $rowtracker == 0 && !$first )
   246     $return .= "</tr>\n<tr>";
   246 		$return .= "</tr>\n<tr>";
   247   
   247 	
   248   $first = false;
   248 	$first = false;
   249   
   249 	
   250   preg_match('/^ns=(' . implode('|', array_keys($paths->nslist)) . ');pid=(.*?)$/i', $id, $match);
   250 	preg_match('/^ns=(' . implode('|', array_keys($paths->nslist)) . ');pid=(.*?)$/i', $id, $match);
   251   $namespace =& $match[1];
   251 	$namespace =& $match[1];
   252   $page_id   =& $match[2];
   252 	$page_id   =& $match[2];
   253   $page_id   = sanitize_page_id($page_id);
   253 	$page_id   = sanitize_page_id($page_id);
   254   
   254 	
   255   $url = makeUrlNS($namespace, $page_id);
   255 	$url = makeUrlNS($namespace, $page_id);
   256   $url = htmlspecialchars($url);
   256 	$url = htmlspecialchars($url);
   257   
   257 	
   258   $link = '<a href="' . $url . '">' . htmlspecialchars($row['name']) . '</a>';
   258 	$link = '<a href="' . $url . '">' . htmlspecialchars($row['name']) . '</a>';
   259   $td = '<td class="' . $tdclass . '" style="width: 50%;">' . $link . '</td>';
   259 	$td = '<td class="' . $tdclass . '" style="width: 50%;">' . $link . '</td>';
   260   
   260 	
   261   $return .= $td;
   261 	$return .= $td;
   262   
   262 	
   263   return $return;
   263 	return $return;
   264 }
   264 }
   265 
   265 
   266 function page_Special_AllPages() 
   266 function page_Special_AllPages() 
   267 {
   267 {
   268   // This should be an easy one
   268 	// This should be an easy one
   269   global $db, $session, $paths, $template, $plugins; // Common objects
   269 	global $db, $session, $paths, $template, $plugins; // Common objects
   270   global $lang;
   270 	global $lang;
   271   
   271 	
   272   $template->header();
   272 	$template->header();
   273   echo '<p>' . $lang->get('pagetools_allpages_blurb') . '</p>';
   273 	echo '<p>' . $lang->get('pagetools_allpages_blurb') . '</p>';
   274   
   274 	
   275   $q = $db->sql_query('SELECT COUNT(urlname) FROM '.table_prefix.'pages WHERE visible!=0;');
   275 	$q = $db->sql_query('SELECT COUNT(urlname) FROM '.table_prefix.'pages WHERE visible!=0;');
   276   if ( !$q )
   276 	if ( !$q )
   277     $db->_die();
   277 		$db->_die();
   278   $row = $db->fetchrow_num();
   278 	$row = $db->fetchrow_num();
   279   $count = $row[0];
   279 	$count = $row[0];
   280   $sz =& $count;
   280 	$sz =& $count;
   281   
   281 	
   282   switch($count % 4)
   282 	switch($count % 4)
   283   {
   283 	{
   284     case 0:
   284 		case 0:
   285     case 2:
   285 		case 2:
   286       // even number of results; do nothing
   286 			// even number of results; do nothing
   287       $last_cell = '';
   287 			$last_cell = '';
   288       break;
   288 			break;
   289     case 1:
   289 		case 1:
   290       // odd number of results and odd number of rows, use row1
   290 			// odd number of results and odd number of rows, use row1
   291       $last_cell = '<td class="row1"></td>';
   291 			$last_cell = '<td class="row1"></td>';
   292       break;
   292 			break;
   293     case 3:
   293 		case 3:
   294       // odd number of results and even number of rows, use row2
   294 			// odd number of results and even number of rows, use row2
   295       $last_cell = '<td class="row2"></td>';
   295 			$last_cell = '<td class="row2"></td>';
   296       break;
   296 			break;
   297   }
   297 	}
   298   
   298 	
   299   $db->free_result();
   299 	$db->free_result();
   300   
   300 	
   301   // This query needs to be generated based on the DBMS
   301 	// This query needs to be generated based on the DBMS
   302   $concat_column = ENANO_DBLAYER == 'MYSQL'
   302 	$concat_column = ENANO_DBLAYER == 'MYSQL'
   303                      ? 'CONCAT("ns=",namespace,";pid=",urlname)'
   303  										? 'CONCAT("ns=",namespace,";pid=",urlname)'
   304                      : "'ns=' || namespace || ';pid=' || urlname";
   304  										: "'ns=' || namespace || ';pid=' || urlname";
   305   
   305 	
   306   $q = $db->sql_unbuffered_query("SELECT $concat_column AS identifier, name FROM " . table_prefix . "pages WHERE visible != 0 ORDER BY name ASC;");
   306 	$q = $db->sql_unbuffered_query("SELECT $concat_column AS identifier, name FROM " . table_prefix . "pages WHERE visible != 0 ORDER BY name ASC;");
   307   if ( !$q )
   307 	if ( !$q )
   308     $db->_die();
   308 		$db->_die();
   309   
   309 	
   310   $offset = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0;
   310 	$offset = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0;
   311   
   311 	
   312   // reset formatter
   312 	// reset formatter
   313   PagelistingFormatter(false, false);
   313 	PagelistingFormatter(false, false);
   314   
   314 	
   315   $result = paginate(
   315 	$result = paginate(
   316       $q,                  // result resource
   316 			$q,                  // result resource
   317       '{identifier}',      // formatting template
   317 			'{identifier}',      // formatting template
   318       $count,              // # of results
   318 			$count,              // # of results
   319       makeUrlNS('Special', 'AllPages', 'offset=%s'), // result URL
   319 			makeUrlNS('Special', 'AllPages', 'offset=%s'), // result URL
   320       $offset,             // start offset
   320 			$offset,             // start offset
   321       40,                  // results per page
   321 			40,                  // results per page
   322       array( 'identifier' => 'PagelistingFormatter' ), // hooks
   322 			array( 'identifier' => 'PagelistingFormatter' ), // hooks
   323       '<div class="tblholder">
   323 			'<div class="tblholder">
   324          <table border="0" cellspacing="1" cellpadding="4">
   324  				<table border="0" cellspacing="1" cellpadding="4">
   325            <tr>',          // print at start
   325  					<tr>',          // print at start
   326       '    ' . $last_cell . '</tr>
   326 			'    ' . $last_cell . '</tr>
   327          </table>
   327  				</table>
   328        </div>'             // print at end
   328  			</div>'             // print at end
   329        );
   329  			);
   330   
   330 	
   331   echo $result;
   331 	echo $result;
   332   
   332 	
   333   $template->footer();
   333 	$template->footer();
   334 }
   334 }
   335 
   335 
   336 function page_Special_SpecialPages()
   336 function page_Special_SpecialPages()
   337 {
   337 {
   338   // This should be an easy one
   338 	// This should be an easy one
   339   global $db, $session, $paths, $template, $plugins; // Common objects
   339 	global $db, $session, $paths, $template, $plugins; // Common objects
   340   global $lang;
   340 	global $lang;
   341   
   341 	
   342   $template->header();
   342 	$template->header();
   343   echo '<p>' . $lang->get('pagetools_specialpages_blurb') . '</p><div class="tblholder"><table border="0" width="100%" cellspacing="1" cellpadding="4"><tr>';
   343 	echo '<p>' . $lang->get('pagetools_specialpages_blurb') . '</p><div class="tblholder"><table border="0" width="100%" cellspacing="1" cellpadding="4"><tr>';
   344   $cclass = 'row1';
   344 	$cclass = 'row1';
   345   $i = -1;
   345 	$i = -1;
   346   foreach ( $paths->pages as $cdata )
   346 	foreach ( $paths->pages as $cdata )
   347   {
   347 	{
   348     if ( $cdata['namespace'] != 'Special' )
   348 		if ( $cdata['namespace'] != 'Special' )
   349       continue;
   349 			continue;
   350     
   350 		
   351     $i++;
   351 		$i++;
   352     if ( $i % 2 == 0 && $i > 0 )
   352 		if ( $i % 2 == 0 && $i > 0 )
   353     {
   353 		{
   354       echo '</tr><tr>';
   354 			echo '</tr><tr>';
   355       $cclass = ( $cclass == 'row1' ) ? 'row3' : 'row1';
   355 			$cclass = ( $cclass == 'row1' ) ? 'row3' : 'row1';
   356     }
   356 		}
   357     echo '<td style="width: 50%;" class="' . $cclass . '">';
   357 		echo '<td style="width: 50%;" class="' . $cclass . '">';
   358     echo '<a href="' . makeUrl($cdata['urlname']) . '">';
   358 		echo '<a href="' . makeUrl($cdata['urlname']) . '">';
   359     echo htmlspecialchars($cdata['name']);
   359 		echo htmlspecialchars($cdata['name']);
   360     echo '</a>';
   360 		echo '</a>';
   361     echo '</td>';
   361 		echo '</td>';
   362   }
   362 	}
   363   // close up the table if necessary
   363 	// close up the table if necessary
   364   if ( $i % 2 > 0 )
   364 	if ( $i % 2 > 0 )
   365   {
   365 	{
   366     echo "<td class=\"$cclass\"></td>";
   366 		echo "<td class=\"$cclass\"></td>";
   367   }
   367 	}
   368   echo '</table></div>';
   368 	echo '</table></div>';
   369   $template->footer();
   369 	$template->footer();
   370 }
   370 }
   371 
   371 
   372 function page_Special_About_Enano()
   372 function page_Special_About_Enano()
   373 {
   373 {
   374   global $db, $session, $paths, $template, $plugins; // Common objects
   374 	global $db, $session, $paths, $template, $plugins; // Common objects
   375   global $lang;
   375 	global $lang;
   376   
   376 	
   377   $platform = 'Unknown';
   377 	$platform = 'Unknown';
   378   $uname = @file_get_contents('/proc/sys/kernel/ostype');
   378 	$uname = @file_get_contents('/proc/sys/kernel/ostype');
   379   if($uname == "Linux\n")
   379 	if($uname == "Linux\n")
   380     $platform = 'Linux';
   380 		$platform = 'Linux';
   381   else if(@file_exists('/hurd/pfinet')) // I have a little experience with GNU/Hurd :-) http://hurdvm.enanocms.org/
   381 	else if(@file_exists('/hurd/pfinet')) // I have a little experience with GNU/Hurd :-) http://hurdvm.enanocms.org/
   382     $platform = 'GNU/Hurd';
   382 		$platform = 'GNU/Hurd';
   383   else if(strtolower(PHP_OS) == 'winnt')
   383 	else if(strtolower(PHP_OS) == 'winnt')
   384     $platform = 'Windows NT';
   384 		$platform = 'Windows NT';
   385   else if(strtolower(PHP_OS) == 'win32')
   385 	else if(strtolower(PHP_OS) == 'win32')
   386     $platform = 'Windows 9x/DOS';
   386 		$platform = 'Windows 9x/DOS';
   387   else if(@file_exists('/System/Library/CoreServices/SystemVersion.plist'))
   387 	else if(@file_exists('/System/Library/CoreServices/SystemVersion.plist'))
   388     $platform = 'Mac OS X';
   388 		$platform = 'Mac OS X';
   389   else if(@file_exists('/bin/bash'))
   389 	else if(@file_exists('/bin/bash'))
   390     $platform = 'Other GNU';
   390 		$platform = 'Other GNU';
   391   else if(@is_dir('/bin'))
   391 	else if(@is_dir('/bin'))
   392     $platform = 'Other POSIX';
   392 		$platform = 'Other POSIX';
   393   $template->header();
   393 	$template->header();
   394   ?>
   394 	?>
   395   <br />
   395 	<br />
   396   <div class="tblholder">
   396 	<div class="tblholder">
   397     <table border="0" cellspacing="1" cellpadding="4">
   397 		<table border="0" cellspacing="1" cellpadding="4">
   398       <tr><th colspan="2" style="text-align: left;"><?php echo $lang->get('meta_enano_about_th'); ?></th></tr>
   398 			<tr><th colspan="2" style="text-align: left;"><?php echo $lang->get('meta_enano_about_th'); ?></th></tr>
   399       <tr><td colspan="2" class="row3">
   399 			<tr><td colspan="2" class="row3">
   400         <?php
   400 				<?php
   401         echo $lang->get('meta_enano_about_poweredby', array(
   401 				echo $lang->get('meta_enano_about_poweredby', array(
   402             'year'     => date('Y')
   402 						'year'     => date('Y')
   403           ));
   403 					));
   404         $subst = array(
   404 				$subst = array(
   405             'gpl_link' => makeUrlNS('Special', 'GNU_General_Public_License')
   405 						'gpl_link' => makeUrlNS('Special', 'GNU_General_Public_License')
   406           );
   406 					);
   407         echo $lang->get('meta_enano_about_gpl', $subst);
   407 				echo $lang->get('meta_enano_about_gpl', $subst);
   408         if ( $lang->lang_code != 'eng' ):
   408 				if ( $lang->lang_code != 'eng' ):
   409         // Do not remove this block of code. Doing so is a violation of the GPL. (A copy of the GPL in other languages
   409 				// Do not remove this block of code. Doing so is a violation of the GPL. (A copy of the GPL in other languages
   410         // must be accompanied by a copy of the English GPL.)
   410 				// must be accompanied by a copy of the English GPL.)
   411         ?>
   411 				?>
   412         <h3>(English)</h3>
   412 				<h3>(English)</h3>
   413         <p>
   413 				<p>
   414           This website is powered by <a href="http://enanocms.org/">Enano</a>, the lightweight and open source CMS that everyone can use.
   414 					This website is powered by <a href="http://enanocms.org/">Enano</a>, the lightweight and open source CMS that everyone can use.
   415           Enano is copyright &copy; 2006-<?php echo date('Y'); ?> Dan Fuhry. For legal information, along with a list of libraries that
   415 					Enano is copyright &copy; 2006-<?php echo date('Y'); ?> Dan Fuhry. For legal information, along with a list of libraries that
   416           Enano uses, please see <a href="http://enanocms.org/Legal_information">Legal Information</a>.
   416 					Enano uses, please see <a href="http://enanocms.org/Legal_information">Legal Information</a>.
   417         </p>
   417 				</p>
   418         <p>
   418 				<p>
   419           The developers and maintainers of Enano strongly believe that software should not only be free to use, but free to be modified,
   419 					The developers and maintainers of Enano strongly believe that software should not only be free to use, but free to be modified,
   420           distributed, and used to create derivative works. To help achieve this goal, we use licensing terms that require you to pass on
   420 					distributed, and used to create derivative works. To help achieve this goal, we use licensing terms that require you to pass on
   421           the freedoms we give you when you share Enano. For more information about Free Software, check out the
   421 					the freedoms we give you when you share Enano. For more information about Free Software, check out the
   422           <a href="http://en.wikipedia.org/wiki/Free_Software" onclick="window.open(this.href); return false;">Wikipedia page</a> or
   422 					<a href="http://en.wikipedia.org/wiki/Free_Software" onclick="window.open(this.href); return false;">Wikipedia page</a> or
   423           the <a href="http://www.fsf.org/" onclick="window.open(this.href); return false;">Free Software Foundation's</a> homepage.
   423 					the <a href="http://www.fsf.org/" onclick="window.open(this.href); return false;">Free Software Foundation's</a> homepage.
   424         </p>
   424 				</p>
   425         <p>
   425 				<p>
   426           This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU General Public License
   426 					This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU General Public License
   427           as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
   427 					as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
   428         </p>
   428 				</p>
   429         <p>
   429 				<p>
   430           This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
   430 					This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
   431           warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
   431 					warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
   432         </p>
   432 				</p>
   433         <p>
   433 				<p>
   434           You should have received <a href="<?php echo makeUrlNS('Special', 'GNU_General_Public_License'); ?>">a copy of
   434 					You should have received <a href="<?php echo makeUrlNS('Special', 'GNU_General_Public_License'); ?>">a copy of
   435           the GNU General Public License</a> along with this program; if not, write to:
   435 					the GNU General Public License</a> along with this program; if not, write to:
   436         </p>
   436 				</p>
   437         <p style="margin-left 2em;">
   437 				<p style="margin-left 2em;">
   438           Free Software Foundation, Inc.,<br />
   438 					Free Software Foundation, Inc.,<br />
   439           51 Franklin Street, Fifth Floor<br />
   439 					51 Franklin Street, Fifth Floor<br />
   440           Boston, MA 02110-1301, USA
   440 					Boston, MA 02110-1301, USA
   441         </p>
   441 				</p>
   442         <p>
   442 				<p>
   443           Alternatively, you can <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">read it online</a>.
   443 					Alternatively, you can <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">read it online</a>.
   444         </p>
   444 				</p>
   445         <?php
   445 				<?php
   446         endif;
   446 				endif;
   447         ?>
   447 				?>
   448       </td></tr>
   448 			</td></tr>
   449       <tr>
   449 			<tr>
   450         <td class="row2" colspan="2">
   450 				<td class="row2" colspan="2">
   451           <table border="0" style="margin: 0 auto; background: none; width: 100%;" cellpadding="5">
   451 					<table border="0" style="margin: 0 auto; background: none; width: 100%;" cellpadding="5">
   452             <tr>
   452 						<tr>
   453               <td style="text-align: center;">
   453 							<td style="text-align: center;">
   454                 <?php echo $template->fading_button; ?>
   454 								<?php echo $template->fading_button; ?>
   455               </td>
   455 							</td>
   456               <td style="text-align: center;">
   456 							<td style="text-align: center;">
   457                 <a href="http://www.php.net/" onclick="window.open(this.href); return false;" style="background: none; padding: 0;">
   457 								<a href="http://www.php.net/" onclick="window.open(this.href); return false;" style="background: none; padding: 0;">
   458                   <img alt="Written in PHP" src="<?php echo scriptPath; ?>/images/about-powered-php.png" style="border-width: 0px;" width="88" height="31" />
   458 									<img alt="Written in PHP" src="<?php echo scriptPath; ?>/images/about-powered-php.png" style="border-width: 0px;" width="88" height="31" />
   459                 </a>
   459 								</a>
   460               </td>
   460 							</td>
   461               <td style="text-align: center;">
   461 							<td style="text-align: center;">
   462                 <?php
   462 								<?php
   463                 switch(ENANO_DBLAYER)
   463 								switch(ENANO_DBLAYER)
   464                 {
   464 								{
   465                   case 'MYSQL':
   465 									case 'MYSQL':
   466                     ?>
   466 										?>
   467                     <a href="http://www.mysql.com/" onclick="window.open(this.href); return false;" style="background: none; padding: 0;">
   467 										<a href="http://www.mysql.com/" onclick="window.open(this.href); return false;" style="background: none; padding: 0;">
   468                       <img alt="Database engine powered by MySQL" src="<?php echo scriptPath; ?>/images/about-powered-mysql.png" style="border-width: 0px;" width="88" height="31" />
   468 											<img alt="Database engine powered by MySQL" src="<?php echo scriptPath; ?>/images/about-powered-mysql.png" style="border-width: 0px;" width="88" height="31" />
   469                     </a>
   469 										</a>
   470                     <?php
   470 										<?php
   471                     break;
   471 										break;
   472                   case 'PGSQL':
   472 									case 'PGSQL':
   473                     ?>
   473 										?>
   474                     <a href="http://www.postgresql.org/" onclick="window.open(this.href); return false;" style="background: none; padding: 0;">
   474 										<a href="http://www.postgresql.org/" onclick="window.open(this.href); return false;" style="background: none; padding: 0;">
   475                       <img alt="Database engine powered by PostgreSQL" src="<?php echo scriptPath; ?>/images/about-powered-pgsql.png" style="border-width: 0px;" width="90" height="30" />
   475 											<img alt="Database engine powered by PostgreSQL" src="<?php echo scriptPath; ?>/images/about-powered-pgsql.png" style="border-width: 0px;" width="90" height="30" />
   476                     </a>
   476 										</a>
   477                     <?php
   477 										<?php
   478                     break;
   478 										break;
   479                 }
   479 								}
   480                 ?>
   480 								?>
   481               </td>
   481 							</td>
   482             </tr>
   482 						</tr>
   483           </table>
   483 					</table>
   484         </td>
   484 				</td>
   485       </tr>
   485 			</tr>
   486       <tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_enanoversion'); ?></td><td class="row1"><?php echo enano_version(true) . ' (' . enano_codename() . ')'; ?></td></tr>
   486 			<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_enanoversion'); ?></td><td class="row1"><?php echo enano_version(true) . ' (' . enano_codename() . ')'; ?></td></tr>
   487       <tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_webserver'); ?></td><td class="row2"><?php if(isset($_SERVER['SERVER_SOFTWARE'])) echo $_SERVER['SERVER_SOFTWARE']; else echo 'Unable to determine web server software.'; ?></td></tr>
   487 			<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_webserver'); ?></td><td class="row2"><?php if(isset($_SERVER['SERVER_SOFTWARE'])) echo $_SERVER['SERVER_SOFTWARE']; else echo 'Unable to determine web server software.'; ?></td></tr>
   488       <tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_serverplatform'); ?></td><td class="row1"><?php echo $platform; ?></td></tr>
   488 			<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_serverplatform'); ?></td><td class="row1"><?php echo $platform; ?></td></tr>
   489       <tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_phpversion'); ?></td><td class="row2"><?php echo PHP_VERSION; ?></td></tr>
   489 			<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_phpversion'); ?></td><td class="row2"><?php echo PHP_VERSION; ?></td></tr>
   490       <?php
   490 			<?php
   491       switch(ENANO_DBLAYER)
   491 			switch(ENANO_DBLAYER)
   492       {
   492 			{
   493         case 'MYSQL':
   493 				case 'MYSQL':
   494           ?>
   494 					?>
   495           <tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_mysqlversion'); ?></td><td class="row1"><?php echo mysql_get_server_info($db->_conn); ?></td></tr>
   495 					<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_mysqlversion'); ?></td><td class="row1"><?php echo mysql_get_server_info($db->_conn); ?></td></tr>
   496           <?php
   496 					<?php
   497           break;
   497 					break;
   498         case 'PGSQL':
   498 				case 'PGSQL':
   499           $pg_serverdata = pg_version($db->_conn);
   499 					$pg_serverdata = pg_version($db->_conn);
   500           $pg_version = $pg_serverdata['server'];
   500 					$pg_version = $pg_serverdata['server'];
   501           ?>
   501 					?>
   502           <tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_pgsqlversion'); ?></td><td class="row1"><?php echo $pg_version; ?></td></tr>
   502 					<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_pgsqlversion'); ?></td><td class="row1"><?php echo $pg_version; ?></td></tr>
   503           <?php
   503 					<?php
   504           break;
   504 					break;
   505       }
   505 			}
   506       ?>
   506 			?>
   507     </table>
   507 		</table>
   508   </div>
   508 	</div>
   509   <?php
   509 	<?php
   510   $template->footer();
   510 	$template->footer();
   511 }
   511 }
   512 
   512 
   513 function page_Special_GNU_General_Public_License()
   513 function page_Special_GNU_General_Public_License()
   514 {
   514 {
   515   global $db, $session, $paths, $template, $plugins; // Common objects
   515 	global $db, $session, $paths, $template, $plugins; // Common objects
   516   global $lang;
   516 	global $lang;
   517   
   517 	
   518   $template->header();
   518 	$template->header();
   519   if(file_exists(ENANO_ROOT . '/GPL'))
   519 	if(file_exists(ENANO_ROOT . '/GPL'))
   520   {
   520 	{
   521     echo '<p>' . $lang->get('pagetools_gpl_blurb', array('about_url' => makeUrlNS('Special', 'About_Enano'))) . '</p>';
   521 		echo '<p>' . $lang->get('pagetools_gpl_blurb', array('about_url' => makeUrlNS('Special', 'About_Enano'))) . '</p>';
   522     
   522 		
   523     if ( $lang->lang_code != 'eng' ):
   523 		if ( $lang->lang_code != 'eng' ):
   524     // Do not remove this block of code. Doing so is a violation of the GPL. (A copy of the GPL in other languages
   524 		// Do not remove this block of code. Doing so is a violation of the GPL. (A copy of the GPL in other languages
   525     // must be accompanied by a copy of the English GPL.)
   525 		// must be accompanied by a copy of the English GPL.)
   526     echo '<p>The following text represents the license that the <a href="'.makeUrlNS('Special', 'About_Enano').'">Enano</a> content management system is under. To make it easier to read, the text has been wiki-formatted; in no other way has it been changed.</p>';
   526 		echo '<p>The following text represents the license that the <a href="'.makeUrlNS('Special', 'About_Enano').'">Enano</a> content management system is under. To make it easier to read, the text has been wiki-formatted; in no other way has it been changed.</p>';
   527     endif;
   527 		endif;
   528     
   528 		
   529     if ( file_exists(ENANO_ROOT . "/GPL_{$lang->lang_code}") )
   529 		if ( file_exists(ENANO_ROOT . "/GPL_{$lang->lang_code}") )
   530     {
   530 		{
   531       echo '<h2>' . $lang->get('pagetools_gpl_title_native') . '</h2>';
   531 			echo '<h2>' . $lang->get('pagetools_gpl_title_native') . '</h2>';
   532       echo '<p><a href="#gpl_english">' . $lang->get('pagetools_gpl_link_to_english') . ' / View the license in English' . '</a></p>';
   532 			echo '<p><a href="#gpl_english">' . $lang->get('pagetools_gpl_link_to_english') . ' / View the license in English' . '</a></p>';
   533       echo RenderMan::render( file_get_contents ( ENANO_ROOT . "/GPL_{$lang->lang_code}" ) );
   533 			echo RenderMan::render( file_get_contents ( ENANO_ROOT . "/GPL_{$lang->lang_code}" ) );
   534       echo '<h2>' . $lang->get('pagetools_gpl_title_english') . ' / English version<a name="gpl_english" id="gpl_english"></a></h2>';
   534 			echo '<h2>' . $lang->get('pagetools_gpl_title_english') . ' / English version<a name="gpl_english" id="gpl_english"></a></h2>';
   535     }
   535 		}
   536     
   536 		
   537     echo RenderMan::render( file_get_contents ( ENANO_ROOT . '/GPL' ) );
   537 		echo RenderMan::render( file_get_contents ( ENANO_ROOT . '/GPL' ) );
   538   }
   538 	}
   539   else
   539 	else
   540   {
   540 	{
   541     echo '<p>' . $lang->get('pagetools_gpl_err_file_missing') . '</p>';
   541 		echo '<p>' . $lang->get('pagetools_gpl_err_file_missing') . '</p>';
   542     if ( $lang->lang_code != 'eng')
   542 		if ( $lang->lang_code != 'eng')
   543       // Also print out English version
   543 			// Also print out English version
   544       // Do not remove the following line of code; doing so would be a violation of the GPL.
   544 			// Do not remove the following line of code; doing so would be a violation of the GPL.
   545       echo '<p>It appears that the file "GPL" is missing from your Enano installation. You may find a wiki-formatted copy of the GPL at: <a href="http://enanocms.org/GPL">http://enanocms.org/GPL</a>. In the mean time, you may wish to contact the site administration and ask them to replace the GPL file.</p>';
   545 			echo '<p>It appears that the file "GPL" is missing from your Enano installation. You may find a wiki-formatted copy of the GPL at: <a href="http://enanocms.org/GPL">http://enanocms.org/GPL</a>. In the mean time, you may wish to contact the site administration and ask them to replace the GPL file.</p>';
   546   }
   546 	}
   547   $template->footer();
   547 	$template->footer();
   548 }
   548 }
   549 
   549 
   550 function page_Special_TagCloud()
   550 function page_Special_TagCloud()
   551 {
   551 {
   552   global $db, $session, $paths, $template, $plugins; // Common objects
   552 	global $db, $session, $paths, $template, $plugins; // Common objects
   553   global $lang;
   553 	global $lang;
   554   
   554 	
   555   $template->header();
   555 	$template->header();
   556   
   556 	
   557   if ( $tag = $paths->getParam(0) )
   557 	if ( $tag = $paths->getParam(0) )
   558   {
   558 	{
   559     $tag = sanitize_tag($tag);
   559 		$tag = sanitize_tag($tag);
   560     $q = $db->sql_query('SELECT page_id, namespace FROM '.table_prefix.'tags WHERE tag_name=\'' . $db->escape($tag) . '\';');
   560 		$q = $db->sql_query('SELECT page_id, namespace FROM '.table_prefix.'tags WHERE tag_name=\'' . $db->escape($tag) . '\';');
   561     if ( !$q )
   561 		if ( !$q )
   562       $db->_die();
   562 			$db->_die();
   563     if ( $row = $db->fetchrow() )
   563 		if ( $row = $db->fetchrow() )
   564     {
   564 		{
   565       echo '<div class="tblholder">
   565 			echo '<div class="tblholder">
   566               <table border="0" cellspacing="1" cellpadding="4">';
   566 							<table border="0" cellspacing="1" cellpadding="4">';
   567       echo '<tr><th colspan="2">' . $lang->get('pagetools_tagcloud_pagelist_th', array('tag' => htmlspecialchars($tag))) . '</th></tr>';
   567 			echo '<tr><th colspan="2">' . $lang->get('pagetools_tagcloud_pagelist_th', array('tag' => htmlspecialchars($tag))) . '</th></tr>';
   568       echo '<tr>';
   568 			echo '<tr>';
   569       $i = 0;
   569 			$i = 0;
   570       $td_class = 'row1';
   570 			$td_class = 'row1';
   571       do
   571 			do
   572       {
   572 			{
   573         if ( $i % 2 == 0 && $i > 1 )
   573 				if ( $i % 2 == 0 && $i > 1 )
   574         {
   574 				{
   575           $td_class = ( $td_class == 'row2' ) ? 'row1' : 'row2';
   575 					$td_class = ( $td_class == 'row2' ) ? 'row1' : 'row2';
   576           echo '</tr><tr>';
   576 					echo '</tr><tr>';
   577         }
   577 				}
   578         $i++;
   578 				$i++;
   579         $title = get_page_title_ns($row['page_id'], $row['namespace']);
   579 				$title = get_page_title_ns($row['page_id'], $row['namespace']);
   580         if ( $row['namespace'] != 'Article' && isset($paths->nslist[$row['namespace']]) )
   580 				if ( $row['namespace'] != 'Article' && isset($paths->nslist[$row['namespace']]) )
   581           $title = $paths->nslist[$row['namespace']] . $title;
   581 					$title = $paths->nslist[$row['namespace']] . $title;
   582         $url = makeUrlNS($row['namespace'], $row['page_id']);
   582 				$url = makeUrlNS($row['namespace'], $row['page_id']);
   583         $class = ( isPage( $paths->nslist[$row['namespace']] . $row['page_id'] ) ) ? '' : ' class="wikilink-nonexistent"';
   583 				$class = ( isPage( $paths->nslist[$row['namespace']] . $row['page_id'] ) ) ? '' : ' class="wikilink-nonexistent"';
   584         $link = '<a href="' . htmlspecialchars($url) . '"' . $class . '>' . htmlspecialchars($title) . '</a>';
   584 				$link = '<a href="' . htmlspecialchars($url) . '"' . $class . '>' . htmlspecialchars($title) . '</a>';
   585         echo "<td class=\"$td_class\" style=\"width: 50%;\">$link</td>";
   585 				echo "<td class=\"$td_class\" style=\"width: 50%;\">$link</td>";
   586         // " workaround for jEdit highlighting bug
   586 				// " workaround for jEdit highlighting bug
   587       }
   587 			}
   588       while ( $row = $db->fetchrow() );
   588 			while ( $row = $db->fetchrow() );
   589       while ( $i % 2 > 0 )
   589 			while ( $i % 2 > 0 )
   590       {
   590 			{
   591         $i++;
   591 				$i++;
   592         echo "<td class=\"$td_class\" style=\"width: 50%;\"></td>";
   592 				echo "<td class=\"$td_class\" style=\"width: 50%;\"></td>";
   593       }
   593 			}
   594       // " workaround for jEdit highlighting bug
   594 			// " workaround for jEdit highlighting bug
   595       echo '<tr>
   595 			echo '<tr>
   596               <th colspan="2" class="subhead"><a href="' . makeUrlNS('Special', 'TagCloud') . '">&laquo; ' . $lang->get('pagetools_tagcloud_btn_return') . '</a></th>
   596 							<th colspan="2" class="subhead"><a href="' . makeUrlNS('Special', 'TagCloud') . '">&laquo; ' . $lang->get('pagetools_tagcloud_btn_return') . '</a></th>
   597             </tr>';
   597 						</tr>';
   598       echo '</table>';
   598 			echo '</table>';
   599       echo '</div>';
   599 			echo '</div>';
   600     }
   600 		}
   601   }
   601 	}
   602   else
   602 	else
   603   {
   603 	{
   604     $cloud = new TagCloud();
   604 		$cloud = new TagCloud();
   605     
   605 		
   606     $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;');
   606 		$q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;');
   607     if ( !$q )
   607 		if ( !$q )
   608       $db->_die();
   608 			$db->_die();
   609     if ( $db->numrows() < 1 )
   609 		if ( $db->numrows() < 1 )
   610     {
   610 		{
   611       echo '<p>' . $lang->get('pagetools_tagcloud_msg_no_tags') . '</p>';
   611 			echo '<p>' . $lang->get('pagetools_tagcloud_msg_no_tags') . '</p>';
   612     }
   612 		}
   613     else
   613 		else
   614     {
   614 		{
   615       echo '<h3>' . $lang->get('pagetools_tagcloud_blurb') . '</h3>';
   615 			echo '<h3>' . $lang->get('pagetools_tagcloud_blurb') . '</h3>';
   616       while ( $row = $db->fetchrow() )
   616 			while ( $row = $db->fetchrow() )
   617       {
   617 			{
   618         $cloud->add_word($row['tag_name']);
   618 				$cloud->add_word($row['tag_name']);
   619       }
   619 			}
   620       echo $cloud->make_html('normal');
   620 			echo $cloud->make_html('normal');
   621       echo '<p>' . $lang->get('pagetools_tagcloud_instructions') . '</p>';
   621 			echo '<p>' . $lang->get('pagetools_tagcloud_instructions') . '</p>';
   622     }
   622 		}
   623   }
   623 	}
   624   
   624 	
   625   $template->footer();
   625 	$template->footer();
   626 }
   626 }
   627 
   627 
   628 function page_Special_Autofill()
   628 function page_Special_Autofill()
   629 {
   629 {
   630   global $db, $session, $paths, $template, $plugins; // Common objects
   630 	global $db, $session, $paths, $template, $plugins; // Common objects
   631   global $lang;
   631 	global $lang;
   632   
   632 	
   633   require_once(ENANO_ROOT . '/includes/search.php');
   633 	require_once(ENANO_ROOT . '/includes/search.php');
   634   
   634 	
   635   header('Content-type: text/javascript');
   635 	header('Content-type: text/javascript');
   636   
   636 	
   637   $dataset = array();
   637 	$dataset = array();
   638   if ( isset($_GET['type']) )
   638 	if ( isset($_GET['type']) )
   639   {
   639 	{
   640     switch($_GET['type'])
   640 		switch($_GET['type'])
   641     {
   641 		{
   642       case 'username':
   642 			case 'username':
   643         if ( isset($_GET['userinput']) && strlen($_GET['userinput']) >= 3 )
   643 				if ( isset($_GET['userinput']) && strlen($_GET['userinput']) >= 3 )
   644         {
   644 				{
   645           $search = '%' . escape_string_like($_GET['userinput']) . '%';
   645 					$search = '%' . escape_string_like($_GET['userinput']) . '%';
   646           $min_id = ( isset($_GET['allow_anon']) && $_GET['allow_anon'] == '1' ) ? '1' : '2';
   646 					$min_id = ( isset($_GET['allow_anon']) && $_GET['allow_anon'] == '1' ) ? '1' : '2';
   647           $q = $db->sql_query('SELECT username FROM ' . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) LIKE '$search' AND user_id >= $min_id");
   647 					$q = $db->sql_query('SELECT username FROM ' . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) LIKE '$search' AND user_id >= $min_id");
   648           if ( !$q )
   648 					if ( !$q )
   649             $db->die_json();
   649 						$db->die_json();
   650           
   650 					
   651           while ( $row = $db->fetchrow($q) )
   651 					while ( $row = $db->fetchrow($q) )
   652           {
   652 					{
   653             $key = array(
   653 						$key = array(
   654               'name' => $row['username'],
   654 							'name' => $row['username'],
   655               'name_highlight' => highlight_term($_GET['userinput'], $row['username'], '<b>', '</b>')
   655 							'name_highlight' => highlight_term($_GET['userinput'], $row['username'], '<b>', '</b>')
   656             );
   656 						);
   657             $key = array_merge($key, $session->get_user_rank($row['username']));
   657 						$key = array_merge($key, $session->get_user_rank($row['username']));
   658             $key['rank_title'] = $lang->get($key['rank_title']);
   658 						$key['rank_title'] = $lang->get($key['rank_title']);
   659             $key[0] = $row['username'];
   659 						$key[0] = $row['username'];
   660             $dataset[] = $key;
   660 						$dataset[] = $key;
   661             // $dataset[] = array($row['username'], $row['username']);
   661 						// $dataset[] = array($row['username'], $row['username']);
   662             // echo "{$row['username']}|{$row['username']}\n";
   662 						// echo "{$row['username']}|{$row['username']}\n";
   663           }
   663 					}
   664         }
   664 				}
   665         // return;
   665 				// return;
   666         break;
   666 				break;
   667       case 'page':
   667 			case 'page':
   668         if ( isset($_GET['userinput']) && strlen($_GET['userinput']) >= 3 )
   668 				if ( isset($_GET['userinput']) && strlen($_GET['userinput']) >= 3 )
   669         {
   669 				{
   670           $search = '%' . escape_string_like($_GET['userinput']) . '%';
   670 					$search = '%' . escape_string_like($_GET['userinput']) . '%';
   671           $q = $db->sql_query('SELECT urlname, namespace, name FROM ' . table_prefix . "pages\n"
   671 					$q = $db->sql_query('SELECT urlname, namespace, name FROM ' . table_prefix . "pages\n"
   672                             . "  WHERE (\n"
   672 														. "  WHERE (\n"
   673                             . "       " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '$search'\n"
   673 														. "       " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '$search'\n"
   674                             . "    OR " . ENANO_SQLFUNC_LOWERCASE . "(name)    LIKE '$search'\n"
   674 														. "    OR " . ENANO_SQLFUNC_LOWERCASE . "(name)    LIKE '$search'\n"
   675                             . "  );");
   675 														. "  );");
   676           if ( !$q )
   676 					if ( !$q )
   677             $db->die_json();
   677 						$db->die_json();
   678           
   678 					
   679           while ( $row = $db->fetchrow() )
   679 					while ( $row = $db->fetchrow() )
   680           {
   680 					{
   681             $pathskey = ( isset($paths->nslist[$row['namespace']]) ? $paths->nslist[$row['namespace']] : $row['namespace'] . substr($paths->nslist['Special'], -1) ) . $row['urlname'];
   681 						$pathskey = ( isset($paths->nslist[$row['namespace']]) ? $paths->nslist[$row['namespace']] : $row['namespace'] . substr($paths->nslist['Special'], -1) ) . $row['urlname'];
   682             
   682 						
   683             $key = array(
   683 						$key = array(
   684               0 => $pathskey,
   684 							0 => $pathskey,
   685               'pid_highlight'  => highlight_term($_GET['userinput'], dirtify_page_id($pathskey), '<b>', '</b>'),
   685 							'pid_highlight'  => highlight_term($_GET['userinput'], dirtify_page_id($pathskey), '<b>', '</b>'),
   686               'name_highlight' => highlight_term($_GET['userinput'], $row['name'], '<b>', '</b>')
   686 							'name_highlight' => highlight_term($_GET['userinput'], $row['name'], '<b>', '</b>')
   687             );
   687 						);
   688             $dataset[] = $key;
   688 						$dataset[] = $key;
   689           }
   689 					}
   690         }
   690 				}
   691         break;
   691 				break;
   692       default:
   692 			default:
   693         $code = $plugins->setHook('autofill_json_request');
   693 				$code = $plugins->setHook('autofill_json_request');
   694         foreach ( $code as $cmd )
   694 				foreach ( $code as $cmd )
   695         {
   695 				{
   696           eval($cmd);
   696 					eval($cmd);
   697         }
   697 				}
   698         break;
   698 				break;
   699     }
   699 		}
   700   }
   700 	}
   701   
   701 	
   702   echo enano_json_encode($dataset);
   702 	echo enano_json_encode($dataset);
   703 }
   703 }
   704 
   704 
   705 ?>
   705 ?>