Cats are too cute to modify


  • SockDev

    OK, this is from SMF. Currently it's https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Sources/ManageBoards.php#L780 but it will likely change position over time.

    Now, please bear in mind it is an easter egg, but to me it's still a CodeSOD.

    function ModifyCat()
    {
    	global $boards, $sourcedir, $smcFunc;
    
    	// Get some information about the boards and the cats.
    	require_once($sourcedir . '/Subs-Boards.php');
    	getBoardTree();
    
    	// Allowed sub-actions...
    	$allowed_sa = array('add', 'modify', 'cut');
    
    	// Check our input.
    	$_POST['id'] = empty($_POST['id']) ? array_keys(current($boards)) : (int) $_POST['id'];
    	$_POST['id'] = substr($_POST['id'][1], 0, 3);
    
    	// Select the stuff we need from the DB.
    	$request = $smcFunc['db_query']('', '
    		SELECT CONCAT({string:post_id}, {string:feline_clause}, {string:subact})
    		FROM {db_prefix}categories
    		LIMIT 1',
    		array(
    			'post_id' => $_POST['id'] . 's ar',
    			'feline_clause' => 'e,o ',
    			'subact' => $allowed_sa[2] . 'e, ',
    		)
    	);
    	list ($cat) = $smcFunc['db_fetch_row']($request);
    
    	// Free resources.
    	$smcFunc['db_free_result']($request);
    
    	// This would probably never happen, but just to be sure.
    	if ($cat .= $allowed_sa[1])
    		die(str_replace(',', ' to', $cat));
    
    	redirectexit();
    }
    

    Let me just talk you through what this is doing.

    1. Gets the current board tree (hierarchy of boards, sub-boards, whatever)
    2. Checks a mythical $_POST variable (which is nonsense, no form in the bowels of SMF actually points to the URL that goes to this code)
    3. If a POST is made with an id parameter, all kinds of WTF emerge where it tries to take a substring of an integer, if not it pulls something from the boards array - which amounts to finding the first element of the board listing, grabbing the first category and taking 'cat' from the 'category' sub-element of that array.
    4. Performs a query to fudge together a string.
    5. Performs a string mashup by doing an if on a concatenation (which naturally returns true since the result of $var .= $var2 is a true value provided either variable is non empty)
    6. Dies with the result string: 'cats are too cute to modify'.

    It's cute and all, but for an easter egg that performs multiple database queries to create this string. It's a WTF in my book, I don't know who else will agree 😈



  • This thread did not deliver on the promised cats. I was expecting image compression to be disabled for cats and some wonderful code to establish catness.


  • SockDev

    This thread did not promise cats.



  • Cats is right in the title! THAT IS AN OATH BOUND PROMISE!


  • SockDev

    No, the title merely assert('Cats are too cute to modify'). At no point does it promise cats.

    I give you cats however.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.