<?php

if (!function_exists('sv') || preg_match('#/plugins/realblog/admin.php#i', $_SERVER['SCRIPT_NAME']))
{
	die('no direct access');
}

/* utf8-marker: äöü 
************************************
RealBlog plugin for CMSimple
RealBlog 4.9
released 2024-08
Gert Ebersbach - ge-webdesign.de
------------------------------------
Based on:  AdvancedNews from Jan Kanters - http://www.jat-at-home.be/
Version :  V 1.0.5 GPL
------------------------------------
Credits :  - flatfile database class Copyright 2005 Luke Plant <L.Plant.98@cantab.net>
           - FCKEditor (older versions) and TinyMCE
           - Date Picker (jscalendar) by Copyright (c) Dynarch.com
License :  GNU General Public License, version 2 or later of your choice
************************************

This program is free software; you can redistribute it and/or modify it under the terms of the 
GNU General Public License as published by the Free Software Foundation; either version 2 of the 
License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; 
if not, see <http://www.gnu.org/licenses>.
*/

// $db_path=$pth['folder']['content'] . 'realblog/';
// $db_name="realblog.txt";

if (isset($realblog))
{
	if(!defined('CMSIMPLE_VERSION'))
	{
		$o.= '<p>This plugin requires <b>CMSimple 4.2</b> or higher.</p><p><a href="http://www.cmsimple.org/">CMSimple Download & Updates &raquo;</a></p>';
		return;
	}
	
	if(defined('XH_ADM'))
	{
		$o.= '<div style="font-size: 15px; font-family: arial, sans-serif; letter-spacing: 0;">
<h4><a href="?realblog">Plugin Info &raquo;</a></h4>
<p style="line-height: 1.6em;"><b>RealBlog</b>&nbsp;by&nbsp;<a href="http://www.ge-webdesign.de/cmsimpleplugins/"><u>ge-webdesign.de&nbsp;&raquo;</u></a> &nbsp; 
for&nbsp;<b>CMSimple&nbsp;4.2</b>&nbsp;or&nbsp;higher&nbsp;from&nbsp;<a href="http://www.cmsimple.org/"><u>cmsimple.org&nbsp;&raquo;</u></a></p>
</div>';
	}
	else
	{
		$o.= '<div style="font-size: 15px; font-family: arial, sans-serif; letter-spacing: 0; padding: 0 0 6px 0;">
<b><a href="?realblog">Plugin Info &raquo;</a></b>
</div>
';
	}
	
    //check if register_globals is turned OFF
    
	if (!isset($_GET)){global $_GET;$_GET = $GLOBALS['HTTP_GET_VARS'];} 
	if (!isset($_POST)){global $_POST;$_POST = $GLOBALS['HTTP_POST_VARS'];} 
	if (!isset($_COOKIE)){global $_COOKIE;$_COOKIE = $GLOBALS['HTTP_COOKIE_VARS'];} 
	if (!isset($_SERVER)){global $_SERVER;$_SERVER = $GLOBALS['HTTP_SERVER_VARS'];}	
//	ini_set('safe_mode', '1');

    // global variables
    global $pth, $cf, $tx, $cl, $u, $sn, $s, $c, $h, $plugin_cf, $plugin_tx;
    // retrieve posted plugin variables
    $admin     =isset($_POST['admin']) ? $_POST['admin'] : (isset($_GET['admin']) ? $_GET['admin'] : null);
    $action    =isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : null);
	
    // get plugin name
    $plugin    =basename(dirname(__FILE__), "/");
	
    // Calendar plugin
    $hjs.= '<link rel="stylesheet" media="all" href="' . $pth['folder']['plugins'] . $plugin . '/jscalendar/calendar-system.css">';
    $hjs.= "\n".'<script src="' . $pth['folder']['plugins'] . $plugin . '/jscalendar/calendar.js"></script>';
		
	// Start modify JAT 07/11/2005 (V 1.0.1)
    // Set jscalendar to default (en) if current website language isn't available
    $hjs.=(is_file($pth['folder']['plugins'].$plugin."/jscalendar/lang/calendar-".$sl.".js"))?"\n".'<script src="'.$pth['folder']['plugins'].$plugin.'/jscalendar/lang/calendar-'.$sl.'.js"></script>':'<script src="'.$pth['folder']['plugins'].$plugin.'/jscalendar/lang/calendar-en.js"></script>';
