示例#1
0
文件: item.php 项目: horrabin/opendb
/**
* 	NOTE: PRIVATE FUNCTION.

	Will return the FROM and WHERE clauses for a selection from the item table.
	
	If $owner_id defined, will limit to only items owned by owner_id
	If $s_item_type defined, will limit to only items of that type.
	If $category defined, will limit to only items of that category.
	If $letter defined will limit to item.title starting with that letter.
	If $interest_level defined will limit to items with that interest level or higher.
	
	@param $HTTP_VARS['...'] variables supported: 
		owner_id, s_item_type, s_item_type[], s_item_type_group, title, title_match, category,
		rating, attribute_type, lookup_attribute_val, attribute_val, attr_match, 
		update_on, datetimemask, update_on_days, letter, start_item_id
		s_status_type[], status_comment, not_s_status_type[], interest_level
*/
function from_and_where_clause($HTTP_VARS, $column_display_config_rs = NULL, $query_type = 'LISTING')
{
    // For checking whether count (DISTINCT ...) is supported, and thus
    // whether we have to do any special processing!
    $from_r[] = 'item i';
    $from_r[] = 'item_instance ii';
    $where_r[] = 'ii.item_id = i.id';
    // only parent items should ever be listed.
    //
    // Owner restriction
    //
    if (strlen($HTTP_VARS['owner_id']) > 0) {
        $where_r[] = 'ii.owner_id = \'' . $HTTP_VARS['owner_id'] . '\'';
    } else {
        if (strlen($HTTP_VARS['not_owner_id']) > 0) {
            //For not showing current user items.
            $where_r[] = 'ii.owner_id <> \'' . $HTTP_VARS['not_owner_id'] . '\'';
        }
    }
    //
    // Item Type / Item Type group restriction
    //
    if (!is_array($HTTP_VARS['s_item_type']) && strlen($HTTP_VARS['s_item_type']) > 0) {
        $where_r[] = 'i.s_item_type = \'' . $HTTP_VARS['s_item_type'] . '\'';
    } else {
        if (strlen($HTTP_VARS['s_item_type_group']) > 0) {
            $from_r[] = 's_item_type_group_rltshp sitgr';
            $where_r[] = 'sitgr.s_item_type = i.s_item_type';
            $where_r[] = 'sitgr.s_item_type_group = \'' . $HTTP_VARS['s_item_type_group'] . '\'';
        } else {
            if (is_not_empty_array($HTTP_VARS['s_item_type'])) {
                $where_r[] = 'i.s_item_type IN(' . format_sql_in_clause($HTTP_VARS['s_item_type']) . ')';
            }
        }
    }
    $from_r[] = 's_status_type sst';
    $where_r[] = 'sst.s_status_type = ii.s_status_type';
    //
    // Status Type restriction
    //
    if (is_not_empty_array($HTTP_VARS['s_status_type'])) {
        $where_r[] = 'sst.s_status_type IN(' . format_sql_in_clause($HTTP_VARS['s_status_type']) . ')';
    } else {
        if ($HTTP_VARS['s_status_type'] != 'ALL' && strlen($HTTP_VARS['s_status_type']) > 0) {
            $where_r[] = 'sst.s_status_type = \'' . $HTTP_VARS['s_status_type'] . '\'';
        }
    }
    // no need for such a restriction if current user is item admin
    if (!is_user_granted_permission(PERM_ITEM_ADMIN)) {
        $where_r[] = "( sst.hidden_ind = 'N' OR ii.owner_id = '" . get_opendb_session_var('user_id') . "') ";
    }
    //
    // User and Status type restriction
    //
    if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) !== 0) {
        // not current user
        $from_r[] = 'user u';
        $where_r[] = 'u.user_id = ii.owner_id';
        $where_r[] = 'u.active_ind = \'Y\'';
    }
    //
    // Status Comment restriction
    //
    if (strlen($HTTP_VARS['status_comment']) > 0) {
        // Escape only the single quote!
        $HTTP_VARS['status_comment'] = str_replace("'", "\\'", $HTTP_VARS['status_comment']);
        if ($HTTP_VARS['status_comment_match'] != 'exact') {
            $parser = new BooleanParser();
            $statements = $parser->parseBooleanStatement($HTTP_VARS['status_comment']);
            if (is_array($statements)) {
                $where_r[] = build_boolean_clause($statements, 'ii.status_comment', $HTTP_VARS['status_comment_match'], 'AND', $HTTP_VARS['status_comment_case']);
            }
        } else {
            if (is_null($HTTP_VARS['status_comment_case'])) {
                $where_r[] = 'ii.status_comment = \'' . $HTTP_VARS['status_comment'] . '\'';
            } else {
                $where_r[] = 'BINARY ii.status_comment = \'' . $HTTP_VARS['status_comment'] . '\'';
            }
        }
    }
    //
    // Title restriction
    //
    if (strlen($HTTP_VARS['title']) > 0) {
        // Escape only the single quote!
        $HTTP_VARS['title'] = str_replace("'", "\\'", $HTTP_VARS['title']);
        if ($HTTP_VARS['title_match'] != 'exact') {
            $parser = new BooleanParser();
            $statements = $parser->parseBooleanStatement($HTTP_VARS['title']);
            if (is_array($statements)) {
                $where_r[] = build_boolean_clause($statements, 'i.title', $HTTP_VARS['title_match'], 'AND', $HTTP_VARS['title_case']);
            }
        } else {
            if (is_null($HTTP_VARS['title_case'])) {
                $where_r[] = 'i.title = \'' . $HTTP_VARS['title'] . '\'';
            } else {
                $where_r[] = 'BINARY i.title = \'' . $HTTP_VARS['title'] . '\'';
            }
        }
    } else {
        if (strlen($HTTP_VARS['letter']) > 0) {
            // Numeric match.
            if ($HTTP_VARS['letter'] == '#') {
                $where_r[] = 'ASCII(LEFT(title,1)) BETWEEN ASCII(\'0\') AND ASCII(\'9\')';
            } else {
                $where_r[] = 'UPPER(LEFT(i.title,1)) = \'' . strtoupper($HTTP_VARS['letter']) . '\'';
            }
        }
    }
    //
    // Last Updated support
    //
    if (strlen($HTTP_VARS['update_on']) > 0) {
        if (strlen($HTTP_VARS['datetimemask']) > 0) {
            $timestamp = get_timestamp_for_datetime($HTTP_VARS['update_on'], $HTTP_VARS['datetimemask']);
            if ($timestamp !== FALSE) {
                $where_r[] = 'ii.update_on >= FROM_UNIXTIME(' . $timestamp . ')';
            } else {
                // by default get items from 1 day ago, if update_on can not be parsed correctly.
                $where_r[] = 'TO_DAYS(ii.update_on) >= (TO_DAYS(now())-1)';
            }
        } else {
            $where_r[] = 'ii.update_on >= \'' . $HTTP_VARS['update_on'] . '\'';
        }
    } else {
        if (is_numeric($HTTP_VARS['update_on_days'])) {
            // GIve us all records updated in the last however many days.
            $where_r[] = 'TO_DAYS(ii.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['update_on_days'] . ')';
        }
    }
    //
    // Item Attribute listing/restriction
    //
    if (is_array($column_display_config_rs)) {
        for ($i = 0; $i < count($column_display_config_rs); $i++) {
            if ($column_display_config_rs[$i]['column_type'] == 's_attribute_type') {
                if ($column_display_config_rs[$i]['search_attribute_ind'] != 'y') {
                    // either LISTING or COUNT
                    if ($query_type != 'COUNT') {
                        $left_join = 'LEFT JOIN item_attribute ia' . $i . ' ON ' . 'ia' . $i . '.item_id = i.id AND (ia' . $i . '.instance_no = 0 OR ia' . $i . '.instance_no = ii.instance_no) AND ia' . $i . '.s_attribute_type = \'' . $column_display_config_rs[$i]['s_attribute_type'] . '\' AND ia' . $i . '.attribute_no = 1';
                        // So we can work out which search attribute types to display
                        if (is_numeric($column_display_config_rs[$i]['order_no'])) {
                            $left_join .= ' AND ia' . $i . '.order_no = ' . $column_display_config_rs[$i]['order_no'];
                        }
                        $left_join_from_r[] = $left_join;
                    }
                } else {
                    // search attribute
                    $from_r[] = 'item_attribute ia' . $i;
                    // now do the where clause.
                    $where_r[] = 'ia' . $i . '.item_id = i.id AND (ia' . $i . '.instance_no = 0 OR ia' . $i . '.instance_no = ii.instance_no) AND ia' . $i . '.s_attribute_type = \'' . $column_display_config_rs[$i]['s_attribute_type'] . '\'';
                    // AND ia'.$i.'.attribute_no = 1';
                    if (strlen($column_display_config_rs[$i]['attribute_val']) > 0 && $column_display_config_rs[$i]['attribute_val'] != '%' && $column_display_config_rs[$i]['attr_match'] != 'exact') {
                        $parser = new BooleanParser();
                        $statements = $parser->parseBooleanStatement(strtoupper(str_replace("'", "\\'", $column_display_config_rs[$i]['attribute_val'])));
                        if (is_array($statements)) {
                            if ($column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') {
                                $where_r[] = build_boolean_clause($statements, 'ia' . $i . '.lookup_attribute_val', 'plain', 'AND', $HTTP_VARS['attr_case']);
                            } else {
                                $where_r[] = build_boolean_clause($statements, 'ia' . $i . '.attribute_val', $column_display_config_rs[$i]['attr_match'], 'AND', $HTTP_VARS['attr_case']);
                            }
                        }
                    } else {
                        if (strlen($column_display_config_rs[$i]['lookup_attribute_val']) > 0 && $column_display_config_rs[$i]['lookup_attribute_val'] != '%' && $column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') {
                            $value = str_replace("'", "\\'", $column_display_config_rs[$i]['lookup_attribute_val']);
                            $where_r[] = 'ia' . $i . '.lookup_attribute_val = \'' . str_replace('\\_', '_', $value) . '\'';
                        } else {
                            if (strlen($column_display_config_rs[$i]['attribute_val']) > 0 && $column_display_config_rs[$i]['attribute_val'] != '%') {
                                if (starts_with($column_display_config_rs[$i]['attribute_val'], '"') && ends_with($column_display_config_rs[$i]['attribute_val'], '"')) {
                                    $column_display_config_rs[$i]['attribute_val'] = substr($column_display_config_rs[$i]['attribute_val'], 1, -1);
                                }
                                $value = strtoupper(str_replace("'", "\\'", $column_display_config_rs[$i]['attribute_val']));
                                $where_r[] = 'UPPER(ia' . $i . '.attribute_val) = \'' . str_replace('\\_', '_', $value) . '\'';
                            }
                        }
                    }
                    if (strlen($HTTP_VARS['attr_update_on']) > 0) {
                        if (strlen($HTTP_VARS['datetimemask']) > 0) {
                            $timestamp = get_timestamp_for_datetime($HTTP_VARS['attr_update_on'], $HTTP_VARS['datetimemask']);
                            if ($timestamp !== FALSE) {
                                $where_r[] = 'ia' . $i . '.update_on >= FROM_UNIXTIME(' . $timestamp . ')';
                            } else {
                                // by default get items from 1 day ago, if update_on can not be parsed correctly.
                                $where_r[] = 'TO_DAYS(ia' . $i . '.update_on) >= (TO_DAYS(now())-1)';
                            }
                        } else {
                            $where_r[] = 'ia' . $i . '.update_on >= \'' . $HTTP_VARS['attr_update_on'] . '\'';
                        }
                    } else {
                        if (is_numeric($HTTP_VARS['attr_update_on_days'])) {
                            // GIve us all records updated in the last however many days.
                            $where_r[] = 'TO_DAYS(ia' . $i . '.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['attr_update_on_days'] . ')';
                        }
                    }
                }
            } else {
                if ($column_display_config_rs[$i]['column_type'] == 's_field_type') {
                    if ($column_display_config_rs[$i]['s_field_type'] == 'CATEGORY') {
                        $from_r[] = 's_item_attribute_type catsiat';
                        $from_r[] = 's_attribute_type catsat';
                        $where_r[] = 'catsiat.s_item_type = i.s_item_type AND catsat.s_attribute_type = catsiat.s_attribute_type AND catsat.s_field_type = \'CATEGORY\'';
                        $left_join_clause = 'LEFT JOIN item_attribute catia ON ' . 'catia.item_id = i.id AND (catia.instance_no = 0 OR catia.instance_no = ii.instance_no) AND catia.s_attribute_type = catsiat.s_attribute_type AND catia.order_no = catsiat.order_no';
                        if (strlen($HTTP_VARS['category']) > 0 || strcasecmp($HTTP_VARS['attr_match'], 'category') === 0 && strlen($HTTP_VARS['attribute_val']) > 0) {
                            // Support specifying $attribute_val for $category where $attr_match=="category"!
                            // If item_type && item_type_group are not set!
                            if (strlen($HTTP_VARS['attribute_type']) > 0 && !is_array($HTTP_VARS['s_item_type']) && strlen($HTTP_VARS['s_item_type']) == 0 && strlen($HTTP_VARS['s_item_type_group']) == 0) {
                                $where_r[] = 'catsat.s_attribute_type = \'' . $HTTP_VARS['attribute_type'] . '\'';
                            }
                            // Escape single quotes only.
                            $value = strtoupper(str_replace("'", "\\'", ifempty($HTTP_VARS['category'], $HTTP_VARS['attribute_val'])));
                            $where_r[] = 'UPPER(catia.lookup_attribute_val) = \'' . str_replace('\\_', '_', $value) . '\'';
                        } else {
                            $left_join_clause .= ' AND catia.attribute_no = 1';
                        }
                        $left_join_from_r[] = $left_join_clause;
                    } else {
                        if ($column_display_config_rs[$i]['s_field_type'] == 'INTEREST') {
                            // can only restrict interest level if its displayed as a column
                            if (strlen($HTTP_VARS['interest_level']) > 0) {
                                $where_r[] = "it.item_id = ii.item_id AND it.instance_no = ii.instance_no AND it.user_id = '" . get_opendb_session_var('user_id') . "'" . " AND it.level >= " . $HTTP_VARS['interest_level'];
                                $from_r[] = "user_item_interest it";
                            } else {
                                $left_join_from_r[] = "LEFT JOIN user_item_interest it ON it.item_id = i.id AND it.instance_no = ii.instance_no AND it.user_id = '" . get_opendb_session_var('user_id') . "'";
                            }
                        }
                    }
                }
            }
        }
    }
    // If attribute_val specified without a attribute_type, then do a loose join to item_attribute table,
    // only on attribute_val column.
    if (strlen($HTTP_VARS['attribute_type']) == 0 && (strlen($HTTP_VARS['attribute_val']) > 0 || strlen($HTTP_VARS['attr_update_on']) > 0 || strlen($HTTP_VARS['attr_update_on_days']) > 0)) {
        $from_r[] = 'item_attribute ia';
        // now do the where clause.
        $where_r[] = 'ia.item_id = i.id ';
        //AND ia.attribute_no = 1';
        if ($HTTP_VARS['attr_match'] != 'exact') {
            $parser = new BooleanParser();
            $statements = $parser->parseBooleanStatement(strtoupper(str_replace("'", "\\'", $HTTP_VARS['attribute_val'])));
            if (is_array($statements)) {
                if (is_lookup_attribute_type($HTTP_VARS['attribute_type'])) {
                    $where_r[] = build_boolean_clause($statements, 'ia.lookup_attribute_val', 'plain', 'AND', $HTTP_VARS['attr_case']);
                } else {
                    $where_r[] = build_boolean_clause($statements, 'ia.attribute_val', $HTTP_VARS['attr_match'], 'AND', $HTTP_VARS['attr_case']);
                }
            }
        } else {
            // attr_match = 'exact'
            if (is_lookup_attribute_type($HTTP_VARS['attribute_type'])) {
                $value = str_replace("'", "\\'", $HTTP_VARS['attribute_val']);
                $where_r[] = 'ia.lookup_attribute_val = \'' . str_replace('\\_', '_', $value) . '\'';
            } else {
                $value = str_replace("'", "\\'", $HTTP_VARS['attribute_val']);
                if (is_null($HTTP_VARS['attr_case'])) {
                    $where_r[] = '( ia.attribute_val = \'' . str_replace('\\_', '_', $value) . '\' OR ' . 'ia.attribute_val LIKE \'% ' . $value . ' %\' OR ' . 'ia.attribute_val LIKE \'' . $value . ' %\' OR ' . 'ia.attribute_val LIKE \'% ' . $value . '\')';
                } else {
                    $where_r[] = '( BINARY ia.attribute_val = \'' . str_replace('\\_', '_', $value) . '\' OR ' . 'ia.attribute_val LIKE BINARY \'% ' . $value . ' %\' OR ' . 'ia.attribute_val LIKE BINARY \'' . $value . ' %\' OR ' . 'ia.attribute_val LIKE BINARY \'% ' . $value . '\')';
                }
            }
        }
        if (strlen($HTTP_VARS['attr_update_on']) > 0) {
            if (strlen($HTTP_VARS['datetimemask']) > 0) {
                $timestamp = get_timestamp_for_datetime($HTTP_VARS['attr_update_on'], $HTTP_VARS['datetimemask']);
                if ($timestamp !== FALSE) {
                    $where_r[] = 'ia.update_on >= FROM_UNIXTIME(' . $timestamp . ')';
                } else {
                    // by default get items from 1 day ago, if update_on can not be parsed correctly.
                    $where_r[] = 'TO_DAYS(ia.update_on) >= (TO_DAYS(now())-1)';
                }
            } else {
                $where_r[] = 'ia.update_on >= \'' . $HTTP_VARS['attr_update_on'] . '\'';
            }
        } else {
            if (is_numeric($HTTP_VARS['attr_update_on_days'])) {
                // GIve us all records updated in the last however many days.
                $where_r[] = 'TO_DAYS(ia.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['attr_update_on_days'] . ')';
            }
        }
    }
    //
    // Review restrictions
    //
    if (strlen($HTTP_VARS['rating']) > 0) {
        $where_r[] = 'r.item_id = i.id AND r.rating >= ' . $HTTP_VARS['rating'];
        $from_r[] = 'review r';
    }
    //
    // Item ID range restriction (Used by Import script)
    //
    if (strlen($HTTP_VARS['item_id_range']) > 0) {
        $where_r[] = 'i.id IN (' . expand_number_range($HTTP_VARS['item_id_range']) . ')';
    }
    //
    // Now build the SQL query
    //
    if (is_array($from_r)) {
        $from_clause = '';
        for ($i = 0; $i < count($from_r); $i++) {
            if (strlen($from_clause) > 0) {
                $from_clause .= ', ';
            }
            $from_clause .= $from_r[$i];
        }
        $query .= 'FROM (' . $from_clause . ') ';
    }
    if (is_array($left_join_from_r)) {
        $left_join_from_clause = '';
        for ($i = 0; $i < count($left_join_from_r); $i++) {
            if (strlen($left_join_from_clause) > 0) {
                $left_join_from_clause .= ' ';
            }
            $left_join_from_clause .= $left_join_from_r[$i];
        }
        $query .= $left_join_from_clause . ' ';
    }
    if (is_array($where_r)) {
        $where_clause = '';
        for ($i = 0; $i < count($where_r); $i++) {
            if (strlen($where_clause) > 0) {
                $where_clause .= ' AND ';
            }
            $where_clause .= $where_r[$i];
        }
        $query .= 'WHERE ' . $where_clause;
    }
    return $query;
}
示例#2
0
 private function replaceConditionals($bFinalOnly = false)
 {
     $iStartPosition = 0;
     $oIf = null;
     while (true) {
         $oIf = $this->identifiersMatching("if", self::$ANY_VALUE, null, true, $iStartPosition);
         if (!$oIf) {
             break;
         }
         if ($bFinalOnly && !$oIf->isFinal()) {
             $iStartPosition = $this->identifierPosition($oIf) + 1;
             continue;
         }
         $oEndIf = $this->findEndIfForIf($oIf);
         if (!$oEndIf) {
             $oIf->destroy();
             continue;
         }
         $sComparison = $oIf->getValue() !== null ? $oIf->getValue() : "=";
         $sFirst = $oIf->getParameter('1');
         $sSecond = $oIf->hasParameter('2') && $oIf->getParameter('2') !== null ? $oIf->getParameter('2') : "";
         $sCompareMode = $oIf->hasParameter('strict') && $oIf->getParameter('strict') === 'true' ? "strict" : "normal";
         $sComparisonString = '==';
         $mUnexpectedResult = false;
         $aFuncArgs = array($sFirst, $sSecond);
         switch ($sComparison) {
             case 'ne':
             case 'notEqual':
             case 'not_eqal':
             case '!=':
             case '!==':
             case '<>':
                 $sComparisonString = "!=";
                 break;
             case 'gt':
             case 'greaterThan':
             case 'greater_than':
             case '>':
                 $sComparisonString = ">";
                 $sCompareMode = "normal";
                 break;
             case 'lt':
             case 'lessThan':
             case 'less_than':
             case '<':
                 $sComparisonString = "<";
                 $sCompareMode = "normal";
                 break;
             case 'gte':
             case 'greaterThanEqual':
             case 'greater_than_equal':
             case '>=':
                 $sComparisonString = ">=";
                 $sCompareMode = "normal";
                 break;
             case 'lte':
             case 'lessThanEqual':
             case 'less_than_equal':
             case '<=':
                 $sComparisonString = "<=";
                 $sCompareMode = "normal";
                 break;
             case '~':
                 $sComparisonString = "preg_match";
                 $sCompareMode = "function";
                 $mUnexpectedResult = 0;
                 break;
             case '|=':
                 $sComparisonString = "in_array";
                 $aFuncArgs = array($sFirst, explode('|', $sSecond));
                 $sCompareMode = "function";
                 break;
             case '~=':
                 $sComparisonString = "in_array";
                 $aFuncArgs = array($sFirst, preg_split('/\\s+/', $sSecond, -1, PREG_SPLIT_NO_EMPTY));
                 $sCompareMode = "function";
                 break;
             case 'contains':
                 $sComparisonString = "stripos";
                 if ($sCompareMode === "strict") {
                     $sComparisonString = "strpos";
                 }
                 $sCompareMode = "function";
                 break;
             case 'file_exists':
                 $sComparisonString = "file_exists";
                 $sFirst = MAIN_DIR . $sFirst;
                 $mUnexpectedResult = !BooleanParser::booleanForString($sSecond);
                 $aFuncArgs = array($sFirst);
                 $sCompareMode = "function";
                 break;
         }
         if ($sCompareMode === "function") {
             $bResult = call_user_func_array($sComparisonString, $aFuncArgs) !== $mUnexpectedResult;
         } else {
             if ($sCompareMode === "strict") {
                 $sComparisonString .= "=";
             }
             $bResult = eval('return $sFirst ' . $sComparisonString . ' $sSecond;') !== $mUnexpectedResult;
         }
         if (!$bResult) {
             $this->replaceAt($oIf, null, $oEndIf);
         } else {
             $oIf->destroy();
             $oEndIf->destroy();
         }
     }
 }
