Example #1
0
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Database_Config_User();
     }
     return self::$instance;
 }
Example #2
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

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";
page_access_level(Filter_Roles::TRANSLATOR_LEVEL);
$database_config_user = Database_Config_User::getInstance();
$database_logs = Database_Logs::getInstance();
$database_bibles = Database_Bibles::getInstance();
$database_modifications = Database_Modifications::getInstance();
$session_logic = Session_Logic::getInstance();
$bible = $_POST['bible'];
$book = $_POST['book'];
$chapter = $_POST['chapter'];
$verse = $_POST['verse'];
$usfm = $_POST['usfm'];
$checksum = $_POST['checksum'];
// Check on information about where to save the verse.
$save = isset($bible) && isset($book) && isset($chapter) && isset($verse) && isset($usfm);
if (!$save) {
    echo Locale_Translate::_("Don't know where to save");
    die;
Example #3
0
 public static function deleteWorkbench($workbench)
 {
     $workbenches = Workbench_Logic::getWorkbenches();
     $database_config_user = Database_Config_User::getInstance();
     $urls = $database_config_user->getWorkbenchURLs();
     $urls = unserialize($urls);
     unset($urls[$workbench]);
     $urls = serialize($urls);
     $database_config_user->setWorkbenchURLs($urls);
     $widths = $database_config_user->getWorkbenchWidths();
     $widths = unserialize($widths);
     unset($widths[$workbench]);
     $widths = serialize($widths);
     $database_config_user->setWorkbenchWidths($widths);
     $heights = $database_config_user->getWorkbenchHeights();
     $heights = unserialize($heights);
     unset($heights[$workbench]);
     $heights = serialize($heights);
     $database_config_user->setWorkbenchHeights($heights);
     $database_config_user->setActiveWorkbench("");
     // For a client, store the setting for sending to the server.
     $database_config_user->addUpdatedSetting(Sync_Logic::WORKBENCH_SETTING);
 }
Example #4
0
 /**
  * handleEmailNew - handles an email received from $from with subject $subject and body $body.
  * Returns true if the mail was processed, else false.
  * The email is considered to have been processed if it created a new Consultation Note.
  */
 public function handleEmailNew($from, $subject, $body)
 {
     // Store the original subject.
     $originalSubject = $subject;
     // Check that the subject indicates that a new consultation note is to be created.
     $pos = strpos(strtolower($subject), "new note");
     if ($pos === false) {
         return false;
     }
     // There is a new note. Remove that bit from the $subject.
     $subject = substr($subject, 0, $pos) . substr($subject, $pos + 8);
     // Clean the subject line.
     $subject = trim($subject);
     $subject = str_replace(".", " ", $subject);
     $subject = str_replace(":", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     // Check that the $from address of the email belongs to an existing user.
     $from = Filter_Email::extractEmail($from);
     $database_users = Database_Users::getInstance();
     if (!$database_users->emailExists($from)) {
         return false;
     }
     $username = $database_users->getEmailToUser($from);
     // Extract book, chapter, verse, and note summary from the $subject
     $book = NULL;
     $chapter = NULL;
     $verse = NULL;
     $summary = NULL;
     $subject = explode(" ", $subject);
     if (count($subject) > 0) {
         $book = Filter_Books::interpretBook($subject[0]);
     }
     if (count($subject) > 1) {
         $chapter = Filter_Numeric::integer_in_string($subject[1]);
     }
     if (count($subject) > 2) {
         $verse = Filter_Numeric::integer_in_string($subject[2]);
     }
     unset($subject[0]);
     unset($subject[1]);
     unset($subject[2]);
     $summary = implode(" ", $subject);
     unset($subject);
     // Check book, chapter, verse, and summary. Give feedback if there's anything wrong.
     $noteCheck = "";
     if (!(is_numeric($book) && $book > 0)) {
         $noteCheck .= Locale_Translate::_("Unknown book");
     }
     if (!is_numeric($chapter)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown chapter");
     }
     if (!is_numeric($verse)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown verse");
     }
     if ($summary == NULL || $summary == "") {
         $noteCheck .= " " . Locale_Translate::_("Unknown summary");
     }
     // Mail user if the note could not be posted.
     $database_mail = Database_Mail::getInstance();
     if ($noteCheck != "") {
         $subject = Locale_Translate::_("Your new note could not be posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $noteCheck);
         return false;
     }
     // Clean the email's body.
     $body = Filter_Email::extractBody($body);
     // Post the note.
     $session_logic = Session_Logic::getInstance();
     $sessionuser = $session_logic->currentUser();
     $session_logic->setUsername($username);
     $database_notes = Database_Notes::getInstance();
     $identifier = $database_notes->storeNewNote("", $book, $chapter, $verse, $summary, $body, false);
     $this->handlerNewNote($identifier);
     $session_logic->setUsername($sessionuser);
     // Mail confirmation to the $username.
     $database_config_user = Database_Config_User::getInstance();
     if ($database_config_user->getUserNotifyMeOfMyPosts($username)) {
         $subject = Locale_Translate::_("Your new note was posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $body);
     }
     // Log operation.
     $database_logs = Database_Logs::getInstance();
     $database_logs->log("New note posted" . ":" . " " . $body);
     // Job done.
     return true;
 }
Example #5
0
 public static function workbench_checksum()
 {
     $database_config_user = Database_Config_User::getInstance();
     $urls = $database_config_user->getWorkbenchURLs();
     $widths = $database_config_user->getWorkbenchWidths();
     $heights = $database_config_user->getWorkbenchHeights();
     $checksum = md5($urls . $widths . $heights);
     return $checksum;
 }
Example #6
0
 public function run()
 {
     $this->view->view->include_jquery_ui = $this->includeJQueryUI;
     $this->view->view->include_jquery_ui_subset = $this->JQueryUISubset;
     $this->view->view->head_lines = $this->headLines;
     $this->view->view->display_topbar = $this->displayTopbar();
     if ($this->view->view->display_topbar) {
         $menu_main = new Menu_Main();
         $this->view->view->mainmenu = $menu_main->create();
         $menu_user = new Menu_User();
         $this->view->view->usermenu = $menu_user->create();
     }
     $this->view->view->display_navigator = $this->displayNavigator;
     if ($this->view->view->display_navigator) {
         $database_config_user = Database_Config_User::getInstance();
         $bible = Access_Bible::clamp($database_config_user->getBible());
         $this->view->view->navigationHtml = Navigation_Passage::getContainer();
         $this->view->view->navigationCode = Navigation_Passage::code($bible, true);
     }
     $this->view->view->included_stylesheet = $this->includedStylesheet;
     $this->view->view->included_editor_stylesheet = $this->includedEditorStylesheet;
     $this->view->render("xhtml_start.php");
     $this->view->render("header.php");
 }
Example #7
0
function enable_client($username, $password, $level)
{
    // Enable client mode upon a successful connection.
    Filter_Client::set(true);
    // Remove all users from the database, and add the current one.
    remove_all_users();
    $database_users = Database_Users::getInstance();
    $database_users->addNewUser($username, $password, $level, "");
    // Clear all pending note actions and Bible actions and settings updates.
    $database_noteactions = Database_NoteActions::getInstance();
    $database_bibleactions = Database_BibleActions::getInstance();
    $database_config_user = Database_Config_User::getInstance();
    $session_logic = Session_Logic::getInstance();
    $database_noteactions->clear();
    $database_noteactions->create();
    $database_bibleactions->clear();
    $database_bibleactions->create();
    $session_logic->setUsername($username);
    $database_config_user->setUpdatedSettings(array());
    // Set it repeats sync every so often.
    $database_config_general = Database_Config_General::getInstance();
    $database_config_general->setRepeatSendReceive(2);
    // Schedule a sync operation straight-away.
    SendReceive_Logic::queuesync(true);
}
Example #8
0
 public function response()
 {
     // The databases to access.
     $database_config_user = Database_Config_User::getInstance();
     $database_volatile = Database_Volatile::getInstance();
     $database_bibles = Database_Bibles::getInstance();
     // The resources to display in the Consistency tool.
     $resources = array();
     $resources[] = Access_Bible::clamp($database_config_user->getBible());
     $resources = array_merge($resources, $database_config_user->getConsistencyResources());
     // The passages entered in the Consistency tool.
     $passages = $database_volatile->getValue($this->id, "passages");
     $passages = trim($passages);
     $passages = Filter_String::string2array($passages);
     // The translations from the Consistency tool.
     $translations = $database_volatile->getValue($this->id, "translations");
     $translations = trim($translations);
     $translations = Filter_String::string2array($translations);
     // Contains the response to display.
     $response = array();
     // Go through the passages interpreting them.
     $previousPassage = array(1, 1, 1);
     foreach ($passages as $line) {
         $line = trim($line);
         if ($line == "") {
             continue;
         }
         $range_sequence = Filter_Books::handleSequencesRanges($line);
         foreach ($range_sequence as $line) {
             $passage = Filter_Books::interpretPassage($previousPassage, $line);
             if ($passage[0] != 0) {
                 $book = $passage[0];
                 $chapter = $passage[1];
                 $verse = $passage[2];
                 $line = Filter_Books::linkForOpeningEditorAt($book, $chapter, $verse);
                 $line .= " ";
                 // Check whether the chapter identifier has changed for this reference.
                 // If so, set a flag so the data can be re-assembled for this verse.
                 // If there was no change, then the data can be fetched from the volatile database.
                 $redoPassage = false;
                 $passageKey = "{$book}.{$chapter}.{$verse}";
                 $currentChapterId = $database_bibles->getChapterId($resources[0], $book, $chapter);
                 $storedChapterId = $database_volatile->getValue($this->id, "{$passageKey}.id");
                 if ($currentChapterId != $storedChapterId) {
                     $database_volatile->setValue($this->id, "{$passageKey}.id", $currentChapterId);
                     $redoPassage = true;
                 }
                 // Go through each resource.
                 foreach ($resources as $resource) {
                     // Produce new verse text if the passage is to be redone, or else fetch the existing text.
                     if ($redoPassage) {
                         $text = $this->verseText($resource, $book, $chapter, $verse);
                         if ($translations != "") {
                             $text = Filter_Markup::words($translations, $text);
                         }
                         $database_volatile->setValue($this->id, "{$passageKey}.{$resource}", $text);
                     } else {
                         $text = $database_volatile->getValue($this->id, "{$passageKey}.{$resource}");
                     }
                     // Formatting.
                     if (count($resources) > 1) {
                         $line .= "<br>";
                     }
                     $line .= $text;
                 }
                 $response[] = $line;
                 $previousPassage = $passage;
             } else {
                 $response[] = '<span class="error">' . Locale_Translate::_("Unknown passage") . " " . $line . '</span>';
             }
         }
     }
     $output = "";
     foreach ($response as $line) {
         $output .= "<div>{$line}</div>\n";
     }
     return $output;
 }
Example #9
0
function processIdentifiers($user, $bible, $book, $chapter, $oldId, $newId, &$email)
{
    if ($oldId != 0) {
        $database_modifications = Database_Modifications::getInstance();
        $database_config_user = Database_Config_User::getInstance();
        $database_config_bible = Database_Config_Bible::getInstance();
        $database_bibles = Database_Bibles::getInstance();
        $database_history = Database_History::getInstance();
        $stylesheet = $database_config_bible->getExportStylesheet($bible);
        $old_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $oldId);
        $old_chapter_usfm = $old_chapter_usfm['oldtext'];
        $new_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $newId);
        $new_chapter_usfm = $new_chapter_usfm['newtext'];
        $timestamp = $database_modifications->getUserTimestamp($user, $bible, $book, $chapter, $newId);
        $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm);
        $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm);
        $verses = array_merge($old_verse_numbers, $new_verse_numbers);
        $verses = array_unique($verses);
        sort($verses, SORT_NUMERIC);
        foreach ($verses as $verse) {
            $old_verse_usfm = Filter_Usfm::getVerseText($old_chapter_usfm, $verse);
            $new_verse_usfm = Filter_Usfm::getVerseText($new_chapter_usfm, $verse);
            if ($old_verse_usfm != $new_verse_usfm) {
                $filter_text_old = new Filter_Text($bible);
                $filter_text_new = new Filter_Text($bible);
                $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
                $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
                $filter_text_old->text_text = new Text_Text();
                $filter_text_new->text_text = new Text_Text();
                $filter_text_old->addUsfmCode($old_verse_usfm);
                $filter_text_new->addUsfmCode($new_verse_usfm);
                $filter_text_old->run($stylesheet);
                $filter_text_new->run($stylesheet);
                $old_html = $filter_text_old->html_text_standard->getInnerHtml();
                $new_html = $filter_text_new->html_text_standard->getInnerHtml();
                $old_text = $filter_text_old->text_text->get();
                $new_text = $filter_text_new->text_text->get();
                if ($old_text != $new_text) {
                    $modification = Filter_Diff::diff($old_text, $new_text);
                    $email .= "<div>";
                    $email .= Filter_Books::passageDisplay($book, $chapter, $verse);
                    $email .= " ";
                    $email .= $modification;
                    $email .= "</div>";
                    if ($database_config_user->getUserUserChangesNotificationsOnline($user)) {
                        $changeNotificationUsers = array($user);
                        $database_modifications->recordNotification($changeNotificationUsers, "☺", $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
                    }
                    $database_history->record($timestamp, $user, $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
                }
            }
        }
    }
}
Example #10
0
 public static function getAction($style)
 {
     $database_config_user = Database_Config_User::getInstance();
     $database_styles = Database_Styles::getInstance();
     $styles_logic = Styles_Logic::getInstance();
     $stylesheet = $database_config_user->getStylesheet();
     $data = $database_styles->getMarkerData($stylesheet, $style);
     @($type = $data["type"]);
     @($subtype = $data["subtype"]);
     switch ($type) {
         case StyleTypeIdentifier:
         case StyleTypeNotUsedComment:
         case StyleTypeNotUsedRunningHeader:
             return self::mono();
         case StyleTypeStartsParagraph:
             return self::paragraph();
         case StyleTypeInlineText:
             return self::character();
         case StyleTypeChapterNumber:
             return self::paragraph();
         case StyleTypeVerseNumber:
             return self::character();
         case StyleTypeFootEndNote:
             switch ($subtype) {
                 case FootEndNoteSubtypeFootnote:
                 case FootEndNoteSubtypeEndnote:
                     return self::note();
                 case FootEndNoteSubtypeContent:
                 case FootEndNoteSubtypeContentWithEndmarker:
                     return self::character();
                 case FootEndNoteSubtypeStandardContent:
                 case FootEndNoteSubtypeParagraph:
                     return self::paragraph();
                 default:
                     return self::unknown();
             }
             break;
         case StyleTypeCrossreference:
             switch ($subtype) {
                 case CrossreferenceSubtypeCrossreference:
                     return self::note();
                 case CrossreferenceSubtypeContent:
                 case CrossreferenceSubtypeContentWithEndmarker:
                     return self::character();
                 case CrossreferenceSubtypeStandardContent:
                     return self::paragraph();
                 default:
                     return self::unknown();
             }
             break;
         case StyleTypePeripheral:
             return self::mono();
         case StyleTypePicture:
             return self::mono();
         case StyleTypePageBreak:
             return self::unknown();
         case StyleTypeTableElement:
             switch ($subtype) {
                 case TableElementSubtypeRow:
                 case TableElementSubtypeHeading:
                 case TableElementSubtypeCell:
                 default:
                     return self::mono();
             }
             break;
         case StyleTypeWordlistElement:
             return self::character();
         default:
             return self::unknown();
     }
 }
Example #11
0
$database->optimize();
$database = Database_Ipc::getInstance();
$database->trim();
$database = Database_Notes::getInstance();
$database->trim();
if (!$client_mode) {
    $database->trim_server();
}
$database->optimize();
$database = Database_Shell::getInstance();
$database->trim();
$database->optimize();
$database = Database_Check::getInstance();
$database->optimize();
unlink("../databases/volatile.sqlite");
$database = Database_Volatile::getInstance();
$database->create();
$database = Database_Sprint::getInstance();
$database->optimize();
unlink("../databases/navigation.sqlite");
$database = Database_Navigation::getInstance();
$database->create();
$database = Database_History::getInstance();
$database->optimize();
$database = Database_Commits::getInstance();
$database->optimize();
$database = Database_Jobs::getInstance();
$database->trim();
$database->optimize();
$database = Database_Config_User::getInstance();
$database->trim();
Example #12
0
 function getVerse()
 {
     $database_config_user = Database_Config_User::getInstance();
     $verse = $database_config_user->getFocusedVerse();
     return $verse;
 }
Example #13
0
 public static function clamp($bible)
 {
     if (!self::read($bible)) {
         $bible = "";
         $bibles = self::bibles();
         if (count($bibles)) {
             $bible = $bibles[0];
         }
         $database_config_user = Database_Config_User::getInstance();
         $database_config_user->setBible($bible);
     }
     return $bible;
 }
Example #14
0
 public function testSubscriptions()
 {
     $database_notes = Database_Notes::getInstance();
     $session_logic = Session_Logic::getInstance();
     // Normally creating a new note would subscribe the current user to the note.
     // But since this PHPUnit test runs without sessions, it would have subscribed an empty user.
     $session_logic->setUsername("");
     $identifier = $database_notes->storeNewNote("", 0, 0, 0, "Summary", "Contents", false);
     $this->identifiers[] = $identifier;
     $subscribers = $database_notes->getSubscribers($identifier);
     $this->assertEquals(array(), $subscribers);
     // Create a note again, but this time set the session variable to a certain user.
     $session_logic->setUsername("phpunit");
     $database_config_user = Database_Config_User::getInstance();
     $database_config_user->setSubscribeToConsultationNotesEditedByMe(true);
     $identifier = $database_notes->storeNewNote("", 1, 1, 1, "Summary", "Contents", false);
     $this->identifiers[] = $identifier;
     $notes_logic = Notes_Logic::getInstance();
     $notes_logic->handlerNewNote($identifier);
     $subscribers = $database_notes->getSubscribers($identifier);
     $this->assertEquals(array("phpunit"), $subscribers);
     $this->assertTrue($database_notes->isSubscribed($identifier, "phpunit"));
     $database_config_user->setSubscribeToConsultationNotesEditedByMe(false);
     // Test various other subscription related functions.
     $this->assertFalse($database_notes->isSubscribed($identifier, "phpunit_phpunit"));
     $database_notes->unsubscribe($identifier);
     $this->assertFalse($database_notes->isSubscribed($identifier, "phpunit"));
     $database_notes->subscribeUser($identifier, "phpunit_phpunit_phpunit");
     $this->assertTrue($database_notes->isSubscribed($identifier, "phpunit_phpunit_phpunit"));
     $database_notes->unsubscribeUser($identifier, "phpunit_phpunit_phpunit");
     $this->assertFalse($database_notes->isSubscribed($identifier, "phpunit_phpunit_phpunit"));
 }
Example #15
0
 public function testTrim()
 {
     $database_config_user = Database_Config_User::getInstance();
     $database_config_user->trim();
 }
Example #16
0
 public static function getText($resource, $book, $chapter, $verse)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_resources = Database_Resources::getInstance();
     $database_usfmresources = Database_UsfmResources::getInstance();
     $database_offlineresources = Database_OfflineResources::getInstance();
     $bibles = $database_bibles->getBibles();
     $usfms = $database_usfmresources->getResources();
     $externals = $database_resources->getNames();
     $isBible = in_array($resource, $bibles);
     $isUsfm = in_array($resource, $usfms);
     if ($isBible || $isUsfm) {
         if ($isBible) {
             $chapter_usfm = $database_bibles->getChapter($resource, $book, $chapter);
         }
         if ($isUsfm) {
             $chapter_usfm = $database_usfmresources->getUsfm($resource, $book, $chapter);
         }
         $verse_usfm = Filter_Usfm::getVerseText($chapter_usfm, $verse);
         $database_config_user = Database_Config_User::getInstance();
         $stylesheet = $database_config_user->getStylesheet();
         $filter_text = new Filter_Text($resource);
         $filter_text->text_text = new Text_Text();
         $filter_text->addUsfmCode($verse_usfm);
         $filter_text->run($stylesheet);
         $text = $filter_text->text_text->get();
     } else {
         if (in_array($resource, $externals)) {
             // Use offline copy if it exists, else fetch it online.
             if ($database_offlineresources->exists($resource, $book, $chapter, $verse)) {
                 $text = $database_offlineresources->get($resource, $book, $chapter, $verse);
             } else {
                 $text = Resource_Logic::getExternal($resource, $book, $chapter, $verse, true);
             }
             $text = Filter_Html::html2text($text);
         } else {
             $text = "";
         }
     }
     return $text;
 }