Skip to content

Commit

Permalink
3.0 code rewritten
Browse files Browse the repository at this point in the history
  • Loading branch information
luanbu committed Feb 3, 2013
1 parent 38d59fc commit 9051f78
Show file tree
Hide file tree
Showing 27 changed files with 666 additions and 356 deletions.
11 changes: 6 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Jesse
Donate link: http://www.wordpressplugindeveloper.com/
Tags: autoblogging, zip, content, posts, post
Requires at least: 2.8.6
Tested up to: 3.2.1
Tested up to: 3.5.1
Stable tag: trunk

Upload zipped .txt files and insert them as wordpress posts
Expand Down Expand Up @@ -34,9 +34,10 @@ If you need a customized version, please <a href="http://www.wordpressplugindeve
= none =

== Upgrade Notice ==
= 2.0 =
2.0 version is lite version yet more reliable than original one. Don't upgrade it if you are satisfied with current version.
= 3.0 =
Code rewritten


== Changelog ==
= 2.0 =
lite version released.
= 3.0 =
Code rewritten
6 changes: 2 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TXT As Post

Import zipped txt files into wordpress.
Import zipped txt files into wordpress.

### Instruction

Expand All @@ -11,6 +11,4 @@ Import zipped txt files into wordpress.
* Done.

### Important Note
txtaspost.php is normal version.
txtaspost-post-tags-version.php is post tags version.
Only can one version activated.
Make sure your txt is saved as UTF-8 to support non-English language.
13 changes: 13 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/*
* Plugin Name: TXTAsPost
* Version: 3.0
* Plugin URI: http://www.wordpressplugindeveloper.com
* Description: Convert TXT into wordpress posts
* Author: Jesse
* Author URI: http://www.wordpressplugindeveloper.com
*/
require_once(dirname(__FILE__).'/txtaspost.php');
register_activation_hook(__FILE__, array(&$TXTAsPost, 'install'));
//register_deactivation_hook(__FILE__, array(&$TXTAsPost, 'uninstall'));
?>
78 changes: 40 additions & 38 deletions dUnzip2.inc.php → lib/dUnzip2.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,35 @@ class dUnzip2{
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;

// Private
var $fh;
var $zipSignature = "\x50\x4b\x03\x04"; // local file header signature
var $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature
var $dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir signature

// Public
Function dUnzip2($fileName){
$this->fileName = $fileName;
$this->compressedList =
$this->centralDirList =
$this->compressedList =
$this->centralDirList =
$this->endOfCentral = Array();
}

Function getList($stopOnFile=false){
if(sizeof($this->compressedList)){
$this->debugMsg(1, "Returning already loaded file list.");
return $this->compressedList;
}

// Open file, and set file handler
$fh = fopen($this->fileName, "r");
$this->fh = &$fh;
if(!$fh){
$this->debugMsg(2, "Failed to load file.");
return false;
}

$this->debugMsg(1, "Loading list from 'End of Central Dir' index list...");
if(!$this->_loadFileListByEOF($fh, $stopOnFile)){
$this->debugMsg(1, "Failed! Trying to load list looking for signatures...");
Expand All @@ -111,7 +111,7 @@ class dUnzip2{
return false;
}
}

if($this->debug){
#------- Debug compressedList
$kkk = 0;
Expand All @@ -133,7 +133,7 @@ class dUnzip2{
echo "</tr>";
}
echo "</table>";

#------- Debug centralDirList
$kkk = 0;
if(sizeof($this->centralDirList)){
Expand All @@ -156,7 +156,7 @@ class dUnzip2{
}
echo "</table>";
}

#------- Debug endOfCentral
$kkk = 0;
if(sizeof($this->endOfCentral)){
Expand All @@ -171,7 +171,7 @@ class dUnzip2{
echo "</table>";
}
}

return $this->compressedList;
}
Function getExtraInfo($compressedFileName){
Expand All @@ -185,13 +185,13 @@ class dUnzip2{
$this->endOfCentral[$detail]:
$this->endOfCentral;
}

Function unzip($compressedFileName, $targetFileName=false, $applyChmod=0777){
if(!sizeof($this->compressedList)){
$this->debugMsg(1, "Trying to unzip before loading file list... Loading it!");
$this->getList(false, $compressedFileName);
}

$fdetails = &$this->compressedList[$compressedFileName];
if(!isset($this->compressedList[$compressedFileName])){
$this->debugMsg(2, "File '<b>$compressedFileName</b>' is not compressed in the zip.");
Expand All @@ -207,8 +207,10 @@ class dUnzip2{
file_put_contents($targetFileName, ""):
"";
}

fseek($this->fh, $fdetails['contents-startOffset']);


$ret = $this->uncompress(
fread($this->fh, $fdetails['compressed_size']),
$fdetails['compression_method'],
Expand All @@ -217,21 +219,21 @@ class dUnzip2{
);
if($applyChmod && $targetFileName)
chmod($targetFileName, 0777);

return $ret;
}
Function unzipAll($targetDir=false, $baseDir="", $maintainStructure=true, $applyChmod=0777){
if($targetDir === false)
$targetDir = dirname(__FILE__)."/";

$lista = $this->getList();
if(sizeof($lista)) foreach($lista as $fileName=>$trash){
$dirname = dirname($fileName);
$outDN = "$targetDir/$dirname";

if(substr($dirname, 0, strlen($baseDir)) != $baseDir)
continue;

if(!is_dir($outDN) && $maintainStructure){
$str = "";
$folders = explode("/", $dirname);
Expand All @@ -247,21 +249,21 @@ class dUnzip2{
}
if(substr($fileName, -1, 1) == "/")
continue;

$maintainStructure?
$this->unzip($fileName, "$targetDir/$fileName", $applyChmod):
$this->unzip($fileName, "$targetDir/".basename($fileName), $applyChmod);
}
}

Function close(){ // Free the file resource
if($this->fh)
fclose($this->fh);
}
Function __destroy(){
Function __destroy(){
$this->close();
}

// Private (you should NOT call these methods):
Function uncompress($content, $mode, $uncompressedSize, $targetFileName=false){
switch($mode){
Expand Down Expand Up @@ -321,10 +323,10 @@ class dUnzip2{
// Check if there's a valid Central Dir signature.
// Let's consider a file comment smaller than 1024 characters...
// Actually, it length can be 65536.. But we're not going to support it.

for($x = 0; $x < 1024; $x++){
fseek($fh, -22-$x, SEEK_END);

$signature = fread($fh, 4);
if($signature == $this->dirSignatureE){
// If found EOF Central Dir
Expand All @@ -345,11 +347,11 @@ class dUnzip2{
'offset_start_cd'=>$eodir['offset_start_cd'][1],
'zipfile_comment'=>$eodir['zipfile_comment'],
);

// Then, load file list
fseek($fh, $this->endOfCentral['offset_start_cd']);
$signature = fread($fh, 4);

while($signature == $this->dirSignature){
$dir['version_madeby'] = unpack("v", fread($fh, 2)); // version made by
$dir['version_needed'] = unpack("v", fread($fh, 2)); // version needed to extract
Expand All @@ -370,8 +372,8 @@ class dUnzip2{
$dir['relative_offset'] = unpack("V", fread($fh, 4)); // relative offset of local header
$dir['file_name'] = fread($fh, $fileNameLength[1]); // filename
$dir['extra_field'] = $extraFieldLength[1] ?fread($fh, $extraFieldLength[1]) :''; // extra field
$dir['file_comment'] = $fileCommentLength[1]?fread($fh, $fileCommentLength[1]):''; // file comment
$dir['file_comment'] = $fileCommentLength[1]?fread($fh, $fileCommentLength[1]):''; // file comment

// Convert the date and time, from MS-DOS format to UNIX Timestamp
$BINlastmod_date = str_pad(decbin($dir['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
$BINlastmod_time = str_pad(decbin($dir['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
Expand All @@ -380,8 +382,8 @@ class dUnzip2{
$lastmod_dateD = bindec(substr($BINlastmod_date, 11, 5));
$lastmod_timeH = bindec(substr($BINlastmod_time, 0, 5));
$lastmod_timeM = bindec(substr($BINlastmod_time, 5, 6));
$lastmod_timeS = bindec(substr($BINlastmod_time, 11, 5));
$lastmod_timeS = bindec(substr($BINlastmod_time, 11, 5));

$this->centralDirList[$dir['file_name']] = Array(
'version_madeby'=>$dir['version_madeby'][1],
'version_needed'=>$dir['version_needed'][1],
Expand All @@ -405,7 +407,7 @@ class dUnzip2{
);
$signature = fread($fh, 4);
}

// If loaded centralDirs, then try to identify the offsetPosition of the compressed data.
if($this->centralDirList) foreach($this->centralDirList as $filename=>$details){
$i = $this->_getFileHeaderInformation($fh, $details['relative_offset']);
Expand All @@ -429,7 +431,7 @@ class dUnzip2{
}
Function _loadFileListBySignatures(&$fh, $stopOnFile=false){
fseek($fh, 0);

$return = false;
for(;;){
$details = $this->_getFileHeaderInformation($fh);
Expand All @@ -448,17 +450,17 @@ class dUnzip2{
if(strtolower($stopOnFile) == strtolower($filename))
break;
}

return $return;
}
Function _getFileHeaderInformation(&$fh, $startOffset=false){
if($startOffset !== false)
fseek($fh, $startOffset);

$signature = fread($fh, 4);
if($signature == $this->zipSignature){
# $this->debugMsg(1, "Zip Signature!");

// Get information about the zipped file
$file['version_needed'] = unpack("v", fread($fh, 2)); // version needed to extract
$file['general_bit_flag'] = unpack("v", fread($fh, 2)); // general purpose bit flag
Expand All @@ -473,10 +475,10 @@ class dUnzip2{
$file['file_name'] = fread($fh, $fileNameLength[1]); // filename
$file['extra_field'] = $extraFieldLength[1]?fread($fh, $extraFieldLength[1]):''; // extra field
$file['contents-startOffset']= ftell($fh);

// Bypass the whole compressed contents, and look for the next file
fseek($fh, $file['compressed_size'][1], SEEK_CUR);

// Convert the date and time, from MS-DOS format to UNIX Timestamp
$BINlastmod_date = str_pad(decbin($file['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
$BINlastmod_time = str_pad(decbin($file['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
Expand All @@ -486,7 +488,7 @@ class dUnzip2{
$lastmod_timeH = bindec(substr($BINlastmod_time, 0, 5));
$lastmod_timeM = bindec(substr($BINlastmod_time, 5, 6));
$lastmod_timeS = bindec(substr($BINlastmod_time, 11, 5));

// Mount file table
$i = Array(
'file_name' =>$file['file_name'],
Expand Down
Empty file added lib/index.php
Empty file.
13 changes: 13 additions & 0 deletions static/images/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/*
* Plugin Name: TXTAsPost
* Version: 0.1
* Plugin URI: http://www.wordpressplugindeveloper.com
* Description: Coded By http://www.wordpressplugindeveloper.com
* Author: Jesse
* Author URI: http://www.wordpressplugindeveloper.com
*/
require_once(dirname(__FILE__).'/txtaspost.php');
register_activation_hook(__FILE__, array(&$TXTAsPost, 'install'));
//register_deactivation_hook(__FILE__, array(&$TXTAsPost, 'uninstall'));
?>
Binary file added static/images/ui-bg_flat_0_aaaaaa_40x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-bg_flat_55_fbec88_40x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-bg_glass_75_d0e5f5_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-bg_glass_85_dfeffc_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-bg_glass_95_fef1ec_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-bg_inset-hard_100_f5f8f9_1x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-bg_inset-hard_100_fcfdfd_1x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_217bc0_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_2e83ff_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_469bdd_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_6da8d5_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_cd0a0a_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_d8e7f3_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ui-icons_f9bd01_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions static/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/*
* Plugin Name: TXTAsPost
* Version: 0.1
* Plugin URI: http://www.wordpressplugindeveloper.com
* Description: Coded By http://www.wordpressplugindeveloper.com
* Author: Jesse
* Author URI: http://www.wordpressplugindeveloper.com
*/
require_once(dirname(__FILE__).'/txtaspost.php');
register_activation_hook(__FILE__, array(&$TXTAsPost, 'install'));
//register_deactivation_hook(__FILE__, array(&$TXTAsPost, 'uninstall'));
?>
Loading

0 comments on commit 9051f78

Please sign in to comment.