示例#3
0
 public function addResourceFromTemplateIdentifier($oIdentifier)
 {
     $mLocation = $oIdentifier->getValue();
     $iPriority = $oIdentifier->hasParameter('priority') ? constant("ResourceIncluder::PRIORITY_" . strtoupper($oIdentifier->getParameter('priority'))) : ResourceIncluder::PRIORITY_NORMAL;
     $sIeCondition = $oIdentifier->hasParameter('ie_condition') ? $oIdentifier->getParameter('ie_condition') : null;
     if ($oIdentifier->hasParameter('library')) {
         $bUseSsl = $oIdentifier->hasParameter('use_ssl') ? null : 'default';
         if ($oIdentifier->getParameter('use_ssl')) {
             $bUseSsl = $oIdentifier->getParameter('use_ssl');
             if ($bUseSsl !== 'auto' && $bUseSsl !== 'default') {
                 $bUseSsl = BooleanParser::booleanForString($bUseSsl);
             }
         }
         $this->addJavaScriptLibrary($mLocation, $oIdentifier->getParameter('library'), $oIdentifier->hasParameter('uncompressed') ? false : null, !$oIdentifier->hasParameter('nodeps'), $bUseSsl, $iPriority, null, $sIeCondition);
         return null;
     }
     if ($oIdentifier->hasParameter('inline')) {
         if ($oIdentifier->getParameter('inline') === 'css') {
             $this->addCustomCss($mLocation);
         } else {
             if ($oIdentifier->getParameter('inline') === 'js') {
                 $this->addCustomJs($mLocation);
             }
         }
         return null;
     }
     if ($oIdentifier->hasParameter('fromBase')) {
         //Is named the same in include so we leave it in camel case
         $mLocation = explode('/', $mLocation);
     }
     $aParams = $oIdentifier->getParameters();
     $aParams['from_template'] = true;
     $sResourceType = $oIdentifier->hasParameter('type') ? $oIdentifier->getParameter('type') : null;
     // Fall back to 'resource_type' param for backwards compatiblity
     if ($sResourceType === null && $oIdentifier->hasParameter('resource_type')) {
         $sResourceType = $oIdentifier->getParameter('resource_type');
     }
     $bIncludeAll = $oIdentifier->hasParameter('include_all');
     $this->addResource($mLocation, $sResourceType, null, $aParams, $iPriority, $sIeCondition, $bIncludeAll);
 }
