/**
  * Generates an entry in the logbook an increases the hits-counter
  *
  * @param \class_module_mediamanager_file $objFile
  */
 public static function generateDlLog(class_module_mediamanager_file $objFile)
 {
     $objDB = class_carrier::getInstance()->getObjDB();
     $strQuery = "INSERT INTO " . _dbprefix_ . "mediamanager_dllog\n\t                   (downloads_log_id, downloads_log_date, downloads_log_file, downloads_log_user, downloads_log_ip) VALUES\n\t                   (?, ?, ?, ?, ?)";
     $objDB->_pQuery($strQuery, array(generateSystemid(), (int) time(), basename($objFile->getStrFilename()), class_carrier::getInstance()->getObjSession()->getUsername(), getServer("REMOTE_ADDR")));
     $objFile->increaseHits();
 }
 public function testFileSync()
 {
     echo "test mediamanager...\n";
     if (class_module_system_module::getModuleByName("samplecontent") == null || !is_file(_realpath_ . "/files/images/samples/IMG_3000.JPG")) {
         return;
     }
     $objFilesystem = new class_filesystem();
     $objFilesystem->folderCreate(_filespath_ . "/images/autotest");
     $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/IMG_3000.jpg");
     $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/IMG_3000.png");
     $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/PA021805.JPG");
     $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/test.txt");
     $objRepo = new class_module_mediamanager_repo();
     $objRepo->setStrPath(_filespath_ . "/images/autotest");
     $objRepo->setStrTitle("autotest repo");
     $objRepo->setStrViewFilter(".jpg,.png");
     $objRepo->updateObjectToDb();
     $objRepo->syncRepo();
     $arrFiles = class_module_mediamanager_file::loadFilesDB($objRepo->getSystemid());
     $this->assertEquals(3, count($arrFiles));
     foreach ($arrFiles as $objOneFile) {
         $objOneFile->deleteObjectFromDatabase();
     }
     $objRepo->deleteObjectFromDatabase();
     $arrFiles = $objFilesystem->getFilelist(_filespath_ . "/images/autotest");
     $this->assertEquals(1, count($arrFiles));
     $this->assertEquals("test.txt", array_values($arrFiles)[0]);
 }
 public function testJsonList()
 {
     $objFilesystem = new class_filesystem();
     $objFilesystem->folderCreate("/files/packageservertest");
     $objFilesystem->folderCreate("/files/packageservertest/t");
     file_put_contents(_realpath_ . "/files/packageservertest/t/metadata.xml", $this->getStrMetadata());
     $objFilesystem->folderCreate("/files/packageservertest/t/system");
     file_put_contents(_realpath_ . "/files/packageservertest/t/system/test.txt", $this->getStrMetadata());
     $objZip = new class_zip();
     $objZip->openArchiveForWriting("/files/packageservertest/autotest.zip");
     $objZip->addFile("/files/packageservertest/t/metadata.xml", "/metadata.xml");
     $objZip->addFile("/files/packageservertest/t/system/test.txt", "/system/test.txt");
     $objZip->closeArchive();
     $objFilesystem->folderDeleteRecursive("/files/packageservertest/t");
     $objMediamanagerRepo = new class_module_mediamanager_repo();
     $objMediamanagerRepo->setStrPath("/files/packageservertest");
     $objMediamanagerRepo->setStrTitle("autotest packages");
     $objMediamanagerRepo->updateObjectToDb();
     class_module_mediamanager_file::syncRecursive($objMediamanagerRepo->getSystemid(), $objMediamanagerRepo->getStrPath());
     /** @var $objPortalServer class_module_packageserver_portal */
     $objPortalServer = class_module_system_module::getModuleByName("packageserver")->getPortalInstanceOfConcreteModule();
     $strJson = $objPortalServer->action("list");
     $this->assertNotNull($strJson);
     $arrData = json_decode($strJson, true);
     $this->assertTrue(isset($arrData["numberOfTotalItems"]));
     $this->assertTrue(isset($arrData["items"]));
     $this->assertTrue(isset($arrData["protocolVersion"]));
     $this->assertEquals(1, count($arrData["items"]));
     $arrItem = $arrData["items"][0];
     $this->assertTrue(isset($arrItem["systemid"]));
     $this->assertTrue(isset($arrItem["title"]));
     $this->assertTrue(isset($arrItem["version"]));
     $this->assertTrue(isset($arrItem["description"]));
     $this->assertTrue(isset($arrItem["type"]));
     $this->assertEquals("Autotest", $arrItem["title"]);
     $this->assertEquals("3.9.1", $arrItem["version"]);
     $this->assertEquals("demo", $arrItem["description"]);
     $this->assertEquals("MODULE", $arrItem["type"]);
     $objMediamanagerRepo->deleteObjectFromDatabase();
     $objFilesystem->fileDelete("/files/packageservertest/autotest.zip");
 }
 /**
  * Internal helper, triggers the counting of packages available for the current request
  *
  * @param $strParentId
  * @param bool $strCategoryFilterFilter
  * @param bool $strNameFilter
  *
  * @return int
  */
 private function getAllPackagesCount($strParentId, $strCategoryFilterFilter = false, $strNameFilter = false)
 {
     if (validateSystemid($strParentId)) {
         return count($this->getAllPackages($strParentId, $strCategoryFilterFilter, null, null, $strNameFilter));
     } else {
         return class_module_mediamanager_file::getFlatPackageListCount($strCategoryFilterFilter, true, $strNameFilter);
     }
 }
 /**
  * Syncs the repo partially
  *
  * @return string
  * @permissions edit
  */
 protected function actionPartialSyncRepo()
 {
     $strReturn = "";
     $strResult = "";
     /** @var class_module_mediamanager_repo|class_module_mediamanager_file $objInstance */
     $objInstance = class_objectfactory::getInstance()->getObject($this->getSystemid());
     if ($objInstance instanceof class_module_mediamanager_file) {
         $arrSyncs = class_module_mediamanager_file::syncRecursive($objInstance->getSystemid(), $objInstance->getStrFilename());
     } else {
         if ($objInstance instanceof class_module_mediamanager_repo) {
             $arrSyncs = $objInstance->syncRepo();
         } else {
             return "";
         }
     }
     $strResult .= $this->getLang("sync_end") . "<br />";
     $strResult .= $this->getLang("sync_add") . $arrSyncs["insert"] . "<br />" . $this->getLang("sync_del") . $arrSyncs["delete"];
     $strReturn .= "<repo>" . xmlSafeString(strip_tags($strResult)) . "</repo>";
     class_logger::getInstance()->addLogRow("synced gallery partially >" . $this->getSystemid() . ": " . $strResult, class_logger::$levelInfo);
     return $strReturn;
 }
 /**
  * Syncs the complete repo with the filesystem. Adds new files and removes delete files to and
  * from the db.
  *
  * @return array [insert, delete]
  */
 public function syncRepo()
 {
     return class_module_mediamanager_file::syncRecursive($this->getSystemid(), $this->getStrPath());
 }