// End modify JAT 07/11/2005
    $hjs.="\n".'<script src="' . $pth['folder']['plugins'] . $plugin . '/jscalendar/calendar-setup.js"></script>';
    // End added JAT 29/10/2005 //

    if ($action == "delete_realblog" || $action == "add_realblog" || $action == "modify_realblog")
    {
        // Selection of external editors
        switch (strtolower($plugin_cf[$plugin]['editor']))
        {
            case 'fckeditor':
                // FCKeditor
				
                require_once ($pth['folder']['cmsimple'] . 'realblog_fckeditor.php');

                break;

            default:
                // default editor of CMSimple
				init_editor(array('realblog_headline_field','realblog_story_field'));

                break;
        }
    }

    // set general variables for the plugin
    // TO DO: check if these folders exist - if not, exit plugin...
    $plugin_images_folder=$pth['folder']['plugins'] . $plugin . "/images/";
    $plugin_include_folder=$pth['folder']['plugins'] . $plugin . "/include/";
    $pth['file']['plugin_stylesheet']=$pth['folder']['plugins'] . $plugin . '/css/stylesheet.css';
    $pth['file']['plugin_config']=$pth['folder']['plugins'] . $plugin . '/config/config.php';
    $pth['file']['plugin_language']=$pth['folder']['plugins'] . $plugin . '/languages/' . $sl . '.php';
    $pth['file']['plugin_help']=$pth['folder']['plugins'] . $plugin . '/help/help.htm';
    $o.=print_plugin_admin('on');
    if ($admin <> 'plugin_main') { $o.=plugin_admin_common($action, $admin, $plugin); }
    if ($admin == '')
        $o.= '<br>'."<div id=\"realblog_version\"><h4>".REALBLOG_VERSION."</h4><p>by <a href=\"http://www.ge-webdesign.de/cmsimplerealblog\" target=\"_blank\">ge-webdesign.de</a> (released: ".$realblog_release.")</p><p>".$realblog_based_on."</p></div>";

    // include the flatfile database class
    // TO DO: check if this file exists
    require_once ($plugin_include_folder . "flatfile.php");
    // declare the realblog database fields
    require_once ($plugin_include_folder . "fields.php");
    // connect to the realblog database file
    $db         =new Flatfile();
    $db->datadir=$db_path;

    if ($admin == 'plugin_main' && is_writable($db_path . $db_name))
    {
        // Verify date format settings & make correct date format for the datepicker.js script
        $my_date_format1=explode('/', $plugin_tx[$plugin]['date_format']);

        if (count($my_date_format1) > 1) { $date_separator1="/"; }
        else
        {
            $my_date_format1=explode('.', $plugin_tx[$plugin]['date_format']);

            if (count($my_date_format1) > 1) { $date_separator1="."; }
            else
            {
                $my_date_format1=explode('-', $plugin_tx[$plugin]['date_format']);

                if (count($my_date_format1) > 1) { $date_separator1="-"; }
            }
        }

        for ($aCounter1=0; $aCounter1 <= 2; $aCounter1++)
        {
            switch ($my_date_format1[$aCounter1])
            {
                case 'd':
                    $cal_date_format1[$aCounter1]="%d";

                    break;

                case 'm':
                    $cal_date_format1[$aCounter1]="%m";

                    break;

                case 'y':
                    $cal_date_format1[$aCounter1]="%y";

                    break;

                case 'Y':
                    $cal_date_format1[$aCounter1]="%Y";

                break;
            }
        }

        $cal_format = '';
		foreach ($cal_date_format1 as $key
        => $value) { $cal_format.=($key < count($my_date_format1) - 1) ? $value . $date_separator1 : $value; }

        // retrieve posted plugin variables
        $realblogID = isset($_POST['realblogID']) ? $_POST['realblogID'] : (isset($_GET['realblogID']) ? $_GET['realblogID'] : null);
        $page = isset($_POST['page']) ? $_POST['page'] : (isset($_GET['page']) ? $_GET['page'] : null);
        $do=isset($_POST['do']) ? $_POST['do'] : (isset($_GET['do']) ? $_GET['do'] : null);
        $filter=isset($_POST['filter']) ? $_POST['filter'] : (isset($_GET['filter']) ? $_GET['filter'] : null);
        // retrieve posted Form fields information
        $realblog_id=isset($_POST['realblog_id']) ? $_POST['realblog_id'] : (isset($_GET['realblog_id']) ? $_GET['realblog_id'] : null);
        $realblog_date=isset($_POST['realblog_date']) ? $_POST['realblog_date'] : (isset($_GET['realblog_date']) ? $_GET['realblog_date'] : null);
        if(isset($_POST['realblog_title'])) $realblog_title=isset($_POST['realblog_title']) ? htmlspecialchars($_POST['realblog_title'], ENT_QUOTES, 'UTF-8') : htmlspecialchars($_GET['realblog_title'], ENT_QUOTES, 'UTF-8');
        $realblog_headline=isset($_POST['realblog_headline']) ? $_POST['realblog_headline'] : (isset($_GET['realblog_headline']) ? $_GET['realblog_headline'] : null);
		if(isset($realblog_headline)) $realblog_headline = preg_replace('/<p>({{{PLUGIN:.*?|{{{function:.*?|#CMSimple .*?)<\/p>/is', '<div>$1</div>', $realblog_headline);
        $realblog_story=isset($_POST['realblog_story']) ? $_POST['realblog_story'] : (isset($_GET['realblog_story']) ? $_GET['realblog_story'] : null);
		if(isset($realblog_story)) $realblog_story = preg_replace('/<p>({{{PLUGIN:.*?|{{{function:.*?|#CMSimple .*?)<\/p>/is', '<div>$1</div>', $realblog_story);
        $realblog_frontpage=isset($_POST['realblog_frontpage']) ? $_POST['realblog_frontpage'] : (isset($_GET['realblog_frontpage']) ? $_GET['realblog_frontpage'] : null);
        $realblog_rssfeed=isset($_POST['realblog_rssfeed']) ? $_POST['realblog_rssfeed'] : (isset($_GET['realblog_rssfeed']) ? $_GET['realblog_rssfeed'] : null);
		$realblog_comments=isset($_POST['realblog_comments']) ? $_POST['realblog_comments'] : (isset($_GET['realblog_comments']) ? $_GET['realblog_comments'] : null); // GE 2010-11
        $realblog_startdate=isset($_POST['realblog_startdate']) ? $_POST['realblog_startdate'] : (isset($_GET['realblog_startdate']) ? $_GET['realblog_startdate'] : null);
        $realblog_enddate=isset($_POST['realblog_enddate']) ? $_POST['realblog_enddate'] : (isset($_GET['realblog_enddate']) ? $_GET['realblog_enddate'] : null);
        $realblog_status=isset($_POST['realblog_status']) ? $_POST['realblog_status'] : (isset($_GET['realblog_status']) ? $_GET['realblog_status'] : null);
        $filter1=isset($_POST['filter1']) ? $_POST['filter1'] : (isset($_GET['filter1']) ? $_GET['filter1'] : null);
        $filter2=isset($_POST['filter2']) ? $_POST['filter2'] : (isset($_GET['filter2']) ? $_GET['filter2'] : null);
        $filter3=isset($_POST['filter3']) ? $_POST['filter3'] : (isset($_GET['filter3']) ? $_GET['filter3'] : null);
        $realblogtopics=isset($_POST['realblogtopics']) ? $_POST['realblogtopics'] : (isset($_GET['realblogtopics']) ? $_GET['realblogtopics'] : null);
        $batchdelete_x=isset($_POST['batchdelete_x']) ? $_POST['batchdelete_x'] : (isset($_GET['batchdelete_x']) ? $_GET['batchdelete_x'] : null);
        $changestatus_x=isset($_POST['changestatus_x']) ? $_POST['changestatus_x'] : (isset($_GET['changestatus_x']) ? $_GET['changestatus_x'] : null);
        $batchchangestatus=isset($_POST['batchchangestatus']) ? $_POST['batchchangestatus'] : (isset($_GET['batchchangestatus']) ? $_GET['batchchangestatus'] : null);
        $new_realblogstatus=isset($_POST['new_realblogstatus']) ? $_POST['new_realblogstatus'] : (isset($_GET['new_realblogstatus']) ? $_GET['new_realblogstatus'] : null);

        // perform the appropriate action for the selected record
        if ($action == "delete_realblog" || $action == "add_realblog" || $action == "modify_realblog")
            { $o.=realblogform($realblogID, $action, $page); }

        // add new realblog item to the database or modify the selected realblog item
        if ($do == "add" || $do == "modify")
        {
            $realblog_date               =realblog_make_timestamp_dates($realblog_date);
            $realblogitem[REALBLOG_DATE]     =$realblog_date;
            $realblogitem[REALBLOG_TITLE]    =stripslashes($realblog_title);
            $realblogitem[REALBLOG_HEADLINE] =stripslashes($realblog_headline);
            $realblogitem[REALBLOG_STORY]    =stripslashes($realblog_story);
            $realblogitem[REALBLOG_FRONTPAGE]=$realblog_frontpage;
            $realblogitem[REALBLOG_STARTDATE]=realblog_make_timestamp_dates($realblog_startdate);
            $realblogitem[REALBLOG_ENDDATE]  =realblog_make_timestamp_dates($realblog_enddate);
            $realblogitem[REALBLOG_STATUS]   =$realblog_status;
            $realblogitem[REALBLOG_RSSFEED]  =$realblog_rssfeed;
			$realblogitem[REALBLOG_COMMENTS] =$realblog_comments; // GE 2010 - 11

            if ($do == "add")
            {
                $realblogitem[REALBLOG_ID]='0'; // dummy
                $newId            =$db->insertWithAutoId($db_name, REALBLOG_ID, $realblogitem);
                $title            =$plugin_tx[$plugin]['tooltip_add'];
                $info             = '<h5>'.$plugin_tx[$plugin]['story_added'].'</h5>';
                $o.=realblog_dbconfirm($title, $info, $page);
                }

            if ($do == "modify")
                {
                $realblogitem[REALBLOG_ID]=$realblog_id;
                $newId            =$db->updateRowById($db_name, REALBLOG_ID, $realblogitem);
                $title            =$plugin_tx[$plugin]['tooltip_modify'];
                $info             ='<h5>'.$plugin_tx[$plugin]['story_modified'].'</h5>';
                $o.=realblog_dbconfirm($title, $info, $page);
            }
        }

        // delete the selected realblog item
        if ($do == "delete")
        {
            $page=$_SESSION['page'];
            $db->deleteWhere($db_name, new SimpleWhereClause(REALBLOG_ID, '=', $realblog_id), INTEGER_COMPARISON);
            $title=$plugin_tx[$plugin]['tooltip_delete'];
            $info = '<h5>'.$plugin_tx[$plugin]['story_deleted'].'</h5>';
            $o.=realblog_dbconfirm($title, $info, $page);
        }

        // batch delete of the selected realblog item
        if ($do == "delselected")
        {
            foreach ($realblogtopics as $key
            => $delrealblog_id) { $db->deleteWhere($db_name, new SimpleWhereClause(REALBLOG_ID, '=', $delrealblog_id),
                                               INTEGER_COMPARISON); }

            $title=$plugin_tx[$plugin]['tooltip_deleteall'];
            $info =$plugin_tx[$plugin]['deleteall_done'];
            $o.=realblog_dbconfirm($title, $info, $page);
        }

        // batch status change of the selected realblog item
        if ($do == "batchchangestatus")
        {
            if (isset($_SESSION['page'])) { $page=$_SESSION['page']; }

            if ($new_realblogstatus != '' && ($new_realblogstatus == 0 || $new_realblogstatus == 1 || $new_realblogstatus == 2))
            {
                foreach ($realblogtopics as $key => $changerealblog_id)
                    {
                    $realblogitem[REALBLOG_ID]    = $changerealblog_id;
                    $realblogitem[REALBLOG_STATUS]=$new_realblogstatus;
                    $db->updateRowById($db_name, REALBLOG_ID, $realblogitem);
                    }

                $title=$plugin_tx[$plugin]['tooltip_changestatus'];
                $info =$plugin_tx[$plugin]['changestatus_done'];
                $o.=realblog_dbconfirm($title, $info, $page);
            }
            else
            {
                $title=$plugin_tx[$plugin]['tooltip_changestatus'];
                $info =$plugin_tx[$plugin]['nochangestatus_done'];
                $o.=realblog_dbconfirm($title, $info, $page);
            }
        }

        //
        if ($action === "plugin_text"||$action==="edit")
        {
            // delete the selected realblog items
            if (isset($batchdelete_x))
            {
                $title=$plugin_tx[$plugin]['tooltip_deleteall'];
                $info =$plugin_tx[$plugin]['confirm_deleteall'];

                if (isset($realblogtopics) && count($realblogtopics) > 0)
                {
                    // Confirm batch delete of the selected realblog topics
                    $o="<div><h4>" . ucfirst(REALBLOG_VERSION) . " : " . $title . "</h4></div>";
                    $o.="<div>&nbsp;</div>";
                    $o.="<form name=\"confirm\" method=\"post\" action=\"" . $sn . "?&amp;" . $plugin
                        . "&amp;admin=plugin_main\">";
                    $o.="<table width=\"100%\" class=\"realblogNoborder\"><tbody>";

                    foreach ($realblogtopics as $value
                    => $key) { $o.= '<input type="hidden" name="realblogtopics[]" value="' . $key . '">'; }

                    $o.= '<input type="hidden" name="page" value="' . $page . '">';
                    $o.= '<input type="hidden" name="do" value="delselected">';
                    $o.="<tr><td class=\"reablog_confirm_info\" align=\"center\">" . $info
                        . "</td></tr><tr><td>&nbsp;</td></tr>";
                    $o.="<tr><td class=\"reablog_confirm_button\" align=\"center\">" . '<div style="display: table; margin: 0 auto;">' . 
					"<input type=\"submit\" class=\"realblog_button_admin\" name=\"submit\" value=\"" . $plugin_tx[$plugin]['btn_delete'] . "\">&nbsp;&nbsp;" . 
					"<input type=\"button\" class=\"realblog_button_admin\" name=\"cancel\" value=\"&nbsp;" . $plugin_tx[$plugin]['btn_cancel'] . "\" onclick='location.href=\"" . $sn . "?&amp;" . $plugin . "&amp;admin=plugin_main&amp;action=plugin_text&amp;page=" . $page . "\"'></div></td></tr>";
                    $o.="</tbody></table></form>";
                    $o.="<div>&nbsp;</div>";
                }
                else
                {
                    // Nothing selected
                    $info=$plugin_tx[$plugin]['nothing_selected'];
                    $o   ="<div><h4>" . ucfirst(REALBLOG_VERSION) . " : " . $title . "</h4></div>";
                    $o.="<div>&nbsp;</div>";
                    $o.="<form name=\"confirm\" method=\"post\" action=\"" . $sn . "?&" . $plugin
                        . "&admin=plugin_main&amp;action=plugin_text\">";
                    $o.="<table width=\"100%\" class=\"realblogNoborder\"><tbody>";
                    $o.="<tr><td class=\"reablog_confirm_info\" align=\"center\">" . $info
                        . "</td></tr><tr><td>&nbsp;</td></tr>";
                    $o.="<tr><td class=\"reablog_confirm_button\" align=\"center\">" . '<div style="display: table; margin: 0 auto;">' . 
					"<input type=\"button\" name=\"cancel\" class=\"realblog_button_admin\" value=\"" . $plugin_tx[$plugin]['btn_ok'] . "\" onclick='location.href=\"" . $sn . "?&amp;" . $plugin . "&amp;admin=plugin_main&amp;action=plugin_text&amp;page=" . $page . "\"'></div></td></tr>";
                    $o.="</tbody></table></form>";
                    $o.="<div>&nbsp;</div>";
                }

                return ($o);
//                break; // causes error under php7
            }

            // batch status change of the selected realblog items
            if (isset($changestatus_x))
            {
//                session_register ('page'); // removed in php 5.4
                $_SESSION['page']=$page;
                session_write_close();
                $title=$plugin_tx[$plugin]['tooltip_changestatus'];
                $info =$plugin_tx[$plugin]['confirm_changestatus'];

                if (isset($realblogtopics) && count($realblogtopics) > 0)
                {
                    // Confirm batch status change of the selected realblog topics
                    $o="<div><h4>" . ucfirst(REALBLOG_VERSION) . " : " . $title . "</h4></div>";
                    $o.="<div>&nbsp;</div>";
                    $o.="<form name=\"confirm\" method=\"post\" action=\"" . $sn . "?&amp;" . $plugin
                        . "&amp;admin=plugin_main\">";
                    $o.="<table width=\"100%\" class=\"realblogNoborder\"><tbody>";

                    foreach ($realblogtopics as $value
                    => $key) { $o.= "<input type=\"hidden\" name=\"realblogtopics[]\" value=\"" . $key . "\">"; }

                    $o.= "<input type=\"hidden\" name=\"page\" value=\"" . $page . "\">";
                    $o.= "<input type=\"hidden\" name=\"do\" value=\"batchchangestatus\">";
                    $o.="<td width=\"100%\"  align=\"center\"><select name=\"new_realblogstatus\"><option value=\"\">"
                        . $plugin_tx[$plugin]['entry_status'] . "</option><option value=\"0\">" . $plugin_tx[$plugin]['readyforpublishing'] . "</option><option value=\"1\">" . $plugin_tx[$plugin]['published'] . "</option><option value=\"2\">" . $plugin_tx[$plugin]['archived'] . "</option></select></td>";
                    $o.="<tr><td class=\"realblog_confirm_info\" align=\"center\"><br>" . $info
                        . "<br><br></td></tr>";
                    $o.="<tr><td class=\"realblog_confirm_button\" align=\"center\">" . '<div style="display: table; margin: 0 auto;">' . 
					"<input type=\"submit\" name=\"submit\" class=\"realblog_button_admin\" value=\"" . $plugin_tx[$plugin]['btn_ok'] . "\">" . "&nbsp;&nbsp;" . 
					"<input type=\"button\" name=\"cancel\" class=\"realblog_button_admin\" value=\"" . $plugin_tx[$plugin]['btn_cancel'] . "\" onclick='location.href=\"" . $sn . "?&amp;" . $plugin . "&amp;admin=plugin_main&amp;action=plugin_text&amp;page=" . $page . "\"'></div></td></tr>";
                    $o.="</tbody></table></form>";
                    $o.="<div>&nbsp;</div>";
                }
                else
                {
                    // Nothing selected
                    $info=$plugin_tx[$plugin]['nothing_selected'];
                    $o   ="<div><h4>" . ucfirst(REALBLOG_VERSION) . " : " . $title . "</h4></div>";
                    $o.="<div>&nbsp;</div>";
                    $o.="<form name=\"confirm\" method=\"post\" action=\"" . $sn . "?&" . $plugin
                        . "&admin=plugin_main\">";
                    $o.="<table width=\"100%\" class=\"realblogNoborder\"><tbody>";
                    $o.="<tr><td class=\"realblog_confirm_info\" align=\"center\">" . $info
                        . "</td></tr><tr><td>&nbsp;</td></tr>";
                    $o.="<tr><td class=\"realblog_confirm_button\" align=\"center\">" . '<div style="display: table; margin: 0 auto;">' . 
					"<input type=\"button\" name=\"cancel\" class=\"realblog_button_admin\" value=\"" . $plugin_tx[$plugin]['btn_ok'] . "\" onclick='location.href=\"" . $sn . "?&" . $plugin . "&admin=plugin_main&action=plugin_text&page=" . $page . "\"'></div></td></tr>";
                    $o.="</tbody></table></form>";
                    $o.="<div>&nbsp;</div>";
                }

                return ($o);
//                break; // causes error under php7
            }

            if ($filter != "true") { $compClause=NULL; }
            else
            {
                if ($filter1 == 'on' && $filter2 == 'on' && $filter3 == 'on' || $filter1 != 'on' && $filter2 != 'on'
                    && $filter3 != 'on') { $compClause=NULL; }

                if ($filter1 == 'on' && $filter2 != 'on' && $filter3 != 'on')
                    { $compClause=new SimpleWhereClause(REALBLOG_STATUS, "=", 0); }

                if ($filter1 != 'on' && $filter2 == 'on' && $filter3 != 'on')
                    { $compClause=new SimpleWhereClause(REALBLOG_STATUS, "=", 1); }

                if ($filter1 != 'on' && $filter2 != 'on' && $filter3 == 'on')
                    { $compClause=new SimpleWhereClause(REALBLOG_STATUS, "=", 2); }

                if ($filter1 == 'on' && $filter2 == 'on' && $filter3 != 'on') { $compClause
                    =new OrWhereClause(new SimpleWhereClause(REALBLOG_STATUS, "=", 0, INTEGER_COMPARISON),
                                           new SimpleWhereClause(REALBLOG_STATUS, "=", 1, INTEGER_COMPARISON)); }

                if ($filter1 == 'on' && $filter2 != 'on' && $filter3 == 'on') { $compClause
                    =new OrWhereClause(new SimpleWhereClause(REALBLOG_STATUS, "=", 0, INTEGER_COMPARISON),
                                           new SimpleWhereClause(REALBLOG_STATUS, "=", 2, INTEGER_COMPARISON)); }

                if ($filter1 != 'on' && $filter2 == 'on' && $filter3 == 'on') { $compClause
                    =new OrWhereClause(new SimpleWhereClause(REALBLOG_STATUS, "=", 1, INTEGER_COMPARISON),
                                           new SimpleWhereClause(REALBLOG_STATUS, "=", 2, INTEGER_COMPARISON)); }
            }

            $records          =$db->selectWhere($db_name, $compClause, -1,
                                                new OrderBy(REALBLOG_ID, DESCENDING, INTEGER_COMPARISON));
            // Set limit of record in the table
            $page_record_limit=$plugin_cf[$plugin]['admin_records_page'];

            if ($page_record_limit <= 0) { $page_record_limit=10; }

            if ($page_record_limit >= 50) { $page_record_limit=32; }

            // Count the total records
            $db_total_records=count($records);
            // Calculate the number of possible pages
            $page_total      =($db_total_records % $page_record_limit == 0)
                ? ((int)$db_total_records / $page_record_limit)
                : ((int)($db_total_records / $page_record_limit) + 1);
            // Calculate table paging
            $o.="<div><h4>" . ucfirst(REALBLOG_VERSION) . " - " . $plugin_tx[$plugin]['story_overview']
                . "</h4></div>";

            if ($page > $page_total) { $page=1; }

            if ($page == "" || $page <= 0 || $page == 1)
            {
                $start_index=0;
                $page       =1;
            }
            else { $start_index=(($page - 1) * ($page_record_limit)); }

// Display realblog items overview
// new table layout - GE 2010 - 11

            $tstfilter1=($filter1 == 'on') ? "checked=\"checked\"" : "";
            $tstfilter2=($filter2 == 'on') ? "checked=\"checked\"" : "";
            $tstfilter3=($filter3 == 'on') ? "checked=\"checked\"" : "";
            $o.="\n<div>\n";
            $o.="\n<form name=\"selectstatus\" method=\"post\" action=\"$sn?&amp;" . $plugin
                . "&amp;admin=plugin_main&amp;action=plugin_text\">";
            $o.="\n<table width=\"100%\" class=\"realblogAdminFilter\">\n<tr>";
            $o.="\n<td width=\"35%\">" . 
			"<input type=\"checkbox\" name=\"filter1\"" . $tstfilter1 . "\">&nbsp;"
                . $plugin_tx[$plugin]['readyforpublishing'] . "</td>";
            $o.="\n<td width=\"30%\">" . 
			"<input type=\"checkbox\" name=\"filter2\"" . $tstfilter2 . "\">&nbsp;"
                . $plugin_tx[$plugin]['published'] . "</td>";
            $o.="\n<td width=\"30%\">" . 
			"<input type=\"checkbox\" name=\"filter3\"" . $tstfilter3 . "\">&nbsp;"
                . $plugin_tx[$plugin]['archived'] . "</td>";
            $o.="\n<td width=\"5%\" style=\"text-align: right!important;\">" . 
			"<input type=\"image\" align=\"middle\" src=\"" . $plugin_images_folder . "btn_filter.png\" name=\"send\" value=\"Apply filter\" title=\"" . $plugin_tx[$plugin]['btn_search'] . "\"></td>";
            $o.="\n</tr>\n</table>";
            $o.="\n<input type=\"hidden\" name=\"filter\" value=\"true\">";
            $o.="\n</form>\n</div>";
            // Display table header
            $o.="\n<div>
			\n<form method=\"post\" action=\"$sn?&amp;" . $plugin .  "&amp;admin=plugin_main&amp;action=plugin_text\">\n<table class=\"realblog_table\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
			
            $o.="\n<tr>
			\n<td class=\"realblog_table_header\" align=\"center\">" . 
			"<input type=\"image\" align=\"middle\" src=\"" . $plugin_images_folder . "btn_delsel.png\" name=\"batchdelete\" value=\"true\" title=\"" . $plugin_tx[$plugin]['tooltip_deleteall'] . "\">" . 
			"</td>
			
			\n<td class=\"realblog_table_header\" align=\"center\">" . 
			"<input type=\"image\" align=\"middle\" src=\"" . $plugin_images_folder . "btn_status.png\" name=\"changestatus\" value=\"true\" title=\"" . $plugin_tx[$plugin]['tooltip_changestatus'] . "\">" . 
			"</td>
			
			\n<td class=\"realblog_table_header\" align=\"center\"><a href=\"$sn?&amp;" . $plugin . "&amp;admin=plugin_main&amp;action=add_realblog\" title=\"" . $plugin_tx[$plugin]['tooltip_add'] . "\">+ &dArr;</a></td>

			\n<td class=\"realblog_table_header\" align=\"center\">" . $plugin_tx[$plugin]['id_label'] . "</td>
			
			\n<td class=\"realblog_table_header\" align=\"center\">" . $plugin_tx[$plugin]['date_label'] . "</td>
			\n<td class=\"realblog_table_header\" align=\"center\">" . 'Status' . "</td>
			\n<td class=\"realblog_table_header\" align=\"center\">RSS Feed</td>
			\n<td class=\"realblog_table_header\" align=\"center\">" . $plugin_tx['realblog']['comments_onoff'] . "</td>
			\n</tr>";
				
            $end_index=$page * $page_record_limit - 1;

            // Display table lines
            for ($record_index=$start_index; $record_index <= $end_index; $record_index++)
            {
                if ($record_index > $db_total_records - 1) 
				{ 
					$o.="<tr>
					<td class=\"realblog_table_line\" align=\"center\">&nbsp;</td>
					<td class=\"realblog_table_line\" align=\"center\">&nbsp;</td>
					<td class=\"realblog_table_line\" align=\"center\">&nbsp;</td>
					<td class=\"realblog_table_line\" align=\"center\">&nbsp;</td>
					<td class=\"realblog_table_line\" align=\"center\">&nbsp;</td>
					<td class=\"realblog_table_line\">&nbsp;</td>
					<td class=\"realblog_table_line\">&nbsp;</td>
					<td class=\"realblog_table_line\">&nbsp;</td>
					</tr>";
                }
                else
                {
                    $field=$records[$record_index];
                    $o.="<tr>
					<td class=\"realblog_table_line\" align=\"center\"><input type=\"checkbox\" name=\"realblogtopics[]\" value=\"" . $field[REALBLOG_ID] . "\"></td>
					<td class=\"realblog_table_line\" valign=\"top\" align=\"center\"><a href=\"$sn?&" . $plugin . "&admin=plugin_main&action=delete_realblog&realblogID=" . $field[REALBLOG_ID] . "&page=" . $page . "\"><img src=\"" . $plugin_images_folder . "btn_delete.gif\" align=\"center\" title=\"" . $plugin_tx[$plugin]['tooltip_delete'] . "\" alt=\"\"></a></td>
					<td class=\"realblog_table_line\" valign=\"top\" align=\"center\"><a href=\"$sn?&"               . $plugin . "&admin=plugin_main&action=modify_realblog&realblogID=" . $field[REALBLOG_ID] . "&page=" . $page . "\"><img src=\"" . $plugin_images_folder . "btn_modify.gif\" align=\"center\" title=\"" . $plugin_tx[$plugin]['tooltip_modify'] . "\" alt=\"\"></a></td>
					<td  class=\"realblog_table_line\" valign=\"top\" align=\"center\"><b>" . $field[REALBLOG_ID] . "</b></td>
					<td valign=\"top\" style=\"text-align: center;\" class=\"realblog_table_line\">" . date($plugin_tx[$plugin]['date_format'], $field[REALBLOG_DATE]) . "</td>
					
					\n<td class=\"realblog_table_line\" valign=\"top\"  style=\"text-align: center;\"><b>" . $field[REALBLOG_STATUS] . "</b></td>
					
					\n<td class=\"realblog_table_line realblog_onoff\" valign=\"top\"  style=\"text-align: center;\">" . $field[REALBLOG_RSSFEED] . "</td>
					
					\n<td class=\"realblog_table_line realblog_onoff\" valign=\"top\"  style=\"text-align: center;\">" . $field[REALBLOG_COMMENTS] . "</td>
					
					\n</tr>
					\n<tr>
						
					\n<td colspan=\"8\" valign=\"top\"class=\"realblog_table_title\"><span>" . $field[REALBLOG_TITLE] . "</span></td></tr>";
				}
			}

            $o.="</table></div>";
            $o.= "<input type=\"hidden\" name=\"page\" value=\"" . $page . "\">" . 
			"</form><div>&nbsp;</div>";
            // Display table paging
            $tmp=($db_total_records > 0)
                ? "" . $plugin_tx[$plugin]['page_label'] . " : " . $page . " / " . $page_total : "";
            $o.="<div class=\"realblog_paging_block\"><div class=\"realblog_db_info\">" . $plugin_tx[$plugin]['record_count'] . " : "
                . $db_total_records . "</div><div class=\"realblog_page_info\">&nbsp;&nbsp;&nbsp;" . $tmp . "</div>";

            if ($db_total_records > 0 && $page_total > 1)
			{
                if ($page_total > $page)
                {
                    $next=$page + 1;
                    $back=($page > 1) ? ($next - 2) : "1";
                }
                else
                {
                    $next=$page_total;
                    $back=$page_total - 1;
                }

                $o.="<div class=\"realblog_table_paging\"><a href=\"" . $sn . "?&" . $plugin . "&admin=plugin_main&action=plugin_text&page=" . $back ."&amp;filter1=".$filter1."&amp;filter2=".$filter2."&amp;filter3=".$filter3."&amp;filter=".$filter. "\" title=\"" . $plugin_tx[$plugin]['tooltip_previous'] . "\"><img src=\"" . $plugin_images_folder . "btn_previous.gif\" . alt=\"\"></a>&nbsp;&nbsp;";

                for ($tt=1; $tt <= $page_total; $tt++)
                {
                    $separator = ($tt < $page_total) ? " " : "";
                    $o.="<a href=\"" . $sn . "?&" . $plugin . "&admin=plugin_main&action=plugin_text&page=" . $tt
                        . "&amp;filter1=".$filter1."&amp;filter2=".$filter2."&amp;filter3=".$filter3."&amp;filter=".$filter. "\" title=\"" . $plugin_tx[$plugin]['page_label'] . " " . $tt . "\">[" . $tt . "]</a>" . $separator;
                }

                $o.="&nbsp;&nbsp;<a href=\"" . $sn . "?&amp;" . $plugin . "&amp;admin=plugin_main&amp;action=plugin_text&amp;page=" . $next . "&amp;filter1=".$filter1."&amp;filter2=".$filter2."&amp;filter3=".$filter3."&amp;filter=".$filter. "\" title=\"" . $plugin_tx[$plugin]['tooltip_next'] . "\"><img src=\"" . $plugin_images_folder . "btn_next.gif\" alt=\"\"></a>";
                $o.="</div>";
            }
            $o.="</div>";
        }
    }
	else
	{
		if ($admin == 'plugin_main')
		{
				$o.= '<h4>Plugin RealBlog</h4>
	<p style="background: #910; color: #fff; text-align: center; font-weight: 700; padding: 9px 16px;">' . $plugin_tx['realblog']['message_datafile'] . '</p>';
		}
	}
}

