function put($putWhat, $justReturnValue = False, $historyInc = array()) { global $mode, $pathToRoot, $pathToRoot2, $whereWeAre; $pageName = basename($_SERVER["SCRIPT_NAME"]); if (strpos($putWhat, '/')) { $putWhat = str_replace('SITEROOT/', '', $putWhat); $includeFileName = str_replace(array('<<', '>>'), '', $putWhat); // FREE INCLUDE if ($mode == "preview") { $includeFilePath = $pathToRoot . CMSDIRNAME . '/includes/' . $includeFileName; } else { $includeFilePath = $pathToRoot . $includeFileName; } } else { // CHILD INCLUDE if ($mode == 'preview') { $includeFilePath = $pathToRoot . CMSDIRNAME . '/includes/' . $whereWeAre . stripFileExtension(basename($_SERVER["SCRIPT_NAME"])) . '_cms_files/cms_preview/' . $putWhat; } else { $includeFilePath = $pathToRoot . CMSDIRNAME . '/includes/' . $whereWeAre . stripFileExtension(basename($_SERVER["SCRIPT_NAME"])) . '_cms_files/cms_live/' . $putWhat; } } // Prevent circular includes! if (in_array($includeFilePath, $historyInc)) { echo '<!-- Warning: Loop caused in includes! -->'; return false; } else { array_push($historyInc, $includeFilePath); } /* If the file doesn't exist, try looking in the page's own directory (i.e. remove the /page_cms_files/cms_live|preview/ bit... */ if (!file_exists($includeFilePath)) { $alternativePath = $pathToRoot . CMSDIRNAME . '/includes/' . $whereWeAre . basename($includeFilePath); if (file_exists($alternativePath)) { $includeFilePath = $alternativePath; } } $fileContents = @file_get_contents($includeFilePath); if ($fileContents !== False) { switch (getFileExtension($includeFilePath)) { case "text": $nestResult = nestIncludes($fileContents, $historyInc); $fileContents = $nestResult[0]; $historyInc = $nestResult[1]; if (!$justReturnValue) { echo $fileContents; } else { return $fileContents; } break; case "html": $nestResult = nestIncludes($fileContents, $historyInc); $fileContents = $nestResult[0]; $historyInc = $nestResult[1]; $fileContents = str_replace('"cmsimages/', '"' . CMSDIRNAME . '/cmsimages/', $fileContents); // May be redundant now? // $fileContents = str_replace('href="/' , 'href="' . $pathToRoot2 . '/', $fileContents) ; REDUNDANT $fileContents = convertSmartQuotes($fileContents); if (!$justReturnValue) { echo $fileContents; } else { return $fileContents; } break; case "set": if (!$justReturnValue) { renderSet($fileContents, False, $historyInc); } else { return renderSet($fileContents, True, $historyInc); } break; case "phpx": ob_start(); include $includeFilePath; $contents = ob_get_contents(); ob_end_clean(); echo $contents; break; } } else { if ($mode == 'preview') { echo '<!-- Not found: ' . $includeFilePath . ' -->'; } } }
// future: this will be a user-uploaded template $fp = fopen($filename, 'r'); // open for reading stream only $output = fread($fp, filesize($filename)); //prepare the output variable fclose($fp); // replace the place holders in the template with our data // future: allow users to define things to replace, so this will not be hardcoded $output = str_replace('[[BOOK TITLE]]', $bookTitle, $output); $output = str_replace('[[AUTHOR NAME]]', $author, $output); $output = str_replace('[[COPYRIGHT]]', $copyright, $output); $libraryItems = $tei->xpath->query("//tei:div[@type='libraryItem']"); $subOutput = ""; for ($i = 0; $i < $libraryItems->length; $i++) { $title = convertSmartQuotes($tei->xpath->query("tei:head/tei:title/text()", $libraryItems->item($i))->item(0)->wholeText); $htmlContent = convertSmartQuotes($tei->xpath->query("body", $libraryItems->item($i))->item(0)->textContent); $subOutput .= "\\par {$title}"; $subOutput .= "\\par"; $subOutput .= "\\par {$htmlContent}"; $subOutput .= "\\par"; $subOutput .= "\\par"; } $replaceChunk = "[[BLOG CONTENT]]"; $output = str_replace($replaceChunk, $subOutput, $output); //generate the headers to help a browser choose the correct application header("Content-type: application/rtf"); header("Charset=UTF-8"); header("Content-Disposition: attachment; filename={$fileName}.{$ext}"); header("Pragma: no-cache"); header("Expires: 0"); // send the generated document to the browser
//Utility function, maybe should be moved for use elsewhere. Seems like it has a multitude of possible hook points function convertSmartQuotes($string) { //UTF-8 $search = array("‘", "’", "“", "”", "–", "—", "…"); $replace = array("'", "'", '"', '"', '-', '--', '...'); $string = str_replace($search, $replace, $string); //Windows $search = array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)); $replace = array("'", "'", '"', '"', '-', '--', '...'); $string = str_replace($search, $replace, $string); return $string; } if (!empty($_REQUEST['edit'])) { global $gBitContent; $_REQUEST['edit'] = convertSmartQuotes($_REQUEST['edit']); } if (!empty($_REQUEST['saveImage']) || !empty($_REQUEST['regenerateThumbnails'])) { if (empty($_REQUEST['gallery_id']) && empty($_REQUEST['image_id'])) { // We have no way to know what gallery to add an image to or what image to edit! $gBitSmarty->assign('msg', tra("No gallery or image was specified")); $gBitSystem->display("error.tpl", NULL, array('display_mode' => 'edit')); die; } // Store/Update the image if (isset($_FILES['imageFile']) && is_uploaded_file($_FILES['imageFile']['tmp_name'])) { $_REQUEST['_files_override'] = array($_FILES['imageFile']); $_REQUEST['_files_override']['process_storage'] = STORAGE_IMAGE; $replaceOriginal = $gContent->getSourceFile(); if (file_exists(dirname($replaceOriginal) . '/original.jpg')) { unlink(dirname($replaceOriginal) . '/original.jpg');