$v) {
$$k = AddslashesDeep($v);
}
}
// ----- input variables normalization - end ----------------------------------
$encap = ( ($encap=="false") ? false : true );
require_once "./include/config.php3";
require_once AA_INC_PATH."easy_scroller.php3";
require_once AA_INC_PATH."util.php3";
require_once AA_INC_PATH."item.php3";
require_once AA_INC_PATH."view.php3";
require_once AA_INC_PATH."pagecache.php3";
require_once AA_INC_PATH."searchlib.php3";
require_once AA_INC_PATH."discussion.php3";
require_once AA_INC_PATH."mgettext.php3";
require_once AA_INC_PATH."slice.class.php3";
require_once AA_INC_PATH."hitcounter.class.php3";
// function definitions:
require_once AA_INC_PATH."slice.php3";
require_once AA_INC_PATH."locsess.php3";
/** MyUrl function - was in sessions before, but now it is used just in this script, so moved here and rewritten to handle encap (=shtml)/not encap version
* rewriten to return URL of shtml page that includes this script instead to return self url of this script.
*/
function MyUrl($encap, $scr_url) { //sliceID is here just for compatibility with MyUrl function in extsess.php3
$server = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$server .= '://'. $_SERVER['HTTP_HOST'];
if ( $scr_url ) { // if included into php script
return $server.$scr_url;
} elseif ($_SERVER["HTTP_X_FORWARDED_SERVER"]) {
return ''; // it is impossible to get original script name when AA is hidden after proxy. In this case we will use reletive URL (which is not bad in any case, I think - Honza 2016-11-21)
}
$ret = $server;
if ($encap) {
if (isset($_SERVER['REDIRECT_DOCUMENT_URI'])) { // CGI --enable-force-cgi-redirect
$ret .= $_SERVER['REDIRECT_DOCUMENT_URI'];
} elseif (isset($_SERVER['DOCUMENT_URI'])) {
$ret .= $_SERVER['DOCUMENT_URI'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$url_parsed = parse_url($_SERVER['REQUEST_URI']);
$ret .= $url_parsed['path'];
} else {
$ret .= $_SERVER['SCRIPT_URL'];
}
} elseif (isset($_SERVER['REDIRECT_SCRIPT_NAME'])) {
$ret .= $_SERVER['REDIRECT_SCRIPT_NAME'];
} else {
$ret .= $_SERVER['SCRIPT_NAME'];
}
// // not executed - mode is cookie. Could be removed (Honza 16-03-31)
// if ( ($this->mode == 'get') AND (!$noquery) ) {
// if ($encap) {
// $ret .= "?".urlencode($this->name)."=".$this->id;
// } else {
// $ret .= "?slice_id=$sliceID" . ($encap?"":"&encap=false"). "&".urlencode($this->name)."=".$this->id;
// }
// }
return $ret;
}
$slice_starttime = microtime(true);
//MLX stuff
require_once AA_INC_PATH."mlx.php";
// session is not working right now with PHP5 style sessions. It should not be
// needed. We are testing the code, and if all will be OK, we remove sessions
// from slice.php3 completely. It doesn-t work because of Cookies vs. SSI.
// Honza 2016-07-12
pageOpen('noauth');
$sess->register('r_packed_state_vars');
$sess->register('slices');
$r_state_vars = unserialize($r_packed_state_vars);
// there was problems with storing too much ids in session veriable,
// so I commented it out. It is not necessary to have it in session. The only
// reason to have it there is the display speed, but because of impementing
// pagecache.php3, it is not so big problem now
//$sess->register(item_ids);
if ($encap) { // adds values from QUERY_STRING_UNESCAPED
add_vars(""); // and REDIRECT_STRING_UNESCAPED
// if we use input type="buton" for submitting of form, then it adds x and y
// variables, which we do not want (x means (unfortunately) - item id in AA)
if (isset($x) AND isset($y) AND ctype_digit((string)$x) AND ctype_digit((string)$y) AND isset($conds)) {
unset($x);
}
}
if (($key != $lock) OR $scrl) { // command is for other slice on page
RestoreVariables(); // or scroller
}
// url posted command to display specified text instead of slice content -------
if ($slicetext) {
echo $slicetext;
ExitPage();
}
// url posted command to display another file ----------------------------------
if ( $inc ) { // this section must be after add_vars()
// StoreVariables(array("inc")); // store in session
if ( !preg_match("/^([0-9a-z_])+(\.[0-9a-z]*)?$/i", $inc) ) {
echo _m("Bad inc parameter - included file must be in the same directory as this .shtml file and must contain only alphanumeric characters"). " $inc";
ExitPage();
} else {
$fp = @fopen(shtml_base().$inc, "r"); // if encapsulated
if (!$fp) {
echo _m("No such file") ." $inc";
} else {
FPassThru($fp);
}
ExitPage();
}
}
// Take any slice to work with
if (!$slice_id AND is_array($slices)) {
reset ($slices);
$slice_id = current($slices);
}
// if someone breaks ');
}
$add_aliases = $aliases = GetAliasesFromUrl($als);
// this is not good way - aliases are then different on each call, so it isn't
// cached. The better way is below
// $add_aliases['_#SESSION_'] = GetAliasDef( 'f_s:'. $sess->id, '', _m('session id'));
$add_aliases['_#SESSION_'] = GetAliasDef( 'f_e:session', 'id..............', _m('session id'));
// if banner parameter supplied => set format
$slice_info = array_merge( $slice_info, ParseBannerParam($banner));
// get alias list from database and possibly from url
// if working with multi-slice, get aliases for all slices
if (!is_array($slices)) {
$aliases = $slice->aliases();
array_add($add_aliases, $aliases);
} else {
foreach ($slices as $sid) {
// hack for searching in multiple slices. This is not so nice part
// of code - we mix there $aliases[] with $aliases[][]
// it is needed by itemview::set_column() (see include/itemview.php3)
$aliases[q_pack_id($sid)] = AA_Slice::getModule($sid)->aliases($als);
array_add($add_aliases, $aliases[q_pack_id($sid)]);
}
}
// fulltext view ---------------------------------------------------------------
if ( $sh_itm OR $x OR $o OR $seo ) {
// $r_state_vars = StoreVariables(array("sh_itm")); // store in session
if ( $x ) {
$zid = new zids((int)$x, 's');
AA_Hitcounter::hit($zid);
}
elseif ( $seo ) {
$zid = new zids(explode('-', StrExpand('AA_Stringexpand_Seo2ids', array($slice_id, $seo))), 'l');
AA_Hitcounter::hit($zid);
}
elseif ( $o ) {
$zid = new zids((int)$o, 's');
} else {
$zid = new zids($sh_itm, 'l');
AA_Hitcounter::hit($zid);
}
if (!isset ($hideFulltext)) {
$itemview = new itemview($slice_info, '', $aliases, $zid, 0, 1, MyUrl($encap, $scr_url));
echo $itemview->get_output_cached("fulltext");
}
// show discussion if assigned
$discussion_vid = ( isset($dview) ? $dview : $slice_info['vid']);
// you can set dview=0 to not show discussion
if ($discussion_vid > 0) {
$db->query("SELECT view.*, slice.flag FROM view, slice
WHERE slice.id='".q_pack_id($slice_id)."' AND view.id=$discussion_vid");
if ($db->next_record()) {
$view_info = $db->Record;
// create array of parameters
$disc = array('ids' => $all_ids ? "" : $ids,
'type' => $add_disc ? "adddisc" : (($sel_ids || $all_ids) ? "fulltext" : "thread"),
'item_id' => $zid->longids(0),
'vid' => $view_info['id'],
'html_format' => $view_info['flag'] & DISCUS_HTML_FORMAT,
'parent_id' => $parent_id
);
$aliases = GetDiscussionAliases();
$format = GetDiscussionFormat($view_info);
$format['id'] = $p_slice_id; // set slice_id because of caching
$itemview = new itemview($format, '', $aliases, null,"", "", MyUrl($encap, $scr_url), $disc);
echo $itemview->get_output("discussion");
// discussions should not be
// cached or even better (TODO) discussions should have its separate slice
// which is cached independently form the item itself through standard
// AA caching
}
}
ExitPage();
}
// multiple items fulltext view ------------------------------------------------
if ( $items AND is_array($items) ) { // shows all $items[] as fulltext one after one
// $r_state_vars = StoreVariables(array("items")); // store in session
while (list($k) = each( $items )) {
$ids[] = substr($k,1); //delete starting character ('x') - used for interpretation of index as string, not number (by PHP)
}
$zids = new zids($ids,"l");
$itemview = new itemview($slice_info, '', $aliases, $zids, 0,$zids->count(), MyUrl($encap, $scr_url));
ExitPage($itemview->get_output_cached("itemlist"));
}
// compact view ----------------------------------------------------------------
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Parse parameters posted by query form and from $slice_info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
$r_state_vars = StoreVariables(array("no_scr","scr_go","order","cat_id", "cat_name",
"exact","restrict","res_val","highlight","conds","group_by", "sort","als","defaultCondsOperator","mlx")); // store in session, added mlx
// ***** CONDS *****
if ($cat_id) { // optional parameter cat_id - deprecated - slow ------
$tmpobj = $slice->getFields();
$cat_field = $tmpobj->getCategoryFieldId();
$cat_group = GetCategoryGroup($slice_id);
$SQL = "SELECT value FROM constant
WHERE group_id = '$cat_group' AND id='". q_pack_id($cat_id) ."'";
$db->query($SQL);
if ( $db->next_record() ) {
$conds[] = array( $cat_field => 1,
'value' => $db->f('value'),
'operator' => ($exact ? '=' : 'LIKE'));
}
} elseif ($cat_name) { // optional parameter cat_name -------
$tmpobj = $slice->getFields();
$cat_field = $tmpobj->getCategoryFieldId();
$conds[] = array( $cat_field => 1,
'value' => $cat_name,
'operator' => ($exact ? '=' : 'LIKE'));
}
if ($restrict) {
$conds[] = array( $restrict => 1,
'value' => ((($res_val[0] == '"' OR $res_val[0] == "'") AND $exact != 2 ) ? $res_val : "\"$res_val\""),
'operator' => ($exact ? '=' : 'LIKE'));
}
if ($highlight != "") {
$conds[] = array('highlight.......' => 1);
}
if (!isset($defaultCondsOperator)) {
$defaultCondsOperator = 'LIKE';
}
if (is_array($conds)) {
ParseEasyConds($conds, $defaultCondsOperator);
foreach ( $conds as $k => $v ) {
SubstituteAliases( $als, $conds[$k]['value'] );
}
} elseif ( is_string($conds) AND strlen($conds) ) {
// we can use also conds=d-switch..........-=-1
$tmp_set = new AA_Set(null, $conds);
$conds = $tmp_set->getConds();
}
// ***** SORT *****
/** order by field xy if other than publish date.
* Syntax: [number]field_id[-]
* (add minus sign for descending order (like "headline.......1-")
* (add number before the field if you want to group limit (limit number of items of the same value))
*/
if ($order) {
$set = new AA_Set;
$set->addSortFromString($order);
$order = reset($set->getSort()); // get the first from array
list($order, $orderdirection) = each($order);
}
if ($debug) {
echo " Group by: -$group_by- Slice_info[category_sort] -$slice_info[category_sort]- slice_info[group_by] -$slice_info[group_by]-";
}
$sort_tmp = array();
if ($group_by) {
$set = new AA_Set;
$set->addSortFromString($group_by);
$sort_tmp = $set->getSort();
$slice_info["group_by"] = key($sort_tmp[0]);
}
elseif ($slice_info['category_sort']) {
$tmpobj = $slice->getFields();
$group_field = $tmpobj->getCategoryFieldId();
$grp_odir = (($order==$group_field) AND ($orderdirection!='d')) ? 'a' : 'd';
$sort_tmp[] = array( $group_field => $grp_odir );
}
elseif ($slice_info['group_by']) {
switch( (string)$slice_info['gb_direction'] ) { // gb_direction is number
case '1': $gbd = '1'; break; // 1 (1)- ascending by priority
case 'd': // d - descending - goes from view (iview) settings
case '8': $gbd = 'd'; break; // d (8)- descending
case '9': $gbd = '9'; break; // 9 (9)- descending by priority (for fields using constants)
default: $gbd = 'a'; // 2 (2)- ascending;
}
$sort_tmp[] = array($slice_info['group_by'] => $gbd);
}
$sort_tmp = array_merge($sort_tmp, getSortFromUrl($sort));
if ($order) {
add2sort($sort_tmp, array($order => (strstr('aAdD19',$orderdirection) ? $orderdirection : 'a')));
}
// time order the fields in compact view
add2sort($sort_tmp, array('publish_date....' => (($timeorder == "rev") ? 'a' : 'd')));
$sort = $sort_tmp;
//mlx stuff
if ($mlxslice = MLXSlice($slice)) {
if (!$mlxView) {
$mlxView = new MLXView($mlx);
}
$mlxView->preQueryZIDs($mlxslice,$conds);
}
$zids = QueryZIDs( ($slices ? $slices : array($slice_id)), $conds, $sort, "ACTIVE", $neverAllItems, 0, $defaultCondsOperator );
if ($mlxslice) {
$mlxView->postQueryZIDs($zids,$mlxslice,$slice_id);
}
if (!is_object($scr)) {
$sess->register('scr');
$scr_url_param = get_url(($scr_url ? $sess->url("$scr_url") : MyUrl($encap, $scr_url)), is_array($als) ? array('als'=>$als) : '');
$scr = new easy_scroller( 'scr', $scr_url_param, $slice_info['d_listlen'], $zids->count());
}
// display 'All' option in scroller
if ($all_scr) { $scr->setShowAll($all_scr); }
// change number of listed items
if ($listlen) { $scr->setMetapage($listlen); }
// default start page = 1
if (!$scr_go) { $scr_go = 1; }
// $scrl comes from easy_scroller
if ($scrl) { $scr->update(); }
/** Add scroller aliases - page number, listlen */
$scr_aliases['_#PAGE_NO_'] = GetAliasDef( 'f_s:'. $scr->current, '', _m('number of current page (on pagescroller)'));
$scr_aliases['_#PAGE_LEN'] = GetAliasDef( 'f_s:'. $scr->metapage, '', _m('page length (number of items)'));
// aliases array have two form (quite stupid - will be changed in future - TODO)
// depending on listing for one slice or many slices
if (!is_array($slices)) {
array_add($scr_aliases, $aliases);
} else {
foreach ($slices as $sid) {
// hack for searching in multiple slices. This is not so nice part
// of code - we mix there $aliases[] with $aliases[][]
// it is needed by itemview::set_column() (see include/itemview.php3)
array_add($scr_aliases, $aliases[q_pack_id($sid)]);
}
}
if ( !$scrl ) {
$scr->current = $scr_go;
}
if ( !$srch AND !$encap AND !$easy_query ) {
$cur_cats=GetCategories($db,$p_slice_id); // get list of categories
pCatSelector($sess->name, $sess->id, MyUrl($encap, $scr_url), $cur_cats,$scr->filters['category_id']['value'], $slice_id, $encap);
}
if ($zids->count() > 0) {
$itemview = new itemview($slice_info, '', $aliases, $zids, $scr->metapage * ($scr->current - 1),
($group_n ? -$group_n : $scr->metapage), // negative number used for displaying n-th group
MyUrl($encap, $scr_url) );
echo $itemview->get_output_cached("view");
if (($scr->pageCount() > 1) AND !$no_scr AND !$group_n) {
$scr->pnavbar();
}
} else {
// test if the the noitem_msg is filled (be carefull - "0" should be considered as filled)
echo (isset($slice_info['noitem_msg']) AND (strlen($slice_info['noitem_msg']) > 0)) ? // is keyword for removing 'no item message'
str_replace( '', '', AA_Stringexpand::unalias($slice_info['noitem_msg'])) : ("
"._m("No item found") ."
");
}
if ($searchlog) {
PutSearchLog();
}
if ($debug) {
$timeend = microtime(true);
$time = $timeend - $slice_starttime;
echo "