Ejemplo n.º 1
0
 function _addFavorites(&$man, $input)
 {
     $result = new Moxiecode_ResultSet("status,file,message");
     for ($i = 0; isset($input['path' . $i]); $i++) {
         $status = $this->addFavorite($man, $input["path" . $i]);
         if ($status) {
             $result->add("OK", $man->encryptPath($input["path" . $i]), "Path was added.");
         } else {
             $result->add("FAILED", $man->encryptPath($input["path" . $i]), "Path was not added.");
         }
     }
     return $result->toArray();
 }
Ejemplo n.º 2
0
 function _createDocs(&$man, &$input)
 {
     $result = new Moxiecode_ResultSet("status,fromfile,tofile,message");
     $config = $man->getConfig();
     if (!$man->isToolEnabled("createdoc", $config)) {
         trigger_error("{#error.no_access}", FATAL);
         die;
     }
     for ($i = 0; isset($input["frompath" . $i]) && isset($input["toname" . $i]); $i++) {
         $fromFile =& $man->getFile($input["frompath" . $i]);
         $ext = getFileExt($fromFile->getName());
         $toFile =& $man->getFile($input["topath" . $i], $input["toname" . $i] . '.' . $ext);
         $toConfig = $toFile->getConfig();
         if (checkBool($toConfig['general.demo'])) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.demo}");
             continue;
         }
         if ($man->verifyFile($toFile, "createdoc") < 0) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), $man->getInvalidFileMsg());
             continue;
         }
         if (!$toFile->canWrite()) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.no_write_access}");
             continue;
         }
         if (!checkBool($toConfig["filesystem.writable"])) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.no_write_access}");
             continue;
         }
         if (!$fromFile->exists()) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.template_missing}");
             continue;
         }
         if ($fromFile->copyTo($toFile)) {
             // Replace title
             $fields = $input["fields"];
             // Replace all fields
             if ($fields) {
                 // Read all data
                 $stream = $toFile->open('r');
                 $fileData = $stream->readToEnd();
                 $stream->close();
                 // Replace fields
                 foreach ($fields as $name => $value) {
                     $fileData = str_replace('${' . $name . '}', htmlentities($value), $fileData);
                 }
                 // Write file data
                 $stream = $toFile->open('w');
                 $stream->write($fileData);
                 $stream->close();
             }
             $result->add("OK", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#message.createdoc_success}");
         } else {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.createdoc_failed}");
         }
     }
     return $result->toArray();
 }
Ejemplo n.º 3
0
 /**
  * Simple keepalive function.
  */
 function _keepAlive(&$man, $input)
 {
     $result = new Moxiecode_ResultSet("status,time,message");
     $man->dispatchEvent("onKeepAlive");
     // Return status KEEPALIVE, current time on server and message.
     $result->add("KEEPALIVE", time(), "{#message.keepalive}");
     return $result->toArray();
 }
Ejemplo n.º 4
0
 /**
  * Lists file.
  */
 function _getMediaInfo(&$man, $input)
 {
     $file =& $man->getFile($input["path"]);
     $config = $file->getConfig();
     $parent =& $file->getParentFile();
     $files = array();
     if ($parent->isDirectory()) {
         // Setup file filter
         $fileFilter = new Moxiecode_BasicFileFilter();
         //$fileFilter->setDebugMode(true);
         $fileFilter->setIncludeDirectoryPattern($config['filesystem.include_directory_pattern']);
         $fileFilter->setExcludeDirectoryPattern($config['filesystem.exclude_directory_pattern']);
         $fileFilter->setIncludeFilePattern($config['filesystem.include_file_pattern']);
         $fileFilter->setExcludeFilePattern($config['filesystem.exclude_file_pattern']);
         $fileFilter->setIncludeExtensions($config['filesystem.extensions']);
         $fileFilter->setOnlyFiles(true);
         // List files
         $files =& $parent->listFilesFiltered($fileFilter);
     }
     $match = false;
     $prev = "";
     $next = "";
     foreach ($files as $curfile) {
         if ($curfile->getAbsolutePath() == $file->getAbsolutePath()) {
             $match = true;
             continue;
         } else {
             if (!$match) {
                 $prev = $curfile->getAbsolutePath();
             }
         }
         if ($match) {
             $next = $curfile->getAbsolutePath();
             break;
         }
     }
     $ext = getFileExt($file->getName());
     // Input default size?
     $width = "425";
     $height = "350";
     // All types that getimagesize support
     $imagearray = array('gif', 'jpg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'jpc', 'jp2', 'jpx', 'jb2', 'swc', 'iff', 'wbmp', 'xbm');
     if (in_array($ext, $imagearray)) {
         $sizeinfo = @getimagesize($file->getAbsolutePath());
         if ($sizeinfo) {
             $width = $sizeinfo[0];
             $height = $sizeinfo[1];
         }
     }
     $result = new Moxiecode_ResultSet("name,path,url,size,type,created,modified,width,height,attribs,next,prev,custom");
     $custom = array();
     $man->dispatchEvent("onCustomInfo", array(&$file, "info", &$custom));
     $attribs = ($file->canRead() && checkBool($config["filesystem.readable"]) ? "R" : "-") . ($file->canWrite() && checkBool($config["filesystem.writable"]) ? "W" : "-");
     $url = $man->removeTrailingSlash($config['preview.urlprefix']) . $man->convertPathToURI($file->getAbsolutePath());
     $result->add(utf8_encode($file->getName()), $man->encryptPath($file->getAbsolutePath()), utf8_encode($url), $file->getLength(), $ext, date($config['filesystem.datefmt'], $file->getCreationDate()), date($config['filesystem.datefmt'], $file->getLastModified()), $width, $height, $attribs, $man->encryptPath($next), $man->encryptPath($prev), $custom);
     return $result->toArray();
 }