/** * 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; } }
/** * Module script info : get infos for a given script parameters * * @param array $parameters the task parameters * task : string task to execute * module : string module codename for the task * uid : string module uid * @return string : HTML scripts infos * @access public */ function scriptInfo($parameters) { if (!isset($parameters['object']) || !sensitiveIO::isPositiveInteger($parameters['object'])) { return parent::scriptInfo($parameters); } //instanciate script related object (use edited object because the script can launch writing of values into object) $object = CMS_poly_object_catalog::getObjectByID($parameters['object'], false, false); global $cms_language; if (!is_object($object) || $object->hasError()) { return $this->getLabel($cms_language) . ' : ' . parent::scriptInfo($parameters); } //then pass query to object $return = $object->scriptInfo($parameters); return $this->getLabel($cms_language) . ' : ' . ($return ? $return : parent::scriptInfo($parameters)); }
$transformedDefinition = $polymodModule->convertDefinitionString($htmlDefinition, false); $parameters = array(); $parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForObjectType($oembedDefinition->getObjectdefinition()); $parameters['objectID'] = $oembedDefinition->getObjectdefinition(); $parameters['public'] = true; $parameters['cache'] = false; $parameters['pageID'] = CURRENT_PAGE; $definitionParsing = new CMS_polymod_definition_parsing($transformedDefinition, true, CMS_polymod_definition_parsing::BLOCK_PARAM_MODE, $parameters['module']); $compiledDefinition = $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_PHP, $parameters); $urlParts = parse_url($url); if (!isset($urlParts['query'])) { die("Incorrect parameters"); } parse_str($urlParts['query']); $parameterName = $oembedDefinition->getParameter(); $embededObject = CMS_poly_object_catalog::getObjectByID(${$parameterName}, false, true); if (!$embededObject) { die("Incorrect parameters"); } // get label ob_start(); eval(sensitiveIO::stripPHPTags($compiledDefinition)); $data = ob_get_contents(); ob_end_clean(); $html = array('html' => $data, 'title' => $embededObject->getLabel(), 'height' => io::get('height'), 'width' => io::get('width')); $oembed = CMS_polymod_oembed_definition::getResults($html); if ($format === 'json') { print json_encode($oembed, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT); } elseif ($format === 'xml') { $output = "<?xml version=\"1.0\" encoding=\"utf-8\">\n"; $output .= "<oembed>\n";
} } } elseif (CMS_modulesCatalog::isPolymod($codename)) { //get object item id $itemID = ''; if (preg_match('#^r[0-9]+_[0-9]+_.*#', $pathinfo['basename'])) { $itemID = preg_replace('#^r([0-9]+)_[0-9]+_.*#', '\\1', $pathinfo['basename']); } if (sensitiveIO::isPositiveInteger($itemID)) { if (!is_object($cms_user)) { //no user => LOGIN header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); exit; } else { $public = preg_match('#.*/(edited|edition)$#', $pathinfo['dirname']) ? false : true; $item = CMS_poly_object_catalog::getObjectByID($itemID, false, $public); if (!$item || !is_object($item) || !$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW, true)) { if ($cms_user->getLogin() == DEFAULT_USER_LOGIN) { //no rights and anonymous => LOGIN header('Location: ' . PATH_FRONTEND_SPECIAL_LOGIN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); } else { //no rights and logged => 403 header('Location: ' . PATH_FORBIDDEN_WR . '?referer=' . base64_encode($_SERVER['REQUEST_URI'])); } exit; } } } } } }
public static function getObjectName() { $page = CMS_tree::getPageByID(CURRENT_PAGE); $oembedDefinition = CMS_polymod_oembed_definition_catalog::getByCodename($page->getCodename()); $parameterName = $oembedDefinition->getParameter(); if (io::get($parameterName) && ($embededObject = CMS_poly_object_catalog::getObjectByID(io::get($parameterName), false, true))) { return $embededObject->getLabel(); } return ''; }