コード例 #1
0
ファイル: diffTest.php プロジェクト: alerque/bibledit
 public function tearDown()
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications = Database_Modifications::getInstance();
     Filter_Client::set(false);
     $database_bibles->deleteBible("phpunit");
     $database_modifications->truncateTeams();
     Filter_Rmdir::rmdir($this->temporary_folder);
 }
コード例 #2
0
ファイル: usfmresources.php プロジェクト: alerque/bibledit
 public function deleteBook($name, $book)
 {
     $path = $this->bookFolder($name, $book);
     // If a folder: Delete it.
     if (is_dir($path)) {
         Filter_Rmdir::rmdir($path);
     }
     // If a file: Delete it.
     if (file_exists($path)) {
         unlink($path);
     }
 }
コード例 #3
0
ファイル: rmdir.php プロジェクト: alerque/bibledit
 public static function rmdir($dir)
 {
     if (is_dir($dir)) {
         $objects = scandir($dir);
         foreach ($objects as $object) {
             if ($object != "." && $object != "..") {
                 if (filetype($dir . "/" . $object) == "dir") {
                     Filter_Rmdir::rmdir($dir . "/" . $object);
                 } else {
                     unlink($dir . "/" . $object);
                 }
             }
         }
         unset($objects);
         rmdir($dir);
     }
 }
コード例 #4
0
ファイル: archive.php プロジェクト: alerque/bibledit
 /**
  * Uncompresses a .tar.gz archive identified by $file.
  * Returns the path to the folder it created.
  * If $show_errors is true, it outputs errors in html.
  */
 public static function untargz($file, $show_errors)
 {
     $file = escapeshellarg($file);
     $folder = uniqid(sys_get_temp_dir() . "/");
     mkdir($folder);
     exec("cd {$folder} && tar zxf {$file} 2>&1", $output, $return_var);
     if ($return_var != 0) {
         Filter_Rmdir::rmdir($folder);
         $folder = NULL;
         if ($show_errors) {
             Assets_Page::error(Locale_Translate::_("Failed to uncompress archive"));
             foreach ($output as $line) {
                 Assets_Page::error($line);
             }
             Assets_Page::error("Return status: {$return_var}");
         }
     }
     return $folder;
 }
コード例 #5
0
ファイル: offlineresources.php プロジェクト: alerque/bibledit
 public function unlink($name, $file)
 {
     $path = $this->resourceFolder($name) . "/{$file}";
     // If a folder: Delete it.
     if (is_dir($path)) {
         Filter_Rmdir::rmdir($path);
     }
     // If a file: Delete it.
     if (file_exists($path)) {
         unlink($path);
     }
 }
