/** * Do unlock of all file on destruct */ public function __destruct() { FlexiFileUtil::doUnlockAll(); }
/** * upload a field * @param FlexiTableFieldObject $oField * @param array $oStore * @param array $oRow (new form row) * @param array $oCurrentRow (old row) */ public function doUploadField(FlexiTableFieldObject $oField, &$oStore, &$oForm, $oCurrentRow) { $sName = $oField->getName(); $sSavePath = is_null($oField->savepath) ? FlexiFileUtil::getFullUploadPath("media/libraries") : $oField->savepath; //relative path is to cut out prefix of path before saving to field $sFullRelativeBasePath = empty($oField->savepath) ? "" : realpath($oField->savepath); //if multiple file //var_dump($oField->type); if ($oField->type == "multiimage-text") { $aCurrentFile = array(); if (!empty($oCurrentRow[$sName])) { $aCurrentFile = explode($oField->uploadseparator, $oCurrentRow[$sName]); } $aResultFile = array(); //var_dump($oForm); for ($c = 1; $c <= $oField->uploadcount; $c++) { if (isset($oForm[$sName . "_" . $c])) { $sNewFile = "media." . FlexiStringUtil::createRandomAlphaNumeric() . "_" . time(); $aStatus = FlexiFileUtil::storeUploadFile($oForm[$sName . "_" . $c], $sSavePath, $sNewFile . "."); $this->onGetUploadFileName($sSaveDir, $sNewFile); if ($aStatus["status"]) { //replace photo if already exists if (!empty($aCurrentFile[$c - 1])) { unlink(FlexiFileUtil::getFullPathFrom($aCurrentFile[$c - 1], $sFullRelativeBasePath)); } if ($oField->isUploadImage() && !empty($oField->maxwidth) || !empty($oField->maxheight)) { FlexiImageUtil::imageResize($oField->maxwidth, $oField->maxheight, $aStatus["path"]); } //if savepath not declared, full path from root is saved // if declared, only save filename // "" => use base root path //resize image based on max width, height //FlexiImageUtil::imageResize(345, 287, $aStatus["path"]); $aResultFile[$c - 1] = FlexiFileUtil::getRelativePathFrom($aStatus["path"], $sFullRelativeBasePath); } else { //No file $aResultFile[$c - 1] = $aCurrentFile[$c - 1]; } } } //for each file $oStore[$sName] = implode($oField->uploadseparator, $aResultFile); } else { //single file upload if (!isset($oForm[$sName])) { return; } //isupload form, presume if (is_array($oForm[$sName])) { $sNewFile = "media." . FlexiStringUtil::createRandomAlphaNumeric() . "_" . time(); //var_dump($oRow[$sName]); $aStatus = FlexiFileUtil::storeUploadFile($oForm[$sName], $sSavePath, $sNewFile . "."); $this->onGetUploadFileName($sSaveDir, $sNewFile); if ($aStatus["status"]) { //replace photo if already exists if (!empty($oCurrentRow[$sName])) { $sOldPath = FlexiFileUtil::getRelativePathFrom($oCurrentRow[$sName], $sFullRelativeBasePath); unlink($sOldPath); } if ($oField->isUploadImage() && !empty($oField->maxwidth) || !empty($oField->maxheight)) { FlexiImageUtil::imageResize($oField->maxwidth, $oField->maxheight, $aStatus["path"]); } //if savepath not declared, full path from root is saved // if declared, only save filename // "" => use base root path //resize image based on max width, height //FlexiImageUtil::imageResize(345, 287, $aStatus["path"]); $oStore[$sName] = FlexiFileUtil::getRelativePathFrom($aStatus["path"], $sFullRelativeBasePath); } else { //No file } } else { if (is_string($oForm[$sName])) { //could be manually saved or from old path $sNewFile = $oForm[$sName]; //delete old file if different from new file if (!empty($oCurrentRow[$sName]) && !empty($sNewFile)) { $sOldPath = FlexiFileUtil::getFullPathFrom($oCurrentRow[$sName], $sFullRelativeBasePath); $sNewPath = FlexiFileUtil::getFullPathFrom($sNewFile, $sFullRelativeBasePath); $sOldPathReal = realpath($sOldPath); if (!empty($sOldPathReal) && $sOldPathReal != realpath($sNewPath)) { unlink($sOldPathReal); } } $oStore[$sName] = FlexiFileUtil::getRelativePathFrom($sNewFile, $sFullRelativeBasePath); } else { throw new Exception("Invalid upload value: " . $oForm[$sName]); } } //else error } //if single file }
public static function doUnlockAll() { foreach (self::$aLocks as $fp) { flock($fp, LOCK_UN); fclose($fp); } self::$aLocks = array(); }
/** * get value safe for html display * @param FlexiTableFieldObject $oField * @param array $oRow * @return String */ public function getFieldDisplay(FlexiTableFieldObject $oField, $oRow) { $sName = $oField->getName(); $mValue = $oRow[$sName]; $bAllowHTML = $oField->allowhtml; switch ($oField->type) { case "select-text": case "select-tinyint": case "select-smallint": case "select-bigint": case "select-mediumint": case "select-enum": case "select-int": if ($oField->existsOption($mValue)) { $mValue = $oField->getOptionLabel($mValue); } break; case "timestamp-int": $sFormat = FlexiDateUtil::getPHPDateTimeFormat(FlexiConfig::$sInputDateTimeFormat); if (!empty($mValue) && $mValue > 0) { $mValue = date($sFormat, $mValue); } else { $mValue = ""; } break; case "datetime": $sFormat = FlexiDateUtil::getPHPDateTimeFormat(FlexiConfig::$sInputDateTimeFormat); if (!empty($mValue) && $mValue != "0000-00-00" && $mValue != "0000-00-00 00:00:00") { $mValue = date($sFormat, strtotime($mValue)); } else { $mValue = ""; } break; case "date": $sFormat = FlexiDateUtil::getPHPDateTimeFormat(FlexiConfig::$sDisplayDateFormat); if (!empty($mValue) && $mValue != "0000-00-00" && $mValue != "0000-00-00 00:00:00") { $mValue = date($sFormat, strtotime($mValue)); } else { $mValue = ""; } break; case "file-varchar": case "file-text": if (!empty($mValue)) { try { $sPath = (empty($oField->savepath) ? "" : $oField->savepath . "/") . $mValue; $sURL = FlexiFileUtil::getMediaURL($sPath); $mValue = "<a href='" . $sURL . "' target='_blank'>Open</a>"; } catch (Exception $e) { $mValue = $e->getMessage(); } $oField->allowtag = "a"; } $bAllowHTML = true; break; case "image-varchar": case "image-text": if (!empty($mValue)) { try { $sPath = (empty($oField->savepath) ? "" : $oField->savepath . "/") . $mValue; //echo "path: " . $sPath; $sURL = FlexiFileUtil::getMediaURL($sPath); $sThumbURL = FlexiFileUtil::getMediaURL($sPath, null, null, array("maxwidth" => $this->iMaxImageWidth)); $mValue = "<a href='" . $sURL . "' target='_blank'>" . "<img src='" . $sThumbURL . "'/>" . "</a>"; } catch (Exception $e) { $mValue = $e->getMessage(); } $oField->allowtag = "a,img"; } $bAllowHTML = true; break; case "multiimage-text": if (!empty($mValue)) { $mValue = ""; $aPath = explode($oField->uploadseparator, $oRow[$sName]); $sBasePath = empty($oField->savepath) ? "" : $oField->savepath . "/"; foreach ($aPath as $sPath) { $sPath = trim($sPath); try { if (!empty($sPath)) { $sPath = $sBasePath . $sPath; $sURL = FlexiFileUtil::getMediaURL($sPath); $sThumbURL = FlexiFileUtil::getMediaURL($sPath, null, null, array("maxwidth" => $this->iMaxImageWidth)); $mValue .= "<a href='" . $sURL . "' target='_blank'>" . "<img src='" . $sThumbURL . "'/>" . "</a>"; } } catch (Exception $e) { $mValue .= $e->getMessage(); } } //foreach $oField->allowtag = "a,img"; } $bAllowHTML = true; break; case "email": if (!empty($mValue)) { $oField->allowtag = "a"; $sURL = "mailto:" . $mValue; $mValue = "<a href='" . $sURL . "'>" . $mValue . "</a>"; } $bAllowHTML = true; break; } //switch type if (is_null($mValue)) { $mValue = ""; } if ($bAllowHTML) { if (!empty($oField->allowtag)) { $aSafe = $this->getFieldSafeTags($oField); $sTag = implode(",", $aSafe["tag"]); $aAttribute = $aSafe["attribute"]; $mValue = FlexiStringUtil::stripTagsAttributes($mValue, $sTag, $aAttribute); } } else { $mValue = strip_tags($mValue); } $this->onGetFieldDisplay($oField, $oRow, $mValue); return $mValue; }
/** * Get list of files which differ or is new from "frompath" * @author James * @param String $sFromPath * @param String $sToPath * @param array $aExclude, default: empty array * @param boolean $bRecursive, default: true * @return array("path", "type"=>"dir"/"file", "status" => "new"/"modified/conflict/include") */ public static function getDiffList($sFromPath, $sToPath, $aExclude = array(), $aInclude = array(), $bRecursive = true, $bCompare = true) { $bDebug = false; $aResult = array(); $sFromPath .= substr($sFromPath, -1, 1) == "/" ? "" : "/"; $sToPath .= substr($sToPath, -1, 1) == "/" ? "" : "/"; $aList = FlexiFileUtil::getDirectoryList($sFromPath, $aExclude, $aInclude); foreach ($aList as $sFile) { $sFromFile = $sFromPath . $sFile; //copy from $sToFile = $sToPath . $sFile; //copy to $sFromType = is_dir($sFromPath . $sFile) ? "dir" : "file"; if ($bDebug) { echo "src: " . $sFromFile . "\r\n<br/>"; } $bInclude = !$bCompare; if ($sFile != "." && $sFile != "..") { if (!$bInclude) { foreach ($aInclude as $sInclude) { //if ($bDebug) echo "include: " . $sInclude . "\r\n<br/>"; list($sIncludeName, $sIncludeName2) = explode("/", $sInclude); if ($bDebug) { echo "checking: " . $sFile . ", include: " . $sIncludeName . "\r\n<br/>"; } if ($sFile == $sIncludeName && empty($sIncludeName2)) { $bInclude = true; break; } } //foreach include } if ($bInclude) { //is in include list $aResult[] = array("path" => $sFromFile, "type" => $sFromType, "status" => "include"); } else { if ($bCompare && file_exists($sToFile)) { //check if file exists if (is_file($sFromFile) && is_file($sToFile)) { //both is file, time to checksum $sFromMD5 = md5_file($sFromFile); $sToMD5 = md5_file($sToFile); if ($sFromMD5 != $sToMD5) { $aResult[] = array("path" => $sFromFile, "type" => $sFromType, "status" => "modified"); } // else is same, ignoring } else { if (is_dir($sFromFile) && is_file($sToFile) || is_file($sFromFile) && is_dir($sToFile)) { $aResult[] = array("path" => $sFromFile, "type" => $sFromType, "status" => "conflict"); } else { if (is_dir($sFromFile) && is_dir($sToFile)) { //both is directory, ignoring as its the same } } } //if to path exissts } else { $aResult[] = array("path" => $sFromFile, "type" => $sFromType, "status" => $bCompare ? "new" : "include"); } } //if not in include list if ($bRecursive && is_dir($sFromFile)) { //if($bDebug) echo "Looping into dir: " . $sFromFile . "\r\n<br/>"; $aChildExclude = array(); foreach ($aExclude as $sExclude) { $aExcludePath = explode("/", $sExclude); if (count($aExcludePath) > 1) { array_shift($aExcludePath); $aChildExclude[] = implode("/", $aExcludePath); } //else, ignore } $aChildInclude = array(); foreach ($aInclude as $sInclude) { $aIncludePath = explode("/", $sInclude); if (count($aIncludePath) > 1) { array_shift($aIncludePath); $aChildInclude[] = implode("/", $aIncludePath); } //else, ignore } if (count($aChildInclude) > 1) { if ($bDebug) { echo "Include to child: " . print_r($aChildInclude, true) . "\r\n<br/>"; } } $aResult = array_merge($aResult, self::getDiffList($sFromFile, $sToFile, $aChildExclude, $aChildInclude, true, !$bInclude)); } } } //foreach path return $aResult; }
$aPath = array(); if (!empty($mValue)) { $aPath = explode($vars["#uploadseparator"], $mValue); } $sBasePath = empty($oField->savepath) ? "" : $oField->savepath . "/"; $aPhoto = array(); $c = 1; foreach ($aPath as $sPath) { $sPath = trim($sPath); if (!empty($sPath)) { try { $sPhotoPath = (empty($vars["#savepath"]) ? "" : $vars["#savepath"] . "/") . $sPath; //echo "path: " . $sPhotoPath . "<br/>\n"; $sURL = FlexiFileUtil::getMediaURL($sPhotoPath); //echo "thumb: " . $sURL . "<br/>\n"; $sThumbURL = FlexiFileUtil::getMediaURL($sPhotoPath, null, null, array("maxwidth" => $vars["#maximagewidth"])); $aPhoto[$c - 1] = array("photopath" => $sPhotoPath, "thumburl" => $sThumbURL, "url" => $sURL, "error" => 0); } catch (Exception $e) { $aPhoto[$c - 1] = array("error" => 1, "message" => $e->getMessage()); } } else { $aPhoto[$c - 1] = array("error" => 0); } $c++; } //for echo isset($vars["#prefix"]) ? $vars["#prefix"] : ""; ?> <div class="fieldUploadDisplay"> <?php echo empty($mValue) ? "(No file uploaded)" : "";
<?php $mValue = isset($vars["#value"]) ? $vars["#value"] : (isset($vars["#default_value"]) ? $vars["#default_value"] : null); $sMaxLen = isset($vars["#maxlength"]) ? " maxlength=\"" . $vars["#maxlength"] . "\"" : ""; $bDisabled = isset($vars["#disabled"]) ? $vars["#disabled"] : false; $sRequired = isset($vars["#required"]) ? $vars["#required"] ? "<span class=\"required\">*</span>" : "" : ""; if (empty($vars["#maximagewidth"])) { throw new Exception("w not set"); } $sError = ""; try { $sPath = (empty($vars["#savepath"]) ? "" : $vars["#savepath"] . "/") . $mValue; $sURL = !empty($mValue) ? FlexiFileUtil::getMediaURL($sPath) : ""; $sThumbURL = !empty($mValue) ? FlexiFileUtil::getMediaURL($sPath, null, null, array("maxwidth" => $vars["#maximagewidth"])) : ""; } catch (Exception $e) { $sError = $e->getMessage(); } echo isset($vars["#prefix"]) ? $vars["#prefix"] : ""; ?> <div class="fieldUploadDisplay"> <?php echo empty($mValue) ? "(No file uploaded)" : ""; ?> <? if(!empty($mValue) && empty($sError)) { ?> <br/><a href="<?php echo $sURL; ?> " target='_blank'><img src="<?php echo $sThumbURL; ?> " /></a>
public static function processUpload($sFieldName, $sSavePath, $aExtension, $sSaveName, $aiMaxUpload = null, $bReplace = true, $sOldPath = null) { $iMaxUpload = self::getMaxUploadFileSize($aiMaxUpload); if (FlexiFileUtil::getIsUploaded($sFieldName)) { $iSize = FlexiFileUtil::getUploadedFileSize($sFieldName); if ($iSize > $iMaxUpload) { $sNotice = flexiT("File Upload exceed permitted size", "first") . ": " . $iSize . " / " . $iMaxUpload; throw new FlexiException($sNotice, ERROR_FILESIZE); } $sExtension = strtolower(trim(FlexiFileUtil::getUploadedFileExtension($sFieldName))); if (!in_array($sExtension, $aExtension)) { $sNotice = flexiT("File type not permitted", "first") . ", " . flexiT("you have uploaded") . ": " . $sExtension; throw new FlexiException($sNotice, ERROR_FILETYPE); } //replace photo if already exists if ($bReplace && !empty($sOldPath)) { //fix windows path issue $sOldFile = substr($sOldPath, 0, 1) == "/" || substr($sOldPath, 1, 2) == ":\\" ? $sOldPath : FlexiFileUtil::getBasePath() . "/" . $sOldPath; @unlink($sOldFile); } $aStatus = FlexiFileUtil::doUploadFile($sFieldName, $sSavePath, $sSaveName . "."); // return $aStatus; } //is upload return false; }
public function methodAjaxSQLLog() { $this->disableView(); $oService = $this->getService("FlexiObject"); $sLog = realpath($oService->sLogPath . "/sql.log"); if (empty($sLog)) { echo $this->returnJSON(true, ""); } else { //$sContent = file_get_contents($sLog); $sContent = implode("", FlexiFileUtil::getTail($sLog, 50)); //var_dump($sContent); $sContent = str_replace("\r\n", "\n", $sContent); $aContent = explode(";\n", $sContent); $aContent = array_reverse($aContent); if (trim($aContent[0]) == "") { array_shift($aContent); } $sContent = implode(";\n\n", $aContent); $sContent .= !empty($sContent) ? ";\n" : ""; $sContent = str_replace("\n", "<br/>\n", $sContent); //$sContent = str_replace("\n", "\n<br/>", $sContent); echo $this->returnJSON(true, $sContent); } return true; }