/** * loadToDbFromYamlFile() * description: * - reading yaml config file with params 'modelName', 'inserts', 'insert_pattern' * - and processing the data by passing it to a propel modelName::insertRow() method passing a array assoc of fieldnames and values * - works only already installed db, handled by propel * - see details in the data/install/'table_name.insert.yml' files and install_notes.txt * @param string $sFileName table_name or optionally fullfilename.yml * @param string $sFileDir optional path to directory (like '/dirname'), defaults to MAIN_DIR/DIRNAME_DATA/install * @return void */ public static function loadToDbFromYamlFile($sFileName, $sFileDir = null) { if ($sFileDir === null) { $sFileDir = ResourceFinder::findResource(array(DIRNAME_DATA, 'install')); } $sFileName = count(explode('.', $sFileName)) == 1 ? $sFileName . '.insert.yml' : $sFileName; $aFileContent = self::loadYamlFile($sFileName, $sFileDir); if (!isset($aFileContent['model_name'])) { throw new Exception('Error in InstallUtil: insertIntoDbFromConfigFile() expects file with param "model_name" set!'); } if (!isset($aFileContent['insert_pattern'])) { throw new Exception('Error in InstallUtil: insertIntoDbFromConfigFile() expects file with array "insert_pattern" set!'); } $aArrayOfValues = array(); foreach ($aFileContent['inserts'] as $sKey => $aData) { $i = 1; foreach ($aFileContent['insert_pattern'] as $sIndex => $sColumnName) { if ($sIndex == 'key' && $i === 1) { $aArrayOfValues[$sColumnName] = $sKey; } else { $aArrayOfValues[$sColumnName] = isset($aData[$sColumnName]) ? $aData[$sColumnName] : false; // optional boolean handling } $i++; } call_user_func(array($aFileContent['model_name'] . 'Peer', "insertRow"), $aArrayOfValues); } }
/** send() * Description: * • This method is called when NewsletterMailer is instanciated * • All newsletter, sender and recipient info are ready * * @return boolean has_invalid email addresses */ public function send() { // Get newsletter email main template and template body and css by template name $oEmailTemplate = new Template('main', array(DIRNAME_TEMPLATES, 'newsletter')); $oEmailTemplate->replaceIdentifier('newsletter_template_css', new Template("{$this->oNewsletter->getTemplateName()}.css", array(DIRNAME_TEMPLATES, 'newsletter'))); // Parse links differently in text RichtextUtil::$USE_ABSOLUTE_LINKS = LinkUtil::isSSL(); $oEMailContent = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($this->oNewsletter->getNewsletterBody())); RichtextUtil::$USE_ABSOLUTE_LINKS = null; // Replace add surrounding (body.tmpl) before content if exists. Template needs to contain a newsletter_content identifier if (ResourceFinder::findResource(array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME, "{$this->oNewsletter->getTemplateName()}.body.tmpl")) !== null) { $oEmailTemplate->replaceIdentifier('newsletter_content', new Template("{$this->oNewsletter->getTemplateName()}.body", array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME)), null, Template::LEAVE_IDENTIFIERS); } $oEmailTemplate->replaceIdentifier('newsletter_content', $oEMailContent, null, Template::LEAVE_IDENTIFIERS); $oEmailTemplate->replaceIdentifier('subject', $this->oNewsletter->getSubject()); $oEmailTemplate->replaceIdentifier('language', $this->oNewsletter->getLanguageId()); $oEmailTemplate->replaceIdentifier('newsletter_link', LinkUtil::absoluteLink($this->oNewsletter->getDisplayLink())); $oEmailTemplate->replaceIdentifier('newsletter_date', LocaleUtil::localizeDate(null, $this->oNewsletter->getLanguageId())); $oEmailTemplate->replaceIdentifier('newsletter_timestamp', time()); // Process templates with each recipient, depending on whether recipient is object and object of Subscriber or string foreach ($this->aRecipients as $mRecipient) { $this->sendNewsletter($mRecipient, clone $oEmailTemplate); } return count($this->aInvalidEmails) === 0; }
public function renderFile() { $sCacheString = 'preview_' . $this->oDocumentType->getId() . '_' . $this->iSize; $oCache = new Cache($sCacheString, DIRNAME_IMAGES); LinkUtil::sendCacheControlHeaders($this->oDocumentType, $oCache); if ($oCache->entryExists() && !$oCache->isOlderThan($this->oDocumentType)) { header("Content-Type: " . self::MIME_TYPE); $oCache->passContents(true); exit; } $sFileName = "{$this->oDocumentType->getDocumentKind()}.png"; $sFilePath = ResourceFinder::findResource(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), ResourceIncluder::RESOURCE_TYPE_ICON, $sFileName)); if ($sFilePath === null) { $sFileName = 'default.png'; } $sFilePath = ResourceFinder::findResource(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), ResourceIncluder::RESOURCE_TYPE_ICON, $sFileName)); if ($sFilePath === null) { throw new Exception("Error in DocumentTypePreviewFileModule->renderFile: type has unknown kind: {$this->oDocumentType->getDocumentKind()}"); } $sFontFilePath = ResourceFinder::findResource(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), 'PTS55F.ttf')); $oImage = Image::imageFromPath($sFilePath); if (Image::supportsText()) { $sText = strtoupper($this->oDocumentType->getExtension()); $fFontSize = 72.0; $aSize = Image::textSize($sFontFilePath, $sText, $fFontSize); $iDesiredWidth = 300; $iDesiredHeight = 145; $fWidthRatio = $iDesiredWidth / $aSize[0]; $fHeightRatio = $iDesiredHeight / $aSize[1]; $fRatio = min($fWidthRatio, $fHeightRatio); $fFontSize *= $fRatio; $iDesiredPositionX = 107 - 7 * $fRatio; $iDesiredPositionY = 338; $iStartPositionX = $iDesiredPositionX + ($iDesiredWidth - $aSize[0] * $fRatio) / 2; $iStartPositionY = $iDesiredPositionY + $aSize[1] * $fRatio + ($iDesiredHeight - $aSize[1] * $fRatio) / 2; $oImage->addText($sFontFilePath, $sText, 1, $fFontSize, 150, 150, 150, $iStartPositionX, $iStartPositionY); } if ($this->iSize < 512) { $oImage->setSize($this->iSize, $this->iSize, Image::STRETCH); } $oImage->setFileType('png'); $oImage->render(true, null, $oCache); exit; }
/** * renderFile() * @return string xhtml output */ public function renderFile() { $oOutput = new XHTMLOutput(XHTMLOutput::SETTING_HTML_4_TRANSITIONAL, true, null, $this->oNewsletter->getLanguageId()); $oOutput->render(); $oNewsletterTemplate = new Template('main_display', array(DIRNAME_TEMPLATES, 'newsletter'), false, true); $oNewsletterTemplate->replaceIdentifier('newsletter_template_css', new Template("{$this->oNewsletter->getTemplateName()}.css", array(DIRNAME_TEMPLATES, 'newsletter'))); $oNewsletterContent = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($this->oNewsletter->getNewsletterBody())); if (ResourceFinder::findResource(array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME, "{$this->oNewsletter->getTemplateName()}.body.tmpl")) !== null) { $oNewsletterTemplate->replaceIdentifier('newsletter_content', new Template("{$this->oNewsletter->getTemplateName()}.body", array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME)), null, Template::LEAVE_IDENTIFIERS); } $oNewsletterTemplate->replaceIdentifier('newsletter_content', $oNewsletterContent, null, Template::LEAVE_IDENTIFIERS); $oNewsletterTemplate->replaceIdentifier('language', $this->oNewsletter->getLanguageId()); if ($this->oMailing !== null) { $oNewsletterTemplate->replaceIdentifier('newsletter_date', LocaleUtil::localizeDate($this->oMailing->getDateSent(null)->getTimestamp(), $this->oNewsletter->getLanguageId())); $oNewsletterTemplate->replaceIdentifier('newsletter_timestamp', $this->oMailing->getDateSent(null)->getTimestamp()); } else { $oNewsletterTemplate->replaceIdentifier('newsletter_date', LocaleUtil::localizeDate($this->oNewsletter->getCreatedAt(null)->getTimestamp(), $this->oNewsletter->getLanguageId())); $oNewsletterTemplate->replaceIdentifier('newsletter_timestamp', $this->oNewsletter->getCreatedAt(null)->getTimestamp()); } $oNewsletterTemplate->replaceIdentifier('recipient', TranslationPeer::getString('wns.newsletter.recipient', $this->oNewsletter->getLanguageId())); $oNewsletterTemplate->replaceIdentifier('subject', $this->oNewsletter->getSubject()); $oNewsletterTemplate->render(); }
/** * Fetches all module metadata (including module info obtained from the info.yml files) and stores it into a static field, returns it */ public static function getModuleMetadataByTypeAndName($sType, $sName) { $aModuleMetadata = @self::$MODULES_METADATA_LIST[$sType][$sName]; if ($aModuleMetadata !== null) { return $aModuleMetadata; } $oInfoFileFinder = ResourceFinder::create(array(DIRNAME_MODULES, $sType, $sName, self::INFO_FILE))->all(); $oCache = new Cache("module_md_{$sType}-{$sName}", DIRNAME_PRELOAD); if ($oCache->entryExists() && !$oCache->isOutdated($oInfoFileFinder)) { $aModuleMetadata = $oCache->getContentsAsVariable(); } else { //Module exists? $aModulePath = array(DIRNAME_MODULES, $sType, $sName); if (ResourceFinder::findResource($aModulePath) === null) { $aModuleMetadata = null; return null; } $aModuleMetadata = array(); //General info $aModuleMetadata['path'] = $aModulePath; $aModuleMetadata['type'] = $sType; $aModuleMetadata['name'] = $sName; //Folders $aModuleMetadata['folders'] = array(); $aFolders = ResourceFinder::findResourceObjectsByExpressions(array(DIRNAME_MODULES, $sType, $sName, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN)); foreach ($aFolders as $oFolder) { $aModuleMetadata['folders'][] = $oFolder->getFileName(); } //Module-info $aModuleInfo = array(); require_once "spyc/Spyc.php"; foreach ($oInfoFileFinder->find() as $sPath) { $aModuleInfo = array_merge($aModuleInfo, Spyc::YAMLLoad($sPath)); } if (!isset($aModuleInfo['enabled'])) { $aModuleInfo['enabled'] = true; } $aModuleMetadata['module_info'] = $aModuleInfo; if (!isset(self::$MODULES_METADATA_LIST[$sType])) { self::$MODULES_METADATA_LIST[$sType] = array(); } $oCache->setContents($aModuleMetadata); } self::$MODULES_METADATA_LIST[$sType][$sName] = $aModuleMetadata; return $aModuleMetadata; }
public function testFindMain() { $sMainPath = ResourceFinder::findResource(array('lib', 'main.php')); $this->assertSame(MAIN_DIR . '/base/lib/main.php', $sMainPath); }
public function getMatchingCustomTemplates($aPostfix = array(self::CONTENT_TEMPLATE_SUFFIX, self::CSS_TEMPLATE_SUFFIX)) { $aMatchingTemplates = array(); $aTemplateList = ResourceFinder::findResourcesByExpressions(array(DIRNAME_TEMPLATES, self::NEWSLETTER_DIRNAME, '/.+.content.tmpl/')); foreach ($aTemplateList as $sTemplateShortPath => $sTemplatePath) { $sTemplateName = substr($sTemplateShortPath, 0, -strlen(self::CONTENT_TEMPLATE_SUFFIX . '.tmpl')); $sTemplateName = substr($sTemplateName, strlen(DIRNAME_TEMPLATES . '/' . self::NEWSLETTER_DIRNAME . '/')); if (ResourceFinder::findResource(array(DIRNAME_TEMPLATES, self::NEWSLETTER_DIRNAME, "{$sTemplateName}.css.tmpl")) !== null) { $aMatchingTemplates[$sTemplateName] = $sTemplateName; } } return $aMatchingTemplates; }
public static function listTemplates($mDirName = DIRNAME_TEMPLATES, $bListSubdirs = false, $bFlag = null) { $aResult = array(); if (!is_array($mDirName)) { $mDirName = explode("/", $mDirName); } $aDirectories = ResourceFinder::findResource($mDirName, $bFlag, false, true); foreach ($aDirectories as $sDirectory) { if ($iTemplatesDir = opendir($sDirectory)) { while (false !== ($sFileName = readdir($iTemplatesDir))) { if (strpos($sFileName, ".tmpl") === strlen($sFileName) - strlen(".tmpl") && is_file("{$sDirectory}/{$sFileName}")) { $aResult[] = substr($sFileName, 0, strlen($sFileName) - strlen(".tmpl")); } else { if (is_dir($sDirectory . "/" . $sFileName) && strpos($sFileName, ".") !== 0 && $bListSubdirs) { $aDirName = $mDirName; $aDirName[] = $sFileName; $aSubItems = self::listTemplates($aDirName, true); foreach ($aSubItems as $sSubItem) { $aResult[] = "{$sFileName}/{$sSubItem}"; } } } } closedir($iTemplatesDir); } } return array_unique($aResult); }
} } else { print 'Launching ' . $sCommand . "\n"; array_push($aArguments, '>/dev/null'); array_push($aArguments, '2>&1'); array_push($aArguments, '&'); } } passthru($sCommand . ' ' . implode(' ', $aArguments)); } // Stylus-convert all .styl files $aStylFiles = find_files('styl'); if (count($aStylFiles) > 0) { $sNibLocation = isset($aOptions['nib']) ? $aOptions['nib'] : null; if ($sNibLocation === null) { $sNibLocation = ResourceFinder::findResource(array(DIRNAME_LIB, DIRNAME_VENDOR, 'nib')); } foreach (ResourceFinder::create()->addPath(DIRNAME_LIB, 'stylus_includes')->searchSiteFirst()->noCache()->all()->find() as $sIncludeDir) { array_unshift($aStylFiles, '-I', $sIncludeDir); } array_unshift($aStylFiles, '-u', $sNibLocation); if (!$aOptions['u']) { array_unshift($aStylFiles, '-c'); } if ($aOptions['d']) { array_unshift($aStylFiles, '-f', '-l'); } call_parser('stylus', $aStylFiles); } $aCoffeeFiles = find_files('coffee'); if (count($aCoffeeFiles) > 0) {
public static function getAvailableResource($sModuleName, $sModuleType, $sResourceType, $aParameters) { if ($aParameters === null) { $aParameters = array(); } $sFileModule = str_replace('template_', "{$sModuleType}_", self::getNameByClassName(get_class())); $sFileName = "{$sModuleName}.{$sModuleType}.{$sResourceType}.tmpl"; if (ResourceFinder::findResource(array(DIRNAME_MODULES, $sModuleType, $sModuleName, DIRNAME_TEMPLATES, "{$sFileName}")) === null) { return null; } return LinkUtil::link(array($sFileModule, $sResourceType, $sModuleName), 'FileManager', $aParameters); }
public function deleteBackupFile($sBackupFile) { $sFilePath = ResourceFinder::findResource(array(DIRNAME_DATA, 'sql', $sBackupFile)); if ($sFilePath) { return unlink($sFilePath); } return true; }
private static function moveModelForSchemaPath($sSchemaPath, $bIsDevVersion) { if ($bIsDevVersion) { $sNewModelDir = dirname(dirname($sSchemaPath)) . "/" . DIRNAME_LIB; if (!is_dir($sNewModelDir)) { mkdir($sNewModelDir); } $sNewModelDir = $sNewModelDir . "/" . DIRNAME_MODEL; if (!is_dir($sNewModelDir)) { mkdir($sNewModelDir); } $sNewModelBaseDir = "{$sNewModelDir}/om"; if (!is_dir($sNewModelBaseDir)) { mkdir($sNewModelBaseDir); } $sNewModelMapDir = "{$sNewModelDir}/map"; if (!is_dir($sNewModelMapDir)) { mkdir($sNewModelMapDir); } } $sSchema = file_get_contents($sSchemaPath); preg_match_all(self::CLASSNAME_PATTERN, $sSchema, $aMatches); $aMatches = $aMatches[1]; foreach ($aMatches as $sClassName) { $sClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, "{$sClassName}.php"), ResourceFinder::SEARCH_MAIN_ONLY); $sPeerClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, "{$sClassName}" . self::$PEER_SUFFIX . ".php"), ResourceFinder::SEARCH_MAIN_ONLY); $sQueryClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, "{$sClassName}" . self::$QUERY_SUFFIX . ".php"), ResourceFinder::SEARCH_MAIN_ONLY); $sBaseClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, 'om', self::$BASE_PREFIX . "{$sClassName}.php"), ResourceFinder::SEARCH_MAIN_ONLY); $sBasePeerClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, 'om', self::$BASE_PREFIX . "{$sClassName}" . self::$PEER_SUFFIX . ".php"), ResourceFinder::SEARCH_MAIN_ONLY); $sBaseQueryClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, 'om', self::$BASE_PREFIX . "{$sClassName}" . self::$QUERY_SUFFIX . ".php"), ResourceFinder::SEARCH_MAIN_ONLY); //No editable version of the map class exists $sMapClassPath = ResourceFinder::findResource(array(DIRNAME_GENERATED, DIRNAME_MODEL, 'map', "{$sClassName}" . self::$MAP_SUFFIX . ".php"), ResourceFinder::SEARCH_MAIN_ONLY); if ($bIsDevVersion) { //Over-writable by the user self::moveOverridableFile($sClassPath, $sClassName, $sNewModelDir); self::moveOverridableFile($sPeerClassPath, $sClassName, $sNewModelDir, self::$PEER_SUFFIX); self::moveOverridableFile($sQueryClassPath, $sClassName, $sNewModelDir, self::$QUERY_SUFFIX); //Not over-writable by the user (allow to re-generate) self::moveNonOverridableFile($sBaseClassPath, $sClassName, $sNewModelBaseDir); self::moveNonOverridableFile($sBasePeerClassPath, $sClassName, $sNewModelBaseDir, self::$PEER_SUFFIX); self::moveNonOverridableFile($sBaseQueryClassPath, $sClassName, $sNewModelBaseDir, self::$QUERY_SUFFIX); self::moveNonOverridableFile($sMapClassPath, $sClassName, $sNewModelMapDir, self::$MAP_SUFFIX); } else { // Remove all overridables and leave non-overridables (Base…) in `generated` to be included unlink($sClassPath); unlink($sPeerClassPath); unlink($sQueryClassPath); } } }