$post) { $post = thecleaner($post); if (preg_match("/^edit/", $key)) $edit[$key] = $post; } } function loadfile($url, $incpath, $f) { global $message, $includes, $pagepath, $doctype, $encode, $edit; $ssi = false; $pagename = (strstr($url, $_SERVER['DOCUMENT_ROOT'])) ? explode($_SERVER['DOCUMENT_ROOT'], $url) : explode('../../', $url); $pagename = trim($pagename[1], '/'); $pagename = str_ireplace('/', '-', $pagename); $pagefile = $pagename; if (@file_exists($url)) { // read the file $doc = fopen($url, "r"); $content = stream_get_contents($doc); fclose($doc); if ((!stristr($content, '[^<]+]*>/', $content)) { preg_match_all('/]*>/', $content, $dtarr); $doctype = $dtarr[0][0]; } if (preg_match('/(?:]*charset=\"*)([^\"<]+)/', $stuff)) { preg_match_all($charreg, $stuff, $enc); $encode = $enc[1][0]; } if ($f) cleanpost(); $elereg = '/<[^>]*class=(?:\"|\'|)[^>]*(\bneocms\b|\bneocmsRepeatArea\b)[^>]*?(?:\"|\'|)[^>]*>/'; $reginclude = '/(?:include\b|include_once\b|require\b|require_once\b)(?:\s*\(*[^;\?>]*)(?:\"|\')([^\"\'<>]*)(?:(\"|\')\)*(;|[\s\t\r\n]*\?>))/i'; // php include regexp if (!preg_match($reginclude, $content)) $reginclude = '/(?:)/i'; // SSI regexp // create a backup $pageext = explode('.', $pagename); $pagename = preg_replace('/(\.php|\.asp|\.html|\.htm|\.phtml|\.shtml|\.cfm)/', '', $pagename); $backup = dirname(__FILE__) . '/../backups/' . $pagename . '_Bak.' . $pageext[1]; if (is_writable($url)) { $backdoc = fopen($backup, "w+"); fwrite($backdoc, $content); fclose($backdoc); } else $message = 'Error: You do not have permission to edit this page: ' . $pagefile . "."; // clean up content if (preg_match($reginclude, $content)) { preg_match_all($reginclude, $content, $includes[$url]); $incArr = preg_split($reginclude, $content); $incfiles = $includes[$url][1]; $neoCon = array(); foreach ($incArr as $k => $v) { $docroot = $_SERVER['DOCUMENT_ROOT']; if (@file_exists($docroot . $incfiles[$k]) && $incfiles[$k] != '') { $neoCon[$k] = $v; $incfile = $docroot . $incfiles[$k]; $incpath = false; } elseif (!stristr($incfiles[$k], 'http://')) { $neoCon[$k] = $v; $incfile = "$pagepath/$incfiles[$k]"; if ($incpath) { $incpathreg = str_replace('/', '\/', $incpath); $incpathreg = '/(^' . $incpathreg . '\/|\/' . $incpathreg . '\/)/'; $incorigpath = preg_replace($incpathreg, '', $incfiles[$k], 1); $newinc = "$pagepath/$incpath/$incorigpath"; $incfile = (@file_exists($newinc)) ? $newinc : $incfile; $incpatharr = explode('/', $incorigpath); array_pop($incpatharr); $incpath = (sizeof($incpatharr) > 0) ? $incpath . implode('/', $incpatharr) : false; } else { $incpatharr = explode('/', $incfiles[$k]); array_pop($incpatharr); $incpath = (sizeof($incpatharr) > 0) ? $incpath . implode('/', $incpatharr) : false; } } else $incpath = false; if (!preg_match('/\/$/', $incfile)) $neoCon[$incfile] = loadfile($incfile, $incpath, false); } return $neoCon; } else return $content; } } else return false; } function output() { global $message; $script = ''; echo $script; } function conArray($content) { $conArray = false; foreach ($content as $con) { if (is_array($con)) $conArray = true; } return conArray; } function makeEdits($conpost) { global $edit, $eles, $inc, $count; $commreg = '//'; preg_match_all($commreg, $conpost, $comments); $conpost = preg_replace($commreg, '', $conpost); $elereg = '/<[^>]*class\s*=\s*(?:\"|\'|)[^\"|\']*(\bneocms\b|\bneocmsRepeatArea\b)[^\"|\'|=]*?(?:\"|\'|)[^>]*>/'; preg_match_all($elereg, $conpost, $neocmseles); if ($neocmseles[0]) { $newsplice = ''; foreach ($neocmseles[0] as $neocmsele) { $splice = explode($neocmsele, $conpost, 2); $newsplice = $splice[0]; $post = $splice[1]; $rest = ''; preg_match_all("/^<([^>\s]*)\b/i", $neocmsele, $eleTag); $eleTag = $eleTag[1][0]; if (stristr($eleTag, 'img')) { if (isset($edit["editImg$count"])) { $editStr = array(); $editIncom = $edit["editImg$count"]; $editIncom = explode(',', $editIncom); foreach ($editIncom as $eikey => $eipost) { $eipost = explode('::', $eipost); $editStr[$eipost[0]] = $eipost[1]; } $editContent = ''; if (isset($editStr['link']) && $editStr['link'] != '') { if (preg_match('/(]*>)$/', $newsplice)) { preg_match_all('/(]*href=(?:\"|\'))([^\"\s]*)((?:\"|\')[^>]*>)$/', $newsplice, $lastlink); $newlink = $lastlink[1][0] . $editStr['link']; if ($editStr['rel'] != '') $newlink .= '" rel="' . $editStr['rel']; $newlink .= $lastlink[3][0]; $newsplice = preg_replace('/(]*>)$/', "$newlink", $newsplice); } else { $newsplice .= ']*>)$/', $newsplice)) $newsplice = preg_replace('/(]*>)$/', '', $newsplice); if (preg_match('/^(<\/a>)/', $post)) $post = preg_replace('/^(<\/a>)/', '', $post); } $editContent .= '' . $editStr['alt'] . ']*>/i'; preg_match_all($eleTagReg, $post, $tags); $contents = preg_split($eleTagReg, $post); $track = 1; foreach ($tags[0] as $tag) { if (strpos($tag, ' 1) { foreach ($tags[0] as $tag) { if (isset($edit["editVid$count"])) $rest .= $contents[0]; else $rest .= $tag . $contents[0]; array_shift($contents); } } else { if (isset($edit["editVid$count"])) $rest = $contents[0]; else $rest = $tags[0][0] . $contents[0]; } } $neocmsele = preg_replace('/neocms\b|neocmsRepeatArea\b/', '$0--D0n3--', $neocmsele); if (isset($edit["edit$count"])) $newsplice .= $neocmsele . "\n" . $edit["edit$count"] . "\n" . $rest; elseif (isset($edit["editImg$count"]) && stristr($eleTag, 'img')) $newsplice .= $post; elseif (isset($edit["editVid$count"]) && (stristr($eleTag, 'embed') || stristr($eleTag, 'object'))) $newsplice .= "\n" . $edit["editVid$count"] . "\n" . $rest; elseif (sizeof($splice) <= 1) $newsplice .= $post; else $newsplice .= $neocmsele . $post; $conpost = $newsplice; $count++; $rest = ''; } $newsplice = preg_replace('/--D0n3--/', '', $newsplice); } else $newsplice = $conpost; foreach ($comments[0] as $com) { $newsplice = preg_replace('//', $com, $newsplice, 1); } return $newsplice; } function editFile($content, $url) { global $message, $includes, $edit, $inc; $fileedits = array(); if (is_array($content)) { foreach ($content as $conkey => $conpost) { if (is_array($conpost)) $content[$conkey] = editFile($conpost, $conkey); else $content[$conkey] = makeEdits($conpost); } foreach ($content as $ckey => $cpost) { if (preg_match('/^(\d+)$/', $ckey)) { if (isset($includes[$url][0][$inc])) $fileedits[$url] .= $cpost . $includes[$url][0][$inc]; else $fileedits[$url] .= $cpost; $inc++; } else $fileedits["$ckey"] = $cpost; } } else $fileedits[$url] = makeEdits($content); $inc = 0; return $fileedits; } function cleanFilecon($files) { global $filecon; foreach ($files as $fkey => $fpost) { if (is_array($fpost)) cleanFilecon($fpost); else { if (!$filecon[$fkey]) $filecon[$fkey] = $fpost; } } } function flatten($ar) { $toflat = array($ar); $res = array(); while (($r = array_shift($toflat)) !== NULL) { foreach ($r as $v) { if (is_array($v)) { $toflat[] = $v; } else { $res[] = $v; } } } return $res; } $conArr = loadfile($pageurl, false, true); if (is_array($conArr)) { $missing = array_search(false, $conArr); if ($conArr[$missing] == '') $missing = false; } elseif ($conArr) $missing = false; if ($missing === false) { cleanFilecon(editFile($conArr, $pageurl)); if (preg_match('/successfully/', $message)) { foreach ($filecon as $fkey => $fpost) { if ($fpost != '') { if (@file_exists($fkey)) { if (is_writable($fkey)) { $doc = fopen($fkey, "w"); fwrite($doc, $fpost); fclose($doc); } else $message = "Error: You do not have permission to edit this page."; } else $message = 'Error: neocms is unable find this page.'; } } } } else $message = 'Error: neocms is unable find this page: ' . $missing . ''; output(); } else output(); } } else { $message = 'Error: neocms is unable find your session.'; output(); } ?>