Exemplo n.º 1
0
 /**
  * Raises an error. Shows it to the screen
  * Deprecated, use raiseError instead
  * @param string $errorMessage the error message.
  * @param boolean $encodeOutput, does the screen output should be encoded (default : false)
  * @return void
  * @access public
  */
 public function _raiseError($errorMessage, $encodeOutput = false, $error = true)
 {
     static $errorNumber;
     $systemDebug = !defined('SYSTEM_DEBUG') ? true : SYSTEM_DEBUG;
     if (isset($this) && isset($this->_debug) && $this->_debug === NULL) {
         $this->_debug = $systemDebug;
     }
     if ($errorMessage) {
         //second condition are for static calls (made by static methods)
         if (!defined('APPLICATION_EXEC_TYPE') || APPLICATION_EXEC_TYPE == 'http' && (!isset($this) && $systemDebug || isset($this) && isset($this->_debug) && $this->_debug)) {
             $backTrace = $backTraceLink = '';
             if (version_compare(phpversion(), "5.2.5", "<")) {
                 $bt = @array_reverse(debug_backtrace());
             } else {
                 $bt = @array_reverse(debug_backtrace(false));
             }
             $backtrace = array('summary' => sensitiveIO::printBackTrace($bt), 'backtrace' => @print_r($bt, true));
             $backtraceName = 'bt_' . md5(rand());
             $backTraceLink = PATH_ADMIN_WR . '/backtrace.php?bt=' . $backtraceName;
             //save backtrace to cache (for 10 min)
             $cache = new CMS_cache($backtraceName, 'atm-backtrace', 600, false);
             if ($cache) {
                 $cache->save($backtrace);
             }
             unset($backtrace, $cache, $bt);
             //append error to current view
             $view = CMS_view::getInstance();
             $outputMessage = $encodeOutput ? io::htmlspecialchars($errorMessage) : $errorMessage;
             $view->addError(array('error' => $outputMessage, 'backtrace' => $backTraceLink));
         }
         //second condition are for static calls (made by static methods)
         if (!isset($this) || !isset($this->_log) || $this->_log) {
             if (@file_put_contents(PATH_MAIN_FS . '/' . self::ERROR_LOG, date("Y-m-d H:i:s", time()) . '|' . APPLICATION_EXEC_TYPE . '|' . $errorMessage . "\n", FILE_APPEND) !== false) {
                 CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . '/' . self::ERROR_LOG);
             } else {
                 die('<pre><b>' . CMS_view::SYSTEM_LABEL . ' ' . AUTOMNE_VERSION . ' error : /automne dir is not writable' . "</b></pre>\n");
             }
         }
     }
     //must be at the end because it interferes with the static calls conditions above
     if ($error && isset($this)) {
         $this->_errRaised = true;
     }
 }