function realblogform ($realblogID = NULL, $action = NULL, $ret_page = 1)
{
    global $pth, $plugin, $plugin_cf, $plugin_tx, $sn, $db_path, $db_name, $plugin_images_folder, $cf, $tx, $cal_format;
    $db         =new Flatfile();
    $db->datadir=$db_path;

    switch ($action)
        {
        case "add_realblog":
            $title         =$plugin_tx[$plugin]['tooltip_add'];

            $realblog_date     =date($plugin_tx[$plugin]['date_format'], time());
            $realblog_startdate=date($plugin_tx[$plugin]['date_format'], time());
            $realblog_enddate  =date($plugin_tx[$plugin]['date_format'], time());
            break;

        case "modify_realblog":
            $title=$plugin_tx[$plugin]['tooltip_modify'] . " [ID: " . $realblogID . "]";

            break;

        case "delete_realblog":
            $title=$plugin_tx[$plugin]['tooltip_delete'] . " [ID: " . $realblogID . "]";

            break;
        }

    if ($action === "modify_realblog" || $action === "delete_realblog")
    {
        $record              =$db->selectUnique($db_name, REALBLOG_ID, $realblogID);
        $realblog_id             =$record[REALBLOG_ID];
        $realblog_date           =date($plugin_tx[$plugin]['date_format'], $record[REALBLOG_DATE]);
        $realblog_title          =htmlspecialchars_decode($record[REALBLOG_TITLE],ENT_QUOTES);
        $realblog_headline       =$record[REALBLOG_HEADLINE];
        $realblog_story          =$record[REALBLOG_STORY];
        $realblog_frontpage      =$record[REALBLOG_FRONTPAGE];
        $realblog_startdate      =date($plugin_tx[$plugin]['date_format'], $record[REALBLOG_STARTDATE]);
        $realblog_enddate        =date($plugin_tx[$plugin]['date_format'], $record[REALBLOG_ENDDATE]);
        $realblog_status         =$record[REALBLOG_STATUS];
        $realblog_rssfeed        =$record[REALBLOG_RSSFEED];
		$realblog_comments       =$record[REALBLOG_COMMENTS]; // GE 2010 - 11
        unset ($status);
        $status[$realblog_status]="selected";
        $checked             =($realblog_frontpage == "on") ? "CHECKED" : "";
        $rsschecked          =($realblog_rssfeed == "on") ? "CHECKED" : "";
		$commentschecked     =($realblog_comments == "on") ? "CHECKED" : ""; // GE 2010 - 11
    }

    // Display realblog item form

    $t = "<div class=\"realblog_fields_block\"><div><h4>" . ucfirst(REALBLOG_VERSION) . " : " . $title . "</h4></div>";
    //$t.="<div>&nbsp;</div>";
    $t.="<form name=\"realblog\" method=\"post\" action=\"$sn?&" . $plugin . "&admin=plugin_main\"><input type=\"hidden\" name=\"page\" value=\"" . $ret_page . "\">";
    $t.="<table width=\"100%\" class=\"realblogTableEntry\"><tr><td>
	<input type=\"hidden\" name=\"realblog_id\" value=\"" . (isset($realblog_id) ? $realblog_id : '') . "\"></td></tr>";
    $t.="<tr><td width=\"30%\"><span class=\"realblog_date_label\">" . $plugin_tx[$plugin]['date_label'] ."</span></td><td width=\"5%\">&nbsp;</td><td width=\"30%\"><span class=\"realblog_date_label\">" . $plugin_tx[$plugin]['startdate_label'] . "</span></td><td width=\"5%\">&nbsp;</td><td width=\"30%\"><span class=\"realblog_date_label\">" . $plugin_tx[$plugin]['enddate_label'] . "</span></td></tr><tr>";
    // Start modify [JAT] 31/10/2005
    $t.="<td width=\"30%\" valign=\"top\">
	<input type=\"text\" name=\"realblog_date\" id=\"date1\" value=\"" . $realblog_date . "\" size=\"10\" maxlength=\"10\" onfocus=\"this.blur()\">&nbsp;<img src=\"" . $plugin_images_folder . "btn_calendar.gif\" style=\"margin-left:1px;margin-bottom:-3px;\" id=\"trig_date1\" title=\"" . $plugin_tx[$plugin]['tooltip_datepicker'] . "\" alt=\"\">
	</td><td width=\"5%\">&nbsp;</td>";
    $t.="<td width=\"30%\" valign=\"top\">";

	// Auto publishing enabled/disabled by config variable - GE 2010-12-16
	if($plugin_cf['realblog']['auto_publish'] == 'true')
	{
		$t.="<input type=\"text\" name=\"realblog_startdate\" id=\"date2\" value=\"" . $realblog_startdate . "\" size=\"10\" maxlength=\"10\" onfocus=\"this.blur()\">&nbsp;<img src=\"" . $plugin_images_folder . "btn_calendar.gif\" style=\"margin-left:1px;margin-bottom:-3px;\" id=\"trig_date2\" title=\"" . $plugin_tx[$plugin]['tooltip_datepicker'] . "\" alt=\"\">";
	}
	else
	{
		$t.=$plugin_tx['realblog']['startdate_hint'];
	}

	$t.="</td><td width=\"5%\">&nbsp;</td>";
    $t.="<td width=\"30%\" valign=\"top\">";
	
	// Auto archiving enabled/disabled by config variable - GE 2010-11-16
	if ($plugin_cf['realblog']['auto_archive'] == 'true')
	{
	$t.= "<input type=\"text\" name=\"realblog_enddate\" id=\"date3\" value=\"" . $realblog_enddate . "\" size=\"10\" maxlength=\"10\" onfocus=\"this.blur()\">&nbsp;<img src=\"" . $plugin_images_folder . "btn_calendar.gif\" style=\"margin-left:1px;margin-bottom:-3px;\" id=\"trig_date3\" title=\"" . $plugin_tx[$plugin]['tooltip_datepicker'] . "\" alt=\"\">";
	}
	else
	{
		$t.= $plugin_tx['realblog']['enddate_hint'];
	}
	
	$t.="</td></tr><tr>";
    // End modify [JAT] 31/10/2005
	
    // Start added [JAT] 31/10/2005
	
	$t.="<script>
	Calendar.setup({inputField : \"date1\",ifFormat : \"" . $cal_format . "\",button : \"trig_date1\",align : \"Br\",singleClick : false,firstDay: 1,weekNumbers : false,electric:false,showsTime:false,timeFormat: \"24\"});";

		
	// Auto publishing enabled/disabled by config variable - GE 2010-12-16
	if($plugin_cf['realblog']['auto_publish'] == 'true')
	{
	$t.="Calendar.setup({inputField : \"date2\",ifFormat : \"" . $cal_format . "\",button : \"trig_date2\",align : \"Br\",singleClick : true,firstDay: 1,weekNumbers : false,electric:false,showsTime:false,timeFormat: \"24\"});";
	}
		
	// Auto archiving enabled/disabled by config variable - GE 2010-11-16
	if ($plugin_cf['realblog']['auto_archive'] == 'true')
	{	
	$t.="Calendar.setup({inputField : \"date3\",ifFormat : \"" . $cal_format . "\",button : \"trig_date3\",align : \"Br\",singleClick : false,firstDay: 1,weekNumbers : false,electric:false,showsTime:false,timeFormat: \"24\"});";
	}
	$t.="</script>";
	
    // End added [JAT] 31/10/2005
	
	if(!isset($realblog_title))$realblog_title = '';
	if(!isset($realblog_headline))$realblog_headline = '';
	if(!isset($realblog_story))$realblog_story = '';
	
    $t.="<td width=\"30%\"><span class=\"realblog_date_label\">" . $plugin_tx[$plugin]['status_label'] . "</span></td><td width=\"5%\">&nbsp;</td><td width=\"30%\">&nbsp;</span></td><td width=\"5%\">&nbsp;</td><td width=\"30%\"><span>&nbsp;</span></td></tr><tr>";

	$t.="<td width=\"30%\" valign=\"top\"><select name=\"realblog_status\"><option value=\"0\" " . (isset($status[0]) ? $status[0] : '') . ">"
        . $plugin_tx[$plugin]['readyforpublishing'] . "</option><option value=\"1\" " . (isset($status[1]) ? $status[1] : '') . ">" . $plugin_tx[$plugin]['published'] . "</option><option value=\"2\" " . (isset($status[2]) ? $status[2] : '') . ">" . $plugin_tx[$plugin]['archived'] . "</option><option value=\"3\" " . (isset($status[3]) ? $status[3] : '') . ">" . $plugin_tx[$plugin]['backuped'] . "</option></select></td>";
    $t.="<td width=\"5%\">&nbsp;</td><td width=\"30%\" valign=\"top\">" . '<input type="checkbox" name="realblog_comments" ' . (isset($commentschecked) ? $commentschecked : '') . '>&nbsp;<span>' . $plugin_tx[$plugin]['comment_label'] . "</td>";
    $t.="<td width=\"5%\">&nbsp;</td><td width=\"30%\" valign=\"top\">" . '<input type="checkbox" name="realblog_rssfeed" ' . (isset($rsschecked) ? $rsschecked : '') . ">&nbsp;<span>" . $plugin_tx[$plugin]['rss_label'] . "</span></td></tr>";

    $t.="<tr><td width=\"30%\"><h4>" . $plugin_tx[$plugin]['title_label'] . "</h4></td></tr>";
    $t.="<tr><td colspan=\"5\"><input type=\"text\" value=\"" . htmlspecialchars($realblog_title, ENT_QUOTES, 'UTF-8') . "\" name=\"realblog_title\" size=\"70\"></td></tr>";

    $t.="<tr><td width=\"30%\" style=\"padding-bottom: 8px;\"><h4>" . $plugin_tx[$plugin]['headline_label'] . "</h4>
	<p><b>Script for copy & paste:</b></p>
	{{{PLUGIN:rbCat('|the_category|');}}}
	</td></tr>";
    $t.="<tr><td colspan=\"5\" style=\"padding-bottom: 8px;\"><textarea class=\"realblog_headline_field\" name=\"realblog_headline\" id=\"realblog_headline\" rows=\"6\" cols=\"60\">" . htmlspecialchars($realblog_headline, ENT_QUOTES, 'UTF-8') . "</textarea></td></tr>";
	
    $t.="<tr><td colspan=5 style=\"padding-bottom: 8px;\"><h4>" . $plugin_tx[$plugin]['story_label'] . "</h4>
	<p><b>Script for copy & paste:</b></p>
	{{{PLUGIN:CommentsMembersOnly();}}}
	</td></tr>";
    $t.="<tr><td colspan=\"5\"><textarea class=\"realblog_story_field\" name=\"realblog_story\" id=\"realblog_story\" rows=\"30\" cols=\"80\">" . htmlspecialchars($realblog_story, ENT_QUOTES, 'UTF-8') . "</textarea></td></tr>";

    switch ($action)
        {
        case "add_realblog":
            $t.="<tr><td>&nbsp;<input type=\"hidden\" name=\"do\" value=\"add\"></td></tr>";
            $button_label=$plugin_tx[$plugin]['btn_add'];
            break;

        case "modify_realblog":
            $t.="<tr><td>&nbsp;<input type=\"hidden\" name=\"do\" value=\"modify\"></td></tr>";

            $button_label=$plugin_tx[$plugin]['btn_modify'];
            break;

        case "delete_realblog":
            $t.="<tr><td>&nbsp;<input type=\"hidden\" name=\"do\" value=\"delete\"></td></tr>";
            $button_label=$plugin_tx[$plugin]['btn_delete'];
            break;
        }

    $t.="<tr><td colspan=\"5\" align=\"center\">
<div style=\"display: table; margin: 0 auto;\"><input type=\"submit\" name=\"save\" class=\"realblog_button_admin\" value=\"" . $button_label . "\">&nbsp;&nbsp;&nbsp;<input type=\"button\" name=\"cancel\" class=\"realblog_button_admin\" value=\"" . $plugin_tx[$plugin]['btn_cancel'] . "\" onclick='location.href=\"" . $sn . "?&" . $plugin . "&admin=plugin_main&action=plugin_text&page=" . $ret_page . "\"'></div></td></tr>";
    $t.="</table></form>";
    $t.="</div>";
    return ($t);
}

function realblog_make_timestamp_dates ($tmpdate = null)
{
    global $plugin_cf, $plugin_tx, $plugin, $date_separator1;
    $my_date_format=explode('/', $plugin_tx[$plugin]['date_format']);

    if (count($my_date_format) > 1) { $date_separator="/"; }
    else
    {
        $my_date_format=explode('.', $plugin_tx[$plugin]['date_format']);

        if (count($my_date_format) > 1) { $date_separator="."; }
        else
            {
            $my_date_format=explode('-', $plugin_tx[$plugin]['date_format']);

            if (count($my_date_format) > 1) { $date_separator="-"; }
        }
    }

    for ($aCounter=0; $aCounter <= 2; $aCounter++)
    {
        switch ($my_date_format[$aCounter])
        {
            case 'd':
                $dayposition                          =$aCounter;

                $my_detected_date_format[$dayposition]=$my_date_format[$aCounter];
                $cal_date_format[$dayposition]        ="DD";
                $regex[$dayposition]                 ='([0-9]{1,2})';
                break;

            case 'm':
                $monthposition                          =$aCounter;

                $my_detected_date_format[$monthposition]=$my_date_format[$aCounter];
                $cal_date_format[$monthposition]        ="MM";
                $regex[$monthposition]                  ='([0-9]{1,2})';
                break;

            case 'y':
                $yearposition                          =$aCounter;

                $my_detected_date_format[$yearposition]=$my_date_format[$aCounter];
                $cal_date_format[$yearposition]        ="YY";
                $regex[$yearposition]                  ='([0-9]{2})';
                break;

            case 'Y':
                $yearposition                          =$aCounter;

                $my_detected_date_format[$yearposition]=$my_date_format[$aCounter];
                $cal_date_format[$yearposition]        ="YYYY";
                $regex[$yearposition]                  ='([0-9]{4})';
                break;
        }
    }

    foreach ($my_detected_date_format as $key => $value)
    {
        if ($key < (count($my_detected_date_format) - 1)) { $date_format =$value . $date_separator; }
        else { $date_format.=$value; }
    }

    foreach ($cal_date_format as $key => $value) { $cal_format =$value; }

    foreach ($regex as $key => $value)
    {
        if ($key < (count($regex) - 1)) { $regex_format =$value . $date_separator; }
        else { $regex_format.=$value; }
    }

    if ($tmpdate == null) { $tmpdate=date($plugin_tx[$plugin]['date_format'], time()); }
	
	if($date_separator1==".")
	{
		$dateArr=explode('.', $tmpdate);
	}
	if($date_separator1=="/")
	{
		$dateArr=explode('/', $tmpdate);
	}
	if($date_separator1=="-")
	{
		$dateArr=explode('-', $tmpdate);
	}
	$m =$dateArr[$monthposition];
	$d =$dateArr[$dayposition];
	$y =$dateArr[$yearposition];

    $tmpdate=mktime(0, null, null, $m, $d, $y);
    return ($tmpdate);
}

function realblog_dbconfirm ($title, $info, $page)
{
    // Display a confirmation
    global $plugin_tx, $plugin, $sn;

    if (!isset($page)) { $page=$_SESSION['page']; }

    $t ="<div><h4>" . ucfirst(REALBLOG_VERSION) . " : " . $title . "</h4></div>";
    $t.="<div>&nbsp;</div>";
    $t.="<form name=\"confirm\" method=\"post\" action=\"" . $sn . "?&" . $plugin . "&admin=plugin_main\">";
    $t.="<table width=\"100%\" class=\"realblogNoborder\"><tbody>";
    $t.="<tr><td class=\"realblog_confirm_info\" align=\"center\">" . $info . "</td></tr><tr><td>&nbsp;</td></tr>";
    $t.="<tr><td class=\"realblog_confirm_button\" align=\"center\"><input type=\"button\" name=\"cancel\" class=\"realblog_button_admin\" style=\"float: none; margin: 0 auto;\" value=\"" . $plugin_tx[$plugin]['btn_ok'] . "\" onclick='location.href=\"" . $sn . "?&" . $plugin . "&admin=plugin_main&action=plugin_text&page=" . $page . "\"'></td></tr>";
    $t.="</tbody></table></form>";
    $t.="<div>&nbsp;</div>";
    return ($t);
}


// BACKUPs Stapelsicherung

if(!is_dir('./backups/'))
{
	mkdir('./backups/', 0777, true);
	chmod('./backups/', 0777);
}

if(!is_dir('./backups/realblog/'))
{
	mkdir('./backups/realblog/', 0777, true);
	chmod('./backups/realblog/', 0777);
}

// create backups array
$backups_array = array();
if($realblog_backups_handle = opendir('./backups/realblog/'))
{
	while($backups_arrayElement = readdir($realblog_backups_handle))
	{
		if($backups_arrayElement != '.' && $backups_arrayElement != '..')
		{
			$backups_array[] = $backups_arrayElement;
			sort($backups_array);
		}
	}
}

// delete oldest
if(!isset($plugin_cf['realblog']['backups_number_of'])) $realblogNumberOfBackups = 20;
if(isset($plugin_cf['realblog']['backups_number_of'])) $realblogNumberOfBackups = $plugin_cf['realblog']['backups_number_of'];
if(count($backups_array) > $realblogNumberOfBackups) unlink('./backups/realblog/' . $backups_array[0]);

// create backup
if(isset($_POST['save']) || isset($_POST['realblog_headline']) || isset($_POST['realblog_story'])) copy('./content/realblog/' . $db_name, './backups/realblog/' . date("Y-m-d___H-i-s") . '_' . $db_name);

function realblog_rrmdir($dir)
{
	if (is_dir($dir))
	{
		$objects = scandir($dir);
		foreach ($objects as $object)
		{
			if ($object != "." && $object != "..") 
			{
				if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
			}
		}
		reset($objects);
		rmdir($dir);
	}
}

if(is_dir('./content/realblog/backups/') && count($backups_array) > 3) realblog_rrmdir('./content/realblog/backups/')
?>