plugins/admin/PageEditor.php
changeset 1227 bdac73ed481e
parent 1081 745200a9cc2a
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
    13 
    13 
    14 // Page editing portal
    14 // Page editing portal
    15 
    15 
    16 function page_Admin_PageEditor()
    16 function page_Admin_PageEditor()
    17 {
    17 {
    18   global $db, $session, $paths, $template, $plugins; // Common objects
    18 	global $db, $session, $paths, $template, $plugins; // Common objects
    19   global $lang;
    19 	global $lang;
    20   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
    20 	if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
    21   {
    21 	{
    22     $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
    22 		$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
    23     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
    23 		echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
    24     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
    24 		echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
    25     return;
    25 		return;
    26   }
    26 	}
    27   
    27 	
    28   echo '<h3>' . $lang->get('acped_heading_main') . '</h3>';
    28 	echo '<h3>' . $lang->get('acped_heading_main') . '</h3>';
    29   $show_select = true;
    29 	$show_select = true;
    30   
    30 	
    31   if ( isset($_REQUEST['action']) || isset($_REQUEST['source']) )
    31 	if ( isset($_REQUEST['action']) || isset($_REQUEST['source']) )
    32   {
    32 	{
    33     if ( isset($_REQUEST['action']) )
    33 		if ( isset($_REQUEST['action']) )
    34     {
    34 		{
    35       $act =& $_REQUEST['action'];
    35 			$act =& $_REQUEST['action'];
    36       $act = strtolower($act);
    36 			$act = strtolower($act);
    37     }
    37 		}
    38     else if ( isset($_REQUEST['source']) && $_REQUEST['source'] == 'ajax' )
    38 		else if ( isset($_REQUEST['source']) && $_REQUEST['source'] == 'ajax' )
    39     {
    39 		{
    40       $act = 'select';
    40 			$act = 'select';
    41     }
    41 		}
    42     switch ( $act )
    42 		switch ( $act )
    43     {
    43 		{
    44       case 'save':
    44 			case 'save':
    45       case 'select':
    45 			case 'select':
    46         // First step is to determine the page ID and namespace
    46 				// First step is to determine the page ID and namespace
    47         
    47 				
    48         if ( isset($_REQUEST['pid_search']) )
    48 				if ( isset($_REQUEST['pid_search']) )
    49         {
    49 				{
    50           list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']);
    50 					list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']);
    51           $name = $db->escape(dirtify_page_id($page_id));
    51 					$name = $db->escape(dirtify_page_id($page_id));
    52           $page_id = $db->escape(sanitize_page_id($page_id));
    52 					$page_id = $db->escape(sanitize_page_id($page_id));
    53           $namespace = $db->escape($namespace);
    53 					$namespace = $db->escape($namespace);
    54           $name = strtolower($name);
    54 					$name = strtolower($name);
    55           $page_id = strtolower($page_id);
    55 					$page_id = strtolower($page_id);
    56           $sql = "SELECT * FROM " . table_prefix . "pages WHERE ( " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '%$page_id%' OR " . ENANO_SQLFUNC_LOWERCASE . "(name) LIKE '%$name%' ) ORDER BY name ASC;";
    56 					$sql = "SELECT * FROM " . table_prefix . "pages WHERE ( " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '%$page_id%' OR " . ENANO_SQLFUNC_LOWERCASE . "(name) LIKE '%$name%' ) ORDER BY name ASC;";
    57         }
    57 				}
    58         else
    58 				else
    59         {
    59 				{
    60           // pid_search was not set, assume absolute page ID
    60 					// pid_search was not set, assume absolute page ID
    61           list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']);
    61 					list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']);
    62           $page_id = $db->escape(sanitize_page_id($page_id));
    62 					$page_id = $db->escape(sanitize_page_id($page_id));
    63           $namespace = $db->escape($namespace);
    63 					$namespace = $db->escape($namespace);
    64           
    64 					
    65           $sql = "SELECT * FROM " . table_prefix . "pages WHERE urlname = '$page_id' AND namespace = '$namespace';";
    65 					$sql = "SELECT * FROM " . table_prefix . "pages WHERE urlname = '$page_id' AND namespace = '$namespace';";
    66         }
    66 				}
    67         
    67 				
    68         if ( !($q = $db->sql_query($sql)) )
    68 				if ( !($q = $db->sql_query($sql)) )
    69         {
    69 				{
    70           $db->_die('PageManager selecting dataset for page');
    70 					$db->_die('PageManager selecting dataset for page');
    71         }
    71 				}
    72         
    72 				
    73         if ( $db->numrows() < 1 )
    73 				if ( $db->numrows() < 1 )
    74         {
    74 				{
    75           echo '<div class="error-box">
    75 					echo '<div class="error-box">
    76                   ' . $lang->get('acped_err_page_not_found') . '
    76 									' . $lang->get('acped_err_page_not_found') . '
    77                 </div>';
    77 								</div>';
    78           break;
    78 					break;
    79         }
    79 				}
    80         
    80 				
    81         if ( $db->numrows() > 1 )
    81 				if ( $db->numrows() > 1 )
    82         {
    82 				{
    83           // Ambiguous results
    83 					// Ambiguous results
    84           if ( isset($_REQUEST['pid_search']) )
    84 					if ( isset($_REQUEST['pid_search']) )
    85           {
    85 					{
    86             echo '<h3>' . $lang->get('acped_msg_results_ambiguous_title') . '</h3>';
    86 						echo '<h3>' . $lang->get('acped_msg_results_ambiguous_title') . '</h3>';
    87             echo '<p>' . $lang->get('acped_msg_results_ambiguous_body') . '</p>';
    87 						echo '<p>' . $lang->get('acped_msg_results_ambiguous_body') . '</p>';
    88             echo '<ul>';
    88 						echo '<ul>';
    89             while ( $row = $db->fetchrow($q) )
    89 						while ( $row = $db->fetchrow($q) )
    90             {
    90 						{
    91               echo '<li>';
    91 							echo '<li>';
    92               $pathskey = $paths->nslist[$row['namespace']] . $row['urlname'];
    92 							$pathskey = $paths->nslist[$row['namespace']] . $row['urlname'];
    93               $edit_url = makeUrlNS($row['namespace'], $row['urlname']) . '#do:edit';
    93 							$edit_url = makeUrlNS($row['namespace'], $row['urlname']) . '#do:edit';
    94               $view_url = makeUrlNS($row['namespace'], $row['urlname']);
    94 							$view_url = makeUrlNS($row['namespace'], $row['urlname']);
    95               $page_name = htmlspecialchars(get_page_title_ns( $row['urlname'], $row['namespace'] ));
    95 							$page_name = htmlspecialchars(get_page_title_ns( $row['urlname'], $row['namespace'] ));
    96               $view_link = $lang->get('acped_ambig_btn_viewpage');
    96 							$view_link = $lang->get('acped_ambig_btn_viewpage');
    97               echo "<a href=\"$edit_url\">$page_name</a> (<a onclick=\"window.open(this.href); return false;\" href=\"$view_url\">$view_link</a>)";
    97 							echo "<a href=\"$edit_url\">$page_name</a> (<a onclick=\"window.open(this.href); return false;\" href=\"$view_url\">$view_link</a>)";
    98               echo '</li>';
    98 							echo '</li>';
    99             }
    99 						}
   100             echo '</ul>';
   100 						echo '</ul>';
   101             $show_select = false;
   101 						$show_select = false;
   102             break;
   102 						break;
   103           }
   103 					}
   104           else
   104 					else
   105           {
   105 					{
   106             echo '<p>' . $lang->get('acped_err_ambig_absolute') . '</p>';
   106 						echo '<p>' . $lang->get('acped_err_ambig_absolute') . '</p>';
   107             break;
   107 						break;
   108           }
   108 					}
   109         }
   109 				}
   110         
   110 				
   111         // From this point on we can assume that exactly one matching page was found.
   111 				// From this point on we can assume that exactly one matching page was found.
   112         $dataset = $db->fetchrow();
   112 				$dataset = $db->fetchrow();
   113         $page_id = $dataset['urlname'];
   113 				$page_id = $dataset['urlname'];
   114         $namespace = $dataset['namespace'];
   114 				$namespace = $dataset['namespace'];
   115         $url = makeUrlNS($namespace, $page_id, false, true) . '#do:edit';
   115 				$url = makeUrlNS($namespace, $page_id, false, true) . '#do:edit';
   116         $url = addslashes($url);
   116 				$url = addslashes($url);
   117         echo '<script type="text/javascript">
   117 				echo '<script type="text/javascript">
   118                 window.location = \'' . $url . '\';
   118 								window.location = \'' . $url . '\';
   119               </script>';
   119 							</script>';
   120         
   120 				
   121         $show_select = false;
   121 				$show_select = false;
   122         break;
   122 				break;
   123     }
   123 		}
   124   }
   124 	}
   125   
   125 	
   126   if ( $show_select )
   126 	if ( $show_select )
   127   {
   127 	{
   128     echo '<p>' . $lang->get('acped_hint') . '</p>';
   128 		echo '<p>' . $lang->get('acped_hint') . '</p>';
   129     
   129 		
   130     // Show the search form
   130 		// Show the search form
   131     
   131 		
   132     $form_action = makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor", true);
   132 		$form_action = makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor", true);
   133     echo "<form action=\"$form_action\" method=\"post\">";
   133 		echo "<form action=\"$form_action\" method=\"post\">";
   134     echo $lang->get('acped_lbl_field_search') . ' ';
   134 		echo $lang->get('acped_lbl_field_search') . ' ';
   135     echo $template->pagename_field('page_id') . ' ';
   135 		echo $template->pagename_field('page_id') . ' ';
   136     echo '<input type="hidden" name="action" value="select" />';
   136 		echo '<input type="hidden" name="action" value="select" />';
   137     echo '<input type="submit" name="pid_search" value="' . $lang->get('search_btn_search') . '" />';
   137 		echo '<input type="submit" name="pid_search" value="' . $lang->get('search_btn_search') . '" />';
   138     echo "</form>";
   138 		echo "</form>";
   139     
   139 		
   140     // Grab all pages from the database and show a list of pages on the site
   140 		// Grab all pages from the database and show a list of pages on the site
   141     
   141 		
   142     echo '<h3>' . $lang->get('acped_heading_select_page_from_list') . '</h3>';
   142 		echo '<h3>' . $lang->get('acped_heading_select_page_from_list') . '</h3>';
   143     echo '<p>' . $lang->get('acped_hint_select_page_from_list') . '</p>';
   143 		echo '<p>' . $lang->get('acped_hint_select_page_from_list') . '</p>';
   144     
   144 		
   145     $q = $db->sql_query('SELECT COUNT(name) AS num_pages FROM ' . table_prefix . 'pages;');
   145 		$q = $db->sql_query('SELECT COUNT(name) AS num_pages FROM ' . table_prefix . 'pages;');
   146     if ( !$q )
   146 		if ( !$q )
   147       $db->_die('PageManager doing initial page count');
   147 			$db->_die('PageManager doing initial page count');
   148     list($num_pages) = $db->fetchrow_num();
   148 		list($num_pages) = $db->fetchrow_num();
   149     $db->free_result();
   149 		$db->free_result();
   150     
   150 		
   151     $pg_start = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0;
   151 		$pg_start = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0;
   152     
   152 		
   153     $q = $db->sql_query('SELECT urlname, name, namespace, ' . $num_pages . ' AS num_pages, ' . $pg_start . ' AS offset, \'edit\' AS mode FROM ' . table_prefix . 'pages ORDER BY name ASC;');
   153 		$q = $db->sql_query('SELECT urlname, name, namespace, ' . $num_pages . ' AS num_pages, ' . $pg_start . ' AS offset, \'edit\' AS mode FROM ' . table_prefix . 'pages ORDER BY name ASC;');
   154     if ( !$q )
   154 		if ( !$q )
   155       $db->_die('PageManager doing main select query for page list');
   155 			$db->_die('PageManager doing main select query for page list');
   156     
   156 		
   157     // Paginate results
   157 		// Paginate results
   158     $html = paginate(
   158 		$html = paginate(
   159         $q,
   159 				$q,
   160         '{urlname}',
   160 				'{urlname}',
   161         $num_pages,
   161 				$num_pages,
   162         makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor&offset=%s", false),
   162 				makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor&offset=%s", false),
   163         $pg_start,
   163 				$pg_start,
   164         99,
   164 				99,
   165         array('urlname' => 'admin_pagemanager_format_listing'),
   165 				array('urlname' => 'admin_pagemanager_format_listing'),
   166         '<div class="tblholder" style="height: 300px; clip: rect(0px, auto, auto, 0px); overflow: auto;">
   166 				'<div class="tblholder" style="height: 300px; clip: rect(0px, auto, auto, 0px); overflow: auto;">
   167         <table border="0" cellspacing="1" cellpadding="4">',
   167 				<table border="0" cellspacing="1" cellpadding="4">',
   168         '  </table>
   168 				'  </table>
   169          </div>'
   169  				</div>'
   170       );
   170 			);
   171     echo $html;
   171 		echo $html;
   172   }
   172 	}
   173   
   173 	
   174 }
   174 }
   175 
   175 
   176 ?>
   176 ?>