Esempio n. 1
0
 /**
  * Get datas vars from a form formatted by such a Automne.LinkField class
  * and build a CMS_href
  *
  * @param array $datas, the datas sent by the Automne.LinkField return
  * @param string $module, the module concerned by this link
  * @param integer $resourceID, ID to prepend the filename uploaded with
  * @param integer $fieldID, optional field ID to surcharge file name representation ("r".$resourceID."_f".$fieldID."_")
  * @return boolean true on success, false on failure
  * @access public
  */
 function create($datas = '', $module = MOD_STANDARD_CODENAME, $resourceID, $fieldID = '')
 {
     $datas = explode($this->_href->getSeparator(), $datas);
     $linkLabel = isset($datas[7]) ? $datas[7] : '';
     $linkType = isset($datas[0]) ? $datas[0] : '';
     $internalLink = isset($datas[1]) ? $datas[1] : '';
     $externalLink = isset($datas[2]) ? $datas[2] : '';
     $this->_href->setLabel($linkLabel);
     $this->_href->setLinkType($linkType);
     $this->_href->setInternalLink($internalLink);
     $this->_href->setExternalLink($externalLink);
     // Delete/Upload file
     if (isset($datas[3])) {
         switch ($module) {
             case MOD_STANDARD_CODENAME:
                 $locationType = RESOURCE_DATA_LOCATION_EDITION;
                 $uniqueName = md5(serialize($this) . microtime());
                 $fileprefix = $fieldID ? 'p' . $resourceID . '_' . $uniqueName . "_f" . $fieldID : 'p' . $resourceID . '_' . $uniqueName;
                 break;
             default:
                 $locationType = RESOURCE_DATA_LOCATION_EDITED;
                 $fileprefix = $fieldID ? 'r' . $resourceID . "_f" . $fieldID . "_" : 'r' . $resourceID . "_";
                 break;
         }
         if ($datas[3] && io::strpos($datas[3], PATH_UPLOAD_WR . '/') !== false) {
             //move and rename uploaded file
             $datas[3] = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $datas[3]);
             $basename = pathinfo($datas[3], PATHINFO_BASENAME);
             $path = $this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM, false);
             $newFilename = $path . '/' . $fileprefix . $basename;
             CMS_file::moveTo($datas[3], $newFilename);
             CMS_file::chmodFile(FILES_CHMOD, $newFilename);
             $datas[3] = pathinfo($newFilename, PATHINFO_BASENAME);
             //remove the old file if any
             if (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) {
                 if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) {
                     $this->raiseError("Could not delete old linked file");
                 }
             }
         } elseif ($datas[3]) {
             //keep old file
             $datas[3] = pathinfo($datas[3], PATHINFO_BASENAME);
         } else {
             $datas[3] = '';
             //remove the old file if any
             if (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) {
                 if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) {
                     $this->raiseError("Could not delete old linked file");
                 }
             }
         }
         $this->_href->setFileLink($datas[3]);
     } elseif (is_file($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) {
         //remove the old file
         if (!unlink($this->_href->getFileLink(true, $module, $locationType, PATH_RELATIVETO_FILESYSTEM))) {
             $this->raiseError("Could not delete old linked file");
         }
     }
     // Target and Popup > (width, height)
     list($width, $height) = explode(',', $datas[6]);
     if (sensitiveIO::isPositiveInteger($width) && sensitiveIO::isPositiveInteger($height)) {
         $this->_href->setPopup($width, $height);
     } else {
         switch ($datas[4]) {
             case "_top":
                 $this->_href->setTarget('_top');
                 $this->_href->setPopup('', '');
                 break;
             case "_blank":
                 $this->_href->setTarget('_blank');
                 $this->_href->setPopup('', '');
                 break;
         }
     }
     return true;
 }
Esempio n. 2
0
        $lineage = $alias->getPath();
        $selectContent[$lineage] = array($alias->getID(), $lineage);
    }
}
ksort($selectContent);
array_unshift($selectContent, array(0, '/'));
$selectContent = sensitiveIO::jsonEncode(array_values($selectContent));
$controlerURL = PATH_ADMIN_MODULES_WR . '/' . $codename . '/controler.php';
$parentId = isset($parentAlias) && is_object($parentAlias) ? $parentAlias->getId() : 0;
//mandatory
$mandatory = '<span class="atm-red">*</span> ';
//create pseudo href for redirection infos
$href = new CMS_href();
if ($pageId) {
    $href->setLinkType(RESOURCE_LINK_TYPE_INTERNAL);
    $href->setInternalLink($pageId);
    $redirDisabled = 'disabled:true,';
    $redirHidden = "{\n\t\txtype:\t\t\t'hidden',\n\t\tname:\t\t\t'page',\n\t\tvalue:\t\t\t'{$pageId}'\n\t},";
} else {
    if (io::isPositiveInteger($item->getPageID())) {
        $href->setLinkType(RESOURCE_LINK_TYPE_INTERNAL);
        $href->setInternalLink($item->getPageID());
    } elseif ($item->getURL()) {
        $href->setLinkType(RESOURCE_LINK_TYPE_EXTERNAL);
        $href->setExternalLink($item->getURL());
    }
    $redirDisabled = $redirHidden = '';
}
$redirectValue = io::sanitizeJSString($href->getTextDefinition());
$visualmode = RESOURCE_DATA_LOCATION_EDITED;
//Websites