Exemplo n.º 2
0
 /**
  * Set soap values
  *
  * @param integer $fieldID The field ID
  * @param $domdocument XML values to set
  * @param $itemId the ID of the polyobject item, if any (necessary for some fields (image, file, etc...)
  * @return boolean true or false
  * @access public
  */
 function setSoapValues($fieldID, $domdocument, $itemId = '')
 {
     $view = CMS_view::getInstance();
     $fieldValues = array();
     // subfield
     foreach ($domdocument->childNodes as $childNode) {
         if ($childNode->nodeType == XML_ELEMENT_NODE) {
             switch ($childNode->tagName) {
                 case 'subfield':
                     //<subfield id="{int}" [name="{string}"] type="int|string|date|text|object|binary|category|user|group">
                     $subFieldId = $childNode->getAttribute('id');
                     if (!sensitiveIO::isPositiveInteger($subFieldId) && $subFieldId != 0) {
                         $view->addError('Missing or invalid attribute id for subfield tag');
                         return false;
                     }
                     if (!isset($this->_subfields[$subFieldId])) {
                         $view->addError('Unknown field id ' . $fieldId . ' for object ' . $this->_objectID);
                         return false;
                     }
                     $fieldValues[$fieldID . '_' . $subFieldId] = trim(io::strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8' ? utf8_decode($childNode->nodeValue) : $childNode->nodeValue);
                     break;
                 case 'object':
                     //TODO
                     break;
                 default:
                     $view->addError('Unknown xml tag ' . $childNode->tagName . ' to process.');
                     return false;
                     break;
             }
         } else {
             if ($childNode->nodeType == XML_TEXT_NODE && trim($childNode->nodeValue)) {
                 $view->addError('Unknown xml content tag ' . $childNode->nodeValue . ' to process.');
                 return false;
             }
         }
     }
     if (!$this->checkMandatory($fieldValues, '')) {
         $view->addError('Error of mandatory values for field ' . $fieldID);
         return false;
     } elseif (!$this->setValues($fieldValues, '', false, $itemId)) {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
    $jsfiles = array('ext', 'debug', 'codemirror', 'main');
} else {
    $jsfiles = array('ext', 'codemirror', 'main');
}
//set title
$view->setTitle($language->getMessage(MESSAGE_PAGE_TITLE, array(APPLICATION_LABEL)));
$content = '
<div id="atm-loading-mask"></div>
<div id="atm-center">
	<div class="atm-loading-indicator">' . $language->getMessage(MESSAGE_PAGE_LOADING) . '</div>
	<noscript class="atm-alert">You must have Javascript enabled to access Automne.<hr />Vous devez avoir Javascript actif pour acc&eacute;der &agrave; Automne.</noscript>
</div>
<script type="text/javascript">
var CKEDITOR_BASEPATH = \'' . PATH_MAIN_WR . '/ckeditor/\';
</script>
' . CMS_view::getJavascript($jsfiles) . CMS_view::getJavascript(array('launch'));
if (io::request('cms_action') == 'logout') {
    //append logout info
    $content .= '<script type="text/javascript">Automne.logout = true;</script>';
}
if (APPLICATION_GCF_SUPPORT) {
    //GCF prompt for IE
    $content .= '
	<script type="text/javascript" 
		src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
	<style type="text/css">
	.chromeFrameOverlayContent {
		z-index:200001;
	}
	</style> 
	<script type="text/javascript">
Exemplo n.º 4
0
 /**
  * Create the redirection of an alias
  *
  * @return boolean true on success, false on failure
  * @access public
  * @static
  */
 function redirect()
 {
     //get aliases for current folder
     $dirname = array_pop(explode(DIRECTORY_SEPARATOR, dirname($_SERVER['SCRIPT_NAME'])));
     $aliases = CMS_module_cms_aliases::getByName($dirname);
     if (!$aliases) {
         //no alias found, go to 404
         CMS_grandFather::raiseError('No alias found for directory ' . dirname($_SERVER['SCRIPT_NAME']));
         CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
     }
     //check each aliases returned to get the one which respond to current alias
     $matchAlias = false;
     $domain = @parse_url($_SERVER['REQUEST_URI'], PHP_URL_HOST) ? @parse_url($_SERVER['REQUEST_URI'], PHP_URL_HOST) : (@parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) ? @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST']);
     $websites = array();
     if ($domain) {
         $websites = CMS_websitesCatalog::getWebsitesFromDomain($domain);
     }
     foreach ($aliases as $alias) {
         if (!$matchAlias && dirname($_SERVER['SCRIPT_NAME']) == substr($alias->getPath(), 0, -1)) {
             if ($websites) {
                 foreach ($websites as $website) {
                     //alias match path, check for website
                     if (!$alias->getWebsites() || !$website || in_array($website->getId(), $alias->getWebsites())) {
                         //alias match website, use it
                         $matchAlias = $alias;
                     }
                 }
             } else {
                 //alias match path, check for website
                 if (!$alias->getWebsites()) {
                     //alias match website, use it
                     $matchAlias = $alias;
                 }
             }
         }
     }
     if (!$matchAlias) {
         //no alias found, go to 404
         CMS_grandFather::raiseError('No alias found for directory ' . dirname($_SERVER['SCRIPT_NAME']) . ' and domain ' . $domain);
         CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
     }
     //if alias is used as a page url, return page
     if ($matchAlias->urlReplaced()) {
         if (io::isPositiveInteger($matchAlias->getPageID())) {
             $page = CMS_tree::getPageById($matchAlias->getPageID());
         } else {
             //no valid page set, go to 404
             $matchAlias->raiseError('No page set for alias ' . $matchAlias->getID());
             CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
         }
         if (!$page || $page->hasError()) {
             //no valid page found, go to 404
             $matchAlias->raiseError('Invalid page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
             CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
         }
         //return page path
         $pPath = $page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM);
         if ($pPath) {
             if (file_exists($pPath)) {
                 return $pPath;
             } elseif ($page->regenerate(true)) {
                 clearstatcache();
                 if (file_exists($pPath)) {
                     return $pPath;
                 }
             }
         }
         //no valid url page found, go to 404
         $matchAlias->raiseError('Invalid url page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
         CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
     } else {
         //this is a redirection
         $params = isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';
         if (isset($_SERVER['HTTP_REFERER'])) {
             header("Referer: " . $_SERVER['HTTP_REFERER']);
         }
         if (io::isPositiveInteger($matchAlias->getPageID())) {
             //it's a redirection to an Automne Page
             $page = CMS_tree::getPageById($matchAlias->getPageID());
             if ($page && !$page->hasError()) {
                 $pageURL = CMS_tree::getPageValue($matchAlias->getPageID(), 'url');
                 if ($pageURL) {
                     CMS_view::redirect($pageURL . $params, true, $matchAlias->isPermanent() ? 301 : 302);
                 } else {
                     //no valid url page found, go to 404
                     $matchAlias->raiseError('Invalid url page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
                     CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
                 }
             } else {
                 //no valid page found, go to 404
                 $matchAlias->raiseError('Invalid page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
                 CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
             }
         } elseif ($matchAlias->getURL()) {
             //it's a redirection to an URL
             CMS_view::redirect($matchAlias->getURL(), true, $matchAlias->isPermanent() ? 301 : 302);
         } else {
             //no valid redirection found, go to 404
             $matchAlias->raiseError('Invalid redirection for alias ' . $matchAlias->getID());
             CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Treat given content tag by this module for the specified treatment mode, visualization mode and object.
  *
  * @param string $tag The CMS_XMLTag.
  * @param string $tagContent previous tag content.
  * @param integer $treatmentMode The current treatment mode (see constants on top of CMS_modulesTags class for accepted values).
  * @param integer $visualizationMode The current visualization mode (see constants on top of cms_page class for accepted values).
  * @param object $treatedObject The reference object to treat.
  * @param array $treatmentParameters : optionnal parameters used for the treatment. Usually an array of objects.
  * @return string the tag content treated.
  * @access public
  */
 function treatWantedTag(&$tag, $tagContent, $treatmentMode, $visualizationMode, &$treatedObject, $treatmentParameters)
 {
     switch ($treatmentMode) {
         case MODULE_TREATMENT_BLOCK_TAGS:
             if (!$treatedObject instanceof CMS_row) {
                 $this->raiseError('$treatedObject must be a CMS_row object');
                 return false;
             }
             if (!$treatmentParameters["page"] instanceof CMS_page) {
                 $this->raiseError('$treatmentParameters["page"] must be a CMS_page object');
                 return false;
             }
             if (!$treatmentParameters["language"] instanceof CMS_language) {
                 $this->raiseError('$treatmentParameters["language"] must be a CMS_language object');
                 return false;
             }
             if (!$treatmentParameters["clientSpace"] instanceof CMS_moduleClientspace) {
                 $this->raiseError('$treatmentParameters["clientSpace"] must be a CMS_moduleClientspace object');
                 return false;
             }
             if ($tag->getName() == 'row') {
                 //replace {{pageID}} tag in all page content.
                 return str_replace('{{pageID}}', $treatmentParameters["page"]->getID(), $tag->getInnerContent());
             } else {
                 //create the block data
                 $block = $tag->getRepresentationInstance();
                 return $block->getData($treatmentParameters["language"], $treatmentParameters["page"], $treatmentParameters["clientSpace"], $treatedObject, $visualizationMode);
             }
             break;
         case MODULE_TREATMENT_CLIENTSPACE_TAGS:
             if (!$treatedObject instanceof CMS_pageTemplate) {
                 $this->raiseError('$treatedObject must be a CMS_pageTemplate object');
                 return false;
             }
             if (!$treatmentParameters["page"] instanceof CMS_page) {
                 $this->raiseError('$treatmentParameters["page"] must be a CMS_page object');
                 return false;
             }
             if (!$treatmentParameters["language"] instanceof CMS_language) {
                 $this->raiseError('$treatmentParameters["language"] must be a CMS_language object');
                 return false;
             }
             $args = array("template" => $treatedObject->getID());
             if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_HTML_EDITION || $visualizationMode == PAGE_VISUALMODE_FORM) {
                 $args["editedMode"] = true;
             }
             //load CS datas
             switch ($tag->getName()) {
                 case 'atm-clientspace':
                 default:
                     $client_space = $tag->getRepresentationInstance($args);
                     switch ($visualizationMode) {
                         case PAGE_VISUALMODE_PRINT:
                             $data = "";
                             $clientSpacesData = array();
                             $csTagID = $tag->getAttribute("id");
                             $printingCS = $treatedObject->getPrintingClientSpaces();
                             if (in_array($csTagID, $printingCS)) {
                                 $clientSpacesData[$csTagID] = $client_space->getData($treatmentParameters["language"], $treatmentParameters["page"], $visualizationMode, $treatedObject->hasPages());
                             }
                             foreach ($printingCS as $cs) {
                                 if (isset($clientSpacesData[$cs])) {
                                     $data .= $clientSpacesData[$cs] . '<br />';
                                 }
                             }
                             return $data;
                             break;
                         default:
                             if (is_object($client_space)) {
                                 return $client_space->getData($treatmentParameters["language"], $treatmentParameters["page"], $visualizationMode, false);
                             } else {
                                 return '';
                             }
                             break;
                     }
                     break;
             }
             break;
         case MODULE_TREATMENT_LINXES_TAGS:
             switch ($tag->getName()) {
                 case "atm-linx":
                     //linx are visible only if target pages are published (public tree)
                     $linx_args = array("page" => $treatedObject, "publicTree" => true);
                     $linx = $tag->getRepresentationInstance($linx_args);
                     return $linx->getOutput(true);
                     break;
             }
             return '';
             break;
         case MODULE_TREATMENT_PAGECONTENT_TAGS:
             if (!$treatedObject instanceof CMS_page) {
                 $this->raiseError('$treatedObject must be a CMS_page object');
                 return false;
             }
             switch ($tag->getName()) {
                 case "atm-main-url":
                     return CMS_websitesCatalog::getMainURL();
                     break;
                 case "atm-keywords":
                     return '<meta name="keywords" content="' . SensitiveIO::sanitizeHTMLString($treatedObject->getKeywords($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC)) . '" />';
                     break;
                 case "atm-description":
                     return '<meta name="description" content="' . SensitiveIO::sanitizeHTMLString($treatedObject->getDescription($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC)) . '" />';
                     break;
                 case "atm-last-update":
                     $lastlog = CMS_log_catalog::getByResourceAction(MOD_STANDARD_CODENAME, $treatedObject->getID(), array(CMS_log::LOG_ACTION_RESOURCE_SUBMIT_DRAFT, CMS_log::LOG_ACTION_RESOURCE_DIRECT_VALIDATION), 1);
                     if (!$lastlog || !is_object($lastlog[0])) {
                         return '';
                     }
                     $user = $lastlog[0]->getUser();
                     $date = $lastlog[0]->getDateTime();
                     $dateformat = $tag->getAttribute("format") ? $tag->getAttribute("format") : 'Y-m-d';
                     $replace = array('{{date}}' => date($dateformat, $date->getTimestamp()), '{{firstname}}' => $user->getFirstName(), '{{lastname}}' => $user->getLastName());
                     return str_replace(array_keys($replace), $replace, $tag->getInnerContent());
                     break;
                 case "atm-print-link":
                     if ($treatedObject->getPrintStatus()) {
                         $template = $tag->getInnerContent();
                         if ($tag->getAttribute("keeprequest") == 'true') {
                             return '<?php echo \'' . str_replace("{{href}}", $treatedObject->getURL(true) . '\'.($_SERVER["QUERY_STRING"] ? \'?\'.$_SERVER["QUERY_STRING"] : \'\').\'', str_replace("\\\\'", "\\'", str_replace("'", "\\'", $template))) . '\' ?>';
                         } else {
                             return str_replace("{{href}}", $treatedObject->getURL(true), $template);
                         }
                     }
                     return '';
                     break;
                 case "atm-constant":
                     $const = SensitiveIO::stripPHPTags(io::strtoupper($tag->getAttribute("name")));
                     if (defined($const)) {
                         return constant($const);
                     }
                     return '';
                     break;
                 case "head":
                     $headCode = '<?php' . "\n" . '$atmHost = null;' . "\n" . '$atmPort = null;' . "\n" . 'if(isset($_SERVER["HTTP_HOST"])) {' . "\n" . '	$atmHost = @parse_url($_SERVER["HTTP_HOST"], PHP_URL_HOST) ? @parse_url($_SERVER["HTTP_HOST"], PHP_URL_HOST) : $_SERVER["HTTP_HOST"];' . "\n" . '	$atmPort = @parse_url($_SERVER[\'HTTP_HOST\'], PHP_URL_PORT) ? \':\'.@parse_url($_SERVER[\'HTTP_HOST\'], PHP_URL_PORT) : \'\';' . "\n" . '}' . "\n" . 'echo "\\t".\'<base href="//\'.$atmHost.$atmPort.PATH_REALROOT_WR.\'/" />\'."\\n";' . "\n" . ' ?>';
                     //Append base code
                     return preg_replace('#<head([^>]*)>#', '<head\\1>' . "\n" . $headCode, $tag->getContent());
                     break;
                 case "body":
                     $statsCode = '<?php if (SYSTEM_DEBUG && STATS_DEBUG) {echo CMS_stats::view();} ?>';
                     //Append stats code
                     return preg_replace('#</body>$#', $statsCode . "\n" . '</body>', $tag->getContent());
                     break;
                 case "html":
                     //Append DTD
                     return '<?php if (defined(\'APPLICATION_XHTML_DTD\')) echo APPLICATION_XHTML_DTD."\\n"; ?>' . "\n" . $tag->getContent();
                     break;
             }
             return '';
             break;
         case MODULE_TREATMENT_PAGEHEADER_TAGS:
             if (!$treatedObject instanceof CMS_page) {
                 $this->raiseError('$treatedObject must be a CMS_page object');
                 return false;
             }
             switch ($tag->getName()) {
                 case "atm-linx":
                     if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_FORM) {
                         //direct linx are visible even if target pages are not published (edited tree)
                         //all other linx are only visible if they are published (public tree)
                         $linx_args = array("page" => $treatedObject, "publicTree" => !($tag->getAttribute('type') == 'direct' || !$tag->getAttribute('type')));
                         $linx = $tag->getRepresentationInstance($linx_args);
                         $linx->setDebug(false);
                         $linx->setLog(false);
                         return $linx->getOutput();
                     } else {
                         //for public and print visualmode, this treatment is done by MODULE_TREATMENT_LINXES_TAGS mode during page file linx treatment
                         if ($visualizationMode != PAGE_VISUALMODE_HTML_PUBLIC && $visualizationMode != PAGE_VISUALMODE_PRINT) {
                             //linx are visible only if target pages are published (public tree)
                             $linx_args = array("page" => $treatedObject, "publicTree" => true);
                             $linx = $tag->getRepresentationInstance($linx_args);
                             return $linx->getOutput();
                         }
                     }
                     break;
                 case "atm-js-tags":
                 case "atm-css-tags":
                     $usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename);
                     $tagFiles = $tag->getAttribute('files');
                     $tagFiles = array_map('trim', explode(',', $tagFiles));
                     //only if current page use a block of this module
                     if ($tagFiles) {
                         //save in global var the page ID who use this tag
                         CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array($tag->getName() => true));
                         $return = '';
                         //overwrite previous modules return to append files of this module
                         //save new modules files
                         switch ($tag->getName()) {
                             case "atm-js-tags":
                                 //get old files for this tag already needed by other modules
                                 $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags");
                                 $files = is_array($files) ? $files : array();
                                 //append module js files
                                 $files = array_merge($files, $tagFiles);
                                 //append CMS_function.js file
                                 if (!isset($usage['js-files']) && file_exists(PATH_JS_FS . '/CMS_functions.js')) {
                                     $file = str_replace(PATH_REALROOT_FS . '/', '', PATH_JS_FS . '/CMS_functions.js');
                                     $files = array_merge($files, array($file));
                                 }
                                 //append swfobject for block flash
                                 if (is_array($usage) && isset($usage['blockflash']) && $usage['blockflash'] == true) {
                                     $files[] = 'swfobject';
                                 }
                                 //save files
                                 CMS_module::moduleUsage($treatedObject->getID(), $tag->getName(), $files, true);
                                 break;
                             case "atm-css-tags":
                                 //get old files for this tag already needed by other modules
                                 $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags");
                                 $files = is_array($files) ? $files : array();
                                 $media = $tag->getAttribute('media') ? $tag->getAttribute('media') : 'all';
                                 //append module css files
                                 if (!isset($files[$media])) {
                                     $files[$media] = array();
                                 }
                                 $files[$media] = array_merge($files[$media], $tagFiles);
                                 //save files
                                 CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags", $files, true);
                                 break;
                         }
                         //Create return for all saved modules files
                         switch ($tag->getName()) {
                             case "atm-js-tags":
                                 //get old files for this tag already needed by other modules
                                 $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags");
                                 //add files from atm-js-add tag
                                 $filesAdd = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags-add");
                                 $filesAdd = is_array($filesAdd) ? $filesAdd : array();
                                 $files = array_merge($files, $filesAdd);
                                 $return .= '<?php echo CMS_view::getJavascript(array(\'' . implode('\',\'', array_unique($files)) . '\')); ?>' . "\n";
                                 break;
                             case "atm-css-tags":
                                 $media = $tag->getAttribute('media') ? $tag->getAttribute('media') : 'all';
                                 //get old files for this tag already needed by other modules
                                 $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags");
                                 //add files from atm-css-add tag
                                 $filesAdd = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags-add");
                                 $filesAdd = is_array($filesAdd) ? $filesAdd : array();
                                 if (isset($files[$media])) {
                                     if (isset($filesAdd[$media])) {
                                         $files[$media] = array_merge($files[$media], $filesAdd[$media]);
                                     }
                                     $return .= '<?php echo CMS_view::getCSS(array(\'' . implode('\',\'', array_unique($files[$media])) . '\'), \'' . $media . '\'); ?>' . "\n";
                                 }
                                 break;
                         }
                         return $return;
                     }
                     break;
                 case "atm-meta-tags":
                     $attributes = array();
                     //normalize values for attributes
                     if ($tag->getAttributes()) {
                         $attributes = $tag->getAttributes();
                         foreach ($attributes as $tagName => $value) {
                             if ($attributes == '1' || $value == 'true') {
                                 $attributes[$tagName] = true;
                             } elseif ($value == '0' || $value == 'false') {
                                 $attributes[$tagName] = false;
                             }
                             if ($attributes[$tagName] !== false && $attributes[$tagName] !== true) {
                                 unset($attributes[$tagName]);
                             }
                         }
                     }
                     $metaDatas = $treatedObject->getMetaTags($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC, $attributes);
                     $usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename);
                     //if page template already use atm-js-tags tag, no need to add JS again
                     if (!is_array($usage) || !isset($usage['atm-js-tags'])) {
                         $metaDatas .= '	<script type="text/javascript" src="' . PATH_REALROOT_WR . '/js/CMS_functions.js"></script>' . "\n";
                         //save JS handled
                         CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('js-files' => true));
                     }
                     if ($visualizationMode == PAGE_VISUALMODE_FORM) {
                         global $cms_user;
                         $isValidator = is_object($cms_user) && $cms_user->hasPageClearance($treatedObject->getID(), CLEARANCE_PAGE_EDIT) && $cms_user->hasValidationClearance(MOD_STANDARD_CODENAME) ? 'true' : 'false';
                         //add needed javascripts
                         $metaDatas .= '<script type="text/javascript">' . "\n" . 'var atmRowsDatas = {};' . "\n" . 'var atmBlocksDatas = {};' . "\n" . 'var atmCSDatas = {};' . "\n" . 'var atmIsValidator = ' . $isValidator . ';' . "\n" . 'var atmIsValidable = true;' . "\n" . 'var atmHasPreview = true;' . "\n" . 'var atmHasPreview = true;' . "\n" . 'var CKEDITOR_BASEPATH = \'' . PATH_MAIN_WR . '/ckeditor/\';' . "\n" . '</script>';
                         //append JS from current view instance
                         $view = CMS_view::getInstance();
                         $metaDatas .= $view->getJavascript();
                         $metaDatas .= CMS_view::getCSS(array('edit'));
                     } else {
                         if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM) {
                             //add needed javascripts
                             $metaDatas .= '<script type="text/javascript">' . "\n" . 'var atmRowsDatas = {};' . "\n" . 'var atmBlocksDatas = {};' . "\n" . 'var atmCSDatas = {};' . "\n" . 'var atmIsValidator = false;' . "\n" . 'var atmIsValidable = false;' . "\n" . 'var atmHasPreview = false;' . "\n" . 'var CKEDITOR_BASEPATH = \'' . PATH_MAIN_WR . '/ckeditor/\';' . "\n" . '</script>';
                             //append JS from current view instance
                             $view = CMS_view::getInstance();
                             $metaDatas .= $view->getJavascript();
                             $metaDatas .= CMS_view::getCSS(array('edit'));
                         }
                     }
                     //if page template already use atm-js-tags tag, no need to add JS again
                     if (!is_array($usage) || !isset($usage['atm-js-tags'])) {
                         //if this page use a row block of this module then add the header code to the page
                         if (is_array($usage) && isset($usage['blockflash']) && $usage['blockflash'] == true) {
                             $metaDatas .= '<script type="text/javascript" src="' . PATH_MAIN_WR . '/swfobject/swfobject.js"></script>' . "\n";
                         }
                     }
                     return $metaDatas;
                     break;
             }
             return '';
             break;
         case MODULE_TREATMENT_WYSIWYG_INNER_TAGS:
             if ($tag->getName() == 'atm-linx') {
                 //linx from standard module
                 $domdocument = new CMS_DOMDocument();
                 try {
                     $domdocument->loadXML('<html>' . $tag->getContent() . '</html>');
                 } catch (DOMException $e) {
                     $this->raiseError('Parse error for atm-linx : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($tag->getContent()));
                     return '';
                 }
                 $nodespecs = $domdocument->getElementsByTagName('nodespec');
                 if ($nodespecs->length == 1) {
                     $nodespec = $nodespecs->item(0);
                 }
                 $htmltemplates = $domdocument->getElementsByTagName('htmltemplate');
                 if ($htmltemplates->length == 1) {
                     $htmltemplate = $htmltemplates->item(0);
                 }
                 $noselections = $domdocument->getElementsByTagName('noselection');
                 if ($noselections->length == 1) {
                     $noselection = $noselections->item(0);
                 }
                 if ($nodespec && $htmltemplate) {
                     //if ($paramsTags[0]->getName() == "nodespec" && $paramsTags[1]->getName() == "noselection" && $paramsTags[2]->getName() == "htmltemplate") {
                     if (isset($noselection)) {
                         // case noselection tag
                         $pageID = $nodespec->getAttribute("value");
                         $link = CMS_DOMDocument::DOMElementToString($htmltemplate, true);
                         $treatedLink = str_replace('href', 'noselection="true" href', str_replace('{{href}}', '{{' . $pageID . '}}', $link));
                     } else {
                         $pageID = $nodespec->getAttribute("value");
                         $link = CMS_DOMDocument::DOMElementToString($htmltemplate, true);
                         $treatedLink = str_replace('{{href}}', '{{' . $pageID . '}}', $link);
                     }
                 }
             } elseif ($tag->getName() == 'span') {
                 //linx from other module
                 $ids = explode('-', $tag->getAttribute('id'));
                 $selectedPageID = (int) $ids[1];
                 $noselection = $ids[2];
                 //then create the code to paste for the current selected object if any
                 if (sensitiveIO::isPositiveInteger($selectedPageID) && ($noselection == 'true' || $noselection == 'false')) {
                     $pattern = "/(.*)<a([^>]*)'\\.CMS_tree.*, 'url'\\)\\.'(.*)\\<\\/a>(.*)<\\/span>/U";
                     if ($noselection == 'true') {
                         $replacement = '<a noselection="true"\\2{{' . $selectedPageID . '}}\\3</a>';
                     } else {
                         $replacement = '<a\\2{{' . $selectedPageID . '}}\\3</a>';
                     }
                     $treatedLink = str_replace("\\'", "'", preg_replace($pattern, $replacement, $tag->getContent()));
                 }
             }
             return $treatedLink;
         case MODULE_TREATMENT_WYSIWYG_OUTER_TAGS:
             //Anchor
             if (preg_match('/^#([a-zA-Z0-9._{}:-]*)$/i', $tag->getAttribute('href')) > 0) {
                 //instanciate anchor tag
                 $anchor = new CMS_XMLTag_anchor($tag->getName(), $tag->getAttributes(), $tag->getChildren(), $tag->getParameters());
                 return $anchor->compute(array('mode' => $treatmentMode, 'visualization' => $visualizationMode, 'object' => $treatedObject, 'parameters' => $treatmentParameters));
             } elseif (preg_match('/^.*\\{\\{(\\d+)\\}\\}.*$/i', $tag->getAttribute('href')) > 0) {
                 //internal links
                 /* Pattern explanation :
                  *
                  * \<a([^>]*) : start with "<a" and any characters after except a ">". Content found into the "()" (first parameters of the link) is the first variable : "\\1"
                  * {{(\d+)}} : some numbers only into "{{" and "}}". Content found into the "()" (the page number) is the second variable : "\\2"
                  * (.*)\<\/a> : any characters after followed by "</a>". Content found into the "()" (last parameters of the link and link content) is the third variable : "\\3"
                  * /U : PCRE_UNGREEDY stop to the first finded occurence.
                  */
                 $pattern = "/<a([^>]*){{(\\d+)}}(.*)\\<\\/a>/Us";
                 if ($tag->getName() == 'a' && $treatmentParameters['module'] == MOD_STANDARD_CODENAME) {
                     if ($tag->getAttribute('noselection') == 'true') {
                         $replacement = "<atm-linx type=\"direct\"><selection><start><nodespec type=\"node\" value=\"\\2\"/></start></selection><noselection>" . $tag->getInnerContent() . "</noselection><display><htmltemplate><a\\1{{href}}\\3</a></htmltemplate></display></atm-linx>";
                         $treatedLink = preg_replace($pattern, $replacement, str_replace('noselection="true"', '', $tag->getContent()));
                     } else {
                         $replacement = "<atm-linx type=\"direct\"><selection><start><nodespec type=\"node\" value=\"\\2\"/></start></selection><display><htmltemplate><a\\1{{href}}\\3</a></htmltemplate></display></atm-linx>";
                         $treatedLink = preg_replace($pattern, $replacement, $tag->getContent());
                     }
                 } elseif ($tag->getName() == 'a' && $treatmentParameters['module'] != MOD_STANDARD_CODENAME) {
                     if ($tag->getAttribute('noselection') == 'true') {
                         $replacement = '<span id="' . MOD_STANDARD_CODENAME . '-\\2-true"><?php if (CMS_tree::pageExistsForUser(\\2)) { echo \'<a\\1\'.CMS_tree::getPageValue(\\2, \'url\').\'\\3</a>\';} else { echo ' . var_export($tag->getInnerContent(), true) . ';} ?><!--{elements:' . base64_encode(serialize(array('module' => array(0 => MOD_STANDARD_CODENAME)))) . '}--></span>';
                         $treatedLink = preg_replace($pattern, $replacement, str_replace(array('noselection="true"', "'"), array('', "\\'"), $tag->getContent()));
                     } else {
                         $replacement = '<span id="' . MOD_STANDARD_CODENAME . '-\\2-false"><?php if (CMS_tree::pageExistsForUser(\\2)) { echo \'<a\\1\'.CMS_tree::getPageValue(\\2, \'url\').\'\\3</a>\';} ?><!--{elements:' . base64_encode(serialize(array('module' => array(0 => MOD_STANDARD_CODENAME)))) . '}--></span>';
                         $treatedLink = preg_replace($pattern, $replacement, str_replace("'", "\\'", $tag->getContent()));
                     }
                 }
                 return $treatedLink;
             }
             break;
     }
     //in case of no tag treatment, simply return it
     return $tag->getContent();
 }
Exemplo n.º 6
0
 /**
  * Get the HTML form given the block HTML example data.
  *
  * @param CMS_language &$language The language of the administration frontend
  * @param CMS_page &$page The page which contains the client space
  * @param CMS_clientSpace &$clientSpace The client space which contains the row
  * @param CMS_row &$row The row which contains the block
  * @param integer $blockID The tag ID of the block
  * @param string $data The data to show as example
  * @return string The HTML form which can send to the page that will modify the block
  * @access private
  */
 protected function _getHTMLForm($language, &$page, &$clientSpace, &$row, $blockID, $data)
 {
     global $cms_user;
     $this->_jsBlockClass = 'Automne.blockCMS_Forms';
     $rawDatas = $this->getRawData($page->getID(), $clientSpace->getTagID(), $row->getTagID(), RESOURCE_LOCATION_EDITION, false);
     $datas = array('page' => isset($rawDatas['page']) ? $rawDatas['page'] : '', 'clientSpaceID' => isset($rawDatas['clientSpaceID']) ? $rawDatas['clientSpaceID'] : '', 'rowID' => isset($rawDatas['rowID']) ? $rawDatas['rowID'] : '', 'blockID' => isset($rawDatas['blockID']) ? $rawDatas['blockID'] : '', 'module' => MOD_CMS_FORMS_CODENAME);
     $this->_value = $datas;
     $html = parent::_getHTMLForm($language, $page, $clientSpace, $row, $blockID, '<div class="atm-form-block atm-block-helper">' . $data . '</div>');
     //load interface instance
     $view = CMS_view::getInstance();
     //append JS block class file
     if (PATH_REALROOT_WR) {
         $file = str_replace(PATH_REALROOT_WR . '/', '', PATH_ADMIN_WR . '/js/edit/block-cms-forms.js');
     } else {
         $file = PATH_ADMIN_WR . '/js/edit/block-cms-forms.js';
     }
     $view->addJSFile($file);
     return $html;
 }
Exemplo n.º 7
0
 /**
  * set object Values
  *
  * @param array $values : the POST result values
  * @param string prefixname : the prefix used for post names
  * @param boolean newFormat : new automne v4 format (default false for compatibility)
  * @param integer $objectID : the current object id. Must be set, but default is blank for compatibility with other objects
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValues($values, $prefixName, $newFormat = false, $objectID = '')
 {
     if (!sensitiveIO::isPositiveInteger($objectID)) {
         $this->raiseError('ObjectID must be a positive integer : ' . $objectID);
         return false;
     }
     //get field parameters
     $params = $this->getParamsValues();
     //get module codename
     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     if ($newFormat) {
         //delete old images ?
         //thumbnail
         if ($this->_subfieldValues[0]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_0'] || pathinfo($values[$prefixName . $this->_field->getID() . '_0'], PATHINFO_BASENAME) != $this->_subfieldValues[0]->getValue())) {
             @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
             $this->_subfieldValues[0]->setValue('');
         }
         //image zoom
         if ($this->_subfieldValues[2]->getValue() && (!isset($values[$prefixName . $this->_field->getID() . '_2']) || !$values[$prefixName . $this->_field->getID() . '_2'] || pathinfo($values[$prefixName . $this->_field->getID() . '_2'], PATHINFO_BASENAME) != $this->_subfieldValues[2]->getValue())) {
             @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
             $this->_subfieldValues[2]->setValue('');
         }
         //set label from label field
         if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_1']))) {
             return false;
         }
         //image zoom (if needed)
         if ((!isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) || $values[$prefixName . $this->_field->getID() . '_makeZoom'] != 1) && isset($values[$prefixName . $this->_field->getID() . '_2']) && $values[$prefixName . $this->_field->getID() . '_2'] && io::strpos($values[$prefixName . $this->_field->getID() . '_2'], PATH_UPLOAD_WR . '/') !== false) {
             $filename = $values[$prefixName . $this->_field->getID() . '_2'];
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //destroy old image if any
             if ($this->_subfieldValues[2]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $this->_subfieldValues[2]->setValue('');
             }
             //move and rename uploaded file
             $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename);
             $basename = pathinfo($filename, PATHINFO_BASENAME);
             //set thumbnail
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $zoomBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename));
             if (io::strlen($zoomBasename) > 255) {
                 $zoomBasename = sensitiveIO::ellipsis($zoomBasename, 255, '-', true);
             }
             $zoomFilename = $path . '/' . $zoomBasename;
             CMS_file::moveTo($filename, $zoomFilename);
             CMS_file::chmodFile(FILES_CHMOD, $zoomFilename);
             //set it
             if (!$this->_subfieldValues[2]->setValue($zoomBasename)) {
                 return false;
             }
         }
         //thumbnail
         if ($values[$prefixName . $this->_field->getID() . '_0'] && io::strpos($values[$prefixName . $this->_field->getID() . '_0'], PATH_UPLOAD_WR . '/') !== false) {
             $filename = $values[$prefixName . $this->_field->getID() . '_0'];
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //destroy old image if any
             if ($this->_subfieldValues[0]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
                 $this->_subfieldValues[0]->setValue('');
             }
             //move and rename uploaded file
             $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename);
             $basename = pathinfo($filename, PATHINFO_BASENAME);
             //set thumbnail
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $newBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename));
             //rename image
             $path_parts = pathinfo($newBasename);
             $extension = io::strtolower($path_parts['extension']);
             $newBasename = io::substr($path_parts['basename'], 0, -(io::strlen($extension) + 1)) . '_thumbnail.' . $extension;
             if (io::strlen($newBasename) > 255) {
                 $newBasename = sensitiveIO::ellipsis($newBasename, 255, '-', true);
             }
             $newFilename = $path . '/' . $newBasename;
             //move file from upload dir to new dir
             CMS_file::moveTo($filename, $newFilename);
             CMS_file::chmodFile(FILES_CHMOD, $newFilename);
             //if we use original image as image zoom, set it
             if (isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) && $values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                 $zoomFilename = str_replace('_thumbnail.' . $extension, '.' . $extension, $newFilename);
                 //copy image as zoom
                 CMS_file::copyTo($newFilename, $zoomFilename);
                 $zoomBasename = pathinfo($zoomFilename, PATHINFO_BASENAME);
                 //set image zoom
                 if (!$this->_subfieldValues[2]->setValue($zoomBasename)) {
                     return false;
                 }
             }
             //resize thumbnail if needed
             if ($params['maxWidth'] > 0 || $params['maxHeight'] > 0) {
                 $oImage = new CMS_image($newFilename);
                 //get current file size
                 $sizeX = $oImage->getWidth();
                 $sizeY = $oImage->getHeight();
                 //check thumbnail size
                 if ($params['maxWidth'] && $sizeX > $params['maxWidth'] || $params['maxHeight'] && $sizeY > $params['maxHeight']) {
                     $newSizeX = $sizeX;
                     $newSizeY = $sizeY;
                     // Check width
                     if ($params['maxWidth'] && $newSizeX > $params['maxWidth']) {
                         $newSizeY = round($params['maxWidth'] * $newSizeY / $newSizeX);
                         $newSizeX = $params['maxWidth'];
                     }
                     if ($params['maxHeight'] && $newSizeY > $params['maxHeight']) {
                         $newSizeX = round($params['maxHeight'] * $newSizeX / $newSizeY);
                         $newSizeY = $params['maxHeight'];
                     }
                     if (!$oImage->resize($newSizeX, $newSizeY, $newFilename)) {
                         return false;
                     }
                 }
             }
             //set thumbnail
             if (!$this->_subfieldValues[0]->setValue($newBasename)) {
                 return false;
             }
         }
         // If label not set yet, set it
         /*if(!$this->_subfieldValues[1]->getValue()){
         			if($this->_subfieldValues[0]->getValue()){
         				$this->_subfieldValues[1]->setValue($this->_subfieldValues[0]->getValue());
         			}
         		}*/
         //if we had an imagezoom, check his size
         if ($this->_subfieldValues[2]->getValue() && ($params['maxZoomWidth'] > 0 || $params['maxZoomHeight'] > 0)) {
             //resize zoom if needed
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $basename = $this->_subfieldValues[2]->getValue();
             $filename = $path . '/' . $basename;
             $extension = io::strtolower(pathinfo($basename, PATHINFO_EXTENSION));
             $oImage = new CMS_image($filename);
             //get current file size
             $sizeX = $oImage->getWidth();
             $sizeY = $oImage->getHeight();
             //check zoom size
             if ($params['maxZoomWidth'] && $sizeX > $params['maxZoomWidth'] || $params['maxZoomHeight'] && $sizeY > $params['maxZoomHeight']) {
                 $newSizeX = $sizeX;
                 $newSizeY = $sizeY;
                 // Check width
                 if ($params['maxZoomWidth'] && $newSizeX > $params['maxZoomWidth']) {
                     $newSizeY = round($params['maxZoomWidth'] * $newSizeY / $newSizeX);
                     $newSizeX = $params['maxZoomWidth'];
                 }
                 if ($params['maxZoomHeight'] && $newSizeY > $params['maxZoomHeight']) {
                     $newSizeX = round($params['maxZoomHeight'] * $newSizeX / $newSizeY);
                     $newSizeY = $params['maxZoomHeight'];
                 }
                 if (!$oImage->resize($newSizeX, $newSizeY, $filename)) {
                     return false;
                 }
             }
         }
         //update files infos if needed
         if ($this->_subfieldValues[0]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue())) {
             $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
             $imageDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension());
         } else {
             $imageDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => '');
         }
         $imageDatas['module'] = $moduleCodename;
         $imageDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED;
         if ($params['useDistinctZoom'] || $this->_subfieldValues[2]->getValue()) {
             //update files infos if needed
             if ($this->_subfieldValues[2]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue())) {
                 $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $zoomDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension());
             } else {
                 $zoomDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => '');
             }
             $zoomDatas['module'] = $moduleCodename;
             $zoomDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED;
         } else {
             $zoomDatas = '';
         }
         $content = array('datas' => array('polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_0]' => $imageDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_2]' => $zoomDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_1]' => sensitiveIO::decodeEntities($this->_subfieldValues[1]->getValue())));
         $view = CMS_view::getInstance();
         $view->addContent($content);
         return true;
     } else {
         //Old format
         //delete old images ?
         if (isset($values[$prefixName . $this->_field->getID() . '_delete']) && $values[$prefixName . $this->_field->getID() . '_delete'] == 1) {
             if ($this->_subfieldValues[0]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
                 $this->_subfieldValues[0]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_0_hidden']);
                 $this->_subfieldValues[0]->setValue('');
             }
             if ($this->_subfieldValues[2]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $this->_subfieldValues[2]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_2_hidden']);
                 $this->_subfieldValues[2]->setValue('');
             }
         }
         //set label from label field
         if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars(@$values[$prefixName . $this->_field->getID() . '_1']))) {
             return false;
         }
         //thumbnail
         if (isset($_FILES[$prefixName . $this->_field->getID() . '_0']) && $_FILES[$prefixName . $this->_field->getID() . '_0']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_0']['error']) {
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_0']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //set label as image name if none set
             /*if (!$values[$prefixName.$this->_field->getID().'_1']) {
             			if (!$this->_subfieldValues[1]->setValue(io::htmlspecialchars($_FILES[$prefixName.$this->_field->getID().'_0']["name"]))) {
             				return false;
             			}
             		}*/
             //destroy all old images if any
             if ($this->_subfieldValues[0]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[0]->getValue());
                 $this->_subfieldValues[0]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_0_hidden']);
                 $this->_subfieldValues[0]->setValue('');
             }
             if ($this->_subfieldValues[2]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[2]->getValue());
                 $this->_subfieldValues[2]->setValue('');
             } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_2_hidden']);
                 $this->_subfieldValues[2]->setValue('');
             }
             //set thumbnail (resize it if needed)
             //create thumbnail path
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_0']["name"]));
             if (io::strlen($filename) > 255) {
                 $filename = sensitiveIO::ellipsis($filename, 255, '-', true);
             }
             //move uploaded file
             $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_0', PATH_TMP_FS);
             if ($fileDatas['error']) {
                 return false;
             }
             if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) {
                 return false;
             }
             if ($params['maxWidth'] > 0) {
                 $oImage = new CMS_image($path . "/" . $filename);
                 //get current file size
                 $sizeX = $oImage->getWidth();
                 $sizeY = $oImage->getHeight();
                 //check thumbnail size
                 if ($sizeX > $params['maxWidth'] || $sizeY > $params['maxHeight']) {
                     $newSizeX = $sizeX;
                     $newSizeY = $sizeY;
                     // Check width
                     if ($params['maxWidth'] && $newSizeX > $params['maxWidth']) {
                         $newSizeY = round($params['maxWidth'] * $newSizeY / $newSizeX);
                         $newSizeX = $params['maxWidth'];
                     }
                     if ($params['maxHeight'] && $newSizeY > $params['maxHeight']) {
                         $newSizeX = round($params['maxHeight'] * $newSizeX / $newSizeY);
                         $newSizeY = $params['maxHeight'];
                     }
                     //resize image
                     $srcfilepath = $path . "/" . $filename;
                     $path_parts = pathinfo($srcfilepath);
                     $thumbnailFilename = io::substr($path_parts['basename'], 0, -(io::strlen($path_parts['extension']) + 1)) . '_thumbnail.' . $path_parts['extension'];
                     $destfilepath = $path . "/" . $thumbnailFilename;
                     $extension = io::strtolower($path_parts['extension']);
                     if (!$oImage->resize($newSizeX, $newSizeY, $destfilepath)) {
                         return false;
                     }
                     //if we use original image as image zoom, set it
                     if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                         //set image zoom
                         if (!$this->_subfieldValues[2]->setValue($filename)) {
                             return false;
                         }
                     } else {
                         //destroy original image
                         unlink($srcfilepath);
                     }
                     //set resized thumbnail
                     if (!$this->_subfieldValues[0]->setValue($thumbnailFilename)) {
                         return false;
                     }
                 } else {
                     //no need to resize thumbnail (below the maximum width), so set it
                     if (!$this->_subfieldValues[0]->setValue($filename)) {
                         return false;
                     }
                     //if we use original image as image zoom, set it
                     if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                         //set image zoom
                         if (!$this->_subfieldValues[2]->setValue($filename)) {
                             return false;
                         }
                     }
                 }
             } else {
                 //no need to resize thumbnail, so set it
                 if (!$this->_subfieldValues[0]->setValue($filename)) {
                     return false;
                 }
                 //if we use original image as image zoom, set it
                 if ($values[$prefixName . $this->_field->getID() . '_makeZoom'] == 1) {
                     //set image zoom
                     if (!$this->_subfieldValues[2]->setValue($filename)) {
                         return false;
                     }
                 }
             }
         } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_0']) && $_FILES[$prefixName . $this->_field->getID() . '_0']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_0']['error'] != 0) {
             return false;
         } elseif (isset($values[$prefixName . $this->_field->getID() . '_0_hidden']) && $values[$prefixName . $this->_field->getID() . '_0_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) {
             //set label as image name if none set
             if (!$this->_subfieldValues[0]->setValue($values[$prefixName . $this->_field->getID() . '_0_hidden'])) {
                 return false;
             }
         }
         //image zoom (if needed)
         if (isset($values[$prefixName . $this->_field->getID() . '_makeZoom']) && $values[$prefixName . $this->_field->getID() . '_makeZoom'] != 1 && isset($_FILES[$prefixName . $this->_field->getID() . '_2']['name']) && $_FILES[$prefixName . $this->_field->getID() . '_2']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_2']['error']) {
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_2']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //create thumbnail path
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_2']["name"]));
             if (io::strlen($filename) > 255) {
                 $filename = sensitiveIO::ellipsis($filename, 255, '-', true);
             }
             //move uploaded file
             $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_2', PATH_TMP_FS);
             if ($fileDatas['error']) {
                 return false;
             }
             if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) {
                 return false;
             }
             //set it
             if (!$this->_subfieldValues[2]->setValue($filename)) {
                 return false;
             }
         } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_2']) && $_FILES[$prefixName . $this->_field->getID() . '_2']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_2']['error'] != 0) {
             return false;
         } elseif (isset($values[$prefixName . $this->_field->getID() . '_2_hidden']) && $values[$prefixName . $this->_field->getID() . '_2_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) {
             if (!$this->_subfieldValues[2]->setValue($values[$prefixName . $this->_field->getID() . '_2_hidden'])) {
                 return false;
             }
         }
         return true;
     }
 }
