1 (edited by 2008-08-01 16:27:04)

Topic: [HACK] Choose Date/Time For Posts & Prospective Posting

Name: Choose Date/Time For Posts & Prospective Posting
Author: NyNe
CuteNews Compatibility: 1.3.6 - 1.4.1
Description: What This Hack Does:
This hack will add date/time selector boxes in both add and edit news.
*update: If the time you enter in either edit or add news is the same as a time already in the database it will add 1 second to the time.
*update: When adding or editing news, the news.txt and comments.txt will be sorted by order of timestamp
It will also put an option in the system config for administrators to turn prospective posting on/off.
With prospective posting on, posts that have been written with dates in the future will not display until their date.

credit to maraboli for conceptual coding
credit to fusion news for the date displaying in html forms
Instructions:

open ./inc/options.mdu
find:

showRow("Reverse News", "if yes, older news will be shown on the top", makeDropDown(array("yes"=>"Yes","no"=>"No"), "save_con[reverse_active]", "$config_reverse_active"));


add below:

// <!-- Start ModifyTime v2.0 -->
        showRow("Prospective Posting", "news in the future does not display until its date", makeDropDown(array("yes"=>"Yes","no"=>"No"), "save_con[prospective_posting]", "$config_prospective_posting"));
// <!-- End ModifyTime v2.0 -->


open ./data/config.php
find:

$config_reverse_active = "no";


