'); unset( $_SESSION[NANO_CMS_ADMIN_LOGGED] ); } //the login form if( $_SESSION[NANO_CMS_ADMIN_LOGGED]!=md5(NANO_CMS_ADMIN_PASS.$_SESSION[ LOGIN_TIME_STAMP ]) or !isset( $_SESSION[NANO_CMS_ADMIN_LOGGED] ) ) { session_destroy(); runTweak( 'before-login-form' ); $form = "NanoCMS Admin login"; $form.= "
username
password
"; runTweak( 'login-form', array( &$form ) ); echo $form; exit(); } function checkBoxList($checkList,$selected=array() ,$return=true) { $op=''; foreach( $checkList as $key=>$ele ) { $keyname = $key;//str_replace('-','_',$key); $checked = ( in_array($key,$selected)?" checked=checked ":'' ); $val = "$key"; $op.= ""; $op.= "     "; } if($return) return $op; else echo $op; } //performEdit() function performEdit() { if( $_GET[action] != 'edit' ) return; global $editErrMsg; $slug = $_GET[slug]; $editErrMsg = array(); $catlist = getDetails('cats'); if( isset( $_POST[save] ) ) { $newp = new Page(); $newp->loadSlug($slug); $oldSlug = $slug; $newSlug = slugify( $_POST[title] ); //newp->slug; $fileName = pageDataDir($slug); $newFileName = $newName = pageDataDir( $newSlug ); if( $slug=='' ) $editErrMsg[]= lt("Title cannot be empty"); $newp->catReset(); foreach( $catlist as $cat=>$cc ) { if( isset( $_POST[ 'check_'.$cat ] ) ) $newp->addToCat( $cat ); } if( count($newp->cats) == 0 ) $newp->addToCat('other-pages'); if( $newSlug!=$oldSlug ) // if a slug change has occured { $renameErr = false; if( file_exists( $newName ) ) { $editErrMsg[] = lt("Cannot Rename Title: Another page with similar title already exists",'cannot-rename-title'); $renameErr = true; }else if( !rename($fileName,$newName) ) { $editErrMsg[]= lt("Error Renaming"); $renameErr = true; } if( !$renameErr ) //edit title only ifrename error has not occured $newp->editTitle( stripslashes($_POST[title]) ); $fileName = $newName; } runTweak( 'file-contents-edit', array( &$_POST[content] ) ); if( !put2file( $fileName, stripslashes( $_POST[content] ) ) ) $editErrMsg[]=lt("Error writing to file",'file-write-error'); } if( count($addtErrMsg)!=0 and isset($newp) ) { //error occured $em = ''; foreach( $addtErrMsg as $msg ) $em .= "
  • $msg
  • "; MsgBox( lt('Errors Occured')." : ", 'redbox' ); } elseif( isset($newp) ) { //success : no error $newp->commitChanges(); savepages(); $em = ''; $gmsg = array(); echo "

    ".lt( 'Edit Content' )."

    "; $gmsg[] = lt("Content Edited Successfully",'content-edit-success-msg'); foreach( $gmsg as $msg ) $em .= "
  • $msg
  • "; MsgBox( "" ); return; } $ep = new Page(); $ep->loadSlug($slug); $fileName = pageDataDir( $slug ); $formAction = "?action=edit&slug=$slug"; $fileContent = file_exists( $fileName )? htmlentities( file_get_contents( $fileName ) ) : lt("no content yet"); $submitButton = lt('Save Page Content'); $editLabel = lt( 'Edit Content' ); $catLabel = lt('Categories'); $contentLabel = lt('Content'); $title = $ep->title; $chkboxs = checkBoxList( getDetails('cats'), $ep->cats ); runTweak( 'edit-form-display' ); $dlink1= '?action=delete&slug='.$_GET['slug']; $deletejs = 'return confirm(\'Are your sure you want to deleate '.$_GET['slug'].'?\nYou cant undo this action!\');'; echo $te=<<

    $editLabel : $ep->title

    Page Title
    $catLabel $chkboxs

    $contentLabel


    | Delete
    TET; runTweak( 'after-edit-form-display' ); } //doAreaEdit() function doAreaEdit() { if( isset($_GET['do']) and $_GET['do']=='editarea' ) { $areaCount = stripslashes($_POST[areaCount]); $errCnt = 0; for( $i=1; $i<=$areaCount; $i++ ) { $areaNamei = stripslashes($_POST["areaName$i"]); $areaContenti = stripslashes($_POST["areaContent$i"]); $areaFilei = areaDataDir( "$areaNamei" ); if( !put2file( $areaFilei, $areaContenti ) ) { $errCnt++; $msg = sprintf( lt("Error saving area : %s to file %s",'error-saving-area-to-file'), $areaNamei, $areaFilei ); MsgBox( $msg ); } } if( $errCnt == 0 ) MsgBox( lt("All Area contents saved Successfully",'areas-save-success' ) ); } } //addpage() function addpage(){ $addtErrMsg = array(); $catlist = getDetails('cats'); $newp = new Page(); $newp->newPageInit(); $newp->addToCat( 'sidebar' ); if( isset( $_POST[save] ) ) { $isFormSubmitted = true; $content = stripslashes($_POST[content]); $title = stripslashes($_POST[title]); $newp->editTitle( $title ); $slug = $newp->slug; $newp->catReset(); foreach( $catlist as $cat=>$cc ) { if( isset( $_POST[ 'check_'.$cat ] ) ) $newp->addToCat( $cat ); } if( count($newp->cats) == 0 ) $newp->addToCat('sidebar'); if( $title != '' and $content !='' ) { $newPageFile = pageDataDir($slug); if( !file_exists($newPageFile) ) { //view all cats $newp->commitChanges(); //debug($newp); runTweak( 'new-page', array( 'page-obj'=>&$newp, 'page-content'=> &$content ) ); if( put2file( $newPageFile, $content ) ) savepages(); $m = lt("The page was created successfully",'page-create-success'). '
    '; $m .= lt("File Created") ." : ".$newPageFile."
    "; $m .= lt("Content")." : ".substr( strip_tags($content), 0, 100 ).( strlen($content)>100 ? '...' : '' )."
    "; MsgBox( $m ); return; // success } else { $addtErrMsg[] = lt("Save Failed"); if( file_exists($newPageFile) ) $addtErrMsg[] = lt("A page with similar Title already exists!!",'similar-page-title-exists'); } } else $addtErrMsg[] = lt("Either the title or the content is/are empty!!! Please check your input!!
    ",'title-or-content-empty'); //die('fucked'); //savepages(); } if( count($addtErrMsg)!=0 and isset($title) ) { //error occured $em = ''; foreach( $addtErrMsg as $msg ) $em .= "
  • $msg
  • "; MsgBox( lt("Errors Occured")." : ", 'background:#FFE8E8;border:1px solid #AE0000' ); } //debug($addtErrMsg); $formAction = "?action=addpage"; $submitButton = lt('Add Page'); $chkboxs = checkBoxList( getDetails('cats'), $newp->cats ); $pageTitleLabel = lt('Page Title'); $catsLabel = lt('Categories'); $contentLabel = lt('Content'); $addnewpageLabel = lt('Add new Page'); echo $te=<<

    $addnewpageLabel

    $pageTitleLabel
    $catsLabel $chkboxs

    $contentLabel


    TET; runTweak( 'after-add-form-display' ); } //performMove() function performMove() { if( $_GET[action]=='reorder' ) { $par = explode(',',$_GET[param]); $par[0] = (int)$par[0]; $par[1] = (int)$par[1]; reorder( $_GET[cat], $par[0], $par[1] ); savepages(); $_SESSION[opencat]=$_GET[cat]; header( "Location:nanoadmin.php?action=pageorder" ); } } //New Function //pageOrder() function pageOrder(){ $cdt = getDetails('cats'); $slugs = getDetails('slugs'); $titles = getDetails('titles'); foreach($cdt as $catname=>$catslugs) { $slugids = array_values($catslugs); $n = count($slugids)-1; foreach($slugids as $pos=>$ids) { $ul = makeLink("?action=reorder&cat=$catname¶m=".$pos.','.($pos-1),'up'); $dl = makeLink("?action=reorder&cat=$catname¶m=".$pos.','.($pos+1),'down'); if( $pos==0 ) $ul='up'; if( $pos==$n ) $dl='down'; echo "".$titles[$ids]."$ul | $dl
    "; } } } //reorder() function reorder($cat,$pos1,$pos2) { $cats = getDetails('cats'); $cc = $cats[$cat][$pos1]; $cats[$cat][$pos1] = $cats[$cat][$pos2]; $cats[$cat][$pos2] = $cc; setDetails('cats',$cats); } //savepages() function savepages() { global $nc; runTweak( 'on-save-pages' ); $pagesdata = serialize( $nc ); if( !put2file( PAGES_DETAILS_FILE, $pagesdata ) ) MsgBox( lt("file writing error"), 'redbox' ); } //doDelete() function doDelete() { $slug = $_GET[slug]; $slugList = getDetails('slugs'); $titleList = getDetails('titles'); $hp = getDetails('homepage'); $delpg = new Page(); $delpg->loadSlug($slug); $title = $titleList[ $delpg->slugId ]; if( $delpg->slugId == $hp ) { $msg = sprintf( lt("Cannot Delete %s : Your homepage cannot be deleted",'cannot-delete-homepage'),$title ); MsgBox( $msg, 'redbox' ); return; } runTweak( 'on-delete-page', array('page'=>$delpg) ); $delpg->catReset(); $delpg->commitChanges(); unset( $slugList[ $delpg->slugId ] ); unset( $titleList[ $delpg->slugId ] ); unlink( pageDataDir( $delpg->slug ) ); setDetails('slugs',$slugList); setDetails('titles',$titleList); savepages(); $msg = sprintf( "".lt("Page '%s' was Successfully Deleted",'page-delete-success').'',"$title" ); echo '
    '; MsgBox( $msg, 'greenbox' ); } //showareas() function showareas() { doAreaEdit(); global $indexTemplateAreas; demoExecuteNanoSite(); $sett = getDetails('settings'); $contents = $sett['def-template-areas']; $areaInfo = array(); foreach( $contents as $areaName ) { $areaFile = areaDataDir( "$areaName" ); $fileContent = file_exists($areaFile) ? file_get_contents( $areaFile ) : ''; $areaInfo[ $areaName ] = $fileContent; } $saveAllTxt = lt('Save all Areas'); $biggerInp = lt('Bigger Input Box'); $smallerInp = lt('Smaller Input Box'); echo "
    "; echo ""; echo ""; $cnt = 1; foreach( $areaInfo as $areaName=>$areaContents ) { $boxId = "box$cnt";//md5($areaName); echo "

    » $areaName

    "; $cnt++; } echo ""; echo "
    "; } function showTweaksInterface() { global $tweakInterfaceList, $tweakList, $tweakData; $tweakName = stripslashes($_GET[tweak]); $tDet = $tweakData[ $tweakName ]; $name = $tDet['name']; $ifunc = $tDet['interface']; $author = $tDet['author']; $authTxt = lt('Author'); $descTxt = lt('Description'); $optdatTxt = lt('Options and Data'); $optTxt = lt('Options'); $nameTxt = lt('Name'); echo "

    $name

    "; echo "$authTxt : $tDet[author]
    "; echo "$descTxt : $tDet[desc]"; echo "

    $optdatTxt

    "; if( is_callable($ifunc) ) call_user_func( $ifunc ); } //showTweakers() - the tweakers interface function showTweakers() { global $tweakInterfaceList, $tweakList, $tweakData; $activeTweaks = getDetails( 'active-tweaks' ); $descTxt = lt( 'Description' ); $optTxt = lt( 'Options' ); if( isset( $_GET['do'] ) ) { $do = $_GET['do']; $tweak = $_GET['tweak']; if( $do == 'activate' && !in_array( $tweak, $activeTweaks ) ) { $activeTweaks[] = $tweak; echo MsgBox( lt( 'Tweak Activated' ) ); } if( $do == 'deactivate' && in_array( $tweak, $activeTweaks ) ) { $activeTweaks = array_diff( $activeTweaks, (array)$tweak ); echo MsgBox( lt( 'Tweak Deactivated' ) ); } setDetails( 'active-tweaks', $activeTweaks ); savepages(); } $tweakerDescTxt = lt("Tweakers are plugins like tools which can be used to tweak the NanoCMS
    ",'tweakers-desc'); echo "

    Tweakers

    "; echo "

    $tweakerDescTxt

    "; echo "

    ".lt('Active Tweakers')."

    "; $t = ""; $t.= ""; $viewInterfaceLable = lt('View Interface'); foreach( $tweakData as $tweakName=>$tweakInfo ) { if( in_array( $tweakName , $activeTweaks ) ) $Lable = makeLink( "?action=tweakers&do=deactivate&tweak=$tweakName", lt('Deactivate') ); else $Lable = makeLink( "?action=tweakers&do=activate&tweak=$tweakName",lt('Activate') ); $desc = $tweakData[ $tweakName ][ 'desc' ]; $opt = ''; $name = $tweakData[ $tweakName ][ 'name' ]; if( isset($tweakData[ $tweakName ]['interface']) ) { $opt = makeLink( "?tweak=$tweakName", $viewInterfaceLable ); } $twk = $tweakData[ $tweakName ][ 'tweaks' ]; // debug( $twk ); $tcnt = count( $twk ); $t.= ""; } $t.= "
    Tweaker $nameTxt$descTxtTweaks$optTxt 
    $name $desc$tcnt $opt $Lable
    "; runTweak( 'before-tweakerlist-display', array( &$t ) ); echo $t; } //showpageslist() function showpageslist() { global $nc; demoExecuteNanoSite(); $cdt = getDetails('cats'); $sett = getDetails('settings'); $slugs = getDetails('slugs'); $titles = getDetails('titles'); $templateCats = $sett['def-template-links']; $defaultCats = explode( ',', NANO_MUSTHAVE_CATS ); $musthaveCats = array_unique( array_merge( $templateCats, $defaultCats ) ); $selectedCat = 1; $toggStat = 'false'; if( isset($_GET[addcat]) ) { $newCatName = strtolower( stripslashes($_POST[catname]) ); if( in_array( $newCatName, array_keys($cdt) ) ) { $msg = sprintf( lt( "Cannot add new Links Category : %s already exists",'cat-add-fail-already-exists'), "$newCatName" ); MsgBox( $msg ); } else { $cdt[$newCatName] = array(); $msg = sprintf( lt( "Pages Category %s Added Successfully",'cat-add-success'), "$newCatName" ); MsgBox( $msg,'greenbox' ); setDetails( 'cats', $cdt ); savepages(); } } if( isset($_GET[removecat]) ) { $catN = $_GET[removecat]; if( !in_array($catN,array_keys($cdt) ) ) MsgBox( lt("Category to be deleted does not exist",'cat-to-del-not-exists'), 'redbox' ); else if( in_array( $catN, $musthaveCats ) ) MsgBox( "$catN : ".lt('Cannot be deleted'), 'redbox' ); else { unset( $cdt[ $catN ] ); $msg = sprintf( lt( "Pages Category %s was removed Successfully",'cat-remove-success'), "$catN" ); MsgBox( $msg,'greenbox' ); setDetails( 'cats', $cdt ); savepages(); } } $catSelectList = array(); foreach( $cdt as $cN=>$cSC ) $catSelectList[$cN] = $cN; $pagesAndOpt = lt( 'Pages & Category Options','page-and-cat-opt' ); $pagesListing = lt( 'Pages & Category Listing','page-and-cat-list' ); $addNewCat = lt( 'Add new Category' ); $addToAnotherCat = lt( 'Add page to another category', 'add-page-to-another-cat' ); $addLabel = lt( 'Add' ); echo "

    $pagesAndOpt

    $addNewCat :
    "; } // automatically gets the content_areas present in the template //////////////////////////////// $indexTemplateAreas = $indexTemplateLL = array(); function readIntoAreaList($l,$a='',$b='') { global $indexTemplateAreas; $indexTemplateAreas[] = $l; } function readIntoLinksList($cat,$f='',$a='',$b='',$c='') { global $indexTemplateLL; $indexTemplateLL[] = $cat; } function demoExecuteNanoSite() { global $indexTemplateAreas,$indexTemplateLL; $sett = getDetails('settings'); $catt = getDetails('cats'); $indexLastModified = filemtime(NANO_CMS_PAGE); if( $sett['index-last-modified'] >= $indexLastModified ) return; $removeFunctionList = array('show_sidebar','show_content_slug','show_title','require_once'); $replaceFunction = 'dummyFunction'; $demoContentToRun = file_get_contents( NANO_CMS_PAGE ); $demoContentToRun = str_replace( 'show_content_area', 'readIntoAreaList', $demoContentToRun ); $demoContentToRun = str_replace( 'show_links', 'readIntoLinksList', $demoContentToRun ); $demoContentToRun = str_replace( $removeFunctionList, $replaceFunction, $demoContentToRun ); ob_start(); //eval(" > ".$demoContentToRun." ?php "); $cont = ob_get_contents(); ob_end_clean(); MsgBox( lt("Template Changes Detected! Config & Settings updated!",'template-changes-detected') ); $newcatt = array_diff( $indexTemplateLL,array_keys($catt) ); foreach( $newcatt as $newcatname ) $catt[$newcatname] = array(); $sett['index-last-modified'] = $indexLastModified; $sett['def-template-areas'] = array_unique( $indexTemplateAreas ); $sett['def-template-links'] = array_unique( $indexTemplateLL ); setDetails( 'settings', $sett ); setDetails( 'cats', $catt ); savepages(); } performMove(); ?> Admin Area
    $catslugs) { $slugids = array_values($catslugs); $n = count($slugids)-1; $ucatname = ucfirst($catname); echo '
    '; echo $ucatname; echo '
    '; if( count($slugids) == 0 ) { echo "
  • No Pages Found :(
  • \n"; continue; } echo "\n"; foreach($slugids as $pos=>$ids) { $ul = makeLink("?action=reorder&cat=$catname¶m=".$pos.','.($pos-1),'up'); $dl = makeLink("?action=reorder&cat=$catname¶m=".$pos.','.($pos+1),'down'); if( $pos==0 ) $ul='up'; if( $pos==$n ) $dl='down'; echo "\n"; } echo "
    ".$titles[$ids]."   $ul | $dl
    \n"; } break; } if( isset($_GET[tweak]) ){ showTweaksInterface(); die ('
    '); } if(!$_GET['action']){ ?>

    Weclome [username], to your admin panel!.

    Explore, Add, and manage your site, all in one place!.
    use the sidebar to the left to start updating!
    (<-------)

    Server News

    Loading the ajax...