コード例 #1
0
    /**
     * @param \eZTemplate $mailTpl
     * @param array $userData
     *
     * @return array|null|string
     */
    function generateRegistration( eZTemplate $mailTpl, array $userData )
    {
        $databaseMap = eZSetupDatabaseMap();
        $databaseInfo = $this->PersistenceList['database_info'];
        $databaseInfo['info'] = $databaseMap[$databaseInfo['type']];
        $regionalInfo = $this->PersistenceList['regional_info'];
        if ( !isset( $regionalInfo['languages'] ) )
            $regionalInfo['languages'] = array();

        $emailInfo = $this->PersistenceList['email_info'];

        $siteType = $this->chosenSiteType();


        $url = $siteType['url'];
        if ( !preg_match( "#^[a-zA-Z0-9]+://(.*)$#", $url ) )
        {
            $url = 'http://' . $url;
        }
        $currentURL = $url;
        $adminURL = $url;
        if ( $siteType['access_type'] == 'url' )
        {
            $url .= '/' . $siteType['access_type_value'];
            $adminURL .= '/' . $siteType['admin_access_type_value'];
        }
        else if ( $siteType['access_type'] == 'hostname' )
        {
            $url = eZHTTPTool::createRedirectURL( 'http://' . $siteType['access_type_value'] );
            $adminURL = eZHTTPTool::createRedirectURL( 'http://' . $siteType['admin_access_type_value'] );
        }
        else if ( $siteType['access_type'] == 'port' )
        {
            $url = eZHTTPTool::createRedirectURL( $currentURL, array( 'override_port' => $siteType['access_type_value'] ) );
            $adminURL = eZHTTPTool::createRedirectURL( $currentURL, array( 'override_port' => $siteType['admin_access_type_value'] ) );
        }
        $siteType['url'] = $url;
        $siteType['admin_url'] = $adminURL;


        $testsRun = $this->PersistenceList['tests_run'];
        $imageMagickProgram = $this->PersistenceList['imagemagick_program'];
        $imageGDExtension = $this->PersistenceList['imagegd_extension'];
        $phpVersion = $this->PersistenceList['phpversion'];
        $phpVersion['sapi'] = PHP_SAPI;

        $webserverInfo = false;
        if ( function_exists( 'apache_get_version' ) )
        {
            $webserverInfo = array( 'version' => apache_get_version() );
        }
        else if ( !empty( $_SERVER['SERVER_SOFTWARE'] ) )
        {
            $webserverInfo = array( 'version' => $_SERVER['SERVER_SOFTWARE'] );
        }

        $systemInfo = new eZSysInfo();
        $systemInfo->scan();

        $optionalTests = eZSetupOptionalTests();
        $runResult = eZSetupRunTests( $optionalTests, 'eZSetup:init:send_registration', $this->PersistenceList );
        $testResults = $runResult['results'];

        // Generate email body e-mail
        $mailTpl->setVariable( 'user_data', $userData );
        $mailTpl->setVariable( 'database_info', $databaseInfo );
        $mailTpl->setVariable( 'regional_info', $regionalInfo );
        $mailTpl->setVariable( 'email_info', $emailInfo );
        $mailTpl->setVariable( 'site_type', $siteType );
        $mailTpl->setVariable( 'tests_run', $testsRun );
        $mailTpl->setVariable( 'imagemagick_program', $imageMagickProgram );
        $mailTpl->setVariable( 'imagegd_extension', $imageGDExtension );
        $mailTpl->setVariable( 'phpversion', $phpVersion );
        $mailTpl->setVariable( 'webserver', $webserverInfo );
        $mailTpl->setVariable( 'system', $systemInfo );
        $mailTpl->setVariable( 'os', array( 'name' => php_uname() ) );
        $mailTpl->setVariable( 'optional_tests', $testResults );
        $mailTpl->setVariable( "version", array( "text" => eZPublishSDK::version(),
                                                 "major" => eZPublishSDK::majorVersion(),
                                                 "minor" => eZPublishSDK::minorVersion(),
                                                 "release" => eZPublishSDK::release() ) );

        return $mailTpl->fetch( 'design:setup/registration_email.tpl' );
    }
