/** * Add a line to the ical string * @return * @param object $a_line */ public function addLine($a_line) { //$chunks = str_split($a_line, self::LINE_SIZE); include_once './Services/Utilities/classes/class.ilStr.php'; // use multibyte split $chunks = array(); $len = ilStr::strLen($a_line); while ($len) { $chunks[] = ilStr::subStr($a_line, 0, self::LINE_SIZE); $a_line = ilStr::subStr($a_line, self::LINE_SIZE, $len); $len = ilStr::strLen($a_line); } for ($i = 0; $i < count($chunks); $i++) { $this->ical .= $chunks[$i]; if (isset($chunks[$i + 1])) { $this->ical .= self::LINEBREAK; $this->ical .= self::BEGIN_LINE_WHITESPACE; } } $this->ical .= self::LINEBREAK; }
/** * Retrieves the full path to a question pool with a given reference id * * @return string The full path to the question pool including the locator * @access public */ function _getFullPathToQpl($ref_id) { global $tree; $path = $tree->getPathFull($ref_id); $items = array(); $counter = 0; foreach ($path as $item) { if ($counter > 0 && $counter < count($path) - 1) { array_push($items, $item["title"]); } $counter++; } $fullpath = join(" > ", $items); include_once "./Services/Utilities/classes/class.ilStr.php"; if (strlen($fullpath) > 60) { $fullpath = ilStr::subStr($fullpath, 0, 30) . "..." . ilStr::subStr($fullpath, ilStr::strLen($fullpath) - 30, 30); } return $fullpath; }
/** * Saves the learners input of the question to the database. * * @access public * @param integer $active_id Active id of the user * @param integer $pass Test pass * @return boolean $status */ public function saveWorkingData($active_id, $pass = NULL) { global $ilDB; global $ilUser; include_once "./Services/Utilities/classes/class.ilStr.php"; if (is_null($pass)) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $pass = ilObjTest::_getPass($active_id); } $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s", array('integer', 'integer', 'integer'), array($active_id, $this->getId(), $pass)); $text = ilUtil::stripSlashes($_POST["TEXT"], FALSE); if ($this->getMaxNumOfChars()) { include_once "./Services/Utilities/classes/class.ilStr.php"; $text_without_tags = preg_replace("/<[^>*?]>/is", "", $text); $len_with_tags = ilStr::strLen($text); $len_without_tags = ilStr::strLen($text_without_tags); if ($this->getMaxNumOfChars() < $len_without_tags) { if (!$this->isHTML($text)) { $text = ilStr::subStr($text, 0, $this->getMaxNumOfChars()); } } } if ($this->isHTML($text)) { $text = preg_replace("/<[^>]*\$/ims", "", $text); } else { //$text = htmlentities($text, ENT_QUOTES, "UTF-8"); } $entered_values = 0; if (strlen($text)) { $next_id = $ilDB->nextId('tst_solutions'); $affectedRows = $ilDB->insert("tst_solutions", array("solution_id" => array("integer", $next_id), "active_fi" => array("integer", $active_id), "question_fi" => array("integer", $this->getId()), "value1" => array("clob", trim($text)), "value2" => array("clob", null), "pass" => array("integer", $pass), "tstamp" => array("integer", time()))); $entered_values++; } if ($entered_values) { include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php"; if (ilObjAssessmentFolder::_enabledAssessmentLogging()) { $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId()); } } else { include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php"; if (ilObjAssessmentFolder::_enabledAssessmentLogging()) { $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId()); } } return true; }
/** * Prepare message for container view * @static * @param string $text * @return string */ public static function prepareMessageForLists($text) { include_once 'Services/Utilities/classes/class.ilStr.php'; $text = strip_tags($text); $text = preg_replace('/\\[(\\/)?quote\\]/', '', $text); if (ilStr::strLen($text) > 40) { $text = ilStr::subStr($text, 0, 37) . '...'; } return $text; }
/** * Ensure that the maximum word lenght within a text is not longer * than $a_len * * @param string input string * @param integer max. word length * @param boolean append "..." to shortened words * @static * */ public static function shortenWords($a_str, $a_len = 30, $a_dots = true) { include_once "./Services/Utilities/classes/class.ilStr.php"; $str_arr = explode(" ", $a_str); for ($i = 0; $i < count($str_arr); $i++) { if (ilStr::strLen($str_arr[$i]) > $a_len) { $str_arr[$i] = ilStr::subStr($str_arr[$i], 0, $a_len); if ($a_dots) { $str_arr[$i] .= "..."; } } } return implode($str_arr, " "); }
/** * Allows to add additional form fields to the certificate editor form * This method will be called when the certificate editor form will built * using the ilPropertyFormGUI class. Additional fields will be added at the * bottom of the form. * * @param object $form An ilPropertyFormGUI instance * @param array $form_fields An array containing the form values. The array keys are the names of the form fields */ public function addAdditionalFormElements(&$form, $form_fields) { global $lng; $short_name = new ilTextInputGUI($lng->txt("certificate_short_name"), "short_name"); $short_name->setRequired(TRUE); require_once "./Services/Utilities/classes/class.ilStr.php"; $short_name->setValue(strlen($form_fields["short_name"]) ? $form_fields["short_name"] : ilStr::subStr($this->object->getTitle(), 0, 30)); $short_name->setSize(30); if (strlen($form_fields["short_name"])) { $short_name->setInfo(str_replace("[SHORT_TITLE]", $form_fields["short_name"], $lng->txt("certificate_short_name_description"))); } else { $short_name->setInfo($lng->txt("certificate_short_name_description")); } if (count($_POST)) { $short_name->checkInput(); } $form->addItem($short_name); $visibility = new ilCheckboxInputGUI($lng->txt("certificate_enabled_scorm"), "certificate_enabled_scorm"); $visibility->setInfo($lng->txt("certificate_enabled_scorm_introduction")); $visibility->setValue(1); if ($form_fields["certificate_enabled_scorm"]) { $visibility->setChecked(TRUE); } if (count($_POST)) { $visibility->checkInput(); } $form->addItem($visibility); }
/** * Reads out the source file and writes all entries to the database * * @return void */ public function writeSourcefileEntriesToDb() { //Read File $entries_from_file = array(); switch ($this->getFiletype()) { case "ris": $entries_from_file = self::__readRisFile($this->getFileAbsolutePath()); break; case "bib": $entries_from_file = self::__readBibFile($this->getFileAbsolutePath()); break; } //fill each entry into a ilBibliographicEntry object and then write it to DB by executing doCreate() foreach ($entries_from_file as $file_entry) { $type = NULL; $x = 0; $parsed_entry = array(); foreach ($file_entry as $key => $attribute) { // if the attribute is an array, make a comma separated string out of it if (is_array($attribute)) { $attribute = implode(", ", $attribute); } // reduce the attribute strings to a maximum of 4000 (ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) characters, in order to fit in the database //if (mb_strlen($attribute, 'UTF-8') > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) { if (ilStr::strLen($attribute) > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) { // $attribute = mb_substr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3, 'UTF-8') . '...'; $attribute = ilStr::subStr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3) . '...'; } // ty (RIS) or entryType (BIB) is the type and is treated seperately if (strtolower($key) == 'ty' || strtolower($key) == 'entrytype') { $type = $attribute; continue; } //TODO - Refactoring for ILIAS 4.5 - get rid off array restructuring //change array structure (name not as the key, but under the key "name") $parsed_entry[$x]['name'] = $key; $parsed_entry[$x++]['value'] = $attribute; } //create the entry and fill data into database by executing doCreate() $entry_model = ilBibliographicEntry::getInstance($this->getFiletype()); $entry_model->setType($type); $entry_model->setAttributes($parsed_entry); $entry_model->setBibliographicObjId($this->getId()); $entry_model->doCreate(); } }
/** * @return mixed|string */ public function getSolutionSubmit() { $text = ilUtil::stripSlashes($_POST["TEXT"], FALSE); if ($this->getMaxNumOfChars()) { include_once "./Services/Utilities/classes/class.ilStr.php"; $text_without_tags = preg_replace("/<[^>*?]>/is", "", $text); $len_with_tags = ilStr::strLen($text); $len_without_tags = ilStr::strLen($text_without_tags); if ($this->getMaxNumOfChars() < $len_without_tags) { if (!$this->isHTML($text)) { $text = ilStr::subStr($text, 0, $this->getMaxNumOfChars()); } } } if ($this->isHTML($text)) { $text = preg_replace("/<[^>]*\$/ims", "", $text); return $text; } else { //$text = htmlentities($text, ENT_QUOTES, "UTF-8"); } return $text; }
/** * Link terms in a dom page object in bb style * * @param * @return */ protected static function linkTermsInDom($a_dom, $a_terms, $a_par_node = null) { // sort terms by their length (shortes first) // to prevent that nested tags are builded foreach ($a_terms as $k => $t) { $a_terms[$k]["termlength"] = strlen($t["term"]); } $a_terms = ilUtil::sortArray($a_terms, "termlength", "asc", true); if ($a_dom instanceof php4DOMDocument) { $a_dom = $a_dom->myDOMDocument; } if ($a_par_node instanceof php4DOMElement) { $a_par_node = $a_par_node->myDOMNode; } $xpath = new DOMXPath($a_dom); if ($a_par_node == null) { $parnodes = $xpath->query('//Paragraph'); } else { $parnodes = $xpath->query('//Paragraph', $a_par_node); } include_once "./Services/Utilities/classes/class.ilStr.php"; foreach ($parnodes as $parnode) { $textnodes = $xpath->query('//text()', $parnode); foreach ($textnodes as $node) { $p = $node->getNodePath(); // we do not change text nodes inside of links if (!is_int(strpos($p, "/IntLink")) && !is_int(strpos($p, "/ExtLink"))) { $node_val = $node->nodeValue; // all terms foreach ($a_terms as $t) { $pos = ilStr::strIPos($node_val, $t["term"]); // if term found while (is_int($pos)) { // check if the string is not included in another word // note that [] $valid_limiters = array("", " ", " ", ".", ",", ":", ";", "!", "?", "\"", "'", "(", ")"); $b = $pos > 0 ? ilStr::subStr($node_val, $pos - 1, 1) : ""; $a = ilStr::subStr($node_val, $pos + ilStr::strLen($t["term"]), 1); if ((in_array($b, $valid_limiters) || htmlentities($b, null, 'utf-8') == " ") && in_array($a, $valid_limiters)) { $mid = '[iln term="' . $t["id"] . '"]' . ilStr::subStr($node_val, $pos, ilStr::strLen($t["term"])) . "[/iln]"; $node_val = ilStr::subStr($node_val, 0, $pos) . $mid . ilStr::subStr($node_val, $pos + ilStr::strLen($t["term"])); $pos += ilStr::strLen($mid); } else { $pos += ilStr::strLen($t["term"]); } $pos = ilStr::strIPos($node_val, $t["term"], $pos); } // insert [iln] tags } $node->nodeValue = $node_val; } // var_dump($p); // var_dump($node->nodeValue); } // dump paragraph node $text = $a_dom->saveXML($parnode); $text = substr($text, 0, strlen($text) - strlen("</Paragraph>")); $text = substr($text, strpos($text, ">") + 1); // replace [iln] by tags with xml representation $text = self::intLinks2xml($text); // "set text" $temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text . '</Paragraph>', DOMXML_LOAD_PARSING, $error); $temp_dom = $temp_dom->myDOMDocument; if (empty($error)) { // delete children of paragraph node $children = $parnode->childNodes; while ($parnode->hasChildNodes()) { $parnode->removeChild($parnode->firstChild); } // copy new content children in paragraph node $xpath_temp = new DOMXPath($temp_dom); $temp_pars = $xpath_temp->query("//Paragraph"); foreach ($temp_pars as $new_par_node) { $new_childs = $new_par_node->childNodes; foreach ($new_childs as $new_child) { //$cloned_child = $new_child->cloneNode(true); $cloned_child = $a_dom->importNode($new_child, true); $parnode->appendChild($cloned_child); } } } } }