/** * This function is used to install the default template on media directory of the site */ function installDefTemplate() { //temporary path of the default templates $path = JNEWSPATH_FRONT . 'templates'; //we get all the directories found on that temporary path $dirs = JFolder::folders($path); //temporary thumbnail path $pathThumbnail = JNEWSPATH_ADMIN . 'templates'; //we get all the files from the $errors = array(); $success = array(); //we create the permament path on media folder if (jnews::createDirectory(JNEWSPATH_TEMPLATES)) { //we get all the files from the temporary directory $allFiles = JFolder::files($path); //we put the index.html file on the permanent diretory foreach ($allFiles as $oneFile) { if (file_exists(JNEWSPATH_MEDIA . DS . 'index.html') and $oneFile == 'index.html') { continue; } if (JFile::copy($path . DS . $oneFile, JNEWSPATH_MEDIA . DS . $oneFile) !== true) { $errors[] = 'Could not copy the file from ' . $path . DS . $oneFile . ' to ' . JNEWSPATH_MEDIA . ' You can also copy it manually'; } } //then we put each directory with the corresponding files to the permanent directory foreach ($dirs as $oneDir) { $toFolder = JNEWSPATH_TEMPLATES . $oneDir; if (!jnews::createDirectory($toFolder)) { $errors[] = 'Could not create directory ' . $toFolder . ' You can also copy it manually'; } if (!jnews::copyFolder($path . DS . $oneDir, $toFolder)) { $errors[] = 'Could not copy the file from ' . $path . DS . $oneFile . ' to ' . $toFolder . ' You can also copy it manually'; } } if (!jnews::createDirectory(JNEWSPATH_TEMPLATES . 'thumbnail')) { $errors[] = 'Could not create directory ' . JNEWSPATH_TEMPLATES . 'thumbnail'; } if (!jnews::copyFolder(JNEWSPATH_ADMIN . 'templates' . DS . 'thumbnail', JNEWSPATH_TEMPLATES . 'thumbnail')) { $errors[] = 'Could not copy the file from ' . JNEWSPATH_ADMIN . 'templates' . DS . 'thumbnail to ' . JNEWSPATH_TEMPLATES . 'thumbnail. You can also copy it manually'; } } else { //otherwise we give an error message to the user $errors[] = 'Could not create directory ' . JNEWSPATH_TEMPLATES . 'You can also create it manually'; } //if there are no errors then we give a success message and do the removal of the temporary directory if (empty($errors)) { $sucess[] = 'Default templates successfully installed.'; jnews::displayInfo($sucess, 'success'); $errorsD = array(); //we get all the files of each directory in the temporary directory and delete them one by one foreach ($dirs as $oneDir) { if ($oneDir == 'entwine') { $dirsEntwine = JFolder::folders($path . DS . $oneDir); foreach ($dirsEntwine as $oneDirEntwine) { if (!jnews::removeFolder($path . DS . $oneDir . DS . $oneDirEntwine)) { $errorsD[] = " Error deleting template directory ' . {$oneDirEntwine} . ' from " . $path . DS . $oneDir . DS; } } if (!jnews::removeFolder($path . DS . $oneDir)) { $errorsD[] = " Error deleting template directory ' . {$oneDir} . ' from " . $path . DS; } } else { if (!jnews::removeFolder($path . DS . $oneDir)) { $errorsD[] = " Error deleting template directory ' . {$oneDir} . ' from " . $path . DS; } } } if (!unlink(JNEWSPATH_ADMIN . 'templates' . DS . 'index.html') || !jnews::removeFolder(JNEWSPATH_ADMIN . 'templates' . DS . 'thumbnail')) { jnews::displayInfo("Error deleting template thumbnail directory from " . JNEWSPATH_ADMIN . 'templates' . DS . 'thumbnail. You can also delete it manually.' . DS, 'error'); } if (!unlink($path . DS . 'index.html') || !jnews::removeFolder($path) || !empty($errorD)) { jnews::displayInfo("Error deleting temporary " . $path . " directory. You can also delete it manually.", 'error'); } else { // jnews::displayInfo("Successfully removed temporary directory ". $path,'success'); } } else { //otherwise we display the errors on screen jnews::displayInfo($errors, 'error'); } }