function getSearchableAnswer()
 {
     return ThreadBody::fromFormattedText($this->ht['answer'], 'html')->getSearchable();
 }
Esempio n. 2
0
 /**
  * Cooperates with the cron system to automatically find content that is
  * not index in the _search table and add it to the index.
  */
 function IndexOldStuff()
 {
     $class = get_class();
     $auto_create = function ($db_error) use($class) {
         if ($db_error != 1146) {
             // Perform the standard error handling
             return true;
         }
         // Create the search table automatically
         $class::__init();
     };
     // THREADS ----------------------------------
     $sql = "SELECT A1.`id`, A1.`title`, A1.`body`, A1.`format` FROM `" . TICKET_THREAD_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='H')\n            WHERE A2.`object_id` IS NULL AND (A1.poster <> 'SYSTEM')\n            AND (LENGTH(A1.`title`) + LENGTH(A1.`body`) > 0)\n            ORDER BY A1.`id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $body = ThreadBody::fromFormattedText($row[2], $row[3]);
         $body = $body->getSearchable();
         $title = Format::searchable($row[1]);
         if (!$body && !$title) {
             continue;
         }
         $record = array('H', $row[0], $title, $body);
         if (!$this->__index($record)) {
             return;
         }
     }
     // TICKETS ----------------------------------
     $sql = "SELECT A1.`ticket_id` FROM `" . TICKET_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`ticket_id` = A2.`object_id` AND A2.`object_type`='T')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`ticket_id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $ticket = Ticket::lookup($row[0]);
         $cdata = $ticket->loadDynamicData();
         $content = array();
         foreach ($cdata as $k => $a) {
             if ($k != 'subject' && ($v = $a->getSearchable())) {
                 $content[] = $v;
             }
         }
         $record = array('T', $ticket->getId(), Format::searchable($ticket->getNumber() . ' ' . $ticket->getSubject()), implode("\n", $content));
         if (!$this->__index($record)) {
             return;
         }
     }
     // USERS ------------------------------------
     $sql = "SELECT A1.`id` FROM `" . USER_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='U')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $user = User::lookup($row[0]);
         $cdata = $user->getDynamicData();
         $content = array();
         foreach ($user->emails as $e) {
             $content[] = $e->address;
         }
         foreach ($cdata as $e) {
             foreach ($e->getAnswers() as $a) {
                 if ($c = $a->getSearchable()) {
                     $content[] = $c;
                 }
             }
         }
         $record = array('U', $user->getId(), Format::searchable($user->getFullName()), trim(implode("\n", $content)));
         if (!$this->__index($record)) {
             return;
         }
     }
     // ORGANIZATIONS ----------------------------
     $sql = "SELECT A1.`id` FROM `" . ORGANIZATION_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='O')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $org = Organization::lookup($row[0]);
         $cdata = $org->getDynamicData();
         $content = array();
         foreach ($cdata as $e) {
             foreach ($e->getAnswers() as $a) {
                 if ($c = $a->getSearchable()) {
                     $content[] = $c;
                 }
             }
         }
         $record = array('O', $org->getId(), Format::searchable($org->getName()), trim(implode("\n", $content)));
         if (!$this->__index($record)) {
             return null;
         }
     }
     // KNOWLEDGEBASE ----------------------------
     require_once INCLUDE_DIR . 'class.faq.php';
     $sql = "SELECT A1.`faq_id` FROM `" . FAQ_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`faq_id` = A2.`object_id` AND A2.`object_type`='K')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`faq_id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $faq = FAQ::lookup($row[0]);
         $q = $faq->getQuestion();
         if ($k = $faq->getKeywords()) {
             $q = $k . ' ' . $q;
         }
         $record = array('K', $faq->getId(), Format::searchable($q), $faq->getSearchableAnswer());
         if (!$this->__index($record)) {
             return;
         }
     }
     // FILES ------------------------------------
     // Flush non-full batch of records
     $this->__index(null, true);
     if (!$this->_reindexed) {
         // Stop rebuilding the index
         $this->getConfig()->set('reindex', 0);
     }
 }
Esempio n. 3
0
 function postReply($vars, &$errors, $alert = true, $claim = true)
 {
     global $thisstaff, $cfg;
     if (!$vars['poster'] && $thisstaff) {
         $vars['poster'] = $thisstaff;
     }
     if (!$vars['staffId'] && $thisstaff) {
         $vars['staffId'] = $thisstaff->getId();
     }
     if (!$vars['ip_address'] && $_SERVER['REMOTE_ADDR']) {
         $vars['ip_address'] = $_SERVER['REMOTE_ADDR'];
     }
     $attachments = array();
     $response = null;
     if ($vars['emailreply'] == 2 || $vars['emailreply'] == 1) {
         $responseBody = null;
         $finalBody = null;
         $threadIdList = array();
         if (isset($vars['thread_list'])) {
             $threadIdList = explode(",", $vars['thread_list']);
         }
         // $this->logErrors($vars['thread_list']);
         // $this->logErrors(json_encode($threadIdList));
         // if(!($clientThreadEntries = $this->getClientThread()))
         //     return null;
         // foreach ($clientThreadEntries as $clientThreadEntry) {
         //     if(!($response = ThreadEntry::lookup($clientThreadEntry['id'])))
         //         return null;
         if ($response = $this->getThread()->addResponse($vars, $errors)) {
             // $responseBody = $responseBody ."<br>--------------Reply from ".$response->getPoster()."--------------<br>";
             $responseBody = $responseBody . $response->ht['body'];
             if (isset($thisstaff) && $thisstaff->getSignature() && $vars['emailreply'] == 2 && sizeof($threadIdList) > 1) {
                 $responseBody = $responseBody . $thisstaff->getSignature();
             }
             // if($vars['emailreply']==1)
             $finalThreadBody = $response->ht['body'];
             $attachments = array_merge($attachments, $response->getAttachments());
         }
         foreach ($threadIdList as $threadId) {
             if ($threadId != "") {
                 $response = ThreadEntry::lookup(intval($threadId));
                 // return null;
                 if ($response->getType() == 'M') {
                     $responseBody = $responseBody . "<br>--------------Message from " . $response->getPoster() . "--------------<br>";
                     if ($response->getUserId() != 0) {
                         if ($user = $response->getUser()) {
                             $responseBody = $responseBody . "<b>Name:</b> " . $user->getFullName() . "<br>";
                             $responseBody = $responseBody . "<b>Email:</b> " . $user->getEmail() . "<br>";
                             if ($user->getPhoneNumber() != "") {
                                 $responseBody = $responseBody . "<b>Phone number:</b> " . $user->getPhoneNumber() . "<br>";
                             }
                         }
                     }
                 } else {
                     $responseBody = $responseBody . "<br>--------------Reply from " . $response->getPoster() . "--------------<br>";
                     if ($response->getStaffId() != 0) {
                         if ($currentThreadStaff = $response->getStaff()) {
                             $responseBody = $responseBody . "<b>Name:</b> " . $currentThreadStaff->getName() . "<br>";
                             $responseBody = $responseBody . "<b>Email:</b> " . $currentThreadStaff->getEmail() . "<br>";
                             // if($currentThreadStaff->getPhoneNumber() != "")
                             //     $responseBody = $responseBody ."<b>Phone number:</b> ".$currentThreadStaff->getPhoneNumber()."<br>";
                         }
                     }
                 }
                 $responseBody = $responseBody . $response->ht['body'];
                 $responseBody = $responseBody . "<br><br>";
                 $finalThreadBody = $response->ht['body'];
                 $attachments = array_merge($attachments, $response->getAttachments());
             }
         }
         $response->setBody(ThreadBody::fromFormattedText($responseBody, $response->ht['format']));
         $response->reload();
         if (!$this->postReplyFromThread($vars, $errors, $alert = true, $claim = true, $response, $attachments)) {
             return null;
         }
         $response->setBody(ThreadBody::fromFormattedText($finalThreadBody, $response->ht['format']));
         $response->reload();
     } else {
         if (!($response = $this->getThread()->addResponse($vars, $errors))) {
             return null;
         }
         if (!$this->postReplyFromThread($vars, $errors, $alert = true, $claim = true, $response, $attachments)) {
             return null;
         }
     }
     return $response;
 }
 function __construct($body, $options = array())
 {
     if (!isset($options['strip-embedded']) || $options['strip-embedded']) {
         $body = $this->extractEmbeddedHtmlImages($body);
     }
     parent::__construct($body, 'html', $options);
 }
Esempio n. 5
0
 function __construct($body, $options = array())
 {
     parent::__construct($body, 'html', $options);
     if ($this->options['strip-embedded']) {
         $this->body = $this->extractEmbeddedHtmlImages($this->body);
     }
 }