| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class AkXdocToText |
|---|
| 20 |
{ |
|---|
| 21 |
public function convert() |
|---|
| 22 |
{ |
|---|
| 23 |
$xdoc2txt_bin = AK_VENDOR_DIR.DS.'hyperestraier'.DS.'xdoc2txt.exe'; |
|---|
| 24 |
|
|---|
| 25 |
if(AK_OS != 'WINDOWS'){ |
|---|
| 26 |
trigger_error(Ak::t('Xdoc2Text is a windows only application. Please use wvWare instead'), E_USER_WARNING); |
|---|
| 27 |
return false; |
|---|
| 28 |
} |
|---|
| 29 |
if(!file_exists($xdoc2txt_bin)){ |
|---|
| 30 |
trigger_error(Ak::t('Could not find xdoc2txt.exe on %path. Please download it from http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html',array('%path'=>$xdoc2txt_bin)),E_USER_WARNING); |
|---|
| 31 |
return false; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
exec('@"'.$xdoc2txt_bin . '" -f "' . $this->source_file . '" "' . $this->destination_file.'"'); |
|---|
| 35 |
|
|---|
| 36 |
$result = Ak::file_get_contents($this->destination_file); |
|---|
| 37 |
$this->delete_source_file ? @Ak::file_delete($this->source_file) : null; |
|---|
| 38 |
$this->keep_destination_file ? null : Ak::file_delete($this->destination_file); |
|---|
| 39 |
|
|---|
| 40 |
return $result; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
public function init() |
|---|
| 44 |
{ |
|---|
| 45 |
$this->ext = empty($this->ext) ? 'doc' : strtolower(trim($this->ext,'.')); |
|---|
| 46 |
$this->tmp_name = Ak::randomString(); |
|---|
| 47 |
if(empty($this->source_file)){ |
|---|
| 48 |
$this->source_file = AK_TMP_DIR.DS.$this->tmp_name.'.'.$this->ext; |
|---|
| 49 |
Ak::file_put_contents($this->source_file,$this->source); |
|---|
| 50 |
$this->delete_source_file = true; |
|---|
| 51 |
$this->keep_destination_file = empty($this->keep_destination_file) ? (empty($this->destination_file) ? false : true) : $this->keep_destination_file; |
|---|
| 52 |
}else{ |
|---|
| 53 |
$this->delete_source_file = false; |
|---|
| 54 |
$this->keep_destination_file = true; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
$this->convert_to = 'txt'; |
|---|
| 58 |
$this->destination_file_name = empty($this->destination_file_name) ? $this->tmp_name.'.'.$this->convert_to : $this->destination_file_name.(strstr($this->destination_file_name,'.') ? '' : '.'.$this->convert_to); |
|---|
| 59 |
$this->destination_file = empty($this->destination_file) ? AK_TMP_DIR.DS.$this->destination_file_name : $this->destination_file; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
?> |
|---|
| 65 |
|
|---|