/** * Given a Temp File Path, this will save the database record AND copy the file at the temporary file path * to the file assets directory for headshots * @param string $strTempFilePath * @return void */ public function SaveHeadShot($strTempFilePath) { // Figure out the Image Type $mixImageInfo = getimagesize($strTempFilePath); switch ($mixImageInfo['mime']) { case 'image/gif': $this->intImageTypeId = ImageType::gif; break; case 'image/jpeg': $this->intImageTypeId = ImageType::jpg; break; case 'image/png': $this->intImageTypeId = ImageType::png; break; default: throw new QCallerException('Image Type Not Supported: ' . $mixImageInfo['mime']); } // Start the Transaction HeadShot::GetDatabase()->TransactionBegin(); // Save the DB Record, Make Folders (if appicable) and Save the File $this->Save(); QApplication::MakeDirectory($this->Folder, 0777); copy($strTempFilePath, $this->Path); chmod($this->Path, 0777); // Commit the Transaction HeadShot::GetDatabase()->TransactionCommit(); }
/** * This will log a message to the Qcodo Log. Location of the log file is defined in __QCODO_LOG__ * * By default, this will log a "Normal" level log entry in the "default" Qcodo log file, which is * located at __QCODO_LOG__/default.log.txt * * Either parameter can be overridden. * * @param string $strMessage * @param integer $intLogLevel * @param string $strLogModule * @return void */ public static function Log($strMessage, $intLogLevel = QLogLevel::Normal, $strLogModule = 'default') { // Cancel out if log level is too low if ($intLogLevel > self::$MinimumLogLevel) { return; } // Setup Log Path if (!defined('__QCODO_LOG__')) { throw new QCallerException('__QCODO_LOG__ must be defined before running QLog::Log'); } // Cancel out if log path is null if (!__QCODO_LOG__) { return; } // Create the Log Directory if it does NOT yet exist if (!is_dir(__QCODO_LOG__)) { QApplication::MakeDirectory(__QCODO_LOG__, 0777); } // Setup the Line $strLine = sprintf("%5s | %s | %s | %s\r\n", getmypid(), QLogLevel::$NameArray[$intLogLevel], QDateTime::Now()->NowToString(QDateTime::FormatIso), self::FormatMessage($strMessage)); // Open the File for Writing $strLogFilePath = __QCODO_LOG__ . '/' . $strLogModule . self::$Extension; $objFile = fopen($strLogFilePath, 'a'); // Write the Line fwrite($objFile, $strLine); fclose($objFile); }
public function SaveFile($strPayload, $strPayloadCompressed) { QApplication::MakeDirectory($this->GetFolder(), 0777); file_put_contents($this->GetFilePath(), $strPayload); file_put_contents($this->GetFilePathCompressed(), $strPayloadCompressed, FILE_BINARY); chmod($this->GetFilePath(), 0666); chmod($this->GetFilePathCompressed(), 0666); }
/** * Given a file at a temp file path location, this will save the file to the repository * and save the db row record. * @param string $strTemporaryFilePath the temporary file path to the file being saved to the repository * @param string $strFileName the name of the file that was originally uploaded * @return void */ public function SaveFile($strTemporaryFilePath, $strFileName) { // Update wiki file metadata $this->FileName = $strFileName; $this->FileSize = filesize($strTemporaryFilePath); $this->FileMime = QMimeType::GetMimeTypeForFilename($strFileName); // Save the Row $this->Save(); // Copy the File QApplication::MakeDirectory($this->GetFolder(), 0777); copy($strTemporaryFilePath, $this->GetPath()); chmod($this->GetPath(), 0666); }
/** * Used by custom RenderImage method to output the final image. * Uses $this->strImageType to determine type of image to be rendered. * This version is to be used when rendering an image using the Imagick library. * * If strPath is not set, output to the screen. If it is, save to strPath. * * @param Imagick $objFinalImage image as an instance of the Imagick class * @param string $strPath */ protected function RenderImageMagickHelper($objFinalImage, $strPath) { // Output the Image (if path isn't specified, output to buffer. Otherwise, output to disk) if (!$strPath) { $strPath = $this->strImagickTempFilePath . '/image_' . str_replace('.', '_', microtime(true)); // Output to a temporary location switch ($this->strImageType) { case QImageType::Gif: $strPath .= '.gif'; $objFinalImage->setImageFormat('gif'); header('Content-Type: image/gif'); break; case QImageType::AnimatedGif: $strPath .= '.gif'; $objFinalImage->setImageFormat('gif'); header('Content-Type: image/gif'); break; case QImageType::Jpeg: $strPath .= '.jpg'; $objFinalImage->setImageFormat('jpeg'); $objFinalImage->setCompressionQuality($this->intJpegQuality); header('Content-Type: image/jpeg'); break; default: $strPath .= '.png'; $objFinalImage->setImageFormat('png'); header('Content-Type: image/png'); break; } if ($this->strImageType == QImageType::AnimatedGif) { file_put_contents($strPath, $objFinalImage->GetImagesBlob()); } else { $objFinalImage->writeImage($strPath); } QApplication::$ProcessOutput = false; header('Cache-Control: cache'); header('Expires: Wed, 20 Mar 2019 05:00:00 GMT'); header('Pragma: cache'); print file_get_contents($strPath); unlink($strPath); } else { // Make Directory QApplication::MakeDirectory(dirname($strPath), 0777); // Output to Disk switch ($this->strImageType) { case QImageType::Gif: $objFinalImage->setImageFormat('gif'); break; case QImageType::AnimatedGif: $objFinalImage->setImageFormat('gif'); break; case QImageType::Jpeg: $objFinalImage->setImageFormat('jpeg'); $objFinalImage->setCompressionQuality($this->intJpegQuality); break; default: $objFinalImage->setImageFormat('png'); break; } $objFinalImage->writeImage($strPath); chmod($strPath, 0777); } $objFinalImage->Destroy(); }
<?php ini_set("memory_limit", "1024M"); // Make the Directory if (!is_dir(STATISTICS_PDF_PATH)) { QApplication::MakeDirectory(STATISTICS_PDF_PATH, 0777); } // Anything to Load? if (is_file(STATISTICS_PDF_PATH . '/run.txt')) { $strTokens = explode(' ', trim(file_get_contents(STATISTICS_PDF_PATH . '/run.txt'))); $intYear = intval($strTokens[0]); unlink(STATISTICS_PDF_PATH . '/run.txt'); } else { exit(0); } if ($intYear < 1950 || $intYear > 2500) { exit(0); } // Setup Zend Framework load set_include_path(get_include_path() . ':' . __INCLUDES__); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Pdf'); print "Generating Statistics PDF for " . $intYear . "\r\n"; // Delete Old Files exec('rm -r -f ' . STATISTICS_PDF_PATH . '/StatisticsFor' . $intYear . '*.pdf'); // Create the PDF Object for the PDF $objStatisticPdf = new Zend_Pdf(); $dtxAfterValue = new QDateTime("1/1/" . $intYear); $dtxBeforeValue = new QDateTime("12/31/" . $intYear); // Get the Data $objContributionCursor = StewardshipContribution::QueryCursor(QQ::AndCondition(QQ::GreaterOrEqual(QQN::StewardshipContribution()->DateCredited, $dtxAfterValue), QQ::LessOrEqual(QQN::StewardshipContribution()->DateCredited, $dtxBeforeValue)));
public function SaveWithImage($strTemporaryFilePath) { // Get Image Info and Ensure a Valid Image $arrValues = getimagesize($strTemporaryFilePath); if (!$arrValues || !count($arrValues) || !$arrValues[0] || !$arrValues[1] || !$arrValues[2]) { throw new QCallerException('Not a valid image file: ' . $strTemporaryFilePath); } // Update image metadata info switch ($arrValues[2]) { case IMAGETYPE_JPEG: $this->intImageFileTypeId = ImageFileType::Jpeg; break; case IMAGETYPE_PNG: $this->intImageFileTypeId = ImageFileType::Png; break; case IMAGETYPE_GIF: $this->intImageFileTypeId = ImageFileType::Gif; break; default: throw new QCallerException('Not a valid image file: ' . $strTemporaryFilePath); } $this->Save(); QApplication::MakeDirectory($this->GetImageFolder(), 0777); copy($strTemporaryFilePath, $this->GetImagePath()); chmod($this->GetImagePath(), 0666); }
/** * This will return the web/docroot-relative path for the thumbnail image for this wiki image * NOTE: if the thumbnail does not exist, this will also CREATE the thumbnail * @return string */ public function GetThumbPath() { // calculate the web/docroot-relative path $strThumbPath = $this->GetThumbFolder() . '/' . $this->intWikiVersionId . '.' . ImageFileType::$ExtensionArray[$this->intImageFileTypeId]; // See if the thumbnail image, itself exists if (file_exists(__DOCROOT__ . $strThumbPath)) { return $strThumbPath; } // It does NOT exist -- we need to create it first QApplication::MakeDirectory(__DOCROOT__ . $this->GetThumbFolder(), 0777); $objImageControl = new QImageControl(null); $objImageControl->ImagePath = $this->GetPath(); $objImageControl->Width = 240; $objImageControl->Height = 240; $objImageControl->ScaleCanvasDown = true; $objImageControl->ScaleImageUp = false; $objImageControl->RenderImage(__DOCROOT__ . $strThumbPath); return $strThumbPath; }
protected static function Run() { // Get the RenderedPage (if applicable) if (ob_get_length()) { QErrorHandler::$RenderedPage = ob_get_contents(); ob_clean(); } // Setup the FileLinesArray QErrorHandler::$FileLinesArray = file(QErrorHandler::$Filename); // Set up the MessageBody QErrorHandler::$MessageBody = htmlentities(QErrorHandler::$Message); QErrorHandler::$MessageBody = str_replace(" ", " ", str_replace("\n", "<br/>\n", QErrorHandler::$MessageBody)); QErrorHandler::$MessageBody = str_replace(": ", ": ", QErrorHandler::$MessageBody); // Figure Out DateTime (and if we are logging, the filename of the error log) $strMicrotime = microtime(); $strParts = explode(' ', $strMicrotime); $strMicrotime = substr($strParts[0], 2); $intTimestamp = $strParts[1]; QErrorHandler::$DateTimeOfError = date('l, F j Y, g:i:s.' . $strMicrotime . ' A T', $intTimestamp); QErrorHandler::$IsoDateTimeOfError = date('Y-m-d H:i:s T', $intTimestamp); if (defined('__ERROR_LOG__') && __ERROR_LOG__ && defined('ERROR_LOG_FLAG') && ERROR_LOG_FLAG) { QErrorHandler::$FileNameOfError = sprintf('qcodo_error_%s_%s.html', date('Y-m-d_His', $intTimestamp), $strMicrotime); } // Cleanup unset($strMicrotime); unset($strParts); unset($strMicrotime); unset($intTimestamp); // Generate the Error Dump if (!ob_get_level()) { ob_start(); } require __QCODO_CORE__ . '/assets/error_dump.inc.php'; // Do We Log??? if (defined('__ERROR_LOG__') && __ERROR_LOG__ && defined('ERROR_LOG_FLAG') && ERROR_LOG_FLAG) { // Log to File in __ERROR_LOG__ $strContents = ob_get_contents(); QApplication::MakeDirectory(__ERROR_LOG__, 0777); $strFileName = sprintf('%s/%s', __ERROR_LOG__, QErrorHandler::$FileNameOfError); file_put_contents($strFileName, $strContents); @chmod($strFileName, 0666); } if (QApplication::$RequestMode == QRequestMode::Ajax) { if (defined('ERROR_FRIENDLY_AJAX_MESSAGE') && ERROR_FRIENDLY_AJAX_MESSAGE) { // Reset the Buffer while (ob_get_level()) { ob_end_clean(); } // Setup the Friendly Response header('Content-Type: text/xml'); $strToReturn = '<controls/><commands><command>alert("' . str_replace('"', '\\"', ERROR_FRIENDLY_AJAX_MESSAGE) . '");</command></commands>'; if (QApplication::$EncodingType) { printf("<?xml version=\"1.0\" encoding=\"%s\"?><response>%s</response>\r\n", QApplication::$EncodingType, $strToReturn); } else { printf("<?xml version=\"1.0\"?><response>%s</response>\r\n", $strToReturn); } return false; } } else { if (defined('ERROR_FRIENDLY_PAGE_PATH') && ERROR_FRIENDLY_PAGE_PATH) { // Reset the Buffer while (ob_get_level()) { ob_end_clean(); } header("HTTP/1.1 500 Internal Server Error"); require ERROR_FRIENDLY_PAGE_PATH; } } exit; }
/** * Generates a php code using a template file * * @param string $strModuleName * @param string $strFilename * @param boolean $blnOverrideFlag whether we are using the _core template, or using a custom one * @param mixed[] $mixArgumentArray * @param boolean $blnSave whether or not to actually perform the save * @throws QCallerException * @throws Exception * @return mixed returns the evaluated template or boolean save success. */ public function GenerateFile($strModuleName, $strFilename, $blnOverrideFlag, $mixArgumentArray, $blnSave = true) { // Figure out the actual TemplateFilePath if ($blnOverrideFlag) { $strTemplateFilePath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . '/' . $strFilename; } else { $strTemplateFilePath = __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . '/' . $strFilename; } // Setup Debug/Exception Message if (QCodeGen::DebugMode) { _p("Evaluating {$strTemplateFilePath}<br/>", false); } // Check to see if the template file exists, and if it does, Load It if (!file_exists($strTemplateFilePath)) { throw new QCallerException('Template File Not Found: ' . $strTemplateFilePath); } // Evaluate the Template if (substr($strFilename, strlen($strFilename) - 8) == '.tpl.php') { // make sure paths are set up to pick up included files from both the override directory and _core directory $strSearchPath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . PATH_SEPARATOR . __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . PATH_SEPARATOR . get_include_path(); set_include_path($strSearchPath); if ($strSearchPath != get_include_path()) { throw new QCallerException('Can\'t override include path. Make sure your apache or server settings allow include paths to be overridden. '); } $strTemplate = $this->EvaluatePHP($strTemplateFilePath, $strModuleName, $mixArgumentArray, $templateSettings); restore_include_path(); if (!isset($templateSettings) || !$templateSettings) { // check if we have old style <template .../> settings $templateSettings = $this->getTemplateSettings($strTemplateFilePath, $strTemplate); } } else { $strTemplate = file_get_contents($strTemplateFilePath); $strTemplate = $this->EvaluateTemplate($strTemplate, $strModuleName, $mixArgumentArray); $templateSettings = $this->getTemplateSettings($strTemplateFilePath, $strTemplate); } $blnOverwriteFlag = QType::Cast($templateSettings['OverwriteFlag'], QType::Boolean); $blnDocrootFlag = QType::Cast($templateSettings['DocrootFlag'], QType::Boolean); $strTargetDirectory = QType::Cast($templateSettings['TargetDirectory'], QType::String); $strDirectorySuffix = QType::Cast($templateSettings['DirectorySuffix'], QType::String); $strTargetFileName = QType::Cast($templateSettings['TargetFileName'], QType::String); if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix) || is_null($blnDocrootFlag)) { throw new Exception('the template settings cannot be null'); } if ($blnSave && $strTargetDirectory) { // Figure out the REAL target directory if ($blnDocrootFlag) { $strTargetDirectory = __DOCROOT__ . $strTargetDirectory . $strDirectorySuffix; } else { $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix; } // Create Directory (if needed) if (!is_dir($strTargetDirectory)) { if (!QApplication::MakeDirectory($strTargetDirectory, 0777)) { throw new Exception('Unable to mkdir ' . $strTargetDirectory); } } // Save to Disk $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName); if ($blnOverwriteFlag || !file_exists($strFilePath)) { $intBytesSaved = file_put_contents($strFilePath, $strTemplate); $this->setGeneratedFilePermissions($strFilePath); return $intBytesSaved == strlen($strTemplate); } else { // Becuase we are not supposed to overwrite, we should return "true" by default return true; } } // Why Did We Not Save? if ($blnSave) { // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true; } // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $strTemplate; }
/** * Enter description here... * * @param string $strModuleName * @param string $strFilename * @param boolean $blnOverrideFlag whether we are using the _core template, or using a custom one * @param mixed[] $mixArgumentArray * @param boolean $blnSave wheather or not to actually perform the save * @return mixed returns the evaluated template or boolean save success. */ public function GenerateFile($strModuleName, $strFilename, $blnOverrideFlag, $mixArgumentArray, $blnSave = true) { // Figure out the actual TemplateFilePath if ($blnOverrideFlag) { $strTemplateFilePath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . '/' . $strFilename; } else { $strTemplateFilePath = __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . '/' . $strFilename; } // Setup Debug/Exception Message if (QCodeGen::DebugMode) { _p("Evaluating {$strTemplateFilePath}<br/>", false); } $strError = 'Template\'s first line must be <template OverwriteFlag="boolean" DocrootFlag="boolean" TargetDirectory="string" DirectorySuffix="string" TargetFileName="string"/>: ' . $strTemplateFilePath; // Check to see if the template file exists, and if it does, Load It if (!file_exists($strTemplateFilePath)) { throw new QCallerException('Template File Not Found: ' . $strTemplateFilePath); } $strTemplate = file_get_contents($strTemplateFilePath); // Evaluate the Template if (substr($strFilename, strlen($strFilename) - 8) == '.tpl.php') { // make sure paths are set up to pick up included files from both the override directory and _core directory $strSearchPath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . PATH_SEPARATOR . __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . PATH_SEPARATOR . get_include_path(); set_include_path($strSearchPath); if ($strSearchPath != get_include_path()) { throw new QCallerException('Can\'t override include path. Make sure your apache or server settings allow include paths to be overriden. '); } $strTemplate = $this->EvaluatePHP($strTemplateFilePath, $strModuleName, $mixArgumentArray); restore_include_path(); } else { $strTemplate = $this->EvaluateTemplate($strTemplate, $strModuleName, $mixArgumentArray); } // Parse out the first line (which contains path and overwriting information) $intPosition = strpos($strTemplate, "\n"); if ($intPosition === false) { throw new Exception($strError); } $strFirstLine = trim(substr($strTemplate, 0, $intPosition)); $strTemplate = substr($strTemplate, $intPosition + 1); $objTemplateXml = null; // Attempt to Parse the First Line as XML try { @($objTemplateXml = new SimpleXMLElement($strFirstLine)); } catch (Exception $objExc) { } if (is_null($objTemplateXml) || !$objTemplateXml instanceof SimpleXMLElement) { throw new Exception($strError); } $blnOverwriteFlag = QType::Cast($objTemplateXml['OverwriteFlag'], QType::Boolean); $blnDocrootFlag = QType::Cast($objTemplateXml['DocrootFlag'], QType::Boolean); $strTargetDirectory = QType::Cast($objTemplateXml['TargetDirectory'], QType::String); $strDirectorySuffix = QType::Cast($objTemplateXml['DirectorySuffix'], QType::String); $strTargetFileName = QType::Cast($objTemplateXml['TargetFileName'], QType::String); if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix) || is_null($blnDocrootFlag)) { throw new Exception($strError); } if ($blnSave && $strTargetDirectory) { // Figure out the REAL target directory if ($blnDocrootFlag) { $strTargetDirectory = __DOCROOT__ . $strTargetDirectory . $strDirectorySuffix; } else { $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix; } // Create Directory (if needed) if (!is_dir($strTargetDirectory)) { if (!QApplication::MakeDirectory($strTargetDirectory, 0777)) { throw new Exception('Unable to mkdir ' . $strTargetDirectory); } } // Save to Disk $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName); if ($blnOverwriteFlag || !file_exists($strFilePath)) { $intBytesSaved = file_put_contents($strFilePath, $strTemplate); $this->setGeneratedFilePermissions($strFilePath); return $intBytesSaved == strlen($strTemplate); } else { // Becuase we are not supposed to overwrite, we should return "true" by default return true; } } // Why Did We Not Save? if ($blnSave) { // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true; } else { // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $strTemplate; } }
/** * This will save the contents of the base64_decoded data to the filesystem. * @param string $strAlternateToken * @return void */ public function SaveFileFromQpm($strAlternateToken = null) { $strDecodedData = base64_decode($this->Base64Data); if (md5($strDecodedData) != $this->Md5) { print "WARNING: Invalid MD5 Match for " . $this->Path . "\r\n"; } QApplication::MakeDirectory(dirname($this->GetFullPath())); if ($strAlternateToken) { file_put_contents($this->GetFullPathWithAlternateToken($strAlternateToken), $strDecodedData); } else { file_put_contents($this->GetFullPath(), $strDecodedData); } }
<?php ini_set("memory_limit", "1024M"); // Make the Directory if (!is_dir(RECEIPT_PDF_PATH)) { QApplication::MakeDirectory(RECEIPT_PDF_PATH, 0777); } // Anything to Load? if (is_file(RECEIPT_PDF_PATH . '/run.txt')) { $strTokens = explode(' ', trim(file_get_contents(RECEIPT_PDF_PATH . '/run.txt'))); $intYear = intval($strTokens[0]); $blnAnnual = strtolower($strTokens[1]) == 'annual'; $intQuarter = intval($strTokens[1]); unlink(RECEIPT_PDF_PATH . '/run.txt'); } else { exit(0); } if ($intYear < 1950 || $intYear > 2500) { exit(0); } $strFileToken = $blnAnnual ? '_Annual' : '_Quarterly'; $fltMinimumAmount = $blnAnnual ? 0 : 249.99; // Setup Zend Framework load set_include_path(get_include_path() . ':' . __INCLUDES__); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Pdf'); print "Generating Receipts PDF for " . $intYear . "\r\n"; // Delete Old Files exec('rm -r -f ' . RECEIPT_PDF_PATH . '/ReceiptsFor' . $intYear . '*.pdf'); // Create the PDF Object for the Single and Multiple-page PDFs $intSingplePageCount = 1;
/** * Given a path to a TIFF image, this will save that image file * to the contribution_image repository * @param string $strTemporaryFilePath */ public function SaveImageFile($strTemporaryFilePath) { if (!$this->Id) { throw new QCallerException('Cannot Save Image File on an unsaved Contribution record'); } $this->DeleteImageFile(); if (!is_dir($this->Folder)) { QApplication::MakeDirectory($this->Folder, 0777); } copy($strTemporaryFilePath, $this->Path); chmod($this->Path, 0777); }
/** * Enter description here... * * @param string $strModuleName * @param string $strFilename * @param boolean $blnOverrideFlag whether we are using the _core template, or using a custom one * @param mixed[] $mixArgumentArray * @param boolean $blnSave wheather or not to actually perform the save * @return mixed returns the evaluated template or boolean save success. */ public function GenerateFile($strModuleName, $strFilename, $blnOverrideFlag, $mixArgumentArray, $blnSave = true) { // Figure out the actual TemplateFilePath if ($blnOverrideFlag) { $strTemplateFilePath = __QCODO__ . QCodeGen::TemplatesPathCustom . $strModuleName . '/' . $strFilename; } else { $strTemplateFilePath = __QCODO_CORE__ . QCodeGen::TemplatesPath . $strModuleName . '/' . $strFilename; } // Setup Debug/Exception Message if (QCodeGen::DebugMode) { _p("Evaluating {$strTemplateFilePath}<br/>", false); } $strError = 'Template\'s first line must be <template OverwriteFlag="boolean" DocrootFlag="boolean" TargetDirectory="string" DirectorySuffix="string" TargetFileName="string"/>: ' . $strTemplateFilePath; // Check to see if the template file exists, and if it does, Load It if (!file_exists($strTemplateFilePath)) { throw new QCallerException('Template File Not Found: ' . $strTemplateFilePath); } $strTemplate = file_get_contents($strTemplateFilePath); // Evaluate the Template $strTemplate = $this->EvaluateTemplate($strTemplate, $strModuleName, $mixArgumentArray); // Parse out the first line (which contains path and overwriting information) $intPosition = strpos($strTemplate, "\n"); if ($intPosition === false) { throw new Exception($strError); } $strFirstLine = trim(substr($strTemplate, 0, $intPosition)); $strTemplate = substr($strTemplate, $intPosition + 1); $objTemplateXml = null; // Attempt to Parse the First Line as XML try { @($objTemplateXml = new SimpleXMLElement($strFirstLine)); } catch (Exception $objExc) { } if (is_null($objTemplateXml) || !$objTemplateXml instanceof SimpleXMLElement) { throw new Exception($strError); } $blnOverwriteFlag = QType::Cast($objTemplateXml['OverwriteFlag'], QType::Boolean); $blnDocrootFlag = QType::Cast($objTemplateXml['DocrootFlag'], QType::Boolean); $strTargetDirectory = QType::Cast($objTemplateXml['TargetDirectory'], QType::String); $strDirectorySuffix = QType::Cast($objTemplateXml['DirectorySuffix'], QType::String); $strTargetFileName = QType::Cast($objTemplateXml['TargetFileName'], QType::String); if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix) || is_null($blnDocrootFlag)) { throw new Exception($strError); } if ($blnSave && $strTargetDirectory) { // Figure out the REAL target directory if ($blnDocrootFlag) { $strTargetDirectory = __DOCROOT__ . $strTargetDirectory . $strDirectorySuffix; } else { $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix; } // Create Directory (if needed) if (!is_dir($strTargetDirectory)) { if (!QApplication::MakeDirectory($strTargetDirectory, 0777)) { throw new Exception('Unable to mkdir ' . $strTargetDirectory); } } // Save to Disk $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName); if ($blnOverwriteFlag || !file_exists($strFilePath)) { $intBytesSaved = file_put_contents($strFilePath, $strTemplate); // CHMOD to full read/write permissions (applicable only to nonwindows) // Need to ignore error handling for this call just in case QApplication::SetErrorHandler(null); chmod($strFilePath, 0666); QApplication::RestoreErrorHandler(); return $intBytesSaved == strlen($strTemplate); } else { // Becuase we are not supposed to overwrite, we should return "true" by default return true; } } // Why Did We Not Save? if ($blnSave) { // We WANT to Save, but Qcodo Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true; } else { // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $strTemplate; } }
<?php // Generate the Error Dump if (!ob_get_level()) { ob_start(); } require __DOCROOT__ . __PHP_ASSETS__ . '/error_dump.php'; // Do We Log??? if (defined('ERROR_LOG_PATH') && ERROR_LOG_PATH && defined('ERROR_LOG_FLAG') && ERROR_LOG_FLAG) { // Log to File in ERROR_LOG_PATH $strContents = ob_get_contents(); QApplication::MakeDirectory(ERROR_LOG_PATH, 0777); $strFileName = ERROR_LOG_PATH . '/' . date('Y-m-d-H-i-s-' . rand(100, 999)) . '.html'; file_put_contents($strFileName, $strContents); @chmod($strFileName, 0666); } if (defined('ERROR_EMAIL')) { $objEmail = new QEmailMessage(); $objEmail->From = ERROR_EMAIL_FROM; $objEmail->Subject = ERROR_EMAIL_SUBJECT; $objEmail->To = ERROR_EMAIL; $strContents = ob_get_contents(); $objEmail->HtmlBody = $strContents; QEmailServer::Send($objEmail); } if (QApplication::$RequestMode == QRequestMode::Ajax) { if (defined('ERROR_FRIENDLY_AJAX_MESSAGE') && ERROR_FRIENDLY_AJAX_MESSAGE) { // Reset the Buffer while (ob_get_level()) { ob_end_clean(); }
} $strAuthor = null; // Try and deduce an author if applicable $arrMatches = array(); if (preg_match('/([bByY][ A-Za-z\\-\']*)(\\[[A-Za-z0-9 \\/.,\\-_]*\\])/', $strDescription, $arrMatches)) { $strAuthor = trim($arrMatches[1]); $strDateTime = trim($arrMatches[2]); $strDescription = trim(substr($strDescription, strlen($arrMatches[0]))); } if ($strAuthor) { $strHtml = sprintf('<div style="cursor: pointer;" onclick="document.location="%s";"><h1 style="font-size: 18px;">Featured Article</h1>%s<strong>%s</strong><br/><em>%s<br/>%s</em><br/>%s<br/><a href="%s" onclick="return false;">Read More</a></div>', QApplication::HtmlEntities($strLink), $strImageHtml, $strTitle, $strAuthor, $strDateTime, QString::Truncate($strDescription, 100), QApplication::HtmlEntities($strLink)); } else { $strHtml = sprintf('<div style="cursor: pointer;" onclick="document.location="%s";"><h1 style="font-size: 18px;">Featured Article</h1>%s<strong>%s</strong><br/><em>%s</em><br/>%s<br/><a href="%s" onclick="return false;">Read More</a></div>', QApplication::HtmlEntities($strLink), $strImageHtml, $strTitle, $dttDateTime->ToString('MMMM D, YYYY'), QString::Truncate($strDescription, 100), QApplication::HtmlEntities($strLink)); } $strHtmlArray[] = $strHtml; } } /////////////////////// // Setup the JS/HTML (if applicable) /////////////////////// if (count($strHtmlArray)) { $strHtml = implode('<br/><br/>', $strHtmlArray); $strHtml = '<img src="/uploads/mediaHeader.png" title="Abundant Living Online" style="position: relative; top: -15px; left: -10px; cursor: pointer;" onclick="document.location="http://abundantliving.alcf.net/"" /><br/>' . $strHtml; $strHtml = str_replace('"', '\\"', $strHtml); if (!is_dir(dirname(SYNDICATION_CACHE_PATH))) { QApplication::MakeDirectory(dirname(SYNDICATION_CACHE_PATH), 0777); } file_put_contents(SYNDICATION_CACHE_PATH, 'document.getElementById("syndicatedContent").innerHTML = "' . $strHtml . '";'); @chmod(SYNDICATION_CACHE_PATH, 0777); print file_get_contents(SYNDICATION_CACHE_PATH); }
/** * Same as mkdir but correctly implements directory recursion. * At its core, it will use the php MKDIR function. * * This method does no special error handling. If you want to use special error handlers, * be sure to set that up BEFORE calling MakeDirectory. * * @param string $strPath actual path of the directoy you want created * @param integer $intMode optional mode * @return boolean the return flag from mkdir */ public static function MakeDirectory($strPath, $intMode = null) { if (is_dir($strPath)) { // Directory Already Exists return true; } // Check to make sure the parent(s) exist, or create if not if (!QApplication::MakeDirectory(dirname($strPath), $intMode)) { return false; } // Create the current node/directory, and return its result $blnReturn = mkdir($strPath); if ($blnReturn && !is_null($intMode)) { // Manually CHMOD to $intMode (if applicable) // mkdir doesn't do it for mac, and this will error on windows // Therefore, ignore any errors that creep up QApplication::SetErrorHandler(null); chmod($strPath, $intMode); QApplication::RestoreErrorHandler(); } return $blnReturn; }
/** * Generates a php code using a template file * * @param string $strModuleSubPath * @param string $strTemplateFilePath Path to the template file * @param mixed[] $mixArgumentArray * @param boolean $blnSave whether or not to actually perform the save * * @throws QCallerException * @throws Exception * @return mixed returns the evaluated template or boolean save success. */ public function GenerateFile($strModuleSubPath, $strTemplateFilePath, $mixArgumentArray, $blnSave = true) { // Setup Debug/Exception Message if (QCodeGen::DebugMode) { _p("Evaluating {$strTemplateFilePath}<br/>", false); } // Check to see if the template file exists, and if it does, Load It if (!file_exists($strTemplateFilePath)) { throw new QCallerException('Template File Not Found: ' . $strTemplateFilePath); } // Evaluate the Template // make sure paths are set up to pick up included files from the various directories. // Must be the reverse of the buildTemplateArray order $a = array(); foreach (static::$TemplatePaths as $strTemplatePath) { array_unshift($a, $strTemplatePath . $strModuleSubPath); } $strSearchPath = implode(PATH_SEPARATOR, $a) . PATH_SEPARATOR . get_include_path(); $strOldIncludePath = set_include_path($strSearchPath); if ($strSearchPath != get_include_path()) { throw new QCallerException('Can\'t override include path. Make sure your apache or server settings allow include paths to be overridden. '); } $strTemplate = $this->EvaluatePHP($strTemplateFilePath, $mixArgumentArray, $templateSettings); set_include_path($strOldIncludePath); $blnOverwriteFlag = QType::Cast($templateSettings['OverwriteFlag'], QType::Boolean); $blnDocrootFlag = QType::Cast($templateSettings['DocrootFlag'], QType::Boolean); $strTargetDirectory = QType::Cast($templateSettings['TargetDirectory'], QType::String); $strDirectorySuffix = QType::Cast($templateSettings['DirectorySuffix'], QType::String); $strTargetFileName = QType::Cast($templateSettings['TargetFileName'], QType::String); if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix) || is_null($blnDocrootFlag)) { throw new Exception('the template settings cannot be null'); } if ($blnSave && $strTargetDirectory) { // Figure out the REAL target directory if ($blnDocrootFlag) { $strTargetDirectory = __DOCROOT__ . $strTargetDirectory . $strDirectorySuffix; } else { $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix; } // Create Directory (if needed) if (!is_dir($strTargetDirectory)) { if (!QApplication::MakeDirectory($strTargetDirectory, 0777)) { throw new Exception('Unable to mkdir ' . $strTargetDirectory); } } // Save to Disk $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName); if ($blnOverwriteFlag || !file_exists($strFilePath)) { $intBytesSaved = file_put_contents($strFilePath, $strTemplate); $this->setGeneratedFilePermissions($strFilePath); return $intBytesSaved == strlen($strTemplate); } else { // Becuase we are not supposed to overwrite, we should return "true" by default return true; } } // Why Did We Not Save? if ($blnSave) { // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true; } // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $strTemplate; }
protected function FilePutContents($strFilePath, $strData) { // Begin Error Handling Functionality QUpdateUtility::$CurrentFilePath = $strFilePath; set_error_handler('QUpdateUtilityFileSystemErrorHandler', E_ALL); // Create the Directory $blnToReturn = false; $strDirectory = dirname($strFilePath); if (!is_dir($strDirectory)) { QApplication::MakeDirectory($strDirectory, null); } $intBytes = file_put_contents($strFilePath, $strData); if ($intBytes) { $blnToReturn = true; } // End Error Handling Functionality restore_error_handler(); return $blnToReturn; }
$intMaxTimeZoneId = Timezone::CountAll(); $intMinForumId = Forum::QuerySingle(QQ::All(), QQ::OrderBy(QQN::Forum()->Id))->Id; $intMaxForumId = Forum::QuerySingle(QQ::All(), QQ::OrderBy(QQN::Forum()->Id, false))->Id; $dttStartDate = new QDateTime('2005-01-01 00:00:00'); // Wiki Files Repository Directory if (is_dir(__DATA_ASSETS__)) { print exec('rm -r -f ' . __DATA_ASSETS__); } clearstatcache(); QApplication::MakeDirectory(__DATA_ASSETS__, 0777); // Image Cached Directory if (is_dir(__DOCROOT__ . __IMAGES_CACHED__)) { print exec('rm -r -f ' . __DOCROOT__ . __IMAGES_CACHED__); } clearstatcache(); QApplication::MakeDirectory(__DOCROOT__ . __IMAGES_CACHED__, 0777); // Setup Sample File Path Array $objDir = opendir(__DOCROOT__ . '/../data_loader_files'); $strRandomFilePathArray = array(); $strRandomImagePathArray = array(); while ($strName = readdir($objDir)) { if ($strName != '.' && $strName != '..') { $strPath = __DOCROOT__ . '/../data_loader_files/' . $strName; $strRandomFilePathArray[] = $strPath; switch (substr($strName, strrpos($strName, '.') + 1)) { case 'jpg': case 'png': case 'gif': $strRandomImagePathArray[] = $strPath; break; }