Skip to content

Commit

Permalink
Code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Aug 1, 2017
1 parent 3ecc585 commit 63cd08e
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 76 deletions.
10 changes: 5 additions & 5 deletions dist/twist/Classes/Error.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

namespace Twist\Classes;
use Twist\Core\Models\String\SyntaxHighlight;

/**
* A custom error handler that handles all of TwistPHPs Errors, Exceptions and Fatal Errors, it also handles errors produced in your PHP code and outputs all HTTP status pages.
Expand Down Expand Up @@ -187,14 +188,14 @@ public static function handleException($resException,$arrError = array()){
$arrTags['dump_data'] = '';
}

$arrTags['php_code'] = \Twist\Core\Models\String\SyntaxHighlight::file($resException->getFile(),'em',$resException->getLine(),5);
$arrTags['php_code'] = SyntaxHighlight::file($resException->getFile(),'em',$resException->getLine(),5);

$arrTags['trace'] = '';
if(count($resException->getTrace())){
$arrTags['trace'] = '<h3>Backtrace</h3>';
foreach($resException->getTrace() as $arrEachCall){
if(array_key_exists('file',$arrEachCall)){
$arrTags['trace'] .= sprintf('<pre class="code" lang="php" title="%s">%s</pre>',$arrEachCall['file'],\Twist\Core\Models\String\SyntaxHighlight::file($arrEachCall['file'],'em',$arrEachCall['line'],2));
$arrTags['trace'] .= sprintf('<pre class="code" lang="php" title="%s">%s</pre>',$arrEachCall['file'],SyntaxHighlight::file($arrEachCall['file'],'em',$arrEachCall['line'],2));
}
}
}
Expand Down Expand Up @@ -260,7 +261,7 @@ public static function handleError($intErrorNo, $strError, $strErrorFile, $intEr
'file' => $strErrorFile,
'file_size' => (file_exists($strErrorFile)) ? filesize($strErrorFile) : 0,
'code_line' => $intErrorLine,
'code' => \Twist\Core\Models\String\SyntaxHighlight::file($strErrorFile,'em',$intErrorLine,3)
'code' => SyntaxHighlight::file($strErrorFile,'em',$intErrorLine,3)
);

\Twist::framework()->debug()->log('Error','php',$arrError);
Expand All @@ -276,7 +277,7 @@ public static function handleFatal(){
$arrLastError = error_get_last();

//Check if the last error was fatal (INSTANT DEATH)
if(self::getType($arrLastError['type'],true) === "Fatal Error"){
if(self::getType($arrLastError['type']) === "Fatal Error"){

//throw new Exception($arrLastError['message']);
//A fatal error has occured, throw and exception instead.
Expand Down Expand Up @@ -450,7 +451,6 @@ public static function outputLog(){
*/
public static function getType($intErrorNo){

$strErrorType = '';
$strDeprecated = $strDeprecatedUser = 'Unknown';

if(defined('E_DEPRECATED')){
Expand Down
2 changes: 1 addition & 1 deletion dist/twist/Core/Controllers/Base.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

namespace Twist\Core\Controllers;
use Twist\Core\Models\Route\Meta;

use Twist\Classes\Error;

/**
Expand Down
6 changes: 4 additions & 2 deletions dist/twist/Core/Controllers/BaseREST.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function _fallback(){
* @param mixed $mxdResults Results of the function call to be returned to the user
* @param int $intCount Number of results returned by the function call
* @param int $intResponseCode HTTP response code for the call
*/
* @return string Response to serve to the client
*/
public function _respond($mxdResults,$intCount = 1,$intResponseCode = 200){

header(sprintf("HTTP/1.1 %s %s",$intResponseCode,Error::responseInfo($intResponseCode)));
Expand Down Expand Up @@ -107,7 +108,8 @@ public function _respond($mxdResults,$intCount = 1,$intResponseCode = 200){
* Error response to an API call should be used to return a standardised RESTful error response
* @param string $strErrorMessage Error message to indicate what when wrong
* @param int $intResponseCode HTTP response code for the call
*/
* @return string Response to the client with an error
*/
public function _respondError($strErrorMessage,$intResponseCode = 404){

header(sprintf("HTTP/1.1 %s %s",$intResponseCode,Error::responseInfo($intResponseCode)));
Expand Down
2 changes: 1 addition & 1 deletion dist/twist/Core/Controllers/BaseRESTUser.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BaseRESTUser extends BaseRESTKey{
/**
* An extension of BaseRest->_auth to determine if the request is a logged in user, if so validate the auth token otherwise try to log the user in.
* A valid auth key and IP address is still required here, Failure to get a valid user session will terminate the request here, the controller function will not be run
* @return bool|void
* @return bool|string
*/
public function _auth(){

Expand Down
8 changes: 4 additions & 4 deletions dist/twist/Core/Controllers/InstallWizard.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,19 @@ public function settings(){
'uploads_path' => ($strSiteRoot === '/') ? '' : ltrim($strSiteRoot,'/').'/uploads',
);

if(array_key_exists($arrSession['settings']['details'],'site_root')){
if(array_key_exists('site_root', $arrSession['settings']['details'])){
$arrTags['site_root'] = $arrSession['settings']['details']['site_root'];
}

if(array_key_exists($arrSession['settings']['details'],'app_path')){
if(array_key_exists('app_path', $arrSession['settings']['details'])){
$arrTags['app_path'] = $arrSession['settings']['details']['app_path'];
}

if(array_key_exists($arrSession['settings']['details'],'packages_path')){
if(array_key_exists('packages_path', $arrSession['settings']['details'])){
$arrTags['packages_path'] = $arrSession['settings']['details']['packages_path'];
}

if(array_key_exists($arrSession['settings']['details'],'uploads_path')){
if(array_key_exists('uploads_path', $arrSession['settings']['details'])){
$arrTags['uploads_path'] = $arrSession['settings']['details']['uploads_path'];
}

Expand Down
13 changes: 7 additions & 6 deletions dist/twist/Core/Controllers/Manager.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Twist\Core\Controllers;

use \Twist\Core\Models\Install;
use \Twist\Core\Models\Security\CodeScanner;

/**
* The route controller for the framework manager, generates the pages of the manager tool.
Expand Down Expand Up @@ -92,7 +93,7 @@ public function dashboard(){
$arrTags['version_status'] = '<span class="tag red">Failed to retrieve version information, try again later!</span>';
}

$objCodeScanner = new \Twist\Core\Models\Security\CodeScanner();
$objCodeScanner = new CodeScanner();
$arrTags['scanner'] = $objCodeScanner->getLastScan(TWIST_DOCUMENT_ROOT);

$arrRoutes = \Twist::Route()->getAll();
Expand Down Expand Up @@ -289,7 +290,7 @@ public function POSThtaccess(){
public function scanner(){

$arrTags = array();
$objCodeScanner = new \Twist\Core\Models\Security\CodeScanner();
$objCodeScanner = new CodeScanner();

if(array_key_exists('scan-now',$_GET)){
$objCodeScanner->scan(TWIST_DOCUMENT_ROOT);
Expand Down Expand Up @@ -328,22 +329,22 @@ public function settings(){
if($arrEachItem['type'] === 'string'){
$arrEachItem['input'] .= sprintf('<input type="text" name="settings[%s]" value="%s">',$arrEachItem['key'],$arrEachItem['value']);
}elseif($arrEachItem['type'] === 'boolean'){
$arrEachItem['input'] .= sprintf('<input type="checkbox" name="settings[%s]" %svalue="1">',$arrEachItem['key'],($arrEachItem['value'] == '1') ? 'checked ' : '');
$arrEachItem['input'] .= sprintf('<input type="checkbox" name="settings[%s]" value="1" %s>',$arrEachItem['key'],($arrEachItem['value'] == '1') ? 'checked ' : '');
}elseif($arrEachItem['type'] === 'options'){

$strOptions = '';
$arrOptions = explode(',',$arrEachItem['options']);

if(count($arrOptions) <= 3){
foreach($arrOptions as $strEachOption){
$strChecked = (trim($strEachOption) == $arrEachItem['value']) ? ' checked': '';
$strChecked = (trim($strEachOption) == $arrEachItem['value']) ? 'checked': '';
$strOptionKey = sprintf('%s-%s',$arrEachItem['key'],trim($strEachOption));
$arrEachItem['input'] .= sprintf('<input type="radio" id="settings_%s" name="settings[%s]" value="%s"%s><label for="settings_%s">%s</label>',$strOptionKey,$arrEachItem['key'],trim($strEachOption),$strChecked,$strOptionKey,trim($strEachOption));
$arrEachItem['input'] .= sprintf('<input type="radio" id="settings_%s" name="settings[%s]" value="%s" %s><label for="settings_%s">%s</label>',$strOptionKey,$arrEachItem['key'],trim($strEachOption),$strChecked,$strOptionKey,trim($strEachOption));
}
}else{
foreach($arrOptions as $strEachOption){
$strChecked = (trim($strEachOption) == $arrEachItem['value']) ? 'selected ': '';
$strOptions .= sprintf('<option %svalue="%s">%s</option>',$strChecked,trim($strEachOption),trim($strEachOption));
$strOptions .= sprintf('<option value="%s" %s>%s</option>',trim($strEachOption),$strChecked,trim($strEachOption));
}
$arrEachItem['input'] .= sprintf('<select name="settings[%s]">%s</select>',$arrEachItem['key'],$strOptions);
}
Expand Down
14 changes: 6 additions & 8 deletions dist/twist/Core/Controllers/Upload.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ public function _construct(){
/**
* Upload a file to the site and place in the uploads directory
* @param null $strFileKey
* @param null $intIndex
* @return string
*/
public function file($strFileKey = null,$intIndex = null){
public function file($strFileKey = null){

$this->resRoute->debugMode(false);
$arrOut = $this->storeFile($strFileKey,$intIndex);
$arrOut = $this->storeFile($strFileKey);

//Now if the file upload was successful process the asset (if required)
if($arrOut['status']){
Expand All @@ -69,13 +68,12 @@ public function file($strFileKey = null,$intIndex = null){
/**
* Upload an asset to the system and create relevant thumbnails of images.
* @param null $strFileKey
* @param null $intIndex
* @return string
*/
public function asset($strFileKey = null,$intIndex = null){
public function asset($strFileKey = null){

$this->resRoute->debugMode(false);
$arrOut = $this->storeFile($strFileKey,$intIndex);
$arrOut = $this->storeFile($strFileKey);

//Now if the file upload was successful process the asset (if required)
if($arrOut['status']){
Expand Down Expand Up @@ -128,10 +126,10 @@ public function asset($strFileKey = null,$intIndex = null){
return json_encode($arrOut);
}

protected function storeFile($strFileKey = null,$intIndex = null){
protected function storeFile($strFileKey = null){

if(is_array($_FILES) && count($_FILES)){
$arrOut = \Twist::File()->upload($strFileKey,null,$intIndex); //TODO: Is $intIndex used?
$arrOut = \Twist::File()->upload($strFileKey,null);
}else{
$arrOut = \Twist::File()->uploadPUT();
}
Expand Down
3 changes: 1 addition & 2 deletions dist/twist/Core/Models/Database/ProtocolMYSQLI.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ public function insertId(){
}

/**
* @param null $resResult
* @return int
*/
public function affectedRows($resResult = null){ //TODO: $resResult not used
public function affectedRows(){
return $this->resLink->affected_rows;
}

Expand Down
12 changes: 6 additions & 6 deletions dist/twist/Core/Models/Database/Record.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ public function delete(){
*/
public function increment($strField,$intStep = 1){
$intValue = $this->get($strField);
$intNewValue = $intValue+$intStep;
$this->set($strField,$intNewValue);
return $intNewValue;
$intValue += $intStep;
$this->set($strField,$intValue);
return $intValue;
}

/**
Expand All @@ -175,9 +175,9 @@ public function increment($strField,$intStep = 1){
*/
public function decrement($strField,$intStep = 1){
$intValue = $this->get($strField);
$intNewValue = $intValue-$intStep;
$this->set($strField,$intValue-$intIncrementStep);
return $intNewValue;
$intValue -= $intStep;
$this->set($strField,$intValue);
return $intValue;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions dist/twist/Core/Models/Debug.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public function window($arrCurrentRoute){
return $this->resTemplate->build('_base.tpl',$arrTags);
}

/**
* Return the JS catcher script for errors and warnings
* @return string
*/
public function catcher() {

$resResource = new \Twist\Core\Models\Resources();
Expand Down
2 changes: 2 additions & 0 deletions dist/twist/Core/Models/Email/ProtocolSMTP.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

class ProtocolSMTP extends BaseProtocol{

private $strLastResponse;

/**
* Open a new FTP connection
* @param string $strHost
Expand Down
1 change: 0 additions & 1 deletion dist/twist/Core/Models/Email/SourceParser.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ protected function stripEmailHeaders($strEmailSource){

$arrParts = explode("\n\n",$strEmailSource);

$strHeaders = $arrParts[0]; //TODO: Remove?
$arrParts[0] = null;

$strEmailSource = implode("\n\n",$arrParts);
Expand Down
1 change: 0 additions & 1 deletion dist/twist/Core/Models/Package.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ public function importSettings($dirSettingsJSON){

$dirInstallFile = $arrBacktrace[0]['file'];
$dirPackage = dirname($dirInstallFile);
$strSlug = strtolower(basename($dirPackage)); //TODO: Remove?

//Install the SQL tables when required
$dirSettingsJSON = (!file_exists($dirSettingsJSON)) ? sprintf('%s/%s', $dirPackage, $dirSettingsJSON) : $dirSettingsJSON;
Expand Down
12 changes: 6 additions & 6 deletions dist/twist/Core/Models/Resources.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ public function viewImage($strReference,$arrParameters = array()){
$strOut = $strImageSRC;
}else{

$strAttributes = '';
$arrAttributes = array();
foreach($arrParameters as $strKey => $mxdValue){
if(!in_array(strtolower($strKey),array('src','base64','uri'))){
$strAttributes .= sprintf(' %s="%s"',strtolower($strKey),htmlentities($mxdValue));
$arrAttributes[] = sprintf('%s="%s"',strtolower($strKey),htmlentities($mxdValue));
}
}

$strOut = sprintf('<img src="%s"%s>',$strImageSRC,$strAttributes);
$strOut = sprintf('<img src="%s" %s>',$strImageSRC,implode(' ',$arrAttributes));
}
}

Expand Down Expand Up @@ -318,15 +318,15 @@ protected function processJS($arrFiles,$strPath,$strURI,$blInline = false,$mxdAs
}
}else{
if(substr($strEachItem,0,2) === '//'){
$strOut .= sprintf('<script src="%s"%s></script>',$strEachItem,(is_null( $mxdAsyncType ) ? '' : sprintf( ' %s', $mxdAsyncType )));
$strOut .= sprintf('<script src="%s" %s></script>',$strEachItem,(is_null( $mxdAsyncType ) ? '' : $mxdAsyncType ));
}else{
$strOut .= sprintf('<script src="%s/%s"%s></script>',$strURI,$strEachItem,(is_null( $mxdAsyncType ) ? '' : sprintf( ' %s', $mxdAsyncType )));
$strOut .= sprintf('<script src="%s/%s" %s></script>',$strURI,$strEachItem,(is_null( $mxdAsyncType ) ? '' : $mxdAsyncType ));
}
}
}

if($blInline){
$strOut = sprintf( '<script%s>%s</script>',(is_null( $mxdAsyncType ) ? '' : sprintf( ' %s', $mxdAsyncType ) ), $strOut );
$strOut = sprintf( '<script %s>%s</script>',(is_null( $mxdAsyncType ) ? '' : $mxdAsyncType ), $strOut );
}

return $strOut;
Expand Down
6 changes: 3 additions & 3 deletions dist/twist/Core/Models/Session/Memcache.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ public function close(){
public function read($intSessionID){

$mxdOut = null;
$mxdOut = memcached::get(spritnf("sessions/sess_%s",$intSessionID));
$mxdOut = memcached::get(sprintf("sessions/sess_%s",$intSessionID));

return $mxdOut;
}

public function write($intSessionID, $mxdData){

$blOut = false;
$blOut = memcached::set(spritnf("sessions/sess_%s",$intSessionID), $mxdData, $this->maxLifetime);
$blOut = memcached::set(sprintf("sessions/sess_%s",$intSessionID), $mxdData, $this->maxLifetime);

return $blOut;
}

public function destroy($intSessionID){

memcached::delete(spritnf("sessions/sess_%s",$intSessionID));
memcached::delete(sprintf("sessions/sess_%s",$intSessionID));
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/twist/Core/Models/Settings.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function install($strPackage,$strGroup,$strKey,$mxdValue,$strTitle,$strDe
'type' => $strType,
'options' => $strOptions,
'null' => ($blNull) ? 1 : 0,
`deprecated` => 0
'deprecated' => 0
);
}else{

Expand All @@ -302,7 +302,7 @@ public function install($strPackage,$strGroup,$strKey,$mxdValue,$strTitle,$strDe
'type' => $strType,
'options' => $strOptions,
'null' => ($blNull) ? 1 : 0,
`deprecated` => 0
'deprecated' => 0
);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/twist/Core/Models/Tools.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function arrayParse( $strKey, $arrData, $strSplitChar = '/' ) {
* Remove an item from a multi-dimensional array using a key, the split char indicates a change in array level
*
* @param string $strKey
* @param string $arrData
* @param array $arrData
* @param string $strSplitChar
* @return array Returns either the original array or the array with the item removed
*/
Expand Down

0 comments on commit 63cd08e

Please sign in to comment.