settings->title;
}
zip_entry_close($zip_entry);
}
}
zip_close($zip);
}
return $rsc_name;
} // try
catch(Exception $e) {
echo 'Caught exception: '.$e->getMessage()."\n";
return $dir;
}
}
function replaceAccents($str) {
$search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,ø,Ø,Å,Á,À,Â,Ä,È,É,Ê,Ë,Í,Î,Ï,Ì,Ò,Ó,Ô,Ö,Ú,Ù,Û,Ü,Ÿ,Ç,Æ,Œ");
$replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,o,O,A,A,A,A,A,E,E,E,E,I,I,I,I,O,O,O,O,U,U,U,U,Y,C,AE,OE");
return str_replace($search, $replace, $str);
}
function adding_resource_json($file_json, $library, $file_name, $id, $title){
$temp_array=$file_json;
if ( isset($temp_array[$library])){
$temp_array[$library]+=array($file_name=>array('id'=>$id, 'title'=> $title));
}else {
$temp_array+=array($library=>array($file_name=>array('id'=>$id, 'title'=> $title)));
}
//echo "se añadieron cosas";
return $temp_array;
}
function resource_not_in_json($file_json, $library, $file_name){
$finded=false;
$temp_array = $file_json;
if ( isset($temp_array[$library][$file_name])){
$identificador=$temp_array[$library][$file_name]['id'];
$titulo=$temp_array[$library][$file_name]['title'];
$finded=true;
return array($file_json, $finded, $identificador, $titulo);
}else{
$identificador=false;
$titulo=false;
}
return array($file_json, $finded, $identificador, $titulo);
}
function CreateButton($dir, $resource, $class, $locale, $activities_orig, $library, $temp_array){
//echo "$resource\n";
//print_r ($activities_orig);
//$file_json="/net/server-sync/share/jclic-aula/jclic_uploads/0rig_jclic/jclic_files.json";
$resource_finded=array(false,false);
//var_dump($temp_array);
if ($class=="html"){
//echo "HTML";
$resource_dir=$resource;
$indexfile="$dir/$resource_dir/index.html";
$file_name="$dir/$resource_dir";
$added=false;
//print("$indexfile");
$resource_finded=resource_not_in_json($temp_array, $library, $file_name);
//var_dump($resource_finded);
if ($resource_finded[1]){
$indent=$resource_finded[2];
$title=$resource_finded[3];
//echo "encontrado html";
}else{
$added=true;
if(is_file($indexfile)){
$file=fopen($indexfile,r);
while (!feof($file)){
$read = fgets($file,255);
if (stristr($read,"
")){
$title=strip_tags($read);
}
}
fclose($file);
// echo "falta este html";
}else{
$title="";
}
//echo $title;
$title=trim($title);
if (in_array($indent,$activities_orig)){
return($indent);
}else{
//print ($title);
if ((strcasecmp( $title, 'sin nombre' ) == 0) || (strcasecmp( $rsc_name, 'sense nom' ) == 0)){
$title=$resource_dir;
}
$indent=$resource;
if ($added) {
$temp_array=adding_resource_json($temp_array, $library, $file_name, $indent, $title);
}
}
}
print("\n");
print("
$title
");
print("
");
} else{
//echo "JCLIC";
//Debemos transformarlo en HTML5 con el python crado cuando se haga click sobre él
/*if ( strcasecmp( $resource, 'menu' ) == 0){
$resource="menu_llx";
}*/
//var_dump($resource);
$file_name="$dir/$resource";
$finded="False";
$resource_finded=resource_not_in_json($temp_array, $library, $file_name);
//var_dump($resource_finded);
//print($library);
//var_dump($file_name);
if ($resource_finded[1]){
$indent=$resource_finded[2];
$title=$resource_finded[3];
//echo "encontrado jclic";
}else{
$rsc_name=getNameFromZip($dir, $resource);
$title=$rsc_name;
$title=(string)$title;
$title=replaceAccents($title);
$path_parts = pathinfo($resource);
$indent=$path_parts['filename'];
$cool_extensions = Array('jclic','zip','inst');
if (in_array(pathinfo($indent, PATHINFO_EXTENSION), $cool_extensions)){
$indent = pathinfo($indent, PATHINFO_FILENAME);
}
if ( (strcasecmp( $title, 'Sin nombre' ) == 0) || (strcasecmp( $title, 'sense nom' ) == 0) || (strcasecmp( $title, '' ) == 0)){
$title=$indent;
}
$title = preg_replace("/[^a-zA-Z 0-9]+/", "", $title );
$temp_array=adding_resource_json($temp_array, $library, $file_name, $indent, $title);
//var_dump($temp_array);
}
if (in_array($indent,$activities_orig)){
$finded="True";
}
//var_dump($finded);
if ($finded=="False"){
if (!$rsc_name){$rsc_name=$dir;}
//print("");
//print("
");
$path=$dir/$resource;
if ($locale=="valencia") {
$alert_lang="Tens un Jclic antic, estem transforman-lo a HTML5";
}else{
$alert_lang="Tienes un jclic antiguo, estamos transformandolo a HTML5";
}
print("
");
print("
$title
");
print("
");
}
}
//var_dump($temp_array);
return array($indent, $temp_array);
}
function LoadResourcesFromDir($jclicdirectory, $locale,$activities_orig, $library, $temp_array){
$rscfound=0; // Resources found
//var_dump($jclicdirectory);
$jclicconten = opendir($jclicdirectory);
//print_r ($activities_orig);
$activities=array();
$lista = array();
while($jclicfile = readdir($jclicconten))
{
//print ("leyendo");
if (substr("$jclicfile", 0, 1) != ".")
{
$ext_path=pathinfo($jclicfile, PATHINFO_EXTENSION);
if (strcasecmp( $ext_path, 'inst' ) !== 0){
$lista[] = $jclicfile;
}
}
}
//print_r($lista);
if(count($lista)>0)
{
sort($lista);
$title2="";
// Search .html
$resource="";
foreach($lista as $item){
//var_dump($item);
if(($item=="index.html") && (strstr($jclicdirectory,'jclic_upload'))){
$resource=$item;
//echo "2222222222222";
break; }
}
//var_dump($resource);
if (($resource!="") && (strstr($jclicdirectory,'jclic_upload'))){ // Found .html
// Button for resource
list ($title2, $temp_array)=CreateButton($jclicdirectory, $resource, "html", $locale,$activities_orig, $library, $temp_array);
$activities[] = $title2;
} else{ // Not found .html... search jclic.jclic
foreach($lista as $item){
if($item=="jclic.jclic"){
$resource=$item;
break;
}
}
if($resource!=""){ // Found jclic.jclic
//Button for jclic.jclic;
list ($title2, $temp_array)=CreateButton($jclicdirectory, $resource, "jclic",$locale ,$activities_orig, $library, $temp_array);
$activities[] = trim($title2);
} else {
foreach($lista as $item){
if((substr($item, -6 )==".jclic")){
$resource=$item;
//var_dump($item);
break;
}
}
if($resource!=""){ // Found any .jclic
//Button for *.jclic
//list ($title2, $temp_array)=CreateButton($jclicdirectory, $resource, "jclic",$locale ,$activities_orig, $library, $temp_array);
//$activities[] = trim($title2);
} else {
foreach($lista as $item){
//var_dump($item);
if(strpos($item, '.jclic')){
//echo "FOUND JCLIC LISTS!!!!!";
//echo "$resource";
//$resource=substr($item, 0, -4);
if ($item!=""){
// Button for .jclic.zip
list ($title2, $temp_array)=CreateButton($jclicdirectory, $item, "jclic",$locale ,$activities_orig, $library, $temp_array);
$activities[] = trim($title2);
//echo "$title2";
//echo "1111111111111111";
// Increasing number of elements
$rscfound++;
}
}else{
//if((substr($item, -4)==".zip")){
//var_dump($item);
$itemdir="$jclicdirectory/$item";
//var_dump($itemdir);
if(is_dir($itemdir) && (strstr($jclicdirectory,'jclic_upload'))){
$index_file="$jclicdirectory/$item/index.html";
if (!strstr($itemdir,'0rig')){
if(is_file($index_file)){
if ($item!=""){
// Button for .jclic.zip
list ($title2, $temp_array)=CreateButton($jclicdirectory, $item, "html",$locale, $activities_orig, $library, $temp_array);
$activities[] = trim($title2);
//echo "$title2";
//echo "222222222222222";
// Increasing number of elements
$rscfound++;
}
} else {
//lista directorio que no posee Index.html y lo creara
//echo "Crear INDEX excepto 0rig";
$item_library="/net/server-sync/share/jclic-aula/$jclicdirectory/$item/$item.jclic";
$item_library2="/net/server-sync/share/jclic-aula/$jclicdirectory/$item/library.jclic";
//var_dump($item_library);
if (file_exists($item_library)){
$item_extended="$item/$item.jclic";
//echo "existe";
}else{
if (file_exists($item_library2)){
$item_extended="$item/library.jclic";
//echo "existe2";
}else{
$item_extended="$item/$item.jclic.zip";
//echo "existe3";
}
}
//var_dump($item_extended);
list ($title2, $temp_array)=CreateButton($jclicdirectory, $item_extended, "jclic",$locale ,$activities_orig, $library, $temp_array);
$activities[] = trim($title2);
$rscfound++;
}
//break;
}
}
}
}
/*if ($resource!=""){ -------> MOVED UP
// Button for .jclic.zip
CreateButton($jclicdirectory, $resource, "jclic");
}*/
}
}
}
}
//print_r($activities);
//var_dump($temp_array);
return array($rscfound,$activities,$temp_array);
}
function LoadResourcesFromMainDir($basePath, $locale){
// Loads any jclic resource from basepath
//echo "aquiii " ;
//echo $basePath;
$numrsc=0;
// loop through the array of files and print them all
$rootdirectory = opendir($basePath);
//Read directory
while($jclicdirectory = readdir($rootdirectory))
{
//Only list directories (or zips)
//echo($jclicdirectory." is ".mime_content_type($jclicdirectory)."
");
if (filetype($jclicdirectory) == "dir" ||
filetype($jclicdirectory) == "link")
{
//if (substr($jclicdirectory, -4)==".zip") echo "ES UN ZIP";
//Only enter non hide directory
if (substr("$jclicdirectory", 0, 1) != "."&&$jclicdirectory!="jclic_uploads")
{
$rscs=LoadResourcesFromDir($jclicdirectory, $locale);
$numrsc+=$rscs;
}
} // if filetype...
} // While
if($numrsc==0){
if ($locale=="valencia") echo "
No hi ha recursos disponibles en esta secció
";
else echo "
No hay recursos disponibles en esta sección
";
}
}
//obtener el locale
$locale= get_locale();
// buscar title
$titles = array();
$titles = preg_find("/\.title/", "./");
foreach ($titles as $title) {
$txt="";
// comprobamos si no tiene extension "localizada"
if ( ereg("\.title$", $title) )
{
// lo mostraremos solamente si no existe version especifica para nuestro "locale"
$testfile=$title . "." . $locale ;
if ( ! is_file( $testfile ) ) $txt = file_get_contents($title);
// en caso contrario, se muestra sólo si tiene extension para el "locale" actual
} elseif ( ereg("\.title." . $locale, $title) )
{
$txt = file_get_contents($title);
}
echo "
$txt
";
}
//comprueba directorios y subdirectorios
function expandDirectories($base_dir) {
$directories = array();
$jclic_biblio_list = array();
foreach(scandir($base_dir) as $file) {
if($file == '.' || $file == '..') continue;
$dir = $base_dir.DIRECTORY_SEPARATOR.$file;
if(is_dir($dir)) {
$directories []= $dir;
$aux=expandDirectories($dir);
$directories = array_merge($directories, $aux[0]);
if (!empty($aux[1])){
//print ("ADDING");
$jclic_biblio_list = array_merge($jclic_biblio_list, $aux[1]);
}
}
else if (strpos($dir, 'jclic.zip')!== false){
//print ($dir);
$jclic_biblio_list[] = $dir;
}
}
//print_r($jclic_biblio_list);
$num_files=count($jclic_biblio_list);
return array ($dir, $jclic_biblio_list, $num_files);
}
/*function CreateButtonBiblio($dir, $resource, $class, $locale, $activities_orig){
}*/
?>
No hi ha recursos disponibles en esta secció
";
else echo "
No hay recursos disponibles en esta sección
";
}
?>