1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-16 11:36:08 +02:00

- Custom Pages front-end almost completely rewritten, backend fixes, SEF URL support, introducing page batch shortcodes and templates (available per page), compatibility stylesheet added (core css and jayya theme), tagwords plugin links proper to new pages URLs;

- Large number of system stability fixes and obsolete code replacement
This commit is contained in:
secretr
2011-12-07 21:07:21 +00:00
parent 3b63b407bb
commit 97b577db43
25 changed files with 965 additions and 298 deletions

View File

@@ -0,0 +1,163 @@
<?php
/*
* Copyright e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* Custom Pages shortcode batch
*/
if (!defined('e107_INIT')) { exit; }
/**
* @package e107
* @subpackage shortcodes
* @version $Id$
*
* Shortcodes for custom page display
*/
class page_shortcodes extends e_shortcode
{
function sc_cpagetitle()
{
return e107::getParser()->toHTML($this->getParserVars()->title, true, 'TITLE');
}
function sc_cpagesubtitle()
{
$subtitle = $this->getParserVars()->sub_title;
return $subtitle ? e107::getParser()->toHTML($subtitle, true, 'TITLE') : '';
}
function sc_cpagebody()
{
// already parsed
return $this->getParserVars()->text;
}
function sc_cpageauthor($parm)
{
$parms = eHelper::scParams($parm);
$author = '';
$url = e107::getUrl()->create('user/profile/view', array('name' => $this->page['user_name'], 'id' => $this->page['user_id']));
if(isset($parms['url']))
{
return $url;
}
if($this->page['page_author'])
{
// currently this field used as Real Name, no matter what the db name says
if($this->page['user_login'] && !isset($parms['user'])) $author = $this->page['user_login'];
elseif($this->page['user_name']) $author = preg_replace('/[^\w\pL\s]+/u', ' ', $this->page['user_name']);
}
if(empty($author)) return '';
if(isset($parms['nolink']))
{
return $author;
}
//TODO title lan
return '<a class="cpage-author" href="'.$url.'" title="">'.$author.'</a>';
}
function sc_cpagedate($parm)
{
if(empty($parm))
{
return e107::getDateConvert()->convert_date($this->page['page_datestamp'], 'long');
}
return e107::getDateConvert()->convert_date($this->page['page_datestamp'], $parm);
}
function sc_cpageid()
{
return $this->page['page_id'];
}
// Not a shortcode really, as it shouldn't be cached at all :/
function cpagecomments()
{
$com = $this->getParserVars()->comments;
//if($parm && isset($com[$parm])) return $com[$parm];
return $com['comment'].$com['comment_form'];
}
function sc_cpagenav()
{
return $this->getParserVars()->np;
}
function sc_cpagerating()
{
return $this->getParserVars()->rating;
}
function sc_cpagemessage()
{
return e107::getMessage()->render();
}
/**
* Auto-thumbnailing now allowed.
* New sc parameter standards
* Exampes:
* - {CPAGETHUMBNAIL=e_MEDIA/images/someimage.jpg|type=tag&w=200} render link with thumbnail max width 200px
* - {CPAGETHUMBNAIL=images/someimage.jpg|w=200} same as above
* - {CPAGETHUMBNAIL=images/someimage.jpg|type=src&aw=200&ah=200} return thumb link only, size forced to 200px X 200px (smart thumbnailing close to how Facebook is doing it)
*
* @see eHelper::scDualParams()
* @see eHelper::scParams()
*/
function sc_cpagehumbnail($parm = '')
{
$parms = eHelper::scDualParams($parm);
if(empty($parms[1])) return '';
$tp = e107::getParser();
$path = rawurldecode($parms[1]);
if(substr($path, 0, 2) === 'e_') $path = str_replace($tp->getUrlConstants('raw'), $tp->getUrlConstants('sc'), $path);
elseif($path[0] !== '{') $path = '{e_MEDIA}'.$path;
$thumb = $tp->thumbUrl($path);
$type = varset($parms[2]['type'], 'tag');
switch($type)
{
case 'src':
return $thumb;
break;
case 'link':
return '<a href="'.$tp->replaceConstants($path, 'abs').'" class="cpage-image" rel="external image"><img class="cpage-image" src="'.$src.'" alt="'.varset($parms[1]['alt']).'" /></a>';
break;
case 'tag':
default:
return '<img class="cpage-image" src="'.$thumb.'" alt="'.varset($parms[1]['alt']).'" />';
break;
}
}
function sc_cpagelink($parm)
{
$url = $this->sc_cpageurl();
if($parm == 'href' || !$url)
{
return $url;
}
return '<a class="cpage" href="'.$url.'">'.$this->sc_cpagetitle().'</a>';
}
function sc_cpageurl()
{
return e107::getUrl()->create('page/view', $this->page, array('allow' => 'page_sef,page_title,page_id'));
}
}

