Exemple #1
0
 public static function getFonts()
 {
     $fonts = scandir(__DIR__);
     $fonts = Filter_Folders::cleanup($fonts);
     $fonts = array_diff($fonts, array("index.php", "logic.php", "scripts", "SIL-Licenses.txt", "SIL-README.txt"));
     return $fonts;
 }
Exemple #2
0
 public static function queued($command)
 {
     $command = trim($command);
     $files = scandir(dirname(__DIR__) . "/processes");
     $files = Filter_Folders::cleanup($files);
     foreach ($files as $file) {
         @($contents = file_get_contents(dirname(__DIR__) . "/processes/{$file}"));
         $contents = trim($contents);
         if (strpos($contents, $command) !== false) {
             return $file;
         }
     }
     return null;
 }
Exemple #3
0
 private function readData()
 {
     $folder = $this->folder();
     $files = scandir($folder);
     $files = Filter_Folders::cleanup($files);
     $data = array();
     foreach ($files as $file) {
         $explosion = explode("__", $file);
         $rowid = $explosion[0];
         $user = $explosion[1];
         $channel = $explosion[2];
         $command = $explosion[3];
         $fields = array('file' => $file, 'rowid' => $rowid, 'user' => $user, 'channel' => $channel, 'command' => $command);
         $data[] = $fields;
     }
     return $data;
 }
Exemple #4
0
 public function getNames()
 {
     $names = array();
     $files = scandir($this->folder());
     $files = Filter_Folders::cleanup($files);
     foreach ($files as $file) {
         if ($file == strtolower($file)) {
             continue;
         }
         if (strpos($file, "_meta.php") != false) {
             continue;
         }
         $suffix = pathinfo($file, PATHINFO_EXTENSION);
         if ($suffix != "php") {
             continue;
         }
         $name = substr($file, 0, -1 - strlen($suffix));
         $name = str_replace("_", " ", $name);
         $names[] = $name;
     }
     $names = array_values($names);
     return $names;
 }
Exemple #5
0
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);
        }
    }
}
Exemple #6
0
 public function trim()
 {
     // Clean empty directories.
     $mainFolder = $this->mainFolder();
     $bits1 = scandir($mainFolder);
     $bits1 = Filter_Folders::cleanup($bits1);
     foreach ($bits1 as $bit1) {
         if (is_numeric($bit1)) {
             $folder = "{$mainFolder}/{$bit1}";
             $bits2 = scandir($folder);
             $bits2 = Filter_Folders::cleanup($bits2);
             if (empty($bits2)) {
                 Filter_Rmdir::rmdir($folder);
             }
             foreach ($bits2 as $bit2) {
                 if (is_numeric($bit2)) {
                     $folder = "{$mainFolder}/{$bit1}/{$bit2}";
                     $bits3 = scandir($folder);
                     $bits3 = Filter_Folders::cleanup($bits3);
                     if (empty($bits3)) {
                         Filter_Rmdir::rmdir($folder);
                     }
                 }
             }
         }
     }
 }
Exemple #7
0
 public function getNext($filename)
 {
     $files = scandir($this->folder());
     $files = Filter_Folders::cleanup($files);
     foreach ($files as $file) {
         if ($file > $filename) {
             $entry = file_get_contents($this->folder() . "/{$file}");
             return array($file, $entry);
         }
     }
     return NULL;
 }
