Esempio n. 1
0
    //Previz
    $previz = $object->getValue("previewURL") ? $item->getPrevizPageURL() : '';
    //Edit
    $edit = false;
    if (!$deleted && (!$lock || $lock == $cms_user->getUserId())) {
        $edit = array('module' => $codename, 'objectId' => $objectId, 'item' => $item->getID());
    }
    //HTML description
    $description = POLYMOD_DEBUG ? '<span class="atm-text-alert"> (ID : ' . $item->getID() . ')</span>' : '';
    if ($resultsDefinition) {
        //set execution parameters
        $parameters = array();
        $parameters['module'] = $codename;
        $parameters['objectID'] = $object->getID();
        $parameters['public'] = false;
        $parameters['item'] = $item;
        $description .= $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
    } else {
        $itemFieldsObjects = $item->getFieldsObjects();
        //Add all needed fields to description
        foreach ($itemFieldsObjects as $fieldID => $itemField) {
            //if field is a poly object
            if ($objectFields[$fieldID]->getValue('searchlist')) {
                $description .= $objectFields[$fieldID]->getLabel($cms_language) . ' : <strong>' . $itemField->getHTMLDescription() . '</strong><br />';
            }
        }
    }
    $itemsDatas['results'][] = array('id' => $item->getID(), 'status' => $htmlStatus, 'pubrange' => $pubRange, 'label' => $item->getLabel(), 'description' => $description, 'locked' => $lock, 'deleted' => $deleted, 'previz' => $previz, 'edit' => $edit, 'published' => !$lock && !$deleted && $edit && $published, 'unpublished' => !$lock && !$deleted && $edit && $unpublished);
}
$view->setContent($itemsDatas);
$view->show();
Esempio n. 2
0
 //then create the code to paste for the current selected object if any
 if (sensitiveIO::isPositiveInteger($itemId) && !$selectedPlugin->needSelection()) {
     //$item = CMS_poly_object_catalog::getObjectByID($selectedItem);
     $definition = $selectedPlugin->getValue('definition');
     $parameters = array();
     $parameters['itemID'] = $itemId;
     $parameters['module'] = $codename;
     $cms_page = CMS_session::getPage();
     if (is_object($cms_page) && !$cms_page->hasError()) {
         $parameters['pageID'] = $cms_page->getID();
     }
     $parameters['selection'] = io::decodeEntities($selectedContent);
     $parameters['public'] = false;
     $parameters['plugin-view'] = true;
     $definitionParsing = new CMS_polymod_definition_parsing($definition, true, CMS_polymod_definition_parsing::PARSE_MODE);
     $codeTopaste = $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
     //add some attributes to images to prevent resizing into editor
     $codeTopaste = str_replace('<img ', '<img contenteditable="false" unselectable="on" ', $codeTopaste);
     //encode all ampersand without reencode already encoded ampersand
     $codeTopaste = sensitiveIO::reencodeAmpersand($codeTopaste);
     if ($codeTopaste) {
         //add identification span tag arround code to paste
         $codeTopaste = '<span id="polymod-' . $pluginId . '-' . $itemId . '" class="polymod" title="' . io::htmlspecialchars($selectedPlugin->getLabel($cms_language) . ' : ' . trim($item->getLabel($cms_language))) . '">' . $codeTopaste . '</span>';
     }
     $content = $codeTopaste;
 } elseif (sensitiveIO::isPositiveInteger($itemId) && $selectedPlugin->needSelection()) {
     $codeTopaste = '<span id="polymod-' . $pluginId . '-' . $itemId . '" class="polymod">' . $selectedContent . '</span>';
     $content = $codeTopaste;
 } else {
     $selectedContent = $selectedContent ? $selectedContent : ' ';
     $content = $selectedContent;
Esempio n. 3
0
 /**
  * Create datas from definition.
  * Parse definition and create PHP / HTML string
  *
  * @param serialized datas $rawDatas : The user specified parameters for the row
  * @param CMS_page $page The reference of the current page using block
  * @param boolean $public The needed precision for USERSPACE location (default : false)
  * @param constant $type The needed return type of datas (default : CMS_polymod_definition_parsing::OUTPUT_RESULT)
  * @return string The PHP / HTML datas
  * @access private
  */
 protected function _createDatasFromDefinition($rawDatas, &$page, $visualizationMode, $type = CMS_polymod_definition_parsing::OUTPUT_RESULT)
 {
     $public = $visualizationMode == PAGE_VISUALMODE_PRINT || $visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC;
     $parameters = $rawDatas ? array_merge($rawDatas, $this->_attributes) : $this->_attributes;
     // If no language parameter : set page language
     $parameters['language'] = isset($parameters['language']) && $parameters['language'] ? $parameters['language'] : $page->getLanguage();
     $parameters = array('block_attributes' => $parameters, 'module' => $this->_attributes['module'], 'language' => $parameters['language'], 'pageID' => $page->getID(), 'public' => $public);
     $polymodParsing = new CMS_polymod_definition_parsing($this->_definition, true, CMS_polymod_definition_parsing::PARSE_MODE, $this->_attributes['module'], $visualizationMode);
     $content = $polymodParsing->getContent($type, $parameters);
     if (!$public) {
         return $content;
     }
     //Cache management
     $cacheHash = md5(serialize(array('definition' => $content, 'parameters' => $parameters)));
     $lifetime = isset($this->_attributes['cache']) ? $this->_attributes['cache'] : 'auto';
     $content = CMS_cache::wrapCode($cacheHash, $content, $lifetime);
     return $content;
 }
Esempio n. 4
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;
     }
 }