コード例 #6
0
ファイル: git.php プロジェクト: alerque/bibledit
 public static function syncBible2Git($bible, $git, $progress = false)
 {
     $success = true;
     $database_bibles = Database_Bibles::getInstance();
     $database_books = Database_Books::getInstance();
     // First stage.
     // Read the chapters in the git repository,
     // and check if they occur in the database.
     // If a chapter is not in the database, remove it from the repository.
     $books = $database_bibles->getBooks($bible);
     foreach (new DirectoryIterator($git) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         if ($fileInfo->isDir()) {
             $bookname = $fileInfo->getFilename();
             $book = $database_books->getIdFromEnglish($bookname);
             if ($book) {
                 if (in_array($book, $books)) {
                     // Book exists in the database: Check the chapters.
                     $chapters = $database_bibles->getChapters($bible, $book);
                     foreach (new DirectoryIterator("{$git}/{$bookname}") as $fileInfo2) {
                         if ($fileInfo2->isDot()) {
                             continue;
                         }
                         if ($fileInfo2->isDir()) {
                             $chapter = $fileInfo2->getFilename();
                             if (is_numeric($chapter)) {
                                 $filename = "{$git}/{$bookname}/{$chapter}/data";
                                 if (file_exists($filename)) {
                                     if (!in_array($chapter, $chapters)) {
                                         // Chapter does not exist in the database.
                                         Filter_Rmdir::rmdir("{$git}/{$bookname}/{$chapter}");
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     // Book does not exist in the database: Remove it from $git.
                     Filter_Rmdir::rmdir("{$git}/{$bookname}");
                 }
             }
         }
     }
     // Second stage.
     // Read the books / chapters from the database,
     // and check if they occur in the repository, and the data matches.
     // If necessary, save the chapter to the repository.
     $books = $database_bibles->getBooks($bible);
     foreach ($books as $book) {
         $bookname = $database_books->getEnglishFromId($book);
         if ($progress) {
             echo "{$bookname} ";
         }
         $bookdir = "{$git}/{$bookname}";
         if (!file_exists($bookdir)) {
             mkdir($bookdir);
         }
         $chapters = $database_bibles->getChapters($bible, $book);
         foreach ($chapters as $chapter) {
             $chapterdir = "{$bookdir}/{$chapter}";
             if (!file_exists($chapterdir)) {
                 mkdir($chapterdir);
             }
             $datafile = "{$chapterdir}/data";
             @($contents = file_get_contents($datafile));
             $usfm = $database_bibles->getChapter($bible, $book, $chapter);
             if ($contents != $usfm) {
                 file_put_contents($datafile, $usfm);
             }
         }
     }
     if ($progress) {
         echo "\n";
     }
     return $success;
 }
コード例 #7
0
ファイル: conflictTest.php プロジェクト: alerque/bibledit
 protected function tearDown()
 {
     Filter_Rmdir::rmdir($this->repository);
     Filter_Rmdir::rmdir($this->userclone);
     Filter_Rmdir::rmdir($this->serverclone);
 }
コード例 #8
0
ファイル: notes.php プロジェクト: alerque/bibledit
 public function delete($identifier)
 {
     // Delete from filesystem.
     $folder = $this->noteFolder($identifier);
     Filter_Rmdir::rmdir($folder);
     // Update database as well.
     $this->deleteChecksum($identifier);
     $db = self::connect();
     $identifier = Database_SQLiteInjection::no($identifier);
     $query = "DELETE FROM notes WHERE identifier = {$identifier};";
     Database_SQLite::exec($db, $query);
     unset($db);
 }
コード例 #9
0
ファイル: sendreceive.php プロジェクト: alerque/bibledit
$directory = Filter_Git::git_directory($bible);
$shelldirectory = escapeshellarg($directory);
// Check that the repository directory is there.
if (!is_dir($directory)) {
    $database_logs->log("{$send_receive} Cannot send and receive because the git repository was not found in the filesystem.");
    die;
}
// Sync the repository with the database.
$success = Filter_Git::syncBible2Git($bible, $directory);
// If the above does not succeed, then there is a serious problem.
// It means that the git repository no longer reflects the data in the database.
// This may lead to data corruption.
// Through the repository this would then be propagated to other the systems.
// The best thing to do is to remove the .git directory altogether so that it cannot propagate corrupt data.
if (!$success) {
    Filter_Rmdir::rmdir("{$directory}/.git");
}
// Commit the new data to the repository.
// Log unusual things.
if ($success) {
    $logs = array();
    $command = "cd {$shelldirectory}; git add . 2>&1";
    $logs[] = "{$send_receive} {$command}";
    unset($result);
    exec($command, $result, $exit_code);
    if ($exit_code != 0) {
        $success = false;
    }
    foreach ($result as $line) {
        $logs[] = "{$send_receive} {$line}";
    }
コード例 #10
0
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::ADMIN_LEVEL);
Assets_Page::header(Locale_Translate::_("Collaboration"));
$view = new Assets_View(__FILE__);
$object = $_GET['object'];
$view->view->object = $object;
$database_config_bible = Database_Config_Bible::getInstance();
if (isset($_POST['url'])) {
    $url = $_POST['urlvalue'];
    $database_config_bible->setRemoteRepositoryUrl($object, $url);
}
$url = $database_config_bible->getRemoteRepositoryUrl($object);
$view->view->url = $url;
// Create the git repository directory now since this is the most convenient moment to do it.
$directory = Filter_Git::git_directory($object);
Filter_Rmdir::rmdir($directory);
mkdir($directory, 0777, true);
$command = "git ls-remote {$url} 2>&1";
$view->view->command = $command;
ob_start();
system($command, $exit_code);
$read_access_result = ob_get_contents();
ob_end_clean();
$view->view->read_access_result = nl2br($read_access_result);
if ($exit_code == 0) {
    $success_message = Locale_Translate::_("Read access to the repository is successful.");
} else {
    $error_message = Locale_Translate::_("Read access failed. Please retry it, possibly with another URL.");
}
@($view->view->success_message = $success_message);
@($view->view->error_message = $error_message);
コード例 #11
0
ファイル: collaboration.php プロジェクト: alerque/bibledit
@($select = $_GET['select']);
if (isset($select)) {
    if ($select == "") {
        $dialog_list = new Dialog_List(array("object"), Locale_Translate::_("Which Bible are you going to use?"), "", "");
        $database_bibles = Database_Bibles::getInstance();
        $bibles = $database_bibles->getBibles();
        foreach ($bibles as $value) {
            $dialog_list->add_row($value, "&select={$value}");
        }
        $dialog_list->run();
        die;
    } else {
        $object = $select;
    }
}
$view->view->object = $object;
$database_config_bible = Database_Config_Bible::getInstance();
$url = $database_config_bible->getRemoteRepositoryUrl($object);
if (isset($_GET['disable'])) {
    $url = "";
    $database_config_bible->setRemoteRepositoryUrl($object, $url);
    $repository = Filter_Git::git_directory($object);
    Filter_Rmdir::rmdir($repository);
}
$url = $database_config_bible->getRemoteRepositoryUrl($object);
$view->view->url = $url;
$git = new Filter_Which("git");
$git = $git->available;
$view->view->git_available = $git;
$view->render("collaboration.php");
Assets_Page::footer();
コード例 #12
0
ファイル: gitTest.php プロジェクト: alerque/bibledit
 public function testSyncGitChapterToBibleDeleteChapters()
 {
     $database_bibles = Database_Bibles::getInstance();
     // The git repository has Psalm 0, Psalm 11, and Song of Solomon 2.
     // Put that into the database.
     Filter_Git::syncGit2Bible($this->repository, $this->bible);
     // Remove one book and one chapter from the git repository,
     Filter_Rmdir::rmdir($this->repository . "/Song of Solomon");
     Filter_Rmdir::rmdir($this->repository . "/Psalms/0");
     // Run updates on the three chapters.
     Filter_Git::syncGitChapter2Bible($this->repository, $this->bible, 19, 0);
     Filter_Git::syncGitChapter2Bible($this->repository, $this->bible, 19, 11);
     Filter_Git::syncGitChapter2Bible($this->repository, $this->bible, 22, 2);
     // There should still be two books, although one book would have no chapters.
     $books = $database_bibles->getBooks($this->bible);
     $this->assertEquals($books, array(19, 22));
     // Check that the chapter data matches.
     $usfm = $database_bibles->getChapter($this->bible, 19, 0);
     $this->assertEmpty($usfm);
     $usfm = $database_bibles->getChapter($this->bible, 19, 11);
     $this->assertEquals($this->psalms_11_data, $usfm);
     $usfm = $database_bibles->getChapter($this->bible, 22, 2);
     $this->assertEmpty($usfm);
 }
コード例 #13
0
ファイル: index.php プロジェクト: alerque/bibledit
$database_config_bible = Database_Config_Bible::getInstance();
$bibles = $database_bibles->getBibles();
// Go through all sub directories of the exports directory.
// Remove subdirectories if their corresponding Bible no longer exists in the system.
$directory = Export_Logic::mainDirectory();
foreach (new DirectoryIterator($directory) as $fileInfo) {
    if ($fileInfo->isDot()) {
        continue;
    }
    if ($fileInfo->isDir()) {
        $bible = $fileInfo->getFilename();
        if (in_array($bible, $bibles)) {
            continue;
        }
        $path = $fileInfo->getPathname();
        Filter_Rmdir::rmdir($path);
        $database_logs->log("Removing exported Bible {$bible}", Filter_Roles::ADMIN_LEVEL);
    }
}
// Schedule the relevant Bibles for export.
foreach ($bibles as $bible) {
    if ($database_config_bible->getExportWebDuringNight($bible)) {
        Export_Logic::scheduleWeb($bible);
        Export_Logic::scheduleWebIndex($bible);
    }
    if ($database_config_bible->getExportHtmlDuringNight($bible)) {
        Export_Logic::scheduleHtml($bible);
    }
    if ($database_config_bible->getExportUsfmDuringNight($bible)) {
        Export_Logic::scheduleUsfm($bible);
    }
コード例 #14
0
ファイル: modifications.php プロジェクト: alerque/bibledit
 public function deleteNotification($identifier, $db = null)
 {
     // Delete from the filesystem.
     $folder = $this->notificationIdentifierFolder($identifier);
     Filter_Rmdir::rmdir($folder);
     // Delete from the database.
     $identifier = Database_SQLiteInjection::no($identifier);
     $query = "DELETE FROM notifications WHERE identifier = {$identifier};";
     // Make a very short connection to the database,
     // to prevent corruption when a user deletes masses of changes notifications
     // by keeping the delete key pressed.
     if ($db == null) {
         $db = $this->connect();
     }
     Database_SQLite::exec($db, $query);
     unset($db);
 }
コード例 #15
0
ファイル: text.php プロジェクト: alerque/bibledit
 public function __destruct()
 {
     Filter_Rmdir::rmdir($this->unpackedOdtFolder);
 }
コード例 #16
0
ファイル: manage.php プロジェクト: alerque/bibledit
$database_bibles = Database_Bibles::getInstance();
$database_users = Database_Users::getInstance();
$session_logic = Session_Logic::getInstance();
// Delete Bible handler.
if (isset($_GET['delete'])) {
    $bible = $_GET['delete'];
    @($confirm = $_GET['confirm']);
    if ($confirm != "") {
        ignore_user_abort(true);
        set_time_limit(0);
        // User needs write access for delete operation.
        if (Access_Bible::write($bible)) {
            Bible_Logic::deleteBible($bible);
            $gitdirectory = Filter_Git::git_directory($bible);
            if (file_exists($gitdirectory)) {
                Filter_Rmdir::rmdir($gitdirectory);
            }
        } else {
            Assets_Page::error("Insufficient privileges to complete action");
        }
    } else {
        $dialog_yes = new Dialog_Yes(NULL, Locale_Translate::_("Would you like to delete Bible {$bible}?"), "delete");
        die;
    }
}
// New Bible handler.
if (isset($_GET['new'])) {
    $dialog_entry = new Dialog_Entry("", Locale_Translate::_("Please enter a name for the new empty Bible"), "", "new", "");
    die;
}
if (isset($_POST['new'])) {
コード例 #17
0
ファイル: archiveTest.php プロジェクト: alerque/bibledit
 public function testFilterArchiveUntargz()
 {
     $tarball = Filter_Archive::tarGzipFile($this->file1, false);
     // Test decompression.
     $folder = Filter_Archive::untargz($tarball, false);
     $this->assertTrue(file_exists($folder));
     Filter_Rmdir::rmdir($folder);
     $folder = Filter_Archive::uncompress($tarball, false);
     $this->assertTrue(file_exists($folder));
     foreach (new DirectoryIterator($folder) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $path = $fileInfo->getFilename();
         $path = "{$folder}/{$path}";
         $this->assertEquals(9000, filesize($path));
     }
     Filter_Rmdir::rmdir($folder);
     unlink($tarball);
     // Test that unzipping garbage returns NULL.
     $folder = Filter_Archive::untargz("xxxxx", false);
     $this->assertEquals(NULL, $folder);
 }
コード例 #18
0
ファイル: temp.php プロジェクト: alerque/bibledit
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
// Security: Page only runs from the cli SAPI.
Filter_Cli::assert();
$database_logs = Database_Logs::getInstance();
$database_logs->log("Removing expired temporal files", Filter_Roles::ADMIN_LEVEL);
$expired = strtotime("-3 days");
$directory = dirname(__DIR__) . "/tmp";
$names = scandir($directory);
$names = Filter_Folders::cleanup($names);
foreach ($names as $name) {
    $filename = "{$directory}/{$name}";
    $mtime = filemtime($filename);
    if ($mtime < $expired) {
        if (is_file($filename)) {
            unlink($filename);
        }
        if (is_dir($filename)) {
            Filter_Rmdir::rmdir($filename);
        }
    }
}
コード例 #19
0
ファイル: bibles.php プロジェクト: alerque/bibledit
 public function deleteChapter($bible, $book, $chapter)
 {
     $folder = $this->chapterFolder($bible, $book, $chapter);
     Filter_Rmdir::rmdir($folder);
 }