Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 2068)
+++ branches/2.8.x/CHANGELOG	(revision 2069)
@@ -11,6 +11,8 @@
 ! = Update/Change
 ===============================================================================
 
+03 Jan-2014 Build 2069 Manuela v.d.Decken(DarkViper)
+! module News: some little fixes, implementation of AccessFile completed.
 03 Jan-2014 Build 2068 Manuela v.d.Decken(DarkViper)
 # admin/users/user_list  corrected multibyte handling
 # Droplet - iEditThisPage: copy/past error fixed (object reference)
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 2068)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 2069)
@@ -51,5 +51,5 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.4');
-if(!defined('REVISION')) define('REVISION', '2068');
+if(!defined('REVISION')) define('REVISION', '2069');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/modules/news/view.php
===================================================================
--- branches/2.8.x/wb/modules/news/view.php	(revision 2068)
+++ branches/2.8.x/wb/modules/news/view.php	(revision 2069)
@@ -23,8 +23,6 @@
 }
 /* -------------------------------------------------------- */
 global $post_id, $post_section,$TEXT,$MESSAGE;
-$sMediaUrl = WB_URL.MEDIA_DIRECTORY;
-
 // load module language file
 $lang = (dirname(__FILE__)) . '/languages/' . LANGUAGE . '.php';
 require_once(!file_exists($lang) ? (dirname(__FILE__)) . '/languages/EN.php' : $lang );
Index: branches/2.8.x/wb/modules/news/upgrade.php
===================================================================
--- branches/2.8.x/wb/modules/news/upgrade.php	(revision 2068)
+++ branches/2.8.x/wb/modules/news/upgrade.php	(revision 2069)
@@ -188,6 +188,50 @@
 			     . 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
 			$oDb->query($sql);
 		}
+/* --- insert SYSVAR placeholders and repair already existing ------------------------- */
+        $sql = 'SELECT `post_id`, `content_long`, `content_short` '
+             . 'FROM `'.$oDb->TablePrefix.'mod_news_posts` ';
+        if (($oEntrySet = $oDb->doQuery($sql))) {
+            $iRecords = 0;
+            $iReplaced = 0;
+            $aSearch = array( '/\{SYSVAR\:MEDIA_REL\}[\/\\\\]?/sU',
+                              '/\{SYSVAR\:WB_URL\}[\/\\\\]?/sU',
+                              '/(\{SYSVAR\:AppUrl\.MediaDir\})[\/\\\\]?/sU',
+                              '/(\{SYSVAR\:AppUrl\})[\/\\\\]?/sU'
+                            );
+            $aReplace = array( '{SYSVAR:AppUrl.MediaDir}', '{SYSVAR:AppUrl}', '\1', '\1' );
+            while (($aEntry = $oEntrySet->fetchRow(MYSQL_ASSOC))) {
+                $iCount = 0;
+                $aSubject = array($aEntry['content_long'], $aEntry['content_short']);
+                $aNewContents = preg_replace($aSearch, $aReplace, $aSubject, -1, $iCount);
+                if ($iCount > 0) {
+                    $iReplaced += $iCount;
+                    $sql = 'UPDATE `'.$oDb->TablePrefix.'mod_news_posts` '
+                         . 'SET `content_long`=\''.$oDb->escapeString($aNewContents[0]).'\', '
+                         .     '`content_short`=\''.$oDb->escapeString($aNewContents[1]).'\' '
+                         . 'WHERE `post_id`='.$aEntry['post_id'];
+                    $oDb->doQuery($sql);
+                    $iRecords++;
+                }
+            }
+            $msg[] = '['.$iRecords.'] records with ['.$iReplaced.'] SYSVAR placeholder(s) repaired'." $OK";
+        }
+        try {
+            $sql  = 'UPDATE `'.$oDb->TablePrefix.'mod_news_posts` ';
+            $sql .= 'SET `content` = REPLACE(`content`, \'"'.$oReg->AppPath.$oReg->MediaDir.'\', \'"{SYSVAR:AppPath.MediaDir}\')';
+            $oDb->doQuery($sql);
+            $msg[] = 'Change internal absolute Media links into SYSVAR placeholders'." $OK";
+        } catch(WbDatabaseException $e) {
+            $msg[] = ''.$oDb->get_error();
+        }
+        try {
+            $sql  = 'UPDATE `'.$oDb->TablePrefix.'mod_news_posts` ';
+            $sql .= 'SET `content` = REPLACE(`content`, \'"'.$oReg->AppPath.'\', \'"{SYSVAR:AppPath}\')';
+            $oDb->doQuery($sql);
+            $msg[] = 'Change internal absolute links into SYSVAR placeholders'." $OK";
+        } catch(WbDatabaseException $e) {
+            $msg[] = ''.$oDb->get_error();
+        }
 /* --- rebuild all access files ------------------------------------------------------- */
 		$aReport = array('FilesDeleted'=>0,'FilesCreated'=>0,);
 		$oReorg = new m_news_Reorg(ModuleReorgAbstract::LOG_EXTENDED);