示例#4
0
 public function adminGetContainers()
 {
     $oTemplate = $this->oPage->getTemplate();
     foreach ($oTemplate->identifiersMatching('container', Template::$ANY_VALUE) as $oIdentifier) {
         $oInheritedFrom = null;
         $sContainerName = $oIdentifier->getValue();
         if (BooleanParser::booleanForString($oIdentifier->getParameter('inherit'))) {
             $oInheritedFrom = $this->oPage;
             $iInheritedObjectCount = 0;
             while ($iInheritedObjectCount === 0 && ($oInheritedFrom = $oInheritedFrom->getParent()) !== null) {
                 $iInheritedObjectCount = $oInheritedFrom->countObjectsForContainer($sContainerName);
             }
         }
         $sInheritedFrom = $oInheritedFrom ? $oInheritedFrom->getName() : '';
         $aTagParams = array('class' => 'template-container template-container-' . $sContainerName, 'data-container-name' => $sContainerName, 'data-container-string' => TranslationPeer::getString('container_name.' . $sContainerName, null, $sContainerName), 'data-inherited-from' => $sInheritedFrom);
         $oContainerTag = TagWriter::quickTag('ol', $aTagParams);
         $mInnerTemplate = new Template(TemplateIdentifier::constructIdentifier('content'), null, true);
         //Replace container info
         //…name
         $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-description'), TranslationPeer::getString('wns.page.template_container', null, null, array('container' => TranslationPeer::getString('template_container.' . $sContainerName, null, $sContainerName)), true)));
         //…additional info
         $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-info')));
         //…tag
         $mInnerTemplate->replaceIdentifierMultiple('content', $oContainerTag);
         //Replace actual container
         $oTemplate->replaceIdentifier($oIdentifier, $mInnerTemplate);
     }
     $bUseParsedCss = Settings::getSetting('admin', 'use_parsed_css_in_config', true);
     $oStyle = null;
     if ($bUseParsedCss) {
         $sTemplateName = $this->oPage->getTemplateNameUsed() . Template::$SUFFIX;
         $sCacheKey = 'parsed-css-' . $sTemplateName;
         $oCssCache = new Cache($sCacheKey, DIRNAME_PRELOAD);
         $sCssContents = "";
         if (!$oCssCache->entryExists() || $oCssCache->isOutdated(ResourceFinder::create(array(DIRNAME_TEMPLATES, $sTemplateName)))) {
             $oIncluder = new ResourceIncluder();
             foreach ($oTemplate->identifiersMatching('addResourceInclude', Template::$ANY_VALUE) as $oIdentifier) {
                 $oIncluder->addResourceFromTemplateIdentifier($oIdentifier);
             }
             foreach ($oIncluder->getAllIncludedResources() as $sIdentifier => $aResource) {
                 if ($aResource['resource_type'] === ResourceIncluder::RESOURCE_TYPE_CSS && !isset($aResource['ie_condition']) && !isset($aResource['frontend_specific'])) {
                     if (isset($aResource['media'])) {
                         $sCssContents .= "@media {$aResource['media']} {";
                     }
                     if (isset($aResource['file_resource'])) {
                         $sCssContents .= file_get_contents($aResource['file_resource']->getFullPath());
                     } else {
                         // Absolute link, requires fopen wrappers
                         $sCssContents .= file_get_contents($aResource['location']);
                     }
                     if (isset($aResource['media'])) {
                         $sCssContents .= "}";
                     }
                 }
             }
             $oParser = new Sabberworm\CSS\Parser($sCssContents, Sabberworm\CSS\Settings::create()->withDefaultCharset(Settings::getSetting("encoding", "browser", "utf-8")));
             $oCss = $oParser->parse();
             $this->cleanupCSS($oCss);
             $sCssContents = Template::htmlEncode($oCss->render(Sabberworm\CSS\OutputFormat::createCompact()));
             $oCssCache->setContents($sCssContents);
         } else {
             $sCssContents = $oCssCache->getContentsAsString();
         }
         $oStyle = new HtmlTag('style');
         $oStyle->addParameters(array('scoped' => 'scoped'));
         $oStyle->appendChild($sCssContents);
     }
     $sTemplate = $oTemplate->render();
     $sTemplate = substr($sTemplate, strpos($sTemplate, '<body') + 5);
     $sTemplate = substr($sTemplate, strpos($sTemplate, '>') + 1);
     $sTemplate = substr($sTemplate, 0, strpos($sTemplate, '</body'));
     $oParser = new TagParser("<body>{$sTemplate}</body>");
     $oTag = $oParser->getTag();
     $this->cleanupContainerStructure($oTag);
     if ($bUseParsedCss) {
         $oTag->appendChild($oStyle);
     }
     $sResult = $oTag->__toString();
     $sResult = substr($sResult, strpos($sResult, '<body>') + 6);
     $sResult = substr($sResult, 0, strrpos($sResult, '</body>'));
     return array('html' => $sResult, 'css_parsed' => $bUseParsedCss);
 }
