public function getDetailPage()
 {
     global $_ARRAYLANG, $objDatabase;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $file = str_replace($cx->getWebsiteOffsetPath(), '', $_GET["path"]) . $_GET["file"];
     $objResult = $objDatabase->Execute("SELECT `id`, `file`, `source`, `hash`, `check`, `expiration_date` FROM " . DBPREFIX . "module_filesharing WHERE `source` = '" . contrexx_raw2db($file) . "'");
     $existing = $objResult !== false && $objResult->RecordCount() > 0;
     if ($_GET["switch"]) {
         if ($existing) {
             $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_filesharing WHERE `source` = '" . contrexx_raw2db($file) . "'");
         } else {
             $hash = FileSharingLib::createHash();
             $check = FileSharingLib::createCheck($hash);
             $source = str_replace($cx->getWebsiteOffsetPath(), '', $_GET["path"]) . $_GET["file"];
             $objDatabase->Execute("INSERT INTO " . DBPREFIX . "module_filesharing (`file`, `source`, `hash`, `check`) VALUES ('" . contrexx_raw2db($source) . "', '" . contrexx_raw2db($source) . "', '" . contrexx_raw2db($hash) . "', '" . contrexx_raw2db($check) . "')");
         }
         $existing = !$existing;
     }
     if ($existing) {
         $this->_objTpl->setVariable(array('FILE_STATUS' => $_ARRAYLANG["TXT_FILESHARING_SHARED"], 'FILE_STATUS_SWITCH' => $_ARRAYLANG["TXT_FILESHARING_STOP_SHARING"], 'FILE_STATUS_SWITCH_HREF' => 'index.php?cmd=Media&archive=FileSharing&act=filesharing&path=' . $_GET["path"] . '&file=' . $_GET["file"] . '&switch=1'));
         $this->_objTpl->touchBlock('shared');
     } else {
         $this->_objTpl->setVariable(array('FILE_STATUS' => $_ARRAYLANG["TXT_FILESHARING_NOT_SHARED"], 'FILE_STATUS_SWITCH' => $_ARRAYLANG["TXT_FILESHARING_START_SHARING"], 'FILE_STATUS_SWITCH_HREF' => 'index.php?cmd=Media&archive=FileSharing&act=filesharing&path=' . $_GET["path"] . '&file=' . $_GET["file"] . '&switch=1'));
         $this->_objTpl->hideBlock('shared');
     }
     if ($_POST["shareFiles"]) {
         $emails = array();
         foreach (preg_split('/[;,\\s]+/', $_POST["email"]) as $email) {
             if (\FWValidator::isEmail($email)) {
                 $emails[] = contrexx_input2raw($email);
             }
         }
         if (count($emails) > 0) {
             FileSharingLib::sendMail($objResult->fields["id"], $_POST["subject"], $emails, $_POST["message"]);
         }
     } elseif ($_POST["saveExpiration"]) {
         if ($_POST["expiration"]) {
             $objDatabase->Execute("UPDATE " . DBPREFIX . "module_filesharing SET `expiration_date` = NULL WHERE `id` = " . $objResult->fields["id"]);
         } else {
             $objDatabase->Execute("UPDATE " . DBPREFIX . "module_filesharing SET `expiration_date` = '" . date('Y-m-d H:i:s', strtotime($_POST["expirationDate"])) . "' WHERE `id` = " . $objResult->fields["id"]);
         }
     }
     $objResult = $objDatabase->Execute("SELECT `id`, `hash`, `check`, `expiration_date` FROM " . DBPREFIX . "module_filesharing WHERE `source` = '" . contrexx_raw2db($file) . "'");
     $this->_objTpl->setVariable(array('FORM_ACTION' => 'index.php?cmd=Media&archive=FileSharing&act=filesharing&path=' . $_GET["path"] . '&file=' . $_GET["file"], 'FORM_METHOD' => 'POST', 'FILESHARING_INFO' => $_ARRAYLANG['TXT_FILESHARING_INFO'], 'FILESHARING_LINK_BACK_HREF' => 'index.php?cmd=Media&archive=FileSharing&path=' . $_GET["path"], 'FILESHARING_LINK_BACK' => $_ARRAYLANG['TXT_FILESHARING_LINK_BACK'], 'FILESHARING_DOWNLOAD_LINK' => $_ARRAYLANG['TXT_FILESHARING_DOWNLOAD_LINK'], 'FILE_DOWNLOAD_LINK_HREF' => FileSharingLib::getDownloadLink($objResult->fields["id"]), 'FILE_DELETE_LINK_HREF' => FileSharingLib::getDeleteLink($objResult->fields["id"]), 'FILESHARING_DELETE_LINK' => $_ARRAYLANG['TXT_FILESHARING_DELETE_LINK'], 'FILESHARING_STATUS' => $_ARRAYLANG['TXT_FILESHARING_STATUS'], 'FILESHARING_EXPIRATION' => $_ARRAYLANG['TXT_FILESHARING_EXPIRATION'], 'FILESHARING_NEVER' => $_ARRAYLANG['TXT_FILESHARING_NEVER'], 'FILESHARING_EXPIRATION_CHECKED' => htmlentities($objResult->fields["expiration_date"] == NULL ? 'checked="checked"' : '', ENT_QUOTES, CONTREXX_CHARSET), 'FILESHARING_EXPIRATION_DATE' => htmlentities($objResult->fields["expiration_date"] != NULL ? date('d.m.Y H:i', strtotime($objResult->fields["expiration_date"])) : date('d.m.Y H:i', time() + 3600 * 24 * 7), ENT_QUOTES, CONTREXX_CHARSET), 'FILESHARING_SEND_MAIL' => $_ARRAYLANG['TXT_FILESHARING_SEND_MAIL'], 'FILESHARING_EMAIL' => $_ARRAYLANG["TXT_FILESHARING_EMAIL"], 'FILESHARING_EMAIL_INFO' => $_ARRAYLANG["TXT_FILESHARING_EMAIL_INFO"], 'FILESHARING_SUBJECT' => $_ARRAYLANG["TXT_FILESHARING_SUBJECT"], 'FILESHARING_SUBJECT_INFO' => $_ARRAYLANG["TXT_FILESHARING_SUBJECT_INFO"], 'FILESHARING_MESSAGE' => $_ARRAYLANG["TXT_FILESHARING_MESSAGE"], 'FILESHARING_MESSAGE_INFO' => $_ARRAYLANG["TXT_FILESHARING_MESSAGE_INFO"], 'FILESHARING_SEND' => $_ARRAYLANG["TXT_FILESHARING_SEND"], 'FILESHARING_SAVE' => $_ARRAYLANG["TXT_FILESHARING_SAVE"], 'TXT_CORE_MAILTEMPLATE_NOTE_TO' => $_ARRAYLANG['TXT_CORE_MAILTEMPLATE_NOTE_TO']));
 }
