prettyurls multiple 'backend'

This commit is contained in:
real_nowhereman 2011-04-04 10:33:56 +00:00
parent fbbe7acc4e
commit 35bcf84f57
3 changed files with 105 additions and 23 deletions

View File

@ -7,14 +7,30 @@
$lang['admin']['plugin']['submenu']['prettyurls'] = 'PrettyURLs Config';
$lang['admin']['plugin']['prettyurls'] = array(
'head' => 'PrettyURLs Configuration',
'htaccess' => '.htaccess',
'description'=>'This raw editor let you edit your '.
'<code><a class="hint" href="http://wiki.flatpress.org/doc:plugins:prettyurls#htaccess">.htaccess</a></code>.',
'cantsave' => 'You can\'t edit this file, because it\'s not <strong>writable</strong>. You can give writing permission or copy and paste to a file and then upload as <a class="hint" href="http://wiki.flatpress.org/doc:plugins:prettyurls#manual_upload">described here</a>',
'submit' => 'Save'
'mode' => 'Mode',
'auto' => 'Automatic',
'autodescr' => 'try to guess the best choice for me',
'pathinfo' => 'Path Info',
'pathinfodescr' => 'e.g. /index.php/2011/01/01/hello-world/',
'httpget' => 'HTTP Get',
'httpgetdescr'=> 'e.g. /?u=/2011/01/01/hello-world/',
'pretty' => 'Pretty',
'prettydescr'=> 'e.g. /2011/01/01/hello-world/',
'saveopt' => 'Save settings',
'submit' => 'Save .htaccess'
);
$lang['admin']['plugin']['prettyurls']['msgs'] = array(
1 => '.htaccess saved successfully',
-1 => '.htaccess could not be saved (do you have writing permissions on <code>'. BLOG_ROOT .'</code>)?'
-1 => '.htaccess could not be saved (do you have writing permissions on <code>'. BLOG_ROOT .'</code>)?',
2 => 'Options saved successfully',
-2 => 'An error occurred attempting to save settings',
);
?>

View File

@ -231,6 +231,34 @@ class Plugin_PrettyURLs {
}
function get_url() {
$baseurl = BLOG_BASEURL;
$opt = plugin_getoptions('prettyurls', 'mode');
$url = substr($_SERVER['REQUEST_URI'], strlen(BLOG_ROOT)-1);
switch($opt) {
case null:
case 0:
$opt = file_exists(ABS_PATH . '.htaccess') ? 3 : 1;
case 1:
$baseurl .= 'index.php/';
$url = $_SERVER['PATH_INFO'];
break;
case 2:
$baseurl .= '?u=/';
$url = @$_GET['u'];
/* case 3: do nothing, it's BLOG_BASEURL */
}
$this->baseurl = $baseurl;
$this->mode = $opt;
return $url;
}
/*
* here is where the real work is done.
*
@ -251,7 +279,7 @@ class Plugin_PrettyURLs {
global $fp_params;
$this->fp_params =& $fp_params;
$this->baseurl = PRETTYURLS_PATHINFO? BLOG_BASEURL . 'index.php/' : BLOG_BASEURL;
$url = $this->get_url();
if (PRETTYURLS_TITLES) {
#if ($f = io_load_file(PRETTYURLS_CACHE))
@ -264,20 +292,20 @@ class Plugin_PrettyURLs {
$this->categories(false);
}
if (!defined('MOD_INDEX'))
return;
# this is not working if you reach flatpress via symlink
# unless you don't edit manually defaults.php
if (strpos($_SERVER['REQUEST_URI'], BLOG_ROOT)!==false) {
$url = $_SERVER['REQUEST_URI'];
$del = BLOG_ROOT;
if (strpos($url, 'index.php')!==false)
$del = $del . 'index.php/';
$url = substr($url, strlen($del)-1);
}
// # this is not working if you reach flatpress via symlink
// # unless you don't edit manually defaults.php
// if (strpos($_SERVER['REQUEST_URI'], BLOG_ROOT)!==false) {
// $url = $_SERVER['REQUEST_URI'];
// $del = BLOG_ROOT;
// if (strpos($url, 'index.php')!==false)
// $del = $del . 'index.php/';
// $url = substr($url, strlen($del)-1);
// }
// removes querystrings
if (false !== $i = strpos($url, '?'))
@ -549,9 +577,12 @@ if (class_exists('AdminPanelAction')){
class admin_plugin_prettyurls extends AdminPanelAction {
var $langres = 'plugin:prettyurls';
var $_config = array('mode'=>0);
function setup() {
$this->smarty->assign('admin_resource', "plugin:prettyurls/admin.plugin.prettyurls");
$this->_config['mode'] = plugin_getoptions('prettyurls', 'mode');
$this->smarty->assign('pconfig', $this->_config);
$blogroot = BLOG_ROOT;
$f = ABS_PATH . '.htaccess';
$txt = io_load_file($f);
@ -583,11 +614,21 @@ STR;
function onsubmit() {
global $fp_config;
if (isset($_POST['saveopt'])) {
$this->_config['mode'] = (int) $_POST['mode'] ;
plugin_addoption('prettyurls', 'mode', $this->_config['mode']);
if( plugin_saveoptions() )
$this->smarty->assign('success', 2);
else $this->smarty->assign('success', -2);
}
if (isset($_POST['htaccess-submit'])) {
if (!empty($_POST['htaccess']) && io_write_file(ABS_PATH.'.htaccess', $_POST['htaccess'])){
$this->smarty->assign('success', 1);
} else {
$this->smarty->assign('success', -1);
}
}
return 2;
}

View File

@ -1,11 +1,36 @@
<h2>{$plang.head}</h2>
<p>{$plang.description}</p>
{include file=shared:errorlist.tpl}
{html_form}
<h3>{$plang.mode} </h3>{debug}
<dl>
<dt><label><input type="radio" name="mode" value="0" {if $pconfig.mode == 0 }checked=checked{/if}>
{$plang.auto} </label> </dt>
<dd>{$plang.autodescr}</dd>
<dt><label><input type="radio" name="mode" value="1" {if $pconfig.mode==1}checked=checked{/if}>
{$plang.pathinfo} </label> </dt>
<dd>{$plang.pathinfodescr}</dd>
<dt><label><input type="radio" name="mode" value="2" {if $pconfig.mode==2}checked=checked{/if}>
{$plang.httpget} </label> </dt>
<dd>{$plang.httpgetdescr}</dd>
<dt><label><input type="radio" name="mode" value="3" {if $pconfig.mode==3}checked=checked{/if}>
{$plang.pretty} </label> </dt>
<dd>{$plang.prettydescr}</dd>
</dl>
<div class="buttonbar">
<input type="submit" name="saveopt" value="{$plang.saveopt}" />
</div>
<h3>{$plang.htaccess}</h3>
<p>{$plang.description}</p>
<p>
<textarea id="htaccess" name="htaccess"
{if $cantsave}readonly="readonly" {/if}cols="70" rows="16">{$htaccess|escape:'html'}</textarea>
@ -15,7 +40,7 @@
{if $cantsave}
<p><em>{$plang.cantsave}</em></p>
{else}
<input type="submit" value="{$plang.submit}"/>
<input type="submit" name="htaccess-submit" value="{$plang.submit}"/>
{/if}
</div>