示例#5
0
 private static function writeConfiguration($oDoc, &$aConfig, $oElement)
 {
     foreach ($aConfig as $sKey => &$mValue) {
         if (is_array($mValue)) {
             $oInner = null;
             if ($oElement->tagName === 'datasources') {
                 $oInner = $oDoc->createElement('datasource');
                 $oInner->setAttribute('id', $sKey);
             } else {
                 $oInner = $oDoc->createElement($sKey);
             }
             $oElement->appendChild($oInner);
             self::writeConfiguration($oDoc, $mValue, $oInner);
         } else {
             if (is_bool($mValue)) {
                 $mValue = BooleanParser::stringForBoolean($mValue);
             }
             $oAttr = $oDoc->createElement($sKey);
             $oAttr->appendChild($oDoc->createTextNode((string) $mValue));
             $oElement->appendChild($oAttr);
         }
     }
 }
示例#6
0
 /**
  * @param int $iLevel level of current NavigationItem (expensive to calculate from the NavigationItem alone)
  * @param BooleanParser $oBooleanParser the BooleanParser instance holding information about the current NavigationItem’s properties]
  * @param NavigationItem $oNavigationItem the current navigation item
  * @return string parsed navigation
  */
 private function getConfigForPage($iLevel, $oBooleanParser, $oNavigationItem)
 {
     $aConfigToCheck = @$this->aConfig[$iLevel];
     if ($aConfigToCheck === null) {
         if (!isset($this->aConfig['all'])) {
             return null;
         }
         $aConfigToCheck = $this->aConfig['all'];
     }
     foreach ($aConfigToCheck as $aConfig) {
         if (isset($aConfig['page_name']) && $aConfig['page_name'] !== $oNavigationItem->getName()) {
             continue;
         }
         if (isset($aConfig['page_identifier']) && $aConfig['page_identifier'] !== $oNavigationItem->getIdentifier()) {
             continue;
         }
         if (isset($aConfig['page_type']) && $aConfig['page_type'] !== $oNavigationItem->getType()) {
             continue;
         }
         if (!isset($aConfig['on']) || $oBooleanParser->parse($aConfig['on'])) {
             return $aConfig;
         }
     }
     return null;
 }