Пример #1
0
 public function testWebResourceParameters()
 {
     include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
     $appender = new ilParameterAppender(999);
     $appender->setName('first');
     $appender->setValue(1);
     $appender->add(888);
     $params = ilParameterAppender::_getParams(888);
     foreach ($params as $key => $data) {
         $appender->delete($key);
         $this->assertEquals($data['name'], 'first');
         $this->assertEquals($data['value'], 1);
     }
 }
 /**
  * get html 
  * @return
  */
 public function getHTML()
 {
     global $lng;
     $lng->loadLanguageModule('webr');
     foreach ($this->getSubItemIds(true) as $sub_item) {
         if (is_object($this->getHighlighter()) and strlen($this->getHighlighter()->getContent($this->getObjId(), $sub_item))) {
             $this->tpl->setCurrentBlock('sea_fragment');
             $this->tpl->setVariable('TXT_FRAGMENT', $this->getHighlighter()->getContent($this->getObjId(), $sub_item));
             $this->tpl->parseCurrentBlock();
         }
         $this->tpl->setCurrentBlock('subitem');
         $this->tpl->setVariable('SUBITEM_TYPE', $lng->txt('webr'));
         $this->tpl->setVariable('SEPERATOR', ':');
         $link_data = ilLinkResourceItems::lookupItem($this->getObjId(), $sub_item);
         $link_data = ilParameterAppender::_append($link_data);
         // handle internal links (#10620)
         if (stristr($link_data["target"], "|")) {
             $parts = explode("|", $link_data["target"]);
             if ($parts[0] == "page") {
                 $parts[0] = "pg";
             }
             if ($parts[0] == "term") {
                 $parts[0] = "git";
             }
             $link_data["target"] = ilLink::_getStaticLink($parts[1], $parts[0]);
         }
         #$this->getItemListGUI()->setChildId($sub_item);
         $this->tpl->setVariable('LINK', $link_data['target']);
         $this->tpl->setVariable('TARGET', '_blank');
         $this->tpl->setVariable('TITLE', $link_data['title']);
         $this->tpl->parseCurrentBlock();
     }
     $this->showDetailsLink();
     return $this->tpl->get();
 }
 public static function _append($a_link_data)
 {
     global $ilUser;
     if (!is_array($a_link_data)) {
         return false;
     }
     if (count($params = ilParameterAppender::_getParams($a_link_data['link_id']))) {
         // Check for prefix
         foreach ($params as $param_data) {
             if (!strpos($a_link_data['target'], '?')) {
                 $a_link_data['target'] .= "?";
             } else {
                 $a_link_data['target'] .= "&";
             }
             $a_link_data['target'] .= $param_data['name'] . "=";
             switch ($param_data['value']) {
                 case LINKS_LOGIN:
                     $a_link_data['target'] .= urlencode($ilUser->getLogin());
                     break;
                 case LINKS_SESSION_ID:
                     $a_link_data['target'] .= session_id();
                     break;
                 case LINKS_USER_ID:
                     $a_link_data['target'] .= $ilUser->getId();
                     break;
                 case LINKS_MATRICULATION:
                     $a_link_data['target'] .= $ilUser->getMatriculation();
                     break;
             }
         }
     }
     return $a_link_data;
 }