コード例 #2
0
 /**
  * Generate result data for a node view
  *
  * @param eZTemplate $tpl
  * @param eZContentObjectTreeNode $node
  * @param eZContentObject $object
  * @param bool|string $languageCode
  * @param string $viewMode
  * @param int $offset
  * @param array $viewParameters
  * @param bool|array $collectionAttributes
  * @param bool $validation
  * @return array Result array for view
  */
 static function generateNodeViewData(eZTemplate $tpl, eZContentObjectTreeNode $node, eZContentObject $object, $languageCode, $viewMode, $offset, array $viewParameters = array('offset' => 0, 'year' => false, 'month' => false, 'day' => false), $collectionAttributes = false, $validation = false)
 {
     $section = eZSection::fetch($object->attribute('section_id'));
     if ($section) {
         $navigationPartIdentifier = $section->attribute('navigation_part_identifier');
         $sectionIdentifier = $section->attribute('identifier');
     } else {
         $navigationPartIdentifier = null;
         $sectionIdentifier = null;
     }
     $keyArray = array(array('object', $object->attribute('id')), array('node', $node->attribute('node_id')), array('parent_node', $node->attribute('parent_node_id')), array('class', $object->attribute('contentclass_id')), array('class_identifier', $node->attribute('class_identifier')), array('view_offset', $offset), array('viewmode', $viewMode), array('remote_id', $object->attribute('remote_id')), array('node_remote_id', $node->attribute('remote_id')), array('navigation_part_identifier', $navigationPartIdentifier), array('depth', $node->attribute('depth')), array('url_alias', $node->attribute('url_alias')), array('class_group', $object->attribute('match_ingroup_id_list')), array('state', $object->attribute('state_id_array')), array('state_identifier', $object->attribute('state_identifier_array')), array('section', $object->attribute('section_id')), array('section_identifier', $sectionIdentifier));
     $parentClassID = false;
     $parentClassIdentifier = false;
     $parentNodeRemoteID = false;
     $parentObjectRemoteID = false;
     $parentNode = $node->attribute('parent');
     if (is_object($parentNode)) {
         $parentNodeRemoteID = $parentNode->attribute('remote_id');
         $keyArray[] = array('parent_node_remote_id', $parentNodeRemoteID);
         $parentObject = $parentNode->attribute('object');
         if (is_object($parentObject)) {
             $parentObjectRemoteID = $parentObject->attribute('remote_id');
             $keyArray[] = array('parent_object_remote_id', $parentObjectRemoteID);
             $parentClass = $parentObject->contentClass();
             if (is_object($parentClass)) {
                 $parentClassID = $parentClass->attribute('id');
                 $parentClassIdentifier = $parentClass->attribute('identifier');
                 $keyArray[] = array('parent_class', $parentClassID);
                 $keyArray[] = array('parent_class_identifier', $parentClassIdentifier);
             }
         }
     }
     $res = eZTemplateDesignResource::instance();
     $res->setKeys($keyArray);
     if ($languageCode) {
         $oldLanguageCode = $node->currentLanguage();
         $node->setCurrentLanguage($languageCode);
     }
     $tpl->setVariable('node', $node);
     $tpl->setVariable('viewmode', $viewMode);
     $tpl->setVariable('language_code', $languageCode);
     if (isset($viewParameters['_custom'])) {
         foreach ($viewParameters['_custom'] as $customVarName => $customValue) {
             $tpl->setVariable($customVarName, $customValue);
         }
         unset($viewParameters['_custom']);
     }
     $tpl->setVariable('view_parameters', $viewParameters);
     $tpl->setVariable('collection_attributes', $collectionAttributes);
     $tpl->setVariable('validation', $validation);
     $tpl->setVariable('persistent_variable', false);
     $parents = $node->attribute('path');
     $path = array();
     $titlePath = array();
     foreach ($parents as $parent) {
         $path[] = array('text' => $parent->attribute('name'), 'url' => '/content/view/full/' . $parent->attribute('node_id'), 'url_alias' => $parent->attribute('url_alias'), 'node_id' => $parent->attribute('node_id'));
     }
     $titlePath = $path;
     $path[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false, 'node_id' => $node->attribute('node_id'));
     $titlePath[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false);
     $tpl->setVariable('node_path', $path);
     $event = ezpEvent::getInstance();
     $event->notify('content/pre_rendering', array($node, $tpl, $viewMode));
     $Result = array();
     $Result['content'] = $tpl->fetch('design:node/view/' . $viewMode . '.tpl');
     $Result['view_parameters'] = $viewParameters;
     $Result['path'] = $path;
     $Result['title_path'] = $titlePath;
     $Result['section_id'] = $object->attribute('section_id');
     $Result['node_id'] = $node->attribute('node_id');
     $Result['navigation_part'] = $navigationPartIdentifier;
     $contentInfoArray = array();
     $contentInfoArray['object_id'] = $object->attribute('id');
     $contentInfoArray['node_id'] = $node->attribute('node_id');
     $contentInfoArray['parent_node_id'] = $node->attribute('parent_node_id');
     $contentInfoArray['class_id'] = $object->attribute('contentclass_id');
     $contentInfoArray['class_identifier'] = $node->attribute('class_identifier');
     $contentInfoArray['remote_id'] = $object->attribute('remote_id');
     $contentInfoArray['node_remote_id'] = $node->attribute('remote_id');
     $contentInfoArray['offset'] = $offset;
     $contentInfoArray['viewmode'] = $viewMode;
     $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier;
     $contentInfoArray['node_depth'] = $node->attribute('depth');
     $contentInfoArray['url_alias'] = $node->attribute('url_alias');
     $contentInfoArray['current_language'] = $object->attribute('current_language');
     $contentInfoArray['language_mask'] = $object->attribute('language_mask');
     $contentInfoArray['main_node_id'] = $node->attribute('main_node_id');
     $contentInfoArray['main_node_url_alias'] = false;
     // Add url alias for main node if it is not current node and user has access to it
     if (!$node->isMain()) {
         $mainNode = $object->mainNode();
         if ($mainNode->canRead()) {
             $contentInfoArray['main_node_url_alias'] = $mainNode->attribute('url_alias');
         }
     }
     $contentInfoArray['persistent_variable'] = false;
     if ($tpl->variable('persistent_variable') !== false) {
         $contentInfoArray['persistent_variable'] = $tpl->variable('persistent_variable');
         $keyArray[] = array('persistent_variable', $contentInfoArray['persistent_variable']);
         $res->setKeys($keyArray);
     }
     $contentInfoArray['class_group'] = $object->attribute('match_ingroup_id_list');
     $contentInfoArray['state'] = $object->attribute('state_id_array');
     $contentInfoArray['state_identifier'] = $object->attribute('state_identifier_array');
     $contentInfoArray['parent_class_id'] = $parentClassID;
     $contentInfoArray['parent_class_identifier'] = $parentClassIdentifier;
     $contentInfoArray['parent_node_remote_id'] = $parentNodeRemoteID;
     $contentInfoArray['parent_object_remote_id'] = $parentObjectRemoteID;
     $Result['content_info'] = $contentInfoArray;
     // Store which templates were used to make this cache.
     $Result['template_list'] = $tpl->templateFetchList();
     // Check if time to live is set in template
     if ($tpl->hasVariable('cache_ttl')) {
         $cacheTTL = $tpl->variable('cache_ttl');
     }
     if (!isset($cacheTTL)) {
         $cacheTTL = -1;
     }
     $Result['cache_ttl'] = $cacheTTL;
     // if cache_ttl is set to 0 from the template, we need to add a no-cache advice
     // to the node's data. That way, the retrieve callback on the next calls
     // will be able to determine earlier that no cache generation should be started
     // for this node
     if ($cacheTTL == 0) {
         $Result['no_cache'] = true;
     }
     if ($languageCode) {
         $node->setCurrentLanguage($oldLanguageCode);
     }
     return $Result;
 }