Exemplo n.º 8
0
 /**
  * set object Values
  *
  * @param array $values : the POST result values
  * @param string $prefixname : the prefix used for post names
  * @param boolean newFormat : new automne v4 format (default false for compatibility)
  * @param integer $objectID : the current object id. Must be set, but default is blank for compatibility with other objects
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValues($values, $prefixName, $newFormat = false, $objectID = '')
 {
     if (!sensitiveIO::isPositiveInteger($objectID)) {
         $this->raiseError('ObjectID must be a positive integer : ' . $objectID);
         return false;
     }
     //get module codename
     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     //create a sub prefix for CMS_dialog_href object
     $subPrefixName = 'href' . $prefixName . $this->_field->getID() . '_0';
     //create object CMS_href & CMS_dialog_href
     $hrefDialog = new CMS_dialog_href(new CMS_href($this->_subfieldValues[0]->getValue()), $subPrefixName);
     if ($newFormat) {
         $hrefDialog->create($values[$subPrefixName], $moduleCodename, $objectID, $this->_field->getID());
         if ($hrefDialog->hasError()) {
             return false;
         }
         $href = $hrefDialog->getHREF();
         if (!$this->_subfieldValues[0]->setValue($href->getTextDefinition())) {
             return false;
         }
         $content = array('datas' => array('polymodFieldsValue[' . $subPrefixName . ']' => sensitiveIO::decodeEntities($this->_subfieldValues[0]->getValue())));
         $view = CMS_view::getInstance();
         $view->addContent($content);
     } else {
         //check for http://
         if ($values[$subPrefixName . 'link_external'] && io::strpos($values[$subPrefixName . 'link_external'], 'http://') !== 0) {
             $values[$subPrefixName . 'link_external'] = 'http://' . $values[$subPrefixName . 'link_external'];
         }
         $hrefDialog->doPost($moduleCodename, $objectID, $this->_field->getID());
         if ($hrefDialog->hasError()) {
             return false;
         }
         $href = $hrefDialog->getHREF();
         if (!$this->_subfieldValues[0]->setValue($href->getTextDefinition())) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * set object Values
  *
  * @param array $values : the POST result values
  * @param string prefixname : the prefix used for post names
  * @param boolean newFormat : new automne v4 format (default false for compatibility)
  * @param integer $objectID : the current object id. Must be set, but default is blank for compatibility with other objects
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValues($values, $prefixName, $newFormat = false, $objectID = '')
 {
     if (!sensitiveIO::isPositiveInteger($objectID)) {
         $this->raiseError('ObjectID must be a positive integer : ' . $objectID);
         return false;
     }
     //get field parameters
     $params = $this->getParamsValues();
     //get module codename
     $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
     if ($newFormat) {
         //delete old files ?
         //thumbnail
         if ($this->_subfieldValues[1]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_1'] || pathinfo($values[$prefixName . $this->_field->getID() . '_1'], PATHINFO_BASENAME) != $this->_subfieldValues[1]->getValue())) {
             @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue());
             $this->_subfieldValues[1]->setValue('');
         }
         //file
         if ($this->_subfieldValues[4]->getValue() && (!$values[$prefixName . $this->_field->getID() . '_4'] || pathinfo($values[$prefixName . $this->_field->getID() . '_4'], PATHINFO_BASENAME) != $this->_subfieldValues[4]->getValue())) {
             @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
             $this->_subfieldValues[4]->setValue('');
             //reset filesize
             if (!$this->_subfieldValues[2]->setValue(0)) {
                 return false;
             }
         }
         if (!(isset($values[$prefixName . $this->_field->getID() . '_0']) && $this->_subfieldValues[0]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_0'])))) {
             return false;
         }
         //thumbnail
         if (isset($values[$prefixName . $this->_field->getID() . '_1']) && $values[$prefixName . $this->_field->getID() . '_1'] && io::strpos($values[$prefixName . $this->_field->getID() . '_1'], PATH_UPLOAD_WR . '/') !== false) {
             $filename = $values[$prefixName . $this->_field->getID() . '_1'];
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //destroy old image if any
             if ($this->_subfieldValues[1]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue());
                 $this->_subfieldValues[1]->setValue('');
             }
             //move and rename uploaded file
             $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $filename);
             $basename = pathinfo($filename, PATHINFO_BASENAME);
             //set thumbnail
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $newBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename));
             //rename image
             $path_parts = pathinfo($newBasename);
             $extension = io::strtolower($path_parts['extension']);
             $newBasename = io::substr($path_parts['basename'], 0, -(io::strlen($extension) + 1)) . '_thumbnail.' . $extension;
             if (io::strlen($newBasename) > 255) {
                 $newBasename = sensitiveIO::ellipsis($newBasename, 255, '-', true);
             }
             $newFilename = $path . '/' . $newBasename;
             //move file from upload dir to new dir
             CMS_file::moveTo($filename, $newFilename);
             CMS_file::chmodFile(FILES_CHMOD, $newFilename);
             //resize thumbnail if needed
             if ($params['thumbMaxWidth'] > 0 || $params['thumbMaxHeight'] > 0) {
                 $oImage = new CMS_image($newFilename);
                 //get current file size
                 $sizeX = $oImage->getWidth();
                 $sizeY = $oImage->getHeight();
                 //check thumbnail size
                 list($sizeX, $sizeY) = @getimagesize($newFilename);
                 if ($params['thumbMaxWidth'] && $sizeX > $params['thumbMaxWidth'] || $params['thumbMaxHeight'] && $sizeY > $params['thumbMaxHeight']) {
                     $newSizeX = $sizeX;
                     $newSizeY = $sizeY;
                     // Check width
                     if ($params['thumbMaxWidth'] && $newSizeX > $params['thumbMaxWidth']) {
                         $newSizeY = round($params['thumbMaxWidth'] * $newSizeY / $newSizeX);
                         $newSizeX = $params['thumbMaxWidth'];
                     }
                     if ($params['thumbMaxHeight'] && $newSizeY > $params['thumbMaxHeight']) {
                         $newSizeX = round($params['thumbMaxHeight'] * $newSizeX / $newSizeY);
                         $newSizeY = $params['thumbMaxHeight'];
                     }
                     if (!$oImage->resize($newSizeX, $newSizeY, $newFilename)) {
                         return false;
                     }
                 }
             }
             //set thumbnail
             if (!$this->_subfieldValues[1]->setValue($newBasename)) {
                 return false;
             }
         }
         //File
         //1- from external location
         if (isset($values[$prefixName . $this->_field->getID() . '_externalfile']) && $values[$prefixName . $this->_field->getID() . '_externalfile']) {
             //from FTP directory
             $filename = $values[$prefixName . $this->_field->getID() . '_externalfile'];
             //check file extension
             if ($params['allowedType'] || $params['disallowedType']) {
                 $extension = io::strtolower(pathinfo($filename, PATHINFO_EXTENSION));
                 if (!$extension) {
                     return false;
                 }
                 //extension must be in allowed list
                 if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) {
                     return false;
                 }
                 //extension must not be in disallowed list
                 if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) {
                     return false;
                 }
             }
             //destroy old file if any
             if ($this->_subfieldValues[4]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
                 $this->_subfieldValues[4]->setValue('');
             }
             $new_filename = 'r' . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($filename));
             if (io::strlen($new_filename) > 255) {
                 $new_filename = sensitiveIO::ellipsis($new_filename, 255, '-', true);
             }
             $destination_path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/';
             $ftp_dir = PATH_REALROOT_FS . $params['ftpDir'];
             if (@file_exists($ftp_dir . $filename) && is_file($ftp_dir . $filename)) {
                 if (CMS_file::moveTo($ftp_dir . $filename, $destination_path . '/' . $new_filename)) {
                     CMS_file::chmodFile(FILES_CHMOD, $destination_path . '/' . $new_filename);
                     //set label as file name if none set
                     if (!$values[$prefixName . $this->_field->getID() . '_0']) {
                         if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($filename))) {
                             return false;
                         }
                     }
                     //set it
                     if (!$this->_subfieldValues[4]->setValue($new_filename)) {
                         return false;
                     }
                     //and set filesize
                     $filesize = @filesize($destination_path . '/' . $new_filename);
                     if ($filesize !== false && $filesize > 0) {
                         //convert in MB
                         $filesize = round($filesize / 1048576, 2);
                     } else {
                         $filesize = '0';
                     }
                     if (!$this->_subfieldValues[2]->setValue($filesize)) {
                         return false;
                     }
                     //set file type
                     if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } else {
             //2- from post
             if ($values[$prefixName . $this->_field->getID() . '_4'] && io::strpos($values[$prefixName . $this->_field->getID() . '_4'], PATH_UPLOAD_WR . '/') !== false) {
                 //check file extension
                 if ($params['allowedType'] || $params['disallowedType']) {
                     $extension = io::strtolower(pathinfo($values[$prefixName . $this->_field->getID() . '_4'], PATHINFO_EXTENSION));
                     if (!$extension) {
                         return false;
                     }
                     //extension must be in allowed list
                     if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) {
                         return false;
                     }
                     //extension must not be in disallowed list
                     if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) {
                         return false;
                     }
                 }
                 //set file type
                 if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) {
                     return false;
                 }
                 //destroy old file if any
                 if ($this->_subfieldValues[4]->getValue()) {
                     @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
                     $this->_subfieldValues[4]->setValue('');
                 }
                 //move and rename uploaded file
                 $filename = str_replace(PATH_UPLOAD_WR . '/', PATH_UPLOAD_FS . '/', $values[$prefixName . $this->_field->getID() . '_4']);
                 $basename = pathinfo($filename, PATHINFO_BASENAME);
                 //create file path
                 $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
                 $newBasename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($basename));
                 if (io::strlen($newBasename) > 255) {
                     $newBasename = sensitiveIO::ellipsis($newBasename, 255, '-', true);
                 }
                 $newFilename = $path . '/' . $newBasename;
                 if (!CMS_file::moveTo($filename, $newFilename)) {
                     return false;
                 }
                 CMS_file::chmodFile(FILES_CHMOD, $newFilename);
                 //set it
                 if (!$this->_subfieldValues[4]->setValue($newBasename)) {
                     return false;
                 }
                 //and set filesize
                 $filesize = @filesize($newFilename);
                 if ($filesize !== false && $filesize > 0) {
                     //convert in MB
                     $filesize = round($filesize / 1048576, 2);
                 } else {
                     $filesize = '0';
                 }
                 if (!$this->_subfieldValues[2]->setValue($filesize)) {
                     return false;
                 }
             }
         }
         // If label not set yet, set it
         if (!$this->_subfieldValues[0]->getValue()) {
             if ($this->_subfieldValues[4]->getValue()) {
                 $this->_subfieldValues[0]->setValue($this->_subfieldValues[4]->getValue());
             }
         }
         //update files infos if needed
         if ($this->_subfieldValues[1]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue())) {
             $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue());
             $imageDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension());
         } else {
             $imageDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => '');
         }
         //update files infos if needed
         if ($this->_subfieldValues[4]->getValue() && file_exists(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue())) {
             $file = new CMS_file(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
             $fileDatas = array('filename' => $file->getName(false), 'filepath' => $file->getFilePath(CMS_file::WEBROOT), 'filesize' => $file->getFileSize(), 'fileicon' => $file->getFileIcon(CMS_file::WEBROOT), 'extension' => $file->getExtension());
         } else {
             $fileDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => '');
         }
         $imageDatas['module'] = $fileDatas['module'] = $moduleCodename;
         $imageDatas['visualisation'] = $fileDatas['visualisation'] = RESOURCE_DATA_LOCATION_EDITED;
         $content = array('datas' => array('polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_1]' => $imageDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_4]' => $fileDatas, 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_externalfile]' => '', 'polymodFieldsValue[' . $prefixName . $this->_field->getID() . '_0]' => sensitiveIO::decodeEntities($this->_subfieldValues[0]->getValue())));
         $view = CMS_view::getInstance();
         $view->addContent($content);
         return true;
     } else {
         //Old format
         //delete old files ?
         if (isset($values[$prefixName . $this->_field->getID() . '_delete']) && $values[$prefixName . $this->_field->getID() . '_delete'] == 1) {
             //thumbnail
             if ($this->_subfieldValues[1]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue());
                 $this->_subfieldValues[1]->setValue('');
             } elseif ($values[$prefixName . $this->_field->getID() . '_1_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_1_hidden']);
                 $this->_subfieldValues[1]->setValue('');
             }
             //file
             if ($this->_subfieldValues[4]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
                 $this->_subfieldValues[4]->setValue('');
             } elseif ($values[$prefixName . $this->_field->getID() . '_4_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_4_hidden']);
                 $this->_subfieldValues[4]->setValue('');
             }
             //reset filesize
             if (!$this->_subfieldValues[2]->setValue(0)) {
                 return false;
             }
         }
         if (!(isset($values[$prefixName . $this->_field->getID() . '_0']) && $this->_subfieldValues[0]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_0'])))) {
             return false;
         }
         //thumbnail
         if (isset($_FILES[$prefixName . $this->_field->getID() . '_1']) && $_FILES[$prefixName . $this->_field->getID() . '_1']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_1']['error']) {
             //check for image type before doing anything
             if (!in_array(io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_1']["name"], PATHINFO_EXTENSION)), $this->_allowedExtensions)) {
                 return false;
             }
             //destroy old image if any
             if ($this->_subfieldValues[1]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[1]->getValue());
                 $this->_subfieldValues[1]->setValue('');
             } elseif ($values[$prefixName . $this->_field->getID() . '_1_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_1_hidden']);
                 $this->_subfieldValues[1]->setValue('');
             }
             //set thumbnail (resize it if needed)
             //create thumbnail path
             $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
             $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_1']["name"]));
             if (io::strlen($filename) > 255) {
                 $filename = sensitiveIO::ellipsis($filename, 255, '-', true);
             }
             //move uploaded file
             $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_1', PATH_TMP_FS);
             if ($fileDatas['error']) {
                 return false;
             }
             if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) {
                 return false;
             }
             if ($params['thumbMaxWidth'] > 0 || $params['thumbMaxHeight'] > 0) {
                 $oImage = new CMS_image($path . "/" . $filename);
                 //get current file size
                 $sizeX = $oImage->getWidth();
                 $sizeY = $oImage->getHeight();
                 //check thumbnail size
                 if ($sizeX > $params['thumbMaxWidth'] || $sizeX > $params['thumbMaxHeight']) {
                     $newSizeX = $sizeX;
                     $newSizeY = $sizeY;
                     // Check width
                     if ($params['thumbMaxWidth'] && $newSizeX > $params['thumbMaxWidth']) {
                         $newSizeY = round($params['thumbMaxWidth'] * $newSizeY / $newSizeX);
                         $newSizeX = $params['thumbMaxWidth'];
                     }
                     if ($params['thumbMaxHeight'] && $newSizeY > $params['thumbMaxHeight']) {
                         $newSizeX = round($params['thumbMaxHeight'] * $newSizeX / $newSizeY);
                         $newSizeY = $params['thumbMaxHeight'];
                     }
                     //resize image
                     $srcfilepath = $path . "/" . $filename;
                     $path_parts = pathinfo($srcfilepath);
                     $thumbnailFilename = io::substr($path_parts['basename'], 0, -(io::strlen($path_parts['extension']) + 1)) . '.png';
                     $destfilepath = $path . "/" . $thumbnailFilename;
                     if (!$oImage->resize($newSizeX, $newSizeY, $destfilepath)) {
                         return false;
                     }
                     //destroy original image
                     @unlink($srcfilepath);
                     //set resized thumbnail
                     if (!$this->_subfieldValues[1]->setValue($thumbnailFilename)) {
                         return false;
                     }
                 } else {
                     //no need to resize thumbnail (below the maximum width), so set it
                     if (!$this->_subfieldValues[1]->setValue($filename)) {
                         return false;
                     }
                 }
             } else {
                 //no need to resize thumbnail (no size limit), so set it
                 if (!$this->_subfieldValues[1]->setValue($filename)) {
                     return false;
                 }
             }
         } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_1']) && $_FILES[$prefixName . $this->_field->getID() . '_1']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_1']['error'] != 0) {
             return false;
         } elseif (isset($values[$prefixName . $this->_field->getID() . '_1_hidden']) && $values[$prefixName . $this->_field->getID() . '_1_hidden'] && $values[$prefixName . $this->_field->getID() . '_delete'] != 1) {
             if (!$this->_subfieldValues[1]->setValue($values[$prefixName . $this->_field->getID() . '_1_hidden'])) {
                 return false;
             }
         }
         //File
         //1- from external location
         if (isset($values[$prefixName . $this->_field->getID() . '_externalfile']) && $values[$prefixName . $this->_field->getID() . '_externalfile']) {
             //destroy old file if any
             if ($this->_subfieldValues[4]->getValue()) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
                 $this->_subfieldValues[4]->setValue('');
             } elseif ($values[$prefixName . $this->_field->getID() . '_4_hidden']) {
                 @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $values[$prefixName . $this->_field->getID() . '_4_hidden']);
                 $this->_subfieldValues[4]->setValue('');
             }
             //from FTP directory
             $filename = $values[$prefixName . $this->_field->getID() . '_externalfile'];
             //io::substr($values[$prefixName.$this->_field->getID().'_externalfile'], 1);
             //check file extension
             if ($params['allowedType'] || $params['disallowedType']) {
                 $extension = io::strtolower(pathinfo($filename, PATHINFO_EXTENSION));
                 if (!$extension) {
                     return false;
                 }
                 //extension must be in allowed list
                 if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) {
                     return false;
                 }
                 //extension must not be in disallowed list
                 if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) {
                     return false;
                 }
             }
             $new_filename = 'r' . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($filename));
             if (io::strlen($new_filename) > 255) {
                 $new_filename = sensitiveIO::ellipsis($new_filename, 255, '-', true);
             }
             $destination_path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/';
             $ftp_dir = PATH_REALROOT_FS . $params['ftpDir'];
             if (@file_exists($ftp_dir . $filename) && is_file($ftp_dir . $filename)) {
                 if (@copy($ftp_dir . $filename, $destination_path . '/' . $new_filename)) {
                     @chmod($destination_path . '/' . $new_filename, octdec(FILES_CHMOD));
                     //set label as file name if none set
                     if (!$values[$prefixName . $this->_field->getID() . '_0']) {
                         if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($filename))) {
                             return false;
                         }
                     }
                     //set it
                     if (!$this->_subfieldValues[4]->setValue($new_filename)) {
                         return false;
                     }
                     //and set filesize
                     $filesize = @filesize($destination_path . '/' . $new_filename);
                     if ($filesize !== false && $filesize > 0) {
                         //convert in MB
                         $filesize = round($filesize / 1048576, 2);
                     } else {
                         $filesize = '0';
                     }
                     if (!$this->_subfieldValues[2]->setValue($filesize)) {
                         return false;
                     }
                     //set file type
                     if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } else {
             //2- from post
             if (isset($_FILES[$prefixName . $this->_field->getID() . '_4']) && $_FILES[$prefixName . $this->_field->getID() . '_4']['name'] && !$_FILES[$prefixName . $this->_field->getID() . '_4']['error']) {
                 //check file extension
                 if ($params['allowedType'] || $params['disallowedType']) {
                     $extension = io::strtolower(pathinfo($_FILES[$prefixName . $this->_field->getID() . '_4']['name'], PATHINFO_EXTENSION));
                     if (!$extension) {
                         return false;
                     }
                     //extension must be in allowed list
                     if ($params['allowedType'] && !in_array($extension, explode(',', io::strtolower($params['allowedType'])))) {
                         return false;
                     }
                     //extension must not be in disallowed list
                     if ($params['disallowedType'] && in_array($extension, explode(',', io::strtolower($params['disallowedType'])))) {
                         return false;
                     }
                 }
                 //set label as image name if none set
                 if (!$values[$prefixName . $this->_field->getID() . '_0']) {
                     if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($_FILES[$prefixName . $this->_field->getID() . '_4']["name"]))) {
                         return false;
                     }
                 }
                 //set file type
                 if (!$this->_subfieldValues[3]->setValue(self::OBJECT_FILE_TYPE_INTERNAL)) {
                     return false;
                 }
                 //destroy old file if any
                 if ($this->_subfieldValues[4]->getValue()) {
                     @unlink(PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED . '/' . $this->_subfieldValues[4]->getValue());
                     $this->_subfieldValues[4]->setValue('');
                 }
                 //create thumnail path
                 $path = PATH_MODULES_FILES_FS . '/' . $moduleCodename . '/' . RESOURCE_DATA_LOCATION_EDITED;
                 $filename = "r" . $objectID . "_" . $this->_field->getID() . "_" . io::strtolower(SensitiveIO::sanitizeAsciiString($_FILES[$prefixName . $this->_field->getID() . '_4']["name"]));
                 if (io::strlen($filename) > 255) {
                     $filename = sensitiveIO::ellipsis($filename, 255, '-', true);
                 }
                 //move uploaded file
                 $fileDatas = CMS_file::uploadFile($prefixName . $this->_field->getID() . '_4', PATH_TMP_FS);
                 if ($fileDatas['error']) {
                     return false;
                 }
                 if (!CMS_file::moveTo(PATH_TMP_FS . '/' . $fileDatas['filename'], $path . "/" . $filename)) {
                     return false;
                 }
                 //set it
                 if (!$this->_subfieldValues[4]->setValue($filename)) {
                     return false;
                 }
                 //and set filesize
                 $filesize = @filesize($path . "/" . $filename);
                 if ($filesize !== false && $filesize > 0) {
                     //convert in MB
                     $filesize = round($filesize / 1048576, 2);
                 } else {
                     $filesize = '0';
                 }
                 if (!$this->_subfieldValues[2]->setValue($filesize)) {
                     return false;
                 }
             } elseif (isset($_FILES[$prefixName . $this->_field->getID() . '_4']) && $_FILES[$prefixName . $this->_field->getID() . '_4']['name'] && $_FILES[$prefixName . $this->_field->getID() . '_4']['error'] != 0) {
                 return false;
             } else {
                 //from hidden fields (previously set but not already saved)
                 if (isset($values[$prefixName . $this->_field->getID() . '_4_hidden']) && $values[$prefixName . $this->_field->getID() . '_4_hidden'] && (!isset($values[$prefixName . $this->_field->getID() . '_delete']) || $values[$prefixName . $this->_field->getID() . '_delete'] != 1)) {
                     //set label as image name if none set
                     if ($values[$prefixName . $this->_field->getID() . '_0']) {
                         if (!$this->_subfieldValues[0]->setValue(io::htmlspecialchars($values[$prefixName . $this->_field->getID() . '_0']))) {
                             return false;
                         }
                     }
                     //set filesize
                     if (!$this->_subfieldValues[2]->setValue($values[$prefixName . $this->_field->getID() . '_2_hidden'])) {
                         return false;
                     }
                     //set file type
                     if (!$this->_subfieldValues[3]->setValue($values[$prefixName . $this->_field->getID() . '_3_hidden'])) {
                         return false;
                     }
                     if (!$this->_subfieldValues[4]->setValue($values[$prefixName . $this->_field->getID() . '_4_hidden'])) {
                         return false;
                     }
                 }
             }
         }
         // If label not set yet, set it
         if (!$this->_subfieldValues[0]->getValue()) {
             if ($this->_subfieldValues[4]->getValue()) {
                 $this->_subfieldValues[0]->setValue($this->_subfieldValues[4]->getValue());
             }
         }
         return true;
     }
 }
Exemplo n.º 10
0
        if (file_exists($pageURL)) {
            $redirectTo = $page->getURL(substr($basename, 0, 5) == 'print' ? true : false);
        } else {
            //try to regenerate page
            if ($page->regenerate(true)) {
                clearstatcache();
                if (file_exists($pageURL)) {
                    $redirectTo = $page->getURL(substr($basename, 0, 5) == 'print' ? true : false);
                }
            }
        }
    }
}
//do redirection to page if found
if ($redirectTo) {
    CMS_view::redirect($redirectTo . (isset($_SERVER['REDIRECT_QUERY_STRING']) ? '?' . $_SERVER['REDIRECT_QUERY_STRING'] : ''), true, 301);
}
//then if no page found, display 404 error page
header('HTTP/1.x 404 Not Found', true, 404);
//Check if requested file is an image
$imagesExtensions = array('jpg', 'jpeg', 'gif', 'png', 'ico');
if (isset($pathinfo['extension']) && in_array(strtolower($pathinfo['extension']), $imagesExtensions)) {
    if (file_exists(PATH_REALROOT_FS . '/img/404.png')) {
        CMS_file::downloadFile(PATH_REALROOT_FS . '/img/404.png');
    }
}
//send an email if needed
if (ERROR404_EMAIL_ALERT && sensitiveIO::isValidEmail(APPLICATION_MAINTAINER_EMAIL)) {
    $body = "A 404 Error occured on your website.\n";
    $body .= "\n\n";
    $body .= 'The requested file : ' . CMS_websitesCatalog::getMainURL() . $_SERVER['REQUEST_URI'] . ' was not found.' . "\n\n";
Exemplo n.º 11
0
 /**
  * Set user by xml definition. Return XML
  *
  * @access public
  * @param string $xmlInput XML definition to define user properties
  * @return boolean True on success, false on failure
  */
 function setSoapValues($domdocument)
 {
     $view = CMS_view::getInstance();
     $contactData = new CMS_contactData();
     $currentPassword = '';
     $newGroups = array();
     foreach ($domdocument->childNodes as $childNode) {
         if ($childNode->nodeType == XML_ELEMENT_NODE) {
             switch ($childNode->tagName) {
                 case 'contactData':
                     foreach ($childNode->childNodes as $cdChildNode) {
                         if ($cdChildNode->nodeType == XML_ELEMENT_NODE) {
                             if (!$contactData->setValue($cdChildNode->tagName, $cdChildNode->nodeValue)) {
                                 $view->addError('Invalid value for contactData tag ' . $cdChildNode->tagName . ' and value ' . $cdChildNode->nodeValue);
                                 return false;
                             }
                         } elseif ($cdChildNode->nodeType == XML_TEXT_NODE && trim($cdChildNode->nodeValue)) {
                             $view->addError('Unknown xml content contactData tag ' . $cdChildNode->nodeValue . ' to process.');
                             return false;
                         }
                     }
                     break;
                 case 'groups':
                     foreach ($childNode->childNodes as $groupChildNode) {
                         if ($groupChildNode->nodeType == XML_ELEMENT_NODE) {
                             $group = CMS_profile_usersGroupsCatalog::getByID($groupChildNode->nodeValue);
                             if ($group && !$group->hasError()) {
                                 $newGroups[$group->getGroupId()] = $group->getGroupId();
                             } else {
                                 $view->addError('Unknown group ID ' . $groupChildNode->nodeValue . '.');
                                 return false;
                             }
                         } elseif ($cdChildNode->nodeType == XML_TEXT_NODE && trim($cdChildNode->nodeValue)) {
                             $view->addError('Unknown xml content contactData tag ' . $cdChildNode->nodeValue . ' to process.');
                             return false;
                         }
                     }
                     break;
                 default:
                     if (!$this->setValue($childNode->tagName, $childNode->nodeValue)) {
                         $view->addError('Invalid value for tag ' . $childNode->tagName . ' and value ' . $childNode->nodeValue);
                         return false;
                     }
                     if ($childNode->tagName == 'password') {
                         $currentPassword = $childNode->nodeValue;
                     }
                     break;
             }
         } elseif ($childNode->nodeType == XML_TEXT_NODE && trim($childNode->nodeValue)) {
             $view->addError('Unknown xml content tag ' . $childNode->nodeValue . ' to process.');
             return false;
         }
     }
     // Check user required fields.
     if ($this->hasError()) {
         $view->addError('Values to set are invalid.');
         return false;
     }
     if ($currentPassword == $this->getValue('login')) {
         $view->addError('Login and password must be different.');
         return false;
     }
     if ($this->getValue('login') && $contactData->getValue('email')) {
         // Save contact data object
         if ($contactData->writeToPersistence() && $this->setValue('contactData', $contactData)) {
             // Get current user groups ids
             $userGroupIds = CMS_profile_usersGroupsCatalog::getGroupsOfUser($this, true, true);
             // First reset profile clearances
             $this->resetClearances();
             // Second, loop through user groups to remove group
             foreach ($userGroupIds as $oldGroupId) {
                 if (!in_array($oldGroupId, $newGroups)) {
                     // Remove user to group
                     $oldGroup = CMS_profile_usersGroupsCatalog::getByID($oldGroupId);
                     if (!$oldGroup->removeUser($this) || !$oldGroup->writeToPersistence()) {
                         $view->addError('Error deleting user\'s group : ' . $oldGroupId);
                         return false;
                     }
                 }
             }
             // Third, loop through user groups to add groups
             foreach ($newGroups as $newGroupId) {
                 if (!in_array($newGroupId, $userGroupIds)) {
                     $newGroup = CMS_profile_usersGroupsCatalog::getByID($newGroupId);
                     if ($newGroup && !$newGroup->hasError()) {
                         // Add group to user
                         $this->addGroup($newGroupId);
                     } else {
                         $view->addError('Error adding user\'s group : ' . $newGroupId);
                         return false;
                     }
                 }
             }
             //Clear polymod cache
             //CMS_cache::clearTypeCacheByMetas('polymod', array('resource' => 'users'));
             CMS_cache::clearTypeCache('polymod');
             return true;
         } else {
             $view->addError('Error saving contactData.');
             return false;
         }
     } else {
         $view->addError('Missing values to set user. Check the login, password and email.');
     }
     return false;
 }