Exemple #8
0
 public function indexTrimAllNotifications()
 {
     // Delete the index database and create an empty one.
     $this->delete();
     $this->create();
     // Change notifications expire after 30 days.
     $expiry_time = time() - 2592000;
     // Database: Connect and speed it up.
     $db = $this->connect();
     Database_SQLite::exec($db, "PRAGMA synchronous = OFF;");
     // Go through the notifications on disk.
     $identifiers = scandir($this->notificationsMainFolder());
     $identifiers = Filter_Folders::cleanup($identifiers);
     sort($identifiers, SORT_NUMERIC);
     foreach ($identifiers as $identifier) {
         // Fetch the data from the filesystem.
         $timestamp = file_get_contents($this->notificationTimeFile($identifier));
         $user = file_get_contents($this->notificationUserFile($identifier));
         $category = file_get_contents($this->notificationCategoryFile($identifier));
         $bible = file_get_contents($this->notificationBibleFile($identifier));
         $passage = file_get_contents($this->notificationPassageFile($identifier));
         $passage = explode(".", $passage);
         @($book = $passage[0]);
         @($chapter = $passage[1]);
         @($verse = $passage[2]);
         $modification = $this->getNotificationModification($identifier);
         // Validate the data.
         $valid = true;
         if ($timestamp < $expiry_time) {
             $valid = false;
         }
         if ($user == "") {
             $valid = false;
         }
         if ($bible == "") {
             $valid = false;
         }
         if (empty($passage)) {
             $valid = false;
         }
         if (!$book) {
             $valid = false;
         }
         if ($chapter == "") {
             $valid = false;
         }
         if ($verse == "") {
             $valid = false;
         }
         if ($modification == "") {
             $valid = false;
         }
         if ($valid) {
             // Store valid data in the database.
             $identifier = Database_SQLiteInjection::no($identifier);
             $timestamp = Database_SQLiteInjection::no($timestamp);
             $user = Database_SQLiteInjection::no($user);
             $category = Database_SQLiteInjection::no($category);
             $bible = Database_SQLiteInjection::no($bible);
             $book = Database_SQLiteInjection::no($book);
             $chapter = Database_SQLiteInjection::no($chapter);
             $verse = Database_SQLiteInjection::no($verse);
             $modification = Database_SQLiteInjection::no($modification);
             $query = "INSERT INTO notifications VALUES ({$identifier}, {$timestamp}, '{$user}', '{$category}', '{$bible}', {$book}, {$chapter}, {$verse}, '{$modification}');";
             Database_SQLite::exec($db, $query);
         } else {
             // Delete invalid / expired data.
             $this->deleteNotification($identifier, $db);
         }
     }
     unset($db);
 }
Exemple #9
0
 public function getChapters($name, $book)
 {
     $chapters = array();
     $folder = $this->bookFolder($name, $book);
     if (is_dir($folder)) {
         $chapters = scandir($folder);
     }
     $chapters = Filter_Folders::cleanup($chapters);
     sort($chapters, SORT_NUMERIC);
     return $chapters;
 }
Exemple #10
0
 public function files($name)
 {
     $files = array();
     $folder = $this->resourceFolder($name);
     if (is_dir($folder)) {
         $files = scandir($folder);
     }
     $files = Filter_Folders::cleanup($files);
     return $files;
 }
Exemple #11
0
    // The filename for the USFM for this book.
    $filename = Export_Logic::baseBookFileName($book);
    $path = "{$usfmDirectoryFull}/{$filename}.usfm";
    // Save.
    file_put_contents($path, $bookUsfmDataFull);
}
// Compress USFM files into one zip file.
$zipfile = "{$usfmDirectoryFull}/" . Export_Logic::baseBookFileName(0) . ".zip";
@unlink($zipfile);
$archive = Filter_Archive::zip($usfmDirectoryFull);
rename($archive, $zipfile);
if ($database_config_bible->getSecureUsfmExport($bible)) {
    // Securing the full USFM export means that there will be one zip file secured with a password.
    // This zip file contains all exported USFM data.
    // All other files will be removed.
    // It uses the external zip binary.
    // PHP 5.6 supports password protected archives: ZipArchive::setPassword ($password).
    $files = scandir($usfmDirectoryFull);
    $files = Filter_Folders::cleanup($files);
    $basefile = basename($zipfile);
    foreach ($files as $file) {
        if ($file != $basefile) {
            unlink("{$usfmDirectoryFull}/{$file}");
        }
    }
    $directory = escapeshellarg($usfmDirectoryFull);
    $password = escapeshellarg($database_config_bible->getExportPassword($bible));
    $command = "cd {$directory}; zip -P {$password} bible.zip {$basefile}; rm {$basefile}";
    Tasks_Logic::save($command);
}
$database_logs->log($bible . ": " . Locale_Translate::_("Exported to USFM"), Filter_Roles::TRANSLATOR_LEVEL);
Exemple #12
0
                     $database_logs->log($line);
                 }
             }
         }
         // Remove tasks from disk.
         $path = $task['path'];
         @unlink($path);
         // Destroy task.
         unset($actives[$offset]);
     }
 }
 // When the maximum number of simultaneously running tasks has not yet been reached, start another task, if available.
 if ($runningTasksCount < 10) {
     clearstatcache();
     $paths = scandir(dirname(__DIR__) . "/processes");
     $paths = Filter_Folders::cleanup($paths);
     // Get the full paths to the files on disk.
     foreach ($paths as $offset => $path) {
         $paths[$offset] = dirname(__DIR__) . "/processes/{$path}";
     }
     // Find the first task which is not yet active.
     $active_paths = array();
     foreach ($actives as $active) {
         $active_paths[] = $active['path'];
     }
     foreach ($paths as $path) {
         if (!in_array($path, $active_paths)) {
             // Get this process.
             $process = file_get_contents($path);
             $process = trim($process);
             // Log process output.