private function getUserData() { $users = array(); // Open up the users folder and loop through all the .user files foreach (scandir('config/users') as $file) { if (File::fileExtension($file) == "user") { // Extract the user information from the file into a useful format $userInfo = User::getUserInfo(File::fileName($file)); // Stuff the record into the result array $users[] = $userInfo; } } return $users; }
private function _formatContent() { global $C; $lf = $this->_lf; if ($this->_lastContent != $this->content && $this->_formattedContent != $this->content || $this->forceReformatContent) { $this->forceReformatContent = false; $this->_boundary = "_=======" . @date('YmdHms') . time() . "=======_"; $this->_lastContent = $this->content; $c = $this->content; $cImgs = ""; $formattedContent = ""; //Get server from 'from' e-mail for imgs cids. eg: server.com.br $arr = explode("@", $this->_from[0]); $server = $arr[1]; if ($this->attachImages) { //Find: <img... src=""...> and <... url() ...> $c = $this->content; $i = 0; $imgs = array(); while (preg_match('#<img(.+?)' . preg_quote("src", '/') . '(.+?)>|<(.+?)' . preg_quote("background=", '/') . '(.+?)>#i', $c, $m) && $i < 150) { if (strpos($m[0], "background=") > 0) { $imgs[] = array($m[0], str_replace(array("'", "\""), "", $m[4])); $pos = strpos($c, $m[0]) + strlen($m[0]); } else { $p2 = (int) strpos($m[2], '"', 2); $p1 = (int) strpos($m[2], "'", 2); if ($p1 == 0) { $p1 = $p2; } $imgs[] = array($m[0], substr($m[2], 2, $p1 - 2)); $pos = strpos($c, $m[0]) + strlen($m[0]); } $c = substr($c, $pos); $i++; } //Replace imgs urls to imgs cids and generate contents. $c = $this->content; $imgTags = array(); $imgFiles = array(); $allowedExtensions = array("jpg", "gif", "png"); foreach ($imgs as $v) { $tag = $v[0]; $path = $v[1]; if (array_search(File::extension($path), $allowedExtensions) !== false && array_search($tag, $imgTags) === false) { $fileName = File::fileName($path); $id = "IMG_" . str_replace(array("." . $ext, " "), "", $fileName) . "@" . $server; $img = str_replace($path, "cid:" . $id, $tag); if (strpos($c, $tag) !== false) { $imgTags[] = $tag; if (strpos($img, "moz-do-not-send=\"false\"") == false && strpos($img, "<img") !== false) { $img = substr($img, 0, strlen($img) - 1) . " moz-do-not-send=\"false\">"; } elseif (strpos($img, "url(") !== false) { } $c = str_replace($tag, $img, $c); if (array_search($path, $imgFiles) === false) { $imgFiles[] = $path; $cImgs .= "--" . $this->_boundary . $lf; $mime = File::mime($ext); $cImgs .= "Content-type: " . $mime . "; name=\"" . $fileName . "\"" . $lf; $cImgs .= "Content-Transfer-Encoding: base64" . $lf; $cImgs .= "Content-ID: <" . $id . ">" . $lf . $lf; $cImgs .= chunk_split(base64_encode($file->readFile($v[1]))) . $lf . $lf; } } } } } //Text plain content /*$formattedContent = "--" . $this->_boundary . "\n"; $formattedContent .= "Content-Type: text/plan; charset=iso-8859-1\n\n"; $formattedContent .= strip_tags(str_replace(array("\r\n", "\n\r", "\n", "<br>"), array("", "", "", "\n"), str_replace(array("<br/>", "<br />"), "<br>", substr($c, (int)strpos($c, "<body"))))) . "\n";*/ //echo $c; //Html content if ($cImgs != "") { $formattedContent .= "--" . $this->_boundary . $lf; $formattedContent .= "Content-Type: text/html; charset=UTF-8" . $lf . $lf; $formattedContent .= $c . $lf . $lf; } else { $formattedContent = $c; } //Images contents if ($cImgs != "") { $formattedContent .= $cImgs; $formattedContent .= "--" . $this->_boundary . "--" . $lf; } $this->_formattedContent = $formattedContent; } }
// Try to resolve the alias myself. if (!$file->read($file->meta['original'], 0)) { pieErrorImage(); } } } if (@$_REQUEST['size'] > 0) { $max = $_REQUEST['size']; } elseif ($GLOBALS['pie']['max_image_size']) { $max = intval($GLOBALS['pie']['max_image_size']); } else { $max = 256; } // Determine image file type. $type = $file->meta['type']; $name = $file->fileName($file->name, 0); if (!file_exists($name)) { pieErrorImage(); } if ((list($ow, $oh) = getimagesize($name, $_REQUEST['stamp'])) === false) { pieErrorImage(); } if ($ow <= $max && $oh <= $max) { dumpFile($name, $type); } // Check the cache for the thumbnail image. if ($GLOBALS['pie']['image_caching']) { $cache = new Cache(); $cid = $cache->key('image', array('file' => $_REQUEST['file'])); $path = $cache->file($cid); } else {
public function save($value) { $flag = $this->module->flag; $path = File::formatDir($this->path); $destPath = static::storagePath() . File::formatDir($this->path); File::mkdir($destPath); if (!is_writable($destPath)) { Response::code(500); return Response::json(array("error" => true, "error_description" => "Directory '" . $destPath . "' is not writtable.")); } $files = json_decode(Session::get($this->sessionKey), true); if ($flag == "U" || $flag == "D") { $oldFiles = $this->module->orm->field($this->name); if (!is_array(@json_decode($oldFiles, true))) { $oldFiles = json_encode(array()); } $oldFiles = json_decode($oldFiles, true); if ($flag == "U") { //Delete files that are on our table but not on our session list foreach ($oldFiles as $oldFile) { $found = false; foreach ($files as $file) { if (!array_key_exists("_tmpName", $file) && current($oldFile) == current($file)) { $found = true; break; } } if (!$found) { foreach ($oldFile as $sample) { File::delete(static::storagePath() . $sample); } } } } else { if ($flag == "D") { //Delete all files foreach ($oldFiles as $oldFile) { foreach ($oldFile as $sample) { File::delete(static::storagePath() . $sample); } } if (count(File::lsdir($destPath)) == 0) { File::rmdir($destPath); } } } } if ($flag == "C" || $flag == "U") { //Copy tmp files to it's target place and save foreach ($files as $k => $file) { if (array_key_exists("_tmpName", $file)) { $samples = array(); $im = new Image(); $i = 0; $tmpPath = static::tmpPath() . $file["_tmpName"]; foreach ($this->samples as $k2 => $sample) { //if ($k2 == 0) //{ $im->load($tmpPath); //} if (!array_key_exists("width", $sample)) { $sample["width"] = 0; } if (!array_key_exists("height", $sample)) { $sample["height"] = 0; } if ($sample["width"] != 0 || $sample["height"] != 0) { $im->resize($sample["width"], $sample["height"], $sample["resizeMethod"], $sample["background"]); } if ($this->customFilters) { foreach ($this->customFilters as $filter) { call_user_func($filter, $im); } } $fileName = $file["_name"]; if ($sample["key"] != "original") { $fileName = File::removeExtension($file["_name"]) . "-" . $sample["key"] . "." . File::extension($file["_name"]); } $unique = static::unique($destPath . $fileName); $im->save($unique); $samples[$sample["key"]] = $path . File::fileName($unique); $samples["caption"] = array_key_exists('caption', $file) ? $file['caption'] : ""; $i++; } File::delete($tmpPath); $files[$k] = $samples; } } $this->module->orm->setField($this->name, json_encode($files)); } }
public function save($value) { $flag = $this->module->flag; $path = File::formatDir($this->path); $destPath = static::storagePath() . File::formatDir($this->path); File::mkdir($destPath); if (!is_writable($destPath)) { Response::code(500); return Response::json(array("error" => true, "error_description" => "Directory '" . $destPath . "' is not writtable.")); } $files = json_decode(Session::get($this->sessionKey), true); if ($flag == "U" || $flag == "D") { $oldFiles = $this->module->orm->field($this->name); if (!is_array(@json_decode($oldFiles, true))) { $oldFiles = json_encode(array()); } $oldFiles = json_decode($oldFiles, true); if ($flag == "U") { //Delete files that are on our table but not on our session list foreach ($oldFiles as $oldFile) { $found = false; foreach ($files as $file) { if (!array_key_exists("_tmpName", $file) && $oldFile["path"] == $file["path"]) { $found = true; break; } } if (!$found) { File::delete(static::storagePath() . $oldFile["path"]); } } } else { if ($flag == "D") { //Delete all files foreach ($oldFiles as $oldFile) { File::delete(static::storagePath() . $oldFile["path"]); } if (count(File::lsdir($destPath)) == 0) { File::rmdir($destPath); } } } } if ($flag == "C" || $flag == "U") { //Copy tmp files to it's target place and save foreach ($files as $k => $file) { if (array_key_exists("_tmpName", $file)) { $unique = static::unique($destPath . $file["_name"]); File::move(static::tmpPath() . $file["_tmpName"], $unique); $files[$k] = array("path" => $path . File::fileName($unique), "caption" => array_key_exists('caption', $file) ? $file['caption'] : ""); } } $this->module->orm->setField($this->name, json_encode($files)); } }
private function getUnpublished() { $path = File::getUserSandboxPath(); $unpublished = array(); // Loop through all the .html files in the published folder foreach (scandir($path) as $file) { // We only want to show the files that the user can edit (html files) if (File::fileExtension($file) == "html") { $unpublished[] = array("name" => urlencode(File::fileName($file)), "path" => $path . $file); } } return $unpublished; }
public function get() { Session::verifySession(); // if editing existing page, load from file $fileData = ''; $currentPageName = $this->pageState['page']; // Determine if this page is already published $isPublished = false; if ($this->pageState['publish'] == '1') { $isPublished = true; } $this->view->isPublished = $isPublished; // Get the current page's contents if ($currentPageName != '') { if ($isPublished) { $fileData = file_get_contents(File::getUserSandboxPath() . $currentPageName . '.published'); } else { $fileData = file_get_contents(File::getUserSandboxPath() . $currentPageName . '.html'); } } $this->view->fileData = $fileData; // Load up page metadata (if it exists) // Load up existing page metadata information (if it exists) $pageTitle = ''; $pageDescription = ''; $pageKeywords = ''; $handle = @fopen(File::getUserSandboxPath() . $currentPageName . '.config', "r"); if ($handle) { // Read the title if (!feof($handle)) { $a = explode("|", fgets($handle)); $pageTitle = trim($a[1]); } // Read the description if (!feof($handle)) { $a = explode("|", fgets($handle)); $pageDescription = trim($a[1]); } // Read the keywords if (!feof($handle)) { $a = explode("|", fgets($handle)); $pageKeywords = trim($a[1]); } fclose($handle); } // Add to page state $this->view->pageState['pageTitle'] = $pageTitle; $this->view->pageState['pageDescription'] = $pageDescription; $this->view->pageState['pageKeywords'] = $pageKeywords; // Assemble a list of pages in the current folder (we hand this to editor control $pageList = array(); $path = File::getUserSandboxPath(); foreach (scandir($path) as $file) { // We only want to include the user files if (File::fileExtension($file) == "html" || File::fileExtension($file) == "published") { $pageList[] = File::fileName($file); } } $this->view->pageList = $pageList; // Render the view $this->view->setMainTemplate('PageTemplate'); $this->renderView('EditPageView'); }