schedule verifier
{source}
<?php
echo “<h1>Verifying the schedule</h1>”;
date_default_timezone_set(‘America/Los_Angeles’);
$today_date = strtotime(“last day of last month”);
$output = “”;
$output .= “<p>it is now “. date(‘D, M jS, Y g:i A T’).” </p>”;
# get list of current columnist titles – parent_id = 2183 for Columns
$sql =”SELECT `title`, id as category_id , path, alias, description FROM #__categories WHERE parent_id = 2183 AND title LIKE ‘%/%’ and level = 2 “;
$database->setQuery( $sql);
$database->query();
$titles = $database->loadAssocList(‘title’ );
// $titles should now be an array indexed by column titles with title, id, path, description
#echo “$titles = “.count($titles).”<pre>” ; var_dump($titles); echo “</pre>” ;
#echo “error = “. $database->getErrorNum();
$sql = “SELECT introtext FROM #__content WHERE `title` = ‘Column Schedule’ “;
$database->setQuery( $sql);
$database->query();
$rows = $database->loadObject();
if ($database->getErrorNum()) {
$output .= $database->stderr();
return false;
}
#echo “<pre>”. var_dump($rows, TRUE). “</pre><br />”;
$temp = str_replace(” “, ‘ ‘, $rows->introtext);
$table = html_entity_decode( $temp ) ;
$table = str_replace(‘<br />’, ‘n’, $table);
$table = preg_replace(“%<(i|b|span)( |).*?>%is”, “”, $table);
$table = preg_replace(“%<.*?>%is”, “”, $table);
#echo ” the values are $table <br>”;
$pattern = ‘%(.*)?!((( *[A-Z])|( *[0-9])).*)?n%i’;
// find all of the entries –
preg_match_all($pattern , $table , $matches, PREG_SET_ORDER);
$col_schedule = array();
foreach($matches as $match){
#echo “<pre>”.var_dump($match, TRUE). “</pre>” ;
if ((substr(trim($match[0]),0, 1) != ‘#’) && (substr(trim($match[0]),0,2) != ‘//’ ) ) {
# echo “we have a match “.$match[0]. “<br />”;
$pub_time = strtotime($match[2]);
if (($pub_time = strtotime($match[2])) === false) {
$output .= “<b>ERROR – The string ‘{$match[2]}’ for column id ‘{$match[1]}’is not a valid date string </b><br>”;
} else {
$col_schedule[ $pub_time] = trim($match[1]);
}
}
}
ksort($col_schedule);
#var_dump($col_schedule, TRUE);
$col_schedule = array_slice($col_schedule, -6, 999, TRUE); // just print last 10 rows of schedule
$output .= “n!– THE SCHEDULE ITEMS SORTED BY DATE n<br />”;
foreach ($col_schedule as $start_date => $colId){
$colId = strtr($colId, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES)));
$string = htmlentities($colId, null, ‘utf-8’);
$colId = str_replace(“ ”, “”, $string);
$colId = trim(html_entity_decode($colId));
$colId_full = array_filter($titles, function($key) use ($colId){
#echo “key<pre>”.print_r($key).”</pre>”;
#echo “key<pre>”.print_r($value) .”</pre>”;
# echo “key = $key and par = $colId <br />”;
#echo (stripos(” $key”, $colId ) > 0 ) ? “good one $key, $colId <br />”: “bad one $key, $colId <br>”;
$result = (stripos(” $key”, $colId ) > 0 ) ? $key : FALSE ;
return ($result);
}
, ARRAY_FILTER_USE_KEY) ;
#echo “key<pre>”.print_r($colId_full) .”</pre>”;
#echo “colId = $colId “.count($colId_full).” “;
$match_count = count($colId_full) ;
if ($match_count == 0 ) $colId = “<b>ERROR – $colId – does not match any column!! </b> ” ;
if ($match_count > 1 ) {
$colId = ” <b>ERROR – ‘$colId’ matches $match_count columns !! NOT SCHEDULED</b> n ” ;
$colId .= “matches “. serialize(array_keys($colId_full) ).” <br>”;
}
if ($match_count == 1) {
# echo “key returns “. key($colId_full) . “<br />”;
$colId = trim(substr(strstr(key($colId_full), ‘/ ‘), 2) ) ;
}
#echo “$colId <br />”;
$jstart_date = new JDate($start_date) ;
$jstart_date->setTimezone(‘America/Los_Angeles’);
date_default_timezone_set(‘America/Los_Angeles’);
$stampx = “$colId start as COTW on “.date(‘D, M jS, Y h:i A T’,$start_date);
$stamp = “$colId starts as COTW on ” . $jstart_date->format(“M jS, Y”);
#if ($jstart_date >= $today_date) {
if ($start_date >= $today_date) {
#$stamp = “<p> $colId scheduled as COTW on $jstart_date === $stampx </p>”;
$stamp = “<p style=’font-weight: bold;’> $stamp </p>”;
$more_schedule = “TRUE”;
}
else {
$stamp = “<p> $stamp <p>”;
$more_schedule = “FALSE”;
$first_par = $colId;
$sel_start_date = $jstart_date;
}
$output .= “$stamp “;
}
$output .= ” !– end of the schedule –>”;
// find category by matching category name
$output .=” n”;
$column_selected = ( array_filter($titles, function( $value, $key) use ($first_par){
#echo “key<pre>”.print_r($key).”</pre>”;
#echo “key<pre>”.print_r($value) .”</pre>”;
#echo “key = $key and par = $first_par <br />”;
return (stripos(” $key”, $first_par) > 0 );
}
, ARRAY_FILTER_USE_BOTH) );
#print_r($column_selected);
#$sql = “SELECT id , path, alias, description FROM #__categories WHERE `parent_id` = 2183 AND `title` LIKE ‘%$first_par%’ “;
#$database->setQuery( $sql);
#$database->query();
#$rows = $database->loadObject();
#print_r($column_selected);
$cat_alias = implode(“”,array_column($column_selected,’alias’));
#echo “cat_alias $cat_alias<br />”;
$output .= “”;
$output .= “”;
#$description = $rows->description;
$description = implode(“”,array_column($column_selected,’description’));
#echo “this is the description $description”;
$bad_flag = FALSE ;
if ($match_count == 1){
$first_par = implode(“”, array_column( $column_selected, ‘category_id’));
# echo “this is first_par – category_id $first_par <br>”;
$path = implode(“”, array_column($column_selected ,’path’));
$output .= “”;
}
echo “<p>$output</p>”;
?>
{/source}