Example #1
0
function exitWithInternalError( $errorText )
{
    header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
    //include_once( 'extension/ezjscore/classes/ezjscajaxcontent.php' );
    $contentType = ezjscAjaxContent::getHttpAccept();

    // set headers
    if ( $contentType === 'xml' )
        header('Content-Type: text/xml; charset=utf-8');
    else if ( $contentType === 'json' )
        header('Content-Type: text/javascript; charset=utf-8');

    echo ezjscAjaxContent::autoEncode( array( 'error_text' => $errorText, 'content' => '' ), $contentType );
    eZExecution::cleanExit();
}
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case 'json_encode':
             // Lets you use json_encode from templates
             $operatorValue = json_encode($namedParameters['hash']);
             break;
         case 'xml_encode':
             // Lets you use ezjscAjaxContent::xmlEncode from templates
             $operatorValue = ezjscAjaxContent::xmlEncode($namedParameters['hash']);
             break;
         case 'node_encode':
             // Lets you use ezjscAjaxContent::nodeEncode from templates
             $operatorValue = ezjscAjaxContent::nodeEncode($namedParameters['node'], $namedParameters['params'], $namedParameters['type']);
             break;
     }
 }
Example #3
0
function multipleezjscServerCalls($calls, $contentType = 'json')
{
    $r = array();
    foreach ($calls as $key => $call) {
        $response = array('error_text' => '', 'content' => '');
        if ($call instanceof ezjscServerRouter) {
            try {
                $response['content'] = $call->call();
            } catch (Exception $e) {
                $response['error_text'] = $e->getMessage();
            }
        } else {
            $response['error_text'] = 'Not a valid ezjscServerRouter argument: "' . htmlentities($call, ENT_QUOTES) . '"';
        }
        $r[] = ezjscAjaxContent::autoEncode($response, $contentType);
    }
    return $r;
}
Example #4
0
        $embedObject = eZContentObject::fetch($embedId);
    }
}
if (!$embedObject instanceof eZContentObject || !$embedObject->canRead()) {
    echo 'false';
    eZExecution::cleanExit();
}
// Params for node to json encoder
$params = array('loadImages' => true);
$params['imagePreGenerateSizes'] = array('small', 'original');
// look for datamap parameter ( what datamap attribute we should load )
if (isset($Params['DataMap']) && $Params['DataMap']) {
    $params['dataMap'] = array($Params['DataMap']);
}
// what image sizes we want returned with full data ( url++ )
if ($http->hasPostVariable('imagePreGenerateSizes')) {
    $params['imagePreGenerateSizes'][] = $http->postVariable('imagePreGenerateSizes');
} else {
    if (isset($Params['ImagePreGenerateSizes']) && $Params['ImagePreGenerateSizes']) {
        $params['imagePreGenerateSizes'][] = $Params['ImagePreGenerateSizes'];
    }
}
// encode embed object as a json response
$json = ezjscAjaxContent::nodeEncode($embedObject, $params);
// display debug as a js comment
//echo "/*\r\n";
//eZDebug::printReport( false, false );
//echo "*/\r\n";
echo $json;
eZDB::checkTransactionCounter();
eZExecution::cleanExit();
Example #5
0
 /**
  * Returns search results based on given post params
  *
  * @param mixed $args Only used if post parameter is not set
  *              0 => SearchStr
  *              1 => SearchOffset
  *              2 => SearchLimit (10 by default, max 50)
  * @return array
  */
 public static function search($args)
 {
     $http = eZHTTPTool::instance();
     if ($http->hasPostVariable('SearchStr')) {
         $searchStr = trim($http->postVariable('SearchStr'));
     } else {
         if (isset($args[0])) {
             $searchStr = trim($args[0]);
         }
     }
     if ($http->hasPostVariable('SearchOffset')) {
         $searchOffset = (int) $http->postVariable('SearchOffset');
     } else {
         if (isset($args[1])) {
             $searchOffset = (int) $args[1];
         } else {
             $searchOffset = 0;
         }
     }
     if ($http->hasPostVariable('SearchLimit')) {
         $searchLimit = (int) $http->postVariable('SearchLimit');
     } else {
         if (isset($args[2])) {
             $searchLimit = (int) $args[2];
         } else {
             $searchLimit = 10;
         }
     }
     // Do not allow to search for more then x items at a time
     $ini = eZINI::instance();
     $maximumSearchLimit = (int) $ini->variable('SearchSettings', 'MaximumSearchLimit');
     if ($searchLimit > $maximumSearchLimit) {
         $searchLimit = $maximumSearchLimit;
     }
     // Prepare node encoding parameters
     $encodeParams = array();
     if (self::hasPostValue($http, 'EncodingLoadImages')) {
         $encodeParams['loadImages'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchChildrenCount')) {
         $encodeParams['fetchChildrenCount'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchSection')) {
         $encodeParams['fetchSection'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFormatDate')) {
         $encodeParams['formatDate'] = $http->postVariable('EncodingFormatDate');
     }
     // Prepare search parameters
     $params = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SortArray' => array('published', 0), 'SortBy' => array('published' => 'desc'));
     if (self::hasPostValue($http, 'SearchContentClassAttributeID')) {
         $params['SearchContentClassAttributeID'] = self::makePostArray($http, 'SearchContentClassAttributeID');
     } else {
         if (self::hasPostValue($http, 'SearchContentClassID')) {
             $params['SearchContentClassID'] = self::makePostArray($http, 'SearchContentClassID');
         } else {
             if (self::hasPostValue($http, 'SearchContentClassIdentifier')) {
                 $params['SearchContentClassID'] = eZContentClass::classIDByIdentifier(self::makePostArray($http, 'SearchContentClassIdentifier'));
             }
         }
     }
     if (self::hasPostValue($http, 'SearchSubTreeArray')) {
         $params['SearchSubTreeArray'] = self::makePostArray($http, 'SearchSubTreeArray');
     }
     if (self::hasPostValue($http, 'SearchSectionID')) {
         $params['SearchSectionID'] = self::makePostArray($http, 'SearchSectionID');
     }
     if (self::hasPostValue($http, 'SearchDate')) {
         $params['SearchDate'] = (int) $http->postVariable('SearchDate');
     } else {
         if (self::hasPostValue($http, 'SearchTimestamp')) {
             $params['SearchTimestamp'] = self::makePostArray($http, 'SearchTimestamp');
             if (!isset($params['SearchTimestamp'][1])) {
                 $params['SearchTimestamp'] = $params['SearchTimestamp'][0];
             }
         }
     }
     if (self::hasPostValue($http, 'EnableSpellCheck') || self::hasPostValue($http, 'enable-spellcheck', '0')) {
         $params['SpellCheck'] = array(true);
     }
     if (self::hasPostValue($http, 'GetFacets') || self::hasPostValue($http, 'show-facets', '0')) {
         $params['facet'] = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array());
     }
     $result = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SearchResultCount' => 0, 'SearchCount' => 0, 'SearchResult' => array(), 'SearchString' => $searchStr, 'SearchExtras' => array());
     // Possibility to keep track of callback reference for use in js callback function
     if ($http->hasPostVariable('CallbackID')) {
         $result['CallbackID'] = $http->postVariable('CallbackID');
     }
     // Only search if there is something to search for
     if ($searchStr) {
         $searchList = eZSearch::search($searchStr, $params);
         $result['SearchResultCount'] = $searchList['SearchResult'] !== false ? count($searchList['SearchResult']) : 0;
         $result['SearchCount'] = (int) $searchList['SearchCount'];
         $result['SearchResult'] = ezjscAjaxContent::nodeEncode($searchList['SearchResult'], $encodeParams, false);
         // ezfind stuff
         if (isset($searchList['SearchExtras']) && $searchList['SearchExtras'] instanceof ezfSearchResultInfo) {
             if (isset($params['SpellCheck'])) {
                 $result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck');
             }
             if (isset($params['facet'])) {
                 $facetInfo = array();
                 $retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields');
                 $baseSearchUrl = "/content/search/";
                 eZURI::transformURI($baseSearchUrl, false, 'full');
                 foreach ($params['facet'] as $key => $defaultFacet) {
                     $facetData = $retrievedFacets[$key];
                     $facetInfo[$key] = array('name' => $defaultFacet['name'], 'list' => array());
                     if ($facetData !== null) {
                         foreach ($facetData['nameList'] as $key2 => $facetName) {
                             if ($key2 != '') {
                                 $tmp = array('value' => $facetName);
                                 $tmp['url'] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName;
                                 $tmp['count'] = $facetData['countList'][$key2];
                                 $facetInfo[$key]['list'][] = $tmp;
                             }
                         }
                     }
                 }
                 $result['SearchExtras']['facets'] = $facetInfo;
             }
         }
         //$searchList['SearchExtras'] instanceof ezfSearchResultInfo
     }
     // $searchStr
     return $result;
 }
Example #6
0
    if ($contentIni->hasVariable('embed-inline-type_' . $contentType, 'CustomAttributes')) {
        $customAttributes['embed-inline'] = $contentIni->variable('embed-inline-type_' . $contentType, 'CustomAttributes');
    } else {
        if ($contentIni->hasVariable('embed-inline', 'CustomAttributes')) {
            $customAttributes['embed-inline'] = $contentIni->variable('embed-inline', 'CustomAttributes');
        }
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('object', $object);
$tpl->setVariable('object_id', $objectID);
$tpl->setVariable('object_version', $objectVersion);
$tpl->setVariable('embed_id', $embedId);
$tpl->setVariable('embed_type', $embedType);
$tpl->setVariable('embed_object', $embedObject);
$tpl->setVariable('embed_data', ezjscAjaxContent::nodeEncode($embedObject, $params));
$tpl->setVariable('content_type', $contentType);
$tpl->setVariable('content_type_name', ucfirst(rtrim($contentType, 's')));
$tpl->setVariable('compatibility_mode', $ezoeIni->variable('EditorSettings', 'CompatibilityMode'));
$tpl->setVariable('tag_name', $tagName);
$xmlTagAliasList = $ezoeIni->variable('EditorSettings', 'XmlTagNameAlias');
if (isset($xmlTagAliasList[$tagName])) {
    $tpl->setVariable('tag_name_alias', $xmlTagAliasList[$tagName]);
} else {
    $tpl->setVariable('tag_name_alias', $tagName);
}
$tpl->setVariable('view_list', json_encode(array('embed' => $viewList, 'embed-inline' => $viewListInline)));
$tpl->setVariable('class_list', json_encode(array('embed' => $classList, 'embed-inline' => $classListInline)));
$tpl->setVariable('attribute_defaults', json_encode(array('embed' => $attributeDefaults, 'embed-inline' => $attributeDefaultsInline)));
$tpl->setVariable('custom_attributes', $customAttributes);
$tpl->setVariable('size_list', $sizeTypeArray);
Example #7
0
 /**
  * Gets current users bookmarks by offset and limit
  *
  * @param array $args  0 => node id:1, 1 => offset:0, 2 => limit:10
  * @return hash
  */
 public static function browse($args)
 {
     $nodeID = isset($args[0]) ? (int) $args[0] : 1;
     $offset = isset($args[1]) ? (int) $args[1] : 0;
     $limit = isset($args[2]) ? (int) $args[2] : 10;
     $http = eZHTTPTool::instance();
     if (!$nodeID) {
         throw new ezcBaseFunctionalityNotSupportedException('Browse node list', 'Parent node id is not valid');
     }
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node instanceof eZContentObjectTreeNode) {
         throw new ezcBaseFunctionalityNotSupportedException('Browse node list', "Parent node '{$nodeID}' is not valid");
     } else {
         if (!$node->canRead()) {
             throw new ezcBaseFunctionalityNotSupportedException('Browse node list', "Parent node '{$nodeID}' is not valid");
         }
     }
     $params = array('Depth' => 1, 'Limit' => $limit, 'Offset' => $offset, 'SortBy' => $node->attribute('sort_array'), 'DepthOperator' => 'eq', 'AsObject' => true);
     // Look for some (class filter and sort by) post params to use as fetch params
     if ($http->hasPostVariable('ClassFilterArray') && $http->postVariable('ClassFilterArray') !== '') {
         $params['ClassFilterType'] = 'include';
         $params['ClassFilterArray'] = $http->postVariable('ClassFilterArray');
     }
     if ($http->hasPostVariable('SortBy') && $http->postVariable('SortBy') !== '') {
         $params['SortBy'] = $http->postVariable('SortBy');
     }
     // fetch nodes and total node count
     $count = $node->subTreeCount($params);
     if ($count) {
         $nodeArray = $node->subTree($params);
     } else {
         $nodeArray = false;
     }
     // generate json response from node list
     if ($nodeArray) {
         $list = ezjscAjaxContent::nodeEncode($nodeArray, array('fetchChildrenCount' => true, 'loadImages' => true), 'raw');
     } else {
         $list = array();
     }
     return array('list' => $list, 'count' => count($nodeArray), 'total_count' => (int) $count, 'node' => ezjscAjaxContent::nodeEncode($node, array('fetchPath' => true), 'raw'), 'offset' => $offset, 'limit' => $limit);
 }
 /**
  * Returns a node data for given object / node id
  *
  * Following parameters are supported:
  * ezjscnode::load::embed_id[::attribute[::load_image_size]]
  *
  * eg: ezjscnode::load::ezobject_46::image::large
  * eg: ezjscnode::load::eznode_44::summary
  *eg: ezjscnode::load::44::summary (44 is in this case node id)
  *
  * @since 1.2
  * @param mixed $args
  * @throws InvalidArgumentException
  * @return array
  */
 public static function load($args)
 {
     $embedObject = false;
     if (isset($args[0]) && $args[0]) {
         $embedType = 'eznode';
         if (is_numeric($args[0])) {
             $embedId = $args[0];
         } else {
             list($embedType, $embedId) = explode('_', $args[0]);
         }
         if ($embedType === 'eznode' || strcasecmp($embedType, 'eznode') === 0) {
             $embedObject = eZContentObject::fetchByNodeID($embedId);
         } else {
             $embedObject = eZContentObject::fetch($embedId);
         }
     }
     if (!$embedObject instanceof eZContentObject) {
         throw new InvalidArgumentException("Argument 1: '{$embedType}\\_{$embedId}' does not map to a valid content object");
     } else {
         if (!$embedObject->canRead()) {
             throw new InvalidArgumentException("Argument 1: '{$embedType}\\_{$embedId}' is not available");
         }
     }
     // Params for node to json encoder
     $params = array('loadImages' => true);
     $params['imagePreGenerateSizes'] = array('small', 'original');
     // look for attribute parameter ( what attribute we should load )
     if (isset($args[1]) && $args[1]) {
         $params['dataMap'] = array($args[1]);
     }
     // what image sizes we want returned with full data ( url++ )
     if (isset($args[2]) && $args[2]) {
         $params['imagePreGenerateSizes'][] = $args[2];
     }
     // Simplify and load data in accordance to $params
     return ezjscAjaxContent::simplify($embedObject, $params);
 }