Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Jun 24, 11:27 PM

in-portal

Index: branches/unlabeled/unlabeled-1.102.2/kernel/parser.php
===================================================================
--- branches/unlabeled/unlabeled-1.102.2/kernel/parser.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.102.2/kernel/parser.php (revision 6429)
@@ -0,0 +1,3839 @@
+<?php
+$ItemTypes["category"]=1;
+$ItemTables[1] = "Category";
+
+$ParserFiles[] = "kernel/parser.php";
+
+function m_ParseEnv($str = NULL)
+{
+ global $m_var_list, $objConfig, $objCatList, $objLanguages, $objThemes;
+ if ($str != NULL)
+ {
+ $str = substr($str,1);
+ $pieces = explode("-", $str);
+ //echo "<PRE>";print_r($pieces);echo "</PRE>";
+ $m_var_list["cat"] = $pieces[0];
+ $m_var_list["p"] = $pieces[1];
+ $objCatList->Page = $m_var_list["p"];
+
+ $m_var_list["lang"] = $pieces[2];
+ $m_var_list["theme"] = $pieces[3];
+ $m_var_list['opener']=$pieces[4];
+ }
+ else
+ {
+ $m_var_list["cat"]=0;
+ $m_var_list["p"] = 1;
+ $m_var_list["lang"] = $objLanguages->GetPrimary();
+ $m_var_list["theme"]= $objThemes->GetPrimaryTheme();
+ $m_var_list['opener']='s';
+ }
+}
+
+function m_BuildEnv()
+{
+ global $m_var_list, $m_var_list_update;
+ $module_vars = Array('cat','p','lang','theme','opener');
+ $ret = GenerateModuleEnv('m', $module_vars);
+ if( isset($GLOBALS['m_var_list_update']['cat']) ) unset($GLOBALS['m_var_list_update']['cat']);
+ return $ret;
+}
+
+function m_BuildEnv_NEW()
+{
+ global $m_var_list, $m_var_list_update;
+ $module_vars = Array( 'cat' => 'm_cat_id', 'p' => 'm_cat_page', 'lang' => 'm_lang',
+ 'theme' => 'm_theme', 'opener' => 'm_opener');
+ $pass_cat = 0;
+ if (isset($m_var_list_update['cat'])) {
+ $pass_cat = 1;
+ }
+ $ret = GenerateModuleEnv_NEW('m', $module_vars);
+ if ($pass_cat) {
+ $ret['pass_category'] = 1;
+ }
+ if( isset($GLOBALS['m_var_list_update']['cat']) ) unset($GLOBALS['m_var_list_update']['cat']);
+ return $ret;
+}
+
+function m_GetVar($name)
+{
+ // get variable from template variable's list
+ global $m_var_list, $m_var_list_update;
+ return isset($m_var_list_update[$name]) ? $m_var_list_update[$name] : $m_var_list[$name];
+}
+
+function LoadRelatedItems(&$Relations,&$RelatedItems,$ResourceId)
+{
+ global $objItemTypes;
+
+ if(!is_object($Relations))
+ {
+ $Relations = new clsRelationshipList();
+ }
+ //$Relations->debuglevel = 2;
+ if ($ResourceId != '') {
+ $sql = sprintf("SELECT RelationshipId, Type, Enabled, Priority,
+ IF(TargetId = %1\$s, TargetId, SourceId) AS SourceId,
+ IF(TargetId = %1\$s, SourceId, TargetId) AS TargetId,
+ IF(TargetId = %1\$s, TargetType, SourceType) AS SourceType,
+ IF(TargetId = %1\$s, SourceType, TargetType) AS TargetType
+ FROM %%s", $ResourceId);
+
+ $where = "((SourceId=$ResourceId) OR (TargetId=$ResourceId AND Type=1)) AND Enabled=1";
+ $Relations->LoadRelated($where,"",$sql);
+ $ids = array();
+ if($Relations->NumItems()>0)
+ {
+ foreach($Relations->Items as $r)
+ {
+ if($r->Get("SourceId")==$ResourceId)
+ {
+ $ids[$r->Get("TargetType")][] = $r->Get("TargetId");
+ }
+ if($r->Get("TargetId")==$ResourceId && $r->Get("Type")==1)
+ {
+ $ids[$r->Get("SourceType")][] = $ResourceId;
+ }
+ }
+ foreach($ids as $ItemType=>$idlist)
+ {
+ $Item =& $objItemTypes->GetItem($ItemType);
+ if( !is_object($Item) )
+ {
+ if( isDebugMode() ) echo 'Item with RID [<b>'.$ResourceId.'</b>] has <b>invalid relation</b> to items with RIDS: <b>'.print_r($idlist, true).'</b><br>';
+ continue;
+ }
+ $table = GetTablePrefix().$Item->Get("SourceTable");
+ if($ItemType!=1)
+ {
+ $cattable = GetTablePrefix()."CategoryItems";
+ $sql = "SELECT *,CategoryId FROM $table INNER JOIN $cattable ON ";
+ $sql .=" ($table.ResourceId=$cattable.ItemResourceId) WHERE $table.Status=1 AND PrimaryCat=1 ";
+ $sql .=" AND ResourceId IN (".implode(",",$ids[$ItemType]).")";
+ }
+ else
+ {
+ $sql = "SELECT *,CategoryId FROM $table ";
+ $sql .="WHERE $table.Status=1 ";
+ $sql .=" AND ResourceId IN (".implode(",",$ids[$ItemType]).")";
+ }
+ // echo $sql."<br>\n";
+ $RelatedItems->Query_Item($sql,-1,-1,$ItemType);
+ }
+ }
+ }
+}
+
+
+/*
+ @description: Inserts the html from a remote source
+ @attrib: _url:: Remote URL to include
+ @attrib: _StartPos:: Numeric start point of text to include, or string match
+ @attrib: _EndPos:: Numeric end point of text to include, or string match
+ @example: <inp:m_insert_url _Url="http://www.google.com" _StartPos="\<center\>" _EndPos="\</center\>" />
+*/
+function m_insert_url($attribs=array())
+{
+ global $pathtoroot;
+
+ $url = $attribs["_url"];
+ $StartPos = $attribs["_startpos"];
+ $EndPos = $attribs["_endpos"];
+
+ $socket = new Socket($url,0,NULL);
+ $txt = $socket->socket_read_all();
+ $lines = explode("\n",$txt);
+ $txt = substr($txt,strpos($txt,"<"));
+ $tmp = strtolower($txt);
+ $bodypos = strpos($tmp,"<body");
+ if(strlen($bodypos)>0)
+ {
+ $head = substr($txt,0,$bodypos-1);
+ $body = substr($txt,$bodypos);
+ if(substr($tmp,-7)=="</html>")
+ $body = substr($body,0,-7);
+ }
+ else
+ $body = $txt;
+ if(strlen($body))
+ {
+ if(strlen($StartPos))
+ {
+ if(!is_numeric($StartPos))
+ {
+ $start = strpos($body,$StartPos);
+ }
+ else
+ $start = (int)$StartPos;
+ }
+ else
+ $start = 0;
+ if(strlen($EndPos))
+ {
+ if(!is_numeric($EndPos))
+ {
+ $end = strpos($body,$EndPos,$start) + strlen($EndPos);
+ }
+ else
+ $end = (int)$EndPos;
+ }
+ else
+ $end = NULL;
+ $o = substr($body,$start,$end-$start);
+ }
+ return $o;
+}
+
+/*
+ @description: Displays a template depending on the login status of the user
+ @attrib: _logintemplate:tpl: template to display when the user is NOT logged in
+ @attrib: _LoggedinTemplate:tpl: template to display when the user is logged in
+ @example: <inp:m_loginbox _LoginTemplate="right_login" _LoggedInTemplate="right_loggedin" />
+*/
+function m_loginbox($attribs = array())
+{
+ global $var_list, $objSession, $objUsers, $objTemplate;
+
+ $userid = $objSession->Get('PortalUserId');
+
+ if ($userid <= 0) {
+ if ( getArrayValue($attribs, '_logintemplate')) {
+ $t = $objTemplate->ParseTemplate($attribs['_logintemplate']);
+ }
+ return $t;
+ }
+ else {
+ $user =& $objUsers->GetItem($userid);
+ if (getArrayValue($attribs, '_loggedintemplate')) {
+ $t = $user->ParseTemplate($attribs['_loggedintemplate']);
+ }
+ return $t;
+ }
+}
+/*
+ @description: result of suggest site action
+*/
+function m_suggest_result()
+{
+ global $objSession;
+ $ret = $objSession->GetVariable('suggest_result');
+ $objSession->SetVariable('suggest_result', '');
+ return $ret;
+}
+
+/*
+ @description: result of subscribe to mailing list action
+*/
+function m_subscribe_result()
+{
+ global $SubscribeResult;
+
+ if(strlen($SubscribeResult))
+ return language($SubscribeResult);
+ return "";
+}
+
+/*
+ @description: email address of user subscribing to mailing list
+*/
+function m_subscribe_address()
+{
+ global $objSession;
+
+ return $objSession->GetVariable('SubscribeAddress');
+}
+
+/*
+ @description: Error message of subscribe to mailing list action
+*/
+function m_subscribe_error()
+{
+ global $objSession;
+ $error_phrase = $objSession->GetVariable('SubscribeError');
+ return $error_phrase ? language($error_phrase) : '';
+}
+
+
+/*
+ @description: Displays a prompt for a form field
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _LangText:lang: Language var to use for field label
+ @attrib: _plaintext:: Plain text to use for field label (langtext is used by default if both are set)
+ @attrib: _Template:tpl: template used to display the field label (if not set "<inp:form_prompt />" is used
+ @attrib: _ErrorTemplate:tpl: If the field is in an error state (ie missing input) this template is used. Will default to the normal template if not set
+*/
+function m_form_prompt($attribs = array())
+{
+ global $FormError, $objTemplate, $objConfig;
+
+ $form = strtolower($attribs["_form"]);
+ $field = strtolower($attribs["_field"]);
+
+ if($form=="m_register" && ($field=="password" || $field=="passwordverify") && $objConfig->Get("User_Password_Auto"))
+ {
+ $o = "";
+ }
+ else
+ {
+ $t = $attribs["_template"];
+ if(!strlen($t))
+ {
+ $templateText = "<inp:form_prompt />";
+ }
+ $e = $attribs["_errortemplate"];
+ if(!strlen($e))
+ $e = $t;
+ if(strlen($attribs["_langtext"]))
+ {
+ $txt = language($attribs["_langtext"]);
+ }
+ else
+ $txt = $attribs["_plaintext"];
+
+ if (strtolower($field) == "dob")
+ {
+ if (isset($FormError[strtolower($form)][strtolower($field."_day")]) || isset($FormError[strtolower($form)][strtolower($field."_month")]) || isset($FormError[strtolower($form)][strtolower($field."_year")]))
+ $rawtext = $objTemplate->GetTemplate($e, true);
+ }
+
+ if(isset($FormError[strtolower($form)][strtolower($field)]))
+ {
+ $rawtext = $objTemplate->GetTemplate($e);
+ }
+ elseif (strlen($t))
+ $rawtext = $objTemplate->GetTemplate($t);
+
+ if(is_object($rawtext))
+ {
+ $src = $rawtext->source;
+ $o = str_replace("<inp:form_prompt />",$txt, $src);
+ }
+ else
+ $o = str_replace("<inp:form_prompt />", $txt, $templateText);
+
+ }
+ return $o;
+}
+
+/*
+ @description: Returns text if system is configured to use auto-generated passwords
+ @attrib:_LangText:lang:Language tag to return
+ @attrib:_PlainText::Plain text to return (_LangText takes precedece)
+ @attrib:_Value:bool:Auto Password setting value to match
+*/
+function m_autopassword($attribs = array())
+{
+ global $objConfig;
+ if($attribs["_value"]=="true" || $attribs["_value"]==1)
+ {
+ $IsAuto = $objConfig->Get("User_Password_Auto");
+ }
+ else
+ {
+ $IsAuto = !$objConfig->Get("User_Password_Auto");
+ }
+
+ if($IsAuto)
+ {
+ if(strlen($attribs["_langtext"]))
+ {
+ $ret = language($attribs["_langtext"]);
+ }
+ else
+ $ret = $attribs["_plaintext"];
+ if(!$ret)
+ return "true";
+ }
+ return $ret;
+}
+
+/*
+ @description: checks if field specified is equals to value specified
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _Value:: Field value to compare to
+ @example: <inp:m_field_equals _field="topic_subject" _Form="edit_topic" _Value="test" />true</inp:m_field_equals>
+*/
+function m_field_equals($attribs = array())
+{
+ global $FormValues;
+ //print_pre($attribs);
+ $form = $attribs["_form"];
+ $field = $attribs["_field"];
+ if(isset($_POST[$field]))
+ {
+ $value = $_POST[$field];
+ }
+ else
+ {
+ $value = $FormValues[$form][$field];
+ if (is_array($value))
+ {
+ $value = is_null($value['lang_value'])? $value['value'] : $value['lang_value'];
+ }
+ }
+ //echo "POST_VALUE: [$value] vs USER_VALUE: [".$attribs['_value']."]<br>";
+ return $value == $attribs['_value'] ? 1 : '';
+}
+
+/*
+ @description: creates an INPUT tag for a form field. All extra attributes are passed to the INPUT tag
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _ForgetValue:bool: if true, forget value
+ @attrib: _Required:bool: If set, In-Portal requires this field have a value when submitting
+ @example: <inp:m_form_input type="text" class="input" style="width:600px;" _field="topic_subject" _Form="edit_topic" _Required="1" />
+*/
+function m_form_input($attribs = array())
+{
+ global $FormValues, $objConfig;
+ $html_attribs = ExtraAttributes($attribs);
+ $form = $attribs["_form"];
+ $field = strtolower($attribs["_field"]);
+// $field = $attribs["_field"];
+ $value='';
+ if(isset($_POST[$field]) && getArrayValue($attribs,'_forgetvalue') != 1)
+ {
+ $value = inp_htmlize($_POST[$field],1);
+ }
+ else {
+ if (getArrayValue($attribs,'_forgetvalue') != 1 && getArrayValue($FormValues[$form],$field) ) {
+ $value = $FormValues[$form][$field];
+ if (is_array($value))
+ {
+ $value = is_null($value['lang_value'])? $value['value'] : $value['lang_value'];
+ }
+ $value = inp_htmlize($value);
+ }
+ }
+
+ if($form=='new_pm' && $field=='pm_subject' && !get_magic_quotes_gpc())
+ {
+ $value = stripslashes($value);
+ }
+
+// print_pre($FormValues);
+// echo $form.".".$field."=".$value." = ".$attribs['_forgetvalue']."<br>\n";
+
+ if($form=="m_register" && ($field=="password" || $field=="passwordverify") && $objConfig->Get("User_Password_Auto"))
+ {
+ $ret = "";
+ }
+ else
+ {
+ $ret = "<INPUT ".$html_attribs." name=\"$field\" VALUE=\"$value\" />";
+ if(getArrayValue($attribs,'_required'))
+ $ret .= "<input type=hidden name=\"required[]\" VALUE=\"$field\" />";
+ if(getArrayValue($attribs,'_custom'))
+ $ret .= "<input type=hidden name=\"custom[]\" VALUE=\"$field\" />";
+ }
+ return $ret;
+}
+
+/*
+ @description: creates an INPUT tag (type checkbox) for a form field. All extra attributes are passed to the INPUT tag
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _Value:bool: If true, the radio button is CHECKED
+ @attrib: _Required:bool: If set, In-Portal requires this field have a value when submitting
+ @attrib: _Custom:bool: If set, handled as a custom field
+ @example: <inp:m_form_checkbox _field="owner_notify" _Form="edit_topic" />
+*/
+function m_form_checkbox($attribs = array())
+{
+ global $FormValues, $objConfig;
+
+ $html_attribs = ExtraAttributes($attribs);
+ $form = $attribs['_form'];
+ $field = strtolower($attribs['_field']);
+ if(isset($_POST[$field]))
+ {
+ $value = (int)$_POST[$field];
+ if($value==1) $checked = ' CHECKED';
+ }
+ else
+ {
+ $value = $FormValues[$form][$field];
+ if (is_array($value)) {
+ $value = $value['value'];
+ }
+
+ if ((int)$value==1) {
+ $checked = ' CHECKED';
+ }
+ }
+ //echo $form.".".$field."=".$value."<br>\n";
+ $ret = "<INPUT TYPE=\"checkbox\" $html_attribs name=\"$field\" VALUE=\"1\" $checked />";
+ if($attribs["_required"])
+ $ret .= "<input type=hidden name=\"required[]\" VALUE=\"$field\" />";
+ if($attribs["_custom"])
+ $ret .= "<input type=hidden name=\"custom[]\" VALUE=\"$field\" />";
+
+ $ret .= '<input type="hidden" name="form_fields[]" VALUE="'.$field.'" />';
+ return $ret;
+}
+
+/*
+ @description: creates an INPUT tag (type radio) for a form field. All extra attributes are passed to the INPUT tag
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _Value:: Value assigned to radio button. If the form field value matches this attribute, the radio button is CHECKED
+ @attrib: _Required:bool: If set, In-Portal requires this field have a value when submitting
+ @attrib: _Default:string: Default value for radiobutton if not checked
+ @attrib: _Custom:bool: If set, handled as a custom field
+ @example: <inp:m_form_radio _field="owner_notify" _Form="edit_topic" />
+*/
+function m_form_radio($attribs = array())
+{
+ global $FormValues, $objConfig;
+
+ $html_attribs = ExtraAttributes($attribs);
+ $form = $attribs['_form'];
+ $field = strtolower($attribs['_field']);
+ $val = $attribs['_value'];
+
+ if( GetVar($field) !== false )
+ {
+ $value = GetVar($field);
+ if($value == $val) $checked = ' CHECKED';
+ }
+ else
+ {
+ $value = $FormValues[$form][$field];
+ if (is_array($value))
+ {
+ $value = $value['value'];
+ }
+ if( !isset($value) && getArrayValue($attribs,'_default') ) $value = $val;
+ if($value==$val) $checked=' CHECKED';
+ }
+
+ //echo $form.".".$field."=".$value."<br>\n";
+ $ret = "<INPUT TYPE=\"radio\" $html_attribs name=\"$field\" VALUE=\"$val\" $checked />";
+ if($attribs["_required"])
+ $ret .= "<input type=hidden name=\"required[]\" VALUE=\"$field\" />";
+ if($attribs["_custom"])
+ $ret .= "<input type=hidden name=\"custom[]\" VALUE=\"$field\" />";
+
+ return $ret;
+}
+/*
+ @description: returns the value for a form field. This may be defaulted by the system or set by a previus submit (as in an error condition)
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @example: <inp:m_form_value _field="owner_notify" _Form="edit_topic" />
+*/
+function m_form_value($attribs = array())
+{
+ global $FormValues;
+
+ $form = $attribs["_form"];
+ $field = strtolower($attribs["_field"]);
+
+ if(isset($_POST[$field]))
+ {
+ $value = inp_htmlize($_POST[$field],1);
+ }
+ elseif(getArrayValue($_GET, 'search_type') == 'advanced')
+ {
+ $value = '';
+ }
+ else
+ {
+ $value = inp_htmlize($FormValues[$form][$field], 1);
+ if (is_array($value))
+ {
+ $value = is_null($value['lang_value'])? $value['value'] : $value['lang_value'];
+ }
+ $value = inp_htmlize($value, 1);
+ }
+ //echo "<pre>"; print_r($FormValues); echo "</pre>";
+ return $value;
+}
+
+/*
+ @description: creates an form OPTION tag for a form SELECT tag.
+ All extra attributes are passed to the OPTION tag.
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _Value:: Value to use for this option (ie the value attribute) If the current value of the select
+ field is the same as this attribute, then this option will be set SELECTED.
+ @attrib: _langtext:lang: language tag to display for this option in the SELECT dropdown
+ @attrib: _plaintext:: plain text to display for this option in the SELECT dropdown (if _langtext is set, it is used instead of _plaintext)
+ @example: <inp:m_form_option _value="3321" _field="formfield" _form="formname" _langtext="lu..."
+*/
+function m_form_option($attribs = array())
+{
+ global $FormValues, $objSession;
+
+ $html_attribs = ExtraAttributes($attribs);
+ $field = getArrayValue($attribs, "_field");
+ $form = getArrayValue($attribs, "_form");
+ $val = getArrayValue($attribs, "_value");
+
+ if(isset($_POST[$field]))
+ {
+ $value = $_POST[$field];
+ }
+ else
+ {
+ $value = isset($FormValues[$form][$field]) ? $FormValues[$form][$field] : $objSession->GetPersistantVariable($field);
+ // No need to read lan_value since it's options/drop-down field
+ if (is_array($value))
+ $value = $value['value'];
+ }
+
+ $selected = (strtolower($val) == strtolower($value))? "SELECTED" : "";
+
+ //echo "Sel $field = $value: $selected<br>";
+
+ if( getArrayValue($attribs,'_langtext') )
+ {
+ $txt = language($attribs["_langtext"]);
+ }
+ else
+ $txt = $attribs["_plaintext"];
+
+ $o = "<OPTION $html_attribs VALUE=\"$val\" $selected>$txt</OPTION>";
+
+ return $o;
+}
+
+ function m_form_custom_options($attribs = array())
+ {
+ global $FormValues, $objSession;
+ $html_attribs = ExtraAttributes($attribs);
+
+ $form = $attribs['_form'];
+ $field = $attribs['_field'];
+
+ $application =& kApplication::Instance();
+ $item_type = $application->getUnitOption($attribs['_prefix'], 'ItemType');
+
+ $sql = 'SELECT ValueList FROM '.GetTablePrefix().'CustomField WHERE FieldName = %s AND Type = %s';
+ $values = $application->Conn->GetOne( sprintf($sql, $application->DB->qstr($field), $item_type ) );
+ if(!$values) return '';
+
+ if( GetVar($field) )
+ {
+ $value = GetVar($field);
+ }
+ else
+ {
+ $value = $FormValues[$form][$field];
+ if( is_array($value) ) $value = $value['value'];
+ }
+
+ $ret = '';
+ $values = explode(',', $values);
+ $option_tpl = '<option value="%s"%s>%s</option>';
+ foreach($values as $mixed_value)
+ {
+ $mixed_value = explode('=', $mixed_value);
+ $label = substr($mixed_value[1],0,1) == '+' ? substr($mixed_value[1],1,strlen($mixed_value[1])) : language($mixed_value[1]);
+ $selected = $mixed_value[0] == $value ? ' selected' : '';
+ $ret .= sprintf($option_tpl, $mixed_value[0], $selected, $label);
+ }
+
+ return $ret;
+ }
+
+
+/*
+ @description: creates an form TEXTAREA field. All extra attributes are passed to the TEXTAREA tag
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _Required:bool: If set, In-Portal requires this field have a value when submitting
+ @attrib: _Custom:bool: If set, handled as a custom field
+ @example: <inp:m_form_textarea class="textarea" _field="bb_signature" _Form="bb_profile" ID="textbody" style="width:300px;" ROWS=10 COLS=65 WRAP="VIRTUAL" />
+*/
+function m_form_textarea($attribs = array())
+{
+ global $FormValues;
+ $html_attribs = ExtraAttributes($attribs);
+ $field = $attribs["_field"];
+ $form = $attribs["_form"];
+ if(isset($_POST[$field]))
+ {
+ $value = inp_htmlize($_POST[$field],1);
+ }
+ else
+ {
+ $value = $FormValues[$form][$field];
+ if (is_array($value)) $value = $value['value'];
+ $value = inp_htmlize($value);
+ }
+
+ $ret = "<TEXTAREA NAME=\"$field\" $html_attribs>$value</TEXTAREA>";
+ if( getArrayValue($attribs,'_required') )
+ {
+ $ret .= "<input type=hidden name=required[] VALUE=\"$field\" />";
+ }
+ if( getArrayValue($attribs,'_custom') )
+ {
+ $ret .= "<input type=hidden name=\"custom[]\" VALUE=\"$field\" />";
+ }
+ return $ret;
+}
+
+/*
+ @description: creates an form field to upload images. (INPUT type=file) All extra attributes are passed to the INPUT tag
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+ @attrib: _Required:bool: If set, In-Portal requires this field have a value when submitting
+ @attrib: _ImageTypes:: Comma-separated list of file extensions allowed
+ @attrib: _Thumbnail:bool: If true, image is treated as a thumbnail
+ @attrib: _ImageName:: System name of image being uploaded
+ @attrib: _MaxSize:int: Maximum size of image to upload, or 0 to allow all
+*/
+function m_form_imageupload($attribs = array())
+{
+ $html_attribs = ExtraAttributes($attribs);
+ $field = $attribs["_field"];
+ $form = $attribs["_form"];
+ $TypesAllowed = getArrayValue($attribs,'_imagetypes');
+ $isthumb = (int)getArrayValue($attribs,'_thumbnail');
+ $imgname = getArrayValue($attribs,'_imagename');
+ $maxsize = getArrayValue($attribs,'_maxsize');
+ $is_default = getArrayValue($attribs, '_default');
+
+ $ret = "<INPUT $html_attribs TYPE=file NAME=\"$field\" >";
+ $ret .= "<INPUT TYPE=HIDDEN name=\"isthumb[$field]\" VALUE=\"$isthumb\">";
+ $ret .= "<INPUT TYPE=HIDDEN name=\"imagetypes[$field]\" VALUE=\"$TypesAllowed\">";
+ $ret .= "<INPUT TYPE=HIDDEN name=\"imagename[$field]\" VALUE=\"$imgname\">";
+ $ret .= "<INPUT TYPE=HIDDEN name=\"maxsize[$field]\" VALUE=\"$maxsize\">";
+ if($is_default) $ret .= '<input type="hidden" name="imgdefault['.$field.']" value="1">';
+
+ if( getArrayValue($attribs,'_required') )
+ {
+ $ret .= "<input type=hidden name=required[] VALUE=\"$field\" />";
+ }
+ return $ret;
+}
+
+/*
+ @description: Returns the error text for a form field, or nothing if no error exists for the field
+ @attrib: _Form:: Form name for the field
+ @attrib: _Field:: Field Name
+*/
+function m_form_error($attribs = array())
+{
+ global $FormError;
+
+ $form = $attribs["_form"];
+ $field = $attribs["_field"];
+
+ return $FormError[$form][$field];
+}
+
+/**
+ @description: Provides a simple solution for displaying a language flag when a form has an error. Generic and limited to 1 language vairable.
+ @attrib: _Form:: Form name for the field
+*/
+function m_form_has_errors($attribs = array())
+{
+ // shows specified template once if form has error(-s)
+ global $FormError;
+ $f = $attribs["_form"];
+
+ $ret = is_array($FormError[$f]);
+ if(!$ret) return '';
+ return isset($attribs["_asif"]) ? true : language('lu_errors_on_form');
+}
+
+/**
+ @description: Lists form errors for all fields in a form
+ @attrib: _Form:: Form name for the field
+ @attrib: _ItemTemplate:tpl: Template used to display each form error (if not set, "<inp:form_error />" is used)
+*/
+function m_list_form_errors($attribs = array())
+{
+ global $FormError, $content_set, $objTemplate;
+
+ $t = $attribs["_itemtemplate"];
+ if(!strlen($t))
+ $templateText = "<inp:form_error />";
+ $f = $attribs["_form"];
+ $o = "";
+ if (strlen($t))
+ {
+ $rawtext = $objTemplate->GetTemplate($t, true);
+ $src = $rawtext->source;
+ }
+ else
+ $src = $templateText;
+
+ //echo $f."<br>";
+ //echo $t."<br>";
+// echo "<PRE>"; print_r($FormError); echo "</pre>";
+ if( getArrayValue($FormError,$f) && is_array($FormError[$f]))
+ {
+ foreach($FormError[$f] as $e)
+ {
+ $o .= str_replace("<inp:form_error />",$e, $src);
+ }
+ }
+ if(!strlen($o))
+ $content_set = 0;
+ return $o;
+}
+
+function m_form_load_values($FormName,$IdValue)
+{
+ global $FormValues, $objUsers, $objSession, $objConfig;
+
+ switch($FormName)
+ {
+ case "m_acctinfo":
+ $u =& $objUsers->GetItem($IdValue);
+ $FormValues[$FormName]["username"] = $u->Get("Login");
+ //$FormValues[$FormName]["password"] = $u->Get("Password");
+ //$FormValues[$FormName]["passwordverify"] = $u->Get("Password");
+
+ $FormValues[$FormName]["password"] = "";
+ $FormValues[$FormName]["passwordverify"] = "";
+
+ $FormValues[$FormName]["firstname"] = $u->Get("FirstName");
+ $FormValues[$FormName]["lastname"] = $u->Get("LastName");
+ $FormValues[$FormName]["company"] = $u->Get("Company");
+ $FormValues[$FormName]["email"] = $u->Get("Email");
+ $FormValues[$FormName]["phone"] = $u->Get("Phone");
+ $FormValues[$FormName]["fax"] = $u->Get("Fax");
+ $FormValues[$FormName]["street"] = $u->Get("Street");
+ $FormValues[$FormName]["street2"] = $u->Get("Street2");
+ $FormValues[$FormName]["city"] = $u->Get("City");
+ $FormValues[$FormName]["state"] = $u->Get("State");
+ $FormValues[$FormName]["zip"] = $u->Get("Zip");
+ $FormValues[$FormName]["country"] = $u->Get("Country");
+ $FormValues[$FormName]["minpwresetdelay"] = $u->Get("MinPwResetDelay");
+
+
+// $FormValues[$FormName]["dob"] = LangDate($u->Get("dob"), 0, true);
+ $FormValues[$FormName]["dob_day"] = adodb_date("d", $u->Get("dob"));
+ $FormValues[$FormName]["dob_year"] = adodb_date("Y", $u->Get("dob"));
+ $FormValues[$FormName]["dob_month"] = adodb_date("m", $u->Get("dob"));
+
+ $u->LoadCustomFields();
+ if(is_array($u->CustomFields))
+ {
+ foreach($u->CustomFields as $f=>$v)
+ {
+ $FormValues[$FormName][$f] = $v;
+ }
+ }
+ break;
+ case "m_profile":
+ $u =& $objUsers->GetItem($IdValue);
+ if(is_object($u))
+ {
+ $FormValues[$FormName]["pp_firstname"] = $objSession->GetPersistantVariable("pp_firstname");
+ $FormValues[$FormName]["pp_lastname"] = $objSession->GetPersistantVariable("pp_lastname");
+ $FormValues[$FormName]["pp_dob"] = $objSession->GetPersistantVariable("pp_dob");
+ $FormValues[$FormName]["pp_email"] = $objSession->GetPersistantVariable("pp_email");
+ $FormValues[$FormName]["pp_phone"] = $objSession->GetPersistantVariable("pp_phone");
+ $FormValues[$FormName]["pp_street"] = $objSession->GetPersistantVariable("pp_street");
+ $FormValues[$FormName]["pp_city"] = $objSession->GetPersistantVariable("pp_city");
+ $FormValues[$FormName]["pp_state"] = $objSession->GetPersistantVariable("pp_state");
+ $FormValues[$FormName]["pp_zip"] = $objSession->GetPersistantVariable("pp_zip");
+ $FormValues[$FormName]["pp_country"] = $objSession->GetPersistantVariable("pp_country");
+ }
+ break;
+ case "m_simplesearch":
+ $FormValues[$FormName]["keywords"] = $objSession->GetVariable("Search_Keywords");
+ break;
+ case "m_simple_subsearch":
+ $FormValues[$FormName]["keywords"] = $objSession->GetVariable("Search_Keywords");
+ break;
+
+ }
+}
+
+/*
+ @description: Generates the ACTTION property for a FORM tag used by In-Portal
+ @attrib: _Template:tpl: If set, this is the template the form submits to (default is the current template)
+ @attrib: _Form:: The form name<br>Possible Values:
+ <UL>
+ <LI>login: user login
+ <LI>logout: user logout
+ <LI>forgotpw: Form to prompt the user for forgotten password information
+ <LI>forgotpw_confirm: confirmation form for forgotpw
+ <LI>suggest: form to suggest the site to a friend
+ <LI>suggest_confirm: form to confirm suggestion of the site to a friend
+ <LI>m_subscribe: form to subscribe to the mailing list
+ <LI>subscribe_confirm: form to confirm subscription to the mailing list
+ <LI>m_unsubscribe: form to unsubscribe from the mailing list
+ <LI>unsubscribe_confirm: form to confirm un-subscription from the mailing list
+ <LI>m_acctinfo: user account information
+ <LI>m_profile: system-level profile information
+ <LI>m_register: New User registration form
+ <LI>m_addcat: Suggest Category form
+ <LI>m_addcat_confirm: Confirmation for add category
+ <LI>m_simplesearch: Perform a simple search
+ <LI>m_simple_subsearch: Search within results
+ <LI>m_adv_searchtype: Form to select type of advanced search
+ <LI>m_adv_subsearch: Advanced Search
+ <LI>m_sort_cats: Sort categories
+ <LI>error_access: form displayed on the access denied template
+ <LI>error_template: Form displayed on the template error page
+ <LI>m_set_theme: Form displayed for theme selection
+ </UL>
+ @attrib: _SubscribeTemplate:tpl: The destination template with "m_subscribe", "subscribe_confirm", "unsubscribe_confirm" _Form actions. Can be reused in other scenarios as programmed.
+ @attrib: _UnSubscribeTemplate:tpl: The destination template for "m_subscribe" _Form action. Can be reused in other scenarios as programmed.
+ @attrib: _ConfirmTemplate:tpl: The destination template for "m_unsubscribe", "suggest" _Form actions. Can be reused in other scenarios as programmed.
+ @attrib: _DestTemplate:tpl: The destination template for "suggest_confirm", "suggest" _Form actions. Can be reused in other scenarios as programmed.
+ @attrib: _ErrorTemplate:tpl: The destination template extensively used in most of _Form actions in case of error.
+ @attrib: _Referer:bool: The destination template will be taken from referer page we can from.
+
+ @example: <FORM enctype="multipart/form-data" method="POST" NAME="article_review" ACTION="<inp:m_form_action _Form="register" _confirm="join_confirm" />">
+*/
+function m_form_action($attribs = array())
+{
+ global $var_list, $var_list_update, $m_var_list_update, $objSession, $objConfig, $objCatList;
+
+ $var_list_update['t'] = getArrayValue($attribs, '_template') ? $attribs['_template'] : $var_list['t'];
+
+ $ret = '';
+ $form = strtolower( $attribs['_form'] );
+ $url_params = Array();
+
+ switch($form)
+ {
+ case 'login':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_login');
+ if( getArrayValue($attribs, '_successtemplate') )
+ {
+ $url_params['dest'] = $attribs['_successtemplate'];
+ }
+ else
+ {
+ if( getArrayValue($var_list, 'dest') )
+ {
+ $var_list_update['t'] = $var_list['dest'];
+// $url_params['dest'] = $var_list['dest'];
+ }
+ }
+ $url_params['pass'] = 'all';
+ }
+ break;
+
+ case 'logout':
+ $url_params = Array('Action' => 'm_logout');
+ break;
+
+ case 'forgotpw':
+ if(!$objSession->SessionEnabled())
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_forgotpw');
+ $url_params['error'] = getArrayValue($attribs, '_errortemplate') ? $attribs['_errortemplate'] : $var_list['t'];
+ if( getArrayValue($attribs, '_confirm') ) $url_params['Confirm'] = $attribs['_confirm'];
+ }
+ break;
+
+ /*case 'forgotpw_confirm':
+ break;*/
+
+ case 'm_sort_cats':
+ $url_params = Array('Action' => 'm_sort_cats');
+ break;
+
+ case 'suggest':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_suggest_email');
+
+ if( getArrayValue($attribs, '_confirmtemplate') )
+ {
+ $url_params['Confirm'] = $attribs['_confirmtemplate'];
+ $url_params['DestTemplate'] = $var_list['t'];
+ }
+ if( getArrayValue($attribs, '_errortemplate') ) $url_params['Error'] = $attribs['_errortemplate'];
+ }
+ break;
+
+ case 'suggest_confirm':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $var_list_update['t'] = getArrayValue($_GET, 'DestTemplate') ? $_GET['DestTemplate'] : 'index';
+ }
+ break;
+
+ case 'm_subscribe':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_subscribe_confirm');
+ $params_map = Array('_subscribetemplate' => 'Subscribe', '_unsubscribetemplate' => 'Unsubscribe', '_errortemplate' => 'Error');
+ MapTagParams($url_params, $attribs, $params_map);
+ }
+ break;
+
+ case 'subscribe_confirm':
+ $url_params = Array('Action' => 'm_subscribe');
+ $params_map = Array('_subscribetemplate' => 'Subscribe');
+ MapTagParams($url_params, $attribs, $params_map);
+ break;
+
+ case 'unsubscribe_confirm':
+ $url_params = Array('Action' => 'm_unsubscribe');
+ $params_map = Array('_subscribetemplate' => 'Subscribe');
+ MapTagParams($url_params, $attribs, $params_map);
+ break;
+
+ case 'm_unsubscribe':
+ $params_map = Array('_confirmtemplate' => 'ErrorTemplate');
+ MapTagParams($url_params, $attribs, $params_map);
+
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params['Action'] = 'm_unsubscribe';
+ if( getArrayValue($attribs, '_confirmtemplate') )
+ {
+ $url_params['Confirm'] = $attribs['_confirmtemplate'];
+ $url_params['DestTemplate'] = $var_list['t'];
+ }
+ }
+ break;
+
+ /*case 'm_unsubscribe_confirm':
+ break;*/
+
+ case 'm_acctinfo':
+ $url_params = Array('Action' => 'm_acctinfo', 'UserId' => $objSession->Get('PortalUserId') );
+ m_form_load_values( $form, $objSession->Get('PortalUserId') );
+ break;
+
+ case 'm_profile':
+ $url_params = Array('Action' => 'm_profile', 'UserId' => $objSession->Get('PortalUserId') );
+ m_form_load_values( $form, $objSession->Get('PortalUserId') );
+ break;
+
+ case 'm_set_theme':
+ $url_params = Array('Action' => 'm_set_theme');
+ break;
+
+ case 'm_register':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_register');
+
+ switch ( $objConfig->Get('User_Allow_New') )
+ {
+ case 1:
+ if( getArrayValue($attribs, '_confirmtemplate') && $objConfig->Get('User_Password_Auto') )
+ {
+ $url_params['dest'] = $attribs['_confirmtemplate'];
+ }
+ else
+ {
+ $url_params['dest'] = $attribs['_logintemplate'];
+ }
+ break;
+
+ case 2:
+ if( getArrayValue($attribs, '_notallowedtemplate') ) $url_params['dest'] = $attribs['_notallowedtemplate'];
+ break;
+
+ case 3:
+ if( getArrayValue($attribs, '_pendingtemplate') ) $url_params['dest'] = $attribs['_pendingtemplate'];
+ break;
+ }
+ }
+ break;
+
+ case 'register_confirm':
+ if( !$objSession->SessionEnabled() ) $var_list_update['t'] = 'error_session';
+ break;
+
+ case 'm_addcat':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_add_cat');
+ if ( $objSession->HasCatPermission('CATEGORY.ADD.PENDING') )
+ {
+
+ $url_params['Confirm'] = $attribs[ getArrayValue($attribs, '_confirmpending') ? '_confirmpending' : '_confirm' ];
+ $url_params['Action'] = 'm_add_cat_confirm';
+ }
+
+ if ( $objSession->HasCatPermission('CATEGORY.ADD') )
+ {
+ $url_params['Confirm'] = $attribs['_confirm'];
+ $url_params['Action'] = 'm_add_cat_confirm';
+ }
+ if( !$url_params['Confirm'] ) unset($url_params['Confirm']);
+
+ if ( getArrayValue($attribs, '_mod_finishtemplate') )
+ {
+ $CurrentCat = (int)$objCatList->CurrentCategoryID();
+ if($CurrentCat > 0)
+ {
+ $c = $objCatList->GetCategory($CurrentCat);
+
+ //will prefix the template with module template root path depending on category
+ $ids = $c->GetParentIds();
+ $tpath = GetModuleArray('template');
+ $roots = GetModuleArray('rootcat');
+
+ // get template path of module, by searching for moudle name
+ // in this categories first parent category
+ // and then using found moudle name as a key for module template paths array
+ $path = $tpath[ array_search($ids[0], $roots) ];
+ $url_params['DestTemplate'] = $path . $attribs['_mod_finishtemplate'];
+ }
+ else
+ {
+ $url_params['DestTemplate'] = $attribs['_mod_finishtemplate']; //Just in case
+ }
+ }
+ else
+ {
+ $url_params['DestTemplate'] = $attribs['_finishtemplate'];
+ }
+ }
+ break;
+
+ case 'm_addcat_confirm':
+ $var_list_update['t'] = getArrayValue($_GET, 'DestTemplate') ? $_GET['DestTemplate'] : $var_list['t'];
+ break;
+
+ case 'm_simplesearch':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_simple_search');
+ if( getArrayValue($attribs, '_errortemplate') ) $url_params['Error'] = $attribs['_errortemplate'];
+ m_form_load_values($form, 0);
+ }
+ break;
+
+ case 'm_simple_subsearch':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_simple_subsearch');
+ m_form_load_values($form,0);
+ }
+ break;
+
+ case 'm_adv_search_type':
+ if( !$objSession->SessionEnabled() )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_advsearch_type');
+ m_form_load_values($form,0);
+ }
+ break;
+
+ case 'm_adv_search':
+ $SearchType = getArrayValue($_GET, 'type') ? $_GET['type'] : $_POST['itemtype'];
+ if( !$objSession->SessionEnabled() && !$SearchType )
+ {
+ $var_list_update['t'] = 'error_session';
+ }
+ else
+ {
+ $url_params = Array('Action' => 'm_adv_search', 'type' => $SearchType);
+ m_form_load_values($form,0);
+ }
+ break;
+
+ case 'error_access':
+ $var_list_update['t'] = getArrayValue($_GET, 'DestTemplate') ? $_GET['DestTemplate'] : 'login';
+ break;
+
+ case 'error_template':
+ $target_template = getArrayValue($_GET, 'DestTemplate');
+ if($attribs['_referer'] == 1)
+ {
+ $target_template = '_referer_';
+ }
+ elseif (!$target_template)
+ {
+ $target_template = 'index';
+ }
+ $var_list_update['t'] = $target_template;
+ break;
+ }
+ return HREF_Wrapper('', $url_params);
+}
+
+/*
+ @description: creates a URL to allow the user to log out. Accepts the same attributes as m_template_link
+
+*/
+function m_logout_link($attribs)
+{
+ $query = getArrayValue($attribs, '_query');
+ $attribs['_query'] = $query.'&Action=m_logout';
+ $ret = m_template_link($attribs);
+ return $ret;
+}
+
+/*
+ @description: returns a URL to the current theme
+ @attrib: _page:: Additional address to be added to the end of the theme URL
+*/
+function m_theme_url($attribs=array())
+{
+ global $objConfig,$objSession, $objThemes, $CurrentTheme;
+
+ if(!is_object($CurrentTheme))
+ $CurrentTheme = $objThemes->GetItem($m_var_list["theme"]);
+
+ $theme_url = PROTOCOL.SERVER_NAME.rtrim(BASE_PATH, '/').'/themes/'.$CurrentTheme->Get('Name').'/';
+ if(getArrayValue($attribs,'_page'))
+ {
+ if ($attribs["_page"] != 'current')
+ {
+ $theme_url .= $attribs["_page"];
+ }
+ else
+ {
+ $theme_url = PROTOCOL.SERVER_NAME.rtrim(BASE_PATH, '/').'/index.php?env='.BuildEnv();
+ }
+ }
+ return $theme_url;
+}
+
+/*
+ @description: returns a URL to the current theme
+*/
+function m_current_page_url($attribs=array())
+{
+ global $objConfig,$objSession;
+
+ $theme_url = "http://".$objConfig->Get("Site_Path")."index.php?env=".BuildEnv();
+
+ return $theme_url;
+}
+
+/*
+ @description: returns a URL to the current theme
+ @attrib: _fullpath:bool: Append the title with the full path of the current category
+ @attrib: _currentcategory:bool: Append the title with the current category
+ @attrib: _catfield:: If _currentcategory is used, this attribute determines which category field to use (Name, Description, etc) Defaults to Name
+*/
+function m_page_title($attribs = array())
+{
+ global $objConfig, $objCatList;
+
+ $application =& kApplication::Instance();
+ if ($application->isModuleEnabled('In-Edit')) {
+ $title = $application->ProcessTag('cms:PageInfo type="htmlhead_title"');
+ if ($title && !preg_match('/^_Auto.*/', $title)) {
+ return $title;
+ }
+ }
+
+ $ret = strip_tags( $objConfig->Get('Site_Name') );
+ if(getArrayValue($attribs,'_fullpath') || getArrayValue($attribs,'_currentcategory'))
+ {
+ $CurrentCat = $objCatList->CurrentCategoryID();
+ if((int)$CurrentCat>0)
+ {
+ $c = $objCatList->GetCategory($CurrentCat);
+ if($attribs["_fullpath"])
+ {
+ $application =& kApplication::Instance();
+ $ml_formatter =& $application->recallObject('kMultiLanguage');
+ $path = $c->Get($ml_formatter->LangFieldName('CachedNavbar'));
+
+ if (strlen($path)) {
+ $ret .= " - ".str_replace('&|&', ' > ', $path);
+ }
+ }
+ else
+ {
+ if($attribs["_currentcategory"])
+ {
+ $f = $attribs["_catfield"];
+ if (!strlen($f)) {
+ $f = "Name";
+ }
+
+ if ($f == 'Name') $f = $objCatList->TitleField;
+ $ret .= " - ".$c->Get($f);
+ }
+ }
+ }
+ }
+ $ret = stripslashes($ret);
+ return $ret;
+}
+
+/*
+ @description: list all active themes
+ @attrib: _ItemTemplate:tpl: Template to display each theme in the list
+*/
+function m_list_themes($attribs=array())
+{
+ global $objThemes;
+
+ $t = $attribs["_itemtemplate"];
+ if(strlen($t))
+ {
+ $objThemes->Clear();
+ $objThemes->LoadThemes("Enabled=1","PrimaryTheme DESC");
+
+ foreach($objThemes->Items as $theme)
+ {
+ $o .= $theme->ParseTemplate($t);
+ }
+ }
+ return $o;
+}
+
+/*
+ @description: display text based on the user's language
+ @attrib: _Phrase:lang: label to replace with language-specific text
+ @example: <inp:m_language _Phrase="lu_hello_world" />
+*/
+function m_language($attribs)
+{
+ global $objSession, $objLanguages, $ForceLanguage;
+
+ $phrase = $attribs["_phrase"];
+ $LangId = (int)$ForceLanguage;
+ if(strlen($phrase))
+ {
+ $lang = getArrayValue($attribs,'_language');
+ if(strlen($lang))
+ {
+ $l = $objLanguages->GetItemByField("PackName",$lang);
+ if(is_object($l))
+ {
+ $LangId = $l->Get("LanguageId");
+ }
+ }
+ return language($phrase,$LangId);
+ }
+ else
+ return "";
+}
+
+/*
+ @description: Creates a URL used to set the current language for a user
+ @attrib: _language:: Language to set (this value should be the language Pack Name)
+*/
+function m_setlang_link($attribs)
+{
+ global $m_var_list_update, $objSession,$objLanguages;
+
+ $lang = getArrayValue($attribs, '_language');
+ if($lang)
+ {
+ $l = $objLanguages->GetItemByField('PackName', $lang);
+ if( is_object($l) ) $LangId = $l->Get('LanguageId');
+ }
+ else
+ {
+ $LangId = $objSession->Get('Language');
+ }
+
+ if($LangId)
+ {
+ $m_var_list_update['lang'] = $LangId;
+ $ret = HREF_Wrapper();
+ unset($m_var_list_update['lang']);
+ }
+ else
+ {
+ $ret = '';
+ }
+ return $ret;
+}
+
+/*
+ @description: list all active languages
+ @attrib: _ItemTemplate:tpl: Template to display each language in the list
+*/
+function m_list_languages($attribs)
+{
+ global $objLanguages, $content_set;
+
+ $sql = "SELECT * FROM ".GetTablePrefix()."Language WHERE Enabled=1";
+ $objLanguages->Clear();
+ $objLanguages->Query_Item($sql);
+ $o='';
+ if($objLanguages->NumItems()>0)
+ {
+ foreach($objLanguages->Items as $l)
+ $o .= $l->ParseTemplate($attribs["_itemtemplate"]);
+ }
+ else
+ $content_set=0;
+ return $o;
+}
+
+/*
+ @description: returns the date format for a language
+ @attrib: _lang:: Pack Name of language to use. The current language is used if this is not set
+*/
+function m_lang_dateformat($attribs=array())
+{
+ global $objLanguages, $objSession;
+
+ $lang = $attribs["_lang"];
+ if(!strlen($lang))
+ {
+ $LangId = $objSession->Get("Language");
+ $l = $objLanguages->GetItem($LangId);
+ }
+ else
+ {
+ $l = $objLanguages->GetItemByField("PackName",$lang);
+ }
+ $fmt = GetDateFormat($LangId, true);
+ $fmt = GetStdFormat($fmt);
+
+ return $fmt;
+}
+
+/*
+ @description: returns a language field value
+ @attrib: _Field:: Language field to return
+ @attrib: _lang:: Pack Name of language to use. The current language is used if this is not set
+*/
+function m_lang_field($attribs = array())
+{
+ global $objLanguages, $objSession;
+
+ if(!strlen($attribs["_field"]))
+ return "";
+ $lang = getArrayValue($attribs,'_lang');
+ if(!strlen($lang))
+ {
+ $LangId = $objSession->Get("Language");
+ $l = $objLanguages->GetItem($LangId);
+ }
+ else
+ {
+ $l = $objLanguages->GetItemByField("PackName",$lang);
+ }
+ if(is_object($l))
+ {
+ //$ret = $l->Get($attribs["_field"]);
+ $e = new clsHtmlTag();
+ $e->name=$l->TagPrefix;
+ $e->attributes=$attribs;
+ $ret = $l->ParseObject($e);
+ }
+ return $ret;
+}
+
+/*
+ @description: Creates a URL used to set the current theme for a user
+ @attrib: _theme:: Name of Theme to set. The template selected in the new them is always "index"
+*/
+function m_settheme_link($attribs)
+{
+ global $m_var_list_update, $objSession, $objThemes, $CurrentTheme;
+
+ $ThemeName = getArrayValue($attribs, '_theme');
+ if($ThemeName)
+ {
+ $t = $objThemes->GetItemByField('Name',$ThemeName);
+ $Id = is_object($t) ? $t->Get('ThemeId') : 0;
+ }
+ else
+ {
+ $t = $CurrentTheme;
+ $Id = 0;
+ }
+ $m_var_list_update['theme'] = $Id;
+ $ret = HREF_Wrapper();
+ unset($m_var_list_update['theme']);
+
+ return $ret;
+}
+
+/*
+ @description: Initializes categories
+*/
+function m_init_cats($attribs = array())
+{
+ // save current & previous category (used in pagination)
+ global $objSession, $objCatList;
+ global $var_list;
+
+ $objSession->SetVariable('prev_category', $objSession->GetVariable('last_category') );
+ $objSession->SetVariable('last_category', $objCatList->CurrentCategoryID() );
+
+ //$last_cat = $objSession->GetVariable('last_category');
+ //$prev_cat = $objSession->GetVariable('prev_category');
+ //echo "Last CAT: [$last_cat]<br>";
+ //echo "Prev CAT: [$prev_cat]<br>";
+}
+
+/*
+ @description: List all subcategories a user is allowed to view
+ @attrib: _columns:int: Numver of columns to display the categories in (defaults to 1)
+ @attrib: _maxlistcount:int: Maximum number of categories to list
+ @attrib: _FirstItemTemplate:tpl: Template used for the first category listed
+ @attrib: _LastItemTemplate:tpl: Template used for the last category listed
+ @attrib: _EdItemTemplate:tpl: Editors Pick template used for category list items
+ @attrib: _ItemTemplate:tpl: default template used for category list items
+ @attrib: _NoTable:bool: If set to 1, the categories will not be listed in a table. If a table is used, all HTML attributes are passed to the TABLE tag
+ @example: <inp:m_list_cats _NoTable="0" _columns="2" _ItemTemplate="catlist_element" border="0" cellspacing="0" cellpadding="0" width="98%" />
+*/
+function m_list_cats($attribs = array())
+{
+ global $var_list, $objConfig, $objSession, $objCatList, $var_list_update, $content_set, $objSystemCache;
+
+ $CachedList = GetTagCache("kernel","m_list_cats",$attribs,m_BuildEnv());
+ if(strlen($CachedList))
+ {
+ return $CachedList;
+ }
+ $cols = $attribs["_columns"];
+ if($cols<1)
+ $cols =1;
+ $CategoryId = getArrayValue($attribs,'_catid');
+ if(!is_numeric($CategoryId))
+ $CategoryId = $objCatList->CurrentCategoryID();
+
+ $cat_count = (int)getArrayValue($attribs,'_maxlistcount');
+ /* validation */
+ if(strlen($attribs["_itemtemplate"])==0)
+ {
+ if($attribs["dataexists"])
+ $content_set = 0;
+ return "";
+ }
+
+ $GroupList = $objSession->Get("GroupList");
+ if(strlen($GroupList))
+ {
+ $Groups = explode(",",$GroupList);
+ }
+ $acl_where = "";
+ if(@count($Groups)>0 && is_array($Groups))
+ {
+ $acl_where = array();
+ for($i=0;$i<count($Groups);$i++)
+ {
+ $g = $Groups[$i];
+ $acl_where[] = "FIND_IN_SET($g,acl) ";
+ }
+ if(count($acl_where))
+ {
+ $acl_where = "(".implode(" OR ",$acl_where).")";
+ }
+ else {
+ $acl_where = "FIND_IN_SET(0,acl)";
+ }
+ }
+ else {
+ $acl_where = "FIND_IN_SET(0,acl)";
+ }
+ $objCatList->Clear();
+ $OrderBy = $objCatList->QueryOrderByClause(TRUE,TRUE,TRUE);
+ $objCatList->LoadCategories("ParentId=$CategoryId AND Status=1",$OrderBy, false);
+ if ($objCatList->NumItems() == 0)
+ {
+ if($attribs["_dataexists"])
+ $content_set = 0;
+ return "";
+ }
+
+ $html_attr = ExtraAttributes($attribs);
+
+ $o="";
+ $notable = $attribs["_notable"];
+
+ $count=0;
+ $row=0;
+ $var_list_update["t"] = $var_list["t"];
+
+ if(!$notable)
+ {
+ $per_row = ceil($objCatList->NumItems()/$cols);
+ $o = '<table '.$html_attr.'><tr class="m_list_cats">';
+ $o .= '<td valign="top">';
+ $CatCount = $objCatList->NumItems();
+ foreach($objCatList->Items as $cat)
+ {
+ $parsed=0;
+ if($count==$per_row)
+ {
+ $o .= '</td><td valign="top">';
+ $count=0;
+ }
+ if($row==0 && strlen($attribs["_firstitemtemplate"]))
+ {
+ $o.= $cat->ParseTemplate($attribs["_firstitemtemplate"]);
+ $parsed=1;
+ }
+ if($row==$CatCount-1 && !$parsed && strlen($attribs["_lastitemtemplate"])>0)
+ {
+ $o .= $cat->ParseTemplate($attribs["_lastitemtemplate"]);
+ $parsed=1;
+ }
+ if(!$parsed)
+ {
+ if (getArrayValue($attribs, '_editemtemplate') && (int)$cat->Get('EditorsPick'))
+ {
+ $o .= $cat->ParseTemplate($attribs["_editemtemplate"]);
+ }
+ else
+ {
+ $o .= $cat->ParseTemplate($attribs['_itemtemplate']);
+ }
+ }
+ $count++;
+ $row++;
+ }
+ if($count != $per_row)
+ $o .= '</td>';
+ $o .= "\n</tr></table>\n";
+ }
+ else
+ {
+ $CatCount = $objCatList->NumItems();
+ foreach($objCatList->Items as $cat)
+ {
+ if($cat->Get("ParentId")==$CategoryId)
+ {
+
+ if($row==0 && strlen($attribs["_firstitemtemplate"]))
+ {
+ //echo 'Saving <b>ID</b> in <b>m_sub_cats</b>[ first ] '.$cat->UniqueId().'<br>';
+ //$GLOBALS['cat_ID'] = $cat->UniqueId();
+ $o.= $cat->ParseTemplate($attribs["_firstitemtemplate"]);
+ $parsed=1;
+ }
+ if($row==$CatCount-1 && !$parsed && strlen($attribs["_lastitemtemplate"])>0)
+ {
+ //echo 'Saving <b>ID</b> in <b>m_sub_cats</b>[ last ] '.$cat->UniqueId().'<br>';
+ //$GLOBALS['cat_ID'] = $cat->UniqueId();
+ $o .= $cat->ParseTemplate($attribs["_lastitemtemplate"]);
+ $parsed=1;
+ }
+ if(!$parsed)
+ {
+ //echo 'Saving <b>ID</b> in <b>m_sub_cats</b>[ each ] '.$cat->UniqueId().'<br>';
+ //$GLOBALS['cat_ID'] = $cat->UniqueId();
+ $o .= $cat->ParseTemplate($attribs["_itemtemplate"]);
+ }
+ $row++;
+ $i++;
+ $count++;
+ if($count>=$cat_count && $cat_count>0)
+ break;
+ }
+ }
+ }
+ unset($var_list_update["t"]);
+ SaveTagCache("kernel","m_list_cats",$attribs,m_BuildEnv(),$o);
+ return $o;
+}
+
+function LoadCatSearchResults($attribs)
+{
+ global $objSession, $objPermissions, $objCatList, $objSearchCats, $objConfig, $CountVal, $m_var_list;
+
+ $GroupList = $objSession->Get("GroupList");
+ if(strlen($GroupList))
+ $Groups = explode(",",$GroupList);
+ $acl_where = "";
+ if(@count($Groups)>0 && is_array($Groups))
+ {
+ $acl_where = array();
+ for($i=0;$i<count($Groups);$i++)
+ {
+ $g = $Groups[$i];
+ $acl_where[] = "FIND_IN_SET($g,acl) ";
+ }
+ if(count($acl_where))
+ {
+ $acl_where = "(".implode(" OR ",$acl_where).")";
+ }
+ else {
+ $acl_where = "FIND_IN_SET(0,acl)";
+ }
+ }
+ else {
+ $acl_where = "FIND_IN_SET(0,acl)";
+ }
+
+ $order_by = "EdPick DESC,Relevance DESC";
+
+ if ($objSession->GetVariable("Category_Sortfield") != "") {
+ $order_by = $objSession->GetVariable("Category_Sortfield")." ".$objSession->GetVariable("Category_Sortorder");
+ }
+
+ $CAT_VIEW = $objPermissions->GetPermId("CATEGORY.VIEW");
+ $ctable = $objCatList->SourceTable;
+ $stable = $objSession->GetSearchTable(); // $objSearchCats->SourceTable;
+ $ptable = GetTablePrefix()."PermCache";
+ $sql = "SELECT * FROM $stable INNER JOIN $ctable ON ($stable.ItemId=$ctable.CategoryId) ";
+ $sql .= "INNER JOIN $ptable ON ($ctable.CategoryId=$ptable.CategoryId) ";
+ $sql .="WHERE ItemType=1 AND Status=1 AND $acl_where AND PermId=$CAT_VIEW ORDER BY $order_by ";
+ $objSearchCats->Page = $m_var_list["p"];
+ if($objSearchCats->Page<1)
+ $objSearchCats->Page=1;
+
+ if(is_numeric($objConfig->Get($objSearchCats->PerPageVar)))
+ {
+ $Start = ($objSearchCats->Page-1)*$objConfig->Get($objSearchCats->PerPageVar);
+ $limit = "LIMIT ".$Start.",".$objConfig->Get($objSearchCats->PerPageVar);
+ }
+ else
+ $limit = NULL;
+
+ if(strlen($limit))
+ $sql .= $limit;
+
+ // echo "TEST:<BR>$sql<br>\n";
+ $objSearchCats->Query_Item($sql);
+ $where = "ItemType=1";
+
+ $Keywords = GetKeywords($objSession->GetVariable("Search_Keywords"));
+ //echo "SQL Loaded ItemCount (<b>".get_class($this).'</b>): '.$this->NumItems().'<br>';
+ for($i = 0; $i < $objSearchCats->NumItems(); $i++)
+ {
+ $objSearchCats->Items[$i]->Keywords = $Keywords;
+ }
+
+ if(is_numeric($CountVal[1]))
+ {
+ $objSearchCats->QueryItemCount = $CountVal[1];
+ }
+ else
+ {
+ $objSearchCats->QueryItemCount = QueryCount($sql);
+ $CountVal[1]= $objSearchCats->QueryItemCount;
+ }
+}
+
+/*
+ @description: Used in conjuction with m_search_list_cats. This function generates a navigation link which is
+ used to switch from a short list to a longer list. The page number is not changed.
+ If this tag is called before the list tag, this function will load the category list.
+ Generally, it is good practice to duplicate all attributes set for m_search_list_cats.
+ Any extra HTML attributes are passed to the anchor tag
+ @attrib: _Template:tpl: Template to link to
+ @attrib: _text:lang: language tag to include as text for the anchor tag
+ @attrib: _plaintext:: plain text to include as text for the anchor tag. The _text attribute takes presedence
+ if both are included.
+ @attrib: _image:: URL to an image to include inside the anchor tag.
+*/
+function m_search_cat_more($attribs = array())
+{
+ global $objSearchCats, $objConfig, $m_var_list_update;
+
+ $html_attribs = ExtraAttributes($attribs);
+ $DestTemplate = $attribs["_template"];
+
+ if($attribs["_shortlist"])
+ $objSearchList->PerPageVar = "Perpage_Category_Short";
+ if($objSearchCats->NumItems()==0)
+ {
+ LoadCatSearchResults($attribs);
+ }
+ $max = $objConfig->Get($objSearchList->PerPageVar);
+ $val = $objSearchCats->QueryItemCount;
+ if($val > $max)
+ {
+ if($attribs["_root"])
+ $attribs["_category"]=0;
+
+ $m_var_list_update["p"]=1;
+ $url = m_template_link($attribs);
+ unset($m_var_list_update["p"]);
+ $o = "<A $html_attribs HREF=\"$url\">";
+ $text = $attribs["_text"];
+ if(!strlen($text))
+ {
+ $text = $attribs["_plaintext"];
+ if(!strlen($text))
+ {
+ }
+ $o .= $text."</A>";
+ }
+ else
+ $o .= language($text);
+ if(strlen($attribs["_image"]))
+ {
+ $o .= "<IMG SRC=\"".$attribs["_image"]."\" BORDER=\"0\" alt=\"\"/>";
+ }
+ $o .= "</A>";
+ }
+ return $o;
+}
+
+/*
+ @description: Used in conjuction with l_list_cats. This function generates the page navigation
+ for the list. If this tag is called before the list tag, this function will load
+ the links. For that reason, the _ListType attribute is required if the pagnav
+ tag preceeds the l_list_links tag in the template. Generally, it is good practice to
+ duplicate all attributes set for l_list_links.
+ @attrib: _PagesToList:int: Number of pages to list (default is 10)
+ @attrib: _ShortList:bool: If set, uses the shortlist configuration value for links
+ @attrib: _label:lang: language tag to include in the output if there are pages to list. If there are no pages listed, this text will not be included (resulting in an empty output)
+ @attrib: _ListType::Determines the type of list to generate<br>
+ Possible values:<UL>
+ <LI>Category: List links from the current category (default)
+ </UL>
+
+*/
+function l_cat_pagenav($attribs = array())
+{
+ global $objCatList, $objSession;
+
+ $DestTemplate = getArrayValue($attribs,'_template');
+ $PagesToList = getArrayValue($attribs,'_pagestolist');
+ $image = getArrayValue($attribs,'_PageIcon');
+ if(!is_numeric($PagesToList))
+ $PagesToList = 10;
+
+ $CatId = getArrayValue($attribs,'_catid');
+ if(!is_numeric($CatId))
+ $CatId = $objCatList->CurrentCategoryID();
+
+ if($attribs["_shortlist"] == 1)
+ $objCatList->PerPageVar = "Perpage_Category_Short";
+
+ $ListType = getArrayValue($attribs,'_listtype');
+ if(!strlen($ListType))
+ $ListType="category";
+/*
+ if($objLinkList->ListType != $ListType) {
+ LoadLinkList($attribs);
+ }
+*/
+ $o = $objCatList->GetPageLinkList($DestTemplate, '', 10, true, ExtraAttributes($attribs) );
+ if (strlen($image)) {
+ $o_i = '<img src="'.$image.'" width="9" height="12" alt="">&nbsp;';
+ }
+ if(strlen($o) && strlen($attribs["_label"]))
+ $o = $o_i.language($attribs["_label"]).' '.$o;
+ return $o;
+}
+
+/*
+ @description: Used in conjuction with m_search_list_cats. This function generates the page navigation
+ for the list. If this tag is called before the list tag, this function will load
+ the category list. Generally, it is good practice to duplicate all attributes set for
+ m_search_list_cats.
+ @attrib: _PagesToList:int: Number of pages to list (default is 10)
+ @attrib: _label:lang: language tag to include in the output if there are pages to list. If there are no pages
+ listed, this text will not be included (resulting in an empty output)
+*/
+function m_search_cat_pagenav($attribs = array())
+{
+ global $objSearchCats, $objConfig, $objCatList, $objSession;
+
+ $DestTemplate = $attribs["_template"];
+ $PagesToList = $attribs["_pagestolist"];
+ if(!is_numeric($PagesToList))
+ $PagesToList = 10;
+
+ $CatId = $attribs["_catid"];
+ if(!is_numeric($CatId))
+ $CatId = $objCatList->CurrentCategoryID();
+
+ $objSearchCats->PerPageVar = "Perpage_Category";
+ if($attribs["_shortlist"])
+ $objSearchCats->PerPageVar = "Perpage_Category_Short";
+ if($objSearchCats->NumItems()==0)
+ {
+ LoadCatSearchResults($attribs);
+ }
+ $o = $objSearchCats->GetPageLinkList($DestTemplate, '', 10, true, ExtraAttributes($attribs));
+ if(strlen($o) && strlen($attribs["_label"]))
+ $o = language($attribs["_label"]).' '.$o;
+ return $o;
+}
+
+/*
+ @description: List all categories matched in a search
+ @attrib: _columns:int: Numver of columns to display the categories in (defaults to 1)
+ @attrib: _maxlistcount:int: Maximum number of categories to list
+ @attrib: _ShortList:bool: If set, the Perpage_Category_Short setting is used instead of Perpage_Category
+ @attrib: _FirstItemTemplate:tpl: Template used for the first category listed
+ @attrib: _LastItemTemplate:tpl: Template used for the last category listed
+ @attrib: _ItemTemplate:tpl: default template used for category list items
+ @attrib: _NoTable:bool: If set to 1, the categories will not be listed in a table. If a table is used, all HTML attributes are passed to the TABLE tag
+ @example: <inp:m_search_list_cats _NoTable="1" _ItemTemplate="category_search_results_element" />
+*/
+function m_search_list_cats($attribs = array())
+{
+ global $var_list, $objConfig, $objSession, $objCatList, $var_list_update, $content_set,
+ $objSearchCats, $objPermissions, $m_var_list;
+
+ if(!is_object($objSearchCats))
+ {
+ $objSearchCats = new clsCatList();
+ $objSearchCats->SourceTable = $objSession->GetSessionTable('Search'); //"ses_".$objSession->GetSessionKey()."_Search"
+ $objSearchCats->Clear();
+ }
+ $objSearchCats->PerPageVar = "Perpage_Category";
+ if($attribs["_shortlist"])
+ {
+ $objSearchCats->Page=1;
+ $m_var_list["p"] = 1;
+ $objSearchCats->PerPageVar = "Perpage_Category_Short";
+ }
+
+ $keywords = $objSession->GetVariable("Search_Keywords"); // for using in all this func branches
+
+ if($objSearchCats->NumItems()==0)
+ {
+ LoadCatSearchResults($attribs);
+ //echo "Cat count: ". $objSearchCats->QueryItemCount;
+ $ret = 0;
+ if ($keywords) {
+ foreach ($objSearchCats->Items as $cat) {
+
+ if (strstr(strip_tags(strtolower($cat->Data[$cat->TitleField])), strtolower($_POST['keywords'])) || strstr(strip_tags(strtolower($cat->Data[$cat->DescriptionField])), strtolower($_POST['keywords']))) {
+ $ret++;
+ }
+ }
+ }
+ else {
+ $ret = $objSearchCats->QueryItemCount;
+ }
+ if ($ret == 0) //if ($objSearchCats->NumItems() == 0)
+ {
+ $content_set = 0;
+ return language("lu_no_categories");
+ }
+ }
+
+ $html_attr = ExtraAttributes($attribs);
+ $cols = $attribs["_columns"];
+ if($cols<1)
+ $cols =1;
+ $cat_count = (int)$attribs["_maxlistcount"];
+ /* validation */
+ if(strlen($attribs["_itemtemplate"])==0)
+ {
+ $content_set = 0;
+ return "ERROR -1";
+ }
+
+ $o="";
+ $notable = $attribs["_notable"];
+
+ $max_categories = $objConfig->Get($objSearchCats->PerPageVar);
+ $count=0;
+ $row=0;
+ $var_list_update["t"] = $var_list["t"];
+
+ if(!$notable)
+ {
+ $per_row = ceil($objCatList->NumItems()/$cols);
+ $o = "<TABLE $html_attr><TR CLASS=\"m_list_cats\">";
+ $o .= "<TD valign=\"top\">";
+ foreach($objSearchCats->Items as $cat)
+ {
+ $parsed=0;
+ if($count==$per_row)
+ {
+ $o .= "</TD><TD valign=\"top\">";
+ $count=0;
+ }
+ if($row==0 && strlen($attribs["_firstitemtemplate"]))
+ {
+ $o.= $cat->ParseTemplate($attribs["_firstitemtemplate"]);
+ $parsed=1;
+ }
+ if($row==$objSearchCats->NumItems()-1 && !$parsed && strlen($attribs["_lastitemtemplate"])>0)
+ {
+ $o .= $cat->ParseTemplate($attribs["_lastitemtemplate"]);
+ $parsed=1;
+ }
+ if(!$parsed)
+ $o.= $cat->ParseTemplate($attribs["_itemtemplate"]);
+ $count++;
+ }
+ if($count != $per_row)
+ $o .= "</TD>";
+ $o .= "\n</tr></table>\n";
+ }
+ else
+ {
+ //echo "<pre>"; print_r($objSearchCats->Items); echo "</pre>";
+ foreach($objSearchCats->Items as $cat)
+ {
+ //$cat->Keywords = GetKeywords($objSession->GetVariable("Search_Keywords"));
+/* $keywords_found = strstr( strip_tags(strtolower($cat->Data[$objCatList->TitleField])), strtolower($keywords)) || strstr(strip_tags(strtolower($cat->Data[$cat->DescriptionField])), strtolower($keywords));
+ if(!$keywords) $keywords_found = true;
+ if ($keywords_found) {*/
+ if($row==0 && strlen($attribs["_firstitemtemplate"]))
+ {
+ $o.= $cat->ParseTemplate($attribs["_firstitemtemplate"]);
+ $parsed=1;
+ }
+ if($row==$objSearchCats->NumItems()-1 && !$parsed && strlen($attribs["_lastitemtemplate"])>0)
+ {
+ $o .= $cat->ParseTemplate($attribs["_lastitemtemplate"]);
+ $parsed=1;
+ }
+ if(!$parsed)
+ $o.= $cat->ParseTemplate($attribs["_itemtemplate"]);
+ $row++;
+ $i++;
+ $count++;
+ if($count == $max_categories) break;
+// }
+ }
+ }
+ unset($var_list_update["t"]);
+ return $o;
+}
+
+/*
+ @description: Parse a template based on the current advanced search type
+ @attrib:_TypeSelect:tpl:Template to parse if no item type has been selected
+ @attrib:_ItemSelect:tpl:Template to parse if an item type has been selected to search
+*/
+function m_advsearch_include($attribs)
+{
+ global $objTemplate;
+
+ $TypeSelectTemplate = $attribs["_typeselect"];
+ $ItemTemplate = $attribs["_itemselect"];
+ if((strlen($_GET["type"])>0 || $_POST["itemtype"]>0) && ($_GET["Action"]=="m_advsearch_type" || $_GET["Action"]=="m_adv_search"))
+ {
+ $o = $objTemplate->ParseTemplate($ItemTemplate);
+ }
+ else
+ $o = $objTemplate->ParseTemplate($TypeSelectTemplate);
+ return $o;
+}
+
+/*
+ @description: Returns the name of the item type currently being advanced searched
+ @attrib::_plaintext:bool:If set, simply returns the name of the item if not, builds a language tag (lu_searchtitle_[name])
+*/
+function m_advsearch_type($attribs)
+{
+ global $objItemTypes;
+
+ if($_GET["Action"]=="m_advsearch_type")
+ {
+ $ItemType = $_POST["itemtype"];
+ }
+ elseif($_GET["Action"]=="m_adv_search")
+ $ItemType = $_GET["type"];
+
+ $o = "";
+ if((int)$ItemType>0)
+ {
+ $Item = $objItemTypes->GetItem($ItemType);
+ if(is_object($Item))
+ {
+ $name = strtolower($Item->Get("ItemName"));
+ if($attribs["_plaintext"])
+ {
+ $o .= $name;
+ }
+ else
+ $o = language("lu_searchtitle_".strtolower($name));
+ }
+ }
+ return $o;
+}
+
+/*
+ @description: Lists advanced search fields for the selected item type
+ @attrib: _FirstItemTemplate:tpl: Template used for the first field listed
+ @attrib: _LastItemTemplate:tpl: Template used for the last field listed
+ @attrib: _AltLastItemTemplate:tpl: Altername Template used for the last field listed
+ @attrib: _ItemTemplate:tpl: default template used for field list items
+ @attrib: _AltTemplate:tpl: Alternate template used for field list items
+*/
+function m_advsearch_fields($attribs)
+{
+ global $objItemTypes, $objTemplate, $objSearchConfig;
+
+ if(!is_object($objSearchConfig))
+ $objSearchConfig = new clsSearchConfigList();
+
+ if($_GET["Action"]=="m_advsearch_type")
+ {
+ $ItemType = $_POST["itemtype"];
+ }
+ elseif($_GET["Action"]=="m_adv_search")
+ $ItemType = $_GET["type"];
+
+ $o = "";
+ if((int)$ItemType>0)
+ {
+ $Item = $objItemTypes->GetItem($ItemType);
+ if(is_object($Item))
+ {
+ $name = strtolower($Item->Get("ItemName"));
+
+ $table = $Item->Get("SourceTable");
+ //$sql = "SELECT * FROM ".$objSearchConfig->SourceTable." WHERE TableName='$table' AND AdvancedSearch=1 ORDER BY DisplayOrder";
+ $sql = "SELECT sc.* FROM ".$objSearchConfig->SourceTable." AS sc LEFT JOIN ".GetTablePrefix()."CustomField AS cf ON sc.CustomFieldId = cf.CustomFieldId WHERE (TableName='$table' OR ((TableName='".GetTablePrefix()."CustomField' OR TableName='CustomField') AND cf.Type = $ItemType)) AND AdvancedSearch=1 ORDER BY sc.DisplayOrder";
+ $objSearchConfig->Query_Item($sql);
+ $row=0;
+ if(is_array($objSearchConfig->Items))
+ {
+ $ItemCount = count($objSearchConfig->Items);
+ foreach($objSearchConfig->Items as $s)
+ {
+ $even = (($row+1) % 2 == 0);
+ $parsed=0;
+ if($row==0 && strlen($attribs["_firstitemtemplate"]))
+ {
+ $o .= $s->ParseTemplate($attribs["_firstitemtemplate"]);
+ $parsed=1;
+ }
+ if($row==$ItemCount-1 && $even && !$parsed && strlen($attribs["_altlastitemtemplate"])>0)
+ {
+ $o .= $s->ParseTemplate($attribs["_altlastitemtemplate"]);
+ $parsed=1;
+ }
+ if($row==$ItemCount-1 && !$parsed && strlen($attribs["_lastitemtemplate"])>0)
+ {
+ $o .= $s->ParseTemplate($attribs["_lastitemtemplate"]);
+ $parsed=1;
+ }
+ if(!$parsed)
+ {
+ if($even && strlen($attribs["_altitemtemplate"])>0)
+ {
+ $o .= $s->ParseTemplate($attribs["_altitemtemplate"]);
+ }
+ else
+ $o .= $s->ParseTemplate($attribs["_itemtemplate"]);
+ }
+ $row++;
+
+ }
+ }
+ }
+ }
+ return $o;
+}
+
+/*
+ @description: create a link to a template based on attributes passed into the tag. All extra HTML attributes
+ are passed to the anchor tag created.
+ @attrib: _Template:tpl: Template to link to. Just the template name is listed here. (ex: use "index" instead if "inlink/index")
+ @attrib: _Module:: Module being linked to (ie In-Bulletin or In-News or In-Link)
+ @attrib: _perm:: A list of permissions to check. If the user has any of the the permissions in the list,
+ the link will be generated. (If the _DeniedTemplate attribute is set, this template is used
+ and the link is created.)
+ @attrib: _DeniedTemplate:tpl: This template is used if the user does not have a permission listed in the _perm
+ attribute. If this attirbute is not included and the user does not have access,
+ nothing is returned. (The link is not created.)
+ @attrib: _Root:bool: If set, the current category is set to the module's root category
+ @attrib: _text:lang: language tag to include as text for the anchor tag
+ @attrib: _plaintext:: plain text to include as text for the anchor tag. The _text attribute takes presedence
+ if both are included.
+ @attrib: _image:: URL to an image to include inside the anchor tag.
+ @attrib: _image_actions:: Image events.
+*/
+function m_module_link($attribs = array())
+{
+ global $objCatList, $objSession;
+
+ $permission = getArrayValue($attribs,'_perm');
+ $o = "";
+ $tpath = GetModuleArray("template");
+ if(strlen($permission))
+ {
+ $perms = explode(",",$permission);
+ $hasperm = FALSE;
+ for($x=0;$x<count($perms);$x++)
+ {
+ if($objSession->HasCatPermission($perms[$x]))
+ {
+ $hasperm = TRUE;
+ break;
+ }
+ }
+ }
+ else
+ $hasperm = TRUE;
+ if(!$hasperm && getArrayValue($attribs,'_deniedtemplate') )
+ {
+ $hasperm = TRUE;
+ $attribs["_template"]=$attribs["_deniedtemplate"];
+ }
+ if($hasperm)
+ {
+ $module = $attribs["_module"];
+ if(ModuleEnabled($module))
+ {
+ $t = $tpath[$attribs["_module"]];
+ $t .= $attribs["_template"];
+ $attribs["_template"] = $t;
+ $html_attr = ExtraAttributes($attribs);
+ if($attribs["_root"])
+ {
+ $func = ModuleTagPrefix($module)."_root_link";
+ if(function_exists($func))
+ {
+ $url = $func($attribs);
+ }
+ else
+ $url = m_template_link($attribs);
+ }
+ else
+ $url = m_template_link($attribs);
+ $o = "<A $html_attr HREF=\"";
+ $o .= $url;
+ $o .= "\"> ";
+ $text = getArrayValue($attribs,'_text');
+ if(!strlen($text))
+ {
+ $text = getArrayValue($attribs,'_plaintext');
+ if(!strlen($text))
+ {
+ if(strlen($attribs["_image"]))
+ {
+ $text = "<IMG SRC=\"".$attribs["_image"]."\" BORDER=\"0\" alt=\"\">";
+ }
+ }
+ $o .= $text."</A>";
+ }
+ else
+ $o .= language($text)."</A>";
+ }
+ else
+ {
+ $o = "";
+ }
+ }
+ return $o;
+}
+/*
+ @description: create a link to a template based on attributes passed into the tag. All extra HTML attributes
+ are passed to the anchor tag created.
+ @attrib: _Template:tpl: Template to link to. Just the template name is listed here. (ex: use "index" instead if "inlink/index")
+ @attrib: _perm:: A list of permissions to check. If the user has any of the the permissions in the list,
+ the link will be generated. (If the _DeniedTemplate attribute is set, this template is used
+ and the link is created.)
+ @attrib: _DeniedTemplate:tpl: This template is used if the user does not have a permission listed in the _perm
+ attribute. If this attirbute is not included and the user does not have access,
+ nothing is returned. (The link is not created.)
+ @attrib: _text:lang: language tag to include as text for the anchor tag
+ @attrib: _plaintext:: plain text to include as text for the anchor tag. The _text attribute takes presedence
+ if both are included.
+ @attrib: _image:: URL to an image to include inside the anchor tag.
+*/
+function m_permission_link($attribs = array())
+{
+ global $objCatList, $objSession;
+
+ $permission = $attribs["_perm"];
+ $o = "";
+ if(strlen($permission))
+ {
+ $perms = explode(",",$permission);
+ $hasperm = FALSE;
+ for($x=0;$x<count($perms);$x++)
+ {
+ if($objSession->HasCatPermission($perms[$x]))
+ {
+ $hasperm = TRUE;
+ break;
+ }
+ }
+ }
+ else
+ $hasperm = TRUE;
+ if(!$hasperm && strlen($attribs["_deniedtemplate"])>0)
+ {
+ $hasperm = TRUE;
+ $attribs["_template"]=$attribs["_deniedtemplate"];
+ }
+ if($hasperm)
+ {
+ $url = m_template_link($attribs);
+ $o = "<A $html_attr HREF=\"";
+ $o .= $url;
+ $o .= "\"> ";
+ $text = $attribs["_text"];
+ if(!strlen($text))
+ {
+ $text = $attribs["_plaintext"];
+ if(!strlen($text))
+ {
+ if(strlen($attribs["_image"]))
+ {
+ $text = "<IMG SRC=\"".$attribs["_image"]."\" BORDER=\"0\" alt=\"\">";
+ }
+ }
+ $o .= $text."</A>";
+ }
+ else
+ $o .= language($text)."</A>";
+ }
+ else
+ {
+ $o = "";
+ }
+
+ return $o;
+}
+
+function m_confirm_password_link($attribs = array())
+{
+ global $m_var_list_update, $var_list_update, $objSession, $objConfig;
+
+ $template = "forgotpw_reset_result";
+ // $user = $objSession->Get("tmp_user_id").";".$objSession->Get("tmp_email");
+ $tmp_user_id = $objSession->Get("tmp_user_id");
+
+ $conn = &GetADODBConnection();
+ $code = md5(GenerateCode());
+ $sql = 'UPDATE '.GetTablePrefix().'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.adodb_mktime().' WHERE PortalUserId='.$tmp_user_id;
+
+ $query = "&user_key=".$code."&Action=m_resetpw";
+
+ $conn->Execute($sql);
+
+ $var_list_update["t"] = $template;
+
+ $ret = ($attribs["_secure"]?"https://":"http://").ThisDomain().$objConfig->Get("Site_Path")."index.php?env=".BuildEnv().$query;
+
+ return $ret;
+}
+
+/**
+ * Returns result of password reset confirmation
+ * code validation as appropriate phrase
+ *
+ * @return string
+ * @example <inp:m_codevalidationresult />
+ */
+function m_codevalidationresult($attribs=Array())
+{
+ global $objSession;
+ $result_phrase = $objSession->GetVariable('codevalidationresult');
+ return $result_phrase ? language($result_phrase) : '';
+}
+
+/*
+ @description: Create a link to a template.
+ @attrib: _Template:tpl: Template to link to (ex: "inbulletin/post_list")
+ @attrib: _Query:str: Extra query sring to be added to link URL (ex: "&test=test")
+ @attrib: _Category:int: Set the current category to this ID. If not set, the current category is unchanged
+ @attrib: _anchor:: If included, a local anchor (#) is added. (ex: _anchor="top" results in <A HREF="..#top">)
+ @attrib: _Root:bool:If set, gets module root category id
+ @attrib: _Module:str:Module Name
+ @attrib: _Relative:bool: Is set, creates an relative url url (../..address)
+ @example: <a href="<inp:m_template_link _Template="index" _Category=0 />"><inp:m_language _Phrase="lu_home" /></a>
+*/
+function m_template_link($attribs = array())
+{
+ global $var_list, $var_list_update, $m_var_list_update, $objCatList;
+
+ $var_list_update['t'] = getArrayValue($attribs,'_template') ? $attribs['_template'] : $var_list['t'];
+
+ $query_string = trim( getArrayValue($attribs,'_query') );
+ $url_params = $query_string ? ExtractParams($query_string) : Array();
+
+ $cat = getArrayValue($attribs, '_category');
+
+ if($cat !== false) $m_var_list_update['cat'] = ($cat == 'NULL') ? 0 : $cat;
+ if( getArrayValue($attribs,'_anchor') ) $url_params['anchor'] = $attribs['_anchor'];
+
+ $ret = HREF_Wrapper('', $url_params);
+
+ unset( $var_list_update['t'] );
+ if($cat) unset( $m_var_list_update['cat'] );
+ return $ret;
+}
+
+/*
+ @description: create a link to a template based on user permissions. All extra HTML attributes are passed to the anchor tag created.
+ @attrib: _Template:tpl: Template to link to if the user has access
+ @attrib: _DeniedTemplate:tpl: This template is used if the user does not have a permission listed in the _perm
+ attribute. If this attirbute is not included and the user does not have access,
+ the "login" template is used.
+ @attrib: _perm:: A list of permissions to check. If the user has any of the the permissions in the list,
+ the link will be generated. (If the _DeniedTemplate attribute is set, this template is used
+ and the link is created.)
+ @attrib: _System:bool: Set this attribute if one of the permissions in the list is a system permission (ie: LOGIN)
+ @attrib: _Category:int: Set the current category to this ID. If not set, the current category is unchanged
+ @example: <a href="<inp:m_access_template_link _Template="my_account" _DeniedTemplate="login" _Perm="login" />"><inp:m_language _Phrase="lu_myaccount" /></A>
+*/
+function m_access_template_link($attribs = array(), $Permission="")
+{
+ global $var_list, $var_list_update, $m_var_list_update, $objCatList, $objSession;
+
+ $cat = getArrayValue($attribs,'_category');
+ if(strlen($cat))
+ {
+ if($cat=="NULL")
+ $cat = 0;
+ }
+ else
+ $cat = $objCatList->CurrentCategoryID();
+
+ if(!strlen($Permission))
+ {
+ $Permission = strtoupper($attribs["_perm"]);
+ }
+
+ $o = "";
+ $hasperm = FALSE;
+ if(strlen($Permission))
+ {
+ $perms = explode(",",$Permission);
+
+ for($x=0;$x<count($perms);$x++)
+ {
+ if($objSession->HasCatPermission(trim($perms[$x]),$cat))
+ {
+ $hasperm = TRUE;
+ break;
+ }
+ }
+
+ if(!$hasperm && $attribs["_system"])
+ {
+ for($x=0;$x<count($perms);$x++)
+ {
+ if($objSession->HasSystemPermission(trim($perms[$x])))
+ {
+ $hasperm = TRUE;
+ break;
+ }
+ }
+ }
+ }
+
+ $url_params = Array('dest' => '');
+
+ $access = $attribs["_template"];
+ $denied = $attribs["_deniedtemplate"];
+ if(!strlen($denied))
+ $denied = "login";
+
+ $m_var_list_update["cat"] = $cat;
+ if($hasperm)
+ {
+ $template = $access;
+ if(!strlen($template))
+ $template = $var_list["t"];
+ $var_list_update["t"] = $template;
+ }
+ else
+ {
+ $template = $denied;
+ if(!strlen($template))
+ $template = $var_list["t"];
+ if($template == "login")
+ {
+ $url_params['dest'] = $access;
+ }
+ $var_list_update["t"] = $template;
+ }
+
+ if( !$url_params['dest'] ) unset($url_params['dest']);
+ $ret = HREF_Wrapper('', $url_params);
+
+ unset($var_list_update["t"]);
+
+ return $ret;
+}
+
+/*
+ @description: returns a text based on user permissions. Text from inside of the tag will be returned if text attributes are not specified and user has permissions to category, or if _NoPerm attribute set to 1 and user doesn't have permissions. Otherwise entire section will be excluded.
+ @attrib: _Text:lang: Template to link to if the user has access
+ @attrib: _PlainText:: This template is used if the user does not have a permission listed in the _perm attribute. If this attirbute is not included and the user does not have access, the "login" template is used.
+ @attrib: _DenyText:lang: Template to link to if the user has access
+ @attrib: _PlainDenyText:: This exact text is used if the user does not have a permission listed in the _perm attribute and _DenyText attribute is not set.
+ @attrib: _perm:: A list of permissions to check. If the user has any of the the permissions in the list, the link will be generated.
+ @attrib: _System:bool: Set this attribute if one of the permissions in the list is a system permission (ie: LOGIN)
+ @attrib: _Category:int: Set the current category to this ID. If not set, the current category is unchanged
+ @attrib: _MatchAllPerms:int: Checks for all listed Permissions to be TRUE. Note: this attribute is rarely used.
+ @attrib: _NoPerm:int: The whole tag will return inner text if user has no permissions and attribute set to 1. Default value is 0.
+ @example: <inp:m_perm_text _Text="!lu_allow_language_tag!" _PlainText="Just a text" _DenyText="!lu_deny_language_tag!" _PlainDenyText="Just a plain text" _Perm="login" _MatchAllPerms="1" _NoPerm="0">Some HTML here!</inp>
+*/
+function m_perm_text($attribs = array())
+{
+ global $var_list, $var_list_update, $m_var_list_update, $objCatList, $objSession;
+
+ $cat = getArrayValue($attribs,'_category');
+ if(strlen($cat))
+ {
+ if($cat=="NULL")
+ $cat = 0;
+ }
+ else
+ $cat = $objCatList->CurrentCategoryID();
+
+ //if(!strlen($Permission))
+ $Permission = strtoupper($attribs["_perm"]);
+
+ $o = "";
+ $hasperm = FALSE;
+
+ $count = 0;
+
+ if(strlen($Permission))
+ {
+ $perms = explode(",",$Permission);
+
+ for($x=0;$x<count($perms);$x++)
+ {
+ $_AllPermsCount[$count] = 0;
+ if($objSession->HasCatPermission($perms[$x],$cat))
+ {
+ $hasperm = TRUE;
+ $_AllPermsCount[$count] = 1;
+// break;
+ }
+
+ $count++;
+ }
+
+ if( !$hasperm && getArrayValue($attribs,'_system') )
+ {
+ for($x=0; $x<count($perms); $x++)
+ {
+ $_AllPermsCount[$count] = 0;
+ if($objSession->HasSystemPermission($perms[$x]))
+ {
+ $hasperm = TRUE;
+ $_AllPermsCount[$count] = 1;
+// break;
+ }
+
+ $count++;
+ }
+ }
+ }
+
+ if ((int)getArrayValue($attribs,'_matchallperms'))
+ {
+ if (count($_AllPermsCount) != array_sum($_AllPermsCount))
+ $hasperm = FALSE;
+ }
+
+ $text = getArrayValue($attribs,'_text');
+ $plaintext = getArrayValue($attribs,'_plaintext');
+ $denytext = getArrayValue($attribs,'_denytext');
+ $plaindenytext = getArrayValue($attribs,'_plaindenytext');
+ $nopermissions_status = (int)getArrayValue($attribs,'_noperm')? 1 : 0;
+
+ //if(!strlen($denied)) $denied = "login";
+
+ if (!$nopermissions_status)
+ {
+ if ($hasperm)
+ {
+ if (strlen($text) || strlen($plaintext))
+ {
+ $ret = strlen($text)? language($text) : $plaintext;
+ }
+ else
+ {
+ $ret = "1";
+ }
+ }
+ else
+ {
+ $ret = strlen($denytext)? language($denytext) : $plaindenytext;
+ }
+ }
+ elseif (!$hasperm)
+ {
+ $ret = "1";
+ }
+
+ return $ret;
+}
+
+
+/*
+ @description: Returns the error string associated with a permission
+*/
+function m_permission_error($attribs = array())
+{
+ global $objPermissions;
+
+ $ret = "";
+ $perm = strtoupper($_GET["error"]);
+ if(strlen($perm))
+ {
+ $ado = &GetADODBConnection();
+ $sql = "SELECT * FROM ".GetTablePrefix()."PermissionConfig WHERE PermissionName ='$perm'";
+ $rs = $ado->Execute($sql);
+ if($rs && !$rs->EOF)
+ {
+ $data = $rs->fields;
+ $error_tag = $data["ErrorMessage"];
+ }
+ else
+ $error_tag = "lu_unknown_error";
+ $ret = language($error_tag);
+ }
+ return $ret;
+}
+
+/*
+ @description: Returns the error text encountered when parsing templates
+*/
+function m_template_error($attribs = array())
+{
+ global $objTemplate;
+
+ $ret = "";
+ if($objTemplate->ErrorNo<0)
+ {
+ $ret = $objTemplate->ErrorStr;
+ }
+ return $ret;
+}
+
+/*
+ @description: Creates a category navigation bar
+ @attrib: _Template:tpl: template to use for navigation links
+ @attrib: _RootTemplate:bool: If set, this template is linked to for the root category
+ @attrib: _LinkCurrent:bool: If set, the last (current) category is linked. Otherwise the current category is simply displayed
+ @attrib: _Separator:: text to display between levels of the navigation bar
+ @attrib: _Root:: Root category configuration variable to use. (ex: Link for In-Link's root category) If not set, the system root is used
+ @example: <inp:m_navbar _RootTemplate="index" _Template="inbulletin/index" _LinkCurrent="1" _separator=" &gt; " />
+*/
+function m_navbar($attribs = array())
+{
+ global $m_var_list_update, $var_list, $objCatList, $objConfig, $objModules;
+
+ $separator = getArrayValue($attribs, '_separator');
+ if(!$separator) $separator = "<span class=\"NAV_ARROW\"> > </span>";
+
+ $admin = (int)getArrayValue($attribs, 'admin');
+
+ $t = getArrayValue($attribs, '_template');
+ $LinkLeafNode = getArrayValue($attribs, '_linkcurrent');
+ $catid = (int)getArrayValue($attribs, '_catid');
+
+ if( getArrayValue($attribs, '_root') )
+ {
+ $var = getArrayValue($attribs, '_root')."_Root";
+ $Root = (int)$objConfig->Get($var);
+ }
+ else
+ $Root = 0;
+
+ $RootTemplate = getArrayValue($attribs, '_roottemplate');
+ if($RootTemplate === false) $RootTemplate = '';
+
+ $Module = getArrayValue($attribs, '_module');
+ $ModuleRootTemplate = '';
+ if($Module)
+ {
+ $ModuleRootCat = $objModules->GetModuleRoot($Module);
+ if($ModuleRootCat>0)
+ {
+ $modkey = "_moduleroottemplate";
+ $ModuleRootTemplate = getArrayValue($attribs, $modkey);
+ }
+ else
+ $ModuleRootTemplate="";
+ }
+ else
+ $ModuleRootCat = 0;
+
+ if(!$catid)
+ $catid = $objCatList->CurrentCategoryID();
+
+ $ret = $objCatList->cat_navbar($admin, $catid, $t, $separator,$LinkLeafNode,$Root,$RootTemplate,$ModuleRootCat,$ModuleRootTemplate);
+ return $ret;
+}
+
+/*
+ @description: Parse a category field and return the value
+ @attrib: _Field:: Category field to parse
+ @attrib: _CatId:int: Category ID to parse (uses current category if not set)
+ @attrib: _StripHTML:bool: if set, all HTML is removed from the output
+*/
+function m_category_field($attribs)
+{
+ global $objCatList;
+
+ $ret = "";
+ $catid = (int)getArrayValue($attribs,'_catid');
+ $field = $attribs["_field"];
+ if(!$catid)
+ $catid = $objCatList->CurrentCategoryID();
+
+ if(strlen($field))
+ {
+ $cat =& $objCatList->GetCategory($catid);
+ if(is_object($cat))
+ {
+ $element = new clsHtmlTag();
+ $element->name=$cat->TagPrefix;
+ $element->attributes = $attribs;
+ $ret = $cat->ParseObject($element);
+ }
+ }
+ if(getArrayValue($attribs,'_striphtml'))
+ $ret = strip_tags($ret);
+ return $ret;
+}
+
+/*
+ @description: returns the date of the last modification to a category
+ @attrib: _Part:: part of the date to display
+ @attrib: _Local:bool: If set, only subcategories of the current category is checked
+ @example: <inp:m_category_modified />
+*/
+function m_category_modified($attribs)
+{
+ global $objConfig, $objCatList;
+
+ $ado = &GetADODBConnection();
+ $ret='';
+ if(getArrayValue($attribs,'_local') && $objCatList->CurrentCategoryID() != 0)
+ {
+ $c =& $objCatList->GetItem($objCatList->CurrentCategoryID());
+ $catlist = $c->GetSubCatIds();
+
+ $catwhere = "CategoryId IN (".explode(",",$catlist).")";
+ $sql = "SELECT MAX(Modified) as ModDate,MAX(CreatedOn) as NewDate FROM ".GetTablePrefix()."Category ";
+ $sql .= "INNER JOIN ".GetTablePrefix()."CategoryItems ON (".GetTablePrefix()."Category.ResourceId=".GetTablePrefix()."CategoryItems.ItemResourceId) ";
+ $sql .= "WHERE $catwhere LIMIT 1";
+ }
+ else
+ {
+ $sql = "SELECT MAX(Modified) as ModDate FROM ".GetTablePrefix()."Category LIMIT 1";
+ }
+ $rs = $ado->Execute($sql);
+ if($rs && ! $rs->EOF)
+ {
+ $mod = $rs->fields["ModDate"];
+ if($mod)
+ {
+ $part = strtolower(getArrayValue($attribs,'_part'));
+ $ret = $part?ExtractDatePart($part,$mod):LangDate($mod);
+ }
+ }
+ return $ret;
+}
+
+/*
+ @description: creates LINK tags to include all module style sheets
+ @attrib: _Modules:: Accepts a comma-separated list of modules to include (ie: "In-Link, In-News, In-Bulletin")
+ @attrib: _*css:none: Each module may set a custom-named stylesheet. For example, for In-Link the attribute would be _In-Linkcss="..".
+ If a module does not have a *css attribute, the default (style.css) is assumed.
+ @example: <inp:m_module_stylesheets _Modules="In-Portal,In-News,In-Bulletin,In-Link" _In-PortalCss="incs/inportal_main.css" />
+*/
+function m_module_stylesheets($attribs)
+{
+ global $TemplateRoot;
+
+ $require_css = explode(',', trim($attribs['_modules']) );
+ $tpath = GetModuleArray('template');
+ $ret = '';
+
+ foreach($require_css as $module_name)
+ {
+ $css_attr = '_'.strtolower($module_name).'css';
+ $mod_css = getArrayValue($attribs,$css_attr) ? $attribs[$css_attr] : 'style.css';
+ $file = $TemplateRoot.getArrayValue($tpath,$module_name).$mod_css;
+ if( file_exists($file) )
+ {
+ $ret .= '<link rel="stylesheet" href="'.$tpath[$module_name].$mod_css.'" type="text/css" />'."\n";
+ }
+ }
+ return $ret;
+}
+
+/*
+ @description: lists items related to a category
+ @attrib:CatId:int: Category ID of category, or current category if not set
+ @attrib:_ListItem: Comma-separated list of item types (ie: Link, Topic, Category, News) The items are listed in the order this list provides, then by priority.
+ Each item should have its own template passed in as an attribute (_{ItemType}Template)
+*/
+function m_related_items($attribs)
+{
+ global $objItemTypes, $objCatList, $content_set, $CatRelations;
+ static $Related;
+
+ $cat = getArrayValue($attribs,'_catid');
+ if(!is_numeric($cat))
+ {
+ $cat = $objCatList->CurrentCategoryID();
+ }
+ $c =& $objCatList->GetCategory($cat);
+ $data_sent=0;
+ if(is_object($c))
+ {
+ $ResourceId = $c->Get("ResourceId");
+ $IncludeList = explode(",",trim(strtolower($attribs["_listitems"])));
+ $o = "";
+
+ if(!is_object($CatRelations))
+ {
+ $CatRelations = new clsMultiTypeList();
+ LoadRelatedItems($Related, $CatRelations,$c->Get("ResourceId"));
+ }
+
+ if($CatRelations->NumItems()>0)
+ {
+ for($inc=0;$inc<count($IncludeList);$inc++)
+ {
+ $t_attr = "_".$IncludeList[$inc]."template";
+ $t = $attribs[$t_attr];
+ $item_type = $IncludeList[$inc];
+
+ if(strlen($item_type))
+ {
+ $objType = $objItemTypes->GetTypeByName($item_type);
+ if(is_object($objType))
+ {
+ foreach($CatRelations->Items as $item)
+ {
+ if(is_object($item))
+ {
+ if(strtolower($objType->Get("ItemName")) == strtolower($item_type) && $item->type==$objType->Get("ItemType"))
+ {
+ if(strlen($item->BasePermissionName))
+ {
+ $perm = $item->BasePermissionName.".VIEW";
+ $haspem = $objSession->HasCatPermission($perm,$item->Get("CategoryId"));
+ }
+ else
+ $hasperm = 1;
+
+ if($hasperm)
+ {
+ $data_sent =1;
+ $classname = $objType->Get("ClassName");
+ if(strlen($classname))
+ {
+ $l = new $classname;
+ $l->Data = $item->Data;
+ $o .= $l->ParseTemplate($t);
+ }
+ }
+ }
+ }
+ $item = NULL;
+ }
+ }
+ else
+ echo $item_type." not found <br>\n";
+ }
+ }
+ if($data_sent)
+ {
+ return $o;
+ }
+ else
+ {
+ $content_set=0;
+ return "";
+ }
+ }
+ else
+ {
+ $content_set = 0;
+ return "";
+ }
+ }
+ else
+ {
+ $content_set = 0;
+ return "";
+ }
+}
+
+/*
+ @description: Returns the number of items related to the current category
+ @attrib:_CatId:int: If set, this is the category ID to use, otherwise the current category is used
+ @attrib:_ItemType::Name of item to count. If not set, all related items are counted
+*/
+function m_related_count($attribs)
+{
+ global $objItemTypes, $objCatList, $content_set, $CatRelations;
+ $cat = getArrayValue($attribs,'_catid');
+
+ if(!is_numeric($cat))
+ {
+ $cat = $objCatList->CurrentCategoryID();
+ }
+ $c =& $objCatList->GetCategory($cat);
+ $data_sent=0;
+ //echo "Category: $cat<pre>"; print_r($c); echo " </pre>";
+ if(is_object($c))
+ {
+ $ResourceId = $c->Get("ResourceId");
+ if(!is_object($CatRelations))
+ {
+ $CatRelations = new clsMultiTypeList();
+ LoadRelatedItems($Related, $CatRelations, $c->Get("ResourceId"));
+ }
+
+ $item_type = getArrayValue($attribs,'_itemtype');
+ if(strlen($item_type))
+ {
+ $objType = $objItemTypes->GetTypeByName($item_type);
+ if(is_object($objType))
+ {
+ $TargetType = $objType->Get("ItemType");
+ }
+ else
+ $TargetType="";
+ }
+ $count=0;
+ if($CatRelations->NumItems()>0)
+ {
+ for($x=0;$x<$CatRelations->NumItems();$x++)
+ {
+ $a = $CatRelations->GetItemByIndex($x);
+ if($a->type == $TargetType || !strlen($TargetType))
+ {
+ $count++;
+ }
+ }
+ }
+ }
+ return $count;
+}
+
+/*
+ @description: Returns the MetaKeywords field for a category, or the system MetaKeywords value if the category doesn't have a value for MetaKeywords
+ @attrib: _CatId:int: Category to use (The current category is used by default)
+*/
+function m_meta_keywords($attribs = array())
+{
+ global $objCatList, $objConfig;
+
+ $application =& kApplication::Instance();
+ if ($application->isModuleEnabled('In-Edit')) {
+ $keywords = $application->ProcessTag('cms:PageInfo type="meta_keywords"');
+ if ($keywords) {
+ return $keywords;
+ }
+ }
+
+ $keywords = '';
+ $catid = (int)getArrayValue($attribs, '_catid');
+
+ if (!$catid)
+ {
+ $catid = $objCatList->CurrentCategoryID();
+ }
+
+ if ($catid)
+ {
+ $c = $objCatList->GetItem($catid);
+ $keywords = $c->Get('MetaKeywords');
+ }
+
+ if (!$keywords)
+ {
+ $keywords = $objConfig->Get('Category_MetaKey');
+ }
+ return $keywords;
+}
+
+/*
+ @description: Returns the MetaDescription field for a category, or the system MetaDescription value if the category doesn't have a value for MetaDescription
+ @attrib: _CatId:int: Category to use (The current category is used by default)
+*/
+function m_meta_description($attribs = array())
+{
+ global $objCatList, $objConfig;
+
+ $application =& kApplication::Instance();
+ if ($application->isModuleEnabled('In-Edit')) {
+ $description = $application->ProcessTag('cms:PageInfo type="meta_description"');
+ if ($description) {
+ return $description;
+ }
+ }
+
+ $description = '';
+ $catid = (int)getArrayValue($attribs, '_catid');
+ if (!$catid)
+ {
+ $catid = $objCatList->CurrentCategoryID();
+ }
+
+ if ($catid)
+ {
+ $c = $objCatList->GetItem($catid);
+ $description = $c->Get('MetaDescription');
+ }
+
+ if (!$description)
+ {
+ $description = $objConfig->Get('Category_MetaDesc');
+ }
+ return $description;
+}
+
+/*
+ @description: return the number of items in the database
+ @attrib: _ItemType:: Name of item to count
+ @attrib: _ListType:: Type of item to count (ie: favorites, editor's pick, etc)
+ @attrib: _CategoryCount:int: Limit scope to the current category
+ @attrib: _SubCats:bool: Count items in all subcategories (_CategoryCount must be set)
+ @attrib: _Today:bool: Count items added today
+ @attrib: _GroupOnly:bool: Only count items the current user can view
+ @attrib: _NoCache:bool: Count without using cache
+*/
+function m_itemcount($attribs = array())
+{
+ global $objItemTypes, $objCatList, $objSession, $objCountCache;
+
+ $Bit_None = 0;
+ $Bit_Today = 1;
+ $Bit_Owner = 2;
+ $Bit_Global = 4;
+ $Bit_SubCats=8;
+
+ if(getArrayValue($attribs,'_categorycount'))
+ {
+ $evar = m_BuildEnv();
+ }
+ else
+ $evar = "";
+
+ $cat = getArrayValue($attribs,'_catid');
+ if(!is_numeric($cat))
+ {
+ $cat = $objCatList->CurrentCategoryID();
+ }
+
+ if((int)$cat>0)
+ $c = $objCatList->GetCategory($cat);
+
+ if(is_numeric($attribs["_itemtype"]))
+ {
+ $item = $objItemTypes->GetItem($attribs["_itemtype"]);
+ }
+ else
+ $item = $objItemTypes->GetTypeByName($attribs["_itemtype"]);
+
+ $DoUpdate=0;
+
+ //echo "<pre>"; print_r($item); echo "</pre>";
+
+ $ExtraId="";
+
+ if(is_object($item))
+ {
+ if($item->Get("ItemType")==1) /* counting categories */
+ {
+ $ret = $objCatList->CountCategories($attribs);
+ }
+ else
+ {
+ $ListVar =& GetItemCollection($attribs["_itemtype"]);
+ if(is_object($ListVar))
+ {
+ //echo get_class($ListVar)."<br>";
+ //print_pre($attribs);
+ $ret = $ListVar->PerformItemCount($attribs);
+ //echo "m_itemcount: $ret<br>";
+ }
+ }
+ }
+ else
+ $ret = 0;
+
+ return !$ret ? 0 : $ret;
+}
+
+/*
+ @description: Parse a User field and return the value
+ @attrib: _Field:: User field to parse
+ @attrib: _UserId:int: Category ID to parse (uses current user if not set)
+*/
+function m_user_field($attribs)
+{
+ global $objUsers, $objSession;
+
+ $o = "";
+ $userid = getArrayValue($attribs,'_userid');
+ if(!is_numeric($userid) || $userid=="0")
+ $userid = $objSession->Get("PortalUserId");
+
+ if($userid)
+ {
+ $u =& $objUsers->GetItem($userid);
+ if(is_object($u))
+ {
+ $element = new clsHtmlTag();
+ $element->name = $u->TagPrefix;
+ $element->attributes = $attribs;
+ $o = $u->ParseObject($element);
+ }
+ }
+ return $o;
+}
+
+/*
+ @description: Parses a user template
+ @attrib:_Template:tpl: Template to parse
+ @attrib:_UserId:int: User ID to parse. If not set, the current user is used
+*/
+function m_user_detail($attribs = array())
+{
+ global $objTemplate, $objUsers, $objSession;
+
+ $tname = $attribs["_template"];
+ $UserId = (int)$attribs["_userid"];
+ if(!$UserId)
+ {
+ $UserId=$objSession->Get("PortalUserId");
+ }
+ if($UserId>0)
+ {
+ $u = $objUsers->GetUser($UserId);
+ $o = $u->ParseTemplate($tname);
+ }
+ else
+ {
+ $u = new clsPortalUser(NULL);
+ $o = $u->ParseTemplate($tname);
+ }
+
+ return $o;
+}
+
+/*
+ @description: returns a user field from the current profile being viewed
+ @example:<inp:m_user_profile_field _Field="login" />
+*/
+function m_user_profile_field($attribs = array())
+{
+ if((int)$_GET["UserId"])
+ {
+ $attribs["_userid"] = $_GET["UserId"];
+ }
+
+ $ret = m_user_field($attribs);
+
+/* if ($ret == '') {
+ $ret = admin_language("lu_Guest");
+ }*/
+
+ return $ret;
+}
+
+/*
+ @description: Parses a user profile template
+ @attrib:_Template:tpl: Template to parse
+ @attrib:_UserId:int: User ID to parse. If not set, the current user is used
+*/
+function m_user_profile_detail($attribs)
+{
+ if((int)$_GET["UserId"])
+ {
+ $attribs["_userid"] = $_GET["UserId"];
+ }
+ $ret = m_user_detail($attribs);
+ return $ret;
+}
+
+/*
+ @description: Lists all user profile fields the user has indicated to be public
+ @attrib: _ItemTemplate:tpl: Template used to list each field
+ @example:<inp:m_user_profile _ItemTemplate="view_profile_field" />
+*/
+function m_user_profile($attribs = array())
+{
+ global $objTemplate, $objUsers;
+
+ $tname = $attribs["_itemtemplate"];
+ $t = $objTemplate->GetTemplate($tname);
+ if(is_object($t))
+ {
+ $html = $t->source;
+ }
+
+ $userid = $_GET["UserId"];
+ $o = "";
+
+ if((int)$userid>0)
+ {
+ $u = $objUsers->GetItem($userid);
+ $vars = $u->GetAllPersistantVars();
+ foreach($vars as $field=>$value)
+ {
+ if(substr($field,0,3)=="pp_")
+ {
+ if($value==1)
+ {
+ $src = $html;
+ $src = str_replace("<inp:user_profile_field />","<inp:user _field=\"".substr($field,3)."\" />",$src);
+ $src = str_replace("lu_profile_field","lu_".$field,$src);
+ $o .= $u->ParseTemplateText($src);
+ }
+ }
+
+ }
+ }
+
+ return $o;
+}
+
+/*
+ @description: List users the current user has marked as 'friend'
+ @attrib: _Status:: Determines which online status to list, either "online" or "offline".
+ @attrib: _ItemTemplate:tpl: Template used to parse list items
+*/
+function m_list_friends($attribs = array())
+{
+ global $objUsers, $objSession;
+
+ global $online_friends;
+
+ $ado = &GetADODBConnection();
+
+ $status = strtolower($attribs["_status"]);
+
+ $logedin_user = $objSession->Get("PortalUserId");
+ $u =& $objUsers->GetUser($logedin_user);
+
+ //echo "<pre>"; print_r($u); echo "</pre>";
+ if(!isset($online_friends) || $status=="online")
+ {
+ $ftable = GetTablePrefix()."Favorites";
+ $stable = GetTablePrefix()."UserSession";
+ $ptable = GetTablePrefix()."PortalUser";
+ if(isset($online_friends))
+ {
+ foreach($online_friends as $id=>$name)
+ {
+ $u =& $objUsers->GetUser($id);
+ $o .= $u->ParseTemplate($attribs["_itemtemplate"]);
+ }
+ }
+ else
+ {
+ $sql = "SELECT $ftable.ResourceId,$ftable.ItemTypeId, $ptable.PortalUserId,$stable.PortalUserId FROM $ftable ";
+ $sql .="INNER JOIN $ptable ON ($ftable.ResourceId=$ptable.ResourceId) INNER JOIN $stable ON ";
+ $sql .= "($ptable.PortalUserId=$stable.PortalUserId) WHERE ItemTypeId=6 AND $ftable.PortalUserId = ".$logedin_user; //$u->Data['ResourceId'];
+ //echo $sql;
+ $rs = $ado->Execute($sql);
+ while($rs && ! $rs->EOF)
+ {
+ $u =& $objUsers->GetItem($rs->fields["PortalUserId"]);
+ if($status=="online")
+ {
+ $o .= $u->ParseTemplate($attribs["_itemtemplate"]);
+ }
+ $online_friends[]=$rs->fields["PortalUserId"];
+ if(ADODB_EXTENSION>0)
+ {
+ adodb_movenext($rs);
+ }
+ else
+ $rs->MoveNext();
+ }
+ }
+ }
+
+ if($status=="offline")
+ {
+ $ftable = GetTablePrefix()."Favorites";
+ $stable = GetTablePrefix()."UserSession";
+ $ptable = GetTablePrefix()."PortalUser";
+
+ $sessql = "SELECT DISTINCT(PortalUserId) FROM $stable";
+ if(count($online_friends)>0)
+ {
+ $sql = "SELECT $ftable.ResourceId,$ftable.ItemTypeId, $ptable.PortalUserId FROM $ftable ";
+ $sql .="INNER JOIN $ptable ON ($ftable.ResourceId=$ptable.ResourceId) WHERE ItemTypeId=6 AND ";
+ $sql .= " $ptable.PortalUserId NOT IN (".implode(",",$online_friends).") AND $ftable.PortalUserId = ".$logedin_user; //$u->Data['ResourceId'];
+ }
+ else
+ {
+ $sql = "SELECT $ftable.ResourceId,$ftable.ItemTypeId, $ptable.PortalUserId FROM $ftable ";
+ $sql .="INNER JOIN $ptable ON ($ftable.ResourceId=$ptable.ResourceId) WHERE ItemTypeId=6 AND $ftable.PortalUserId = ".$logedin_user; //$u->Data['ResourceId'];
+ }
+
+ //echo $sql;
+ $rs = $ado->Execute($sql);
+ while($rs && ! $rs->EOF)
+ {
+ $u = $objUsers->GetItem($rs->fields["PortalUserId"]);
+ $o .= $u->ParseTemplate($attribs["_itemtemplate"]);
+ if(ADODB_EXTENSION>0)
+ {
+ adodb_movenext($rs);
+ }
+ else
+ $rs->MoveNext();
+ }
+ }
+ $t = $attribs["_itemtemplate"];
+ return $o;
+}
+
+/*
+ @description: Returns the number of users the current user has marked as 'friend'
+ @attrib: _Status:: Determines which online status to count, either "online" or "offline".
+*/
+function m_friend_count($attribs=array())
+{
+ global $objUsers, $objSession;
+
+ global $online_friends;
+
+ $ado = &GetADODBConnection();
+
+ $logedin_user = $objSession->Get("PortalUserId");
+ $u =& $objUsers->GetUser($logedin_user);
+
+ $status = strtolower($attribs["_status"]);
+ if(!isset($online_friends) || $status=="online")
+ {
+ $ftable = GetTablePrefix()."Favorites";
+ $stable = GetTablePrefix()."UserSession";
+ $ptable = GetTablePrefix()."PortalUser";
+ if(isset($online_friends) && $status="online")
+ {
+ return count($online_friends);
+ }
+ else
+ {
+ $online_friends = array();
+ $sql = "SELECT $ftable.ResourceId,$ftable.ItemTypeId, $ptable.PortalUserId,$stable.PortalUserId FROM $ftable ";
+ $sql .="INNER JOIN $ptable ON ($ftable.ResourceId=$ptable.ResourceId) INNER JOIN $stable ON ";
+ $sql .= "($ptable.PortalUserId=$stable.PortalUserId) WHERE ItemTypeId=6 AND $ftable.PortalUserId = ".$logedin_user; //$u->Data['ResourceId'];
+ //echo $sql."<br>\n";
+ $rs = $ado->Execute($sql);
+ while($rs && ! $rs->EOF)
+ {
+ $online_friends[$rs->fields["PortalUserId"]]=$rs->fields["PortalUserId"];
+ if(ADODB_EXTENSION>0)
+ {
+ adodb_movenext($rs);
+ }
+ else
+ $rs->MoveNext();
+ }
+ if($status=="online")
+ return count($online_friends);
+ }
+ }
+
+ if($status=="offline")
+ {
+ $ftable = GetTablePrefix()."Favorites";
+ $stable = GetTablePrefix()."UserSession";
+ $ptable = GetTablePrefix()."PortalUser";
+
+ $sessql = "SELECT DISTINCT(PortalUserId) FROM $stable";
+
+ if(count($online_friends)>0)
+ {
+ $sql = "SELECT count($ftable.ResourceId) as ItemCount FROM $ftable ";
+ $sql .="INNER JOIN $ptable ON ($ftable.ResourceId=$ptable.ResourceId) WHERE ItemTypeId=6 AND ";
+ $sql .= " $ptable.PortalUserId NOT IN (".implode(",",$online_friends).") AND $ftable.PortalUserId = ".$logedin_user; //$u->Data['ResourceId'];
+ }
+ else
+ {
+ $sql = "SELECT count($ftable.ResourceId) as ItemCount FROM $ftable ";
+ $sql .="INNER JOIN $ptable ON ($ftable.ResourceId=$ptable.ResourceId) WHERE ItemTypeId=6 AND $ftable.PortalUserId = ".$logedin_user; //$u->Data['ResourceId'];
+ }
+ $rs = $ado->Execute($sql);
+ return $rs->fields["ItemCount"];
+ }
+}
+
+/*
+ @description: Returns the number of users the current user has marked as 'friend' today
+*/
+function m_friend_count_today($attribs)
+{
+ global $objSession;
+
+ $logedin_user = $objSession->Get("PortalUserId");
+
+ $ret =0;
+ $ado = &GetADODBConnection();
+ $today = adodb_mktime(0, 0, 0, adodb_date("m"), adodb_date("d"), adodb_date("Y"));
+ $sql = "SELECT count(*) as c FROM ".GetTablePrefix()."Favorites WHERE ItemTypeId=6 and PortalUserId=".$objSession->Get("PortalUserId")." AND Modified>$today";
+ $rs = $ado->Execute($sql);
+ if($rs && !$rs->EOF)
+ $ret = $rs->fields["c"];
+ return $ret;
+}
+
+/*
+ @description: Returns the number of items in a search result
+
+ @Example: <span>(<inp:m_search_item_count _ItemType="Topic" />)</span>
+*/
+function m_search_item_count($attribs)
+{
+ global $objItemTypes, $objCatList, $objSession, $CountVal;
+
+ if(!is_array($CountVal))
+ $CountVal=array();
+ $item = $objItemTypes->GetTypeByName($attribs["_itemtype"]);
+ if(is_object($item))
+ {
+ $val = $CountVal[$item->Get("ItemType")];
+ if(is_numeric($val))
+ return $val;
+ $where = "ItemType=".$item->Get("ItemType");
+ $table = $objSession->GetSearchTable();
+ $ret = TableCount($table,$where,0);
+ $CountVal[$item->Get("ItemType")]=(int)$ret;
+ }
+
+ return $ret;
+}
+/*
+ @description: Returns the number of categories in a search result
+ @Example: <span>(<inp:m_search_cat_count />)</span>
+*/
+function m_search_cat_count($attribs = array())
+{
+ global $objItemTypes, $objCatList, $objSession, $CountVal, $objSearchCats;
+
+ if(!is_object($objSearchCats))
+ {
+ $objSearchCats = new clsCatList();
+ $objSearchCats->SourceTable = $objSession->GetSearchTable();
+ $objSearchCats->Clear();
+ }
+
+ if( !clsParsedItem::TableExists( $objSearchCats->SourceTable ) )
+ {
+ return 0;
+ }
+ LoadCatSearchResults($attribs);
+ //echo "<pre>"; print_r($objSearchCats->Items); echo "</pre>";
+ $ret = 0;
+ $keywords = $objSession->GetVariable("Search_Keywords");
+
+ /*if ($keywords) {
+ foreach ($objSearchCats->Items as $cat) {
+
+ if (strstr(strip_tags(strtolower($cat->Data[$objCatList->TitleField])), strtolower($keywords)) || strstr(strip_tags(strtolower($cat->Data[$cat->DescriptionField])), strtolower($keywords))) {
+ $ret++;
+ }
+ }
+ }*/
+ //else {
+ $ret = $objSearchCats->QueryItemCount;
+ //}
+
+ if ($ret == '') {
+ $ret = 0;
+ }
+
+ //echo $ret;
+ //$objSearchCats->QueryItemCount = $ret;
+
+ return $ret;
+}
+
+/*
+ @description: Returns super global variable by type and name
+ @attrib: _Name:: Name of variable
+ @attrib: _Type:: Type super global variable <br>Possible Values:
+ <UL>
+ <LI>get: $_GET super variable
+ <LI>post: $_POST super variable
+ <LI>cookie: $_COOKIE super variable
+ <LI>env: $_ENV super variable
+ <LI>server: $_SERVER super variable
+ <LI>session: $_SESSION super variable
+ </UL>
+ @Example: <inp:m_get_var _name="url" _type="get" />
+*/
+function m_get_var($attribs = array())
+{
+ $type = strtoupper( $attribs['_type'] );
+ $name = $attribs['_name'];
+
+ $array_name = '_'.$type;
+ $vars = $GLOBALS[ isset( $GLOBALS[$array_name] ) ? $array_name : '_POST' ];
+ return $vars[$name];
+}
+
+/*
+ @description: Returns number of users currently on-line
+ @attrib: _LastActive:: Last user/session activity in seconds
+ @attrib: _OwnCount:bool: Count user's own session
+*/
+function m_users_online($attribs = array())
+{
+ global $objSession;
+
+ $LastActive = (int)($attribs['_lastactive']);
+ $OwnCount = (int)($attribs['_owncount']);
+
+ if ($LastActive && !is_null($LastActive))
+ $sql_add = " AND LastAccessed>".(adodb_mktime()-$LastActive);
+
+ if (!$OwnCount || is_null($OwnCount))
+ $sql_add.= " AND SessionKey!='".$objSession->GetSessionKey()."'";
+
+ $ado = &GetADODBConnection();
+ $sql = "SELECT COUNT(*) AS Counter FROM ".GetTablePrefix()."UserSession WHERE Status=1".$sql_add;
+ $rs = $ado->Execute($sql);
+ $ret = ($rs && !$rs->EOF)? $rs->fields["Counter"] : 0;
+
+ return $ret;
+}
+
+function m_debug_mode($attribs = array())
+{
+ $const_name = $attribs['_debugconst'];
+ return defined($const_name) && (constant($const_name) == 1) ? 'yes' : '';
+}
+
+function m_info($attribs = array())
+{
+ switch ($attribs['_infotype'])
+ {
+ case 'site':
+ global $objConfig;
+ $ret = ThisDomain().$objConfig->Get('Site_Path');
+ break;
+
+ default:
+ $ret = '';
+ break;
+ }
+ return $ret;
+}
+
+function m_module_enabled($attribs = array())
+{
+ global $objModules;
+ $module = $attribs['_module'];
+
+ // check if module is installed
+ $ModuleItem = $objModules->GetItemByField('Name', $module);
+ if( !is_object($ModuleItem) ) return '';
+
+ // module is enabled
+ $ret = $ModuleItem->Get('Loaded') == 1;
+
+ // check if installed module is licensed
+ return $ret ? 'yes' : '';
+}
+
+function m_recall($attribs = array())
+{
+ global $objSession;
+ return $objSession->GetVariable($attribs['_name']);
+}
+
+function m_regional_option($attribs = array())
+{
+ return GetRegionalOption($attribs['_name']);
+}
+
+/*
+ @description: Returns a sitemap
+ @attrib: _CatId:int: Top Level Catagory ID to start sitemap with.
+ @attrib: _ModuleName:: Module name (optional, default none)
+ @attrib: _MainItemTemplate:tpl: Item template for Top level category
+ @attrib: _SubCatItemTemplate:tpl: Item template for Sub categories
+ @attrib: _MaxDepth:: Max Depth, default all, minimum 2
+ @attrib: _MaxCats:: Maximum number of Categories for each Module, default 300
+*/
+function m_sitemap($attribs = array())
+{
+ global $objModules, $objConfig, $objCatList;
+
+ $html_attribs = ExtraAttributes($attribs);
+
+ $mod_name = getArrayValue($attribs, "_modulename");
+ $StartCatId = getArrayValue($attribs, "_catid");
+ $MaxDepth = (int)getArrayValue($attribs, "_maxdepth");
+ $MaxCats = getArrayValue($attribs, "_maxcats");
+ $MaxCats = !empty($MaxCats) ? (int)$MaxCats : 300;
+
+ if ($MaxDepth == 0)
+ unset($MaxDepth);
+ elseif ($MaxDepth < 2)
+ $MaxDepth = 2;
+
+ $MainItemTemplate = getArrayValue($attribs, "_mainitemtemplate");
+ $SubCatItemTemplate = getArrayValue($attribs, "_subcatitemtemplate");
+
+ if (!strlen($SubCatItemTemplate))
+ $SubCatItemTemplate = "sitemap_subcat_element";
+
+ if (!strlen($MainItemTemplate))
+ $MainItemTemplate = "sitemap_cat_element";
+
+
+ $cols = getArrayValue($attribs, "_columns");
+ $cols = ($cols<1)? 2 : $cols;
+
+ if (!isset($StartCatId))
+ {
+ if (!strlen($mod_name))
+ {
+ $_RootCat = 0;
+ }
+ else
+ {
+ $_RootCat = $objModules->GetModuleRoot($mod_name);
+ }
+ }
+ else
+ {
+ $_RootCat = (int)$StartCatId? (int)$StartCatId : 0;
+ }
+
+ // Get Root Categories of all installed Modules
+ if (is_array($objModules->Items))
+ {
+ foreach ($objModules->Items as $curr_mod)
+ {
+ if( !$curr_mod->Get('Loaded') || ($curr_mod->Get('Name') == 'In-Portal') ) continue;
+
+ $mod_name = (int)$curr_mod->Get('RootCat');
+ if( !empty($mod_name) )
+ {
+ $modules[$mod_name] = !isset($modules[$mod_name]) ? $curr_mod->Get('TemplatePath') : '';
+ }
+ else
+ {
+ $modules[$mod_name] = '';
+ }
+ }
+ }
+
+ $_C_objCat = new clsCatList();
+ $_Where = GetTablePrefix()."Category.ParentId = $_RootCat AND Status = 1";
+ $_OrderBy = " ORDER BY ".GetTablePrefix()."Category.Priority DESC ";
+ $_C_catList = $_C_objCat->LoadCategories($_Where, $_OrderBy, false);
+
+ ## getting TOP level categories
+ if( is_array($_C_catList) && count($_C_catList) )
+ {
+ $ret = "<TABLE $html_attribs><TR CLASS=\"m_list_cats\">";
+ $ret.= "<TD valign=\"top\">";
+
+ $CatCount = $_C_objCat->NumCategories();
+ $per_row = ceil($CatCount / $cols);
+
+ foreach ($_C_catList as $cat)
+ {
+ $text = $cat->Get($objCatList->TitleField);
+ $val = $cat->Get("CategoryId");
+ $sub_path = $cat->Get("ParentPath");
+
+ $add_path = "";
+ if( is_array($modules) )
+ {
+ foreach($modules as $curr => $v)
+ {
+ if (strpos($sub_path, "|$curr|") !== false)
+ {
+ $add_path = $v;
+ break;
+ }
+ }
+ }
+ if(!$add_path) continue;
+
+ $main_templ = $add_path.$MainItemTemplate;
+ $ret.= $cat->ParseTemplate($main_templ);
+
+ $count++;
+ $row++;
+
+ $_C_objCatSubs = new clsCatList();
+
+ $ParentPath = empty($_RootCat) ? '|'.$val.'|%' : '|'.$_RootCat.'|'.$val.'|%';
+
+ $_Where = GetTablePrefix()."Category.ParentPath LIKE '$ParentPath' AND ".GetTablePrefix()."Category.CategoryId!=$val AND Status=1";
+ $_OrderBy = " ORDER BY ".GetTablePrefix()."Category.ParentPath ASC, ".GetTablePrefix()."Category.".$objCatList->TitleField." ASC";
+ $old_value = $objConfig->Get($_C_objCatSubs->PerPageVar);
+ $objConfig->Set($_C_objCatSubs->PerPageVar, (int)$MaxCats);
+
+ $SubCats = $_C_objCatSubs->LoadCategories($_Where, $_OrderBy, false);
+
+ $objConfig->Set($_C_objCatSubs->PerPageVar, $old_value);
+
+ if (is_array($SubCats) && count($SubCats))
+ {
+ foreach ($SubCats as $subcat)
+ {
+ $SubCatName = $subcat->Get($objCatList->TitleField);
+ $SubCatId = $subcat->Get("CategoryId");
+
+ $SubPath = $subcat->Get("ParentPath");
+
+ $add_path = "";
+ if (is_array($modules))
+ {
+ foreach ($modules as $curr => $v)
+ {
+ if (strpos($SubPath, "|$curr|") !== false)
+ {
+ $add_path = $v;
+ break;
+ }
+ }
+ }
+
+ $CatIds = $subcat->GetParentIds();
+
+ $nbs = "";
+
+// echo 'MD: <b>'.$MaxDepth.'</b>, CATS: <b>'.count($CatIds).'</b><br />';
+ if (!isset($MaxDepth) || (isset($MaxDepth) && ($MaxDepth >= count($CatIds))))
+ {
+ for ($i = (count($CatIds)-2); $i>0; $i--)
+ $nbs.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+
+ $sub_templ = $add_path.$SubCatItemTemplate;
+ $ret.= $nbs.$subcat->ParseTemplate($sub_templ);
+ }
+ }
+ }
+
+ unset($_C_objCatSubs);
+
+ if($count==$per_row)
+ {
+ $ret.= "</TD><TD valign=\"top\">";
+ $count=0;
+ }
+ else
+ $ret.= "<BR />";
+ }
+
+ if($count != $per_row)
+ $ret .= "</TD>";
+ $ret.= "\n</tr></table>\n";
+ }
+
+ return $ret;
+}
+
+function m_IsDebugMode($params)
+{
+// echo 'kool';
+ return IsDebugMode() ? true : '';
+}
+
+ function m_param($params)
+ {
+ $parser_params = GetVar('parser_params');
+ $param_name = strtolower($params['_name']);
+ $value = getArrayValue($parser_params, $param_name);
+
+ if ($value) {
+ if (getArrayValue($params, '_asphrase')) {
+ $value = language($value);
+ }
+ }
+
+ return $value;
+ }
+
+ function m_set_category($params)
+ {
+ global $m_var_list;
+
+ if (getArrayValue($params, '_onlyonce') && $m_var_list['cat']) return ;
+
+ $db =& GetADODBConnection();
+ $category_id = getArrayValue($params, '_catid');
+ if (!$category_id) {
+ $module = getArrayValue($params, '_module');
+ if ($module) {
+
+ $sql = 'SELECT RootCat FROM '.GetTablePrefix().'Modules WHERE LOWER(Name) = '.$db->qstr( strtolower($module) );
+ $category_id = $db->GetOne($sql);
+ }
+ }
+
+ if ($category_id) {
+ $m_var_list['cat'] = $category_id;
+ }
+ }
+
+ function m_template_equals($params)
+ {
+ $t = preg_replace('/(.*)\.tpl/', '\\1', $params['_template']);
+ return $GLOBALS['var_list']['t'] == $t ? true : '';
+ }
+
+ function m_ShowSearchError($params)
+ {
+ global $objSession, $objTemplate;
+
+ $error_phrase = $objSession->GetVariable('search_error');
+ if (!$error_phrase) {
+ return '';
+ }
+
+ $template = getArrayValue($params, '_itemtemplate');
+ if (!$template) {
+ $ret = '<inp:form_error />';
+ }
+
+ $ret = $objTemplate->GetTemplate($template, true);
+ $ret = $ret->source;
+
+ return str_replace('<inp:form_error />', language($error_phrase), $ret);
+ }
+
+/*function m_object($attribs=Array())
+{
+ $element = new clsHtmlTag();
+ $element->name=$attribs['_prefix'];
+ $element->attributes = $attribs;
+ $ret = $cat->ParseObject($element);
+}*/
+
+?>
Property changes on: branches/unlabeled/unlabeled-1.102.2/kernel/parser.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.102
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline