18 require_once SQ_CORE_PACKAGE_PATH.
'/files/file/file.inc';
19 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
41 public $allowed_extensions = Array(
'pdf');
52 parent::__construct($assetid);
66 if (empty($file_info))
return '';
67 $file = $file_info[
'path'];
69 $indexer_path = dirname(__FILE__).
'/files';
73 if (SQ_TOOL_PDFTOHTML_ENABLED) {
74 $pwd = $this->
attr(
'password');
75 $pwd = (empty($pwd)) ?
'' : $pwd =
' -opw '.$pwd.
' ';
78 $cmd = SQ_TOOL_PDFTOHTML_PATH.
" -i -nomerge -noframes -stdout $pwd $file";
79 $cmd = escapeshellcmd($cmd);
98 $process = proc_open($cmd, $spec, $pipes, $cwd, $env);
100 if (is_resource($process)) {
104 $content = stream_get_contents($pipes[1]);
108 $errors = stream_get_contents($pipes[2]);
109 if (!empty($errors)) {
110 $errors = array_unique(explode(PHP_EOL, $errors));
111 trigger_error(
'Error occured while getting contents for pdf File Asset #'.$this->
id.
' : '.trim(implode(
', ', $errors),
', '), E_USER_WARNING);
117 $status = proc_close($process);
121 if ($status !=
'0') {
124 $error_str =
'Invalid Argument.';
128 $error_str =
'Invalid Encoded Output.';
132 $error_str =
'Copying text from this Document is not allowed.';
136 $error_str =
'Error Opening File (e.g. corrupted file).';
140 $error_str =
'Unknown Error.';
144 trigger_error(
'Error occured while getting contents for pdf File Asset #'.$this->
id.
' : '.$error_str, E_USER_WARNING);
149 $file = str_replace(
'"',
'\\\"',$file);
150 if (empty($content))
return '';
153 $content = trim(strip_tags($content));
154 if (empty($content))
return '';
158 if (($this->status & SQ_SC_STATUS_SAFE_EDITING) && ($GLOBALS[
'SQ_SYSTEM']->user instanceof
Public_User)) {
160 $file = preg_replace(
'/,ffv\d+$/',
'', $file);
164 if (substr($file, -4) ==
'.pdf') {
165 $file = substr($file, 0, strlen($file)-4);
170 if (isset($content[0]) && $content[0] ==
'/') {
171 $content = substr($content, strlen($file));
175 $search = Array(
'/[\s,]+/',
'/\&[^;\s]+;/');
176 $replace = Array(
' ',
'');
178 $content = strtolower(trim(preg_replace($search, $replace, $content)));