Пример #4
0
 /**
  * handler for begin of element
  *
  * @param	resource	$a_xml_parser		xml parser
  * @param	string		$a_name				element name
  * @param	array		$a_attribs			element attributes array
  */
 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
 {
     global $ilErr;
     if ($this->in_metadata) {
         parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
         return;
     }
     switch ($a_name) {
         case "MetaData":
             $this->in_metadata = true;
             // Delete old meta data
             $md = new ilMD($this->getWebLink()->getId(), 0, 'webr');
             $md->deleteAll();
             parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
             break;
         case 'WebLink':
             $this->current_link_update = false;
             $this->current_link_delete = false;
             $this->current_parameters = array();
             if ($this->getMode() == self::MODE_CREATE or isset($a_attribs['action']) and $a_attribs['action'] == 'Create') {
                 // New weblink
                 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
             } elseif ($this->getMode() == self::MODE_UPDATE and $a_attribs['action'] == 'Delete') {
                 $this->current_link_delete = true;
                 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
                 $this->current_link->delete($a_attribs['id']);
                 break;
             } elseif ($this->getMode() == self::MODE_UPDATE and ($a_attribs['action'] == 'Update' or !isset($a_attribs['action']))) {
                 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
                 $this->current_link->readItem($a_attribs['id']);
                 $this->current_link_update = true;
                 // Delete all dynamic parameter
                 include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
                 foreach (ilParameterAppender::getParameterIds($this->getWebLink()->getId(), $a_attribs['id']) as $param_id) {
                     $param = new ilParameterAppender($this->getWebLink()->getId());
                     $param->delete($param_id);
                 }
             } else {
                 throw new ilWebLinkXmlParserException('Invalid action given for element "Weblink"');
             }
             // Active
             $this->current_link->setActiveStatus($a_attribs['active'] ? 1 : 0);
             // Valid
             if (!isset($a_attribs['valid'])) {
                 $valid = 1;
             } else {
                 $valid = $a_attribs['valid'] ? 1 : 0;
             }
             $this->current_link->setValidStatus($valid);
             // Disable check
             $this->current_link->setDisableCheckStatus($a_attribs['disableValidation'] ? 1 : 0);
             break;
         case 'Sorting':
             include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
             $sort = new ilContainerSortingSettings($this->getWebLink()->getId());
             $sort->delete();
             switch ($a_attribs['type']) {
                 case 'Manual':
                     $sort->setSortMode(ilContainer::SORT_MANUAL);
                     break;
                 case 'Title':
                 default:
                     $sort->setSortMode(ilContainer::SORT_TITLE);
             }
             $sort->save();
             break;
         case 'WebLinks':
         case 'Title':
         case 'Description':
         case 'Target':
             // Nothing to do
             break;
         case 'DynamicParameter':
             $param = new ilParameterAppender($this->getWebLink()->getId());
             $param->setName($a_attribs['name']);
             switch ($a_attribs['type']) {
                 case 'userName':
                     #						$GLOBALS['ilLog']->write("VALUE: ".LINKS_LOGIN);
                     $param->setValue(LINKS_LOGIN);
                     break;
                 case 'userId':
                     #						$GLOBALS['ilLog']->write("VALUE: ".LINKS_USER_ID);
                     $param->setValue(LINKS_USER_ID);
                     break;
                 case 'matriculation':
                     #						$GLOBALS['ilLog']->write("VALUE: ".LINKS_MATRICULATION);
                     $param->setValue(LINKS_MATRICULATION);
                     break;
                 default:
                     throw new ilWebLinkXmlParserException('Invalid attribute "type" given for element "Dynamic parameter". Aborting');
                     break;
             }
             $this->current_parameters[] = $param;
             break;
     }
 }
 /**
  * Get data of first active link resource
  *
  * @return array link data array
  */
 function __readLink()
 {
     include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
     include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
     if (ilParameterAppender::_isEnabled()) {
         return $this->link_data = ilParameterAppender::_append($tmp =& ilLinkResourceItems::_getFirstLink($this->obj_id));
     }
     return $this->link_data = ilLinkResourceItems::_getFirstLink($this->obj_id);
 }
 function callLink()
 {
     if ($_REQUEST["link_id"]) {
         $obj_id = $this->object->getId();
         include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
         $items = new ilLinkResourceItems($obj_id);
         $item = $items->getItem($_REQUEST["link_id"]);
         if ($item["target"]) {
             // handle internal links
             if (stristr($item["target"], "|")) {
                 $parts = explode("|", $item["target"]);
                 if ($parts[0] == "page") {
                     $parts[0] = "pg";
                 }
                 include_once "./Services/Link/classes/class.ilLink.php";
                 $item["target"] = ilLink::_getStaticLink($parts[1], $parts[0]);
                 if ($parts[0] == "term") {
                     $parts[0] = "git";
                     $item["target"] = ilLink::_getStaticLink(0, $parts[0], true, "&target=git_" . $parts[1]);
                 }
             }
             include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
             if (ilParameterAppender::_isEnabled()) {
                 $item = ilParameterAppender::_append($item);
             }
             //var_dump($item); exit;
             $this->redirectToLink($this->ref_id, $obj_id, $item["target"]);
         }
     }
 }
 /**
  * @see ilTable2GUI::fillRow()
  */
 protected function fillRow($a_set)
 {
     global $ilCtrl, $lng;
     if (!stristr($a_set['target'], '|')) {
         $this->tpl->setCurrentBlock('external');
         $this->tpl->setVariable('VAL_ID', $a_set['id']);
         $this->tpl->setVariable('VAL_TARGET', $a_set['target']);
         $this->tpl->parseCurrentBlock();
     } else {
         $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar', 'tar_' . $a_set['id']);
         $trigger_link = array(get_class($this->parent_obj), 'ilinternallinkgui');
         $trigger_link = $ilCtrl->getLinkTargetByClass($trigger_link, '', false, true, false);
         $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar', '');
         $this->tpl->setCurrentBlock('internal');
         $this->tpl->setVariable('VAL_ID', $a_set['id']);
         $this->tpl->setVariable('VAL_TRIGGER_INTERNAL', $trigger_link);
         $this->tpl->setVariable('TXT_TRIGGER_INTERNAL', $this->lng->txt('edit'));
         // info about current link
         if ($a_set['target']) {
             $parts = explode('|', $a_set['target']);
             $this->tpl->setVariable('VAL_INTERNAL_TYPE', $parts[0]);
             $this->tpl->setVariable('VAL_INTERNAL_ID', $parts[1]);
             $parts = ilLinkInputGUI::getTranslatedValue($a_set['target']);
             $this->tpl->setVariable('TXT_TRIGGER_INFO', $parts['type'] . ' "' . $parts['name'] . '"');
         }
         $this->tpl->parseCurrentBlock();
     }
     $this->tpl->setVariable('TXT_LAST_CHECK', $this->lng->txt('webr_last_check_table'));
     $this->tpl->setVariable('LAST_CHECK', $a_set['last_check'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_check'], IL_CAL_UNIX)) : $this->lng->txt('no_date'));
     // Valid
     $this->tpl->setVariable('VAL_VALID', ilUtil::formCheckbox($a_set['valid'], 'links[' . $a_set['id'] . '][vali]', 1));
     // Active
     $this->tpl->setVariable('VAL_ACTIVE', ilUtil::formCheckbox($a_set['active'], 'links[' . $a_set['id'] . '][act]', 1));
     // Valid
     $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox($a_set['disable_check'], 'links[' . $a_set['id'] . '][che]', 1));
     // Dynamic parameters
     foreach ($a_set['params'] as $param_id => $param) {
         $this->tpl->setCurrentBlock('dyn_del_row');
         $this->tpl->setVariable('TXT_DYN_DEL', $this->lng->txt('delete'));
         $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'param_id', $param_id);
         $this->tpl->setVariable('DYN_DEL_LINK', $ilCtrl->getLinkTarget($this->getParentObject(), 'deleteParameter'));
         $this->tpl->setVariable('VAL_DYN', ilParameterAppender::parameterToInfo($param['name'], $param['value']));
         $this->tpl->parseCurrentBlock();
     }
     if ($a_set['params']) {
         $this->tpl->setCurrentBlock('dyn_del_rows');
         $this->tpl->setVariable('TXT_EXISTING', $this->lng->txt('links_existing_params'));
         $this->tpl->parseCurrentBlock();
     }
     if (ilParameterAppender::_isEnabled()) {
         $this->tpl->setCurrentBlock('dyn_add');
         $this->tpl->setVariable('TXT_DYN_ADD', $this->lng->txt('links_add_param'));
         $this->tpl->setVariable('TXT_DYN_NAME', $this->lng->txt('links_name'));
         $this->tpl->setVariable('TXT_DYN_VALUE', $this->lng->txt('links_value'));
         $this->tpl->setVariable('VAL_DYN_NAME', $a_set['name']);
         $this->tpl->setVariable('DYN_ID', $a_set['id']);
         $this->tpl->setVariable('SEL_DYN_VAL', ilUtil::formSelect($a_set['value'] ? $a_set['value'] : 0, 'links[' . $a_set['id'] . '][val]', ilParameterAppender::_getOptionSelect(), false, true));
         $this->tpl->parseCurrentBlock();
     }
     if (in_array($a_set['id'], $this->getInvalidLinks())) {
         $this->tpl->setVariable('CSS_ROW', 'warn');
     }
     // Check
     $this->tpl->setVariable('VAL_ID', $a_set['id']);
     $this->tpl->setVariable('VAL_CHECKBOX', ilUtil::formCheckbox(false, 'link_ids[]', $a_set['id']));
     // Column title
     $this->tpl->setVariable('TXT_TITLE', $this->lng->txt('title'));
     $this->tpl->setVariable('VAL_TITLE', ilUtil::prepareFormOutput($a_set['title']));
     $this->tpl->setVariable('TXT_DESC', $this->lng->txt('description'));
     $this->tpl->setVariable('VAL_DESC', ilUtil::prepareFormOutput($a_set['description']));
     // Column Target
     $this->tpl->setVariable('TXT_TARGET', $this->lng->txt('target'));
 }
 /**
  * Write link XML
  * @param ilXmlWriter $writer
  * @return 
  */
 public function toXML(ilXmlWriter $writer)
 {
     foreach (self::getAllItemIds($this->getLinkResourceId()) as $link_id) {
         $link = self::lookupItem($this->getLinkResourceId(), $link_id);
         $writer->xmlStartTag('WebLink', array('id' => $link['link_id'], 'active' => $link['active'] ? 1 : 0, 'valid' => $link['valid'] ? 1 : 0, 'disableValidation' => $link['disable_check'] ? 1 : 0));
         $writer->xmlElement('Title', array(), $link['title']);
         $writer->xmlElement('Description', array(), $link['description']);
         $writer->xmlElement('Target', array(), $link['target']);
         // Dynamic parameters
         include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
         foreach (ilParameterAppender::_getParams($link_id) as $param_id => $param) {
             $value = '';
             switch ($param['value']) {
                 case LINKS_USER_ID:
                     $value = 'userId';
                     break;
                 case LINKS_LOGIN:
                     $value = 'userName';
                     break;
                 case LINKS_MATRICULATION:
                     $value = 'matriculation';
                     break;
             }
             if (!$value) {
                 // Fix for deprecated LINKS_SESSION
                 continue;
             }
             $writer->xmlElement('DynamicParameter', array('id' => $param_id, 'name' => $param['name'], 'type' => $value));
         }
         $writer->xmlEndTag('WebLink');
     }
     return true;
 }
 function callLink()
 {
     if ($_REQUEST["link_id"]) {
         $obj_id = $this->object->getId();
         include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
         $items = new ilLinkResourceItems($obj_id);
         $item = $items->getItem($_REQUEST["link_id"]);
         if ($item["target"]) {
             $item["target"] = $this->handleSubItemLinks($item["target"]);
             include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
             if (ilParameterAppender::_isEnabled()) {
                 $item = ilParameterAppender::_append($item);
             }
             $this->redirectToLink($this->ref_id, $obj_id, $item["target"]);
         }
     }
 }