Ejemplo n.º 1
0
 /**
  * Function resultsTextLimit()
  *
  * This function is used to find keywords in search result content
  *
  * @param data $data The resulted to be added applied
  * @param searchCriteria $searchCriteria The criteria of selecting terms
  * @param style $style The style to be applied
  * @param limitText $limitText Limitation of word length
  * @param start $start The starting characters
  * @param end $end The ending characters
  * @since 3.5.0
  * @access public
  */
 public static function resultsTextLimit($data, $searchCriteria, $style, $limitText = "150", $start = "...", $end = "...")
 {
     $data = strip_tags($data);
     $dataLength = mb_strlen($data);
     if (!is_array($searchCriteria)) {
         $searchCriteria = explode(" ", trim($searchCriteria));
         //create an array of keywords if it does not exists
     }
     foreach ($searchCriteria as $key => $value) {
         $value = mb_strtolower($value);
         if (mb_strpos(mb_strtolower($data), $value) !== false) {
             $positions[] = mb_strpos(mb_strtolower($data), $value);
         }
     }
     $head = 0;
     $foot = $dataLength;
     $startC = $endC = null;
     if (sizeof($positions) > 0) {
         if ($positions[0] > floor($limitText / 2)) {
             $head = $positions[0] - floor($limitText / 2);
             $startC = $start;
         }
         if ($positions['0'] + floor($limitText / 2) < $dataLength) {
             $foot = $positions[0] + floor($limitText / 2);
             $endC = $end;
         }
         return $startC . EfrontSearch::highlightText(mb_substr($data, $head, $foot - $head), $searchCriteria, $style) . $endC;
     } else {
         return EfrontSearch::highlightText(mb_substr($data, 0, $limitText), $searchCriteria, $style) . $end;
     }
 }
Ejemplo n.º 2
0
             if ($lesson[0]['id'] != "") {
                 $lessonTemp = new EfrontLesson($lesson[0]['id']);
             } else {
                 $lesson[0]['id'] = 0;
             }
             $forumTitle = eF_getTableData("f_forums", "title", "id=" . $res1[0]['category_id']);
             if ($_SESSION['s_type'] != "student" || $lessonTemp->options['forum'] != 0 || $lesson[0]['id'] == 0) {
                 $f_messageBody = EfrontSearch::resultsTextLimit($res1[0]['body'], $cr, 'resultsText');
                 $search_results_forum[] = array('category_id' => $res1[0]['category_id'], 'lesson_name' => $forumTitle[0]['title'], 'topic_subject' => $res1[0]['topic_title'], 'topic_id' => $res1[0]['f_topics_ID'], 'message_subject' => $res1[0]['title'], 'body' => $f_messageBody, 'message_id' => $res1[0]['id'], 'table_name' => $results[$i]['table_name'], 'position' => $position_str);
             }
             //pr($search_results_forum);
         }
     }
 } elseif ($results[$i]['table_name'] == 'f_personal_messages' && $_SESSION['s_login'] == $res1[0]['users_LOGIN']) {
     if (!isset($GLOBALS['currentUser']->coreAccess['personal_messages']) || $GLOBALS['currentUser']->coreAccess['personal_messages'] != 'hidden') {
         $search_results_pmsgs[] = array('message_subject' => EfrontSearch::highlightText($res1[0]['title'], $cr, 'resultsTitleBold'), 'message_id' => $res1[0]['id'], 'folder_name' => $res1[0]['name'], 'folder_id' => $res1[0]['folder_id'], 'body' => EfrontSearch::highlightText($res1[0]['body'], $cr, 'resultsTitleBold'), 'recipient' => $res1[0]['recipient'], 'sender' => $res1[0]['sender'], 'position' => $position_str);
     }
 } elseif ($results[$i]['table_name'] == 'files') {
     $pos1 = strpos($res1[0]['path'], '/content/lessons/');
     //echo $pos1;
     if ($pos1 !== false) {
         $pos2 = strpos($res1[0]['path'], '/', $pos1 + mb_strlen('/content/lessons/'));
         //echo $pos2;
         $lessonID = mb_substr($res1[0]['path'], $pos1 + mb_strlen('/content/lessons/'), $pos2 - $pos1 - mb_strlen('/content/lessons/'));
         //echo $lessonID;
     } else {
         $lessonID = 0;
     }
     try {
         $file = new EfrontFile($res1[0]['id']);
         $fileIcon = $file->getTypeImage();