Пример #1
0
 /**
  * Module script task
  * @param array $parameters the task parameters
  *		task : string task to execute
  *		object : string module codename for the task
  *		field : string module uid
  *		...	: optional field relative parameters
  * @return Boolean true/false
  * @access public
  */
 function scriptTask($parameters)
 {
     switch ($parameters['task']) {
         case 'emailNotification':
             @set_time_limit(300);
             $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //create a new script for all recipients
             $allUsers = $this->_getRecipients($parameters['object']);
             foreach ($allUsers as $userId) {
                 //add script to send email for user if needed
                 CMS_scriptsManager::addScript($module, array('task' => 'emailSend', 'user' => $userId, 'field' => $parameters['field'], 'object' => $parameters['object']));
             }
             //then set sending date to current date
             $sendingDate = new CMS_date();
             $sendingDate->setNow();
             $this->_subfieldValues[1]->setValue($sendingDate->getDBValue());
             $this->writeToPersistence();
             break;
         case 'emailSend':
             @set_time_limit(300);
             $params = $this->getParamsValues();
             if (!sensitiveIO::isPositiveInteger($parameters['user'])) {
                 return false;
             }
             //instanciate script related item
             $item = CMS_poly_object_catalog::getObjectByID($parameters['object'], false, true);
             if (!is_object($item) || $item->hasError()) {
                 return false;
             }
             //instanciate user
             $cms_user = new CMS_profile_user($parameters['user']);
             //check user
             if (!$cms_user || $cms_user->hasError() || !$cms_user->isActive() || $cms_user->isDeleted() || !sensitiveIO::isValidEmail($cms_user->getEmail())) {
                 return false;
             }
             $cms_language = $cms_user->getLanguage();
             //globalise cms_user and cms_language
             $GLOBALS['cms_language'] = $cms_user->getLanguage();
             $GLOBALS['cms_user'] = $cms_user;
             //check user clearance on object
             if (!$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW)) {
                 return false;
             }
             //create email subject
             $parameters['item'] = $item;
             $parameters['public'] = true;
             $polymodParsing = new CMS_polymod_definition_parsing($params['emailSubject'], false);
             $subject = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
             $body = '';
             //create email body
             if ($params['emailBody']['type'] == 1) {
                 //send body
                 $parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
                 $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['html'], true, CMS_polymod_definition_parsing::PARSE_MODE, $parameters['module']);
                 $body = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
             } elseif ($params['emailBody']['type'] == 2) {
                 //send a page
                 $page = CMS_tree::getPageById($params['emailBody']['pageID']);
                 if (!$page || $page->hasError()) {
                     $this->raiseError('Page ID is not a valid page : ' . $params['emailBody']['pageID']);
                     return false;
                 }
                 $pageHTMLFile = new CMS_file($page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM));
                 if (!$pageHTMLFile->exists()) {
                     $this->raiseError('Page HTML file does not exists : ' . $page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM));
                     return false;
                 }
                 $body = $pageHTMLFile->readContent();
                 //create page URL call
                 $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['pageURL'], false);
                 $pageURL = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
                 parse_str($pageURL, $GLOBALS['_REQUEST']);
                 //$GLOBALS['_REQUEST']
                 //parse and eval HTML page
                 $cms_page_included = true;
                 $GLOBALS['cms_page_included'] = $cms_page_included;
                 //eval() the PHP code
                 $body = sensitiveIO::evalPHPCode($body);
                 $website = $page->getWebsite();
                 $webroot = $website->getURL();
                 //replace URLs values
                 $replace = array('="/' => '="' . $webroot . '/', "='/" => "='" . $webroot . "/", "url(/" => "url(" . $webroot . "/");
                 $body = str_replace(array_keys($replace), $replace, $body);
             } else {
                 $this->raiseError('No valid email type to send : ' . $params['emailBody']['type']);
                 return false;
             }
             if (isset($sendmail)) {
                 //$body .= print_r($sendmail,true);
             }
             //drop email sending
             if (isset($sendmail) && $sendmail === false) {
                 return false;
             }
             //if no body for email or if sendmail var is set to false, quit
             if (!$body) {
                 $this->raiseError('No email body to send ... Email parameters : user : '******'user'] . ' - object ' . $parameters['object']);
                 return false;
             }
             //This code is for debug purpose only.
             //$testFile = new CMS_file('/test/test_'.$cms_user->getUserId().'.php', CMS_file::WEBROOT);
             //$testFile->setContent($body);
             //$testFile->writeToPersistence();
             // Set email
             $email = new CMS_email();
             $email->setSubject($subject);
             $email->setEmailHTML($body);
             $email->setEmailTo($cms_user->getEmail());
             if ($params['includeFiles']) {
                 //check for file fields attached to object
                 $files = array();
                 $this->_getFieldsFiles($item, $files);
                 if (sizeof($files)) {
                     foreach ($files as $file) {
                         $email->setFile($file);
                     }
                 }
             }
             //set email From
             if (!$params['emailFrom']) {
                 $email->setFromName(APPLICATION_LABEL);
                 $email->setEmailFrom(APPLICATION_POSTMASTER_EMAIL);
             } else {
                 $email->setFromName($params['emailFrom']);
                 $email->setEmailFrom($params['emailFrom']);
             }
             //Send
             if ($email->sendEmail()) {
                 //store email sent number
                 $this->_subfieldValues[2]->setValue($this->_subfieldValues[2]->getValue() + 1);
                 $this->writeToPersistence();
                 return true;
             } else {
                 return false;
             }
             break;
         default:
             $this->raiseError('No valid task given : ' . $parameters['task']);
             return false;
             break;
     }
 }
                    $cms_message = $cms_language->getMessage(MESSAGE_ERROR_NO_PAGES_FOUND);
                }
            }
        }
        break;
    case 'restart-scripts':
        CMS_scriptsManager::startScript(true);
        $cms_message = $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE);
        break;
    case 'stop-scripts':
        CMS_scriptsManager::clearScripts();
        CMS_scriptsManager::startScript(true);
        $cms_message = $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE);
        break;
    case 'clear-scripts':
        CMS_scriptsManager::clearScripts();
        $cms_message = $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE);
        break;
    default:
        CMS_grandFather::raiseError('Unknown action to do ...');
        $view->show();
        break;
}
//set user message if any
if ($cms_message) {
    $view->setActionMessage($cms_message);
}
if ($content) {
    $view->setContent($content);
}
$view->show();
Пример #3
0
 /**
  * Delete object and values.
  * If object is a primary resource, this deletion is submitted to validation and an email is sent to validators.
  *
  * @param boolean $hardDelete : completely destroy object and associated resource if any. After this, this object will no longer exists at all. Default : false.
  * /!\ if object is a primary resource, no validation will be queried to validators, object will be directly destroyed from all locations. /!\
  * @return boolean true on success, false on failure
  * @access public
  */
 function delete($hardDelete = false)
 {
     global $cms_user;
     //get Object definition
     $objectDef = $this->getObjectDefinition();
     //get module codename
     $polyModuleCodename = $objectDef->getValue('module');
     //if object is not a primary resource
     if ($this->_objectResourceStatus != 1 || $hardDelete) {
         $forceSecondaryRessourcePublication = false;
         if ($this->_objectResourceStatus == 2 && !$hardDelete) {
             //if this object is a secondary resource, primary items which uses this object must be updated
             //get all primary resource associated
             $primaryItems = CMS_poly_object_catalog::getPrimaryItemsWhichUsesSecondaryItem($this->_ID, true, false);
             if ($primaryItems) {
                 foreach ($primaryItems as $primaryItem) {
                     $primaryItem->writeToPersistence();
                 }
             } else {
                 $forceSecondaryRessourcePublication = true;
             }
         }
         //if object is not a secondary resource, delete public datas, else preserve it : it will be deleted on primary resource validation
         if ($this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication || $hardDelete) {
             //delete datas from public locations
             CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_DEVNULL);
             if (!$hardDelete) {
                 //mark item as deleted
                 CMS_modulePolymodValidation::markDeletedItem($this->getID());
             } else {
                 //destroy poly_object reference
                 $sql = "delete from mod_object_polyobjects where id_moo = '" . $this->getID() . "'";
                 new CMS_query($sql);
             }
         }
         if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) {
             $modulesCodes = new CMS_modulesCodes();
             //add a call to all modules for before validation specific treatment
             $modulesCodes->getModulesCodes(MODULE_TREATMENT_BEFORE_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete'));
         }
         if (!$hardDelete) {
             //move resource datas from edited to deleted location
             CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DELETED);
         } else {
             //delete datas from edited locations
             CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DEVNULL);
         }
         if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) {
             //add a call to all modules for after validation specific treatment
             $modulesCodes->getModulesCodes(MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete'));
         }
         if ($this->_objectResourceStatus == 1 && $hardDelete) {
             //delete associated resource
             parent::destroy();
         }
         //Log action
         $log = new CMS_log();
         $language = $cms_user->getLanguage();
         $log->logMiscAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $polyModuleCodename);
         if ($hardDelete) {
             unset($this);
         }
         //Clear polymod cache
         //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename));
         CMS_cache::clearTypeCache('polymod');
         return true;
     } else {
         //change the article proposed location and send emails to all the validators
         if ($this->setProposedLocation(RESOURCE_LOCATION_DELETED, $cms_user)) {
             parent::writeToPersistence();
             if (APPLICATION_ENFORCES_WORKFLOW) {
                 if (!NO_APPLICATION_MAIL) {
                     //get editors
                     $editors = $this->getEditors();
                     $editorsIds = array();
                     foreach ($editors as $editor) {
                         $editorsIds[] = $editor->getUserId();
                     }
                     $validators = CMS_profile_usersCatalog::getValidators($polyModuleCodename);
                     foreach ($validators as $validator) {
                         //add script to send email for validator if needed
                         CMS_scriptsManager::addScript($polyModuleCodename, array('task' => 'emailNotification', 'object' => $this->getID(), 'validator' => $validator->getUserId(), 'type' => 'delete', 'editors' => $editorsIds));
                     }
                     //then launch scripts execution
                     CMS_scriptsManager::startScript();
                 }
             } else {
                 $validation = new CMS_resourceValidation($polyModuleCodename, RESOURCE_EDITION_LOCATION, $this);
                 $mod = CMS_modulesCatalog::getByCodename($polyModuleCodename);
                 $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT);
             }
             //Log action
             $log = new CMS_log();
             $language = $cms_user->getLanguage();
             $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, $polyModuleCodename, $this->getStatus(), 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $this);
             //Clear polymod cache
             //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename));
             CMS_cache::clearTypeCache('polymod');
             return true;
         } else {
             return false;
         }
     }
 }