コード例 #3
0
 /**
  * @param $tpl eZTemplate
  * @param $operatorName array
  * @param $operatorParameters array
  * @param $rootNamespace string
  * @param $currentNamespace string
  * @param $operatorValue mixed
  * @param $namedParameters array
  *
  * @return mixed
  */
 function modify(&$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     $ini = eZINI::instance('ocoperatorscollection.ini');
     $appini = eZINI::instance('app.ini');
     switch ($operatorName) {
         case 'related_attribute_objects':
             $object = $operatorValue;
             $identifier = $namedParameters['identifier'];
             $dataMap = $object instanceof eZContentObject || $object instanceof eZContentObjectTreeNode ? $object->attribute('data_map') : array();
             $data = array();
             if (isset($dataMap[$identifier])) {
                 $ids = $dataMap[$identifier] instanceof eZContentObjectAttribute ? explode('-', $dataMap[$identifier]->toString()) : array();
                 if (!empty($ids)) {
                     $data = eZContentObject::fetchList(true, array("id" => array($ids)));
                 }
             }
             $operatorValue = $data;
             break;
         case 'smart_override':
             $identifier = $namedParameters['identifier'];
             $view = $namedParameters['view'];
             $node = $operatorValue;
             $operatorValue = $this->findSmartTemplate($identifier, $view, $node);
             break;
         case 'parse_link_href':
             $href = $operatorValue;
             $hrefParts = explode(':', $href);
             $hrefFirst = array_shift($hrefParts);
             if (!in_array($hrefFirst, array('http', 'https', 'file', 'mailto', 'ftp'))) {
                 if (!empty($hrefFirst)) {
                     $nodeID = eZURLAliasML::fetchNodeIDByPath('/' . $hrefFirst);
                     if ($nodeID) {
                         $contentNode = eZContentObjectTreeNode::fetch($nodeID);
                         if ($contentNode instanceof eZContentObjectTreeNode) {
                             $keyArray = array(array('node', $contentNode->attribute('node_id')), array('object', $contentNode->attribute('contentobject_id')), array('class_identifier', $contentNode->attribute('class_identifier')), array('class_group', $contentNode->attribute('object')->attribute('content_class')->attribute('match_ingroup_id_list')));
                             $tpl = new eZTemplate();
                             $ini = eZINI::instance();
                             $autoLoadPathList = $ini->variable('TemplateSettings', 'AutoloadPathList');
                             $extensionAutoloadPath = $ini->variable('TemplateSettings', 'ExtensionAutoloadPath');
                             $extensionPathList = eZExtension::expandedPathList($extensionAutoloadPath, 'autoloads/');
                             $autoLoadPathList = array_unique(array_merge($autoLoadPathList, $extensionPathList));
                             $tpl->setAutoloadPathList($autoLoadPathList);
                             $tpl->autoload();
                             $tpl->setVariable('node', $contentNode);
                             $tpl->setVariable('object', $contentNode->attribute('object'));
                             $tpl->setVariable('original_href', $href);
                             $res = new eZTemplateDesignResource();
                             $res->setKeys($keyArray);
                             $tpl->registerResource($res);
                             $result = trim($tpl->fetch('design:link/href.tpl'));
                             if (!empty($result)) {
                                 $href = $result;
                             }
                         }
                     }
                 }
             }
             return $operatorValue = $href;
             break;
         case 'gmap_static_image':
             try {
                 $cacheFileNames = array();
                 //@todo
                 $operatorValue = OCOperatorsCollectionsTools::gmapStaticImage($namedParameters['parameters'], $namedParameters['attribute'], $cacheFileNames);
             } catch (Exception $e) {
                 eZDebug::writeError($e->getMessage(), 'gmap_static_image');
             }
             break;
         case 'fa_class_icon':
             $faIconIni = eZINI::instance('fa_icons.ini');
             $node = $operatorValue;
             $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : $faIconIni->variable('ClassIcons', '_fallback');
             if ($node instanceof eZContentObjectTreeNode) {
                 if ($faIconIni->hasVariable('ClassIcons', $node->attribute('class_identifier'))) {
                     $data = $faIconIni->variable('ClassIcons', $node->attribute('class_identifier'));
                 }
             }
             $operatorValue = $data;
             break;
         case 'fa_object_icon':
             $faIconIni = eZINI::instance('fa_icons.ini');
             $object = $operatorValue;
             $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : '';
             if ($object instanceof eZContentObject) {
                 if ($faIconIni->hasVariable('ObjectIcons', $object->attribute('id'))) {
                     $data = $faIconIni->variable('ObjectIcons', $object->attribute('id'));
                 }
             } else {
                 if ($faIconIni->hasVariable('ObjectIcons', $node)) {
                     $data = $faIconIni->variable('ObjectIcons', $node);
                 }
             }
             $operatorValue = $data;
             break;
         case 'fa_node_icon':
             $faIconIni = eZINI::instance('fa_icons.ini');
             $node = $operatorValue;
             $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : '';
             if ($node instanceof eZContentObjectTreeNode) {
                 if ($faIconIni->hasVariable('NodeIcons', $node->attribute('node_id'))) {
                     $data = $faIconIni->variable('NodeIcons', $node->attribute('node_id'));
                 }
             } else {
                 if ($faIconIni->hasVariable('NodeIcons', $node)) {
                     $data = $faIconIni->variable('NodeIcons', $node);
                 }
             }
             $operatorValue = $data;
             break;
         case 'children_class_identifiers':
             $node = $operatorValue;
             $data = array();
             if ($node instanceof eZContentObjectTreeNode) {
                 $search = eZFunctionHandler::execute('ezfind', 'search', array('subtree_array' => array($node->attribute('node_id')), 'limit' => 1, 'as_objects' => false, 'filter' => array('-meta_id_si:' . $node->attribute('contentobject_id')), 'facet' => array(array('field' => 'meta_class_identifier_ms', 'name' => 'class_identifier', 'limit' => 200))));
                 if (isset($search['SearchExtras'])) {
                     $facets = $search['SearchExtras']->attribute('facet_fields');
                     $data = array_diff(array_values($facets[0]['nameList']), $namedParameters['exclude']);
                 }
             }
             //eZDebug::writeNotice( $data, 'children_class_identifiers'  );
             $operatorValue = $data;
             break;
         case 'json_encode':
             $operatorValue = json_encode($operatorValue);
             break;
         case 'browse_template':
             $identifiers = array('image', 'image2', 'galleria', 'gallery', 'immagini');
             if ($ini->hasVariable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers')) {
                 $identifiers = $ini->variable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers');
             }
             if ($operatorValue instanceof eZContentBrowse && $operatorValue->hasAttribute('type') && $operatorValue->attribute('type') == 'AddRelatedObjectListToDataType' && $operatorValue->hasAttribute('action_name')) {
                 $currentAttributeId = str_replace('AddRelatedObject_', '', $operatorValue->attribute('action_name'));
                 $currentAttribute = eZPersistentObject::fetchObject(eZContentObjectAttribute::definition(), null, array("id" => $currentAttributeId), false);
                 if (isset($currentAttribute['contentclassattribute_id'])) {
                     $contentClassAttribute = eZContentClassAttribute::fetch($currentAttribute['contentclassattribute_id']);
                     if ($contentClassAttribute instanceof eZContentClassAttribute && ($contentClassAttribute->attribute('data_type_string') == 'mugoobjectrelationlist' || $contentClassAttribute->attribute('data_type_string') == 'ezobjectrelationlist') && in_array($contentClassAttribute->attribute('identifier'), $identifiers)) {
                         return $operatorValue = 'multiupload.tpl';
                     }
                 }
             } elseif ($operatorValue instanceof eZContentBrowse && $operatorValue->hasAttribute('action_name') && $operatorValue->attribute('action_name') == 'MultiUploadBrowse') {
                 return $operatorValue = 'multiupload.tpl';
             }
             $operatorValue = 'default.tpl';
             break;
         case 'multiupload_file_types_string':
             $availableFileTypes = array();
             $availableFileTypesString = '';
             if (eZINI::instance('ezmultiupload.ini')->hasGroup('FileTypeSettings_' . $operatorValue)) {
                 $availableFileTypes = eZINI::instance('ezmultiupload.ini')->variable('FileTypeSettings_' . $operatorValue, 'FileType');
             }
             if (!empty($availableFileTypes)) {
                 $availableFileTypesString = implode(';', $availableFileTypes);
             }
             $operatorValue = $availableFileTypesString;
             break;
         case 'multiupload_file_types_string_from_attribute':
             $availableFileTypesString = '';
             $attribute = $operatorValue;
             if ($attribute instanceof eZContentObjectAttribute) {
                 $identifiers = array();
                 if ($ini->hasVariable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers')) {
                     $identifier = $attribute->attribute('contentclass_attribute_identifier');
                     $identifiers = $ini->variable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers');
                     if (in_array($identifier, $identifiers)) {
                         $availableFileTypes = array();
                         $groups = $ini->group('ObjectRelationsMultiuploadFileTypesGroups');
                         foreach ($groups as $groupName => $fileType) {
                             $groupIdentifiers = $ini->variable('ObjectRelationsMultiuploadFileTypes_' . $groupName, 'Identifiers');
                             if (in_array($identifier, $groupIdentifiers)) {
                                 $availableFileTypesString = $fileType;
                             }
                         }
                     }
                 }
             }
             $operatorValue = $availableFileTypesString;
             break;
         case 'session_id':
             $operatorValue = session_id();
             break;
         case 'session_name':
             $operatorValue = session_name();
             break;
         case 'user_session_hash':
             $operatorValue = '';
             break;
         case 'developer_warning':
             $res = false;
             $user = eZUser::currentUser();
             if ($user->attribute('login') == 'admin') {
                 $templates = $tpl->templateFetchList();
                 $data = array_pop($templates);
                 $res = '<div class="developer-warning alert alert-danger"><strong>Avviso per lo sviluppatore</strong>:<br /><code>' . $data . '</code><br />' . $namedParameters['text'] . '</div>';
             }
             $operatorValue = $res;
             break;
         case 'editor_warning':
             $res = false;
             $user = eZUser::currentUser();
             if ($user->hasAccessTo('content', 'dashboard')) {
                 $res = '<div class="editor-warning alert alert-warning"><strong>Avviso per l\'editor</strong>: ' . $namedParameters['text'] . '</div>';
             }
             $operatorValue = $res;
             break;
         case 'appini':
             if ($appini->hasVariable($namedParameters['block'], $namedParameters['setting'])) {
                 $rs = $appini->variable($namedParameters['block'], $namedParameters['setting']);
             } else {
                 $rs = $namedParameters['default'];
             }
             $operatorValue = $rs;
             break;
         case 'has_attribute':
         case 'attribute':
             if ($operatorName == 'attribute' && $namedParameters['show_values'] == 'show') {
                 $legacy = new eZTemplateAttributeOperator();
                 $parameters = $legacy->namedParameterList();
                 if (isset($parameters['attribute'])) {
                     $parameters = $parameters['attribute'];
                 }
                 $legacyParameters = array();
                 foreach (array_keys($parameters) as $key) {
                     switch ($key) {
                         case "as_html":
                             $legacyParameters[$key] = true;
                             break;
                         default:
                             $legacyParameters[$key] = isset($namedParameters[$key]) ? $namedParameters[$key] : false;
                     }
                 }
                 $legacy->modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, $operatorValue, $legacyParameters, null);
                 return $operatorValue;
             }
             return $operatorValue = $this->hasContentObjectAttribute($operatorValue, $namedParameters['show_values']);
             break;
         case 'set_defaults':
             if (is_array($namedParameters['variables'])) {
                 foreach ($namedParameters['variables'] as $key => $value) {
                     if (!$tpl->hasVariable($key, $currentNamespace)) {
                         $tpl->setLocalVariable($key, $value, $currentNamespace);
                     }
                 }
             }
             break;
         case 'unset_defaults':
             foreach ($namedParameters['variables'] as $key) {
                 $tpl->unsetLocalVariable($key, $currentNamespace);
                 //                    if ( isset( $tpl->Variables[$rootNamespace] ) &&
                 //                         array_key_exists( $key, $tpl->Variables[$rootNamespace] ) )
                 //                    {
                 //                        $tpl->unsetVariable( $key, $rootNamespace );
                 //                    }
             }
             break;
             //@todo add cache!
         //@todo add cache!
         case 'include_cache':
             $tpl = eZTemplate::factory();
             foreach ($namedParameters['variables'] as $key => $value) {
                 $tpl->setVariable($key, $value);
             }
             $operatorValue = $tpl->fetch('design:' . $namedParameters['template']);
             break;
         case 'find_global_layout':
             $result = false;
             $node = $operatorValue;
             if (is_numeric($node)) {
                 $node = eZContentObjectTreeNode::fetch($node);
             }
             if (!$node) {
                 return $operatorValue = $result;
             }
             $pathArray = $node->attribute('path_array');
             $nodesParams = array();
             foreach ($pathArray as $pathNodeID) {
                 if ($pathNodeID < eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode') || $pathNodeID == $node->attribute('node_id')) {
                     continue;
                 } else {
                     $nodesParams[] = array('ParentNodeID' => $pathNodeID, 'ResultID' => 'ezcontentobject_tree.node_id', 'ClassFilterType' => 'include', 'ClassFilterArray' => $ini->variable('GlobalLayout', 'Classes'), 'Depth' => 1, 'DepthOperator' => 'eq', 'AsObject' => false);
                 }
             }
             //eZDebug::writeWarning( var_export($nodesParams,1), __METHOD__);
             $findNodes = eZContentObjectTreeNode::subTreeMultiPaths($nodesParams, array('SortBy' => array('node_id', false)));
             $sortByParentNodeID = array();
             if (!empty($findNodes)) {
                 foreach ($findNodes as $findNode) {
                     $sortByParentNodeID[$findNode['parent_node_id']] = $findNode;
                 }
                 krsort($sortByParentNodeID);
                 $result = array_shift($sortByParentNodeID);
                 $result = eZContentObjectTreeNode::makeObjectsArray(array($result));
                 if (!empty($result)) {
                     $result = $result[0];
                 }
             }
             return $operatorValue = $result;
         case 'redirect':
             $url = $namedParameters['url'];
             header('Location: ' . $url);
             break;
         case 'sort_nodes':
             $sortNodes = array();
             if (!empty($operatorValue) && is_array($operatorValue)) {
                 $nodes = $operatorValue;
                 foreach ($nodes as $node) {
                     if (!$node instanceof eZContentObjectTreeNode) {
                         continue;
                     }
                     $object = $node->object();
                     switch ($namedParameters['by']) {
                         case 'published':
                         default:
                             $sortby = $object->attribute('published');
                             break;
                     }
                     $sortNodes[$sortby] = $node;
                 }
                 ksort($sortNodes);
                 if ($namedParameters['order'] == 'desc') {
                     $sortNodes = array_reverse($sortNodes);
                 }
             }
             return $operatorValue = $sortNodes;
             break;
         case 'to_query_string':
             if (!empty($namedParameters['param'])) {
                 $value = $namedParameters['param'];
             } else {
                 $value = $operatorValue;
             }
             $string = http_build_query($value);
             return $operatorValue = $string;
             break;
         case 'has_abstract':
         case 'abstract':
             $node = $operatorValue;
             if (!$node instanceof eZContentObjectTreeNode && isset($namedParameters['node'])) {
                 $node = $namedParameters['node'];
                 if (is_numeric($node)) {
                     $node = eZContentObjectTreeNode::fetch($node);
                 }
             }
             return $operatorValue = $this->getAbstract($node, $operatorName == 'has_abstract');
             break;
         case 'subsite':
             $path = $this->getPath($tpl);
             $result = false;
             $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array();
             $root = eZContentObjectTreeNode::fetch(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode'));
             if (in_array($root->attribute('class_identifier'), $identifiers)) {
                 $result = $root;
             }
             foreach ($path as $item) {
                 if (isset($item['node_id'])) {
                     $node = eZContentObjectTreeNode::fetch($item['node_id']);
                     if (in_array($node->attribute('class_identifier'), $identifiers)) {
                         $result = $node;
                     }
                 }
             }
             return $operatorValue = $result;
             break;
         case 'in_subsite':
             $result = false;
             $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array();
             $root = eZContentObjectTreeNode::fetch(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode'));
             if (in_array($root->attribute('class_identifier'), $identifiers)) {
                 $result = $root;
             }
             $node = $operatorValue;
             if (is_numeric($node)) {
                 $node = eZContentObjectTreeNode::fetch($node);
             }
             if (!$node) {
                 return $operatorValue = $result;
             }
             foreach ($node->attribute('path') as $item) {
                 if (in_array($item->attribute('class_identifier'), $identifiers)) {
                     $result = $item;
                     break;
                 }
             }
             return $operatorValue = $result;
             break;
         case 'is_subsite':
             $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array();
             $inSubsite = false;
             $node = $operatorValue;
             if (is_numeric($node)) {
                 $node = eZContentObjectTreeNode::fetch($node);
             }
             if (!$node instanceof eZContentObjectTreeNode) {
                 $inSubsite = false;
             } elseif (in_array($node->attribute('class_identifier'), $identifiers)) {
                 $inSubsite = true;
             }
             return $operatorValue = $inSubsite;
             break;
         case 'is_in_subsite':
             if ($operatorValue instanceof eZContentObject) {
                 $nodes = $operatorValue->attribute('assigned_nodes');
                 foreach ($nodes as $node) {
                     if ($this->isNodeInCurrentSiteaccess($node)) {
                         return $operatorValue;
                     }
                 }
             } elseif ($operatorValue instanceof eZContentObjectTreeNode) {
                 if ($this->isNodeInCurrentSiteaccess($operatorValue)) {
                     return $operatorValue;
                 }
             }
             return $operatorValue = false;
         case 'section_color':
             $path = $this->getPath($tpl);
             $color = false;
             $attributesIdentifiers = $ini->hasVariable('Color', 'Attributes') ? $ini->variable('Color', 'Attributes') : array();
             foreach ($path as $item) {
                 if (isset($item['node_id'])) {
                     $node = eZContentObjectTreeNode::fetch($item['node_id']);
                     /** @var eZContentObjectAttribute[] $attributes */
                     $attributes = $node->attribute('object')->fetchAttributesByIdentifier($attributesIdentifiers);
                     if (is_array($attributes)) {
                         foreach ($attributes as $attribute) {
                             if ($attribute->hasContent()) {
                                 $color = $attribute->content();
                             }
                         }
                     }
                 }
             }
             return $operatorValue = $color;
             break;
         case 'oc_shorten':
             $search = array('@<script[^>]*?>.*?</script>@si', '@<style[^>]*?>.*?</style>@siU');
             $operatorValue = preg_replace($search, '', $operatorValue);
             $operatorValue = strip_tags($operatorValue, $namedParameters['allowable_tags']);
             $operatorValue = preg_replace('!\\s+!', ' ', $operatorValue);
             $operatorValue = str_replace('&nbsp;', ' ', $operatorValue);
             $strlenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen';
             $operatorLength = $strlenFunc($operatorValue);
             if ($operatorLength > $namedParameters['chars_to_keep']) {
                 if ($namedParameters['trim_type'] === 'middle') {
                     $appendedStrLen = $strlenFunc($namedParameters['str_to_append']);
                     if ($namedParameters['chars_to_keep'] > $appendedStrLen) {
                         $chop = $namedParameters['chars_to_keep'] - $appendedStrLen;
                         $middlePos = (int) ($chop / 2);
                         $leftPartLength = $middlePos;
                         $rightPartLength = $chop - $middlePos;
                         $operatorValue = trim($this->custom_substr($operatorValue, 0, $leftPartLength) . $namedParameters['str_to_append'] . $this->custom_substr($operatorValue, $operatorLength - $rightPartLength, $rightPartLength));
                     } else {
                         $operatorValue = $namedParameters['str_to_append'];
                     }
                 } else {
                     $chop = $namedParameters['chars_to_keep'] - $strlenFunc($namedParameters['str_to_append']);
                     $operatorValue = $this->custom_substr($operatorValue, 0, $chop);
                     $operatorValue = trim($operatorValue);
                     if ($operatorLength > $chop) {
                         $operatorValue = $operatorValue . $namedParameters['str_to_append'];
                     }
                 }
             }
             if ($namedParameters['allowable_tags'] !== '') {
                 $operatorValue = $this->force_balance_tags($operatorValue);
             }
             break;
         case 'cookieset':
             $key = isset($namedParameters['cookie_name']) ? $namedParameters['cookie_name'] : false;
             $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix');
             $key = "{$prefix}{$key}";
             // Get our parameters:
             $value = $namedParameters['cookie_val'];
             $expire = $namedParameters['expiry_time'];
             // Check and calculate the expiry time:
             if ($expire > 0) {
                 // It is a number of days:
                 $expire = time() + 60 * 60 * 24 * $expire;
             }
             setcookie($key, $value, $expire, '/');
             eZDebug::writeDebug('setcookie(' . $key . ', ' . $value . ', ' . $expire . ', "/")', __METHOD__);
             return $operatorValue = false;
             break;
         case 'cookieget':
             $key = isset($namedParameters['cookie_name']) ? $namedParameters['cookie_name'] : false;
             $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix');
             $key = "{$prefix}{$key}";
             $operatorValue = false;
             if (isset($_COOKIE[$key])) {
                 $operatorValue = $_COOKIE[$key];
             }
             return $operatorValue;
             break;
         case 'check_and_set_cookies':
             $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix');
             $http = eZHTTPTool::instance();
             $return = array();
             if ($ini->hasVariable('Cookies', 'Cookies')) {
                 $cookies = $ini->variable('Cookies', 'Cookies');
                 foreach ($cookies as $key) {
                     $_key = "{$prefix}{$key}";
                     $default = isset($_COOKIE[$_key]) ? $_COOKIE[$_key] : $ini->variable($key, 'Default');
                     $value = $http->variable($key, $default);
                     setcookie($_key, $value, time() + 60 * 60 * 24 * 365, '/');
                     $return[$key] = $value;
                 }
             }
             $operatorValue = $return;
             break;
         case 'checkbrowser':
             @(require 'extension/ocoperatorscollection/lib/browser_detection.php');
             if (function_exists('browser_detection')) {
                 $full = browser_detection('full_assoc', 2);
                 $operatorValue = $full;
             } else {
                 eZDebug::writeError("function browser_detection not found", __METHOD__);
             }
             break;
         case 'is_deprecated_browser':
             $browser = $namedParameters['browser_array'];
             if ($browser['browser_working'] == 'ie' && $browser['browser_number'] > '7.0') {
                 $operatorValue = true;
             }
             $operatorValue = false;
             break;
         case 'slugize':
             $operatorValue = $this->sanitize_title_with_dashes($operatorValue);
             break;
     }
     return false;
 }
コード例 #4
0
 /**
  * @deprecated usare un client ad hoc
  *
  * @param eZModule $module
  * @param eZTemplate $tpl
  * @param $repositoryNodeID
  * @param $localParentNodeID
  *
  * @throws Exception
  */
 protected function handleTagChooserImport(eZModule $module, eZTemplate $tpl, $repositoryNodeID, $localParentNodeID, &$Result)
 {
     if (isset($this->attributes['definition']['AskTagTematica']) && $this->attributes['definition']['AskTagTematica'] == true) {
         $http = eZHTTPTool::instance();
         if (!$http->hasPostVariable('SelectTags')) {
             $tpl->setVariable('fromPage', '/repository/import/' . $this->attributes['definition']['Identifier'] . '/' . $repositoryNodeID);
             $tpl->setVariable('localParentNodeID', $localParentNodeID);
             $Result['content'] = $tpl->fetch('design:repository/eztagschooser.tpl');
             $Result['path'] = array(array('url' => false, 'text' => 'Scegli Tag'));
             return;
         } else {
             $tagIDs = array();
             $tagKeywords = array();
             $tagParents = array();
             foreach ($_POST as $key => $value) {
                 if (substr($key, 0, 8) == 'tematica') {
                     list($tagID, $tagKeyword, $tagParent) = explode(";", $value);
                     $tagIDs[] = $tagID;
                     $tagKeywords[] = $tagKeyword;
                     $tagParents[] = $tagParent;
                 }
             }
         }
         $newObject = $this->import($repositoryNodeID, $localParentNodeID);
         foreach ($newObject->contentObjectAttributes() as $attribute) {
             if ($attribute->contentClassAttributeIdentifier() == 'tematica') {
                 $eZTags = new eZTags();
                 $eZTags->createFromStrings(implode('|#', $tagIDs), implode('|#', $tagKeywords), implode('|#', $tagParents));
                 $eZTags->store($attribute);
                 break;
             }
         }
         $module->redirectTo($newObject->attribute('main_node')->attribute('url_alias'));
     } else {
         $newObject = $this->import($repositoryNodeID, $localParentNodeID);
         $module->redirectTo($newObject->attribute('main_node')->attribute('url_alias'));
     }
 }
コード例 #5
0
 /**
  * Generate G+ comments feed for an activity
  * @param eZTemplate $tpl
  * @param array $namedParameters
  * @return string
  */
 private function getGooglePlusComments($tpl, $namedParameters)
 {
     //get config
     $nlGooglePlusIni = eZINI::instance('nlgoogleplus.ini');
     //initilize G+ Service
     $plus = $this->initializeGooglePlusService();
     if (!isset($namedParameters['activityid'])) {
         eZLog::write('Activity id is required', 'error.log');
         return false;
     }
     //parameters needed
     $activityId = $namedParameters['activityid'];
     $title = $namedParameters['title'];
     //find all related comments
     $optParams = array('maxResults' => $nlGooglePlusIni->variable('Feed', 'MaxResults'));
     try {
         $comments = $plus->comments->listComments($activityId, $optParams);
     } catch (Exception $e) {
         eZLog::write('Google Plus get comments problem : ' . $e->getMessage(), 'error.log');
     }
     //use template
     $tpl->setVariable('comments', $comments);
     $tpl->setVariable('title', $title);
     return $tpl->fetch('design:nlgoogleplus/googleplusboxcomments.tpl');
 }