Exemplo n.º 12
0
		}
		/*close login window*/
		Ext.WindowMgr.get(\'loginWindow\').close();';
            //eval content into parent
            $jscontent = '
		try {delete parent.Ext.Element.cache[\'loginField\'];} catch (e) {}
		parent.eval(\'' . sensitiveIO::sanitizeJSString($jscontent, true) . '\');';
            $view->addJavascript($jscontent);
            $view->show(CMS_view::SHOW_HTML);
        } else {
            //Disconnect user
            CMS_session::authenticate(array('disconnect' => true, 'type' => 'admin'));
            //Reset session (start fresh)
            Zend_Session::destroy();
            //Redirect
            CMS_view::redirect($_SERVER['SCRIPT_NAME'] . '?cms_action=wrongcredentials', true, 301);
        }
        break;
    case 'wrongcredentials':
        //display error login window on top of login form
        $loginError = "\n\t\tparent.Automne.message.popup({\n\t\t\tmsg: '{$cms_language->getJsMessage(MESSAGE_ERROR_LOGIN_INCORRECT)}',\n\t\t\tbuttons: Ext.MessageBox.OK,\n\t\t\ticon: Ext.MessageBox.ERROR,\n\t\t\tfn:function() {\n\t\t\t\tExt.fly('loginField').dom.select();\n\t\t\t}\n\t\t});";
        break;
}
//Send Login form frame window (in which login form is displayed)
//set main and ext CSS
$view->addCSSFile('ext');
$view->addCSSFile('main');
$view->addCSSFile('codemirror');
if (SYSTEM_DEBUG) {
    $view->addCSSFile('debug');
}
Exemplo n.º 13
0
}
$rootPage = $website->getRoot();
if ($rootPage->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
    //redirect to subpage if any
    $redirectlink = $rootPage->getRedirectLink(true);
    while ($redirectlink && $redirectlink->hasValidHREF() && sensitiveIO::IsPositiveInteger($redirectlink->getInternalLink())) {
        $rootPage = new CMS_page($redirectlink->getInternalLink());
        if ($rootPage->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
            $redirectlink = $rootPage->getRedirectLink(true);
        } else {
            $redirectlink = '';
        }
    }
}
$pPath = $rootPage->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM);
if ($pPath) {
    if (file_exists($pPath)) {
        $cms_page_included = true;
        require $pPath;
        exit;
    } elseif ($rootPage->regenerate(true)) {
        clearstatcache();
        if (file_exists($pPath)) {
            $cms_page_included = true;
            require $pPath;
            exit;
        }
    }
}
CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
Exemplo n.º 14
0
    $jsfiles = array('ext', 'debug', 'codemirror', 'main');
} else {
    $jsfiles = array('ext', 'codemirror', 'main');
}
//set title
$view->setTitle($language->getMessage(MESSAGE_PAGE_TITLE, array(APPLICATION_LABEL)));
$content = '
<div id="atm-loading-mask"></div>
<div id="atm-center">
	<div class="atm-loading-indicator">' . $language->getMessage(MESSAGE_PAGE_LOADING) . '</div>
	<noscript class="atm-alert">You must have Javascript enabled to access Automne.<hr />Vous devez avoir Javascript actif pour acc&eacute;der &agrave; Automne.</noscript>
