Пример #1
0
 /**
  * Replace block definition vars.
  *
  * @param array data : the block datas
  * @param string html_attributes : html attributes
  * @param integer $location The location of the page
  * @param boolean $public The needed precision for USERSPACE location
  * @return string the HTML data
  * @access public
  */
 function _replaceBlockVars($data, $html_attributes, $location, $public)
 {
     switch ($location) {
         case RESOURCE_DATA_LOCATION_PUBLIC:
             $folder = $public ? "public" : "edited";
             break;
         case RESOURCE_DATA_LOCATION_ARCHIVED:
             $folder = "archived";
             break;
         case RESOURCE_DATA_LOCATION_DELETED:
             $folder = "deleted";
             break;
         case RESOURCE_DATA_LOCATION_EDITION:
             $folder = "edition";
             break;
     }
     $currentLink = new CMS_href($data["externalLink"]);
     //must put the main website URL before
     $html_imgZoomHtml = '';
     $html_imgZoomName = '';
     $html_imageZoomHref = '';
     $html_imageZoomPop = '';
     if ($public && ALTERNATIVE_DOMAIN) {
         $domain = ALTERNATIVE_DOMAIN;
     } else {
         $domain = CMS_websitesCatalog::getCurrentDomain(@$this->_pageID);
     }
     if ($data["file"]) {
         $html_img = '<img src="' . $domain . PATH_MODULES_FILES_STANDARD_WR . '/' . $folder . '/' . $data["file"] . '" alt="' . io::htmlspecialchars($data["label"]) . '" ' . $html_attributes . ' />';
     }
     if ($data["enlargedFile"]) {
         $html_imgZoomName = $data["enlargedFile"];
         $html_imgZoomHtml = '<img src="' . $domain . PATH_MODULES_FILES_STANDARD_WR . '/' . $folder . '/' . $data["enlargedFile"] . '" alt="' . io::htmlspecialchars($data["label"]) . '" ' . $html_attributes . ' />';
     }
     if ($data["enlargedFile"]) {
         $href = OPEN_ZOOMIMAGE_IN_POPUP ? CMS_websitesCatalog::getCurrentDomain(@$this->_pageID) . PATH_REALROOT_WR . "/" . CMS_block_image::BLOCK_IMAGE_POPUP . '?location=' . $folder . '&amp;file=' . $data["enlargedFile"] . '&amp;label=' . urlencode($data["label"]) : $domain . PATH_MODULES_FILES_STANDARD_WR . '/' . $folder . '/' . $data["enlargedFile"];
         $popup = OPEN_ZOOMIMAGE_IN_POPUP ? ' onclick="javascript:CMS_openPopUpImage(\'' . addslashes($href) . '\');return false;"' : '';
         if ($html_img) {
             $html = '<a target="_blank" rel="atm-enlarge" href="' . $href . '"' . $popup . ' title="' . io::htmlspecialchars($data["label"]) . '">' . $html_img . '</a>';
         }
         $html_imageZoomHref = $href;
         $linkLabel = '<a class="imagezoomlink" target="_blank" href="' . $href . '"' . $popup . ' title="' . io::htmlspecialchars($data["label"]) . '">' . io::htmlspecialchars($data["label"]) . '</a>';
     } else {
         if ($currentLink->getHTML(false, MOD_STANDARD_CODENAME, $location)) {
             $html = $currentLink->getHTML($html_img, MOD_STANDARD_CODENAME, $location);
             $currentLink->setLabel('');
             $linkLabel = $currentLink->getHTML($data['label'], MOD_STANDARD_CODENAME, $location);
         } else {
             $html = $html_img;
             $linkLabel = io::htmlspecialchars($data["label"]);
         }
     }
     $replace = array('{{data}}' => $html, '{{label}}' => io::htmlspecialchars($data["label"]), '{{jslabel}}' => io::htmlspecialchars($data["label"]), '{{linkLabel}}' => $linkLabel, '{{imageZoomHtml}}' => $html_imgZoomHtml, '{{imagePath}}' => $domain . PATH_MODULES_FILES_STANDARD_WR . '/' . $folder, '{{imageName}}' => $data["file"], '{{imageZoomHref}}' => $html_imageZoomHref, '{{imageZoomName}}' => $html_imgZoomName);
     if (io::strpos($this->_definition, 'Width}}') !== false || io::strpos($this->_definition, 'Height}}') !== false) {
         list($sizeX, $sizeY) = @getimagesize(PATH_MODULES_FILES_STANDARD_FS . '/' . $folder . '/' . $data["file"]);
         if (isset($data["enlargedFile"])) {
             list($sizeZoomX, $sizeZoomY) = @getimagesize(PATH_MODULES_FILES_STANDARD_FS . '/' . $folder . '/' . $data["enlargedFile"]);
         }
         $replace['{{imageWidth}}'] = isset($sizeX) ? $sizeX : "0";
         $replace['{{imageHeight}}'] = isset($sizeY) ? $sizeY : "0";
         $replace['{{imageZoomWidth}}'] = isset($sizeZoomX) ? $sizeZoomX : "0";
         $replace['{{imageZoomHeight}}'] = isset($sizeZoomY) ? $sizeZoomY : "0";
     }
     return str_replace(array_keys($replace), $replace, $this->_definition);
 }
Пример #2
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;
 }