Beispiel #7
0
 /**
  * Wrapper to load a single element and generate the image
  * @return void
  */
 private function generateMediamanagerImage()
 {
     if (class_module_system_module::getModuleByName("mediamanager") !== null) {
         $objElement = new class_module_pages_pageelement($this->strElementId);
         $objPortalElement = $objElement->getConcretePortalInstance();
         $objFile = new class_module_mediamanager_file($this->strSystemid);
         if (!$objFile->rightView()) {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_FORBIDDEN);
             class_response_object::getInstance()->sendHeaders();
             return;
         }
         $arrElementData = $objPortalElement->getElementContent($objElement->getSystemid());
         class_session::getInstance()->sessionClose();
         if (is_file(_realpath_ . $objFile->getStrFilename())) {
             $objImage = new class_image2();
             $objImage->load($objFile->getStrFilename());
             $objImage->addOperation(new class_image_scale($arrElementData["gallery_maxw_d"], $arrElementData["gallery_maxh_d"]));
             $objImage->addOperation(new class_image_text($arrElementData["gallery_text"], $arrElementData["gallery_text_x"], $arrElementData["gallery_text_y"], 10, "#ffffff"));
             if (is_file(_realpath_ . $arrElementData["gallery_overlay"])) {
                 $objImageOverlay = new class_image2();
                 $objImageOverlay->load($arrElementData["gallery_overlay"]);
                 $objImage->addOperation(new class_image_overlay($arrElementData["gallery_overlay"], $arrElementData["gallery_text_x"], $arrElementData["gallery_text_y"]));
             }
             $objImage->setJpegQuality((int) $this->intQuality);
             $objImage->sendToBrowser();
             return;
         }
     }
     class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_NOT_FOUND);
     class_response_object::getInstance()->sendHeaders();
 }
 /**
  * @param string $strParentId
  *
  * @return array
  */
 private function getNavigationNodesHelper($strParentId)
 {
     $arrFoldersDB = class_module_mediamanager_file::loadFilesDB($strParentId, class_module_mediamanager_file::$INT_TYPE_FOLDER, true);
     $arrReturn = array();
     foreach ($arrFoldersDB as $objOneFolder) {
         $objPoint = new class_module_navigation_point();
         $objPoint->setIntRecordStatus(1);
         $objPoint->setStrName($objOneFolder->getStrName());
         $objPoint->setStrPageI($this->getPagename());
         $objPoint->setSystemid($objOneFolder->getSystemid());
         $objPoint->setStrLinkSystemid($objOneFolder->getSystemid());
         $objPoint->setStrLinkAction("mediaFolder");
         $objPoint->setBitIsForeignNode(true);
         $arrTemp = array("node" => $objPoint, "subnodes" => $this->getNavigationNodesHelper($objOneFolder->getSystemid()));
         $arrReturn[] = $arrTemp;
     }
     return $arrReturn;
 }
 /**
  * Will be kept for legacy compatibility
  *
  * @param bool $bitJsonResponse
  *
  * @return string
  */
 private function doUpload($bitJsonResponse = false)
 {
     $strReturn = "";
     //prepare the folder to be used as a target-folder for the upload
     $objFilemanagerRepo = new class_module_mediamanager_repo($this->arrElementData["char2"]);
     $objDownloadfolder = null;
     //add a special subfolder?
     $strPath = $objFilemanagerRepo->getStrPath();
     if ($this->getParam("portaluploadDlfolder") != "") {
         /** @var $objDownloadfolder class_module_mediamanager_file */
         $objDownloadfolder = class_objectfactory::getInstance()->getObject($this->getParam("portaluploadDlfolder"));
         //check if the folder is within the current repo
         /** @var $objTemp class_module_mediamanager_file */
         $objTemp = $objDownloadfolder;
         while (validateSystemid($objTemp->getSystemid()) && ($objTemp instanceof class_module_mediamanager_file || $objTemp instanceof class_module_mediamanager_repo)) {
             if ($objTemp->getSystemid() == $this->arrElementData["char2"]) {
                 $strPath = $objDownloadfolder->getStrFilename();
                 break;
             }
             $objTemp = class_objectfactory::getInstance()->getObject($objTemp->getPrevId());
         }
     }
     //upload the file...
     if ($objFilemanagerRepo->rightRight1()) {
         //Handle the fileupload
         $arrSource = $this->getParam("portaluploadFile");
         $strTarget = $strPath . "/" . createFilename($arrSource["name"]);
         $objFilesystem = new class_filesystem();
         if ($objFilesystem->isWritable($strPath)) {
             //Check file for correct filters
             $arrAllowed = explode(",", $objFilemanagerRepo->getStrUploadFilter());
             $strSuffix = uniStrtolower(uniSubstr($arrSource["name"], uniStrrpos($arrSource["name"], ".")));
             if ($objFilemanagerRepo->getStrUploadFilter() == "" || in_array($strSuffix, $arrAllowed)) {
                 if ($objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"])) {
                     //upload was successfull. try to sync the downloads-archive.
                     if ($objDownloadfolder != null && $objDownloadfolder instanceof class_module_mediamanager_file) {
                         class_module_mediamanager_file::syncRecursive($objDownloadfolder->getSystemid(), $objDownloadfolder->getStrFilename());
                     } else {
                         $objFilemanagerRepo->syncRepo();
                     }
                     $this->flushCompletePagesCache();
                     if ($bitJsonResponse) {
                         return true;
                     }
                     //reload the site to display the new file
                     if (validateSystemid($this->getParam("portaluploadDlfolder"))) {
                         $this->portalReload(class_link::getLinkPortalHref($this->getPagename(), "", "mediaFolder", "uploadSuccess=1", $this->getParam("portaluploadDlfolder")));
                     } else {
                         $this->portalReload(class_link::getLinkPortalHref($this->getPagename(), "", "", $this->getAction(), "uploadSuccess=1", $this->getSystemid()));
                     }
                 } else {
                     $strReturn .= $this->uploadForm($this->getLang("portaluploadCopyUploadError"));
                 }
             } else {
                 @unlink($arrSource["tmp_name"]);
                 $strReturn .= $this->uploadForm($this->getLang("portaluploadFilterError"));
             }
         } else {
             $strReturn .= $this->uploadForm($this->getLang("portaluploadNotWritableError"));
         }
     } else {
         $strReturn .= $this->getLang("commons_error_permissions");
     }
     return $strReturn;
 }
 /**
  * Syncs the files in the db with the files in the filesystem
  *
  * @param string $strPrevID
  * @param string $strPath
  * @param bool $bitRecursive
  * @param \class_module_mediamanager_repo|null $objRepo
  *
  * @return array [insert, delete]
  */
 public static function syncRecursive($strPrevID, $strPath, $bitRecursive = true, class_module_mediamanager_repo $objRepo = null)
 {
     $arrReturn = array();
     $arrReturn["insert"] = 0;
     $arrReturn["delete"] = 0;
     if ($objRepo == null) {
         $objRepo = class_objectfactory::getInstance()->getObject($strPrevID);
         while ($objRepo != null && !$objRepo instanceof class_module_mediamanager_repo) {
             $objRepo = class_objectfactory::getInstance()->getObject($objRepo->getPrevId());
         }
     }
     //Load the files in the DB
     $arrObjDB = class_module_mediamanager_file::loadFilesDB($strPrevID);
     //Load files and folder from filesystem
     $objFilesystem = new class_filesystem();
     //if the repo defines a view-filter, take that one into account
     $arrViewFilter = array();
     if ($objRepo->getStrViewFilter() != "") {
         $arrViewFilter = explode(",", $objRepo->getStrViewFilter());
     }
     $arrFilesystem = $objFilesystem->getCompleteList($strPath, $arrViewFilter, array(), array(".", "..", ".svn"));
     //So, lets sync those two arrays
     //At first the files
     foreach ($arrFilesystem["files"] as $intKeyFS => $arrOneFileFilesystem) {
         //search the db-array for this file
         foreach ($arrObjDB as $intKeyDB => $objOneFileDB) {
             //File or folder
             if ($objOneFileDB->getintType() == self::$INT_TYPE_FILE) {
                 //compare
                 if ($objOneFileDB->getStrFilename() == str_replace(_realpath_, "", $arrOneFileFilesystem["filepath"])) {
                     //And unset from both arrays
                     unset($arrFilesystem["files"][$intKeyFS]);
                     unset($arrObjDB[$intKeyDB]);
                 }
             }
         }
     }
     //And loop the folders
     foreach ($arrFilesystem["folders"] as $intKeyFolder => $strFolder) {
         //search the array for folders
         foreach ($arrObjDB as $intKeyDB => $objOneFolderDB) {
             //file or folder?
             if ($objOneFolderDB->getIntType() == self::$INT_TYPE_FOLDER) {
                 //compare
                 if ($objOneFolderDB->getStrFilename() == $strPath . "/" . $strFolder) {
                     //Unset from both
                     unset($arrFilesystem["folders"][$intKeyFolder]);
                     unset($arrObjDB[$intKeyDB]);
                 }
             }
         }
     }
     //the remaining records from the database have to be deleted!
     if (count($arrObjDB) > 0) {
         foreach ($arrObjDB as $objOneFileDB) {
             $objOneFileDB->deleteObjectFromDatabase();
             $arrReturn["delete"]++;
         }
     }
     //the remaining records from the filesystem have to be added
     foreach ($arrFilesystem["files"] as $arrOneFileFilesystem) {
         $strFileName = $arrOneFileFilesystem["filename"];
         $strFileFilename = str_replace(_realpath_, "", $arrOneFileFilesystem["filepath"]);
         $objFile = new class_module_mediamanager_file();
         $objFile->setStrFilename($strFileFilename);
         $objFile->setStrName($strFileName);
         $objFile->setIntType(self::$INT_TYPE_FILE);
         $objFile->updateObjectToDb($strPrevID);
         $arrReturn["insert"]++;
     }
     foreach ($arrFilesystem["folders"] as $strFolder) {
         $strFileName = $strFolder;
         $strFileFilename = $strPath . "/" . $strFolder;
         $objFile = new class_module_mediamanager_file();
         $objFile->setStrFilename($strFileFilename);
         $objFile->setStrName($strFileName);
         $objFile->setIntType(self::$INT_TYPE_FOLDER);
         $objFile->updateObjectToDb($strPrevID);
         $arrReturn["insert"]++;
     }
     //Load subfolders
     class_carrier::getInstance()->getObjDB()->flushQueryCache();
     if ($bitRecursive) {
         $objFolders = class_module_mediamanager_file::loadFilesDB($strPrevID, self::$INT_TYPE_FOLDER);
         foreach ($objFolders as $objOneFolderDB) {
             $arrTemp = class_module_mediamanager_file::syncRecursive($objOneFolderDB->getSystemid(), $objOneFolderDB->getStrFilename(), $bitRecursive, $objRepo);
             $arrReturn["insert"] += $arrTemp["insert"];
             $arrReturn["delete"] += $arrTemp["delete"];
         }
     }
     return $arrReturn;
 }
 /**
  * Loads the content of a folder
  * If requested, loads subactions,too
  *
  * SPECIAL MODE FOR MODULE FOLDERVIEW
  *
  * @return string
  * @permissions view
  * @autoTestable
  */
 protected function actionFolderContentFolderviewMode()
 {
     $strReturn = "<script type='text/javascript'>KAJONA.admin.loader.loadFile('" . class_resourceloader::getInstance()->getCorePathForModule("module_mediamanager") . "/module_mediamanager/admin/scripts/mediamanager.js');</script>";
     //if set, save CKEditors CKEditorFuncNum parameter to read it again in KAJONA.admin.folderview.selectCallback()
     //so we don't have to pass through the param with all requests
     if ($this->getParam("CKEditorFuncNum") != "") {
         $strReturn .= "<script type=\"text/javascript\">window.opener.KAJONA.admin.folderview.selectCallbackCKEditorFuncNum = " . (int) $this->getParam("CKEditorFuncNum") . ";</script>";
     }
     $strTargetfield = $this->getParam("form_element");
     $this->setArrModuleEntry("template", "/folderview.tpl");
     //list repos or contents?
     if ($this->getSystemid() == "") {
         //Load the repos
         $arrObjRepos = class_module_mediamanager_repo::getObjectList();
         $intI = 0;
         //Print every repo
         /** @var class_module_mediamanager_repo $objOneRepo */
         foreach ($arrObjRepos as $objOneRepo) {
             //check rights
             if ($objOneRepo->rightView()) {
                 $strActions = "";
                 $strActions .= $this->objToolkit->listButton(class_link::getLinkAdmin($this->getArrModule("modul"), "folderContentFolderviewMode", "&form_element=" . $strTargetfield . "&systemid=" . $objOneRepo->getSystemid(), "", $this->getLang("action_open_folder"), "icon_folderActionOpen"));
                 $strReturn .= $this->objToolkit->simpleAdminList($objOneRepo, $strActions, $intI++);
             }
         }
         if (uniStrlen($strReturn) != 0) {
             $strReturn = $this->objToolkit->listHeader() . $strReturn . $this->objToolkit->listFooter();
         }
         if (count($arrObjRepos) == 0) {
             $strReturn .= $this->getLang("commons_list_empty");
         }
     } else {
         $objFile = class_objectfactory::getInstance()->getObject($this->getSystemid());
         if ($objFile === null || !$objFile->rightView()) {
             return $this->getLang("commons_error_permissions");
         }
         $objIterator = new class_array_section_iterator(class_module_mediamanager_file::getFileCount($this->getSystemid()));
         $objIterator->setPageNumber($this->getParam("pv"));
         $objIterator->setArraySection(class_module_mediamanager_file::loadFilesDB($this->getSystemid(), false, false, $objIterator->calculateStartPos(), $objIterator->calculateEndPos()));
         $strReturn .= $this->actionUploadFileInternal();
         $strReturn .= $this->generateNewFolderDialogCode();
         $strReturn .= $this->renderFloatingGrid($objIterator, class_module_mediamanager_admin::INT_LISTTYPE_FOLDERVIEW, "&form_element=" . $this->getParam("form_element"), false);
     }
     return $strReturn;
 }