View File

@@ -43,6 +43,8 @@
* - plugin (string) [optional]: plugin name used for template loading
* - tmpl_prefix (string) [optional]: template keys prefix; core supported are 'default' and 'dropdown', default depends on 'old_np' pref
* - navcount (integer) [optional]: number of navigation items to be shown, minimal allowed value is 4, default is 10
* - nonavcount (no value) [optional]: if is set it'll disable navigation counting (navcount will be ignored)
* - bullet (string) [optional]: currently it should contain the markup to be prepended to the navigation item title
*
* WARNING: You have to do rawuldecode() on url, caption and title parameter values (before passing them to the shortcode)
* or you'll break the whole script
@@ -134,15 +136,24 @@ function nextprev_shortcode($parm = '')
if($total_pages <= 1) { return ''; }
// urldecoded once by parse_str()
if(substr($parm['url'], 0, 5) == 'url::')
if(substr($parm['url'], 0, 7) == 'route::')
{
// New - use URL assembling engine
// Format is: url::route::params::options
// Format is: route::module/controller/action::urlParams::urlOptions
// Example: url::news/list/category::id=xxx&name=yyy&page=--PAGE--::full=1
// WARNING - url parameter string have to be rawurlencode-ed BEFORE passed to the shortcode, or it'll break everything
$urlParms = explode('::', $parm['url']);
$url = str_replace(array('--FROM--', '--AMP--'), array('[FROM]', '&amp;'), $e107->url->create($urlParms[1], $urlParms[2], varset($urlParms[3])));
}
elseif(substr($parm['url'], 0, 5) == 'url::')
{
// New - use URL assembling engine
// Format is: url::module/controller/action?id=xxx&name=yyy&page=--PAGE--::full=1
// WARNING - url parameter string have to be rawurlencode-ed BEFORE passed to the shortcode, or it'll break everything
$urlParms = explode('::', $parm['url']);
$url = str_replace(array('--FROM--', '--AMP--'), array('[FROM]', '&amp;'), $e107->url->create($urlParms[1], array(), varset($urlParms[2])));
}
// just regular full or absolute URL
else $url = str_replace(array('--FROM--', '--AMP--'), array('[FROM]', '&amp;'), $parm['url']);
// Simple parser vars
@@ -161,11 +172,24 @@ function nextprev_shortcode($parm = '')
// urldecoded by parse_str()
$pagetitle = explode('|',$parm['pagetitle']);
// new - bullet support
$bullet = vartrue($parm['bullet'], '');
// navigation number settings
$navcount = abs(intval(vartrue($parm['navcount'], 10))); // prevent infinite loop!
if($navcount < 4) $navcount = 4;
$navmid = floor($navcount/2);
// no navigation counter
if(isset($parm['nonavcount']))
{
$navcount = $total_pages;
$navmid = 0;
}
else
{
// navigation number settings
$navcount = abs(intval(vartrue($parm['navcount'], 10))); // prevent infinite loop!
if($navcount < 4) $navcount = 4;
$navmid = floor($navcount/2);
}
// get template - nextprev_template.php, support for plugin template locations - myplug/templates/nextprev_template.php
$tmpl = e107::getTemplate(varset($parm['plugin'], null), 'nextprev');
@@ -173,9 +197,9 @@ function nextprev_shortcode($parm = '')
// init advanced navigation visibility
$show_first = $show_prev = ($current_page != 1);
$show_last = $show_next = ($current_page != $total_pages);
// Render
// XXX - parseTemplate vs simpleParse ??? Currently can't find a reason why we should parse via parseTemplate
// Parse via simpleParse()
$tp = e107::getParser();
// Nextprev navigation start
@@ -248,6 +272,7 @@ function nextprev_shortcode($parm = '')
}
$e_vars_loop = new e_vars();
$e_vars_loop->bullet = $bullet;
$ret_items = array();
for($c = $loop_start; $c < $loop_end; $c++)
{

View File

@@ -90,9 +90,9 @@ class core_news_rewrite_extended_url extends eUrlConfig
### View news item - kinda catch all - very bad performance when News is chosen as default namespace - two additional DB queries on every site call!
## Leading category name - uncomment to enable
'<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_title' => 'name', 'mapVars' => array('category_name' => 'category', 'news_title' => 'name', 'news_id' => 'id'), 'category_name' => 'category'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
'<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('category_name' => 'category', 'news_title' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
// Base location as item view - fallback if category sef is missing
'<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_title' => 'name'), 'mapVars' => array('news_id' => 'id', 'news_title' => 'name'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
'<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_id' => 'id', 'news_title' => 'name'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
// fallback if news sef is missing
'View/<id:{number}>' => array('view/item', 'mapVars' => array('news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),

View File

@@ -0,0 +1,99 @@
<?php
/**
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* User routing config
*/
class core_page_sef_url extends eUrlConfig
{
public function config()
{
return array(
'config' => array(
'allowMain' => true,
'noSingleEntry' => false, // [optional] default false; disallow this module to be shown via single entry point when this config is used
'legacy' => '{e_BASE}page.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
'selfParse' => false, // [optional] default false; use only this->parse() method, no core routine URL parsing
'selfCreate' => false, // [optional] default false; use only this->create() method, no core routine URL creating
'defaultRoute' => 'view/index',// [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
'mapVars' => array(
'page_id' => 'id',
'page_title' => 'name',
),
'allowVars' => array(
'page', 'id',
),
),
'rules' => array(
### using only title for pages is risky enough (non-unique title, possible bad characters)
//'<name:{secure}>' => array('view/index', 'allowVars' => array('name'),'legacyQuery' => '{name}.{page}', 'parseCallback' => 'itemIdByTitle'),
'<id:{number}>/<name:{secure}>' => array('view/index', 'legacyQuery' => '{id}.{page}', ),
### fallback when assembling method don't know the title of the page - build by ID only
'<id:{number}>' => array('view/index', 'legacyQuery' => '{id}.{page}', ),
### page list
'list' => array('list/index', 'legacyQuery' => '', ),
'/' => array('list/index', 'legacyQuery' => '', ),
) // rule set array
);
}
/**
* Admin callback
* Language file not loaded as all language data is inside the lan_eurl.php (loaded by default on administration URL page)
*/
public function admin()
{
// static may be used for performance
static $admin = array(
'labels' => array(
'name' => LAN_EURL_CORE_PAGE, // Module name
'label' => LAN_EURL_PAGE_SEF_LABEL, // Current profile name
'description' => LAN_EURL_PAGE_SEF_DESCR, //
),
'form' => array(), // Under construction - additional configuration options
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
);
return $admin;
}
### CUSTOM METHODS ###
/**
* view/item by name callback
* @param eRequest $request
*/
public function itemIdByTitle(eRequest $request)
{
$name = $request->getRequestParam('name');
if(($id = $request->getRequestParam('id')))
{
$request->setRequestParam('name', $id);
return;
}
elseif(!$name) return;
elseif(is_numeric($name))
{
return;
}
$sql = e107::getDb('url');
$name = e107::getParser()->toDB($name);var_dump($name);
if($sql->db_Select('page', 'page_id', "page_theme='' AND page_title='{$name}'")) // TODO - it'll be page_sef (new) field
{
$name = $sql->db_Fetch();
$request->setRequestParam('name', $name['page_id']);
}
else $request->setRequestParam('name', 0);
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* Page routing config
*/
class core_page_url extends eUrlConfig
{
public function config()
{
return array(
'config' => array(
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
'legacy' => '{e_BASE}page.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
'mapVars' => array(),
'allowVars' => array(),
),
'rules' => array() // rule set array
);
}
/**
*
*/
public function create($route, $params = array())
{
if(!$params) return 'page.php';
if(is_string($route)) $route = explode('/', $route, 2);
if(!varset($route[1])) $route[1] = 'index';
## aliases as retrieved from the DB, map vars to proper values
if(isset($params['page_title']) && !empty($params['page_title'])) $params['name'] = $params['page_title'];
if(isset($params['page_id']) && !empty($params['page_id'])) $params['id'] = $params['page_id'];
$url = 'page.php?';
if('--FROM--' != vartrue($params['page'])) $page = varset($params['page']) ? intval($params['page']) : '0';
else $page = '--FROM--';
$url .= intval($params['id']).($page ? '.'.$page : '');
return $url;
}
/**
* Admin callback
* Language file not loaded as all language data is inside the lan_eurl.php (loaded by default on administration URL page)
*/
public function admin()
{
// static may be used for performance
static $admin = array(
'labels' => array(
'name' => LAN_EURL_CORE_PAGE, // Module name
'label' => LAN_EURL_PAGE_DEFAULT_LABEL, // Current profile name
'description' => LAN_EURL_PAGE_DEFAULT_DESCR, //
),
'form' => array(), // Under construction - additional configuration options
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
);
return $admin;
}
public function parse($pathInfo)
{
// this config doesn't support parsing, it's done by the module entry script (news.php)
// this means News are not available via single entry point if this config is currently active
return false;
}
}

View File

@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
/*
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* System routing config

View File

@@ -1,5 +1,10 @@
<?php
/*
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* System routing config
*/
class core_system_url extends eUrlConfig
{
public function config()

View File

@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
/*
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* User routing config

View File

@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*