add under: (change yes to no if you'd like it turned off, can be changed from system config later)

$config_prospective_posting = "yes";


open ./inc/shows.inc.php
find:

if($category and $requested_cats[$news_arr[6]] != TRUE){ continue; }


add above:

// <!-- Start ModifyTime v2.0 -->
if ($config_prospective_posting == "yes") { $current_date = date("U"); if ($news_arr[0] > $current_date) { continue; } }
// <!-- End ModifyTime v2.0 -->


open ./inc/addnews.mdu
find:

if($member_db[1] > 3){ msg("error", "Access Denied", "You don't have permission to add news"); }


add under:

// <!-- Start ModifyTime v2.0 -->
$months = array('01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
if ($config_prospective_posting == "yes") { $prospective_message = "<font style=\"font-size:7pt\">(posts in the future will not be displayed until after their dates)</font>"; } else { $prospective_message = ""; }
$current_time = time()+ ($config_date_adjust*60);
// <!-- End ModifyTime v2.0 -->

find:

    echo "
    <script LANGUAGE=\"JavaScript\">
    function preview(){


add above:

// <!-- Start ModifyTime v2.0 -->
  $month = "<select size=\"1\" name=\"edit_month\">";
  for($i=1;$i<=12;$i++){
    if( $i < 10 ) $i = '0'.$i;
    if( date("m", $current_time) == $i )
      $selected = " selected";
    else
      $selected = "";
    $month .= "<option value=\"$i\"$selected>".$months[$i]."</option>";
  }
  $month .= "</select>";
  $day = "<select size=\"1\" name=\"edit_day\">";
  for($i=1;$i<=31;$i++){
    if( date("j", $current_time) == $i )
      $selected = " selected";
    else
      $selected = "";
    $day .= "<option value=\"$i\"$selected>$i</option>";
  }
  $day .= "</select>";
  $year = "<select size=\"1\" name=\"edit_year\">";
  for($i=(date("Y")-30);$i<=(date("Y")+30);$i++){
    if( date("Y", $current_time) == $i )
      $selected = " selected";
    else
      $selected = "";
    $year .= "<option value=\"$i\"$selected>$i</option>";
  }
  $year .= "</select>";
  $hour = "<select size=\"1\" name=\"edit_hour\">";
  for($i=0;$i<=23;$i++){
    if( date("G", $current_time) == $i )
      $selected = " selected";
    else
      $selected = "";
    $hour .= "<option value=\"$i\"$selected>$i</option>";
  }
  $hour .= "</select>";
  $min = "<select size=\"1\" name=\"edit_min\">";
 for($i=0;$i<=59;$i++){
    if( $i < 10 ) $i = '0'.$i;
    if( date("i", $current_time) == $i )
      $selected = " selected";
    else
      $selected = "";
    $min .= "<option value=\"$i\"$selected>$i</option>";
  }
  $min .= "</select>";
  $sec = "<select size=\"1\" name=\"edit_sec\">";
  for($i=0;$i<=59;$i++){
    if( $i < 10 ) $i = '0'.$i;
    if( date("s", $current_time) == $i )
      $selected = " selected";
    else
      $selected = "";
    $sec .= "<option value=\"$i\"$selected>$i</option>";
  }
  $sec .= "</select>";
// <!-- End ModifyTime v2.0 -->

find:

<form method=post name=addnews action=\"$PHP_SELF\">


add below:

<!-- Start ModifyTime v2.0 -->
       <tr>
       <td valign=middle width=\"75\">
       Date:
       <td width=\"571\" colspan=\"7\">
       $month$day$year
       </tr>
       <tr>
       <td valign=middle width=\"75\">
       Time:
       <td width=\"571\" colspan=\"7\">
       $hour:$min:$sec $prospective_message
       </tr>
<!-- End ModifyTime v2.0 -->

find:

$added_time = time()+ ($config_date_adjust*60);


replace with:

    // <!-- Start ModifyTime v2.0 -->
    $added_time = strtotime("$edit_day ".$months[$edit_month]." $edit_year $edit_hour:$edit_min:$edit_sec");
    // <!-- End ModifyTime v2.0 -->

find:

$all_db = file("./data/news.txt");


add under:

// <!-- Start ModifyTime v2.0 -->
    rsort($all_db); reset($all_db);
// <!-- End ModifyTime v2.0 -->

find:

foreach ($all_db as $line){ fwrite($news_file, "$line");}


replace with:

// <!-- Start ModifyTime v2.0 -->
rsort($all_db);  reset($all_db);
foreach ($all_db as $null => $line){ fwrite($news_file, "$line");}
// <!-- End ModifyTime v2.0 -->

find:

    fwrite($new_com_db, "$added_time|>|\n");
    foreach ($old_com_db as $line){ fwrite($new_com_db, "$line");}


replace with:

// <!-- Start ModifyTime v2.0 -->
    fwrite($new_com_db, "$added_time|>|\n");
    rsort($old_com_db);  reset($old_com_db);
    foreach ($old_com_db as $null => $line){ fwrite($new_com_db, "$line");}
// <!-- End ModifyTime v2.0 -->


open ./inc/editnews.mdu
find:

if($member_db[1] > 3){ msg("error", "Access Denied", "You don't have permission to edit news"); }


add under:

// <!-- Start ModifyTime v2.0 -->
$months = array('01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
if ($config_prospective_posting == "yes") { $prospective_message = "<font style=\"font-size:7pt\">(posts in the future will not be displayed until after their dates)</font>"; } else { $prospective_message = ""; }
// <!-- End ModifyTime v2.0 -->

find:

    echo"
    <script LANGUAGE=\"JavaScript\">
        function preview(){


add above:

// <!-- Start ModifyTime v2.0 -->
  $month = "<select size=\"1\" name=\"edit_month\">";
  for($i=1;$i<=12;$i++){
    if( $i < 10 ) $i = '0'.$i;
    if( date("m", $item_db[0]) == $i )
      $selected = " selected";
    else
      $selected = "";
    $month .= "<option value=\"$i\"$selected>".$months[$i]."</option>";
  }
  $month .= "</select>";
  $day = "<select size=\"1\" name=\"edit_day\">";
  for($i=1;$i<=31;$i++){
    if( date("j", $item_db[0]) == $i )
      $selected = " selected";
    else
      $selected = "";
    $day .= "<option value=\"$i\"$selected>$i</option>";
  }
  $day .= "</select>";
  $year = "<select size=\"1\" name=\"edit_year\">";
  for($i=(date("Y")-30);$i<=(date("Y")+30);$i++){
    if( date("Y", $item_db[0]) == $i )
      $selected = " selected";
    else
      $selected = "";
    $year .= "<option value=\"$i\"$selected>$i</option>";
  }
  $year .= "</select>";
  $hour = "<select size=\"1\" name=\"edit_hour\">";
  for($i=0;$i<=23;$i++){
    if( date("G", $item_db[0]) == $i )
      $selected = " selected";
    else
      $selected = "";
    $hour .= "<option value=\"$i\"$selected>$i</option>";
  }
  $hour .= "</select>";
  $min = "<select size=\"1\" name=\"edit_min\">";
 for($i=0;$i<=59;$i++){
    if( $i < 10 ) $i = '0'.$i;
    if( date("i", $item_db[0]) == $i )
      $selected = " selected";
    else
      $selected = "";
    $min .= "<option value=\"$i\"$selected>$i</option>";
  }
  $min .= "</select>";
  $sec = "<select size=\"1\" name=\"edit_sec\">";
  for($i=0;$i<=59;$i++){
    if( $i < 10 ) $i = '0'.$i;
    if( date("s", $item_db[0]) == $i )
      $selected = " selected";
    else
      $selected = "";
    $sec .= "<option value=\"$i\"$selected>$i</option>";
  }
  $sec .= "</select>";
// <!-- End ModifyTime v2.0 -->

find:

        <td valign=middle width=\"75\">
        Info.
        <td width=\"571\" colspan=\"6\">
        Posted on $newstime by $item_db[1]


replace with:

<!-- Start ModifyTime v2.0 -->
        <tr>
        <td valign=middle width=\"75\">
        Info.
        <td width=\"571\" colspan=\"6\">
        Posted on $newstime by $item_db[1]
        </tr>
        <tr>
        <td valign=middle width=\"75\">
        Date:
        <td width=\"571\" colspan=\"7\">
        $month$day$year
        </tr>
        <tr>
        <td valign=middle width=\"75\">
        Time:
        <td width=\"571\" colspan=\"7\">
        $hour:$min:$sec $prospective_message
        </tr>
        <input type=hidden name=pass_time value=$item_db[0]>
<!-- End ModifyTime v2.0 -->

find:

fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$category||\n");


replace with:

//<!-- Start ModifyTime v2.0 -->
$converted_input_date=strtotime("$edit_day ".$months[$edit_month]." $edit_year $edit_hour:$edit_min:$edit_sec");
$all_db = file("./data/news.txt"); rsort($all_db); reset($all_db);
foreach($all_db as $null => $news_line){ $news_arr = explode("|", $news_line); if($news_arr[0] == $converted_input_date){ $converted_input_date++; } }
if ($disable_comments != 1) $disable_comments = 0;
fwrite($new_db,"$converted_input_date|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$category||\n");
$ccf=""; $converted_com_file = file($com_file);
for ($c = 0; $c < sizeof($converted_com_file); $c++) {$ccf=$ccf.$converted_com_file[$c];}
$fp = fopen($com_file, "wb"); fwrite($fp, str_replace($pass_time,$converted_input_date,$ccf)); fclose($fp);
//<!-- End ModifyTime v2.0 -->

find:

fclose($new_db);


add under:

//<!-- Start ModifyTime v2.0 -->
  $sorted_news = file("./data/news.txt"); sort($sorted_news); reset($sorted_news);
  foreach ($sorted_news as $null => $sorted_news_line) {
      $sorted_news_output = str_replace("\n", "", $sorted_news_line)."\n".$sorted_news_output;
  }
  $fp = fopen($news_file, "wb"); fwrite($fp, $sorted_news_output); fclose($fp);
//<!-- End ModifyTime v2.0 -->

find:

msg("info","Changes Saved","The changes were successfully saved", "$PHP_SELF?mod=editnews&action=editnews&id=$id&source=$source");


replace with:

// <!-- Start ModifyTime v2.0 -->
msg("info","Changes Saved","The changes were successfully saved", "$PHP_SELF?mod=editnews&action=editnews&id=$converted_input_date&source=$source");
// <!-- End ModifyTime v2.0 -->

and you're done!

2 (edited by 2009-01-08 14:40:26)

Re: [HACK] Choose Date/Time For Posts & Prospective Posting

Updated By: DooSHeK
CuteNews Compatibility: 1.4.5 - * (no incompatibility reported yet)
Instructions:
open ./inc/options.mdu

find:

showRow("Reverse News", "if yes, older news will be shown on the top", makeDropDown(array("yes"=>"Yes","no"=>"No"), "save_con[reverse_active]", "$config_reverse_active"));

add below:

showRow("Prospective Posting", "news in the future does not display until its date", makeDropDown(array("yes"=>"Yes","no"=>"No"), "save_con[prospective_posting]", "$config_prospective_posting"));

open ./data/config.php

find:

$config_reverse_active = "no";

add below:

$config_prospective_posting = "yes";

open ./inc/shows.inc.php

find (twice):

if($requested_cats and $requested_cats[$news_arr[6]] == TRUE){ $is_in_cat=TRUE;}

add above (in two places):

if ($config_prospective_posting == "yes") { $current_date = date("U"); if ($news_arr[0] > $current_date) { continue; } }

open ./inc/addnews.mdu

find:

if($member_db[1] > 3){ msg("error", "Access Denied", "You don't have permission to add news"); }

add under:

$months = array('01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
if ($config_prospective_posting == "yes") { $prospective_message = "<font style=\"font-size:7pt\">(post with future date won't be displayed until seted date)</font>"; } else { $prospective_message = ""; }
$current_time = time()+ ($config_date_adjust*60);

find:

echo "
<script LANGUAGE=\"JavaScript\">
function preview(){

add above:

$month = "<select size=\"1\" name=\"edit_month\">";
for($i=1;$i<=12;$i++){
if( $i < 10 ) $i = '0'.$i;
if( date("m", $current_time) == $i )
$selected = " selected";
else
$selected = "";
$month .= "<option value=\"$i\"$selected>".$months[$i]."</option>";
}
$month .= "</select>";
$day = "<select size=\"1\" name=\"edit_day\">";
for($i=1;$i<=31;$i++){
if( date("j", $current_time) == $i )
$selected = " selected";
else
$selected = "";
$day .= "<option value=\"$i\"$selected>$i</option>";
}
$day .= "</select>";
$year = "<select size=\"1\" name=\"edit_year\">";
for($i=(date("Y")-30);$i<=(date("Y")+30);$i++){
if( date("Y", $current_time) == $i )
$selected = " selected";
else
$selected = "";
$year .= "<option value=\"$i\"$selected>$i</option>";
}
$year .= "</select>";
$hour = "<select size=\"1\" name=\"edit_hour\">";
for($i=0;$i<=23;$i++){
if( date("G", $current_time) == $i )
$selected = " selected";
else
$selected = "";
$hour .= "<option value=\"$i\"$selected>$i</option>";
}
$hour .= "</select>";
$min = "<select size=\"1\" name=\"edit_min\">";
for($i=0;$i<=59;$i++){
if( $i < 10 ) $i = '0'.$i;
if( date("i", $current_time) == $i )
$selected = " selected";
else
$selected = "";
$min .= "<option value=\"$i\"$selected>$i</option>";
}
$min .= "</select>";
$sec = "<select size=\"1\" name=\"edit_sec\">";
for($i=0;$i<=59;$i++){
if( $i < 10 ) $i = '0'.$i;
if( date("s", $current_time) == $i )
$selected = " selected";
else
$selected = "";
$sec .= "<option value=\"$i\"$selected>$i</option>";
}
$sec .= "</select>";

find:

<form onSubmit = \"return submitForm();\"  method=post name=addnews action=\"$PHP_SELF\">
        <table border=0 cellpading=0 cellspacing=0 width=\"654\" >

add below:

<tr>
<td valign=middle width=\"75\">
Date:
<td width=\"571\" colspan=\"7\">
$month$day$year
</tr>
<tr>
<td valign=middle width=\"75\">
Time:
<td width=\"571\" colspan=\"7\">
$hour:$min:$sec $prospective_message
</tr>

find (twice):

$added_time = time()+ ($config_date_adjust*60);

replace with (in two places):

$added_time = strtotime("$edit_day ".$months[$edit_month]." $edit_year $edit_hour:$edit_min:$edit_sec");

find:

$all_db = file("$decide_news_file");

add below:

rsort($all_db); reset($all_db);

find:

$news_file = fopen("$decide_news_file", "w");
fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$nice_category||\n");
foreach ($all_db as $line){ fwrite($news_file, "$line");}
fclose($news_file);

replace with:

$news_file = fopen("$decide_news_file", "w");
$edittime="";
$edituser="";
fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$nice_category||\n");
rsort($all_db); reset($all_db);
foreach ($all_db as $null => $line){ fwrite($news_file, "$line");}
fclose($news_file);

find:

fwrite($new_com_db, "$added_time|>|\n");
foreach ($old_com_db as $line){ fwrite($new_com_db, "$line");}

replace with:

fwrite($new_com_db, "$added_time|>|\n");
rsort($old_com_db); reset($old_com_db);
foreach ($old_com_db as $null => $line){ fwrite($new_com_db, "$line");}

open ./inc/editnews.mdu

find:

if($member_db[1] > 3){ msg("error", "Access Denied", "You don't have permission to edit news"); }

add below:

$months = array('01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
$currenttime   = strtotime(date("D, d F Y H:i:s"));
if ($config_prospective_posting == "yes") { $prospective_message = "<font style=\"font-size:7pt\">(post with future date won't be displayed until seted date)</font>"; } else { $prospective_message = ""; }

find:

echo"
<script LANGUAGE=\"JavaScript\">
function preview(){

add above:

$month = "<select size=\"1\" name=\"edit_month\">";
for($i=1;$i<=12;$i++){
if( $i < 10 ) $i = '0'.$i;
if( date("m", $item_db[0]) == $i )
$selected = " selected";
else
$selected = "";
$month .= "<option value=\"$i\"$selected>".$months[$i]."</option>";
}
$month .= "</select>";
$day = "<select size=\"1\" name=\"edit_day\">";
for($i=1;$i<=31;$i++){
if( date("j", $item_db[0]) == $i )
$selected = " selected";
else
$selected = "";
$day .= "<option value=\"$i\"$selected>$i</option>";
}
$day .= "</select>";
$year = "<select size=\"1\" name=\"edit_year\">";
for($i=(date("Y")-30);$i<=(date("Y")+30);$i++){
if( date("Y", $item_db[0]) == $i )
$selected = " selected";
else
$selected = "";
$year .= "<option value=\"$i\"$selected>$i</option>";
}
$year .= "</select>";
$hour = "<select size=\"1\" name=\"edit_hour\">";
for($i=0;$i<=23;$i++){
if( date("G", $item_db[0]) == $i )
$selected = " selected";
else
$selected = "";
$hour .= "<option value=\"$i\"$selected>$i</option>";
}
$hour .= "</select>";
$min = "<select size=\"1\" name=\"edit_min\">";
for($i=0;$i<=59;$i++){
if( $i < 10 ) $i = '0'.$i;
if( date("i", $item_db[0]) == $i )
$selected = " selected";
else
$selected = "";
$min .= "<option value=\"$i\"$selected>$i</option>";
}
$min .= "</select>";
$sec = "<select size=\"1\" name=\"edit_sec\">";
for($i=0;$i<=59;$i++){
if( $i < 10 ) $i = '0'.$i;
if( date("s", $item_db[0]) == $i )
$selected = " selected";
else
$selected = "";
$sec .= "<option value=\"$i\"$selected>$i</option>";
}
$sec .= "</select>";

find:

<td valign=middle width=\"75\">
Info.
<td width=\"571\" colspan=\"6\">
Posted on $newstime by $item_db[1]

replace with:

<!-- Start ModifyTime v2.0 -->
        <tr>
        <td valign=middle width=\"75\">
        Info.
        <td width=\"571\" colspan=\"6\">
        Posted on $newstime by $item_db[1]
        </tr>
        <tr>
        <td valign=middle width=\"75\">
        Date:
        <td width=\"571\" colspan=\"7\">
        $month$day$year
        </tr>
        <tr>
        <td valign=middle width=\"75\">
        Time:
        <td width=\"571\" colspan=\"7\">
        $hour:$min:$sec $prospective_message
        </tr>
        <input type=hidden name=pass_time value=$item_db[0]>
<!-- End ModifyTime v2.0 -->

find:

fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$nice_category||\n");

replace with:

//<!-- Start ModifyTime v2.0 -->
$converted_input_date=strtotime("$edit_day ".$months[$edit_month]." $edit_year $edit_hour:$edit_min:$edit_sec");
$all_db = file("./data/news.txt"); rsort($all_db); reset($all_db);
foreach($all_db as $null => $news_line){ $news_arr = explode("|", $news_line); if($news_arr[0] == $converted_input_date){ $converted_input_date++; } }
if ($disable_comments != 1) $disable_comments = 0;
fwrite($new_db,"$converted_input_date|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$nice_category||\n");
$ccf=""; $converted_com_file = file($com_file);
for ($c = 0; $c < sizeof($converted_com_file); $c++) {$ccf=$ccf.$converted_com_file[$c];}
$fp = fopen($com_file, "wb"); fwrite($fp, str_replace($pass_time,$converted_input_date,$ccf)); fclose($fp);
//<!-- End ModifyTime v2.0 -->

find:

fclose($new_db);

add below:

$sorted_news = file($news_file); sort($sorted_news); reset($sorted_news);
foreach ($sorted_news as $null => $sorted_news_line) {
$sorted_news_output = str_replace("\n", "", $sorted_news_line)."\n".$sorted_news_output;
}
$fp = fopen($news_file, "wb"); fwrite($fp, $sorted_news_output); fclose($fp);

find:

msg("info","Changes Saved","The changes were successfully saved", "$PHP_SELF?mod=editnews&action=editnews&id=$id&source=$source");

replace with:

msg("info","Changes Saved","The changes were successfully saved", "$PHP_SELF?mod=editnews&action=editnews&id=$converted_input_date&source=$source");