Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reduced the nesting level

  • Loading branch information...
commit 3697745dab8391111487a82475141d7cd4c5907e 1 parent e2151eb
@tijsverkoyen tijsverkoyen authored
View
24 backend/core/engine/model.php
@@ -652,24 +652,20 @@ public static function getURLForBlock($module, $action = null, $language = null)
}
}
- // pageId stored?
- if($pageIdForURL !== null)
- {
- // build URL
- $URL = self::getURL($pageIdForURL, $language);
+ // still no page id?
+ if($pageIdForURL === null) return self::getURL(404);
- // set locale
- FrontendLanguage::setLocale($language);
+ // build URL
+ $URL = self::getURL($pageIdForURL, $language);
- // append action
- $URL .= '/' . urldecode(FL::act(SpoonFilter::toCamelCase($action)));
+ // set locale
+ FrontendLanguage::setLocale($language);
- // return the unique URL!
- return $URL;
- }
+ // append action
+ $URL .= '/' . urldecode(FL::act(SpoonFilter::toCamelCase($action)));
- // fallback
- return self::getURL(404);
+ // return the unique URL!
+ return $URL;
}
/**
View
67 backend/init.php
@@ -109,44 +109,43 @@ public static function autoLoader($className)
$className = func_get_arg(0);
// split in parts
- if(preg_match_all('/[A-Z][a-z0-9]*/', $className, $parts))
+ if(!preg_match_all('/[A-Z][a-z0-9]*/', $className, $parts)) return;
+
+
+ // the real matches
+ $parts = $parts[0];
+
+ // get root path constant and see if it exists
+ $rootPath = strtoupper(array_shift($parts)) . '_PATH';
+ if(!defined($rootPath)) return;
+
+ foreach($parts as $i => $part)
{
- // the real matches
- $parts = $parts[0];
+ // skip the first
+ if($i == 0) continue;
+
+ // action
+ $action = strtolower(implode('_', $parts));
- // get root path constant and see if it exists
- $rootPath = strtoupper(array_shift($parts)) . '_PATH';
- if(defined($rootPath))
+ // module
+ $module = '';
+ for($j = 0; $j < $i; $j++) $module .= strtolower($parts[$j]) . '_';
+
+ // fix action & module
+ $action = substr($action, strlen($module));
+ $module = substr($module, 0, -1);
+
+ // check the actions, engine & widgets directories
+ foreach(array('actions', 'engine', 'widgets') as $dir)
{
- foreach($parts as $i => $part)
+ // file to be loaded
+ $pathToLoad = constant($rootPath) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $action . '.php';
+
+ // if it exists, load it!
+ if($pathToLoad != '' && SpoonFile::exists($pathToLoad))
{
- // skip the first
- if($i == 0) continue;
-
- // action
- $action = strtolower(implode('_', $parts));
-
- // module
- $module = '';
- for($j = 0; $j < $i; $j++) $module .= strtolower($parts[$j]) . '_';
-
- // fix action & module
- $action = substr($action, strlen($module));
- $module = substr($module, 0, -1);
-
- // check the actions, engine & widgets directories
- foreach(array('actions', 'engine', 'widgets') as $dir)
- {
- // file to be loaded
- $pathToLoad = constant($rootPath) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $action . '.php';
-
- // if it exists, load it!
- if($pathToLoad != '' && SpoonFile::exists($pathToLoad))
- {
- require_once $pathToLoad;
- break 2;
- }
- }
+ require_once $pathToLoad;
+ break 2;
}
}
}
View
164 backend/modules/blog/actions/mass_comment_action.php
@@ -30,17 +30,55 @@ public function execute()
// no id's provided
if(!isset($_GET['id'])) $this->redirect(BackendModel::createURLForAction('comments') . '&error=no-comments-selected');
- // at least one id
- else
+ // redefine id's
+ $ids = (array) $_GET['id'];
+
+ // delete comment(s)
+ if($action == 'delete') BackendBlogModel::deleteComments($ids);
+
+ // spam
+ elseif($action == 'spam')
{
- // redefine id's
- $ids = (array) $_GET['id'];
+ // is the spamfilter active?
+ if(BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false))
+ {
+ // get data
+ $comments = BackendBlogModel::getComments($ids);
+
+ // loop comments
+ foreach($comments as $row)
+ {
+ // unserialize data
+ $row['data'] = unserialize($row['data']);
+
+ // check if needed data is available
+ if(!isset($row['data']['server']['REMOTE_ADDR'])) continue;
+ if(!isset($row['data']['server']['HTTP_USER_AGENT'])) continue;
+
+ // build vars
+ $userIp = $row['data']['server']['REMOTE_ADDR'];
+ $userAgent = $row['data']['server']['HTTP_USER_AGENT'];
+ $content = $row['text'];
+ $author = $row['author'];
+ $email = $row['email'];
+ $url = (isset($row['website']) && $row['website'] != '') ? $row['website'] : null;
+ $referrer = (isset($row['data']['server']['HTTP_REFERER'])) ? $row['data']['server']['HTTP_REFERER'] : null;
+ $others = $row['data']['server'];
+
+ // submit as spam
+ BackendModel::submitSpam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others);
+ }
+ }
- // delete comment(s)
- if($action == 'delete') BackendBlogModel::deleteComments($ids);
+ // set new status
+ BackendBlogModel::updateCommentStatuses($ids, $action);
+ }
- // spam
- elseif($action == 'spam')
+ // other actions (status updates)
+ else
+ {
+ // published?
+ if($action == 'published')
{
// is the spamfilter active?
if(BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false))
@@ -51,89 +89,47 @@ public function execute()
// loop comments
foreach($comments as $row)
{
- // unserialize data
- $row['data'] = unserialize($row['data']);
-
- // check if needed data is available
- if(!isset($row['data']['server']['REMOTE_ADDR'])) continue;
- if(!isset($row['data']['server']['HTTP_USER_AGENT'])) continue;
-
- // build vars
- $userIp = $row['data']['server']['REMOTE_ADDR'];
- $userAgent = $row['data']['server']['HTTP_USER_AGENT'];
- $content = $row['text'];
- $author = $row['author'];
- $email = $row['email'];
- $url = (isset($row['website']) && $row['website'] != '') ? $row['website'] : null;
- $referrer = (isset($row['data']['server']['HTTP_REFERER'])) ? $row['data']['server']['HTTP_REFERER'] : null;
- $others = $row['data']['server'];
-
- // submit as spam
- BackendModel::submitSpam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others);
- }
- }
-
- // set new status
- BackendBlogModel::updateCommentStatuses($ids, $action);
- }
-
- // other actions (status updates)
- else
- {
- // published?
- if($action == 'published')
- {
- // is the spamfilter active?
- if(BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false))
- {
- // get data
- $comments = BackendBlogModel::getComments($ids);
-
- // loop comments
- foreach($comments as $row)
+ // previous status is spam
+ if($row['status'] == 'spam')
{
- // previous status is spam
- if($row['status'] == 'spam')
- {
- // unserialize data
- $row['data'] = unserialize($row['data']);
-
- // check if needed data is available
- if(!isset($row['data']['server']['REMOTE_ADDR'])) continue;
- if(!isset($row['data']['server']['HTTP_USER_AGENT'])) continue;
-
- // build vars
- $userIp = $row['data']['server']['REMOTE_ADDR'];
- $userAgent = $row['data']['server']['HTTP_USER_AGENT'];
- $content = $row['text'];
- $author = $row['author'];
- $email = $row['email'];
- $url = (isset($row['website']) && $row['website'] != '') ? $row['website'] : null;
- $referrer = (isset($row['data']['server']['HTTP_REFERER'])) ? $row['data']['server']['HTTP_REFERER'] : null;
- $others = $row['data']['server'];
-
- // submit as spam
- BackendModel::submitHam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others);
- }
+ // unserialize data
+ $row['data'] = unserialize($row['data']);
+
+ // check if needed data is available
+ if(!isset($row['data']['server']['REMOTE_ADDR'])) continue;
+ if(!isset($row['data']['server']['HTTP_USER_AGENT'])) continue;
+
+ // build vars
+ $userIp = $row['data']['server']['REMOTE_ADDR'];
+ $userAgent = $row['data']['server']['HTTP_USER_AGENT'];
+ $content = $row['text'];
+ $author = $row['author'];
+ $email = $row['email'];
+ $url = (isset($row['website']) && $row['website'] != '') ? $row['website'] : null;
+ $referrer = (isset($row['data']['server']['HTTP_REFERER'])) ? $row['data']['server']['HTTP_REFERER'] : null;
+ $others = $row['data']['server'];
+
+ // submit as spam
+ BackendModel::submitHam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others);
}
}
}
-
- // set new status
- BackendBlogModel::updateCommentStatuses($ids, $action);
}
- // define report
- $report = (count($ids) > 1) ? 'comments-' : 'comment-';
+ // set new status
+ BackendBlogModel::updateCommentStatuses($ids, $action);
+ }
- // init var
- if($action == 'published') $report .= 'moved-published';
- if($action == 'moderation') $report .= 'moved-moderation';
- if($action == 'spam') $report .= 'moved-spam';
- if($action == 'delete') $report .= 'deleted';
+ // define report
+ $report = (count($ids) > 1) ? 'comments-' : 'comment-';
- // redirect
- $this->redirect(BackendModel::createURLForAction('comments') . '&report=' . $report . '#tab' . ucfirst($from));
- }
+ // init var
+ if($action == 'published') $report .= 'moved-published';
+ if($action == 'moderation') $report .= 'moved-moderation';
+ if($action == 'spam') $report .= 'moved-spam';
+ if($action == 'delete') $report .= 'deleted';
+
+ // redirect
+ $this->redirect(BackendModel::createURLForAction('comments') . '&report=' . $report . '#tab' . ucfirst($from));
}
}
View
55 backend/modules/extensions/engine/model.php
@@ -976,40 +976,39 @@ public static function validateThemeInformation($information)
continue;
}
- // check if there are positions
- if(isset($template['positions']) && $template['positions'])
+ // if there are no positions we should continue with the next item
+ if(!isset($template['positions']) && $template['positions']) continue;
+
+ // loop positions
+ foreach($template['positions'] as $j => $position)
{
- // loop positions
- foreach($template['positions'] as $j => $position)
+ // check if position is valid
+ if(!isset($position['name']) || !$position['name'])
{
- // check if position is valid
- if(!isset($position['name']) || !$position['name'])
- {
- unset($information['templates'][$i]['positions'][$j]);
- continue;
- }
+ unset($information['templates'][$i]['positions'][$j]);
+ continue;
+ }
- // ensure widgets are well-formed
- if(!isset($position['widgets']) || !$position['widgets'])
- {
- $information['templates'][$i]['positions'][$j]['widgets'] = array();
- }
+ // ensure widgets are well-formed
+ if(!isset($position['widgets']) || !$position['widgets'])
+ {
+ $information['templates'][$i]['positions'][$j]['widgets'] = array();
+ }
- // ensure editors are well-formed
- if(!isset($position['editors']) || !$position['editors'])
- {
- $information['templates'][$i]['positions'][$j]['editors'] = array();
- }
+ // ensure editors are well-formed
+ if(!isset($position['editors']) || !$position['editors'])
+ {
+ $information['templates'][$i]['positions'][$j]['editors'] = array();
+ }
- // loop widgets
- foreach($position['widgets'] as $k => $widget)
+ // loop widgets
+ foreach($position['widgets'] as $k => $widget)
+ {
+ // check if widget is valid
+ if(!isset($widget['module']) || !$widget['module'] || !isset($widget['action']) || !$widget['action'])
{
- // check if widget is valid
- if(!isset($widget['module']) || !$widget['module'] || !isset($widget['action']) || !$widget['action'])
- {
- unset($information['templates'][$i]['positions'][$j]['widgets'][$k]);
- continue;
- }
+ unset($information['templates'][$i]['positions'][$j]['widgets'][$k]);
+ continue;
}
}
}
View
96 backend/modules/profiles/actions/mass_action.php
@@ -28,70 +28,62 @@ public function execute()
$ids = (isset($_GET['id'])) ? (array) $_GET['id'] : array();
$newGroupId = SpoonFilter::getGetValue('newGroup', array_keys(BackendProfilesModel::getGroups()), '');
- // at least one id
- if(!empty($ids))
+ // no ids provided
+ if(empty($ids)) $this->redirect(BackendModel::createURLForAction('index') . '&error=no-profiles-selected');
+
+ // delete the given profiles
+ if($action === 'delete')
{
- // delete the given profiles
- if($action === 'delete')
- {
- BackendProfilesModel::delete($ids);
- $report = 'deleted';
- }
+ BackendProfilesModel::delete($ids);
+ $report = 'deleted';
+ }
+
+ // add the profiles to the given group
+ elseif($action === 'addToGroup')
+ {
+ // no group id provided
+ if($newGroupId == '') $this->redirect(BackendModel::createURLForAction('index') . '&error=no-group-selected');
- // add the profiles to the given group
- elseif($action === 'addToGroup')
+ // set new status
+ foreach($ids as $id)
{
- // for which we need a group of course
- if($newGroupId != '')
+ // profile must exist
+ if(BackendProfilesModel::exists($id))
{
- // set new status
- foreach($ids as $id)
+ // make sure the user is not already part of this group without an expiration date
+ foreach(BackendProfilesModel::getProfileGroups($id) as $existingGroup)
{
- // profile must exist
- if(BackendProfilesModel::exists($id))
- {
- // make sure the user is not already part of this group without an expiration date
- foreach(BackendProfilesModel::getProfileGroups($id) as $existingGroup)
- {
- // if he is, skip to the next user
- if($existingGroup['group_id'] === $newGroupId) continue 2;
- }
-
- // OK, it's safe to add the user to this group
- BackendProfilesModel::insertProfileGroup(array(
- 'profile_id' => $id,
- 'group_id' => $newGroupId,
- 'starts_on' => BackendModel::getUTCDate()
- ));
- }
+ // if he is, skip to the next user
+ if($existingGroup['group_id'] === $newGroupId) continue 2;
}
- // report
- $report = 'added-to-group';
+ // OK, it's safe to add the user to this group
+ BackendProfilesModel::insertProfileGroup(array(
+ 'profile_id' => $id,
+ 'group_id' => $newGroupId,
+ 'starts_on' => BackendModel::getUTCDate()
+ ));
}
-
- // no group id provided
- else $this->redirect(BackendModel::createURLForAction('index') . '&error=no-group-selected');
}
- // unknown action
- else $this->redirect(BackendModel::createURLForAction('index') . '&error=unknown-action');
-
// report
- $report = (count($ids) > 1 ? 'profiles-' : 'profile-') . $report;
-
- // redirect
- $this->redirect(BackendModel::createURLForAction('index', null, null, array(
- 'offset' => SpoonFilter::getGetValue('offset', null, ''),
- 'order' => SpoonFilter::getGetValue('order', null, ''),
- 'sort' => SpoonFilter::getGetValue('sort', null, ''),
- 'email' => SpoonFilter::getGetValue('email', null, ''),
- 'status' => SpoonFilter::getGetValue('status', null, ''),
- 'group' => SpoonFilter::getGetValue('group', null, '')
- )) . '&report=' . $report);
+ $report = 'added-to-group';
}
- // no id's provided
- else $this->redirect(BackendModel::createURLForAction('index') . '&error=no-profiles-selected');
+ // unknown action
+ else $this->redirect(BackendModel::createURLForAction('index') . '&error=unknown-action');
+
+ // report
+ $report = (count($ids) > 1 ? 'profiles-' : 'profile-') . $report;
+
+ // redirect
+ $this->redirect(BackendModel::createURLForAction('index', null, null, array(
+ 'offset' => SpoonFilter::getGetValue('offset', null, ''),
+ 'order' => SpoonFilter::getGetValue('order', null, ''),
+ 'sort' => SpoonFilter::getGetValue('sort', null, ''),
+ 'email' => SpoonFilter::getGetValue('email', null, ''),
+ 'status' => SpoonFilter::getGetValue('status', null, ''),
+ 'group' => SpoonFilter::getGetValue('group', null, '')
+ )) . '&report=' . $report);
}
}
View
70 frontend/core/engine/navigation.php
@@ -468,45 +468,40 @@ public static function getURLForBlock($module, $action = null, $language = null)
foreach($pages as $pageId => $properties)
{
// only process pages with extra_blocks
- if(isset($properties['extra_blocks']))
+ if(!isset($properties['extra_blocks'])) continue;
+
+ // loop extras
+ foreach($properties['extra_blocks'] as $extra)
{
- // loop extras
- foreach($properties['extra_blocks'] as $extra)
+ // direct link?
+ if($extra['module'] == $module && $extra['action'] == $action)
+ {
+ // exact page was found, so return
+ return self::getURL($properties['page_id'], $language);
+ }
+
+ // correct module but no action
+ elseif($extra['module'] == $module && $extra['action'] == null)
{
- // direct link?
- if($extra['module'] == $module && $extra['action'] == $action)
- {
- // exact page was found, so return
- return self::getURL($properties['page_id'], $language);
- }
-
- // correct module but no action
- elseif($extra['module'] == $module && $extra['action'] == null)
- {
- // store pageId
- $pageIdForURL = (int) $pageId;
- }
+ // store pageId
+ $pageIdForURL = (int) $pageId;
}
}
}
}
}
- // pageId stored?
- if($pageIdForURL !== null)
- {
- // build URL
- $URL = self::getURL($pageIdForURL, $language);
+ // pageId stull null?
+ if($pageIdForURL === null) return self::getURL(404, $language);
- // append action
- $URL .= '/' . FL::act(SpoonFilter::toCamelCase($action));
+ // build URL
+ $URL = self::getURL($pageIdForURL, $language);
- // return the URL
- return $URL;
- }
+ // append action
+ $URL .= '/' . FL::act(SpoonFilter::toCamelCase($action));
- // fallback
- return self::getURL(404, $language);
+ // return the URL
+ return $URL;
}
/**
@@ -533,18 +528,17 @@ public static function getURLForExtraId($id, $language = null)
// loop pages
foreach($pages as $properties)
{
- // only process pages with extra_blocks
- if(isset($properties['extra_blocks']))
+ // no extra_blocks available, so skip this item
+ if(isset($properties['extra_blocks'])) continue;
+
+ // loop extras
+ foreach($properties['extra_blocks'] as $extra)
{
- // loop extras
- foreach($properties['extra_blocks'] as $extra)
+ // direct link?
+ if($extra['id'] == $id)
{
- // direct link?
- if($extra['id'] == $id)
- {
- // exact page was found, so return
- return self::getURL($properties['page_id'], $language);
- }
+ // exact page was found, so return
+ return self::getURL($properties['page_id'], $language);
}
}
}
View
74 frontend/init.php
@@ -28,14 +28,11 @@ class FrontendInit
*/
public function __construct($type)
{
- // init vars
$allowedTypes = array('frontend', 'frontend_ajax', 'frontend_js');
$type = (string) $type;
// check if this is a valid type
if(!in_array($type, $allowedTypes)) exit('Invalid init-type');
-
- // set type
$this->type = $type;
// register the autoloader
@@ -57,7 +54,6 @@ public function __construct($type)
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
- // require globals
$this->requireGlobals();
// get last modified time for globals
@@ -69,10 +65,8 @@ public function __construct($type)
// define as a constant
define('LAST_MODIFIED_TIME', $lastModifiedTime);
- // define constants
$this->definePaths();
$this->defineURLs();
-
$this->setIncludePath();
$this->setDebugging();
@@ -121,45 +115,43 @@ public static function autoLoader($className)
// we'll need the original class name again, with the uppercases
$className = func_get_arg(0);
- // split in parts
- if(preg_match_all('/[A-Z][a-z0-9]*/', $className, $parts))
+ // split in parts, if nothing is found we stop processing
+ if(!preg_match_all('/[A-Z][a-z0-9]*/', $className, $parts)) return;
+
+ // the real matches
+ $parts = $parts[0];
+
+ // doublecheck that we are looking for a frontend class, of that isn't the case we should stop.
+ $root = array_shift($parts);
+ if(strtolower($root) != 'frontend') return;
+
+ foreach($parts as $i => $part)
{
- // the real matches
- $parts = $parts[0];
+ // skip the first
+ if($i == 0) continue;
- // doublecheck that we are looking for a frontend class
- $root = array_shift($parts);
- if(strtolower($root) == 'frontend')
+ // action
+ $action = strtolower(implode('_', $parts));
+
+ // module
+ $module = '';
+ for($j = 0; $j < $i; $j++) $module .= strtolower($parts[$j]) . '_';
+
+ // fix action & module
+ $action = substr($action, strlen($module));
+ $module = substr($module, 0, -1);
+
+ // check the actions, engine & widgets directories
+ foreach(array('actions', 'engine', 'widgets') as $dir)
{
- foreach($parts as $i => $part)
+ // file to be loaded
+ $pathToLoad = FRONTEND_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $action . '.php';
+
+ // if it exists, load it!
+ if($pathToLoad != '' && SpoonFile::exists($pathToLoad))
{
- // skip the first
- if($i == 0) continue;
-
- // action
- $action = strtolower(implode('_', $parts));
-
- // module
- $module = '';
- for($j = 0; $j < $i; $j++) $module .= strtolower($parts[$j]) . '_';
-
- // fix action & module
- $action = substr($action, strlen($module));
- $module = substr($module, 0, -1);
-
- // check the actions, engine & widgets directories
- foreach(array('actions', 'engine', 'widgets') as $dir)
- {
- // file to be loaded
- $pathToLoad = FRONTEND_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $action . '.php';
-
- // if it exists, load it!
- if($pathToLoad != '' && SpoonFile::exists($pathToLoad))
- {
- require_once $pathToLoad;
- break;
- }
- }
+ require_once $pathToLoad;
+ break;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.