Index: branches/2.8.x/wb/modules/news/modify_post.php
===================================================================
--- branches/2.8.x/wb/modules/news/modify_post.php	(revision 2068)
+++ branches/2.8.x/wb/modules/news/modify_post.php	(revision 2069)
@@ -65,10 +65,14 @@
     $sMediaUrl = WB_URL.MEDIA_DIRECTORY;
     // Get header and footer
     $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_news_posts` WHERE `post_id`='.(int)$post_id;
-    if($oPostRes = $database->query($sql)){
+    if (($oPostRes = $database->query($sql))) {
     	$aPostRec = $oPostRes->fetchRow(MYSQL_ASSOC);
-    	$aPostRec['content_short'] = str_replace('{SYSVAR:MEDIA_REL}', $sMediaUrl,$aPostRec['content_short']);
-    	$aPostRec['content_long']  = str_replace('{SYSVAR:MEDIA_REL}', $sMediaUrl,$aPostRec['content_long']);
+        $sFilterApi = WB_PATH.'/modules/output_filter/OutputFilterApi.php';
+        if (is_readable($sFilterApi)) {
+            require_once($sFilterApi);
+            $aPostRec['content_short'] = OutputFilterApi('ReplaceSysvar', $aPostRec['content_short']);
+            $aPostRec['content_long'] = OutputFilterApi('ReplaceSysvar', $aPostRec['content_long']);
+        }
     }
     //$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
     
Index: branches/2.8.x/wb/modules/news/save_post.php
===================================================================
--- branches/2.8.x/wb/modules/news/save_post.php	(revision 2068)
+++ branches/2.8.x/wb/modules/news/save_post.php	(revision 2069)
@@ -16,69 +16,69 @@
  */
     error_reporting(E_ALL);
 	require('../../config.php');
-	require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
+    $oReg = WbAdaptor::getInstance();
+    $oDb  = WbDatabase::getInstance();
+    $sNewsLinkSubdir = 'posts/';
+//	require_once($oReg->AppPath."include/jscalendar/jscalendar-functions.php");
 // Get post_id
-	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
-		header("Location: ".ADMIN_URL."/pages/index.php");
+    if (!isset($_POST['post_id']) || !($post_id = intval($_POST['post_id']))) {
+		header("Location: ".$oReg->AcpUrl.'pages/index.php');
 		exit( 0 );
-	}else {
-		$post_id = intval($_POST['post_id']);
-	}
-
+    }
+//	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
+//		header("Location: ".$oReg->AcpUrl.'pages/index.php');
+//		exit( 0 );
+//	}else {
+//		$post_id = intval($_POST['post_id']);
+//	}
 	$admin_header = false;
 	// Tells script to update when this page was last updated
 	$update_when_modified = true;
 	// Include WB admin wrapper script
-	require(WB_PATH.'/modules/admin.php');
-
+	require($oReg->AppPath.'modules/admin.php');
+    $oReg->getWbConstants();
 	if (!$admin->checkFTAN()) {
 		$admin->print_header();
 		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
-		                    ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
+		                    $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id );
 	}
 	$admin->print_header();
 
 // Validate all fields
-	$title      = $admin->StripCodeFromText($admin->get_post('title'));
-	$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
-	$active     = intval($admin->get_post('active'));
-	$old_link   = $admin->StripCodeFromText($admin->get_post('link'));
-	$group_id   = intval($admin->get_post('group'));
-
 	if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
-		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
+		$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
 		             '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
 		$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
 	} else {
-		$short      = $admin->get_post('short');
-		$long       = $admin->get_post('long');
-		$short = $admin->ReplaceAbsoluteMediaUrl($short);
-		$long = $admin->ReplaceAbsoluteMediaUrl($long);
+		$short = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('short'));
+		$long  = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('long'));
 	}
-
+	$title      = $admin->StripCodeFromText($admin->get_post('title'));
+	$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
+	$active     = intval($admin->get_post('active'));
+	$group_id   = intval($admin->get_post('group'));
 // Include WB functions file
-	require(WB_PATH.'/framework/functions.php');
-// Work-out what the link should be
-	$sNewFile = page_filename($title).PAGE_SPACER.$post_id;
-    $newLink = '/posts/'.$sNewFile;
-    $sPagesPath = WB_PATH.PAGES_DIRECTORY;
-    $sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
-    $sNewFilename = $sPagesPath.$newLink.PAGE_EXTENSION;
-    $sOldFilename = $sPagesPath.$old_link.PAGE_EXTENSION;
-
+	require($oReg->AppPath.'framework/functions.php');
+// Work-out all needed path and filenames
+    $sAccessFsileRootPath = $oReg->AppPath.$oReg->PagesDir.$sNewsLinkSubdir;
+	$sOldLink     = preg_replace('/^\/?'.preg_quote($sNewsLinkSubdir, '/').'/', '', str_replace('\\', '/', $admin->StripCodeFromText($admin->get_post('link'))));
+    $sOldFilename = $sAccessFileRootPath.$sOldLink.$oReg->PageExtension;
+	$sNewLink     = page_filename($title).$oReg->PageSpacer.$post_id;
+    $sNewFilename = $sAccessFileRootPath.$sNewLink.$oReg->PageExtension;
+    $sBackUrl = $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id;
 // get publisedwhen and publisheduntil
-	$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
-	if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
-	$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
-	if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
-// Update row
-	$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` '
+    $x = strtotime(preg_replace('/^(\d{1,2})\.(\d{1,2})\.(\d{2,4})(.*)$/s', '\2/\1/\3\4', $admin->get_post_escaped('publishdate')));
+    $publishedwhen = $x ? $x : 0;
+    $x = strtotime(preg_replace('/^(\d{1,2})\.(\d{1,2})\.(\d{2,4})(.*)$/s', '\2/\1/\3\4', $admin->get_post_escaped('enddate')), $publishedwhen);
+    $publisheduntil = $x ? $x : 0;
+// Update row in database
+	$sql  = 'UPDATE `'.$oDb->TablePrefix.'mod_news_posts` '
           . 'SET `group_id`='.(int)$group_id.', '