Beispiel #12
0
 private function updateGalleryLevel($strNewPrevid, $strOldPrevid)
 {
     $arrFiles = class_module_mediamanager_file::loadFilesDB($strNewPrevid);
     $arrOldFiles = $this->objDB->getPArray("SELECT * FROM  " . _dbprefix_ . "system, " . _dbprefix_ . "gallery_pic WHERE system_id = pic_id AND system_prev_id = ?", array($strOldPrevid));
     foreach ($arrFiles as $objOneFile) {
         $strNewFilename = basename($objOneFile->getStrFilename());
         echo "  searching image/folder " . $strNewFilename . "\n";
         foreach ($arrOldFiles as $arrOneOldFile) {
             if (basename($arrOneOldFile["pic_filename"]) == $strNewFilename) {
                 $objOneFile->setStrName($arrOneOldFile["pic_name"]);
                 $objOneFile->setStrDescription($arrOneOldFile["pic_description"]);
                 $objOneFile->setStrSubtitle($arrOneOldFile["pic_subtitle"]);
                 $objOneFile->setIntHits((int) $arrOneOldFile["pic_hits"]);
                 $objOneFile->updateObjectToDb();
                 $this->moveComments($arrOneOldFile["pic_id"], $objOneFile->getSystemid());
                 $this->migrateRatings($arrOneOldFile["pic_id"], $objOneFile->getSystemid());
                 echo "...update succeeded\n";
                 if ($objOneFile->getIntType() == class_module_mediamanager_file::$INT_TYPE_FOLDER) {
                     $this->updateGalleryLevel($objOneFile->getSystemid(), $arrOneOldFile["pic_id"]);
                 }
             }
         }
     }
 }
 /**
  * Copies the metadata.xml content into the files properties.
  * @permissions edit
  * @xml
  * @return string
  */
 protected function actionUpdateDataFromMetadata()
 {
     $objPackage = new class_module_mediamanager_file($this->getSystemid());
     $objZip = new class_zip();
     $strMetadata = $objZip->getFileFromArchive($objPackage->getStrFilename(), "/metadata.xml");
     if ($strMetadata !== false) {
         $objMetadata = new class_module_packagemanager_metadata();
         $objMetadata->autoInit($objPackage->getStrFilename());
         $objPackage->setStrName($objMetadata->getStrTitle());
         $objPackage->setStrDescription($objMetadata->getStrDescription());
         //updateObjectToDb triggers the update of the isPackage and the category flags
         $objPackage->updateObjectToDb();
         return "<message><success /></message>";
     }
     return "<message><error /></message>";
 }