Esempio n. 5
0
 /**
  * get object previzualisation URL if set
  *
  * @param boolean $addPrevizParameter : add the previz=previz parameter at end of address (default : true)
  * @return string : the object previzualisation URL or false if none set
  * @access public
  */
 function getPrevizPageURL($addPrevizParameter = true)
 {
     //get Object definition
     $objectDef = $this->getObjectDefinition();
     if (!$objectDef->getValue("previewURL")) {
         //no previz set
         return false;
     }
     $previzInfos = explode('||', $objectDef->getValue("previewURL"));
     if (!sensitiveIO::isPositiveInteger($previzInfos[0])) {
         //no valid previz page set
         return false;
     }
     $page = CMS_tree::getPageByID($previzInfos[0]);
     if (!$page || $page->hasError()) {
         //no valid previz page set
         return false;
     }
     $previewPageURL = $page->getURL(false, false, PATH_RELATIVETO_WEBROOT, false, $addPrevizParameter);
     if (!$previewPageURL) {
         //no valid previz page set
         return false;
     }
     //convert URL parameters
     $parameters['item'] =& $this;
     $parameters['public'] = $this->_public;
     $polymodParsing = new CMS_polymod_definition_parsing($previzInfos[1], false);
     $previewPageParams = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
     //overwrite website host with admin current host (to avoid session lost)
     if ($addPrevizParameter) {
         //check for website host
         $pageHost = @parse_url($previewPageURL, PHP_URL_HOST);
         $httpHost = @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) ? @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST'];
         if ($pageHost && $_SERVER['HTTP_HOST'] && io::strtolower($httpHost) != io::strtolower($pageHost)) {
             //page host is not the same of current host so change it to avoid JS restriction
             $previewPageURL = str_replace($pageHost, $httpHost, $previewPageURL);
         }
         //check for website protocol
         $pageScheme = @parse_url($previewPageURL, PHP_URL_SCHEME);
         $currentScheme = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] && strtolower($_SERVER["HTTPS"]) != 'off' ? 'https' : 'http';
         if ($pageScheme && $currentScheme != io::strtolower($pageScheme)) {
             $previewPageURL = str_replace($pageScheme . '://', $currentScheme . '://', $panelURL);
         }
     }
     return $previewPageURL . '?' . $previewPageParams . ($addPrevizParameter ? '&atm-previz=previz' : '');
 }
