All pastes #1686237 Raw Edit

NucleusCMS in_array removal patc

public diff v1 · immutable
#1686237 ·published 2009-11-25 00:40 UTC
rendered paste body
Index: nucleus/convert/functions.inc.php===================================================================--- nucleus/convert/functions.inc.php	(revision 1425)+++ nucleus/convert/functions.inc.php	(working copy)@@ -785,13 +785,13 @@ 	}  	function _addAuthorName($name) {-		if (!in_array($name, $this->aAuthorNames))-			array_push($this->aAuthorNames, $name);+		$name_str = "$name";+		$this->aAuthorNames[$name_str] = $name_str; 	}  	function _addCategoryName($name) {-		if (!in_array($name, $this->aCategoryNames))-			array_push($this->aCategoryNames, $name);+		$name_str = "$name";+		$this->aCategoryNames[$name_str] = $name_str; 	}  	function sql_addToItem($title, $body, $more, $blogid, $authorid, $timestamp, $closed, $category, $karmapos, $karmaneg) {@@ -1006,4 +1006,4 @@ 	}  -?>\ No newline at end of file+?>Index: nucleus/convert/bloggercaif.php===================================================================--- nucleus/convert/bloggercaif.php	(revision 1425)+++ nucleus/convert/bloggercaif.php	(working copy)@@ -201,9 +201,8 @@ 			$row = $entry->getRow();  			// handle one item-			if (!in_array($row['author'],$authors))-				array_push($authors,$row['author']);-+			$author = "{$row['author']}";+			$authors[$author] = $author; 		}  		$blog->close();	// close the file@@ -553,4 +552,4 @@   -?>\ No newline at end of file+?>Index: nucleus/plugins/skinfiles/index.php===================================================================--- nucleus/plugins/skinfiles/index.php	(revision 1425)+++ nucleus/plugins/skinfiles/index.php	(working copy)@@ -150,29 +150,37 @@ 	 	echo "<h2>" . _SKINFILES_MANAGEMENT . "</h2>"; 	-	$actions = array (-		'renfile', 'renfile_process', 'delfile', 'delfile_process', -		'editfile', 'editfile_process', 'uploadfile', 'createfile', 'viewfile',-		'rendir', 'rendir_process', 'deldir', 'deldir_process',-		'emptydir', 'emptydir_process', 'createdir'-	);-	-	if (in_array($action, $actions)) +	switch($action) 	{ -		if (!$manager->checkTicket())-		{-			echo '<p class="error">Error: ' . _ERROR_BADTICKET . '</p>';+		case 'renfile':+		case 'renfile_process':+		case 'delfile':+		case 'delfile_process':+		case 'editfile':+		case 'editfile_process':+		case 'uploadfile':+		case 'createfile':+		case 'viewfile':+		case 'rendir':+		case 'rendir_process':+		case 'deldir':+		case 'deldir_process':+		case 'emptydir':+		case 'emptydir_process':+		case 'createdir':+			if (!$manager->checkTicket())+			{+				echo '<p class="error">Error: ' . _ERROR_BADTICKET . '</p>';+				sfShowDirectory();+			} +			else +			{+				call_user_func('_skinfiles_' . $action);+			}+			break;+		default 			sfShowDirectory();-			-		} -		else -		{-			call_user_func('_skinfiles_' . $action);-		}-	} -	else -	{-		sfShowDirectory();+			break; 	}  	$oPluginAdmin->end();Index: nucleus/libs/PAGEFACTORY.php===================================================================--- nucleus/libs/PAGEFACTORY.php	(revision 1425)+++ nucleus/libs/PAGEFACTORY.php	(working copy)@@ -81,10 +81,18 @@ 			'autosaveinfo', 			'ifautosave', 		);+	} +	function isAllowedType($type) { 		// TODO: maybe add 'skin' later on? 		// TODO: maybe add other pages from admin area-		$this->allowedTypes = Array('bookmarklet','admin');+		switch($type) {+			case 'bookmarklet':+			case 'admin':+				return true;+			default:+				return false;+		} 	}  	/**@@ -94,7 +102,7 @@ 	 *		'admin' or 'bookmarklet' 	 */ 	function createAddForm($type, $contents = array()) {-		if (!in_array($type, $this->allowedTypes))+		if(!$this->isAllowedType($type)) 			return; 		$this->type = $type; 		$this->method = 'add';@@ -116,7 +124,7 @@ 	 *			'' => 	 */ 	function createEditForm($type, $contents) {-		if (!in_array($type, $this->allowedTypes))+		if (!$this->isAllowedType($type)) 			return; 		$this->type = $type; 		$this->method = 'edit';@@ -438,4 +446,4 @@  } - ?>\ No newline at end of file+ ?>Index: nucleus/libs/showlist.php===================================================================--- nucleus/libs/showlist.php	(revision 1425)+++ nucleus/libs/showlist.php	(working copy)@@ -596,10 +596,20 @@ 					$friendlyNames = SKIN::getFriendlyNames(); 					for ($i=0;$i<sizeof($types);$i++) { 						$type = $types[$i];-						if (in_array($type, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup'))) {-							$types[$i] = '<li>' . helpHtml('skinpart'.$type) . ' <a href="index.php?action=skinedittype&amp;skinid='.$current->sdnumber.'&amp;type='.$type.'" tabindex="'.$template['tabindex'].'">' . htmlspecialchars($friendlyNames[$type]) . "</a></li>";-						} else {-							$types[$i] = '<li>' . helpHtml('skinpartspecial') . ' <a href="index.php?action=skinedittype&amp;skinid='.$current->sdnumber.'&amp;type='.$type.'" tabindex="'.$template['tabindex'].'">' . htmlspecialchars($friendlyNames[$type]) . "</a></li>";+						switch($type) {+							case 'index':+							case 'item':+							case 'archivelist':+							case 'archive':+							case 'search':+							case 'error':+							case 'member':+							case 'imagepopup':+								$types[$i] = '<li>' . helpHtml('skinpart'.$type) . ' <a href="index.php?action=skinedittype&amp;skinid='.$current->sdnumber.'&amp;type='.$type.'" tabindex="'.$template['tabindex'].'">' . htmlspecialchars($friendlyNames[$type]) . "</a></li>";+								break;+							default:+								$types[$i] = '<li>' . helpHtml('skinpartspecial') . ' <a href="index.php?action=skinedittype&amp;skinid='.$current->sdnumber.'&amp;type='.$type.'" tabindex="'.$template['tabindex'].'">' . htmlspecialchars($friendlyNames[$type]) . "</a></li>";+								break; 						} 					} 					echo '<br /><br />',_LIST_SKINS_DEFINED,' <ul>',implode($types,'') ,'</ul>';Index: nucleus/libs/globalfunctions.php===================================================================--- nucleus/libs/globalfunctions.php	(revision 1425)+++ nucleus/libs/globalfunctions.php	(working copy)@@ -778,18 +778,28 @@     global $imagepopup, $catid, $special;     global $manager; -    $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');     $action = requestVar('action'); -    if (in_array($action, $actionNames) ) {-        global $DIR_LIBS, $errormessage;-        include_once($DIR_LIBS . 'ACTION.php');-        $a = new ACTION();-        $errorInfo = $a->doAction($action);+    switch($action) {+        case 'addcomment':+        case 'sendmessage':+        case 'createaccount':+        case 'forgotpassword':+        case 'votepositive':+        case 'votenegative':+        case 'plugin':+            global $DIR_LIBS, $errormessage;+            include_once($DIR_LIBS . 'ACTION.php');+            $a = new ACTION();+            $errorInfo = $a->doAction($action); -        if ($errorInfo) {-            $errormessage = $errorInfo['message'];-        }+            if ($errorInfo) {+                $errormessage = $errorInfo['message'];+            }+            break;++        default:+            break;     }      // show error when headers already sent out@@ -1883,9 +1893,6 @@  */ function sanitizeArray(&$array) {-    $excludeListForSanitization = array('query');-//	$excludeListForSanitization = array();-     foreach ($array as $k => $v) {          // split to key and value@@ -1902,8 +1909,18 @@         $val = addslashes($val);          // if $key is included in exclude list, skip this param-        if (!in_array($key, $excludeListForSanitization)) {+        switch($key) {+            case 'query':+                $exclude = true;+                break; +            default:+                $exclude = false;+                break;+        }++        if (!$exclude) {+             // check value             if (strpos($val, '\\')) {                 list($val, $tmp) = explode('\\', $val);Index: nucleus/libs/xmlrpcs.inc.php===================================================================--- nucleus/libs/xmlrpcs.inc.php	(revision 1425)+++ nucleus/libs/xmlrpcs.inc.php	(working copy)@@ -900,13 +900,20 @@ 			// decompose incoming XML into request structure 			if ($req_encoding != '') 			{-				if (!in_array($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))+				//if (!in_array($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) 				// the following code might be better for mb_string enabled installs, but 				// makes the lib about 200% slower... 				//if (!is_valid_charset($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))+				switch($req_encoding) 				{-					error_log('XML-RPC: xmlrpc_server::parseRequest: invalid charset encoding of received request: '.$req_encoding);-					$req_encoding = $GLOBALS['xmlrpc_defencoding'];+					case 'UTF-8':+					case 'ISO-8859-1':+					case 'US-ASCII':+						break;+					default:+						error_log('XML-RPC: xmlrpc_server::parseRequest: invalid charset encoding of received request: '.$req_encoding);+						$req_encoding = $GLOBALS['xmlrpc_defencoding'];+						break; 				} 				/// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue, 				// the encoding is not UTF8 and there are non-ascii chars in the text...Index: nucleus/libs/xmlrpc.inc.php===================================================================--- nucleus/libs/xmlrpc.inc.php	(revision 1425)+++ nucleus/libs/xmlrpc.inc.php	(working copy)@@ -2515,13 +2515,20 @@  			// if response charset encoding is not known / supported, try to use 			// the default encoding and parse the xml anyway, but log a warning...-			if (!in_array($resp_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))+			//if (!in_array($resp_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) 			// the following code might be better for mb_string enabled installs, but 			// makes the lib about 200% slower... 			//if (!is_valid_charset($resp_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))+			switch($resp_encoding) 			{-				error_log('XML-RPC: xmlrpcmsg::parseResponse: invalid charset encoding of received response: '.$resp_encoding);-				$resp_encoding = $GLOBALS['xmlrpc_defencoding'];+				case 'UTF-8':+				case 'ISO-8859-1':+				case 'US-ASCII':+					break;+				default:+					error_log('XML-RPC: xmlrpcmsg::parseResponse: invalid charset encoding of received response: '.$resp_encoding);+					$resp_encoding = $GLOBALS['xmlrpc_defencoding'];+					break; 			} 			$parser = xml_parser_create($resp_encoding); 			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);Index: nucleus/libs/ADMIN.php===================================================================--- nucleus/libs/ADMIN.php	(revision 1425)+++ nucleus/libs/ADMIN.php	(working copy)@@ -35,7 +35,6 @@      * Class constructor      */     function ADMIN() {-     }      /**@@ -62,62 +61,68 @@         // check ticket. All actions need a ticket, unless they are considered to be safe (a safe action         // is an action that requires user interaction before something is actually done)         // all safe actions are in this array:-        $aActionsNotToCheck = array(-            'showlogin',-            'login',-            'overview',-            'itemlist',-            'blogcommentlist',-            'bookmarklet',-            'blogsettings',-            'banlist',-            'deleteblog',-            'editmembersettings',-            'browseownitems',-            'browseowncomments',-            'createitem',-            'itemedit',-            'itemmove',-            'categoryedit',-            'categorydelete',-            'manage',-            'actionlog',-            'settingsedit',-            'backupoverview',-            'pluginlist',-            'createnewlog',-            'usermanagement',-            'skinoverview',-            'templateoverview',-            'skinieoverview',-            'itemcommentlist',-            'commentedit',-            'commentdelete',-            'banlistnewfromitem',-            'banlistdelete',-            'itemdelete',-            'manageteam',-            'teamdelete',-            'banlistnew',-            'memberedit',-            'memberdelete',-            'pluginhelp',-            'pluginoptions',-            'plugindelete',-            'skinedittype',-            'skinremovetype',-            'skindelete',-            'skinedit',-            'templateedit',-            'templatedelete',-            'activate',-            'systemoverview'-        ); /*         // the rest of the actions needs to be checked         $aActionsToCheck = array('additem', 'itemupdate', 'itemmoveto', 'categoryupdate', 'categorydeleteconfirm', 'itemdeleteconfirm', 'commentdeleteconfirm', 'teamdeleteconfirm', 'memberdeleteconfirm', 'templatedeleteconfirm', 'skindeleteconfirm', 'banlistdeleteconfirm', 'plugindeleteconfirm', 'batchitem', 'batchcomment', 'batchmember', 'batchcategory', 'batchteam', 'regfile', 'commentupdate', 'banlistadd', 'changemembersettings', 'clearactionlog', 'settingsupdate', 'blogsettingsupdate', 'categorynew', 'teamchangeadmin', 'teamaddmember', 'memberadd', 'addnewlog', 'addnewlog2', 'backupcreate', 'backuprestore', 'pluginup', 'plugindown', 'pluginupdate', 'pluginadd', 'pluginoptionsupdate', 'skinupdate', 'skinclone', 'skineditgeneral', 'templateclone', 'templatenew', 'templateupdate', 'skinieimport', 'skinieexport', 'skiniedoimport', 'skinnew', 'deleteblogconfirm', 'activatesetpwd'); */-        if (!in_array($this->action, $aActionsNotToCheck))+        switch($this->action) {+            case 'showlogin':+            case 'login':+            case 'overview':+            case 'itemlist':+            case 'blogcommentlist':+            case 'bookmarklet':+            case 'blogsettings':+            case 'banlist':+            case 'deleteblog':+            case 'editmembersettings':+            case 'browseownitems':+            case 'browseowncomments':+            case 'createitem':+            case 'itemedit':+            case 'itemmove':+            case 'categoryedit':+            case 'categorydelete':+            case 'manage':+            case 'actionlog':+            case 'settingsedit':+            case 'backupoverview':+            case 'pluginlist':+            case 'createnewlog':+            case 'usermanagement':+            case 'skinoverview':+            case 'templateoverview':+            case 'skinieoverview':+            case 'itemcommentlist':+            case 'commentedit':+            case 'commentdelete':+            case 'banlistnewfromitem':+            case 'banlistdelete':+            case 'itemdelete':+            case 'manageteam':+            case 'teamdelete':+            case 'banlistnew':+            case 'memberedit':+            case 'memberdelete':+            case 'pluginhelp':+            case 'pluginoptions':+            case 'plugindelete':+            case 'skinedittype':+            case 'skinremovetype':+            case 'skindelete':+            case 'skinedit':+            case 'templateedit':+            case 'templatedelete':+            case 'activate':+            case 'systemoverview':+		$bCheckAction = false;+                break;+            default:+                $bCheckAction = true;+                break;+        }++        if ($bCheckAction)         {             if (!$manager->checkTicket())                 $this->error(_ERROR_BADTICKET);@@ -1202,15 +1207,40 @@         $blogid =  getBlogIDFromItemID($itemid);         $blog   =& $manager->getBlog($blogid); -        $wasdrafts = array('adddraft', 'addfuture', 'addnow');-        $wasdraft  = in_array($actiontype, $wasdrafts) ? 1 : 0;-        $publish   = ($actiontype != 'adddraft' && $actiontype != 'backtodrafts') ? 1 : 0;-        if ($actiontype == 'addfuture' || $actiontype == 'changedate') {-            $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year'));-        } else {-            $timestamp =0;+        switch($actiontype) {+            case 'adddraft':+            case 'addfuture':+            case 'addnow':+                $wasdraft = 1;+                break;++            default:+                $wasdraft = 0;+                break;         } +        switch($actiontype) {+            case 'adddraft':+            case 'backtodrafts':+                $publish = 1;+                break;++            default:+                $publish = 0;+                break;+        } ++        switch($actiontype) {+            case 'addfuture':+            case 'changedate':+                $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year'));+                break;++            default:+                $timestamp =0;+                break;+        }+         // edit the item for real         ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); @@ -4368,10 +4398,22 @@         <input type="submit" value="<?php echo _SKIN_UPDATE_BTN?>" onclick="return checkSubmit();" />         <input type="reset" value="<?php echo _SKIN_RESET_BTN?>" />         (skin type: <?php echo htmlspecialchars(isset($friendlyNames[$type]) ? $friendlyNames[$type] : ucfirst($type)); ?>)-        <?php if (in_array($type, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup'))) {-            help('skinpart' . $type);-        } else {-            help('skinpartspecial');+        <?php switch($type) {+            case 'index':+            case 'item':+            case 'archivelist':+            case 'archive':+            case 'search':+            case 'error':+            case 'member':+            case 'imagepopup':+                help('skinpart' . $type);+                break;++            default:+                help('skinpartspecial');+                break;+        }         }?>         <br /> @@ -4517,8 +4559,20 @@         $member->isAdmin() or $this->disallow();          // don't allow default skinparts to be deleted-        if (in_array($skintype, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup'))) {-            $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE);+        switch($skintype) {+            case 'index':+            case 'item':+            case 'archivelist':+            case 'archive':+            case 'search':+            case 'error':+            case 'member':+            case 'imagepopup':+                $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE);+                break;++            default:+                break;         }          $this->pagehead();@@ -4561,8 +4615,20 @@         $member->isAdmin() or $this->disallow();          // don't allow default skinparts to be deleted-        if (in_array($skintype, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup'))) {-            $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE);+        switch($skintype) {+            case 'index':+            case 'item':+            case 'archivelist':+            case 'archive':+            case 'search':+            case 'error':+            case 'member':+            case 'imagepopup':+                $this->error(_ERROR_SKIN_PARTS_SPECIAL_DELETE);+                break;++            default:+                break;         }          $manager->notify('PreDeleteSkinPart', array('skinid' => $skinid, 'skintype' => $skintype));@@ -6402,7 +6468,7 @@         $res = sql_query($query);         $aOptions = array();         while ($o = sql_fetch_object($res)) {-            if (in_array($o->oid, array_keys($aIdToValue)))+            if (isset($aIdToValue[$o->oid]))                 $value = $aIdToValue[$o->oid];             else                 $value = $o->odef;Index: nucleus/index.php===================================================================--- nucleus/index.php	(revision 1425)+++ nucleus/index.php	(working copy)@@ -49,7 +49,15 @@ 	}  	$bNeedsLogin = false;-	$bIsActivation = in_array($action, array('activate', 'activatesetpwd'));+	switch($action) {+		case 'activate':+		case 'activatesetpwd':+			$bIsActivation = true;+			break;+		default:+			$bIsActivation = false;+			break;+	}  	if ($action == 'logout') 		$bNeedsLogin = true;@@ -73,4 +81,4 @@  	$admin = new ADMIN(); 	$admin->action($action);-?>\ No newline at end of file+?>Index: nucleus/bookmarklet.php===================================================================--- nucleus/bookmarklet.php	(revision 1425)+++ nucleus/bookmarklet.php	(working copy)@@ -50,16 +50,22 @@  // check ticket $action = strtolower($action);-$aActionsNotToCheck = array('login', 'add', 'edit'); -if (!in_array($action, $aActionsNotToCheck) ) {+switch($action)+{+	case 'login':+	case 'add':+	case 'edit':+		// Do not check these actions.+		break;+	default:+		if (!$manager->checkTicket() ) {+			bm_doError(_ERROR_BADTICKET);+		}+		break;+} -	if (!$manager->checkTicket() ) {-		bm_doError(_ERROR_BADTICKET);-	} -}- // find out what to do switch ($action) { 	// adds the item for real