Пример #4
0
                    break;
                case '2':
                    $detailsContent .= '<li class="atm-pic-cancel" ext:qtip="' . $cms_language->getMessage(MESSAGE_PAGE_NO_SCRIPTS_PID_OK) . '">' . $runningScript["Title"] . ' (' . $date->getLocalizedDate($cms_language->getDateFormat() . " H:i:s") . ')</li>';
                    break;
                case '3':
                    $detailsContent .= '<li class="atm-pic-cancel" ext:qtip="' . $cms_language->getMessage(MESSAGE_PAGE_SCRIPTS_END_PID_OK) . '">' . $runningScript["Title"] . ' (' . $date->getLocalizedDate($cms_language->getDateFormat() . " H:i:s") . ')</li>';
                    break;
            }
        }
        $detailsContent .= '</ul>';
    } else {
        $detailsContent = $cms_language->getJsMessage(MESSAGE_PAGE_NO_SCRIPTS_IN_PROGRESS);
    }
}
if ($queue) {
    $scripts = CMS_scriptsManager::getScriptsLeft();
    if (is_array($scripts) && sizeof($scripts)) {
        $queueContent = '<ol>';
        foreach ($scripts as $script) {
            $queueContent .= '<li>' . $script . '</li>';
        }
        $queueContent .= '</ol>';
    } else {
        $queueContent .= $cms_language->getJsMessage(MESSAGE_PAGE_NO_SCRIPTS_QUEUED);
    }
}
if ($detailsContent || $queueContent) {
    $xmlcontent = '
	<details><![CDATA[' . $detailsContent . ']]></details>
	<queue><![CDATA[' . $queueContent . ']]></queue>';
    $view->setContent($xmlcontent);
Пример #5
0
 /**
  * Get current session infos
  * 
  * @return array : the user session infos
  * @access public
  * @static
  */
 public static function getSessionInfos()
 {
     $sessionInfos = array();
     $user = CMS_session::getUser();
     if (!$user) {
         return array();
     }
     $sessionInfos['fullname'] = $user->getFullName();
     $sessionInfos['userId'] = $user->getUserId();
     $sessionInfos['language'] = $user->getLanguage()->getCode();
     $sessionInfos['scriptsInProgress'] = CMS_scriptsManager::getScriptsNumberLeft();
     $sessionInfos['hasValidations'] = $user->hasValidationClearance();
     $sessionInfos['awaitingValidation'] = CMS_modulesCatalog::getValidationsCount($user);
     $sessionInfos['applicationLabel'] = APPLICATION_LABEL;
     $sessionInfos['applicationVersion'] = AUTOMNE_VERSION;
     $sessionInfos['systemLabel'] = CMS_grandFather::SYSTEM_LABEL;
     $sessionInfos['token'] = CMS_session::getToken('admin');
     $sessionInfos['sessionDuration'] = APPLICATION_SESSION_TIMEOUT;
     $sessionInfos['permanent'] = CMS_session::getPermanent();
     $sessionInfos['path'] = PATH_REALROOT_WR;
     $sessionInfos['debug'] = '';
     $sessionInfos['debug'] += SYSTEM_DEBUG ? 1 : 0;
     $sessionInfos['debug'] += STATS_DEBUG ? 2 : 0;
     $sessionInfos['debug'] += POLYMOD_DEBUG ? 4 : 0;
     $sessionInfos['debug'] += VIEW_SQL ? 8 : 0;
     return $sessionInfos;
 }
Пример #6
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;
        }
    }
