function createEmailFromTemplate($templateName, $user, $data = null) { global $APP_DIR; $email_config = getConfig("_email"); if (!$email_config || !$templateName || !$user) { return null; } $templateDir = $email_config["templates"]; $template = readTextFile("{$APP_DIR}/{$templateDir}/{$templateName}.html"); if (!$template) { return null; } $name = is_string($user) ? substringBefore($user, "@") : $user["first_name"] . " " . $user["last_name"]; $to_email = is_string($user) ? $user : $user["email"]; if (isset($email_config["to"])) { $to_email = $email_config["to"]; } $logo = combine($email_config["baseUrl"], getConfig("app.logo")); $cfg = array("site" => getConfig("defaultTitle"), "baseUrl" => $email_config["baseUrl"], "logo" => $logo, "name" => $name, "to" => $to_email); $template = replaceVariables($template, $cfg); $template = replaceVariables($template, $user); $template = replaceVariables($template, $data); $subject = substringBefore($template, "\n"); $body = substringAfter($template, "\n"); //replace classes with inlineStyles $styles = readConfigFile("{$APP_DIR}/{$templateDir}/inline.css"); if ($styles) { $body = "<div class=\"fp-email\">{$body}</div>"; $body = inlineStyles($body, $styles); } debug("createEmail subject", $subject); debug("createEmail body", $body); return createEmail($to_email, $subject, $body, true); }
public function process($currentXml) { if (!file_exists($this->generatePath('docvert--all-docbook.xml'))) { $editableDocbook = xsltTransform($currentXml, $this->docvertTransformDirectory . 'docbook-to-docbook-with-placeholders.xsl'); $this->saveFile('docvert--all-docbook.xml', $editableDocbook); } $chosenTheme = getGlobalConfigItem('theme'); if ($chosenTheme == null) { $chosenTheme = 'docvert'; } $editorTemplatePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $chosenTheme . DIRECTORY_SEPARATOR . 'fckeditor-template.html'; $editorTemplate = file_get_contents($editorTemplatePath); $editorTemplate = preg_replace_callback('/\\&(.*?)\\;/s', 'replaceLanguagePlaceholder', $editorTemplate); include_once dirname(__FILE__) . '/DocBookToXHTML.php'; $toHtmlObject = new DocBookToXHTML($this->elementAttributes, $this->pipelineDirectory, $this->contentDirectory, $this->docvertTransformDirectory, $this->loopDepth, $this->depthArray, $this->previewDirectory, $this->pipelineSettings); $html = $toHtmlObject->process($currentXml); $documentTitlePattern = "/<title[^>]*?>(.*?)<\\/title>/sm"; preg_match($documentTitlePattern, $html, $matches); $documentTitle = trim($matches[1]); $documentTitle = preg_replace("/<.*?>/", '', $documentTitle); //die($documentTitle.'<hr />'.$html); $html = substringAfter($html, '<body'); $html = substringAfter($html, '>'); $html = substringBefore($html, '</body'); $paragraphTitlePattern = "/<p.*?documentTitle[^>]*?>(.*?)<\\/p>/sm"; $html = preg_replace($paragraphTitlePattern, '', $html); $imagePathPrefix = '../../../../writable/' . basename($this->previewDirectory) . '/' . basename($this->contentDirectory) . '/'; $html = str_replace('src="', 'src="' . $imagePathPrefix, $html); //displayXmlString($html); $html = str_replace('&', '&', $html); $html = str_replace('<', '<', $html); $html = str_replace('>', '>', $html); $html = str_replace('"', '"', $html); $html = trim($html); $autoPipeline = $this->pipelineSettings['autopipeline']; $autoPipeline = str_replace('.xml', '', $autoPipeline); $autoPipeline = str_replace('.default', '', $autoPipeline); $editorTemplate = str_replace('{{value}}', $html, $editorTemplate); $editorTemplate = str_replace('{{config}}', '', $editorTemplate); $editorTemplate = str_replace('{{documentTitle}}', $documentTitle, $editorTemplate); $editorTemplate = str_replace('{{documentPath}}', basename($this->previewDirectory) . '/' . basename($this->contentDirectory), $editorTemplate); $editorTemplate = str_replace('{{pathToRemove}}', $imagePathPrefix, $editorTemplate); $editorTemplate = str_replace('{{pipeline}}', $this->pipelineSettings['pipeline'], $editorTemplate); $editorTemplate = str_replace('{{autopipeline}}', $autoPipeline, $editorTemplate); $this->saveFile('docvert--all-html.html', $editorTemplate); return $currentXml; }
function showGenerationStep() { $docvertDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR; $disallowDocumentGeneration = getGlobalConfigItem('doNotAllowDocumentGeneration'); if ($disallowDocumentGeneration == 'true') { return $this->getThemeFragment('generation-disabled.htmlf'); } if (isset($_REQUEST['step'])) { switch ($_REQUEST['step']) { case '4': if (!isset($_REQUEST['pages'])) { webServiceError('&error-webpage-generation-no-pages;'); } $template = $this->getThemeFragment('generation-step4.htmlf'); $hiddenFormChosenPages = array(); $listItems = array(); foreach ($_REQUEST['pages'] as $page) { $listItems[] = "\n\t\t\t\t" . '<li>' . $page . '</li>'; $hiddenFormChosenPages[] = "\n\t\t\t\t" . '<input type="hidden" name="pages[]" value="' . $page . '"/>'; } $template = str_replace('{{page-order}}', implode($listItems), $template); $template = str_replace('{{hidden-form-chosen-pages}}', implode($hiddenFormChosenPages), $template); $generatorPipelines = glob($this->docvertRootDirectory . 'generator-pipeline' . DIRECTORY_SEPARATOR . '*'); $generatorPipelinesArray = array(); foreach ($generatorPipelines as $generatorPipeline) { $generatorName = basename($generatorPipeline); $generatorPipelinesArray[] = '<option value="' . $generatorName . '">' . $generatorName . '</option>'; } return str_replace('{{generator-pipelines}}', implode('', $generatorPipelinesArray), $template); case '3': $template = $this->getThemeFragment('generation-step3.htmlf'); $listItems = array(); foreach ($_REQUEST['pages'] as $page) { $listItems[] = "\n\t\t\t\t" . '<option value="' . $page . '">' . $page . '</option>'; } return str_replace('{{chosen-scrape-urls}}', implode($listItems), $template); case '2': if (!isset($_REQUEST['url'])) { webServiceError('&error-webpage-generation-url;'); } $originalUrl = $_REQUEST['url']; if (trim($originalUrl) == '') { webServiceError('&error-webpage-generation-no-url-given;'); } if (!stringStartsWith($originalUrl, 'http')) { $originalUrl = 'http://' . $originalUrl; } $originalUrl = str_replace(array("\n", "\r", "\t", " "), '', $originalUrl); include_once dirname(__FILE__) . '/http.php'; if (trim(getUrlLocalPart($originalUrl)) == '') { $originalUrl = followUrlRedirects($originalUrl . '/'); } else { $originalUrl = followUrlRedirects($originalUrl); } if ($originalUrl === false) { webServiceError('&error-webpage-cannot-get-url;', 500, array('url' => $originalUrl)); } $page = file_get_contents($originalUrl); $baseTagPattern = "/<base[^>]*?href=([^>]*?)>/is"; preg_match($baseTagPattern, $page, $matches); if (count($matches) > 0) { $originalUrl = trim($matches[1]); $originalUrl = substr($originalUrl, 1, strlen($originalUrl) - 2); } $url = $originalUrl; $connectionPart = getUrlConnectionPart($url); $getUrlLocalPart = getUrlLocalPart($url); $localPartDirectory = getUrlLocalPartDirectory($url); $links = array(); $matches = null; preg_match_all('/href="(.*?)"/', $page, $matches); $matches = $matches[1]; $urls = array(); $urls[$originalUrl] = 'value that does not matter'; foreach ($matches as $match) { $link = $match; if (stringStartsWith($link, '/')) { $link = $connectionPart . $link; } elseif (stringStartsWith($link, "http://") || stringStartsWith($link, "https://")) { } elseif (stringStartsWith($link, "mailto:")) { } else { $link = $connectionPart . resolveRelativeUrl($localPartDirectory . $link); } if (containsString($link, '#')) { $link = substringBefore($link, '#'); } if (stringEndsWith($link, '?')) { $link = substringBefore($link, '?'); } if (stringStartsWith($link, 'http')) { $fileExtension = substr($link, strrpos($link, '.') + 1); switch ($fileExtension) { case 'avi': case 'mov': case 'mpg': case 'css': case 'jpeg': case 'jpg': case 'gif': case 'png': case 'bmp': case 'apng': case 'tiff': case 'ico': case 'js': case 'gz': case 'tar': case 'zip': case 'bin': case 'sit': case 'mp3': case 'mp4': case 'wav': case 'swf': case 'fla': case 'rss': case 'atom': case 'pdf': case 'xls': case 'doc': case 'txt': case 'pps': break; default: $urls[$link] = 'value that does not matter'; } } } $urls = array_keys($urls); $mostLikelyUrls = array(); $possibleUrls = array(); $unlikelyUrls = array(); $numberOfSlashesInOriginalUrl = strlen($originalUrl) - strlen(str_replace('/', '', $originalUrl)); foreach ($urls as $url) { $url = followUrlRedirects($url); if (trim($url) != '') { $numberOfSlashesInUrl = strlen($url) - strlen(str_replace('/', '', $url)); if (stringStartsWith($url, $connectionPart . $localPartDirectory) && $numberOfSlashesInUrl == $numberOfSlashesInOriginalUrl) { $mostLikelyUrls[] = $url; } elseif (stringStartsWith($url, $connectionPart)) { $possibleUrls[] = $url; } else { $unlikelyUrls[] = $url; } } } asort($unlikelyUrls); $itemId = 0; foreach ($mostLikelyUrls as $url) { $links[] = '<li class="orderingItem"><label for="urlId' . $itemId . '"><input type="checkbox" name="pages[]" value="' . $url . '" id="urlId' . $itemId . '" checked="checked"/><span class="title">' . $url . '</label></span></li>' . "\n"; $itemId++; } foreach ($possibleUrls as $url) { $links[] = '<li class="orderingItem"><label for="urlId' . $itemId . '"><input type="checkbox" name="pages[]" value="' . $url . '" id="urlId' . $itemId . '"/><span class="title">' . $url . '</label></span></li>' . "\n"; $itemId++; } foreach ($unlikelyUrls as $url) { $links[] = '<li class="orderingItem"><label for="urlId' . $itemId . '"><input type="checkbox" name="pages[]" value="' . $url . '" id="urlId' . $itemId . '"/><span class="title">' . $url . '</label></span></li>' . "\n"; $itemId++; } $step2Template = $this->getThemeFragment('generation-step2.htmlf'); $step2Template = str_replace('{{scrape-results}}', implode('', $links), $step2Template); $step2Template = str_replace('{{scrape-url}}', $url, $step2Template); return $step2Template; default: return $this->getThemeFragment('generation-step1.htmlf'); } } else { return $this->getThemeFragment('generation-step1.htmlf'); } }
function getLanguageToUse() { $language = getGlobalConfigItem('language'); if ($language == '' || $language == getAutoDetectLanguage()) { $langCodes = array(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $httpLangCodes = substringBefore($_SERVER['HTTP_ACCEPT_LANGUAGE'], ';'); $httpLangCodes = explode(',', $httpLangCodes); foreach ($httpLangCodes as $httpLangCode) { if (strlen($httpLangCode) >= 2) { $langCodes[] = substr($httpLangCode, 0, 2); } } } elseif (isset($_ENV['LC_MESSAGES']) || isset($_ENV[' LC_ALL']) || isset($_ENV['LANG'])) { $langCode = ''; if (isset($_ENV['LC_MESSAGES']) && trim($_ENV['LC_MESSAGES'])) { $langCode = $_ENV['LC_MESSAGES']; } elseif (isset($_ENV['LC_ALL']) && trim($_ENV['LC_ALL'])) { $langCode = $_ENV['LC_ALL']; } elseif (isset($_ENV['LANG']) && trim($_ENV['LANG'])) { $langCode = $_ENV['LANG']; } if (strlen($langCode) >= 2) { $langCodes = array(substr($langCode, 0, 2)); } } foreach ($langCodes as $langCode) { switch ($langCode) { case 'en': return 'english'; case 'fr': return 'french'; } } return 'english'; } else { return $language; } }
function matchStrings($userValue, $label) { // debug("matchStrings $label", $userValue); if(!strcasecmp($userValue, $label)) return true; $firstWord = substringBefore($label, " "); return startsWith($userValue, $firstWord); }
private static function sqlCondition(&$params, $key, $statement) { $value = $params[$key]; if ($value === NULL) { unset($params[$key]); return "{$key} is NULL"; } if (is_array($value) && startsWith($value[0], "%")) { unset($params[$key]); $sqlValue = $sep = ""; foreach ($value as $el) { $sqlValue .= "{$sep}{$key} LIKE '{$el}'"; $sep = " AND "; } return $sqlValue; } if (is_array($value)) { unset($params[$key]); $sqlValue = $sep = ""; foreach ($value as $el) { $sqlValue .= "{$sep}'{$el}'"; $sep = ","; } return "{$key} in ({$sqlValue})"; } //SQL operator $op = "="; if (endsWith($key, "_max")) { $op = "<="; $key = substringBefore($key, "_max"); } else { if (endsWith($key, "_min")) { $op = ">="; $key = substringBefore($key, "_min"); } else { if (contains($value, "%")) { $op = "LIKE"; } } } if ($statement) { return "{$key} {$op} ?"; } return "{$key} {$op} '{$value}'"; }