Tengo este error que no me daba con versiones anteriores de wordpress. Mi versión es 3.4.1 y anteriormente usaba la 2.9.x
Fatal error: Cannot redeclare class dUnzip2 in /home/s025d5f1/public_html/xxxxxxxxxxxx/c/wp-content/plugins/txt-as-post/dUnzip2.inc.php on line 66
Cómo se puede hacer para evitar este redeclare fatal error. Me valen soluciones chapuceras :).
Gracias
Copio el código de los ficheros debajo:
Código PHP:
/////////////////////////////////////////////////////// dUnzip2.inc.php ///////////////////
if(!function_exists('file_put_contents')){
// If not PHP5, creates a compatible function
Function file_put_contents($file, $data){
if($tmp = fopen($file, "w")){
fwrite($tmp, $data);
fclose($tmp);
return true;
}
echo "<b>file_put_contents:</b> Cannot create file $file<br>";
return false;
}
}
class dUnzip2{
Function getVersion(){
return "2.6";
}
// Public
var $fileName;
var $compressedList; // You will problably use only this one!
var $centralDirList; // Central dir list... It's a kind of 'extra attributes' for a set of files
var $endOfCentral; // End of central dir, contains ZIP Comments
var $debug;
.....................................//cortado
...........................................//cortado
...........................................//cortado
...............................................//cortado
'compressed_size' =>$file['compressed_size'][1],
'uncompressed_size' =>$file['uncompressed_size'][1],
'extra_field' =>$file['extra_field'],
'general_bit_flag' =>str_pad(decbin($file['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT),
'contents-startOffset'=>$file['contents-startOffset']
);
return $i;
}
return false;
}
}
//////////////////////////////////////////////////////// txtaspost.php ///////////////
<?php
/*
* Plugin Name: TXTAsPost
* Version: 1.8
* Plugin URI: http://www.s101.net/txt-as-post/
* Description: Import .txt as post in bulk
* Author: Jesse
* Author URI: http://www.s101.net/txt-as-post/
*/
require(dirname(__FILE__) . "/dUnzip2.inc.php");
class TXTAsPost {
/*Simple log*/
var $log='';
/*time interval retrieving from user input*/
var $interval='';
/*category retrieving from user input*/
var $post_category='';
/*tags retrieving from user input or second line of txt*/
var $tags_input='';
/* 0 means default process, 1 means fetch second line as date,2 means fetch second line as tags */
var $option=0;
/*default post type is post*/
var $post_type='post';
var $notify=0;
function TXTAsPost(){
add_action('admin_menu', array(&$this,'txtaspost_menu_setup'));
add_action('admin_footer',array(&$this,'txtaspost_js'));
}
function txtaspost_menu_setup() {
add_options_page('TxtAsPost Settings', 'TXT As Post', 10, __FILE__, array(&$this,'txtaspost_menu'));
if (isset($_FILES["zip"])) {
check_admin_referer( 'txtaspost_update'); // nonce
if (is_uploaded_file($_FILES['zip']['tmp_name'])) {
$this->txtaspost_process();
}
}
}
function txtaspost_process() {
//I need much time xD
set_time_limit(0);
$zipfilename = $_FILES['zip']['tmp_name'];
$zip = &new dUnzip2($zipfilename);
$zip->debug = false;
$list = $zip->getList();
shuffle($list);
$this->interval=absint($_POST['timeInterval']);
$this->post_category= $this->process_category($_POST['category']);
$this->post_type= $_POST['post_type'];
if($_POST['version'] == 'date')
$this->option=1;
else if($_POST['version'] == 'tags')
$this->option=2;
$this->tags_input= $_POST['tags'];
$tm = ($_POST['when']=='Now')? time() : ( $this->getLatestTime() + $this->interval*3600 );
// echo $this->getLatestTime() + $this->interval;
//echo date("Y-m-d H:i:s", $this->getLatestTime() + $this->interval);exit;
foreach($list as $filename => $b) {
$content = $zip->unzip($b['file_name']);
// Process each article
if($id=$this->process_content($content,$tm)){
// time will be associated with the time of latest post
$tm += strtotime($id->post_date) + $this->interval*3600 + rand(0,60);
}
else{
$this->log .= "Duplicate post: $filename <br />";
}
}
$this->notify=1;
}
function process_content($content,$post_date){
........................//cortado
........................................//cortado .....................//cortado
..........................................//cortado .........................//cortado
.................................//cortado
) );
return $id;
}
function process_category($category){
$cats=explode(",",$category);
$cats_id=array();
foreach($cats as $cat){
if($cat){
if( 0 == get_cat_id($cat) ){
if(!function_exists('wp_create_category')) include_once(ABSPATH.'wp-admin/includes/taxonomy.php');
// 0 means default category, if wp_create_category fail, return 0. nice. xD
array_push($cats_id,wp_create_category($cat));
}else
array_push($cats_id,get_cat_id($cat));
}//who cares if cat name is empty?
}
return array_unique($cats_id);
}
function getLatestTime() {
global $wpdb;
$post = $wpdb->get_results( "SELECT post_date FROM $wpdb->posts ORDER BY post_date DESC limit 0,1" );
$tm=strtotime($post[0]->post_date);
// strtotime will return false if no post found
if(false == $tm)
$tm = time();
return $tm;
}
function txtaspost_menu() {
?>
<div class="wrap">
<?php
if( $this->notify ){
echo '<div id="message" class="updated fade"><p><a href="'. get_option("siteurl").'/wp-admin/edit.php">Edit post</a></p></div>';
}
?>
<h2>TXT As post</h2>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data">
<?php wp_nonce_field('txtaspost_update'); ?>
<input type="hidden" name="action" value="update" />
<p>
<input type="radio" value="default" name="version" onclick="hidden(this.value);" checked/> Default Version
<input type="radio" value="date" name="version" onclick="hidden(this.value);" /> Custom Date Version
<input type="radio" value="tags" name="version" onclick="hidden(this.value);" /> Custom Tags Version<br />
</p>
<p>Upload zip file that contains plain text(.txt format files) <br />Format<br /><span id="promt" style="color:red;">1st line:[title]<br />the rest:[content]<br /></span></p>
<p>Upload Zip: <input type="file" name="zip" /> Maximum file size <?php echo ini_get('upload_max_filesize');?></p>
<div id="customDate">
<p>Time Interval by hours:<input type="text" name="timeInterval" value="8"/></p>
<p>Published time<br />
<input type="radio" name="when" value="Next" checked>According to the time of latest post<br />
<input type="radio" name="when" value="Now" >From Now On<br />
</p>
<p>Hint: the post date will be current servert time, if no post found.</p>
</div>
<div id="customTags">
<p>
Tags(separated by comma):<input type="text" name="tags" id="tags" value=""/>
</p>
</div>
<p>Category/Categories to post(separated by comma):<input type="text" id="category" name="category" value=""/></p>
<p>Hint: Category will automatically added if not exists. </p>
<p>
Post type: <select id="post_type" name="post_type">
<option value="post" selected="selected">post</option>
<option value="page" >page</option>
</select>
</p>
<p><input type="submit" class="button" value="Upload" /></p>
Error log:<br/>
<div id="log" style="color:red;"><?php echo $this->log;?></div>
</form>
</div>
<?php
}
function txtaspost_js(){
?>
<script type='text/javascript'>
function hidden(value){
if(value == 'tags'){
document.getElementById('customDate').style.display='';
document.getElementById('customTags').style.display='none';
document.getElementById('promt').innerHTML='1st line:[title]\<br \/\>2nd line:tag a,tag b,tag c\<br \/\>the rest:[content]';
}else if(value == 'date'){
document.getElementById('customDate').style.display='none';
document.getElementById('customTags').style.display='';
document.getElementById('promt').innerHTML='1st line:[title]\<br \/\>2nd line:02/16/2009 8:53 am\<br \/\>the rest:[content]';
}else if(value == 'default'){
document.getElementById('customTags').style.display='';
document.getElementById('customDate').style.display='';
document.getElementById('promt').innerHTML='1st line:[title]\<br \/\>the rest:[content]';
}
}
</script>
<?php
}
}
$txtaspost = & new TXTAsPost();
?>