Пример #7
0
 /**
  * Submit pages to the regenerator. The first argument can either be a single page ID or an array of those.
  *
  * @param mixed $pages If it's a scalar, it's a page ID, else an array of pages IDs
  * @param integer $fromScratch Is the submission concerning a full from scratch regeneration (true) or a regeneration from linx files (false) ?
  * @param boolean $dontLaunchRegenerator to avoid multiple launch of the regenerator during multiple validation only the last page validation launch the script
  * @return void
  * @access public
  */
 static function submitToRegenerator($pages, $fromScratch, $dontLaunchRegenerator = false)
 {
     $fs = $fromScratch ? true : false;
     if (!is_array($pages)) {
         $pages = array($pages);
     }
     //get all scripts for standard module
     if (!class_exists('CMS_module_standard')) {
         CMS_grandFather::raiseError("Can not found standard module");
         return false;
     }
     $scripts = CMS_scriptsManager::getScripts(MOD_STANDARD_CODENAME);
     $pagesToRegen = array();
     foreach ($scripts as $scriptID => $script) {
         $pagesToRegen[$script['pageid']] = array('fromscratch' => $script['fromscratch'], 'script' => $scriptID);
     }
     foreach ($pages as $page) {
         if (isset($pagesToRegen[$page])) {
             //is existant script need to be updated ?
             $actual_fs = $pagesToRegen[$page]['fromscratch'];
             if (!$actual_fs && $fs) {
                 $parameters = array('pageid' => $page, 'fromscratch' => $fs);
                 CMS_scriptsManager::addScript(MOD_STANDARD_CODENAME, $parameters, $pagesToRegen[$page]['script']);
             }
         } else {
             //add script
             $parameters = array('pageid' => $page, 'fromscratch' => $fs);
             CMS_scriptsManager::addScript(MOD_STANDARD_CODENAME, $parameters);
         }
     }
     if (!$dontLaunchRegenerator) {
         //then, launch the regenerator script
         CMS_scriptsManager::startScript();
     }
 }