Пример #2
0
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
     $imageUrl = clone \Env::get("Resolver")->getUrl();
     // get the image url
     $files = array();
     $directory = \Env::get('Resolver')->getCmd();
     if ($directory != 'Downloads') {
         $targetPath = $cx->getWebsiteMediaFileSharingPath() . '/' . (!empty($directory) ? $directory . '/' : '');
         $targetPathWeb = $cx->getWebsiteMediaFileSharingWebPath() . '/' . (!empty($directory) ? $directory . '/' : '');
     } else {
         $targetPath = $cx->getWebsiteImagesDownloadsPath() . '/';
         $targetPathWeb = $cx->getWebsiteImagesDownloadsWebPath() . '/';
     }
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     $dirTempPath = $tup[0] . '/' . $tup[2] . '/';
     //get the tmp/$uploadId files
     foreach (glob($dirTempPath . '/*') as $uploadedFile) {
         $file = basename($uploadedFile);
         $uploadedFileName = $fileSystem->copyFile($dirTempPath, $file, $targetPath, $file, false);
         if ($uploadedFileName === 'error') {
             continue;
         }
         \Cx\Lib\FileSystem\FileSystem::delete_file($dirTempPath . '/' . $file);
         $uploadedFileSource = $targetPathWeb . $uploadedFileName;
         $hash = self::createHash();
         $check = self::createCheck($hash);
         $objResult = $objDatabase->Execute("INSERT INTO " . DBPREFIX . "module_filesharing (`file`, `source`, `cmd`, `hash`, `check`, `upload_id`)\n                                VALUES (\n                                    '" . contrexx_raw2db($uploadedFileName) . "',\n                                    '" . contrexx_raw2db($uploadedFileSource) . "',\n                                    '" . contrexx_raw2db($directory) . "',\n                                    '" . contrexx_raw2db($hash) . "',\n                                    '" . contrexx_raw2db($check) . "',\n                                    '" . contrexx_input2int($uploadId) . "'\n                                )");
         if (!$objResult) {
             continue;
         }
         $imageUrl->setParam("act", "image");
         $imageUrl->setParam("hash", $hash);
         $info = pathinfo($cx->getWebsiteOffsetPath() . $uploadedFileSource, PATHINFO_EXTENSION);
         // if the file is an image show a thumbnail of the image
         if (!in_array(strtoupper($info), array('JPEG', 'JPG', 'TIFF', 'GIF', 'BMP', 'PNG'))) {
             $imageUrl = false;
         }
         $fieldId = $objDatabase->Insert_ID();
         $files[] = array("name" => $uploadedFileName, "image" => $imageUrl->toString(), "download" => parent::getDownloadLink($fieldId), "delete" => parent::getDeleteLink($fieldId));
     }
     return $files;
 }
Пример #3
0
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $files = array();
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     // loop through the uploaded files
     $objResult = $objDatabase->Execute("SELECT `id`, `file`, `source`, `hash`, `check` FROM " . DBPREFIX . "module_filesharing WHERE `upload_id` = " . intval($uploadId));
     if ($objResult !== false && $objResult->RecordCount() > 0) {
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         while (!$objResult->EOF) {
             $filePath = explode("/", $objResult->fields["source"]);
             $fileNameSource = end($filePath);
             $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
             $directory = \Env::get('Resolver')->getCmd();
             if ($directory != 'Downloads') {
                 $newPath = $cx->getWebsiteMediaFileSharingPath() . '/' . $directory . '/';
             } else {
                 $newPath = $cx->getWebsiteImagesDownloadsPath() . '/';
             }
             $fileSystem->copyFile($tup[0] . '/' . $tup[2] . '/', $fileNameSource, $newPath, $fileNameSource, false);
             // get file name
             $fileName = $objResult->fields["file"];
             // get the image url
             $imageUrl = clone \Env::get("Resolver")->getUrl();
             $imageUrl->setParam("act", "image");
             $imageUrl->setParam("hash", $objResult->fields["hash"]);
             $info = pathinfo($cx->getWebsiteOffsetPath() . $objResult->fields["source"]);
             // if the file is an image show a thumbnail of the image
             if (!in_array(strtolower($info["extension"]), array("jpeg", "jpg", "png", "gif"))) {
                 $imageUrl = false;
             }
             $files[] = array("name" => $fileName, "image" => $imageUrl, "download" => parent::getDownloadLink($objResult->fields["id"]), "delete" => parent::getDeleteLink($objResult->fields["id"]));
             $objResult->moveNext();
         }
     }
     return $files;
 }