'$errfile' 2>&1"); } } function PmDocConvert($opts) { global $FarmD, $UploadDir, $pagename, $PubCacheDir, $PubCacheUrl, $PmDocConvertPython, $PmDocConvertPgm, $PmDocConvertIWidth, $PmDocConvertIHeight, $PmDocConvertIBorder, $PmDocConvertIScroll, $PmDocConvertIAlign, $UploadUrlFmt, $PmDocConvertSpecial; SDV($PubCacheDir, "$FarmD/pub/cache"); SDV($PubCacheUrl, "$PubDirUrl/cache"); SDV($PmDocConvertPython, '/usr/bin/python'); SDV($PmDocConvertPgm, '/usr/local/bin/DC.py'); // For HTML inline iframe viewing // DocumentConverter.py will default to 640x480 images inside // a 800x600 space for OOo Impress and PowerPoint files. // SDV($PmDocConvertIWidth, '800'); SDV($PmDocConvertIHeight, '600'); SDV($PmDocConvertIBorder, 'default'); SDV($PmDocConvertIScroll, 'default'); SDV($PmDocConvertIAlign, 'default'); // http://labs.csg.stercomm.com/ProfilesCcox/TestPTV?action=upload&upname=hello.jpg // Determine this Group // $group = FmtPageName('$Group',$pagename); $name = FmtPageName('$Name',$pagename); // Process markup arguments first // $defaults = array( 'convertto'=>'', 'display'=>'link', 'headingrows'=>'1', 'iwidth'=>$PmDocConvertIWidth, 'iheight'=>$PmDocConvertIHeight, 'iborder'=>$PmDocConvertIBorder, 'iscroll'=>$PmDocConvertIScroll, 'ialign'=>$PmDocConvertIAlign, 'dcopts'=>'', 'htmlwidth'=>$PmDocConvertIWidth, 'htmlcolor'=>'none', 'imageformat'=>'1', 'file'=>'', 'filetype'=>'', 'forceconvert'=>false, 'linktext'=>'', 'quiet'=>false, 'showfilelink'=>false, 'showinlinelink'=>false, 'showicons'=>true ); $args = array_merge($defaults, ParseArgs($opts)); $upfile = $args['file']; $display = $args['display']; $upfiletype = $args['filetype']; $convertto = $args['convertto']; $forceconvert = $args['forceconvert']; $linktext = $args['linktext']; $showfilelink = $args['showfilelink']; $showicons = $args['showicons']; $headingrows = $args['headingrows']; $iwidth = $args['iwidth']; $iheight= $args['iheight']; $iborder= $args['iborder']; $iscroll = $args['iscroll']; $ialign = $args['ialign']; $quiet = $args['quiet']; $debug = $args['debug']; // Pull rest straight from args (FilterData opts) // Convert command separated list of rows that // will be csv inline headings to an array. $headingarray=explode(',',$headingrows); $out=''; if (!file_exists("$UploadDir/$group")) { mkdir("$UploadDir/$group"); } if (file_exists("$UploadDir/$group")) { $lastcwd=getcwd(); if (chdir("$UploadDir/$group")) { if (!$linktext) { $linktext=$upfile; } if (!$linkurl) { $linkurl="Attach:$group/$name/$upfile"; } if ($showfilelink == 'true') { $filelink="[[Attach:$group/$name/$upfile|$upfile]] "; } else { $filelink=''; } // Does the upload exist already? if (!file_exists("$upfile")) { // Must upload something to present it! // $out.="Please upload: [[$linkurl|$linktext]]"; } else { // Upload exists, convert if necessary and display it. // $upinfo=pathinfo($upfile); $upfileext=$upinfo['extension']; if (!$upfiletype) { // Try to figure out file type of upload. // Would love to get a file/magic value, but // php's support is varied and even so, magic // values vary from platform to platform as well. // // For now, the file extension determines the type. // $upfiletype=$upfileext; } if ($debug) echo "upfiletype=[$upfiletype] "; if (!$convertto) { switch ($upfiletype) { case 'xls': if ($display == 'inline') $convertto='csv'; else $convertto='pdf'; break; default: $convertto='pdf'; break; } } if ($debug) echo "convertto=[$convertto] "; // Handle an identity, no convert, case, for display only entities if ($convertto == $upfiletype) { $bupfile=basename($upfile, ".$upfileext"); $noconvert=1; } else { $bupfile=basename($upfile, ".$upfileext") . "-$upfileext"; } if ($debug) echo "bupfile=[$bupfile] "; // Normally, converted file is in the normal // upload group dir, but html conversion results // in many files and collision potential is // high. So create a sub-directory and assume // inline display. // $convertedfile="$bupfile.$convertto"; if ($convertto == 'html') { $display='inline'; $convertedfiledir="$convertedfile.dir"; $convertedfile="$convertedfiledir/$convertedfile"; if (!file_exists($convertedfiledir)) { mkdir($convertedfiledir); } if (!file_exists($convertedfiledir)) { $errout.='!! %red% PmDocConvert ERROR: Cannot create '.$convertedfiledir."\n"; $display='none'; $noconvert=1; } } if (!$noconvert) { // If the convertedfile exists, and the source uploaded file // is newer, then delete the convertedfile to force // new conversion. // // Note: right now, the directory for html conversion is NOT // cleaned up. // if (file_exists("$convertedfile")) { if ($debug) echo "EXISTS "; if ($forceconvert || filectime("$upfile") > filectime("$convertedfile")) { if ($debug) echo "NEWER "; unlink("$convertedfile"); $noconvert=0; } else { $noconvert=1; } } $linkurl="Attach:$group/$name/$convertedfile"; $linktext="$convertedfile"; } if (!$noconvert) { if ($debug) echo "CONVERTING "; // Why all of this? Well.. I was thinking that things // might vary at some point and even include other kinds // of converters besides DocumentConverter.py. // switch ($convertto) { case 'pdf': PmDocConvertFile($upfile, "$convertedfile", "$bupfile.err", $args); break; case 'csv': PmDocConvertFile($upfile, "$convertedfile", "$bupfile.err", $args); break; default: if ($convertto) { PmDocConvertFile($upfile, "$convertedfile", "$bupfile.err", $args); } } } if (!$noconvert && !file_exists("$convertedfile") && file_exists("$bupfile.err")) { $fp=fopen("$bupfile.err", 'r'); $errout.='!! %red% PmDocConvert ERROR: '.fread($fp,1000)."\n"; $display='none'; } if ($debug) echo "filelink=[$filelink] linkurl=[$linkurl] linktext=[$linktext]]n"; switch ($display) { case 'imagelink': $out.="$filelink"."[[Attach:$group/$name/$upfile|$linkurl]]"; break; case 'link': $out.="$filelink"."[[$linkurl|$linktext]]"; break; case 'attach': $out.="$filelink"."$linkurl"; break; case 'inline': switch ($convertto) { case 'csv': if ($showfilelink == 'true') { $out.="$filelink\n"; } $out.=PmDocConvertInlineCsv($convertedfile, $headingarray); break; // wiki means MediaWiki format.. so not really a nice // way for inline PmWiki viewing... might add a convert // here to convert MediaWiki to PmWiki... for now... // it's text. // case 'wiki': case 'txt': if ($showfilelink == 'true') { $out.="$filelink\n"; } $out.=PmDocConvertInlineTxt($convertedfile); break; case 'html': if ($showfilelink == 'true') { $out.="$filelink\n"; } $out.="\n\n"; break; default: $out.="$filelink"."$linkurl"; break; } break; } } } chdir($lastcwd); } if ($quiet == 'true') $out=''; PRR(); return $errout."\n".$out; } ?>