Support » Plugins and Hacks » [Plugin: Upload ] WP 2.6

  • To get around the unserialize issues after WP2.6 upgrade, I stripped out the unserialize calls and used direct assignment. Works for me as far as I can tell!

    // Instead of $y
    	$x = get_option('uploadplus_style');
    	//$x = unserialize($y);
            // Instead of using array index
    	if($x == 1){ $flag1 = 'checked="checked"'; }

    There are a few other changes to make in various case statements (check $x not $x[0] etc)…

Viewing 13 replies - 1 through 13 (of 13 total)
  • can you post your modified version somewhere? It seems the developer hasn’t noticed this post and I kind of rely on this plugin 🙁

    is it just a matter of changing the code you provided above?

    any news? maybe from the developer?

    No news…

    Here’s a dump of uploadplus.php

    Plugin Name: Upload+
    Plugin URI:
    Description: Security and sanity in file names while uploading. Once activate, please <a href="options-general.php?page=uploadplus">define your settings</a>.
    Author: Pixline
    Version: 2.5.1.x Patched for 2.6
    Author URI:
    Copyright (C) 2007/2008 Paolo Tresso / Pixline (
    Includes hints and code by:
    	Francesco Terenzani (
    	Jennifer Hodgdon (
    Uses UTF8 PHP classes by
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    require_once 'utf8/utf8.php';
    require_once 'utf8/str_ireplace.php';
    require_once UTF8 . '/utils/validation.php';
    require_once UTF8 . '/utils/ascii.php';
    require_once 'utf8_to_ascii/utf8_to_ascii.php';
    $version = get_option('uploadplus_version');
    if ($version == '') $version = 0;
    if ($version < 3) {
    	add_option('uploadplus_style','a:1:{i:0;s:1:"1";}','Choose what style will be used','yes');
    	add_option('uploadplus_lettercase','a:1:{i:0;s:1:"1";}','Make all lowercase','yes');
    	update_option('uploadplus_version', 3);
    /* add option page */
    function upp_add_mangle_options_page(){
    		add_options_page('Upload+ Options','Upload+',8,'uploadplus','upp_mangle_options_page');
    /* the real option page */
    function upp_mangle_options_page(){
    global $wp_db_version;
    	if (isset($_POST['info_update'])) {
    		$style = serialize($_POST['uploadplus_style']);
    		$lettercase = serialize($_POST['uploadplus_lettercase']);
    		if( !empty($_POST['uploadplus_prefix_custom']) && $_POST['uploadplus_prefix']=='none' ){
    		echo('<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>');
    	$flag1 = ""; $flag2 = $flag1; $flag3 = $flag1; $flag4 = $flag1; $flag5 = $flag1;
    	$x = get_option('uploadplus_style');
    	//$x = unserialize($y);
    	if($x == 1){ $flag1 = 'checked="checked"'; }
    	if($x == 2){ $flag2 = 'checked="checked"'; }
    	if($x == 3){ $flag3 = 'checked="checked"'; }
    	$new_lettercase = get_option('uploadplus_lettercase');
    	//$new_lettercase = unserialize($opt_lettercase);
    	if($new_lettercase == 1){ $flag4='checked="checked"'; }else{ $flag5='checked="checked"'; }
    	$custom		= get_option('uploadplus_prefix_custom');
    	$standard	= get_option('uploadplus_prefix_standard');
    	$pref_custom = "";
    	$prefs = array("none"=>"","md"=>"","ymd"=>"","ymdhi"=>"","ymdhis"=>"","random"=>"","unix"=>"");
    		$pref_custom = $custom;
    		$prefs[$standard] = "selected='selected'";
    	$test_string1 = "WordPress Manual (for dummies, experts and pro's) 2.2nd Edition.pdf";
    #	$test_string1 = 'У беларускіх гарадах працягваецца паказ культавага швэдзкага кіно.pdf';
    #	$test_string3 = 'اذاعة شباب اف ام.pdf';
    	$demo_string1 = upp_mangle_filename($test_string1);
    #	$demo_string2 = upp_mangle_filename($test_string2);
    #	$demo_string3 = upp_mangle_filename($test_string3);
    	echo("<div class='wrap'>");
    	echo("<form method='post' accept-charset='utf-8'>");
    	echo("<h2>Upload+ Options</h2>");
    	echo("<p>Welcome to Upload+. This plugin allows you to rename every file you upload, and in this page you can define this behaviour.</p>");
    	echo("<p> According to your actual ruleset, your files will be renamed like this:<br />
    	<li> <em>".$test_string1."</em><br /> saved as &rsaquo; <strong>".$demo_string1."</strong></li>
    	<!-- li> <em>".$test_string2."</em><br /> saved as &rsaquo; <strong>".$demo_string2."</strong></li>
    	<li> <em>".$test_string3."</em><br /> saved as &rsaquo; <strong>".$demo_string3."</strong></li -->
    	echo("<p><small>You can choose to <em>convert spaces and underscores into dashes</em>, <em>strip all dashes/underscores/spaces</em>, or <em>convert every spaces into an underscore</em>. Also, you can choose to <em>lowercase</em> the file name or leave it with mixed case, and finally you can define a custom prefix to prepend, either a fixed one (like the name of your blog) or a date-based one. Feel free to play with the settings and save them, because you can check in this page what kind of transformation will be applied.</small></p>");
    	if($wp_db_version < 6846) $tableclass = "editform optiontable"; else $tableclass = "form-table";
    	echo('<fieldset class="options" name="set1">
    	<legend>Cleaning rules</legend>
    	<table class="'.$tableclass.'">
    	<th scope="row" valign="top">Basic cleaning</th>
    	<p><input type="radio" name="uploadplus_style[]" id="uploadplus_style-1" value="1" '.$flag1.'/>
    	<label for="uploadplus_style-1">Convert spaces and underscores into dashes.
    	<small>[ &rsaquo; <em>wordpress-manual.pdf</em> ]</small></label></p>
    	<p><input type="radio" name="uploadplus_style[]" id="uploadplus_style-2" value="2" '.$flag2.'/>
    	<label for="uploadplus_style-2">Strip all spaces/dashes/underscores.
    	<small>[ &rsaquo; <em>wordpressmanual.pdf</em> ]</small></label></p>
    	<p><input type="radio" name="uploadplus_style[]" id="uploadplus_style-3" value="3" '.$flag3.'/>
    	<label for="uploadplus_style-3">Convert spaces into underscores (dashes allowed).
    	<small>[ &rsaquo; <em>wordpress_manual.pdf</em> ]</small></label></p>
    	<th scope="row" valign="top">Lowercase</th>
    	<input type="radio" name="uploadplus_lettercase[]" id="uploadplus_lettercase-1" value="1" '.$flag4.'/>
    	Make ALL lowercase.
    	<input type="radio" name="uploadplus_lettercase[]" id="uploadplus_lettercase-0" value="0" '.$flag5.'/>
    	Leave untouched.
    echo('<fieldset class="options" name="set1">
    	<table class="'.$tableclass.'">
    	<th scope="row" valign="top">Prefix</th>
    	<select name="uploadplus_prefix" id="uploadplus_prefix">
    	<option value="none" label="No prefix, or custom prefix">No prefix, or custom prefix</option>
    	<optgroup label="Human Readable">
    	<option value="d" label="dd (like: '.date('d').'_)" '.$prefs['d'].'>d (like: '.date('d').'_)</option>
    	<option value="md" label="mmdd (like: '.date('md').'_)" '.$prefs['md'].'>mmdd (like: '.date('md').'_)</option>
    	<option value="ymd" label="yyyymmdd (like: '.date('Ymd').'_)" '.$prefs['ymd'].'>yyyymmdd (like: '.date('Ymd').'_)</option>
    	<option value="ymdhi" label="yyyymmddhhmm (like: '.date('YmdHi').'_)" '.$prefs['ymdhi'].'>yyyymmddhhmm (like: '.date('YmdHi').'_)</option>
    	<option value="ymdhis" label="yyyymmddhhmmss (like: '.date('YmdHis').'_)" '.$prefs['ymdhis'].'>yyyymmddhhmmss (like: '.date('YmdHis').'_)</option>
    	<optgroup label="Other Styles">
    	<option value="random" label="[random (mt-rand)] '.mt_rand().'_" '.$prefs['random'].'>[random] '.mt_rand().'_</option>
    	<option value="unix" label="[unix timestamp] '.date('U').'_" '.$prefs['unix'].'>[unix] '.date('U').'_</option>
    	<!-- option value="blog" label="[blog name] '.strtolower(get_bloginfo('name')).'_" '.$prefs['blog'].'>[blog] '.strtolower(get_bloginfo('name')).'_</option -->
    	<input type="text" name="uploadplus_prefix_custom" size="50" id="uploadplus_prefix_custom" value="'.$pref_custom.'"/><br />
    	<small>Enter your custom textual prefix (like "prefix_"). Please note this is a *string*, so please do not use php <em>date()</em> arguments :-)</a>.</small>
    	echo('<p class="submit">
    	<input type="hidden" name="action" value="update" />
    	<input type="submit" name="info_update" value="Update Settings &raquo;" />
    	echo('<hr/> <p><small><a href="">Upload+</a> is GPL&copy; <a href="">Paolo Tresso / Pixline</a>. UTF8 php classes and translitteration by <a href="">phputf8</a>.<br /> If you find this plugin useful you can donate and support its development. Thank you!
    <form action="" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="image" src="" border="0" name="submit" alt="Support via PayPal">
    <img alt="" border="0" src="" width="1" height="1">
    /* find extension */
    function upp_findexts ($filename) {
    	$exts = split("[/\\.]", $filename) ;
    	$n = count($exts)-1;
    	$exts = $exts[$n];
    	return $exts;
    /* find full filename */
    function upp_find_filename ($filename) {
    	$explode = explode("/",$filename);
    	$explode = array_reverse($explode);
    	return $explode[0];
    /*    sanitize uploaded file name    */
    function upp_mangle_filename($file_name){
    	/* remove internal dots (cosmetical, it would be done by WP, but we need to display it :)*/
    	$ext = upp_findexts($file_name);
    	$file_name = str_replace(".".$ext,"",$file_name);
    	$file_name = str_replace(".","",$file_name);
    	// initial cleaning
    	$file_name = str_replace("(","",$file_name);
    	$file_name = str_replace(")","",$file_name);
    	$file_name = str_replace("'","",$file_name);
    	$file_name = str_replace('"',"",$file_name);
    	$file_name = str_replace(',',"",$file_name);
    	// some language-based prefilter. props denis.
    	$de_from 	= array('ä','ö','ü','ß','Ä','Ö','Ü');
    	$de_to 		= array('ae','oe','ue','ss','Ae','Oe','Ue');
    	$file_name	= str_replace($de_from, $de_to, $file_name);
    	if ( utf8_is_valid($file_name) ) {
            $file_name = utf8_to_ascii($file_name);
            $file_name = utf8_to_ascii($file_name);
    	$file_name = $file_name.".".$ext;
    	$un_lettercase = get_option('uploadplus_lettercase');
    	//$un_lettercase = unserialize($lettercase);
    		case "1":
    			$file_name = utf8_strtolower($file_name);
    	$x = get_option('uploadplus_style');
    	//$x = unserialize($y);
    	case "1":
    		$file_name = ereg_replace("[^A-Za-z0-9._]", "-", $file_name);
    		$file_name = utf8_ireplace("_", "-", $file_name);
    		$file_name = utf8_ireplace(" ", "-", $file_name);
    		$file_name = utf8_ireplace("%20", "-", $file_name);
    	case "2":
    		$file_name = ereg_replace("[^A-Za-z0-9._]", "", $file_name);
    		$file_name = utf8_ireplace("_", "", $file_name);
    		$file_name = utf8_ireplace("-", "", $file_name);
    		$file_name = utf8_ireplace("%20", "", $file_name);
    	case "3":
    		$file_name = ereg_replace("[^A-Za-z0-9._]", "_", $file_name);
    		$file_name = utf8_ireplace("-", "_", $file_name);
    		$file_name = utf8_ireplace(" ", "_", $file_name);
    		$file_name = utf8_ireplace("%20", "_", $file_name);
    	$custom = get_option('uploadplus_prefix_custom');
    	$standard = get_option('uploadplus_prefix_standard');
    	if($custom!="" && $standard=="none"){
    		$file_name = $custom.$file_name;
    			case "d":		$file_name = date('d')."_".$file_name;			break;
    			case "md":		$file_name = date('md')."_".$file_name;			break;
    			case "ymd":		$file_name = date('Ymd')."_".$file_name;		break;
    			case "ymdhi":	$file_name = date('YmdHi')."_".$file_name;		break;
    			case "ymdhis":	$file_name = date('YmdHis')."_".$file_name;		break;
    			case "random":	$file_name = mt_rand()."_".$file_name;			break;
    			case "unix":	$file_name = date('U')."_".$file_name;			break;
    #			case "blog":	$file_name = strtolower(get_bloginfo('name'))."_".$file_name;	break;
    	return $file_name;
    /* apply out changes to the real file while it's being moved to its destination */
    // $array( 'file' => $new_file, 'url' => $url, 'type' => $type );
    function upp_rename($array){
    global $action;
    	$current_name = upp_find_filename($array['file']);
    	$current_name = urldecode($current_name);
    	$new_name = upp_mangle_filename($current_name);
    	$lpath = str_replace($current_name, "", urldecode($array['file']));
    	$wpath = str_replace($current_name, "", urldecode($array['url']));
    	$lpath_new = $lpath . $new_name;
    	$wpath_new = $wpath . $new_name;
    	if( @rename($array['file'], $lpath_new) )
    	return array(
    		'file' => $lpath_new,
    		'url' => $wpath_new,
    		'type' => $array['type']
    	return $array;
    add_action( 'admin_menu', 'upp_add_mangle_options_page' );	// add option page
    add_action('wp_handle_upload', 'upp_rename');				// apply our modifications

    thx a lot, worked beautiful.

    I am in contact with the developer, but he said he has no time to update his plugin, so I’ll send him a link to this thread 🙂

    I have to correct myself, it seems the settings do not get saved 🙁 but no errors anymore.

    can you actually save your settings? i.e. I set it to make all file names into lowercase, save, it says successful, but the settings still remain on default 🙁

    Hey, yes I can save my settings.
    I have it set to:
    spaces as underscores, prepend YYMMDD_, lowercase

    I set it to:
    spaces to underscores,
    all lowercase

    and it doesn’t save…

    any hints on what I could try to do to debug?

    oh, and I tried this on a wp 2.6.3 blog and on a wpmu 2.6.2 installation, both don’t save the values I set.

    besides, with older wp and wpmu versions the plugins used to work flawlessly.

    I’m really sorry for disappearing, several personal and work issues on top of each others. There’s a major API change in WordPress 2.7, by the way, so this is another plugin that needs a partial rewrite.

    I’ll try to have a look at this and other plugins as soon as I have 5 free minutes, this is the simplest one so I hope it will be easy to fix.

    Thank you for caring

    I’ve just committed a somewhat working version for 2.7. Hope it works for you.



    somewhat. unfortunately wpmu doesn’t have the options menu where you moved the settings to 🙁 this was a great plugin for wpmu, keeping uploads in a certain format…

    btw. I am also interested how I can change the plugin’s defaults 🙂

    just replaced all occurances of ‘misc’ with ‘media’ and now I have these settings under => options => media where I think they fit in well, working with wpmu 2.7.1

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: Upload ] WP 2.6’ is closed to new replies.