-          .     '`title`=\''.$database->escapeString($title).'\', '
-          .     '`link`=\''.$database->escapeString($newLink).'\', '
-          .     '`content_short`=\''.$database->escapeString($short).'\', '
-          .     '`content_long`=\''.$database->escapeString($long).'\', '
-          .     '`commenting`=\''.$database->escapeString($commenting).'\', '
+          .     '`title`=\''.$oDb->escapeString($title).'\', '
+          .     '`link`=\''.$oDb->escapeString('/'.$sNewsLinkSubdir.$sNewLink).'\', '
+          .     '`content_short`=\''.$oDb->escapeString($short).'\', '
+          .     '`content_long`=\''.$oDb->escapeString($long).'\', '
+          .     '`commenting`=\''.$oDb->escapeString($commenting).'\', '
           .     '`active`='.(int)$active.', '
           .     '`published_when`='.(int)$publishedwhen.', '
           .     '`published_until`='.(int)$publisheduntil.', '
@@ -85,26 +85,24 @@
           .     '`posted_when`='.time().', '
           .     '`posted_by`='.(int)$admin->get_user_id().' '
           . 'WHERE `post_id`='.(int)$post_id;
-	if( $database->query($sql) ) {
-		// create new accessfile
-        $sDoWhat = (($newLink == $old_link) && (file_exists($sNewFilename))) ? "nothing" : "action";
-        if($sDoWhat == "action") {
-            $sDoWhat = (($sDoWhat == "action") && file_exists($sOldFilename)) ? "update" : "create";
-        }
-
+	if ($oDb->query($sql)) {
+    // create new accessfile
+        $sDoWhat = (($sNewLink == $sOldLink) && (file_exists($sNewFilename)))
+                   ? "nothing"
+                   : ((file_exists($sOldFilename)) ? "update" : "create");
         switch($sDoWhat)
         {
             case "update":
                 try {
-// prozedural rename accessfile if link has changed, has to be changed to accessfile class when fixed
-            		if(($sNewFilename != $sOldFilename) && (is_writable($sOldFilename))) {
-            			if(!rename($sOldFilename,$sNewFilename)) {
-            				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
-            			}
-            		}
-//                    $oAF = new AccessFile($sOldFilename, $page_id);
-//                    $oAF->rename($sNewFile);
-//                    unset($oAF);
+//// prozedural rename accessfile if link has changed, has to be changed to accessfile class when fixed
+//            		if(($sNewFilename != $sOldFilename) && (is_writable($sOldFilename))) {
+//            			if(!rename($sOldFilename,$sNewFilename)) {
+//            				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
+//            			}
+//            		}
+                    $oAF = new AccessFile($sAccessFileRootPath, $sOldLink, $page_id);
+                    $oAF->rename($sNewLink);
+                    unset($oAF);
                 }catch(AccessFileException $e) {
                     $admin->print_error($e,$sBackUrl);
                 }
@@ -111,7 +109,7 @@
             break;
             case "create":
                 try {
-                    $oAF = new AccessFile($sNewFilename, $page_id);
+                    $oAF = new AccessFile($sAccessFileRootPath, $sNewLink, $page_id);
                     $oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
                     $oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
                     $oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
@@ -124,12 +122,12 @@
         }
 	}
 // Check if there is a db error, otherwise say successful
-	if($database->is_error()) {
-		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
+	if($oDb->is_error()) {
+		$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
 					 '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
-		$admin->print_error($database->get_error(), $recallUrl);
+		$admin->print_error($oDb->get_error(), $recallUrl);
 	}else {
-		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
+		$admin->print_success($TEXT['SUCCESS'], $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id);
 	}
 // Print admin footer
-	$admin->print_footer();
\ No newline at end of file
+	$admin->print_footer();
