/* This plugin sets a placeholder that displays the three latest articles to be posted to my modx site.
* Author: Sarah Vardy
* Date: Wed 7th November, 2007
*/
//This plugin that checks the database to see what articles have been posted the most recently
//get the timestamp from the server
if(!isset($timestamp)) {
$timestamp=time();
}
//select the modx table to use
$table = $modx->getFullTableName("site_content");
//An array to store the new articles that have been created
$newArticlesList = new array();
//An array to store the amount of time since the article has been published
$newArticlesTime = new array();
//A limit to limit the size of the array by
$maxArrayLength = 3;
//Index incrementer for the newArticlesList array
$indexIncrementer = 0;
//Most recent article
$recentArticleOne = '';
//Second most recent article
$recentArticleTwo = '';
//Third most recent article
$recentArticleThree = '';
//iterate through the table and see how close the articles createdBy time is to the timestamp
$result = $modx->db->select('*', $table);
//while there are still more rows in the table check to see whether the document is published
//if the value stored at the array index equals NULL store the
while ($r = $modx->db->getRow($result))
{
$createdby = $r['createdby'];
$published = $r['published'];
$publishedon = $r['publishedon'];
//if published does not equal false
if ($published != 0)
{
//subtract the current timestamp from the publishedon date and store it in a temporary variable
$tempTimeStore = $publishedon - $timestamp;
//if the value stored in the newArticlesList array at the index of indexIncrementer equals NULL
if ($newArticlesList($indexIncrementer) == NULL)
{
//store createdby in the newArticlesList array at the index of indexIncrementer
$newArticlesList($indexIncrementer) = $createdby;
//store createdby in the newArticlesTime array at the index of indexIncrementer
$newArticlesTime($indexIncrementer) = $tempTimeStore;
//if indexIncrementer equals 2 then reset it to 0
if ($indexIncrementer == 2)
{
//reset indexIncrementer to 0
$indexIncrementer = 0;
//return to the while loop
return;
}
else
{
//increment indexIncrementer by 1
$indexIncrementer++;
return;
}
}
else if ($newArticlesList($indexIncrementer) != NULL)
{
//iterate through the array of values stored in the newArticlesTime array
for ($i = 0; $i < $maxArrayLength; $i++)
{
//if the value stored in the newArticlesTime array is more than array the value of tempTimeStore
if ($newArticlesTime($i) > $tempTimeStore)
{
//replace the value stored in both arrays at this index with the current result
$newArticlesList($i) = $createdby;
$newArticlesTime($i) = $tempTimeStore;
return;
}
else
{
return;
}
}
}
}
}//end while
//set variables to set modx placeholders
$recentArticleOne = $newArticlesList(0);
$recentArticleTwo = $newArticlesList(1);
$recentArticleThree = $newArticlesList(2);
//set modx placeholders
$modx->setPlaceHolder('recentArticleOne', $recentArticleOne);
$modx->setPlaceHolder('recentArticleTwo', $recentArticleTwo);
$modx->setPlaceHolder('recentArticleThree', $recentArticleThree);
/* This plugin sets a placeholder that displays the three latest articles to be posted to my modx site.
* Author: Sarah Vardy
* Date: Wed 7th November, 2007
*/
//This plugin that checks the database to see what articles have been posted the most recently
//get the timestamp from the server
if(!isset($timestamp)) {
$timestamp = time();
}
//select the modx table to use
$table = $modx->getFullTableName("site_content");
//An array to store the new articles that have been created
$newArticlesList = new array();
//An array to store the amount of time since the article has been published
$newArticlesTime = new array();
//A limit to limit the size of the array by
$maxArrayLength = 3;
//Index incrementer for the newArticlesList array
$indexIncrementer = 0;
//Most recent article
$recentArticleOne = '';
//Second most recent article
$recentArticleTwo = '';
//Third most recent article
$recentArticleThree = '';
//iterate through the table and see how close the articles createdBy time is to the timestamp
$result = $modx->db->select('*', $table);
//while there are still more rows in the table check to see whether the document is published
//if the value stored at the array index equals NULL store the
while ($r = $modx->db->getRow($result))
{
$createdby = $r['createdby'];
$published = $r['published'];
$publishedon = $r['publishedon'];
//if published does not equal false
if ($published != 0)
{
//subtract the current timestamp from the publishedon date and store it in a temporary variable
$tempTimeStore = $publishedon - $timestamp;
//if the value stored in the newArticlesList array at the index of indexIncrementer equals NULL
if ($newArticlesList[$indexIncrementer] == NULL)
{
//store createdby in the newArticlesList array at the index of indexIncrementer
$newArticlesList[$indexIncrementer] = $createdby;
//store createdby in the newArticlesTime array at the index of indexIncrementer
$newArticlesTime[$indexIncrementer] = $tempTimeStore;
//if indexIncrementer equals 2 then reset it to 0
if ($indexIncrementer == 2)
{
//reset indexIncrementer to 0
$indexIncrementer = 0;
//return to the while loop
return;
}
else
{
//increment indexIncrementer by 1
$indexIncrementer++;
return;
}
}
else if ($newArticlesList[$indexIncrementer] != NULL)
{
//iterate through the array of values stored in the newArticlesTime array
for ($i = 0; $i < $maxArrayLength; $i++)
{
//if the value stored in the newArticlesTime array is more than array the value of tempTimeStore
if ($newArticlesTime[$i] > $tempTimeStore)
{
//replace the value stored in both arrays at this index with the current result
$newArticlesList[$i] = $createdby;
$newArticlesTime[$i] = $tempTimeStore;
return;
}
else
{
return;
}
}
}//end if /else
}
else
{
return;
}//end if
}//end while
//set variables to set modx placeholders
$recentArticleOne = $newArticlesList[0];
$recentArticleTwo = $newArticlesList[1];
$recentArticleThree = $newArticlesList[2];
//set modx placeholders
$modx->setPlaceHolder('recentArticleOne', $recentArticleOne);
$modx->setPlaceHolder('recentArticleTwo', $recentArticleTwo);
$modx->setPlaceHolder('recentArticleThree', $recentArticleThree);
<?php
/* This snippet displays the three latest articles to be posted to the RCS IT Newsletters site.
* Author: Sarah Vardy
* Date: Wed 7th November, 2007
* Research Computing Services, Griffith University, Nathan QLD
*/
//This plugin that checks the database to see what articles have been posted the most recently
//get the timestamp from the server
if(!isset($timestamp)) {
$timestamp = time();
}
//select the modx table to use
$table = $modx->getFullTableName("site_content");
//An array to store the new articles that have been created
$newArticlesList = new array();
//An array to store the amount of time since the article has been published
$newArticlesTime = new array();
//A limit to limit the size of the array by
$maxArrayLength = 3;
//Index incrementer for the newArticlesList array
$indexIncrementer = 0;
//Most recent article
$recentArticleOne = '';
//Second most recent article
$recentArticleTwo = '';
//Third most recent article
$recentArticleThree = '';
//iterate through the table and see how close the articles createdBy time is to the timestamp
$result = $modx->db->select('*', $table);
//while there are still more rows in the table check to see whether the document is published
//if the value stored at the array index equals NULL store the
while ($r = $modx->db->getRow($result))
{
$createdby = $r['createdby'];
$published = $r['published'];
$publishedon = $r['publishedon'];
//if published does not equal false
if ($published != 0)
{
//subtract the current timestamp from the publishedon date and store it in a temporary variable
$tempTimeStore = $publishedon - $timestamp;
//if the value stored in the newArticlesList array at the index of indexIncrementer equals NULL
if ($newArticlesList[$indexIncrementer] == NULL)
{
//store createdby in the newArticlesList array at the index of indexIncrementer
$newArticlesList[$indexIncrementer] = $createdby;
//store createdby in the newArticlesTime array at the index of indexIncrementer
$newArticlesTime[$indexIncrementer] = $tempTimeStore;
//if indexIncrementer equals 2 then reset it to 0
if ($indexIncrementer == 2)
{
//reset indexIncrementer to 0
$indexIncrementer = 0;
//return to the while loop
//return;
//break;
}
else
{
//increment indexIncrementer by 1
$indexIncrementer++;
//return;
//break;
}
}
else if ($newArticlesList[$indexIncrementer] != NULL)
{
//iterate through the array of values stored in the newArticlesTime array
for ($i = 0; $i < $maxArrayLength; $i++)
{
//if the value stored in the newArticlesTime array is more than array the value of tempTimeStore
if ($newArticlesTime[$i] > $tempTimeStore)
{
//replace the value stored in both arrays at this index with the current result
$newArticlesList[$i] = $createdby;
$newArticlesTime[$i] = $tempTimeStore;
//return;
//break;
}
else
{
//return;
//break;
}
}
}//end if /else
}
else
{
//return;
//break;
}//end if
}//end while
for ($j = 0; $j < 3; $j++)
{
print $newArticlesList[$j];
print "<br>";
}
?>