Esempio n. 6
0
 /**
  * Get search results objects for module by Id
  *
  * @param array : the results score ids
  * @return array : results elements (cms_page)
  * @access public
  */
 function getSearchResults($resultsIds, &$user)
 {
     if (!$resultsIds || !is_array($resultsIds)) {
         return array();
     }
     $cms_language = $user->getLanguage();
     //get results object types
     $sql = "\n\t\t\tselect\n\t\t\t\tobject_type_id_moo as type, id_moo as id\n\t\t\tfrom\n\t\t\t\tmod_object_polyobjects\n\t\t\twhere\n\t\t\t\tid_moo in (" . sensitiveIO::sanitizeSQLString(implode(',', $resultsIds)) . ")\n\t\t";
     $q = new CMS_query($sql);
     $resultsType = array();
     while ($r = $q->getArray()) {
         $resultsType[$r['type']][] = $r['id'];
     }
     $results = array();
     foreach ($resultsType as $type => $ids) {
         //load current object definition
         $object = CMS_poly_object_catalog::getObjectDefinition($type);
         //create search object for current object
         $search = new CMS_object_search($object);
         $search->addWhereCondition("items", $ids);
         $search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS);
         //launch search
         $objectLabel = $object->getLabel($cms_language);
         // Check if need to use a specific display for search results
         $resultsDefinition = $object->getValue('resultsDefinition');
         if ($resultsDefinition) {
             $definitionParsing = new CMS_polymod_definition_parsing($resultsDefinition, true, CMS_polymod_definition_parsing::PARSE_MODE);
             $itemsResourcesFiles = '';
             // Add specific css and js files we use the resultsDefinition
             if (file_exists(PATH_CSS_FS . '/modules/' . $this->getCodename() . '.css')) {
                 $itemsResourcesFiles .= '<link rel="stylesheet" type="text/css" href="' . PATH_CSS_WR . '/modules/' . $this->getCodename() . '.css" />';
             }
             $jsFiles = $this->getJSFiles();
             if ($jsFiles) {
                 foreach ($jsFiles as $jsfile) {
                     $itemsResourcesFiles .= '<script type="text/javascript" src="' . $jsfile . '"></script>' . "\n";
                 }
             }
         } else {
             //load fields objects for object
             $objectFields = CMS_poly_object_catalog::getFieldsDefinition($object->getID());
         }
         //loop on results items
         while ($item = $search->getNextResult()) {
             //Resource related informations
             $htmlStatus = $pubRange = '';
             $lock = $deleted = $primaryResource = false;
             if ($object->isPrimaryResource()) {
                 $status = $item->getStatus();
                 if (is_object($status)) {
                     $htmlStatus = $status->getHTML(false, $user, $this->getCodename(), $item->getID());
                     $pubRange = $status->getPublicationRange($cms_language);
                     $lock = $item->getLock();
                     $deleted = $item->getProposedLocation() == RESOURCE_LOCATION_DELETED;
                 }
                 $primaryResource = true;
             }
             //Edit
             $edit = false;
             if (!$deleted && (!$lock || $lock == $user->getUserId())) {
                 $edit = array('url' => PATH_ADMIN_MODULES_WR . '/' . MOD_POLYMOD_CODENAME . '/item.php', 'type' => 'window', 'params' => array('module' => $this->getCodename(), 'type' => $type, 'item' => $item->getID()));
             }
             //Previz
             $view = false;
             if ($object->getValue("previewURL")) {
                 $view = array('url' => $item->getPrevizPageURL(), 'type' => 'frame');
             }
             //HTML description
             $description = POLYMOD_DEBUG ? '<span class="atm-text-alert"> (ID : ' . $item->getID() . ')</span>' : '';
             if ($resultsDefinition) {
                 //set execution parameters
                 $parameters = array();
                 $parameters['module'] = $this->getCodename();
                 $parameters['objectID'] = $object->getID();
                 $parameters['public'] = false;
                 $parameters['item'] = $item;
                 $description .= $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
                 if ($itemsResourcesFiles) {
                     $description = $itemsResourcesFiles . $description;
                 }
             } else {
                 $itemFieldsObjects = $item->getFieldsObjects();
                 //Add all needed fields to description
                 foreach ($itemFieldsObjects as $fieldID => $itemField) {
                     //if field is a poly object
                     if ($objectFields[$fieldID]->getValue('searchlist')) {
                         $description .= $objectFields[$fieldID]->getLabel($cms_language) . ' : <strong>' . $itemField->getHTMLDescription() . '</strong><br />';
                     }
                 }
             }
             $results[$item->getID()] = array('id' => $item->getID(), 'type' => $objectLabel, 'status' => $htmlStatus, 'pubrange' => $pubRange, 'label' => $item->getLabel(), 'description' => $description, 'resource' => $primaryResource ? array('module' => $this->getCodename(), 'resource' => $item->getID(), 'action' => 'unlock') : false, 'edit' => $edit, 'view' => $view);
         }
     }
     return $results;
 }
Esempio n. 7
0
$pageLang = $page->getLanguage(true);
$cms_language = new CMS_language($pageLang);
define('CURRENT_PAGE', $page->getID());
$website = $page->getWebsite();
$htmlDefinition = $oembedDefinition->getHtml();
$module = CMS_poly_object_catalog::getModuleCodenameForObjectType($oembedDefinition->getObjectdefinition());
$polymodModule = CMS_modulesCatalog::getByCodename($module);
$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();
 /**
  * Compile the indexURL definition
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function compileDefinition()
 {
     global $cms_language;
     $parameters = array();
     $parameters['module'] = $this->_objectValues["module"];
     $parameters['cache'] = false;
     //Do not cache this content
     $definitionParsing = new CMS_polymod_definition_parsing($this->_objectValues['indexURL'], true, CMS_polymod_definition_parsing::PARSE_MODE, $parameters['module']);
     $compiledIndexURL = $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_PHP, $parameters);
     $this->_objectValues['compiledIndexURL'] = $compiledIndexURL;
     return true;
 }
 /**
  * Compile the Plugin definition
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function compileDefinition()
 {
     $parameters = array();
     $parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForObjectType($this->getValue('objectID'));
     $parameters['objectID'] = $this->getValue('objectID');
     $definitionParsing = new CMS_polymod_definition_parsing($this->_objectValues['definition'], true, CMS_polymod_definition_parsing::PARSE_MODE);
     $compiledDefinition = $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_PHP, $parameters);
     $this->_objectValues['compiledDefinition'] = $compiledDefinition;
     return true;
 }