</div>
<script type="text/javascript">
var CKEDITOR_BASEPATH = \'' . PATH_MAIN_WR . '/ckeditor/\';
</script>
' . CMS_view::getJavascript($jsfiles) . CMS_view::getJavascript(array('popup'));
if (APPLICATION_GCF_SUPPORT) {
    //GCF prompt for IE
    $content .= '
	<script type="text/javascript" 
		src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
	<style type="text/css">
	.chromeFrameOverlayContent {
		z-index:200001;
	}
	</style> 
	<script type="text/javascript">
		CFInstall.check({mode: "overlay"});
	</script>';
}
//Page content
Exemplo n.º 15
0
 /**
  * Usefull function to dump a var.
  */
 function pr($data, $useVarDump = false)
 {
     //$data .= ' ('.io::getCallInfos().')';
     $view = CMS_view::getInstance();
     if (!$useVarDump) {
         $view->addRawData(print_r($data, true));
     } else {
         ob_start();
         var_dump($data);
         $rawdata = ob_get_contents();
         ob_end_clean();
         $view->addRawData($rawdata);
     }
 }
Exemplo n.º 16
0
 * @subpackage admin
 * @author Sébastien Pauchet <*****@*****.**>
 */
//does this file is directly included by another automne script ?
$included = defined('APPLICATION_CONFIG_LOADED') ? true : false;
if (!$included) {
    if (file_exists(dirname(__FILE__) . '/../upload-vault/allow_front_update')) {
        //in case of update patch which destroy admin user session, we need to allow
        //this file with frontend rights
        @unlink(dirname(__FILE__) . '/../upload-vault/allow_front_update');
        require_once dirname(__FILE__) . '/../../cms_rc_frontend.php';
    } else {
        require_once dirname(__FILE__) . '/../../cms_rc_admin.php';
    }
    //load interface instance
    $view = CMS_view::getInstance();
    //set default display mode for this page
    $view->setDisplayMode(CMS_view::SHOW_HTML);
}
$content = '';
$content .= "<pre>Start update of Automne database ... <br />";
//START UPDATE FROM 4.0.2 TO 4.1.0
if (!function_exists('atm_regen')) {
    function atm_regen()
    {
    }
}
if (!defined('APPLICATION_CONFIG_LOADED')) {
    define('APPLICATION_CONFIG_LOADED', true);
}
# Change structure of some tables to add uuid data
Exemplo n.º 17
0
 /**
  * Get soap values
  *
  * @param integer $fieldID The field ID
  * @param object $language The CMS_language to deal with
  * @param string $xml Values to set
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function setSoapValues($fieldID, $domdocument)
 {
     $view = CMS_view::getInstance();
     $return = true;
     $itemId = '';
     // Fields
     foreach ($domdocument->childNodes as $childNode) {
         if ($childNode->nodeType == XML_ELEMENT_NODE) {
             switch ($childNode->tagName) {
                 case 'field':
                     //<field id="40" label="Identifiant" required="1">
                     $fieldId = $childNode->getAttribute('id');
                     if (!sensitiveIO::isPositiveInteger($fieldId)) {
                         $view->addError('Missing or invalid attribute id for field tag');
                         return false;
                     }
                     if (!isset($this->_objectValues[$fieldId])) {
                         $view->addError('Unknown field id ' . $fieldId . ' for object ' . $this->_objectID);
                         return false;
                     }
                     // Check if field requires itemID to set values
                     if (method_exists($this->_objectValues[$fieldId], 'needIDToSetValues')) {
                         if (!$this->getID()) {
                             //if object has no id yet, save it
                             if (!$this->writeToPersistence(false, false, true)) {
                                 $view->addError('Error during saving process (pre-saving need for the field ' . $this->_objectID . ')');
                                 return false;
                             }
                         }
                         $itemId = $this->getID();
                     }
                     if (!$this->_objectValues[$fieldId]->setSoapValues($fieldId, $childNode, $itemId)) {
                         $view->addError('Unable to set values for field ' . $fieldId);
                         $return = false;
                     }
                     break;
                 case 'resource':
                     //TODO
                     break;
                 default:
                     $view->addError('Unknown xml tag ' . $childNode->tagName . ' to process.');
                     return false;
                     break;
             }
         } else {
             if ($childNode->nodeType == XML_TEXT_NODE && trim($childNode->nodeValue)) {
                 $view->addError('Unknown xml content tag ' . $childNode->nodeValue . ' to process.');
                 return false;
             }
         }
     }
     return $return;
 }
Exemplo n.º 18
0
?>
/modules/polymod/fckplugin.php',
						params:		{
							winId:			'FCKPolymod',
							id:				id,
							content:		content
						},
						nocache:	true,
						scope:		this
					}
				});
			}
		</script>
		<?php 
echo CMS_view::getCSS(array('ext', 'main'));
echo CMS_view::getJavascript(array('ext', 'main', 'initConfig'));
?>
		<script type="text/javascript">
			if (parent.parent) {
				//Declare Automne namespace
				Ext.namespace('Automne');
				pr = parent.parent.pr;
				Automne.locales = parent.parent.Automne.locales;
				Automne.message = parent.parent.Automne.message;
				Ext.MessageBox = parent.parent.Ext.MessageBox;
				Automne.server = parent.parent.Automne.server;
				Automne.context = parent.parent.Automne.context;
				Ext.Ajax = parent.parent.Ext.Ajax;
				Ext.BLANK_IMAGE_URL = '<?php 
echo PATH_ADMIN_IMAGES_WR;
?>
Exemplo n.º 19
0
    /**
     * Writes html header
     *
     * @return void
     * @access private
     */
    private function _showHead($returnValue = false)
    {
        switch ($this->_displayMode) {
            case self::SHOW_JSON:
            case self::SHOW_RAW:
            case self::SHOW_XML:
                $return = '';
                if ($this->hasErrors()) {
                    $return .= '	<error>1</error>' . "\n" . '	<errormessage><![CDATA[' . $this->_espaceCdata($this->getErrors(true)) . ']]></errormessage>' . "\n";
                } else {
                    $return .= '	<error>0</error>' . "\n";
                }
                if ($this->_secure && CMS_session::tokenIsExpired('admin')) {
                    $token = CMS_session::getToken('admin');
                    //pr('new token : '.$token);
                    $return .= '	<token><![CDATA[' . $token . ']]></token>' . "\n";
                }
                if ($this->hasRawDatas()) {
                    $return .= '	<rawdatas><![CDATA[' . $this->_espaceCdata($this->getRawDatas(true)) . ']]></rawdatas>' . "\n";
                }
                if ($this->_actionmessage) {
                    $return .= '	<message><![CDATA[' . $this->_espaceCdata($this->_actionmessage) . ']]></message>' . "\n";
                }
                if ($this->_title) {
                    $return .= '	<title><![CDATA[' . $this->_espaceCdata($this->_title) . ']]></title>' . "\n";
                }
                if ($this->_disconnected) {
                    $return .= '	<disconnected>1</disconnected>' . "\n";
                }
                $scripts = CMS_scriptsManager::getScriptsNumberLeft();
                if ($scripts) {
                    $return .= '	<scripts>' . $scripts . '</scripts>' . "\n";
                }
                if (SYSTEM_DEBUG && STATS_DEBUG) {
                    $return .= '	<stats><![CDATA[' . $this->_espaceCdata(CMS_stats::view(true)) . ']]></stats>' . "\n";
                }
                $jsfiles = CMS_view::getJavascript(array(), 'screen', true);
                if ($jsfiles) {
                    $files = array('files' => $jsfiles, 'manager' => CMS_view::getJSManagerURL());
                    $return .= '	<jsfiles><![CDATA[' . $this->_espaceCdata(sensitiveIO::jsonEncode($files)) . ']]></jsfiles>' . "\n";
                }
                $cssfiles = CMS_view::getCSS(array(), 'screen', true);
                if ($cssfiles) {
                    $files = array('files' => $cssfiles, 'manager' => CMS_view::getCSSManagerURL());
                    $return .= '	<cssfiles><![CDATA[' . $this->_espaceCdata(sensitiveIO::jsonEncode($files)) . ']]></cssfiles>' . "\n";
                }
                if (!$returnValue) {
                    echo $return;
                } else {
                    return $return;
                }
                break;
            case self::SHOW_HTML:
            default:
                $title = $this->_title ? '<title>' . APPLICATION_LABEL . ' :: ' . $this->_title . '</title>' : '';
                echo '<head>
						<meta http-equiv="Content-Type" content="text/html; charset=' . APPLICATION_DEFAULT_ENCODING . '" />
						' . $title . '
						' . $this->_copyright() . '
						<meta name="generator" content="' . CMS_grandFather::SYSTEM_LABEL . '" />
						' . CMS_view::getCSS() . '
						' . CMS_view::getJavascript();
                if (APPLICATION_GCF_SUPPORT) {
                    echo '<meta http-equiv="X-UA-Compatible" content="chrome=1">';
                }
                echo '</head>';
                break;
        }
    }