6. Functions in file iminfo_xhr.php¶
Function content
- Functions in file iminfo_xhr.php
- Private variables
- check_mediacount_iminfo_files()
- DetailedStatusAnalysis(…)
- GetIminfoObjects()
- get_medianames_from_iminfo(…)
- ImArray2IminfoXML(…)
- IminfoNewImageObject(…)
- IminfoNewVideoObject(…)
- IminfoTXT2IminfoXML(…)
- Iminfo_XML_Objects_UpdateAndSave(…)
- send_email_update_iminfo(…)
- updateIminfoXMLFile(…)
- updateIminfoFiles(…)
6.1. Private variables¶
6.1.1. Private data in check_mediacount_iminfo_files()
¶
-
property
$update_iminfo
¶ Private data array of integers. Array length is determined by the number of locations (each location directory has an iminfo.xml file). Each number represents how to update the iminfo.xml in each location directory. Possible values for each array element are:
- UPDATE_IMINFO_NOFILE (0x0): the file iminfo.xml needs to be generated with the available information,
- UPDATE_IMINFO_EXISTS_OK (0x1): default situation,
- UPDATE_IMINFO_MEDIACOUNT (0x2): the file iminfo.xml needs to be updated because media content in public and/or private directories has been changed (removing and adding media).
- In the normal workflow of adding new media, media is added to a location directory. Updating to public or private directories need confirmation by the owner or administrator, i.e. different type of update process compared to adding media directly public and or private directories, which is not the recommended workflow of adding new media (see next bullet)
- New media has been added directly to public and or private directories. When this is detected the iminfo.xml must be updated automatically without user or administrator credentials.
The update will result in:
- Adding or removing media elements (i.e. <media> … </media>,
- Updating elements:
- <ImageInfo><PublicCount>NN</PublicCount></ImageInfo>,
- <VideoInfo><PublicCount>NN</PublicCount></VideoInfo>, and
- <VideoInfo><PublicFilesCount>NN</PublicFilesCount></VideoInfo>
- UPDATE_IMINFO_VERSION (0x4): the file iminfo.xml needs to be updated (internal structure is modified and must be such that it is backwards compatible),
- UPDATE_IMINFO_MAXCOUNT (0x8),
-
property
$Iminfo_check
¶ Private data array (matrix): #rows= #locations, #columns=8: columns are specified with associative keys
- Column 1 [‘xml_pub_im’]: number of public images in iminfo.xml,
- Column 2 [‘xml_pub_vi’]: number of public videos in iminfo.xml,
- Column 3 [‘xml_prv_im’]: number of private images in iminfo.xml,
- Column 4 [‘xml_prv_vi’]: number of private videos in iminfo.xml,
- Column 5 [‘xml_r_pub_im’]: number of public released images in iminfo.xml,
- Column 6 [‘xml_r_pub_vi’]: number of public released videos in iminfo.xml,
- Column 7 [‘xml_r_prv_im’]: number of private released images in iminfo.xml,
- Column 8 [‘xml_r_prv_vi’]: number of private released videos in iminfo.xml,
- Column 5 [‘loc_pub_im’]: number of images in public directory,
- Column 6 [‘loc_pub_vi’]: number of videos in public directory
-
property
$update_media_dir
¶ Private data array with numerical keys and the length is determined by the number of locations. Each element is an array with 2 associative keys:
- Column 1 [‘name’]: Name of location directory
- Column 1 [‘modus’]: Update modus. Initialization value: UPD_NOTHING. For other values: see Table 2.5.
6.1.2. Private data in Iminfo_XML_Objects_UpdateAndSave()
, updateIminfoFiles()
¶
-
property
$upd_succ
¶ Private datastructure: Numerical array with length of count($new_media_list) where each element is an array with the following keys:
- ‘status’ => UPDATE_IMINFO_EXISTS_OK,
- ‘directory’ => ‘’,
- ‘fname’ => ‘iminfo.xml’,
- ‘reason’=> ‘’,
- ‘code’ => 0,
- ‘iminfo_version’ => $iminfo_version.
6.1.3. Private data in DetailedStatusAnalysis()
¶
-
property
$new_media
¶ Private datastructure: Object structure is also shown in Fig. 6.2. Array with new media, and array length is determined by the number of locations and location directoryname is primary key. Each element has 4 sub-object identified with sub-keys:
$NewMedia[‘location’][‘image_files’][$i][0]: 2 index - array with numerical keys for new image filenames. Each element has 3 associated subkeys:
- First index ($i): new image media counter.
- Second index: 0 (use of second index is to be consistent with the [‘video_files’] sub-object.
$NewMedia[‘location’][‘video_files’][$i][$k]: 2 index – array with numerical keys for new video filenames. Each element has 3 associated subkeys:
- First index ($i): new video media counter.
- Second index ($k): number of different video formats for the current video (i.e. files with same basename but with different extensions. E.g.:
video_file.mp4
, andvideo_file.webm
represent the same video media, but there are 2 files). The element itself has 3 associated subkeys (such as for images):
- [‘name’]: (String) filename of the new video,
- [‘pubpriv’]: (String) new video must be stored in public or private directory (the same for all the different video formats of the same video).
- [‘tableEntry’]: (Intger) -1, which is an initialization value. Row position in the table is not yet known (see Fig. 5.3 and Fig. 5.4).
$NewMedia[‘location’][‘image_count’]: Number of new image media filenames,
$NewMedia[‘location’][‘video_count’]: Number of new video media filenames. Video filenames with the same basename but with different extensions will be considered as only one filename!
Remark: if no new media is detected this output argument is NOT empty. The length of the array is determined by the number of location directories. This means the array length does not to be equal to the number new media.
-
property
$rem_media
¶ Private datastructure: Array with associative keys (location directory names) length determined by the number of locations. Each element is a numerical ( $k) array with length determined by the number of removed media. Each element of this array is a smaller object (array) with the following associative keys:
- $RemMedia[‘location’][$k][‘name’]: (String) filename of media selected to be removed,
- $RemMedia[‘location’][$k][‘public_private’]: (String) ‘public’ or ‘private’,
- $RemMedia[‘location’][$k][‘TransferStatus’]: (Integer) See Table 2.8,
- $RemMedia[‘location’][$k][‘location_org_name’] (String) Original filename of media,
- $RemMedia[‘location’][$k][‘tableEntry’]: -1, which is an initialization value. Row position in the table is not yet known (see Fig. 5.3 and Fig. 5.4).
Remark: The length of the output array is equal to the number of removed medias. If no removed media is detected the output argument is an empty array. The datastructure of $RemMedia is different compared to the structure of $NewMedia.
6.2. check_mediacount_iminfo_files()¶
Interface definition
-
check_mediacount_iminfo_files
(&$statDB_html, $xmlDefs, $modalClassID, $media)¶ Function checks consistency of iminfo.xml files in each “location” directory, and how media should be updated: image and video count stored in iminfo.xml are compared with image and video count in public and private directories. When logged on the “Media processing status” tables are displayed: this function will generate table 1 (XML tab in Fig. 6.1). When updating is needed based on media count, the tab (1) in media status window is shown with a red border. iminfo.xml file has different media count types ():
- PublicCount: all media (images or videos) with public tag, transferred or not transferred, i.e. the tag Transferred2SiteDir can have the values: TRANSFER_NONE, TRANSFER2PUBLIC, TRANSFER2PRIVATE, TRANSFER2PUBLIC_AGAIN, TRANSFER2PRIVATE_AGAIN, or TRANSFER_FIRST_TIME_SCHEDULED (see Section 3.1.5.1 and Section 3.1.5.2). Values of these constants are given in Table 2.8.
- PrivateCount: all media with private tag, transferred or not.
- TransferCount = TransferCountPublic + TransferCountPrivate,
- TransferCountPublic: all transferred media with public tag: The tag Transferred2SiteDir = 1 ( TRANSFER2PUBLIC).
- TransferCountPrivate: all transferred media with private tag: The tag Transferred2SiteDir = 2 ( TRANSFER2PRIVATE).
Updating is needed in a location directory when count of media with tag Transferred2SiteDir = TRANSFER2PUBLIC_AGAIN, or Transferred2SiteDir = TRANSFER2PRIVATE_AGAIN is larger than 0.
Parameters: - &$statDB_html – Pointer to Object of type
htmlStatCode_Object
(see also Table 4.18) - $xmlDefs (Object) – SimpleXMLElement object of phpdefinition.xml
- $modalClassID (String) – modal dialog ID for JQUERY
- $media (Object) – Media object, is initialized in
CheckProcessStatus_X000FF()
Returns: $update_iminfo ( Object ) - See object definition
$update_iminfo
. Note: when the function is called afterIminfo_XML_Objects_UpdateAndSave()
the iminfo.xml have been updated already and this output array will only contain 0’s.$update_media_dir ( Object ) - If iminfo.xml has to be updated because of changed media count in at least one of the public or private directories, then this output variable has info about what kind of updates needs to be done in each iminfo.xml file. $update_media_dir is a matrix: #rows= #locations, #columns=2: columns are specified with associative keys:
Column 1 [‘name’]: name of location directory,
Column 2 [‘modus’]: 4 bits number (see also Table 2.5): specifies what and where new media must be updated,
- Bit 1: UPD_PUB_IMAGES (0x01000 = 4096) [●●●● 0001 ●●●● ●●●● ●●●●]
- Bit 2: UPD_PUB_VIDEOS (0x02000 = 8192) [●●●● 0010 ●●●● ●●●● ●●●●]
- Bit 3: UPD_PRV_IMAGES (0x04000 = 16384) [●●●● 0100 ●●●● ●●●● ●●●●]
- Bit 4: UPD_PRV_VIDEOS (0x08000 = 32768) [●●●● 1000 ●●●● ●●●● ●●●●]
$Iminfo_check ( 2 dimensional Array ) - See object definition
$Iminfo_check
.
The information in this output argument is used for generating the page with the overview of locations of an album (location directories, days of bicycle holiday). This information is in principle also available in iminfo.xml (<ImageInfo><PublicCount> xx </PublicCount></ImageInfo>). Opportunity for code optimization: output argument is not needed 🡺 remove code which is generating this variable.
![]() Fig. 6.1 Media Processing Status dialog window. Left: admin user or local host. Right: “normal” user. |
6.2.1. Source code¶
<?php
function check_mediacount_iminfo_files(&$statDB_html,$iminfo_objs,$modalClassID,$mediaObj){
//function check_mediacount_iminfo_files($iminfo_objs,$modalClassID,$mediaList,$stat){
// ONLY MEDIA COUNT CHECK: COMPARE #MEDIA IN IMINFO AND PUBLIC/PRIVATE DIRECTORIES
// INP1: $em:
// INP2: XML data object with definitions,
// INP3: ModalClassID,
// INP4: MediaObj from CheckProcessStatus_X000FF function (each row has 6 columns),
// OUT1: $update_iminfo array #locations with update code (type of updating)
// OUT2: $update_media_dir array: update code based on IMINFO
// OUT3: $iminfo_check matrix: #rows= #locations, #columns=8.
// Content of both types of IMINFO files (TXT and XML) must be be consistent with the content of te "Resized" directory.
// Content of "Resized" directory determines the updating of IMINFO files
// Read each IMINFO.XML and compare (IMINFO.TXT IS NOT CHECKED!!)
$dm=$statDB_html['DisplayModus'];
$statDB_html['genTable']=($dm&01000)&&((strlen($modalClassID)>1));
$statDB_html['db_active']=$dm&00001;
$statDB_html['db_buttons']=$dm&00100;
$em=($dm&00010);
$mediaList=$mediaObj['CountList'];
$dirCnt=count($iminfo_objs);
$update_iminfo=array_fill(0,$dirCnt,UPDATE_IMINFO_EXISTS_OK);
$iminfo_check=array_fill(0,$dirCnt,array('xml_pub_im'=>0,'xml_pub_vi'=>0,'xml_prv_im'=>0,'xml_prv_vi'=>0,'xml_r_pub_im'=>0,'xml_r_pub_vi'=>0,'xml_r_prv_im'=>0,'xml_r_prv_vi'=>0,'loc_pub_im'=>0,'loc_pub_vi'=>0,'loc_prv_im'=>0,'loc_prv_vi'=>0));
$update_media_dir=array_fill(0,$dirCnt,array('name'=>'','modus'=>UPD_NOTHING));
$transferCnt=array_fill(0,$dirCnt,array('xml_t_pub_im'=>0,'xml_t_pub_vi'=>0,'xml_t_prv_im'=>0,'xml_t_prv_vi'=>0));
$xml_ok=true;
$i=0;
$new_media_cnt['image']=0;
$new_media_cnt['video']=0;
foreach ($iminfo_objs as $key=>$xml_iminfo){
$iminfo_check[$i]['loc_pub_im']=$mediaList[$i]['Rsz_images'];
$iminfo_check[$i]['loc_pub_vi']=$mediaList[$i]['Rsz_videos']/2;
$iminfo_check[$i]['loc_prv_im']=$mediaList[$i]['Prv_images'];
$iminfo_check[$i]['loc_prv_vi']=$mediaList[$i]['Prv_videos']/2;
$update_media_dir[$i]['name']=$key;
if ($xml_iminfo!=NULL){
$mediaCntXML=count($xml_iminfo->media);
if (isset($xml_iminfo->ImageInfo->PublicCount)&&isset($xml_iminfo->VideoInfo->PublicCount)&&
isset($xml_iminfo->ImageInfo->PrivateCount)&&isset($xml_iminfo->VideoInfo->PrivateCount)){
$ImInfo=$xml_iminfo->ImageInfo;
$ViInfo=$xml_iminfo->VideoInfo;
$iminfo_check[$i]['xml_pub_im']=intval($ImInfo->PublicCount->__toString());
$iminfo_check[$i]['xml_pub_vi']=intval($ViInfo->PublicCount->__toString());
$iminfo_check[$i]['xml_prv_im']=intval($ImInfo->PrivateCount->__toString());
$iminfo_check[$i]['xml_prv_vi']=intval($ViInfo->PrivateCount->__toString());
$iminfo_check[$i]['xml_r_pub_im']=intval($ImInfo->Rel_PublicCount->__toString());
$iminfo_check[$i]['xml_r_pub_vi']=intval($ViInfo->Rel_PublicCount->__toString());
$iminfo_check[$i]['xml_r_prv_im']=intval($ImInfo->Rel_PrivateCount->__toString());
$iminfo_check[$i]['xml_r_prv_vi']=intval($ViInfo->Rel_PrivateCount->__toString());
$iminfo_check[$i]['xml_t_pub_im']=intval($ImInfo->Trf_PublicCount->__toString());
$iminfo_check[$i]['xml_t_pub_vi']=intval($ViInfo->Trf_PublicCount->__toString());
$iminfo_check[$i]['xml_t_prv_im']=intval($ImInfo->Trf_PrivateCount->__toString());
$iminfo_check[$i]['xml_t_prv_vi']=intval($ViInfo->Trf_PrivateCount->__toString());
if(($ImInfo->HasImage) xor ($ImInfo->ReleasedCount)){
$update_iminfo[$i]|=UPDATE_IMINFO_IMAGEINFO;
}
// if(($ViInfo->HasVideo) xor ($ViInfo->ReleasedCount)){
// $update_iminfo[$i]|=UPDATE_IMINFO_VIDEOINFO;
// }
if((intval($ViInfo->HasVideo->__toString())) xor (intval($ViInfo->ReleasedCount->__toString()))){
$update_iminfo[$i]|=UPDATE_IMINFO_VIDEOINFO;
}
}
else { // FALLBACK SCENARIO FOR BACKWARD COMPATIBILITY
if ($mediaCntXML>0){
foreach ($xml_iminfo->media as $media) {// Do media count in IMINFO file
$mtype=$media->MIMETYPE->children();
// PITFALL: $media->PublicPrivate is not of string type but is an object(SimpleXMLElement) type.
// Therefor the === operator can not be used to compare.
if (trim($media->PublicPrivate)=='R'){
if ($mtype->getName()==='IMAGE'){$iminfo_check[$i]['xml_pub_im']++;}
else if ($mtype->getName()==='VIDEO'){$iminfo_check[$i]['xml_pub_vi']++;}
} else if (trim($media->PublicPrivate)==PRIVATE_DIR){
if ($mtype->getName()==='IMAGE'){$iminfo_check[$i]['xml_prv_im']++;}
else if ($mtype->getName()==='VIDEO'){$iminfo_check[$i]['xml_prv_vi']++;}
}
}
}
}
if ((!isset($xml_iminfo->Version))||(strcmp($xml_iminfo->Version,IMINFO_VERSION))){
$update_iminfo[$i]|=UPDATE_IMINFO_VERSION;
}
if (isset($xml_iminfo->MediaCounterInfo->MaxCnt)&&($xml_iminfo->MediaCounterInfo->MaxCnt!=$mediaCntXML)){
$update_iminfo[$i]|=UPDATE_IMINFO_MAXCOUNT;
}
} else {
$mediaCntXML=0;
$iminfo_check[$i]['xml_pub_im']='No XML';
$iminfo_check[$i]['xml_pub_vi']='No XML';
$iminfo_check[$i]['xml_prv_im']='No XML';
$iminfo_check[$i]['xml_prv_vi']='No XML';
// Reset $update_iminfo[$i] and continue with next directory
$update_iminfo[$i]=UPDATE_IMINFO_NOFILE;
$xml_ok &= false;
$i++;
continue;
}
$xml_directory_ok = true;
// Check if IMINFO.XML needs to be updated.
if ($iminfo_check[$i]['xml_pub_im']<$iminfo_check[$i]['loc_pub_im']){
$update_iminfo[$i]|=UPDATE_IMINFO_MEDIACOUNT;
$xml_directory_ok = false;
}
if ($iminfo_check[$i]['xml_pub_vi']<$iminfo_check[$i]['loc_pub_vi']){
$update_iminfo[$i]|=UPDATE_IMINFO_MEDIACOUNT;
$xml_directory_ok = false;
}
if ($iminfo_check[$i]['xml_prv_im']<$iminfo_check[$i]['loc_prv_im']){
$update_iminfo[$i]|=UPDATE_IMINFO_MEDIACOUNT;
$xml_directory_ok = false;
}
if ($iminfo_check[$i]['xml_prv_vi']<$iminfo_check[$i]['loc_prv_vi']){
$update_iminfo[$i]|=UPDATE_IMINFO_MEDIACOUNT;
$xml_directory_ok = false;
}
// Check if media directory needs to be updated.
// #Transferred2SiteDir[=TRANSFER2PUBLIC or PRIVATE] + #Transferred2SiteDir[=TRANSFER2PUBLIC_AGAIN or PRIVATE] > #media in public and/or private
// Code must be modified
$val=$iminfo_check[$i]['xml_r_pub_im']+$iminfo_check[$i]['xml_t_pub_im'];
if ($val>$iminfo_check[$i]['loc_pub_im']){
$update_media_dir[$i]['modus']=UPD_PUB_IMAGES;
$xml_directory_ok = false;
}
$val=$iminfo_check[$i]['xml_r_pub_vi']+$iminfo_check[$i]['xml_t_pub_vi'];
if ($val>$iminfo_check[$i]['loc_pub_vi']){
$update_media_dir[$i]['modus']+=UPD_PUB_VIDEOS;
$xml_directory_ok = false;
}
$val=$iminfo_check[$i]['xml_r_prv_im']+$iminfo_check[$i]['xml_t_prv_im'];
if ($val>$iminfo_check[$i]['loc_prv_im']){
$update_media_dir[$i]['modus']+=UPD_PRV_IMAGES;
$xml_directory_ok = false;
}
$val=$iminfo_check[$i]['xml_r_prv_vi']+$iminfo_check[$i]['xml_t_prv_vi'];
if ($val>$iminfo_check[$i]['loc_prv_vi']){
$update_media_dir[$i]['modus']+=UPD_PRV_VIDEOS;
$xml_directory_ok = false;
}
$xml_ok &= $xml_directory_ok;
$i++;
} // Next directory
// DISPLAY INFO WHEN MODALCLASSID IS GIVEN
if ($statDB_html['genTable']){
// $resize_stat=$stat&RESIZE_STAT_MASK;
$class='.'.$modalClassID;
$str="<table id=\"iminfo-table\" class=\"modal-table\">";
$str.="<thead style=\"background-color:#cecece\"><tr>";
$toolTip="If there are 2 numbers: first number is PublicCount, second number is Rel_PublicCount";
$str.="<th title=\"".$toolTip."\">xml <br>pub (im)</th>";// Column 1 header
$str.="<th title=\"".$toolTip."\">xml <br>pub (vid)</th>";// Column 2 header
$toolTip="If there are 2 numbers: first number is PrivateCount, second number is Rel_PrivateCount";
$str.="<th title=\"".$toolTip."\">xml <br>priv (im)</th>";// Column 3 header
$str.="<th title=\"".$toolTip."\">xml <br>priv (vid)</th>";// Column 4 header
$str.="<th>Resized <br>img</th>";// Column 5 header
$str.="<th>Resized <br>video</th>";// Column 6 header
$str.="<th>Private <br>img</th>";// Column 7 header
$str.="<th>Private <br>video</th>";// Column 8 header
$str.="</tr></thead>";
$str.="<tbody>";
$i=0;
foreach ($iminfo_check as $row){
$str.="<tr>";
$bg['xml_pub_im']=BACKGROUND_COLOR_NORMAL;
$bg['xml_pub_vi']=BACKGROUND_COLOR_NORMAL;
$bg['xml_prv_im']=BACKGROUND_COLOR_NORMAL;
$bg['xml_prv_vi']=BACKGROUND_COLOR_NORMAL;
$bg['loc_pub_im']=BACKGROUND_COLOR_NORMAL;
$bg['loc_pub_vi']=BACKGROUND_COLOR_NORMAL;
$bg['loc_prv_im']=BACKGROUND_COLOR_NORMAL;
$bg['loc_prv_vi']=BACKGROUND_COLOR_NORMAL;
if (is_int($row['xml_pub_im'])){
if ($row['xml_pub_im']>$row['loc_pub_im']){
if ($row['xml_r_pub_im']>$row['loc_pub_im']) $bg['loc_pub_im']=BACKGROUND_COLOR_ALERT;
else $bg['loc_pub_im']=BACKGROUND_COLOR_NOTIFY;
}
else if ($row['xml_pub_im']<$row['loc_pub_im']){$bg['xml_pub_im']=BACKGROUND_COLOR_ALERT;}
}
if (is_int($row['xml_pub_vi'])){
if ($row['xml_pub_vi']>$row['loc_pub_vi']){
if ($row['xml_r_pub_vi']>$row['loc_pub_vi']) $bg['loc_pub_vi']=BACKGROUND_COLOR_ALERT;
else $bg['loc_pub_vi']=BACKGROUND_COLOR_NOTIFY;
}
else if ($row['xml_pub_vi']<$row['loc_pub_vi']){$bg['xml_pub_vi']=BACKGROUND_COLOR_ALERT;}
}
if (is_int($row['xml_prv_im'])){
if ($row['xml_prv_im']>$row['loc_prv_im']){
if ($row['xml_r_prv_im']>$row['loc_prv_im']) $bg['loc_prv_im']=BACKGROUND_COLOR_ALERT;
else $bg['loc_prv_im']=BACKGROUND_COLOR_NOTIFY;
}
else if ($row['xml_prv_im']<$row['loc_prv_im']){$bg['xml_prv_im']=BACKGROUND_COLOR_ALERT;}
}
if (is_int($row['xml_prv_vi'])){
if ($row['xml_prv_vi']>$row['loc_prv_vi']){
if ($row['xml_r_prv_vi']>$row['loc_prv_vi']) $bg['loc_prv_vi']=BACKGROUND_COLOR_ALERT;
else $bg['loc_prv_vi']=BACKGROUND_COLOR_NOTIFY;
}
else if ($row['xml_prv_vi']<$row['loc_prv_vi']){$bg['xml_prv_vi']=BACKGROUND_COLOR_ALERT;}
}
// Data in columns 1 --> 4
$str_mcnt=strval($row['xml_pub_im']); // Column 1
if ($row['xml_pub_im'] > $row['xml_r_pub_im']) $str_mcnt.=', '.strval($row['xml_r_pub_im']);
$toolTip=$update_media_dir[$i++]['name'];
$str.="<td title=\"".$toolTip."\" style=\"background-color:".$bg['xml_pub_im']."\">".$str_mcnt."</td>";
$str_mcnt=strval($row['xml_pub_vi']); // Column 2
if ($row['xml_pub_vi'] > $row['xml_r_pub_vi']) $str_mcnt.=', '.strval($row['xml_r_pub_vi']);
$str.="<td style=\"background-color:".$bg['xml_pub_vi']."\">".$str_mcnt."</td>";
$str_mcnt=strval($row['xml_prv_im']); // Column 3
if ($row['xml_prv_im'] > $row['xml_r_prv_im']) $str_mcnt.=', '.strval($row['xml_r_prv_im']);
$str.="<td style=\"background-color:".$bg['xml_prv_im']."\">".$str_mcnt."</td>";
$str_mcnt=strval($row['xml_prv_vi']); // Column 4
if ($row['xml_prv_vi'] > $row['xml_r_prv_vi']) $str_mcnt.=', '.strval($row['xml_r_prv_vi']);
$str.="<td style=\"background-color:".$bg['xml_prv_vi']."\">".$str_mcnt."</td>";
// Data in columns 5 --> 8
$str.="<td style=\"background-color:".$bg['loc_pub_im']."\">".strval($row['loc_pub_im'])."</td>";
$str.="<td style=\"background-color:".$bg['loc_pub_vi']."\">".strval($row['loc_pub_vi'])."</td>";
$str.="<td style=\"background-color:".$bg['loc_prv_im']."\">".strval($row['loc_prv_im'])."</td>";
$str.="<td style=\"background-color:".$bg['loc_prv_vi']."\">".strval($row['loc_prv_vi'])."</td>";
$str.="</tr>";
}
$str.="</tbody></table>";
$statDB_html['htmlStringCode']=$str;
$statDB_html['dialogStatus']=$xml_ok;
}
return array($update_iminfo,$update_media_dir,$iminfo_check);
}
6.3. DetailedStatusAnalysis(…)¶
Interface definition
-
DetailedStatusAnalysis
($iminfo_objs, $media, $scheme)¶ Executes a detailed status analysis in each location directory: all media filenames in a location directory are compared with the filenames of media in public and private directories (info is stored in iminfo.xml file in each location directory). Differences mean that either media in public and or private directories have been added and/or deleted, and are determined with the PHP function array_diff(), using the following code $df=array_diff($imlistLocation,$mListOrgFnames);
The function array_diff() returns the values in array $imlistLocation that are not present in array $mListOrgFnames. This means only media in location directories with filenames which are NOT known to iminfo.xml are considered as new media.
Function is called by
dirThumbs()
.Parameters: - $iminfo_objs (Object) – Array of SimpleXMLElement objects of Iminfo.xml files
- $media (Object) – Media object, is initialized in
CheckProcessStatus_X000FF()
- $scheme (Integer) –
Returns: - $media ( Object ) - updated Media object. Following keys are changed:
- $media[‘NewImageCnt’]
- $media[‘NewVideoCnt’]
- $media[‘NewCount’]
- $media[‘RemovedCount’]
- $media[‘ImInfoNT_ImageCnt’]
- $media[‘ImInfoNT_VideoCnt’]
- $media[‘PutBackM_ImageCnt’]
- $media[‘PutBackM_VideoCnt’]
- $media[‘PutBackM_Cnt’]
- $NewMedia (Object ) - list with new media. Object definition: see
$new_media
Object structure is (also shown in Fig. 6.2): - $RemMedia (Object ) - list (array) with removed media. Object definition: see
$rem_media
.
6.3.1. Source code¶
<?php
function DetailedStatusAnalysis($iminfo_objs,$media,$scheme){
// OUT1: $mediaDB: update media record (database)
// OUT2: $new_media: List with new media filenames in location directory (media filenames which are NOT in IMINFO.XML)
// List is never empty! #Keys is equal to #location directories.
// $new_media[$location]['image_files']: array with new image media files
// $new_media[$location]['video_files']: matrix (each web-video can have multiple video files) with new image media files
// OUT3: $rem_media: List with removed media filenames (removed in public and/or private directories)
// Fieldnames: name, public_private, TransferStatus, location_org_name
$mediaDB=$media;
$mList=$mediaDB['CountList'];
$total_newmedia_cnt=array('image'=>0,'video'=>0);
$ImInfoNT_cnt=array('image'=>0,'video'=>0); // NT = NO TRANSFER
$PutBackM_cnt=array('image'=>0,'video'=>0);
$new_media=array();
$privat_media_list=array();
$rem_media=array();
$xml_media=array();
$rem_media_cnt=0;
$xml_media_known=FALSE;
$finfo=finfo_open(FILEINFO_MIME_TYPE);
if (($scheme===PROCESSED_FILES_ORIGINALS_ADD_REM)||($scheme===PROCESSED_FILES_ORIGINALS_REMOVED)){
$key_counter=0;
foreach ($iminfo_objs as $key=>$xml_iminfo){
if (chdir($key)){
// Compare media in each location directory and media list in IMINFO objects: NEW MEDIA
$im_cnt=0;
$vi_cnt=0;
$imlistLocation=glob(MEDIA_FILES,GLOB_BRACE);
list($mListOrg,$mListSort,$mListSort_Public,$mListSort_Privat,$iminfo_mediaCount)=get_medianames_from_iminfo($xml_iminfo);
$mListOrgFnames=array_column($mListOrg,'fname');
$mListSortFnames=array_column($mListSort,'fname');
$df=array_diff($imlistLocation,$mListOrgFnames);
$image_media=array();
$video_media=array();
$first_video_name='';
$ImInfo=$xml_iminfo->ImageInfo;
$ViInfo=$xml_iminfo->VideoInfo;
$ImInfoNT_cnt['image']+=$ImInfo->PublicCount+$ImInfo->PrivateCount-$ImInfo->ReleasedCount;
$ImInfoNT_cnt['video']+=$ViInfo->PublicCount+$ViInfo->PrivateCount-$ViInfo->ReleasedCount;
if (count($df)){
foreach ($df as $new_media_fname){
$mime=finfo_file($finfo,$new_media_fname);
if (substr($mime,0,strlen('image'))==='image'){
$image_media[$im_cnt][0]['name']=$new_media_fname;
$image_media[$im_cnt][0]['pubpriv']='public';
$image_media[$im_cnt][0]['tableEntry']=-1;
$im_cnt++;
}
elseif (substr($mime,0,strlen('video'))==='video'){
$basename=pathinfo($new_media_fname,PATHINFO_FILENAME);
if ($first_video_name!=$basename){
$k=0;
$first_video_name=$basename;
$video_media[$vi_cnt][$k]['name']=$new_media_fname;
$video_media[$vi_cnt][$k]['pubpriv']='public';
$video_media[$vi_cnt][$k]['tableEntry']=-1;
$vi_cnt++;
// $k++;
}
else {// get same videofiles with different formats (fallback)
$video_media[$vi_cnt-1][$k]['name']=$new_media_fname;
$video_media[$vi_cnt-1][$k]['pubpriv']='public';
$video_media[$vi_cnt-1][$k]['tableEntry']=-1;
// $k++;
}
$k++;
}
}
$new_media[$key]['image_count']=$im_cnt;
$new_media[$key]['video_count']=$vi_cnt;
$total_newmedia_cnt['image']+=$new_media[$key]['image_count'];
$total_newmedia_cnt['video']+=$new_media[$key]['video_count'];
$new_media[$key]['image_files']=$image_media;
$new_media[$key]['video_files']=$video_media;
$xml_media[$key]=$mListOrgFnames;
}
$d=$key_counter;
$mediaFileCount=$mList[$d]['Rsz_images']+$mList[$d]['Rsz_videos']+$mList[$d]['Prv_images']+$mList[$d]['Prv_videos'];
// Compare media in public and private directories and media list in IMINFO objects: DELETED MEDIA
if (($iminfo_mediaCount['publicFiles']+$iminfo_mediaCount['privateFiles'])>$mediaFileCount){
// Media in public and or private directories has (have) been deleted: identify which mediafiles has (have) been deleted.
chdir(PUBLIC_DIR);
$pub_im_list=glob(GALLERY_IMAGE_FILES,GLOB_BRACE);
$pub_vi_list=glob(VIDEO_FILES,GLOB_BRACE);
$public_media_list=array_merge($pub_im_list,$pub_vi_list);
if (is_dir(PRIVATE_DIR)) {
chdir(PRIVATE_DIR);
$pri_im_list=glob(GALLERY_IMAGE_FILES,GLOB_BRACE);
$pri_vi_list=glob(VIDEO_FILES,GLOB_BRACE);
$privat_media_list=array_merge($pri_im_list,$pri_vi_list);
$media_list_dir=array_merge($public_media_list,$privat_media_list);
chdir("..");
} else $media_list_dir=$public_media_list;
chdir("..");
$df_public=array_diff($mListSort_Public,$public_media_list);
$df_privat=array_diff($mListSort_Privat,$privat_media_list);
$k=0;
$rem_media_cnt+=count($df_public)+count($df_privat);
foreach ($df_public as $rem_media_fname){
$rem_media[$key][$k]['name']=$rem_media_fname;
$rem_media[$key][$k]['public_private']='public';
$m=array_search($rem_media_fname,$mListSortFnames);
$rem_media[$key][$k]['TransferStatus']=$mListSort[$m]['TrStat'];
$rem_media[$key][$k]['location_org_name']=$mListOrgFnames[$m];
if ($mListSort[$m]['TrStat']<TRANSFER_NONE){
if ($mListSort[$m]['mtype']=='IMAGE'){
$PutBackM_cnt['image']++;
}
else if ($mListSort[$m]['mtype']=='VIDEO'){
$PutBackM_cnt['video']++;
}
}
$k++;
}
foreach ($df_privat as $rem_media_fname){
$rem_media[$key][$k]['name']=$rem_media_fname;
$rem_media[$key][$k]['public_private']='private';
$m=array_search($rem_media_fname,$mListSortFnames);
$rem_media[$key][$k]['TransferStatus']=$mListSort[$m]['TrStat'];
$rem_media[$key][$k]['location_org_name']=$mListOrgFnames[$m];
if ($mListSort[$m]['TrStat']<TRANSFER_NONE){
if ($mListSort[$m]['mtype']==='IMAGE') $PutBackM_cnt['image']++;
else if ($mListSort[$m]['mtype']==='VIDEO') $PutBackM_cnt['video']++;
}
$k++;
}
}
if (($iminfo_mediaCount['publicFiles']+$iminfo_mediaCount['privateFiles'])<$mediaFileCount){
// Media has been added in public and or private directories
// This should not occur
}
chdir("..");
}
else{ // Key as directory not known
$new_media[$key]['image_count']=-1;
$new_media[$key]['video_count']=-1;
$new_media[$key]['image_files']=NULL;
$new_media[$key]['video_files']=NULL;
$xml_media[$key]=NULL;
}
$key_counter++;
}
$xml_media_known=TRUE;
}
// CHECK B
/*
if ($xml_media_known){
foreach ($xmlDefs->directory as $loc){
}
}
else {
foreach ($xmlDefs->directory as $loc){
if (chdir($loc->name->__toString())){
$imlistLocation=glob(MEDIA_FILES,GLOB_BRACE);
$xml_iminfo=simplexml_load_file('iminfo.xml');
chdir("..");
list($mListOrg,$mListSort,$mListOrg_Public,$mListOrg_Private,$mediaCount)=get_medianames_from_iminfo($xml_iminfo);
}
else{
}
}
}
*/
$mediaDB['NewImageCnt']=$total_newmedia_cnt['image'];
$mediaDB['NewVideoCnt']=$total_newmedia_cnt['video'];
$mediaDB['NewCount']=$total_newmedia_cnt['image']+$total_newmedia_cnt['video'];
$mediaDB['RemovedCount']=$rem_media_cnt;
// Not Transferred
$mediaDB['ImInfoNT_ImageCnt']=$ImInfoNT_cnt['image'];
$mediaDB['ImInfoNT_VideoCnt']=$ImInfoNT_cnt['video'];
// Put Back Removed Media: media has been removed but is still registered in IMINFO.XML
$mediaDB['PutBackM_ImageCnt']=$PutBackM_cnt['image'];
$mediaDB['PutBackM_VideoCnt']=$PutBackM_cnt['video'];
$mediaDB['PutBackM_Cnt']=$PutBackM_cnt['image']+$PutBackM_cnt['video'];
return array($mediaDB,$mListSort,$new_media,$rem_media);
}
6.4. GetIminfoObjects()¶
Interface definition
-
GetIminfoObjects
($xmlDefs)¶ Parameters: - $xmlDefs (Object) –
Returns: $iminfo_objs: Array of SimpleXMLElement objects of Iminfo.xml files.
6.5. get_medianames_from_iminfo(…)¶
Interface definition
-
get_medianames_from_iminfo
($xml_iminfo)¶ Get media filenames from iminfo objects. The filenames are retrieved from the <media> elements in the iminfo objects (see Listing 3.5 and Listing 3.6). A video <media> element may refer to multiple videofiles (same video content but with different video codecs/format, i.e. different file extensions). Videofiles with the same basename but with n different file extensions are considered as n different media files.
Parameters: - $iminfo_objs (Object) –
Array of SimpleXMLElement objects of Iminfo.xml files.
Returns: - $mListOrg ( List object ) - media list array with numerical keys. Each array element has the following keys:
- [‘fname’]: original filename ( $media->OriginalFile->__toString()),
- [‘TrStat’]: transfer status (see Table 2.8, $media->Transferred2SiteDir),
- [‘mtype’]: media type ( media->MIMETYPE->children()->getName()).
- $mListSorted ( List object ) - time sorted media list array with numerical keys. Each array element has the following keys:
- [‘fname’]: time sorted filename ( $media->TimeSortedFile->__toString()),
- [‘TrStat’]: transfer status (see Table 2.8),
- [‘mtype’]: media type ( media->MIMETYPE->children()->getName()),
- [‘TimeStamp’]: timestamp ( $media->TimeStamp).
- $mListSorted_Public ( List object ) - time sorted public media list array with numerical keys.
- $mListSorted_Private ( List object ) - time sorted private media list array with numerical keys.
- $count ( Array ) - Array with 2 associative keys:
- [‘publicFiles’]: $xml_iminfo->ImageInfo->PublicCount+$xml_iminfo->VideoInfo->PublicFilesCount
- [‘privateFiles’]: $xml_iminfo->ImageInfo->PrivateCount+$xml_iminfo->VideoInfo->PrivateFilesCount
- $iminfo_objs (Object) –
6.6. ImArray2IminfoXML(…)¶
Interface definition
-
ImArray2IminfoXML
($imArray, $ldir, $xml_name)¶ Converts $imArray matrix data structure (derived from
iminfo.txt
) to iminfo.xml file with a given name $xml_name in location directory $ldir. The format ofiminfo.txt
is given in Listing 3.3. Function is called in functionIminfoTXT2IminfoXML()
Parameters: - $imArray (Matrix) – Matrix data content of
iminfo.txt
, and is assigned in functionIminfoTXT2IminfoXML()
. - $ldir (String) – location / date directory name.
- $xml_name (String) – filename of iminfo file (standard iminfo filename is iminfo.xml).
Returns: - SaveStatus ( Integer ) -
- 0: Failed to save $imArray to iminfo file with name $xml_name.
- 1: $xml_name is successfully saved.
- $imArray (Matrix) – Matrix data content of
6.6.1. Source code¶
<?php
function ImArray2IminfoXML($imArray,$ldir,$xml_name){
// INP1: imArray matrix
// INP2: location directory
// RESULT: IMINFO.XML FILE IS GENERATED. IF IT EXISTS IT IS OVERWRITTEN!
$fp=fopen($ldir.DS.$xml_name,'w');
$hasVideo=false;
$videoWidth=0;
$videoHeight=0;
$hasImage=false;
$public_image_count=0;
$private_image_count=0;
$public_image_transfer_count=0;
$private_image_transfer_count=0;
$public_video_count=0;
$public_videofiles_count=0;
$private_video_count=0;
$private_videofiles_count=0;
$public_video_transfer_count=0;
$public_videofiles_transfer_count=0;
$private_video_transfer_count=0;
$private_videofiles_transfer_count=0;
$maxCnt=0;
if ($fp==FALSE) return 0;
fwrite($fp,'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL);
fwrite($fp,'<directory>'.PHP_EOL);
$imCnt=count($imArray);
for ($i=0;$i<$imCnt;$i++){
$mimeWritten=0;
$count=0;
$transferred=FALSE;
$basename=pathinfo(trim($imArray[$i][1]),PATHINFO_FILENAME);
$sortFilename=trim($imArray[$i][0]);
$pos=strpos($sortFilename,$basename);
if ($pos>0){
$TimeSortNr=substr($sortFilename,0,$pos-1);
if (is_numeric($TimeSortNr)) $TimeSortNr=intval($TimeSortNr);
else $TimeSortNr=-1;
}
else $TimeSortNr=-1;
$maxCnt=$TimeSortNr>$maxCnt?$TimeSortNr:$maxCnt;
fwrite($fp,'<media>'.PHP_EOL);
fwrite($fp,'<Selected>');fwrite($fp,1);fwrite($fp,'</Selected>'.PHP_EOL);
fwrite($fp,'<TimeSortedFile>');fwrite($fp,' '.$imArray[$i][0]);fwrite($fp,'</TimeSortedFile>'.PHP_EOL);
fwrite($fp,'<OriginalFile>');fwrite($fp,' '.$imArray[$i][1]);fwrite($fp,'</OriginalFile>'.PHP_EOL);
fwrite($fp,'<TimeString>');fwrite($fp,' '.$imArray[$i][2]);fwrite($fp,'</TimeString>'.PHP_EOL);
fwrite($fp,'<TimeStamp>');fwrite($fp,' '.$imArray[$i][3]);fwrite($fp,'</TimeStamp>'.PHP_EOL);
fwrite($fp,'<PublicPrivate>');fwrite($fp,' '.$imArray[$i][4]);fwrite($fp,'</PublicPrivate>'.PHP_EOL);
fwrite($fp,'<Transferred2SiteDir>');
$a=$imArray[$i][4];
if (($imArray[$i][4]=='R')&&file_exists($ldir.DS.PUBLIC_DIR.DS.$imArray[$i][0])){
fwrite($fp,' '.TRANSFER2PUBLIC);
$transferred=TRUE;
}
else if (($imArray[$i][4]==PRIVATE_DIR)&&file_exists($ldir.DS.PUBLIC_DIR.DS.PRIVATE_DIR.DS.$imArray[$i][0])){
fwrite($fp,' '.TRANSFER2PRIVATE);
$transferred=TRUE;
}
else fwrite($fp,' '.TRANSFER_NONE);
fwrite($fp,'</Transferred2SiteDir>'.PHP_EOL);
if (array_key_exist_and_not_empty(5,$imArray[$i])){
fwrite($fp,'<Width>');
fwrite($fp,$imArray[$i][5]);
fwrite($fp,'</Width>'.PHP_EOL);
}
if (array_key_exist_and_not_empty(6,$imArray[$i])){
fwrite($fp,'<Height>');
fwrite($fp,$imArray[$i][6]);
fwrite($fp,'</Height>'.PHP_EOL);
}
if (array_key_exist_and_not_empty(7,$imArray[$i])){
fwrite($fp,'<XResolution>');
fwrite($fp,$imArray[$i][7]);
fwrite($fp,'</XResolution>'.PHP_EOL);
}
if (array_key_exist_and_not_empty(8,$imArray[$i])){
fwrite($fp,'<YResolution>');
fwrite($fp,$imArray[$i][8]);
fwrite($fp,'</YResolution>'.PHP_EOL);
}
if (array_key_exist_and_not_empty(9,$imArray[$i])){
fwrite($fp,'<GPSLongitude>');
fwrite($fp,$imArray[$i][9]);
fwrite($fp,'</GPSLongitude>'.PHP_EOL);
}
if (array_key_exist_and_not_empty(10,$imArray[$i])){
fwrite($fp,'<GPSLatitude>');
fwrite($fp,$imArray[$i][10]);
fwrite($fp,'</GPSLatitude>'.PHP_EOL);
}
if (array_key_exist_and_not_empty(11,$imArray[$i])){
fwrite($fp,'<MIMETYPE>'.PHP_EOL);
if (substr($imArray[$i][11],0,strlen('image'))==='image'){
$hasImage=true;
$count++;
if (trim($imArray[$i][4])=='R'){
$public_image_count++;
if ($transferred) $public_image_transfer_count++;
}
else if (trim($imArray[$i][4])==PRIVATE_DIR){
$private_image_count++;
if ($transferred) $private_image_transfer_count++;
}
fwrite($fp,'<IMAGE>'.PHP_EOL);
fwrite($fp,'<BASENAME>');
fwrite($fp,pathinfo($imArray[$i][1],PATHINFO_FILENAME));
fwrite($fp,'</BASENAME>'.PHP_EOL);
fwrite($fp,'<TYPE ext="JPEG">1</TYPE>'.PHP_EOL);
fwrite($fp,'</IMAGE>'.PHP_EOL);
}
else if (substr($imArray[$i][11],0,strlen('video'))==='video'){
$hasVideo=true;
$videoWidth=max($videoWidth,$imArray[$i][5]);
$videoHeight=max($videoHeight,$imArray[$i][6]);
fwrite($fp,'<VIDEO>'.PHP_EOL);
fwrite($fp,'<BASENAME>');
fwrite($fp,pathinfo($imArray[$i][1],PATHINFO_FILENAME));
fwrite($fp,'</BASENAME>'.PHP_EOL);
if (array_key_exist_and_not_empty(12,$imArray[$i])){
if ($imArray[$i][12]==='webm'){
fwrite($fp,'<TYPE ext="WEBM">1</TYPE>'.PHP_EOL);
$count++;
}
// else if ($imArray[$i][12]==='no-webm') fwrite($fp,0);
// else fwrite($fp,'Undefined status of WEBM');
}
if (array_key_exist_and_not_empty(13,$imArray[$i])){
if ($imArray[$i][13]==='mp4'){
fwrite($fp,'<TYPE ext="MP4">1</TYPE>'.PHP_EOL);
$count++;
}
// else if ($imArray[$i][13]==='no-mp4') fwrite($fp,0);
// else fwrite($fp,'Undefined status of MP4');
}
if (trim($imArray[$i][4])=='R'){
$public_video_count++;
$public_videofiles_count+=$count;
if ($transferred){
$public_video_transfer_count++;
$public_videofiles_transfer_count+=$count;
}
}
else if (trim($imArray[$i][4])==PRIVATE_DIR){
$private_video_count++;
$private_videofiles_count+=$count;
if ($transferred){
$private_video_transfer_count++;
$private_videofiles_transfer_count+=$count;
}
}
fwrite($fp,'</VIDEO>'.PHP_EOL);
}
fwrite($fp,'</MIMETYPE>'.PHP_EOL);
$mimeWritten=1;
}
if (!$mimeWritten){
fwrite($fp,'<MIMETYPE>'.PHP_EOL);
fwrite($fp,'<IMAGE>'.PHP_EOL);
fwrite($fp,'<BASENAME>');
fwrite($fp,pathinfo($imArray[$i][1],PATHINFO_FILENAME));
fwrite($fp,'</BASENAME>'.PHP_EOL);
fwrite($fp,"<TYPE ext=\"JPEG\">1</TYPE>".PHP_EOL);
fwrite($fp,'</IMAGE>'.PHP_EOL);
fwrite($fp,'</MIMETYPE>'.PHP_EOL);
}
fwrite($fp,'<Count>');fwrite($fp,$count);fwrite($fp,'</Count>'.PHP_EOL);
fwrite($fp,'</media>'.PHP_EOL);
}
// GENERIC IMAGE INFO
fwrite($fp,'<ImageInfo>'.PHP_EOL);
fwrite($fp,'<HasImage>');
if ($hasImage)fwrite($fp,1);
else fwrite($fp,0);
fwrite($fp,'</HasImage>'.PHP_EOL);
fwrite($fp,'<ReleasedCount>');
fwrite($fp,$public_image_transfer_count+$private_image_transfer_count);
fwrite($fp,'</ReleasedCount>'.PHP_EOL);
fwrite($fp,'<Rel_PublicCount>');
fwrite($fp,$public_image_transfer_count);
fwrite($fp,'</Rel_PublicCount>'.PHP_EOL);
fwrite($fp,'<Rel_PrivateCount>');
fwrite($fp,$private_image_transfer_count);
fwrite($fp,'</Rel_PrivateCount>'.PHP_EOL);
fwrite($fp,'<Trf_PublicCount>'.PHP_EOL);
fwrite($fp,0);
fwrite($fp,'</Trf_PublicCount>'.PHP_EOL);
fwrite($fp,'<Trf_PrivateCount>'.PHP_EOL);
fwrite($fp,0);
fwrite($fp,'</Trf_PrivateCount>'.PHP_EOL);
fwrite($fp,'<PublicCount>');
fwrite($fp,$public_image_count);
fwrite($fp,'</PublicCount>'.PHP_EOL);
fwrite($fp,'<PrivateCount>');
fwrite($fp,$private_image_count);
fwrite($fp,'</PrivateCount>'.PHP_EOL);
fwrite($fp,'</ImageInfo>'.PHP_EOL);
// GENERIC VIDEO INFO
fwrite($fp,'<VideoInfo>'.PHP_EOL);
fwrite($fp,'<HasVideo>');
if ($hasVideo)fwrite($fp,1);
else fwrite($fp,0);
fwrite($fp,'</HasVideo>'.PHP_EOL);
fwrite($fp,'<ReleasedCount>');
fwrite($fp,$public_video_transfer_count+$private_video_transfer_count);
fwrite($fp,'</ReleasedCount>'.PHP_EOL);
fwrite($fp,'<Rel_PublicCount>');
fwrite($fp,$public_video_transfer_count);
fwrite($fp,'</Rel_PublicCount>'.PHP_EOL);
fwrite($fp,'<Rel_PrivateCount>');
fwrite($fp,$private_video_transfer_count);
fwrite($fp,'</Rel_PrivateCount>'.PHP_EOL);
fwrite($fp,'<Rel_PublicFilesCount>');
fwrite($fp,$public_videofiles_transfer_count);
fwrite($fp,'</Rel_PublicFilesCount>'.PHP_EOL);
fwrite($fp,'<Rel_PrivateFilesCount>');
fwrite($fp,$private_videofiles_transfer_count);
fwrite($fp,'</Rel_PrivateFilesCount>'.PHP_EOL);
fwrite($fp,'<Trf_PublicCount>'.PHP_EOL);
fwrite($fp,0);
fwrite($fp,'</Trf_PublicCount>'.PHP_EOL);
fwrite($fp,'<Trf_PrivateCount>'.PHP_EOL);
fwrite($fp,0);
fwrite($fp,'</Trf_PrivateCount>'.PHP_EOL);
fwrite($fp,'<PublicCount>');
fwrite($fp,$public_video_count);
fwrite($fp,'</PublicCount>'.PHP_EOL);
fwrite($fp,'<PublicFilesCount>');
fwrite($fp,$public_videofiles_count);
fwrite($fp,'</PublicFilesCount>'.PHP_EOL);
fwrite($fp,'<PrivateCount>');
fwrite($fp,$private_video_count);
fwrite($fp,'</PrivateCount>'.PHP_EOL);
fwrite($fp,'<PrivateFilesCount>');
fwrite($fp,$private_videofiles_count);
fwrite($fp,'</PrivateFilesCount>'.PHP_EOL);
fwrite($fp,'<VideoWidth>');fwrite($fp,$videoWidth);fwrite($fp,'</VideoWidth>'.PHP_EOL);
fwrite($fp,'<VideoHeight>');fwrite($fp,$videoHeight);fwrite($fp,'</VideoHeight>'.PHP_EOL);
fwrite($fp,'</VideoInfo>'.PHP_EOL);
fwrite($fp,'<MediaCounterInfo>'.PHP_EOL);
fwrite($fp,'<MaxCnt>');fwrite($fp,$maxCnt);fwrite($fp,'</MaxCnt>'.PHP_EOL);
fwrite($fp,'</MediaCounterInfo>'.PHP_EOL);
fwrite($fp,'<Version>');
fwrite($fp,IMINFO_VERSION);
fwrite($fp,'</Version>'.PHP_EOL);
fwrite($fp,'</directory>'.PHP_EOL);
fclose($fp);
return 1;
}
6.7. IminfoNewImageObject(…)¶
Interface definition
-
IminfoNewImageObject
($exif)¶ Create new image media SimpleXMLElement object . (See Section 3.1.5.1). Function is called by
Iminfo_XML_Objects_UpdateAndSave()
, andphp\analyse_status_table.php
.Parameters: - $exif (Array) – Return value of exif_read_data() . $exif is metadata of the new image.
Returns: Image media object (SimpleXMLElement object)
6.7.1. Source code¶
<?php
function IminfoNewImageObject($exif){
if (isset($exif['DateTimeOriginal'])){
$timeStr=$exif['DateTimeOriginal'];
$timeStamp=strtotime($timeStr);
}
else {
$timeStamp=$exif['FileDateTime'];
$timeStr=date("Y-m-d H:i:s",$timeStamp);
}
$media_xml=new SimpleXMLElement('<media></media>');
$media_xml->addChild('Selected','1');
// GENERIC EXIF HEADERS
$media_xml->addChild('TimeSortedFile',$exif['FileName']);
$media_xml->addChild('OriginalFile',$exif['FileName']);
$media_xml->addChild('TimeString',$timeStr);
$media_xml->addChild('TimeStamp',$timeStamp);
$media_xml->addChild('PublicPrivate',' R');
$media_xml->addChild('Transferred2SiteDir',strval(TRANSFER_FIRST_TIME_SCHEDULED));
$media_xml->addChild('Width',$exif['COMPUTED']['Width']);
$media_xml->addChild('Height',$exif['COMPUTED']['Height']);
// SPECIFIC EXIF HEADERS
if (isset($exif['XResolution'])) $xres=$exif['XResolution']; else $xres='';
if (isset($exif['XResolution'])) $yres=$exif['YResolution']; else $yres='';
$media_xml->addChild('XResolution',$xres);
$media_xml->addChild('YResolution',$yres);
if(array_key_exists('GPSLongitude',$exif)&& array_key_exists('GPSLatitude',$exif)){
$lng=getGps($exif["GPSLongitude"],$exif['GPSLongitudeRef']);
$lat=getGps($exif["GPSLatitude"],$exif['GPSLatitudeRef']);
} else{$lng='NO-LNG';$lat='NO-LAT';}
$media_xml->addChild('GPSLongitude',$lng);
$media_xml->addChild('GPSLatitude',$lat);
// MIMETYPE INFO
$mime=$media_xml->addChild('MIMETYPE');
$image=$mime->addChild('IMAGE');
$image->addChild('BASENAME',pathinfo($exif['FileName'],PATHINFO_FILENAME));
$type=$image->addChild('TYPE','1');
$type->addAttribute('ext',strtoupper(substr($exif['MimeType'],6)));
$media_xml->addChild('Count','1');
return $media_xml;
}
6.8. IminfoNewVideoObject(…)¶
Interface definition
-
IminfoNewVideoObject
($exif)¶ Create new video media SimpleXMLElement object .(See Section 3.1.5.2). Function is called by
Iminfo_XML_Objects_UpdateAndSave()
, andphp\analyse_status_table.php
.Parameters: - $exif (Array) –
Return value of exif_read_data() . $exif is metadata of the new video. Video metadata is retrieved with PHP package getID3.
Returns: Video media object (SimpleXMLElement object)
- $exif (Array) –
6.8.1. Source code¶
<?php
function IminfoNewVideoObject($video_info,$unixTime,$mimes){
$media_xml=new SimpleXMLElement('<media></media>');
$media_xml->addChild('Selected','1');
$media_xml->addChild('TimeSortedFile',$video_info['filename']);
$media_xml->addChild('OriginalFile',$video_info['filename']);
$media_xml->addChild('TimeString',date("Y-m-d H:i:s",$unixTime));
$media_xml->addChild('TimeStamp',$unixTime);
$media_xml->addChild('PublicPrivate',' R');
$media_xml->addChild('Transferred2SiteDir',strval(TRANSFER_FIRST_TIME_SCHEDULED));
if (array_key_exists('resolution_x',$video_info['video'])){
$media_xml->addChild('Width',$video_info['video']['resolution_x']);
$media_xml->addChild('Height',$video_info['video']['resolution_y']);
}
else if (array_key_exists('resolution_x',$video_info['video']['streams'][0])){
$media_xml->addChild('Width',$video_info['video']['streams'][0]['resolution_x']);
$media_xml->addChild('Height',$video_info['video']['streams'][0]['resolution_y']);
}
$media_xml->addChild('XResolution','0');
$media_xml->addChild('YResolution','0');
$media_xml->addChild('GPSLongitude','NO-LNG');
$media_xml->addChild('GPSLatitude','NO-LAT');
$mime_elm=$media_xml->addChild('MIMETYPE');
$video=$mime_elm->addChild('VIDEO');
$video->addChild('BASENAME',pathinfo($video_info['filename'],PATHINFO_FILENAME));
foreach ($mimes as $mime){
$type=$video->addChild('TYPE','1');
$type->addAttribute('ext',strtoupper($mime));
}
$media_xml->addChild('Count',strval(count($mimes)));
return $media_xml;
}
6.9. IminfoTXT2IminfoXML(…)¶
Interface definition
-
IminfoTXT2IminfoXML
($deb_test, $ldir, $timeStr)¶ iminfo.txt
files were the first format to store media information in a description file (see also Section 3.1.4). Converts aiminfo.txt
file to an iminfo.xml file in location directory $ldir. Th actual conversion is done by calling functionImArray2IminfoXML()
. In DEBUG mode the convertediminfo.txt
to iminfo_updateIminfoXMLFile.xml if there is already an iminfo.xml file. In non DEBUG mode and if there is already an iminfo.xml file it will be renamed by appending timeStr to the filename. Function will become obsolete.param Boolean $deb_test: Debug test purpose.
param String $ldir: location / date directory name
param String $timeStr: return: - Status ( Integer ) - E_IMINFO_FS_W, E_IMINFO_TXT_1, E_IMINFO_TXT_2, E_IMINFO_UPD_OK, E_IMINFO_UPD_OK_B, E_IMINFO_CRE_OK
- Name of IMINFO XML file or NULL if no XML file is generated.
6.9.1. Source code¶
<?php
function IminfoTXT2IminfoXML($deb_test,$ldir,$timeStr){
// Create IMINFO.XML file from IMINFO.TXT file
// INP1: Boolean debugstatus: use true for debug purpose
// INP2: location directory
// INP3: timestring
// OUT1: status: E_IMINFO_FS_W, E_IMINFO_TXT_1, E_IMINFO_TXT_2, E_IMINFO_UPD_OK, E_IMINFO_UPD_OK_B, E_IMINFO_CRE_OK
// OUT2: Name of IMINFO XML file or NULL if no XML file generated.
$fname=$ldir.DS.'iminfo.txt';
$public_dir=$ldir.DS.PUBLIC_DIR.DS;
if (!file_exists($fname)) return array(E_IMINFO_TXT_1,NULL);
if (filesize($fname)==0) return array(E_IMINFO_TXT_2,NULL);
$imArray=f_parse_csv($fname,1000,',');
$nrCols=count($imArray[0]);
$xml_name='iminfo.xml';
if (file_exists($ldir.DS.$xml_name)){
if ($deb_test){
$xml_name='iminfo_updateIminfoXMLFile.xml';
$outVal=E_IMINFO_UPD_OK_B;
}
else {
rename_with_timestamp($ldir.DS.$xml_name,$timeStr);
$outVal=E_IMINFO_UPD_OK;
}
}
else $outVal=E_IMINFO_CRE_OK;
$imCnt=count($imArray);
for ($i=0;$i<$imCnt;$i++){
$ext=pathinfo($imArray[$i][1],PATHINFO_EXTENSION);
// $keywords=preg_split("/[\s,]+/",IMAGE_FILES);
$imArray[$i][11]='';
$imArray[$i][12]='';
$imArray[$i][13]='';
if ((strtoupper($ext)=='JPG')){
// JPEG IMAGE
$imArray[$i][11]='image/jpeg';
} else if (strtoupper($ext)=='PNG'){
// PNG IMAGE
$imArray[$i][11]='image/'.strtolower($ext);
} else if ((strtoupper($ext)=='MP4')||(strtoupper($ext)=='WEBM')){
// HTML5 VIDEO
$basefilename=pathinfo($imArray[$i][0],PATHINFO_FILENAME);
$fname_mp4=$basefilename.'.mp4';
$fname_wbm=$basefilename.'.webm';
$mp4=false;
$webm=false;
$imArray[$i][12]='no-webm';
$imArray[$i][13]='no-mp4';
if ($imArray[$i][4]=='R'){
if (file_exists($public_dir.$fname_mp4)){
$imArray[$i][13]='mp4';
$mp4=true;
}
if (file_exists($public_dir.$fname_wbm)){
$imArray[$i][12]='webm';
$webm=true;
}
} else if ($imArray[$i][4]==PRIVATE_DIR){
if (file_exists($public_dir.PRIVATE_DIR.DS.$fname_mp4)){
$imArray[$i][13]='mp4';
$mp4=true;
}
if (file_exists($public_dir.PRIVATE_DIR.$fname_wbm)){
$imArray[$i][12]='webm';
$webm=true;
}
}
if ($mp4&&$webm) $imArray[$i][11]='video/mp4-webm'; // NORMAL SITUATION
else if ($mp4&& !$webm) $imArray[$i][11]='video/mp4';
else if (!$mp4&& $webm) $imArray[$i][11]='video/webm';
else { // VIDEO NOT IN PUBLIC OR PRIVATE DIRECTORIES
$imArray[$i][11]='video/not-processed';
}
}
}
if (ImArray2IminfoXML($imArray,$ldir,$xml_name)==0){
return array(E_IMINFO_FS_W,NULL);
}
return array($outVal,$xml_name);
}
6.10. Iminfo_XML_Objects_UpdateAndSave(…)¶
Interface definition
-
Iminfo_XML_Objects_UpdateAndSave
($doZIP, &$iminfo_objs, $new_media_list, $XFFFFF, $server_info, $send_email=FALSE)¶ Function updates IMINFO object with new media entries, and is called in
dirThumbs()
.Parameters: - $doZIP (Boolean) – If TRUE iminfo.xml files, which will be updated (overwritten) will be zipped first.
- $iminfo_objs (Object) –
Array of SimpleXMLElement objects of Iminfo.xml files
- $new_media_list (Array) – Array of
$new_media
objects - $XFFFFF (Array) – Data $XFFFFF is not used for updating IMINFO objects, but as additional information in notifying e-mail.
- $server_info (Object) – Data $server_info (
server_info_Object
object) is not used for updating IMINFO objects, but as additional information in notifying e-mail. - $send_email (Boolean) – Optional argument (default FALSE). If TRUE, email will be sent by calling
send_email_update_iminfo()
.
Returns: Void
Internal data object
$upd_succ
6.10.1. Source code¶
<?php
function Iminfo_XML_Objects_UpdateAndSave($doZIP,&$iminfo_objs,$new_media_list,$XFFFFF,$server_info,$send_email=FALSE){
// INP1: doZIP,
// INP2: pointer to array with IMINFO objects,
// INP3: array with filenames of new media,
// INP4: $XFFFFF
// INP5: send_email Boolean
$iminfo_version=array('old'=>0,'new'=>0);
$upd_succ=array_fill(0,count($new_media_list),array('status'=>UPDATE_IMINFO_EXISTS_OK,'directory'=>'','fname'=>'iminfo.xml','reason'=>'','code'=>0,'iminfo_version'=>$iminfo_version));
$unixTime=time();
$timeStr=date("Ymd-Hi",$unixTime);
$wdir=str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace ("\\","/",getcwd()));
$zip=0;
$zipname='';
$nIminfoInZIP=0;
$getID3=new getID3;
$finfo=finfo_open(FILEINFO_MIME_TYPE);
$i=0;
foreach ($new_media_list as $key=>$loc_obj){
if (($loc_obj[' ']==0)&&($loc_obj['video_count']==0)) continue; // Next location
$new_image_loc=$loc_obj['image_files'];
$new_video_loc=$loc_obj['video_files'];
chdir($key);
$new_im_media_cnt=0;
$new_vi_media_cnt=0;
$new_vi_files_cnt=0;
$mediaCnt=count($iminfo_objs[$key]->media);
foreach ($new_image_loc as $new_image){
$insert_last_pos=FALSE;
$exif=exif_read_data($new_image[0]['name'],'IFD0');
if (!$exif) $exif=exif_read_data($new_image[0]['name'],'FILE');
$new_image_object=IminfoNewImageObject($exif);
$new_im_media_cnt++;
if (isset($exif['DateTimeOriginal'])){
$stamp=strtotime($exif['DateTimeOriginal']);// What if not set?
$target=$iminfo_objs[$key]->xpath("//media[TimeStamp > $stamp][1]"); // SINGLE ELEMENT
if (!empty($target)) // OLDER IMAGES ARE FOUND
if (iminfo_insert($new_image_object,current($target),$tPos,'BEFORE_TARGET')){
$mediaCnt++;
}
else // NO OLDER IMAGES FOUND --> INSERT AT LAST POSITION
$insert_last_pos=TRUE;
}
else $insert_last_pos=TRUE;
if ($insert_last_pos){
$target=current($iminfo_objs[$key]->xpath('//media[last()]'));
if (iminfo_insert($new_image_object,$target,$tPos,'AFTER_TARGET'))
$mediaCnt++;
}
}
foreach ($new_video_loc as $new_video){// Each new video media can have multiple files, i.e. different formats
$insert_last_pos=TRUE;
$video_cnt=count($new_video);
$mimes=array_fill(0,$video_cnt,'');
foreach ($new_video as $key2=>$video) $mimes[$key2]=substr(finfo_file($finfo,$video['name']),6);
$mimes_keys=array_flip($mimes);
if (isset($mimes_keys['mp4'])){
$video_info=$getID3->analyze($new_video[$mimes_keys['mp4']]['name']);
if (isset($video_info['quicktime'])){// Overwrite $unixTime
$unixTime=intval($video_info['quicktime']['moov']['subatoms'][0]['creation_time_unix']);
if ($unixTime<0){// creation_time_unix is not specified in header
// Fallback scenario
$unixTime=filemtime($new_video[$mimes_keys['mp4']]['name']);// TIMEZONE + 00:00
}
$target=$iminfo_objs[$key]->xpath("//media[TimeStamp > $unixTime][1]");
if (!empty($target)) $insert_last_pos=FALSE;
}
}
else {
if (isset($mimes_keys['webm'])){
$video_info=$getID3->analyze($new_video[$mimes_keys['webm']]['name']);
$unixTime=filemtime($new_video[$mimes_keys['webm']]['name']);
}
else{
$video_info=$getID3->analyze($new_video[0]['name']);
$unixTime=filemtime($new_video[0]['name']);
}
$insert_last_pos=TRUE;
}
$new_video_object=IminfoNewVideoObject($video_info,$unixTime,$mimes);
$new_vi_media_cnt++;
$new_vi_files_cnt+=$video_cnt;
if (!$insert_last_pos) {
if (iminfo_insert($new_video_object,current($target),$tPos,'BEFORE_TARGET')){
$mediaCnt++;
}
}
else {
$target=current($iminfo_objs[$key]->xpath('//media[last()]'));
if (iminfo_insert($new_video_object,$target,$tPos,'AFTER_TARGET')){
$mediaCnt++;
}
}
}
$iminfo_objs[$key]->ImageInfo->PublicCount+=$new_im_media_cnt;
$iminfo_objs[$key]->ImageInfo->Trf_PublicCount=$new_im_media_cnt;
$iminfo_objs[$key]->VideoInfo->PublicCount+=$new_vi_media_cnt;
$iminfo_objs[$key]->VideoInfo->Trf_PublicCount=$new_vi_media_cnt;
$iminfo_objs[$key]->VideoInfo->PublicFilesCount+=$new_vi_files_cnt;
// Tag Transferred2SiteDir is not yet updated here because the media are not processed in this procedure.
// This is done in "media-update-progress.php: function update_videos() and update_images()".
if ($doZIP) rename_with_timestamp('iminfo.xml',$timeStr);
if ($iminfo_objs[$key]->asXML('iminfo_UpdateAndSave.xml')){
$upd_succ[$i]['status']=1;
}
chdir('..');
$upd_succ[$i]['directory']=$key;
if ($upd_succ[$i]['status']==1){$zip=$doZIP;}
$upd_succ[$i]['reason']='New media';
$i++;
}
$ZipModuleLoaded=extension_loaded('zip');
if ($zip && $ZipModuleLoaded){
list($nIminfoInZIP,$zipname)=zip_iminfo_files($ZipModuleLoaded,$upd_succ,$timeStr);
}
if ($send_email){send_email_update_iminfo($nIminfoInZIP,$zipname,$wdir,$upd_succ,$XFFFFF,$server_info,__FUNCTION__);}
}
6.11. send_email_update_iminfo(…)¶
Interface definition
-
send_email_update_iminfo
($nIminfoInZIP, $zipname, $wdir, $upd_success, $XFFFFF, $server_info, $caller)¶ Called by
Iminfo_XML_Objects_UpdateAndSave()
,updateIminfoFiles()
, andphp\Imageresizeprocess.php
.Parameters: - $nIminfoInZIP (Integer) – Number of iminfo.xml files in ZIP.
- $zipname (String) – Name of the ZIP file.
- $wdir (String) – Location directory name.
- $upd_success (Array) –
$upd_succ
Private data ofIminfo_XML_Objects_UpdateAndSave()
andupdateIminfoFiles()
. - $XFFFFF (Object) – See object definition.
- $server_info (Object) – See
server_info_Object
object. - $caller (String) –
Returns: array($status, $mail->ErrorInfo)
6.11.1. Source code¶
<?php
function send_email_update_iminfo($nIminfoInZIP,$zipname,$wdir,$upd_success,$XFFFFF,$server_info,$caller){
// Reference: https://github.com/PHPMailer/PHPMailer
// For methods and properties: http://phpmailer.github.io/PHPMailer/classes/PHPMailer.html
// INP1: Name of the ZIP-file containing the original iminfo files which have been updated
// INP2: Work directory.
// INP3: update status array
// INP4: ip address of web client
// INP5: Name of the function calling this function
// OUT1: list(boolean,mail->ErrorInfo)
$mail=CreateEmailContainer(WEBMASTER,false,$XFFFFF['client_ip']);
if ($mail->obj_stat==1){
$mail->Subject.="$wdir: iminfo files updated";
$str="User: ".$server_info['uname']."<br>";
$str.=__FILE__.",<br>	in function ".__FUNCTION__."(), <br>	called by ".$caller."().<br>";
if ($nIminfoInZIP==-1) $str.="ZIP module not loaded --> No ZIP-file has been created:";
else if ($nIminfoInZIP==0) {
$str.="No ZIP-file has been created: <b>no</b> iminfo.xml files have been changed: <br>";
$str.="This can mean that either there was problem with:<br>";
$str.="1) iminfo.txt or iminfo.xml files do not exist, or<br>";
$str.="2) Time stamped iminfo.xml files do not exist (modified code?), or <br>";
$str.="3) Time stamped iminfo.xml files do not exist: macro DEBUG_TEST = TRUE, or <br>";
$str.="4) Update code not yet implemented (IminfoXML2UpdatedIminfoXML_Obj()).<br><br>";
$str.="In the following lines the strings \"<code>\$upd_success['code']</code>\" and \"<code>\$upd_success['status']</code>\" refer to the first output argument of the function <b>check_mediacount_iminfo_files()</b><br><br>";
$str.="<code>UPDATE_IMINFO_EXISTS_OK = 0x01</code><br>";
$str.="<code>UPDATE_IMINFO_MEDIACOUNT= 0x02</code><br>";
$str.="<code>UPDATE_IMINFO_VERSION = 0x04</code><br>";
$str.="<code>UPDATE_IMINFO_MAXCOUNT = 0x08</code><br>";
$str.="<code>UPDATE_IMINFO_IMAGEINFO = 0x10</code><br>";
$str.="<code>UPDATE_IMINFO_VIDEOINFO = 0x20</code><br><br>";
}
else if ($nIminfoInZIP>0){
if (strlen($zipname)>0){
$mail->addAttachment($zipname);
$str.="iminfo.xml files in <b>$zipname</b> have been updated: <br>";
}
}
foreach ($upd_success as $upd){
//echo $upd['iminfo_version']['old']." ".$upd['iminfo_version']['new']."<br>";
$dname=$upd['directory'];
if ($upd['code'] != UPDATE_IMINFO_EXISTS_OK){
switch ($upd['status']){
case E_IMINFO_TXT_1:
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code']=".$upd['code']."</code>):<br><pre> IMINFO.XML NOT UPDATED: IMINFO.TXT DOES NOT EXIST! (\$upd_success['status']=E_IMINFO_TXT_1)</pre>";
break;
case E_IMINFO_TXT_2:
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code']=".$upd['code']."</code>):<br><pre> IMINFO.XML NOT UPDATED: IMINFO.TXT IS EMPTY! (\$upd_success['status']=E_IMINFO_TXT_2)</pre>";
break;
case E_IMINFO_UPD_OK:
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code']=".$upd['code']."</code>):<br><pre> IMINFO.XML succesfully updated. Original is zipped. (\$upd_success['status']=E_IMINFO_UPD_OK)</pre>";
$str.="<pre> Reason for update: ".$upd['reason']."</pre>";
if ($upd['code']==UPDATE_IMINFO_VERSION){
$str.="<pre> From version ".$upd['iminfo_version']['old']." to ".$upd['iminfo_version']['new']."</pre>";
}
break;
case E_IMINFO_UPD_OK_B:
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code']=".$upd['code']."</code>):<br><pre> IMINFO.XML succesfully updated and written to new file (".$upd['fname']."). (\$upd_success['status']=E_IMINFO_UPD_OK_B)</pre>";
$str.="<pre> Reason for update: ".$upd['reason']."</pre>";
if ($upd['code']==UPDATE_IMINFO_VERSION){
$str.="<pre> From version ".$upd['iminfo_version']['old']." to ".$upd['iminfo_version']['new']."</pre>";
}
break;
case E_IMINFO_CRE_OK:
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code']=".$upd['code']."</code>):<br><pre> IMINFO.XML DOES NOT EXIST --> SUCCESSFULLY GENERATED. (\$upd_success['status']=E_IMINFO_CRE_OK)</pre>";
break;
case E_IMINFO_UPD_NOT_MODIFIED:
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code']=".$upd['code']."</code>):<br><pre> IMINFO.XML NOT UPDATED, but update was requested. (\$upd_success['status']=E_IMINFO_UPD_NOT_MODIFIED)</pre>";
$str.="<pre> Reason for requested update: ".$upd['reason']."</pre>";
break;
}
}
else {
$str.="Directory: \"".$dname."\" (<code>\$upd_success['code'] = UPDATE_IMINFO_EXISTS_OK</code>): <br><pre> IMINFO.XML NO UPDATE NEEDED.</pre>";
}
}
$mail->Body =$str;
$mail->AltBody="iminfo.xml files in $zipname have been updated";
if(!$mail->send()){$status=0;} else {$status=1;}
return array($status,$mail->ErrorInfo);
}
else {
return array(0,-1);
}
}
6.12. updateIminfoXMLFile(…)¶
Interface definition
-
updateIminfoXMLFile
($deb_test, $ldir, $timeStr, $xml_data, $preserveDateModified)¶ Function is called by
updateIminfoFiles()
Parameters: - $deb_test (Boolean) – Debug test purpose.
- $ldir (String) – location directory name
- $timeStr (String) – Time string
- $xml_data –
Iminfo data object (SimpleXMLElement object)
- $preserveDateModified (Integer - Octogonal format) –
Returns: - $outVal ( ** ),
- $xml_name ( String ) - name of iminfo filename to which the updated iminfo object is saved.
6.13. updateIminfoFiles(…)¶
Interface definition
-
updateIminfoFiles
($mod, $updIminfo, $iminfo_objs, $XFFFFF, $send_email=FALSE)¶ Function for updating all iminfo.xml’s only (no media updating) and for all users as well as for privileged user (admin, …) in the UPDATE-1 process phase. The conditions for calling UPDATE-1 process are described in Table 6.1.
Function is called by
dirThumbs()
. Internal data object$upd_succ
.Parameters: - $mod (Integer) –
Determines update method
- 1: updating iminfo by calling
IminfoTXT2IminfoXML()
- 2: updating iminfo by calling
updateIminfoXMLFile()
- 1: updating iminfo by calling
- $updIminfo (Object) – Data object (see Private variables and
$update_iminfo
) returned by first output argument ofcheck_mediacount_iminfo_files()
- $iminfo_objs (Object) –
Array of SimpleXMLElement objects of Iminfo.xml files
- $XFFFFF (Object) – See object definition.
- $send_email (Boolean) – optional argument, default = FALSE
Returns: - $FinalUpdateStat ( Intger ) - Result depends on the values in the array $upd_succ[$i][‘status’], where $i is a counter over the number of location directories.
- $mod (Integer) –
Reason | Implemented | ||
---|---|---|---|
1 | UPDATE_IMINFO_MEDIACOUNT
0x2
|
|
NO |
2 | UPDATE_IMINFO_VERSION
0x4
|
IMINFO version has changed (defined by IMINFO_VERSION = 20170525H2314) | YES |
3 | UPDATE_IMINFO_MAXCOUNT
0x8
|
$xml->media->count()≠$xml->MediaCounterInfo->MaxCnt. Normally, this should not occur. | YES |
6.13.1. Source code¶
<?php
function updateIminfoFiles($modus,$updIminfo,$iminfo_objs,$XFFFFF,$server_info,$send_email=FALSE){
// Function called by dirThumb(): prepareDirOverviewGalleryAjax.php
// Update and save IMINFO files (phase 1): $iminfo_objs are not updated since the updated info is not needed in phase 1.
// INP1: modus determines how to update IMINFO.XML [call IminfoTXT2IminfoXML or updateIminfoXMLFile()]
// INP2: Array returned by check_mediacount_iminfo_files(…).
// INP3: $iminfo_objs
// INP4: $XFFFFF status information
// INP5: (Optional) send e-mail or not
// OUT1: TRUE if at least one iminfo file has been updated, otherwise FALSE
$iminfo_version=array('old'=>0,'new'=>0);
$upd_succ=array_fill(0,count($updIminfo),array('status'=>UPDATE_IMINFO_EXISTS_OK,'directory'=>'','fname'=>'iminfo.xml','reason'=>'','code'=>0,'iminfo_version'=>$iminfo_version));
$timeStr=date("Ymd-Hi",time());
$wdir=str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace("\\","/",getcwd()));
$zip=0;
$zipname='';
$nIminfoInZIP=0;
$i=0;
$mod=$modus&007;
foreach ($iminfo_objs as $ldir=>$xml_iminfo){
// if (($updIminfo[$i]==UPDATE_IMINFO_NOFILE)||($updIminfo[$i]==UPDATE_IMINFO_MEDIACOUNT)||($updIminfo[$i]==UPDATE_IMINFO_VERSION)){
$upd_succ[$i]['directory']=$ldir;
$upd_succ[$i]['code']=$updIminfo[$i];
if ($updIminfo[$i] != UPDATE_IMINFO_EXISTS_OK){
// IMINFO.XML file does not exist --> IMINFO.XML must be created from IMINFO.TXT.
if ($xml_iminfo==NULL) $mod=1;
if ($mod==1){
// Kept for backward compatibility.
// Update IMINFO.XML with data from IMINFO.TXT. The original IMINFO.XML is renamed using datestring.
// Output val.IminfoTXT2IminfoXML:
// E_IMINFO_FS_W(-10), E_IMINFO_TXT_1(-1), E_IMINFO_TXT_2(0), E_IMINFO_UPD_OK(1), E_IMINFO_UPD_OK(2), E_IMINFO_CRE_OK(3)
list($upd_succ[$i]['status'],$upd_succ[$i]['fname'])=IminfoTXT2IminfoXML(DEBUG_TEST,$ldir,$timeStr);
}
if ($mod==2){
// Default update method
// Update IMINFO.XML by updating OBJECT and SAVING OBJECT. Output val.updateIminfoXMLFile:
// E_IMINFO_XML_2(-3), E_IMINFO_XML_1(-2), E_IMINFO_UPD_OK(1), E_IMINFO_UPD_OK_B(2)
$upd_succ[$i]['iminfo_version']['old']=(string)$xml_iminfo->Version;
list($upd_succ[$i]['status'],$upd_succ[$i]['fname'])=updateIminfoXMLFile(DEBUG_TEST,$ldir,$timeStr,$xml_iminfo,$modus&070);
$upd_succ[$i]['iminfo_version']['new']=IMINFO_VERSION;
}
if ($upd_succ[$i]['status']==E_IMINFO_UPD_OK){$zip=1;}
// switch($updIminfo[$i]){
// case UPDATE_IMINFO_NOFILE: $upd_succ[$i]['reason']='No IMINFO.XML file';
// break;
// case UPDATE_IMINFO_MEDIACOUNT: $upd_succ[$i]['reason']='Media count in public/private directories has changed';
// break;
// case UPDATE_IMINFO_VERSION: $upd_succ[$i]['reason']='IMINFO Version number has changed';
// break;
// }
if ($updIminfo[$i]==UPDATE_IMINFO_NOFILE) {
$upd_succ[$i]['reason']='No IMINFO.XML file';
}
else {
// TAB-char = 	
if (($updIminfo[$i]&UPDATE_IMINFO_MEDIACOUNT)==UPDATE_IMINFO_MEDIACOUNT){
$upd_succ[$i]['reason'].='Media count in public/private directories has changed.';
}
if (($updIminfo[$i]&UPDATE_IMINFO_VERSION)==UPDATE_IMINFO_VERSION){
$upd_succ[$i]['reason'].='IMINFO Version number has changed.';
}
if (($updIminfo[$i]&UPDATE_IMINFO_MAXCOUNT)==UPDATE_IMINFO_MAXCOUNT){
$upd_succ[$i]['reason'].='Max media count number has changed.';
}
}
}
$i++;
}
// ZIP renamed iminfo.xml files if ZIP module is loaded.
if ($zip) {
if (extension_loaded('zip')){
list($nIminfoInZIP,$zipname)=zip_iminfo_files(true,$upd_succ,$timeStr);
}
}
if ($send_email){send_email_update_iminfo($nIminfoInZIP,$zipname,$wdir,$upd_succ,$XFFFFF,$server_info,__FUNCTION__);}
// if array $upd_succ[$i]['status'] has at least 1 value equal to 1 then $FinalUpdateStat = TRUE.
$status=array_column($upd_succ,'status');
$FinalUpdateStat=array_reduce($status,"_has_value_1",0);
return ($FinalUpdateStat);
// WHEN MEDIA FILES HAVE BEEN MOVED FROM RESIZED TO PRIVATE DIRECTORY, IMINFO FILE MUST BE UPDATED
$pwd=getcwd();
$resizedDir="Resized";
$private="Private";
$sdir=$parent.DS.$vakantieDir;
chdir($sdir);
$rprocData=f_parse_csv('rproc.txt',1000,',');
$dirCnt=count($rprocData)-1;
/* Read iminfo file in each location directory */
$dirList = array_diff(scandir('.'),array('..','.'));
$dirNames=array();
foreach ($dirList as $locDir){
if (is_dir($locDir)){
chdir($locDir);
$dirNames[]=$locDir;
$imArray=f_parse_csv('iminfo.txt',1000,',');
$fCnt=count($imArray);
$fnames=array();
for ($i=0;$i<$fCnt;$i++){
$fnames[$i]=$imArray[$i][0];
$imArray[$i][4]="R";
}
chdir($resizedDir);
if (is_dir($private)){
chdir($private);
$imlist_P=glob('*-small.*');
/* update info array */
foreach ($imlist_P as $img){
$pos=array_search($img,$fnames);
$imArray[$pos][4]="Private";
}
chdir("..");
}
chdir("..");
$fp2=fopen('iminfo.txt','w');
foreach ($imArray as $key => $row){
$str='';
for ($i=0;$i<9;$i++){$str.=$row[$i].',';}
$str.=PHP_EOL;
fwrite($fp2,$str);
}
// foreach ($imArray as $fields){fputcsv($fp,$fields);fwrite($fp,PHP_EOL);}
fclose($fp2);
flush();
chdir("..");
}
}
chdir($pwd);
}