/** * get an object value * * @param string $name : the name of the value to get * @param string $parameters (optional) : parameters for the value to get * @return multidimentionnal array : the object values structure * @access public */ function getValue($name, $parameters = '') { $href = new CMS_href($this->_subfieldValues[0]->getValue()); switch ($name) { case 'validhref': return $href->hasValidHREF(); break; case 'hrefvalue': //get module codename $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); //set location $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED; return $href->getHTML(false, $moduleCodename, $location, false, true); break; case 'hreflabel': return io::htmlspecialchars($href->getLabel()); break; case 'hreftarget': return $href->getTarget(); break; case 'hreftype': return $href->getLinkType(); break; case 'popupWidth': $popup = $href->getPopup(); return $popup['width']; break; case 'popupHeight': $popup = $href->getPopup(); return $popup['height']; break; case 'hrefHTML': //get module codename $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()); //set location $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED; //add link title (if any) if ($parameters) { $title = $parameters; //add title attribute to link $href->setAttributes(array('title' => io::htmlspecialchars($href->getLabel() . ' (' . $title . ')'))); } else { $title = false; //add title attribute to link $href->setAttributes(array('title' => io::htmlspecialchars($href->getLabel()))); } return $href->getHTML($title, $moduleCodename, $location); break; default: return parent::getValue($name, $parameters); break; } }
/** * Returns XHTML formatted form fields for this Href * * @param CMS_language $cms_language, the language to build the form with * @param string $module, the module codename (default : MOD_STANDARD_CODENAME) * @param constant $dataLocation, the current data location (RESOURCE_DATA_LOCATION_EDITED (default), RESOURCE_DATA_LOCATION_PUBLIC, etc.) * @param array $options, array of possible link options (default false : all options actived) * Example : * Array ( * 'label' => true|false, // Link has label ? * 'internal' => true|false, // Link can target an Automne page ? * 'external' => true|false, // Link can target an external resource ? * 'file' => true|false, // Link can target a file ? * 'destination'=> true|false, // Can select a destination for the link ? * 'no_admin' => true|false, // Deprecated : Remove all admin class reference (default = false) * 'admin' => true|false, // Use admin JS and classes instead of direct actions (default = true) * 'currentPage'=> int|false, // Current page to open tree panel (default : CMS_tree::getRoot()) * ) * @return string HTML formated expected * @access public */ function getHTMLFields($cms_language, $module = MOD_STANDARD_CODENAME, $dataLocation = RESOURCE_DATA_LOCATION_EDITED, $options = false) { global $cms_user; if (!is_a($this->_href, 'CMS_href')) { $this->raiseError("\$this->_href isn't a CMS_href"); return ''; } $tdClass = $tdClassLight = $tdClassDark = $inputClass = ''; if (!isset($options['no_admin']) || $options['no_admin'] === false) { $tdClass = ' class="admin"'; $tdClassLight = ' class="admin_lightgreybg"'; $tdClassDark = ' class="admin_darkgreybg"'; $inputClass = ' class="admin_input_text"'; } $s = ''; if (!isset($options['destination']) || $options['destination'] == true) { $s .= ' <script type="text/javascript"> if (typeof CMS_openPopUpPage != "function") { function CMS_openPopUpPage(href, id, width, height) { if (href != "") { pagePopupWin = window.open(href, \'CMS_page_\'+id, \'width=\'+width+\',height=\'+height+\',resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=no,left=0,top=0\'); } } } </script>'; } $s .= ' <table>'; if (!isset($options['label']) || $options['label'] == true) { $s .= ' <!-- link label --> <tr> <th' . $tdClass . '><span class="admin_text_alert">*</span> ' . $cms_language->getMessage(self::MESSAGE_PAGE_LINK_LABEL) . '</th> <td' . $tdClassLight . ' colspan="2"><input style="width:100%;" type="text"' . $inputClass . ' name="' . $this->_prefix . 'link_label" value="' . io::htmlspecialchars($this->_href->getLabel()) . '" /></td> </tr>'; } $checked = $this->_href->getLinkType() == RESOURCE_LINK_TYPE_NONE ? ' checked="checked"' : ''; $rowspan = 4; if (isset($options['internal']) && $options['internal'] == false) { $rowspan--; } if (isset($options['external']) && $options['external'] == false) { $rowspan--; } if (isset($options['file']) && $options['file'] == false) { $rowspan--; } $s .= ' <tr> <th' . $tdClass . ' rowspan="' . $rowspan . '"><span class="admin_text_alert">*</span> ' . $cms_language->getMessage(self::MESSAGE_PAGE_LINK_DESTINATION) . '</th> <td' . $tdClassDark . '><input type="radio" id="' . $this->_prefix . 'link_type_0" name="' . $this->_prefix . 'link_type" value="' . RESOURCE_LINK_TYPE_NONE . '"' . $checked . ' /></td> <td' . $tdClassDark . '><label for="' . $this->_prefix . 'link_type_0">' . $cms_language->getMessage(self::MESSAGE_PAGE_NOLINK) . '</label></td> </tr> '; if (!isset($options['internal']) || $options['internal'] == true) { $checked = $this->_href->getLinkType() == RESOURCE_LINK_TYPE_INTERNAL ? ' checked="checked"' : ''; // Build tree link $grand_root = isset($options['currentPage']) && sensitiveIO::isPositiveInteger($options['currentPage']) ? CMS_tree::getPageByID($options['currentPage']) : CMS_tree::getRoot(); $grand_rootID = $grand_root->getID(); if ($cms_user && is_a($cms_user, 'CMS_profile_user')) { if (!$cms_user->hasPageClearance($grand_rootID, CLEARANCE_PAGE_VIEW)) { // If user don't have any clearance view for page root : search a "first root" and viewable page sections $sections_roots = array(); $sections_roots = $cms_user->getViewablePageClearanceRoots(); if ($sections_roots) { CMS_session::setSessionVar('sectionsRoots', $sections_roots); $sections_roots = array_reverse($sections_roots); foreach ($sections_roots as $pageID) { $lineages[count(CMS_tree::getLineage($grand_rootID, $pageID, false))] = $pageID; } } ksort($lineages); $grand_rootID = array_shift($lineages); } } if (!isset($options['admin']) || $options['admin'] == false) { //build tree link $href = '/automne/admin-v3/tree.php'; $href .= '?root=' . $grand_rootID; $href .= '&heading=' . $cms_language->getMessage(self::MESSAGE_PAGE_TREEH1); $href .= '&encodedOnClick=' . base64_encode("window.opener.document.getElementById('" . $this->_prefix . "link_internal').value = '%s';self.close();"); $href .= '&encodedPageLink=' . base64_encode('false'); $treeLink = '<a href="' . $href . '"' . $tdClass . ' target="_blank"><img src="' . PATH_ADMIN_IMAGES_WR . '/tree.gif" border="0" align="absmiddle" /></a>'; } else { $treeLink = '<a href="#" onclick="Automne.view.tree(\'' . $this->_prefix . 'link_internal\', \'' . sensitiveIO::sanitizeJSString($cms_language->getMessage(self::MESSAGE_PAGE_TREEH1)) . '\', \'' . $grand_rootID . '\')"><img src="' . PATH_ADMIN_IMAGES_WR . '/tree.gif" border="0" align="absmiddle" /></a>'; } $s .= '<tr> <td' . $tdClassLight . '><input type="radio" id="' . $this->_prefix . 'link_type_1" name="' . $this->_prefix . 'link_type" value="' . RESOURCE_LINK_TYPE_INTERNAL . '"' . $checked . ' /></td> <td' . $tdClassLight . '> <label for="' . $this->_prefix . 'link_type_1">' . $cms_language->getMessage(self::MESSAGE_PAGE_INTERNALLINK) . '</label> <input type="text"' . $inputClass . ' id="' . $this->_prefix . 'link_internal" name="' . $this->_prefix . 'link_internal" value="' . $this->_href->getInternalLink() . '" size="6" /> ' . $treeLink . ' </td> </tr>'; } if (!isset($options['external']) || $options['external'] == true) { $checked = $this->_href->getLinkType() == RESOURCE_LINK_TYPE_EXTERNAL ? ' checked="checked"' : ''; $s .= ' <tr> <td' . $tdClassDark . '><input type="radio" id="' . $this->_prefix . 'link_type_2" name="' . $this->_prefix . 'link_type" value="' . RESOURCE_LINK_TYPE_EXTERNAL . '"' . $checked . ' /></td> <td' . $tdClassDark . '> <label for="' . $this->_prefix . 'link_type_2">' . $cms_language->getMessage(self::MESSAGE_PAGE_EXTERNALLINK) . '</label> <input type="text"' . $inputClass . ' id="' . $this->_prefix . 'link_external" name="' . $this->_prefix . 'link_external" value="' . io::htmlspecialchars($this->_href->getExternalLink()) . '" size="30" /> </td> </tr> '; } if (!isset($options['file']) || $options['file'] == true) { $checked = $this->_href->getLinkType() == RESOURCE_LINK_TYPE_FILE ? ' checked="checked"' : ''; $s .= ' <tr> <td' . $tdClassLight . '><input type="radio" id="' . $this->_prefix . 'link_type_3" name="' . $this->_prefix . 'link_type" value="' . RESOURCE_LINK_TYPE_FILE . '"' . $checked . ' /></td> <td' . $tdClassLight . '> <label for="' . $this->_prefix . 'link_type_3">' . $cms_language->getMessage(self::MESSAGE_PAGE_LINKFILE) . '</label> <input type="file"' . $inputClass . ' name="' . $this->_prefix . 'link_file" /><br /> <label for="' . $this->_prefix . 'link_edit_linkfile"><input type="checkbox" id="' . $this->_prefix . 'link_edit_linkfile" name="' . $this->_prefix . 'link_edit_linkfile" value="1" /> ' . $cms_language->getMessage(self::MESSAGE_PAGE_FIELD_EDITFILE) . '</label>'; if ($this->_href->getFileLink(false, $module, $dataLocation)) { $s .= '<br />' . $cms_language->getMessage(self::MESSAGE_PAGE_EXISTING_FILE) . ' : <a href="' . $this->_href->getFileLink(true, $module, $dataLocation) . '" target="_blank">' . $this->_href->getFileLink(false, $module, $dataLocation) . '</a>'; } else { $s .= '<br />' . $cms_language->getMessage(self::MESSAGE_PAGE_EXISTING_FILE) . ' : ' . $cms_language->getMessage(self::MESSAGE_PAGE_NO_FILE); } $s .= ' </td> </tr>'; } if (!isset($options['destination']) || $options['destination'] == true) { $popup = $this->_href->getPopup(); $checked_pop = isset($popup['width']) && $popup['width'] > 0 ? ' checked="checked"' : ''; $checked_top = isset($popup['width']) && $popup['width'] <= 0 && $this->_href->getTarget() == '_top' ? ' checked="checked"' : ''; $checked_bl = isset($popup['width']) && $popup['width'] <= 0 && $this->_href->getTarget() == '_blank' ? ' checked="checked"' : ''; if (!$checked_pop && !$checked_top && !$checked_bl) { $checked_top = ' checked="checked"'; } $width = isset($popup['width']) ? $popup['width'] : 0; $height = isset($popup['height']) ? $popup['height'] : 0; $s .= ' <!-- Link target --> <tr> <th' . $tdClass . ' rowspan="3">' . $cms_language->getMessage(self::MESSAGE_PAGE_LINK_SHOW) . '</th> <td' . $tdClassDark . '><input type="radio" id="' . $this->_prefix . 'link_target_top" name="' . $this->_prefix . 'link_target" value="top"' . $checked_top . ' /></td> <td' . $tdClassDark . '> <label for="' . $this->_prefix . 'link_target_top"><img src="' . PATH_ADMIN_IMAGES_WR . '/pic_link_top.gif" alt="" border="0" align="absmiddle" /> ' . $cms_language->getMessage(self::MESSAGE_PAGE_TARGET_TOP) . '</label> </td> </tr> <tr> <td' . $tdClassLight . '><input type="radio" id="' . $this->_prefix . 'link_target_blank" name="' . $this->_prefix . 'link_target" value="blank"' . $checked_bl . ' /></td> <td' . $tdClassLight . '> <label for="' . $this->_prefix . 'link_target_blank"><img src="' . PATH_ADMIN_IMAGES_WR . '/pic_link_blank.gif" alt="" border="0" align="absmiddle" /> ' . $cms_language->getMessage(self::MESSAGE_PAGE_TARGET_BLANK) . '</label> </td> </tr> <tr> <td' . $tdClassDark . '><input type="radio" id="' . $this->_prefix . 'link_target_popup" name="' . $this->_prefix . 'link_target" value="popup"' . $checked_pop . ' /></td> <td' . $tdClassDark . '> <label for="' . $this->_prefix . 'link_target_popup"><img src="' . PATH_ADMIN_IMAGES_WR . '/pic_link_top.gif" alt="" border="0" align="absmiddle" /> ' . $cms_language->getMessage(self::MESSAGE_PAGE_TARGET_POPUP) . ' : </label> ' . $cms_language->getMessage(self::MESSAGE_PAGE_POPUP_WIDTH) . ' <input type="text"' . $inputClass . ' name="' . $this->_prefix . 'link_popup_width" value="' . $width . '" size="3" /> ' . $cms_language->getMessage(self::MESSAGE_PAGE_POPUP_HEIGHT) . ' <input type="text"' . $inputClass . ' name="' . $this->_prefix . 'link_popup_height" value="' . $height . '" size="3" /> </td> </tr>'; } $s .= '</table>'; return $s; }