<?php
//#################################################################################################
// Insert pictures into content helper functions
//#################################################################################################
// chillyCMS - Content Management System
// Copyright (C) 2008
// Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//
// This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
// insertpictures_form()
// show_minipics($folder)
// folderselect_recursive()
//#################################################################################################
defined('DOIT') or die('Restricted access');
//Insert pictures form/////////////////////////////////////////////////////////////////////////////
function insert_pictures() {
global $showfolder,$mysession,$is_admin,$l_edit,$l_gen,$page;
$insertpictures = "<div class='popup'><br />".
"<h3 class='center'>$l_edit[lbl_pic]</h3><a class=\"info\" title=\"".$l_edit["lbl_howto"]."\"></a><br />";
$folders=array();
$path="../media";
$folders[]=$path;
folderselect_recursive($path,$folders);
$sql="select name from system_groups where";
foreach ($mysession->user->gids as $gid) {
$sql.=" gid=$gid or";
}
$sql=substr($sql,0,-3);
$page->query($sql);
$result = $page->db->getdata_array();
$okgroups=array();
foreach ($result as $group) {
$okgroups[]=$group["name"];
}
$insertpictures .= "<form style='margin:0 0 0 10px;' method='post' action='insertpictures.site.php'>".
"<select name='folder' size='1' class='button'>";
sort($folders);
foreach ($folders as $folder) {
$folderend=explode("/",$folder);
$folderend=array_pop($folderend);
//either a group the user is in or the media folder
if (in_array($folderend,$okgroups) or $folderend=="media" or $is_admin) {
if ($showfolder==$folder) {
$insertpictures .= "<option selected='selected'>$folder</option>";
} else {
$insertpictures .= "<option>$folder</option>";
}
}
}
$insertpictures .= "</select><input type='submit' class='button' value='$l_gen[lbl_show]'></input></form>";
$insertpictures .= show_minipics($showfolder);
$insertpictures .= "</div>";
return $insertpictures;
}
//Show links to all items /////////////////////////////////////////////////////////////////////////
function show_minipics($path) {
global $showfolder,$mysession,$is_admin,$page;
//Open selected folder
$fh = opendir($path);
$verzeichnisinhalt = array();
while (true == ($file = readdir($fh))) {
//Validate file formats //TODO
$formats=array("jpeg",".jpg",".png",".gif");
if (in_array(substr(strtolower($file),-4), $formats)) {
$verzeichnisinhalt[] = $file;
}
}
//Check if the directory is a groupfolder
$thisfolder = explode("/",substr($path,0,-1));
$foldername = array_pop($thisfolder);
$sql = "select u.uid from system_groups as g, system_users as u where g.name='$foldername' and g.moderator=u.uid";
$page->query($sql);
$uid = $page->db->getdata();
//The moderator's uid
$moduid=$uid["uid"];
$is_mod=false;
if ($moduid == $mysession->user->uid) { $is_mod=true; }
//append / if required
if (substr($path,-1)!="/") { $path.="/"; }
sort($verzeichnisinhalt);
$minipics = "\t\t<div class='minipics'>\n".
"\t\t\t<table cellspacing='10'>\n";
//Generate thumbnails
for($i=0;$i<sizeof($verzeichnisinhalt);$i++) {
$minipics .= "\t\t\t\t<tr>\n";
for ($j=0;$j<5;$j++) {
if ($i<sizeof($verzeichnisinhalt)) {
//make name short enough not to destroy the layout
$imgname = substr($verzeichnisinhalt[$i],0,strlen($verzeichnisinhalt[$i])-4);
if (strlen($imgname)>=9) { $imgname = substr($imgname,0,8).'...'; }
//One row (5 images)
$minipics .= "\t\t\t\t\t<td class='miniimages'>";
//Show file images
$minipics .= "<img src='".$path.$verzeichnisinhalt[$i]."' ".
" alt='$verzeichnisinhalt[$i]' title=\"$verzeichnisinhalt[$i]\" />".
"\t\t\t\t\t<p style='overflow:hidden;'>".$imgname."</p></td>\n";
if ($j<4) { $i++; }
}
}
$minipics .= "\t\t\t\t</tr>\n";
}
$minipics .= "\t\t\t</table>\n".
"\t\t</div>\n".
"\t<div class='clr'></div>\n".
"\t</div>\n";
return $minipics;
}
//Show folder select///////////////////////////////////////////////////////////////////////////////
function folderselect_recursive($path,&$folders) {
global $mysession,$is_admin,$page;
$result = false;
$handle = opendir($path);
//does the directory exist and can it be accessed?
if ($handle) {
//is there any content?
while (false !== ($file = readdir($handle))) {
//file is not the folder itself or the parent folder
if ($file != "." && $file != "..") {
$name = $path."/".$file;
$printname=substr($name,strlen($path)+1);
//"file" is a folder
if (is_dir($name)) {
array_push($folders,$name);
//is the user allowed to see the folder? if not stop recursing into it
$foldername=explode("/",$name);
$myfolder=array_pop($foldername);
$page->query("select gid from system_groups where name='$myfolder' limit 1");
$result = $page->db->getdata();
//If the user is in that group show him the folder
if ($is_admin or $result>2) {
$ar = folderselect_recursive($name,$folders);
}
}
}
}
}
//close directory and return the contents
closedir($handle);
return $result;
}
?>