When an image gallery has several thousands images and a deep tree of folders, it may be difficult
to find out what the latest changes are. This sample shows how mark new and updated
albums in tree with an icon or text to make latest modifications immediately visible.
The code below adds two custom fields to every album: creation date and modification date. Creation date
is set to today's date when .albumdef.ini is created. Modification date must be changed manually in
album properties whenever the album is modified (it's just YYMMDD format): pictures added, important comment
changes made etc. Modification date is automatically propagated up the folder tree during reindex. Folder with a
new or modified subfolder gets its modification date set to the latest updated subfolder modification date.
CExAlbumModified::GetTreeNodeCode method verifies if current album has been modified during the last 10 days
and displays new! text after album name for new albums and updated! -
for updated albums. You can display different text or an image instead.
Instructions
1. Edit you custom.php and add
the following code. Modify GetTreeNodeCode method to include preferred number of days and the method to
mark modified albums.
| // Localize text strings below (these localizations will be added
// to DAlbum installation later)
if (!isset($lang['cModifiedNew']))
{
$lang['cModifiedNew']='new!';
$lang['cModifiedUpdated']='updated!';
}
class CExAlbumModified extends CAlbum
{
function Create($sPath, $parentUsers,$bCleanup, $bDeleteImages=false)
{
// New albums get modification time set to today's date
if (!file_exists(absfname($sPath."/.albumdef.ini")))
{
$this->m_arrCustomFields["Modified_YYMMDD"]=
$this->m_arrCustomFields["Created_YYMMDD"]=date("ymd");
}
// Call default implementation
return parent::Create($sPath,$parentUsers,$bCleanup,$bDeleteImages);
}
// Get list of custom field names
function &GetCustomFieldNames()
{
$f=parent::GetCustomFieldNames();
$f[]="Created_YYMMDD";
$f[]="Modified_YYMMDD";
return $f;
}
// Modify tree node text
function GetTreeNodeCode($myID,$nParentID,$sText,$sRef)
{
// Display (Modified) or (Updated) for those modified/updated 10 days ago or less.
// (change 10 to any number of days you wish)
$dateRecent=date("ymd",time()-86400*10);
$cur_ct=$this->GetCustomField("Created_YYMMDD");
$cur_mt=$this->GetCustomField("Modified_YYMMDD");
global $lang;
$sAdd="";
$dr=DALBUM_BROWSERROOT;
// Modify tree item text
if ($cur_ct>$dateRecent)
{
// This displays text only
$sAdd=" <sup><b>".$lang['cModifiedNew']."</b></sup>";
// Uncomment the next 2 lines to display custimg/new.gif next to new albums
//$sAdd=" <sup><img src=\'{$dr}custimg/new.gif\' alt=\'\' title=\'".
// $lang['cModifiedNew']."\'></sup>";
}
elseif ($cur_mt>$dateRecent)
{
// This displays text only
$sAdd=" <sup><b>".$lang['cModifiedUpdated']."</b></sup>";
// Uncomment the next 2 lines to display custimg/updated.gif next to updated albums
//$sAdd=" <sup><img src=\'{$dr}custimg/updated.gif\' alt=\'\' title=\'".
// $lang['cModifiedUpdated']."\'></sup>";
}
if (!empty($sAdd) && $this->m_sFolder!='/')
$sText.=$sAdd;
// Call default implementation to display updated string.
return parent::GetTreeNodeCode($myID,$nParentID,$sText,$sRef);
}
// This function is always called during reindex AFTER subfolders are loaded
function ParseDetails(&$ini_array,$bAllDetails)
{
parent::ParseDetails($ini_array,$bAllDetails);
// Get modified time for this folder
$cur_mt=$this->GetCustomField("Modified_YYMMDD");
if (strlen($cur_mt)!=6)
$cur_mt="000000";
$cur_ct=$this->GetCustomField("Created_YYMMDD");
if (strlen($cur_ct)!=6)
$cur_ct="000000";
// Go through all subfolders and set this folder modification time
// to not be before any subfolder modification time
for ($i=0;$i<count($this->m_arrContents);++$i)
{
$obj=&$this->m_arrContents[$i];
if (!$obj->IsImage())
{
$mt=$obj->GetCustomField("Modified_YYMMDD");
if (!empty($mt) && $mt>$cur_mt)
$cur_mt=$mt;
}
}
if ($this->GetCustomField("Modified_YYMMDD")!=$cur_mt)
{
$this->m_arrCustomFields["Modified_YYMMDD"]=$cur_mt;
$this->m_arrCustomFields["Created_YYMMDD"]=$cur_ct;
create_defaultIni($this,true);
}
}
}
function &customCreateAlbum()
{
return new CExAlbumModified();
} |
2. Reindex (you may also need to delete .private/.album_index.dat file). When you
add new albums they will be marked as "new!" in album tree and their parent albums marked as "updated!".
|