ocPortal Developer's Guide: Catalogues
» Return to Contents
sources/catalogues.php
Global_functions_catalogues.php
Function summary
|
void
|
init__catalogues ()
|
|
tempcode
|
get_catalogue_category_html (array row, ID_TEXT zone, boolean put_in_box)
|
|
void
|
grant_catalogue_full_access (AUTO_LINK category_id)
|
|
array
|
count_catalogue_category_children (AUTO_LINK category_id)
|
|
array
|
get_catalogue_category_entry_buildup (?AUTO_LINK category_id, ID_TEXT catalogue_name, ?array catalogue, ID_TEXT view_type, ID_TEXT tpl_set, ?integer max, ?integer start, ?mixed select, ?AUTO_LINK root, ?SHORT_INTEGER display_type, boolean do_sorting, ?array entries, string search, ?ID_TEXT _order_by)
|
|
array
|
get_catalogue_entry_map (array entry, ?array catalogue, ID_TEXT view_type, ID_TEXT tpl_set, ?AUTO_LINK root, ?array fields, ?array only_fields, boolean feedback_details, boolean tree_details, ?integer order_by)
|
|
tempcode
|
nice_get_catalogues (?ID_TEXT it, boolean prefer_ones_with_entries, boolean only_submittable)
|
|
array
|
get_catalogue_entry_field_values (?ID_TEXT catalogue_name, mixed entry_id, ?array only_fields, ?array fields, boolean natural_order)
|
|
string
|
_get_catalogue_entry_field (AUTO_LINK field_id, mixed entry_id, ID_TEXT type)
|
|
tempcode
|
nice_get_catalogue_entries_tree (ID_TEXT catalogue_name, ?AUTO_LINK it, ?AUTO_LINK submitter, boolean editable_filter)
|
|
array
|
get_catalogue_entries_tree (ID_TEXT catalogue_name, ?AUTO_LINK submitter, ?AUTO_LINK category_id, ?string tree, ?ID_TEXT title, ?integer levels, boolean editable_filter)
|
|
tempcode
|
nice_get_catalogue_category_tree (ID_TEXT catalogue_name, ?AUTO_LINK it, boolean addable_filter, boolean use_compound_list)
|
|
array
|
get_catalogue_category_tree (ID_TEXT catalogue_name, ?AUTO_LINK category_id, ?tempcode tree, ?string title, ?integer levels, boolean addable_filter, boolean use_compound_list)
|
|
tempcode
|
catalogue_category_breadcrumbs (AUTO_LINK category_id, ?AUTO_LINK root, boolean no_link_for_me_sir)
|
|
boolean
|
is_ecommerce_catalogue (SHORT_TEXT catalogue_name)
|
|
boolean
|
is_ecommerce_catalogue_entry (AUTO_LINK entry_id)
|
|
tempcode
|
render_catalogue_entry_screen (AUTO_LINK id, boolean no_title)
|
void init__catalogues()
Standard code module initialisation function.
Parameters…
(No return value)
function init__catalogues()
{
global $PT_PAIR_CACHE;
$PT_PAIR_CACHE=array();
global $CAT_FIELDS_CACHE;
$CAT_FIELDS_CACHE=array();
// We do not actually necessarily use these constants in the code (they're based on an extensive of an old BINARY field): but they're here for reference so as to understand the codes
if (!defined('C_DT_MAPS'))
{
define('C_DT_MAPS',0);
define('C_DT_LIST',1);
define('C_DT_MATRIX',2);
}
}
tempcode get_catalogue_category_html(array row, ID_TEXT zone, boolean put_in_box)
Get tempcode for a catalogue category 'feature box' for the given row
Parameters…
| Name |
row |
| Description |
The database field row of it |
| Type |
array |
| Name |
zone |
| Description |
The zone to use |
| Default value |
_SEARCH |
| Type |
ID_TEXT |
| Name |
put_in_box |
| Description |
Whether to put it in a box |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
A box for it, linking to the full page |
| Type |
tempcode |
function get_catalogue_category_html($row,$zone='_SEARCH',$put_in_box=true)
{
$content=paragraph(get_translated_tempcode($row['cc_description']),'yghjgfjftgerr');
$url=build_url(array('page'=>'catalogues','type'=>'category','id'=>$row['id']),$zone);
$tree=catalogue_category_breadcrumbs($row['id']);
if (!$tree->is_empty()) $content->attach(paragraph(do_lang_tempcode('LOCATED_IN',$tree)));
$preview=do_template('SIMPLE_PREVIEW_BOX',array('SUMMARY'=>$content,'URL'=>$url));
if (!$put_in_box) return $preview;
return put_in_standard_box($preview,get_translated_text($row['cc_title']));
}
void grant_catalogue_full_access(AUTO_LINK category_id)
Grant all usergroups access to the specified catalogue category.
Parameters…
| Name |
category_id |
| Description |
The ID of the category that access is being given to |
| Type |
AUTO_LINK |
(No return value)
function grant_catalogue_full_access($category_id)
{
$groups=$GLOBALS['FORUM_DRIVER']->get_usergroup_list(false,true);
foreach (array_keys($groups) as $group_id)
{
$GLOBALS['SITE_DB']->query_insert('group_category_access',array('module_the_name'=>'catalogues_category','category_name'=>strval($category_id),'group_id'=>$group_id));
}
}
array count_catalogue_category_children(AUTO_LINK category_id)
Count the entries and subcategories underneath the specified category, recursively.
Parameters…
| Name |
category_id |
| Description |
The ID of the category for which count details are collected |
| Type |
AUTO_LINK |
Returns…
| Description |
The number of entries is returned in $output['num_entries'], and the number of subcategories is returned in $output['num_children'], the (possibly recursive) number of subcategories in $output['num_children_children'], and the (possibly recursive) number of entries is returned in $output['num_entries_children']. |
| Type |
array |
function count_catalogue_category_children($category_id)
{
static $total_categories=NULL;
if (is_null($total_categories)) $total_categories=$GLOBALS['SITE_DB']->query_value('catalogue_categories','COUNT(*)');
$out=array();
$out['num_children']=$GLOBALS['SITE_DB']->query_value('catalogue_categories','COUNT(*)',array('cc_parent_id'=>$category_id));
$out['num_entries']=$GLOBALS['SITE_DB']->query_value('catalogue_entries','COUNT(*)',array('cc_id'=>$category_id,'ce_validated'=>1));
$rec_record=$GLOBALS['SITE_DB']->query_select('catalogue_childcountcache',array('c_num_rec_children','c_num_rec_entries'),array('cc_id'=>$category_id),'',1);
if (!array_key_exists(0,$rec_record)) $rec_record[0]=array('c_num_rec_children'=>0,'c_num_rec_entries'=>0);
$out['num_children_children']=$rec_record[0]['c_num_rec_children'];
$out['num_entries_children']=$rec_record[0]['c_num_rec_entries'];
return $out;
}
array get_catalogue_category_entry_buildup(?AUTO_LINK category_id, ID_TEXT catalogue_name, ?array catalogue, ID_TEXT view_type, ID_TEXT tpl_set, ?integer max, ?integer start, ?mixed select, ?AUTO_LINK root, ?SHORT_INTEGER display_type, boolean do_sorting, ?array entries, string search, ?ID_TEXT _order_by)
Get an ordered array of all the entries in the specified catalogue.
Parameters…
| Name |
category_id |
| Description |
The ID of the category for which the entries are being collected (NULL: entries are [and must be] passed instead) |
| Type |
?AUTO_LINK |
| Name |
catalogue_name |
| Description |
The name of the catalogue |
| Type |
ID_TEXT |
| Name |
catalogue |
| Description |
A database row of the catalogue we are working with (NULL: read it in) |
| Type |
?array |
| Name |
view_type |
| Description |
The view type we're doing |
| Type |
ID_TEXT |
| Values restricted to |
PAGE SEARCH CATEGORY |
| Name |
tpl_set |
| Description |
The template set we are rendering this category using |
| Type |
ID_TEXT |
| Name |
max |
| Description |
The maximum number of entries to show on a single page of this this category (ignored if $select is not NULL) (NULL: all) |
| Type |
?integer |
| Name |
start |
| Description |
The entry number to start at (ignored if $select is not NULL) (NULL: all) |
| Type |
?integer |
| Name |
select |
| Description |
The entries to show, may be from other categories. Can either be SQL fragment, or array (NULL: use $start and $max) |
| Type |
?mixed |
| Name |
root |
| Description |
The virtual root for display of this category (NULL: default) |
| Type |
?AUTO_LINK |
| Name |
display_type |
| Description |
The display type to use (NULL: lookup from $catalogue) |
| Default value |
|
| Type |
?SHORT_INTEGER |
| Name |
do_sorting |
| Description |
Whether to perform sorting |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
entries |
| Description |
A list of entry rows (NULL: select them normally) |
| Default value |
|
| Type |
?array |
| Name |
search |
| Description |
Search filter (blank: no filter) |
| Default value |
|
| Type |
string |
| Name |
_order_by |
| Description |
Orderer (NULL: read from environment) |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
An array containing our built up entries (renderable tempcode), our sorting interface, and our entries (entry records from database, with an additional 'map' field), and the max rows |
| Type |
array |
function get_catalogue_category_entry_buildup($category_id,$catalogue_name,$catalogue,$view_type,$tpl_set,$max,$start,$select,$root,$display_type=NULL,$do_sorting=true,$entries=NULL,$search='',$_order_by=NULL)
{
if (addon_installed('ecommerce'))
{
require_code('ecommerce');
}
$is_ecomm=is_ecommerce_catalogue($catalogue_name);
if (is_null($catalogue))
{
$_catalogues=$GLOBALS['SITE_DB']->query_select('catalogues',array('*'),array('c_name'=>$catalogue_name),'',1);
$catalogue=$_catalogues[0];
}
if ((is_null($category_id)) && (is_null($entries)))
{
if (!is_null($select))
{
if (((is_array($select)) && (count($select)==0)) || ((is_string($select)) && ($select=='')))
{
$entries=array();
} else
{
if (!is_array($select))
{
$or_list=$select;
} else
{
$or_list='';
foreach ($select as $s)
{
if ($or_list!='') $or_list.=' OR ';
$or_list.='id='.strval($s);
}
}
$entries=$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'catalogue_entries WHERE '.db_string_equal_to('c_name',$catalogue_name).' AND ce_validated=1 AND ('.$or_list.') ORDER BY ce_add_date DESC');
}
} else
{
fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
}
}
if (is_null($display_type))
{
$display_type=get_param_integer('keep_cat_display_type',$catalogue['c_display_type']);
}
// Find order field
global $CAT_FIELDS_CACHE;
if (isset($CAT_FIELDS_CACHE[$catalogue_name]))
{
$fields=$CAT_FIELDS_CACHE[$catalogue_name];
} else
{
$fields=$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('*'),array('c_name'=>$catalogue_name),'ORDER BY cf_order');
}
$CAT_FIELDS_CACHE[$catalogue_name]=$fields;
if ($do_sorting)
{
if (is_null($_order_by))
$_order_by=get_param('order','');
if (($_order_by=='') || (strpos($_order_by,' ')===false/*probably some bot probing URLs -- sorting always has a space between sorter and direction*/))
{
$order_by='0';
$direction='ASC';
foreach ($fields as $i=>$field)
{
if ($field['cf_defines_order']!=0)
{
$order_by=strval($i);
$direction=($field['cf_defines_order']==1)?'ASC':'DESC';
$_order_by=strval($field['id']).' '.$direction;
break;
}
}
} else
{
list($order_by,$direction)=explode(' ',$_order_by);
if (($order_by!='rating') && ($order_by!='add_date'))
{
$found=false;
foreach ($fields as $i=>$field)
{
if ($order_by==$field['id'])
{
$order_by=strval($i);
$found=true;
break;
}
}
if (!$found) $order_by='0'; // Could not find
}
}
} else
{
$order_by=mixed();
$direction='ASC';
}
// Get entries in this category
if ($select==='1=1') $select=NULL;
$map=array('cc_id'=>$category_id);
if (!has_specific_permission(get_member(),'see_unvalidated')) $map['ce_validated']=1;
$in_db_sorting=!is_null($order_by) && $do_sorting && is_null($select);
require_code('fields');
if (is_null($entries))
{
if ($in_db_sorting)
{
$num_entries=$GLOBALS['SITE_DB']->query_value('catalogue_entries','COUNT(*)',$map);
if ($order_by=='add_date')
{
$entries=($max==0)?array():$GLOBALS['SITE_DB']->query_select('catalogue_entries e',array('e.*'),$map,'ORDER BY ce_add_date '.$direction,$max,$start);
}
elseif ($order_by=='rating')
{
$select_rating='(SELECT AVG(rating) FROM '.get_table_prefix().'rating WHERE '.db_string_equal_to('rating_for_type','catalogues').' AND rating_for_id=id) AS compound_rating';
$entries=($max==0)?array():$GLOBALS['SITE_DB']->query_select('catalogue_entries e',array('e.*',$select_rating),$map,'ORDER BY compound_rating '.$direction,$max,$start);
} else
{
$ob=get_fields_hook($fields[intval($order_by)]['cf_type']);
list(,,$table)=$ob->get_field_value_row_bits($fields[$order_by]);
if (strpos($table,'_trans')!==false)
{
$join='catalogue_entries e LEFT JOIN '.get_table_prefix().'catalogue_efv_'.$table.' f ON f.ce_id=e.id AND f.cf_id='.strval($fields[$order_by]['id']).' LEFT JOIN '.get_table_prefix().'translate t ON f.cv_value=t.id';
$entries=($max==0)?array():$GLOBALS['SITE_DB']->query_select($join,array('e.*'),$map,($num_entries>300)?'':'ORDER BY t.text_original '.$direction /* For large data sets too slow as after two MySQL joins it can't then use index for ordering */,$max,$start);
} else
{
$join='catalogue_entries e LEFT JOIN '.get_table_prefix().'catalogue_efv_'.$table.' f ON f.ce_id=e.id AND f.cf_id='.strval($fields[$order_by]['id']);
$entries=($max==0)?array():$GLOBALS['SITE_DB']->query_select($join,array('e.*'),$map,'ORDER BY f.cv_value '.$direction,$max,$start);
}
}
$start=0; // To stop it skipping itself
} else
{
if ((is_null($order_by) || !$do_sorting) && (!is_null($max)))
{
$entries=($max==0)?array():$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('*'),$map,'',$max,$start);
$num_entries=$GLOBALS['SITE_DB']->query_value('catalogue_entries','COUNT(*)',$map);
$start=0; // To stop it skipping itself
} else
{
$entries=($max==0)?array():$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('*'),$map);
$num_entries=count($entries);
}
}
} else
{
$num_entries=count($entries);
}
if (($num_entries>300) && (!$in_db_sorting)) $in_db_sorting=true; // Needed to stop huge slow down
foreach ($entries as $i=>$entry)
{
if ((!$in_db_sorting) || (((is_null($start)) || ($i>=$start) && ($i<$start+$max)) && ((!is_array($select)) || ((is_array($select)) && (in_array($entry['id'],$select))))))
{
$entries[$i]['map']=get_catalogue_entry_map($entry,$catalogue,$view_type,$tpl_set,$root,$fields,(($display_type==1) && (!$is_ecomm) && (!is_null($order_by)))?array(0,intval($order_by)):NULL,false,false,intval($order_by));
}
}
// Implement search filter
if ($search!='')
{
$new_entries=array();
for ($i=0;$i<$num_entries;$i++)
{
$two_d_list=$entries[$i]['map']['FIELDS_2D'];
$all_output='';
foreach ($two_d_list as $index=>$l)
{
$all_output.=(is_object($l['VALUE'])?$l['VALUE']->evaluate():$l['VALUE']).' ';
}
if (strpos(strtolower($all_output),strtolower($search))!==false)
{
$new_entries[]=$entries[$i];
}
}
$entries=$new_entries;
}
disable_php_memory_limit();
if ($do_sorting)
{
// Sort entries
$selectors=new ocp_tempcode();
foreach ($fields as $i=>$field)
{
if ($field['cf_searchable']==1)
{
$potential_sorter_name=get_translated_text($field['cf_name']);
foreach (array('ASC'=>'_ASCENDING','DESC'=>'_DESCENDING') as $dir_code=>$dir_lang)
{
$sort_sel=(($order_by==strval($i)) && ($direction==$dir_code));
$_potential_sorter_name=new ocp_tempcode();
$_potential_sorter_name->attach(escape_html($potential_sorter_name));
$_potential_sorter_name->attach(do_lang_tempcode($dir_lang));
$selectors->attach(do_template('RESULTS_BROWSER_SORTER',array('_GUID'=>'dfdsfdsusd0fsd0dsf','SELECTED'=>$sort_sel,'NAME'=>protect_from_escaping($_potential_sorter_name),'VALUE'=>strval($field['id']).' '.$dir_code)));
}
}
}
foreach (array('add_date'=>'_ADDED','rating'=>'RATING') as $extra_sort_code=>$extra_sort_lang)
{
foreach (array('ASC'=>'_ASCENDING','DESC'=>'_DESCENDING') as $dir_code=>$dir_lang)
{
$sort_sel=(($order_by==$extra_sort_code) && ($direction==$dir_code));
$_potential_sorter_name=new ocp_tempcode();
$_potential_sorter_name->attach(do_lang_tempcode($extra_sort_lang));
$_potential_sorter_name->attach(do_lang_tempcode($dir_lang));
$selectors->attach(do_template('RESULTS_BROWSER_SORTER',array('_GUID'=>'xfdsfdsusd0fsd0dsf','SELECTED'=>$sort_sel,'NAME'=>protect_from_escaping($_potential_sorter_name),'VALUE'=>$extra_sort_code.' '.$dir_code)));
}
}
$sort_url=get_self_url(false,false,array('order'=>NULL),false,true);
$sorting=do_template('RESULTS_BROWSER_SORT',array('_GUID'=>'9fgjfdklgjdfgkjlfdjgd90','SORT'=>'order','RAND'=>uniqid(''),'URL'=>$sort_url,'SELECTORS'=>$selectors));
if (!$in_db_sorting)
{
for ($i=0;$i<$num_entries;$i++)
{
if (!array_key_exists($i,$entries)) continue;
for ($j=$i+1;$j<$num_entries;$j++)
{
if (!array_key_exists($j,$entries)) continue;
$a=@$entries[$j]['map']['FIELD_'.$order_by];
if (array_key_exists('FIELD_'.$order_by.'_PLAIN',@$entries[$j]['map']))
{
$a=@$entries[$j]['map']['FIELD_'.$order_by.'_PLAIN'];
}
$b=@$entries[$i]['map']['FIELD_'.$order_by];
if (array_key_exists('FIELD_'.$order_by.'_PLAIN',@$entries[$i]['map']))
{
$b=@$entries[$i]['map']['FIELD_'.$order_by.'_PLAIN'];
}
if (is_object($a)) $a=$a->evaluate();
if (is_object($b)) $b=$b->evaluate();
if ($fields[$order_by]['cf_type']=='date')
{
$bits=explode(' ',$a,2);
$date_bits=explode((strpos($bits[0],'-')!==false)?'-':'/',$bits[0],3);
if (!array_key_exists(1,$date_bits)) $date_bits[1]=date('m');
if (!array_key_exists(2,$date_bits)) $date_bits[2]=date('Y');
$time_bits=explode(':',$bits[1],3);
if (!array_key_exists(1,$time_bits)) $time_bits[1]='00';
if (!array_key_exists(2,$time_bits)) $time_bits[2]='00';
$time_a=mktime(intval($time_bits[0]),intval($time_bits[1]),intval($time_bits[2]),intval($date_bits[1]),intval($date_bits[2]),intval($date_bits[0]));
$bits=explode(' ',$b,2);
$date_bits=explode((strpos($bits[0],'-')!==false)?'-':'/',$bits[0],3);
if (!array_key_exists(1,$date_bits)) $date_bits[1]=date('m');
if (!array_key_exists(2,$date_bits)) $date_bits[2]=date('Y');
$time_bits=explode(':',$bits[1],3);
if (!array_key_exists(1,$time_bits)) $time_bits[1]='00';
if (!array_key_exists(2,$time_bits)) $time_bits[2]='00';
$time_b=mktime(intval($time_bits[0]),intval($time_bits[1]),intval($time_bits[2]),intval($date_bits[1]),intval($date_bits[2]),intval($date_bits[0]));
$r=($time_a<$time_b)?-1:(($time_a==$time_b)?0:1);
} else
{
$r=strnatcmp(strtolower($a),strtolower($b));
}
if ((($r<0) && ($direction=='ASC')) || (($r>0) && ($direction=='DESC')))
{
$temp=$entries[$i];
$entries[$i]=$entries[$j];
$entries[$j]=$temp;
}
}
}
}
} else $sorting=new ocp_tempcode();
// Build up entries
$entry_buildup=new ocp_tempcode();
$extra_map=array();
if($is_ecomm)
{
require_lang('shopping');
$i=0;
for ($i=0;$i<$num_entries;$i++)
{
if (!array_key_exists($i,$entries)) break;
$entry=$entries[$i];
$extra_map[$i]['ADD_TO_CART']=build_url(array('page'=>'shopping','type'=>'add_item','product_id'=>$entry['id'],'hook'=>'catalogue_items'),get_module_zone('shopping'));
}
}
if ($display_type==2)
{
for ($i=0;$i<$num_entries;$i++)
{
if (!array_key_exists($i,$entries)) break;
$entry=$entries[$i];
if (((is_null($start)) || ($i>=$start) && ($i<$start+$max)) && ((!is_array($select)) || (is_array($select)) && (in_array($entry['id'],$select))))
{
$tab_entry_map=$entry['map']+(array_key_exists($i,$extra_map)?$extra_map[$i]:array());
if ((get_option('is_on_comments')=='1') && ($entry['allow_comments']>=1) || (get_option('is_on_rating')=='1') && ($entry['allow_rating']==1) || (get_option('is_on_trackbacks')=='1') && ($entry['allow_trackbacks']==1))
{
$tab_entry_map['VIEW_URL']=build_url(array('page'=>'catalogues','type'=>'entry','id'=>$entry['id'],'root'=>($root==-1)?NULL:$root),get_module_zone('catalogues'));
} else
{
$tab_entry_map['VIEW_URL']='';
}
$entry_buildup->attach(/*Preserve memory*/static_evaluate_tempcode(do_template('CATALOGUE_'.$tpl_set.'_TAB_ENTRY',$tab_entry_map,NULL,false,'CATALOGUE_DEFAULT_TAB_ENTRY')));
}
if ((!is_null($start)) && ($i>=$start+$max)) break;
}
if (!$entry_buildup->is_empty())
{
$head=new ocp_tempcode();
$field_count=0;
foreach ($fields as $i=>$field)
{
if (((($field['cf_put_in_category']==1) && ($view_type=='CATEGORY')) || (($field['cf_put_in_search']==1) && ($view_type=='SEARCH'))) && ($field['cf_visible']==1))
{
if ($field['cf_searchable']==1)
{
$sort_url_asc=get_self_url(false,false,array('order'=>strval($field['id']).' ASC'),true);
$sort_url_desc=get_self_url(false,false,array('order'=>strval($field['id']).' DESC'),true);
$sort_asc_selected=(($order_by==strval($field['id'])) && ($direction=='ASC'));
$sort_desc_selected=(($order_by==strval($field['id'])) && ($direction=='DESC'));
} else
{
$sort_url_asc='';
$sort_url_desc='';
$sort_asc_selected=false;
$sort_desc_selected=false;
}
$head->attach(do_template('CATALOGUE_'.$tpl_set.'_TAB_FIELD_HEAD',array('SORT_ASC_SELECTED'=>$sort_asc_selected,'SORT_DESC_SELECTED'=>$sort_desc_selected,'SORT_URL_ASC'=>$sort_url_asc,'SORT_URL_DESC'=>$sort_url_desc,'CATALOGUE'=>$catalogue_name,'FIELDID'=>strval($i),'_FIELDID'=>strval($field['id']),'FIELD'=>get_translated_text($field['cf_name']),'FIELDTYPE'=>$field['cf_type']),NULL,false,'CATALOGUE_DEFAULT_TAB_FIELD_HEAD'));
$field_count++;
}
}
$entry_buildup=do_template('CATALOGUE_'.$tpl_set.'_TAB_WRAP',array('CATALOGUE'=>$catalogue_name,'HEAD'=>$head,'CONTENT'=>$entry_buildup,'FIELD_COUNT'=>strval($field_count)),NULL,false,'CATALOGUE_DEFAULT_TAB_WRAP');
}
}
elseif ($display_type==0)
{
for ($i=0;$i<$num_entries;$i++)
{
if (!array_key_exists($i,$entries)) break;
$entry=$entries[$i];
if ((is_null($max)) || ((is_null($start)) || ($i>=$start) && ($i<$start+$max)) && ((!is_array($select)) || ((is_array($select)) && (in_array($entry['id'],$select)))))
$entry_buildup->attach(do_template('CATALOGUE_'.$tpl_set.'_ENTRY_EMBED',$entry['map']+(array_key_exists($i,$extra_map)?$extra_map[$i]:array()),NULL,false,'CATALOGUE_DEFAULT_ENTRY_EMBED'));
}
}
else
{
for ($i=0;$i<$num_entries;$i++)
{
if (!array_key_exists($i,$entries)) break;
$entry=$entries[$i];
if (((is_null($start)) || ($i>=$start) && ($i<$start+$max)) && ((!is_array($select)) || ((is_array($select)) && (in_array($entry['id'],$select)))))
$entry_buildup->attach(do_template('CATALOGUE_'.$tpl_set.'_LINE',$entry['map']+(array_key_exists($i,$extra_map)?$extra_map[$i]:array()),NULL,false,'CATALOGUE_DEFAULT_LINE'));
}
if (!$entry_buildup->is_empty()) $entry_buildup=do_template('CATALOGUE_'.$tpl_set.'_LINE_WRAP',$entry['map']+array('CATALOGUE'=>$catalogue_name,'CONTENT'=>$entry_buildup),NULL,false,'CATALOGUE_DEFAULT_LINE_WRAP');
}
return array($entry_buildup,$sorting,$entries,$num_entries);
}
array get_catalogue_entry_map(array entry, ?array catalogue, ID_TEXT view_type, ID_TEXT tpl_set, ?AUTO_LINK root, ?array fields, ?array only_fields, boolean feedback_details, boolean tree_details, ?integer order_by)
Get a map of the fields for the given entry.
Parameters…
| Name |
entry |
| Description |
A database row of the entry we are working with |
| Type |
array |
| Name |
catalogue |
| Description |
A database row of the catalogue we are working with (NULL: read it in here) |
| Type |
?array |
| Name |
view_type |
| Description |
The view type we're doing |
| Type |
ID_TEXT |
| Values restricted to |
PAGE SEARCH CATEGORY |
| Name |
tpl_set |
| Description |
The template set we are rendering this category using |
| Type |
ID_TEXT |
| Name |
root |
| Description |
The virtual root for display of this category (NULL: none) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
fields |
| Description |
The database rows for the fields for this catalogue (NULL: find them) |
| Default value |
|
| Type |
?array |
| Name |
only_fields |
| Description |
A list of fields that we are limiting ourselves to (NULL: get ALL fields) |
| Default value |
|
| Type |
?array |
| Name |
feedback_details |
| Description |
Whether to grab the feedback details |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
tree_details |
| Description |
Whether to grab the tree details |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
order_by |
| Description |
Field index to order by (NULL: none) |
| Default value |
|
| Type |
?integer |
Returns…
| Description |
A map of information relating to the entry. The map contains 'FIELDS' (tempcode for all accumulated fields), 'FIELD_x' (for each field x applying to the entry), STAFF_DETAILS, COMMENT_DETAILS, RATING_DETAILS, VIEW_URL, TREE (tempcode category tree to this entry) |
| Type |
array |
function get_catalogue_entry_map($entry,$catalogue,$view_type,$tpl_set,$root=NULL,$fields=NULL,$only_fields=NULL,$feedback_details=false,$tree_details=false,$order_by=NULL)
{
$id=$entry['id'];
if (is_null($catalogue))
{
$catalogue_rows=$GLOBALS['SITE_DB']->query_select('catalogues',array('*'),array('c_name'=>$entry['c_name']),'',1);
if (!array_key_exists(0,$catalogue_rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$catalogue=$catalogue_rows[0];
}
// Views
if (get_db_type()!='xml')
{
$entry['ce_views']++;
}
$catalogue_name=$catalogue['c_name'];
$fields=get_catalogue_entry_field_values($catalogue_name,$entry,$only_fields,$fields);
$map=array();
$map['FIELDS']=new ocp_tempcode();
$map['FIELDS_TABLE']=new ocp_tempcode();
$map['fields']=$fields;
$fields_1d=array();
$fields_2d=array();
$all_visible=true;
require_code('fields');
foreach ($fields as $i=>$field)
{
if (!array_key_exists('effective_value',$field))
{
$all_visible=false;
continue;
}
$ev=$field['effective_value'];
$dereference_ev=is_object($field['effective_value'])?$field['effective_value']->evaluate():$field['effective_value'];
$use_ev=$dereference_ev;
/*if (($field['cf_visible']==1) || ($i==0) || ($order_by===$i)) // If it's visible, or if it is the first (name) field, or if it is our order field Actually we always want the data even if it's not visible, especially for catalogues */
{
$ob=get_fields_hook($field['cf_type']);
$use_ev=$ob->render_field_value($field,$ev,$i,$only_fields);
if (($i==0) && ($catalogue['c_display_type']==1))
{
//$use_ev=hyperlink(build_url(array('page'=>'catalogues','type'=>'entry','id'=>$id,'root'=>$root),get_module_zone('catalogues')),$ev,false,!is_object($ev));
$use_ev=$ev;
}
//Set image thumbnail in to the map array
if($field['cf_type']=='picture')
{
if((!is_null($ev)) && ($dereference_ev!=''))
{
require_code('images');
$map['FIELD_'.strval($i).'_THUMB']=do_image_thumb($dereference_ev,($i==0)?'':(is_object($map['FIELD_0'])?$map['FIELD_0']->evaluate():$map['FIELD_0']),false,false,100,100);
} else
{
$map['FIELD_'.strval($i).'_THUMB']= new ocp_tempcode();
}
$map['_FIELD_'.strval($field['id']).'_THUMB']=$map['FIELD_'.strval($i).'_THUMB'];
}
$map['FIELD_'.strval($i)]=$use_ev;
$map['_FIELD_'.strval($field['id'])]=$use_ev;
$map['FIELD_'.strval($i).'_PLAIN']=$ev;
$map['_FIELD_'.strval($field['id']).'_PLAIN']=$ev;
if (array_key_exists('effective_value_pure',$field))
{
$map['FIELD_'.strval($i).'_PURE']=$field['effective_value_pure'];
$map['_FIELD_'.strval($field['id']).'_PURE']=$field['effective_value_pure'];
}
$field_name=get_translated_text($field['cf_name']);
$map['FIELDNAME_'.strval($i)]=$field_name;
$fields_2d[]=array('NAME'=>$field_name,'VALUE'=>$use_ev);
$field_type=$field['cf_type'];
$map['FIELDTYPE_'.strval($i)]=$field_type;
if (($view_type=='PAGE') || (($field['cf_put_in_category']==1) && ($view_type=='CATEGORY')) || (($field['cf_put_in_search']==1) && ($view_type=='SEARCH')))
{
$use_ev_enhanced=$use_ev;
/*if (($view_type!='PAGE') && ($i==0) && (($field['cf_type']=='short_trans') || ($field['cf_type']=='short_text')))
{
foreach ($fields as $field_temp)
{
if ((array_key_exists('effective_value',$field_temp)) && ($field_temp['cf_type']=='url') && (!((($field_temp['cf_put_in_category']==1) && ($view_type=='CATEGORY')) || (($field_temp['cf_put_in_search']==1) && ($view_type=='SEARCH')))) && ($field_temp['cf_visible']==1))
{
if ($field_temp['effective_value']!='')
{
$use_ev_enhanced=hyperlink($field_temp['effective_value'],$use_ev,true);
break;
}
}
}
}*/
if (($field['cf_visible']==1) || ($i==0))
{
$_field=do_template('CATALOGUE_'.$tpl_set.'_ENTRY_FIELD',array('ENTRYID'=>strval($id),'CATALOGUE'=>$catalogue_name,'TYPE'=>$field['cf_type'],'FIELD'=>$field_name,'FIELDID'=>strval($i),'_FIELDID'=>strval($field['id']),'FIELDTYPE'=>$field_type,'VALUE_PLAIN'=>$ev,'VALUE'=>$use_ev_enhanced),NULL,false,'CATALOGUE_DEFAULT_ENTRY_FIELD');
if ((!is_string($ev)) || ($ev!='')) $map['FIELDS']->attach($_field);
$_field=do_template('CATALOGUE_'.$tpl_set.'_TAB_FIELD',array('ENTRYID'=>strval($id),'CATALOGUE'=>$catalogue_name,'TYPE'=>$field['cf_type'],'FIELD'=>$field_name,'FIELDID'=>strval($i),'_FIELDID'=>strval($field['id']),'FIELDTYPE'=>$field_type,'VALUE_PLAIN'=>$ev,'VALUE'=>$use_ev_enhanced),NULL,false,'CATALOGUE_DEFAULT_TAB_FIELD');
$map['FIELDS_TABLE']->attach($_field);
}
} else $all_visible=false;
$fields_1d[]=$field;
}
if (!(($field['cf_visible']==1) || ($i==0) || ($order_by===$i))) $all_visible=false;
}
$map['FIELDS_1D']=$fields_1d;
$map['FIELDS_2D']=$fields_2d;
// Admin functions
if ((has_actual_page_access(NULL,'cms_catalogues',NULL,NULL)) && (has_edit_permission('mid',get_member(),$entry['ce_submitter'],'cms_catalogues',array('catalogues_catalogue',$catalogue_name,'catalogues_category',$entry['cc_id']))))
{
$map['EDIT_URL']=build_url(array('page'=>'cms_catalogues','type'=>'_edit_entry','catalogue_name'=>$catalogue_name,'id'=>$id),get_module_zone('cms_catalogues'));
} else $map['EDIT_URL']='';
$map['SUBMITTER']=strval($entry['ce_submitter']);
$map['VIEWS']=strval($entry['ce_views']);
$map['ADD_DATE_RAW']=strval($entry['ce_add_date']);
$map['EDIT_DATE_RAW']=is_null($entry['ce_edit_date'])?'':strval($entry['ce_edit_date']);
$map['ADD_DATE']=get_timezoned_date($entry['ce_add_date']);
$map['EDIT_DATE']=get_timezoned_date($entry['ce_edit_date']);
$map['ID']=strval($id);
if ((get_option('is_on_comments')=='1') && (!has_no_forum()) && ($entry['allow_comments']>=1)) $map['COMMENT_COUNT']='1';
// Feedback
//Set basic rating display of item to the map array
require_code('feedback');
$c_value=array_key_exists('FIELD_0_PLAIN_PURE',$map)?$map['FIELD_0_PLAIN_PURE']:$map['FIELD_0_PLAIN'];
if (is_object($c_value)) $c_value=$c_value->evaluate();
$self_url=build_url(array('page'=>'catalogues','type'=>'entry','id'=>$id),get_module_zone('catalogues'),NULL,false,false,true);
if (($feedback_details) || ($only_fields!==array(0)))
{
$map['RATING']=($entry['allow_rating']==1)?display_rating($self_url,$c_value,'catalogues',strval($id),'RATING_INLINE_STATIC',$entry['ce_submitter']):new ocp_tempcode();
}
if ($feedback_details)
{
list($map['RATING_DETAILS'],$map['COMMENT_DETAILS'],$map['TRACKBACK_DETAILS'])=embed_feedback_systems(
'catalogues__'.$catalogue_name,
strval($id),
$entry['allow_rating'],
$entry['allow_comments'],
$entry['allow_trackbacks'],
$entry['ce_validated'],
$entry['ce_submitter'],
$self_url,
$c_value,
get_value('comment_forum__catalogues__'.$catalogue_name)
);
}
if ((get_option('is_on_comments')=='1') && ($entry['allow_comments']>=1) || (get_option('is_on_rating')=='1') && ($entry['allow_rating']==1) || (get_option('is_on_trackbacks')=='1') && ($entry['allow_trackbacks']==1) || (!$all_visible))
{
$map['VIEW_URL']=($tpl_set=='WML')?make_string_tempcode('wap.php?page=catalogues&type=entry&id='.strval($id)):build_url(array('page'=>'catalogues','type'=>'entry','id'=>$id,'root'=>($root==-1)?NULL:$root),get_module_zone('catalogues'));
} else
{
$map['VIEW_URL']='';
}
if ($tree_details)
{
$map['TREE']='';
if (($catalogue['c_is_tree']==1) && (is_null($only_fields)))
{
$tree=catalogue_category_breadcrumbs($entry['cc_id'],$root,false);
$map['TREE']=$tree;
}
}
$map['CATALOGUE']=$catalogue_name;
$map['CAT']=strval($entry['cc_id']);
return $map;
}
tempcode nice_get_catalogues(?ID_TEXT it, boolean prefer_ones_with_entries, boolean only_submittable)
Get a nice, formatted, XHTML list of all the catalogues.
Parameters…
| Name |
it |
| Description |
The name of the currently selected catalogue (NULL: none selected) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
prefer_ones_with_entries |
| Description |
If there are too many to list prefer to get ones with entries rather than just the newest |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
only_submittable |
| Description |
Whether to only show catalogues that can be submitted to |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Catalogue selection list |
| Type |
tempcode |
function nice_get_catalogues($it=NULL,$prefer_ones_with_entries=false,$only_submittable=false)
{
$query='SELECT c.* FROM '.get_table_prefix().'catalogues c';
if ($prefer_ones_with_entries)
{
if (can_arbitrary_groupby())
$query.=' JOIN '.get_table_prefix().'catalogue_entries e ON e.c_name=c.c_name GROUP BY c.c_name';
}
$query.=' ORDER BY c_add_date DESC';
$rows=$GLOBALS['SITE_DB']->query($query,100/*reasonable limit*/);
if (count($rows)==100) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__ALPHABETICAL',escape_html(integer_format(100))),'warn');
$out=new ocp_tempcode();
foreach ($rows as $row)
{
if (!has_category_access(get_member(),'catalogues_catalogue',$row['c_name'])) continue;
if (($only_submittable) && (!has_specific_permission(get_member(),'submit_midrange_content','cms_catalogues',array('catalogues_catalogue',$row['c_name'])))) continue;
if (($row['c_ecommerce']==0) || (addon_installed('shopping')))
{
$selected=($row['c_name']==$it);
$out->attach(form_input_list_entry($row['c_name'],$selected,get_translated_text($row['c_title'])));
}
}
return $out;
}
array get_catalogue_entry_field_values(?ID_TEXT catalogue_name, mixed entry_id, ?array only_fields, ?array fields, boolean natural_order)
Get the values for the specified fields, for the stated catalogue entry.
Parameters…
| Name |
catalogue_name |
| Description |
The catalogue name we are getting an entry in (NULL: lookup) |
| Type |
?ID_TEXT |
| Name |
entry_id |
| Description |
The ID of the entry we are getting OR the row |
| Type |
mixed |
| Name |
only_fields |
| Description |
A list of fields that we are limiting ourselves to (NULL: get ALL fields) |
| Default value |
|
| Type |
?array |
| Name |
fields |
| Description |
The database rows for the fields for this catalogue (NULL: find them) |
| Default value |
|
| Type |
?array |
| Name |
natural_order |
| Description |
Whether to order the fields in their natural database order |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A list of maps (each field for the entry gets a map), where each map contains 'effective_value' (the value for the field). Some maps get additional fields (effective_value_nontrans, effective_value_pure), depending on the field type |
| Type |
array |
function get_catalogue_entry_field_values($catalogue_name,$entry_id,$only_fields=NULL,$fields=NULL,$natural_order=false)
{
global $CAT_FIELDS_CACHE;
if (is_null($fields))
{
if ((isset($CAT_FIELDS_CACHE[$catalogue_name])) && (!$natural_order))
{
$fields=$CAT_FIELDS_CACHE[$catalogue_name];
} else
{
if (is_null($catalogue_name)) $catalogue_name=$GLOBALS['SITE_DB']->query_value('catalogue_entries','c_name',array('id'=>$entry_id));
$fields=$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('*'),array('c_name'=>$catalogue_name),'ORDER BY '.($natural_order?'id':'cf_order'));
}
}
if (!$natural_order)
$CAT_FIELDS_CACHE[$catalogue_name]=$fields;
require_code('fields');
foreach ($fields as $i=>$field)
{
$field_id=$field['id'];
if ((!is_null($only_fields)) && (!in_array($i,$only_fields))) continue;
$ob=get_fields_hook($field['cf_type']);
list($raw_type,,$type)=$ob->get_field_value_row_bits($field);
if (is_null($raw_type)) $raw_type=$field['cf_type'];
switch ($raw_type)
{
case 'short_trans':
$fields[$i]['effective_value_nontrans']=_get_catalogue_entry_field($field_id,$entry_id,'short_trans');
if (is_null($fields[$i]['effective_value_nontrans']))
{
$fields[$i]['effective_value']=do_lang_tempcode('INTERNAL_ERROR');
$fields[$i]['effective_value_pure']=do_lang('INTERNAL_ERROR');
break;
}
$fields[$i]['effective_value']=get_translated_tempcode($fields[$i]['effective_value_nontrans']);
$fields[$i]['effective_value_pure']=get_translated_text($fields[$i]['effective_value_nontrans']);
break;
case 'long_trans':
$fields[$i]['effective_value_nontrans']=_get_catalogue_entry_field($field_id,$entry_id,'long_trans');
if (is_null($fields[$i]['effective_value_nontrans']))
{
$fields[$i]['effective_value']=do_lang_tempcode('INTERNAL_ERROR');
$fields[$i]['effective_value_pure']=do_lang('INTERNAL_ERROR');
break;
}
$fields[$i]['effective_value']=get_translated_tempcode($fields[$i]['effective_value_nontrans']);
$fields[$i]['effective_value_pure']=get_translated_text($fields[$i]['effective_value_nontrans']);
break;
case 'long_text':
$fields[$i]['effective_value_pure']=_get_catalogue_entry_field($field_id,$entry_id,'long');
$fields[$i]['effective_value']=$fields[$i]['effective_value_pure'];
if (is_null($fields[$i]['effective_value']))
{
$fields[$i]['effective_value']=do_lang_tempcode('INTERNAL_ERROR');
$fields[$i]['effective_value_pure']=do_lang('INTERNAL_ERROR');
break;
}
break;
case 'short_text':
$fields[$i]['effective_value_pure']=_get_catalogue_entry_field($field_id,$entry_id);
$fields[$i]['effective_value']=$fields[$i]['effective_value_pure'];
if (is_null($fields[$i]['effective_value']))
{
$fields[$i]['effective_value']=do_lang_tempcode('NA_EM');
$fields[$i]['effective_value_pure']=do_lang('NA');
break;
}
break;
case 'long_unescaped':
$fields[$i]['effective_value']=_get_catalogue_entry_field($field_id,$entry_id,'long');
if (is_null($fields[$i]['effective_value']))
{
$fields[$i]['effective_value']=do_lang_tempcode('NA_EM');
$fields[$i]['effective_value_pure']=do_lang('NA');
break;
}
break;
case 'short_unescaped':
case 'float_unescaped':
case 'integer_unescaped':
$fields[$i]['effective_value']=_get_catalogue_entry_field($field_id,$entry_id,$type);
if (is_null($fields[$i]['effective_value']))
{
$fields[$i]['effective_value']=do_lang_tempcode('NA_EM');
$fields[$i]['effective_value_pure']=do_lang('NA');
break;
}
break;
default:
warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
}
}
return $fields;
}
string _get_catalogue_entry_field(AUTO_LINK field_id, mixed entry_id, ID_TEXT type)
Get the value for the specified field, for the stated catalogue entry.
Parameters…
| Name |
field_id |
| Description |
The ID of the field we are getting |
| Type |
AUTO_LINK |
| Name |
entry_id |
| Description |
The ID of the entry we are getting for OR the row |
| Type |
mixed |
| Name |
type |
| Description |
The type of field |
| Default value |
short |
| Type |
ID_TEXT |
| Values restricted to |
short long |
Returns…
| Description |
The value |
| Type |
string |
function _get_catalogue_entry_field($field_id,$entry_id,$type='short')
{
if (is_array($entry_id)) $entry_id=$entry_id['id'];
$value=$GLOBALS['SITE_DB']->query_value_null_ok('catalogue_efv_'.$type,'cv_value',array('cf_id'=>$field_id,'ce_id'=>$entry_id));
if (is_integer($value)) $value=strval($value);
if (is_float($value)) $value=float_to_raw_string($value);
return $value;
}
tempcode nice_get_catalogue_entries_tree(ID_TEXT catalogue_name, ?AUTO_LINK it, ?AUTO_LINK submitter, boolean editable_filter)
Get a nice, formatted XHTML list of entries, in catalogue category tree structure
Parameters…
| Name |
catalogue_name |
| Description |
The catalogue name |
| Type |
ID_TEXT |
| Name |
it |
| Description |
The currently selected entry (NULL: none selected) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
submitter |
| Description |
Only show entries submitted by this member (NULL: no filter) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
editable_filter |
| Description |
Whether to only show for what may be edited by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list of entries |
| Type |
tempcode |
function nice_get_catalogue_entries_tree($catalogue_name,$it=NULL,$submitter=NULL,$editable_filter=false)
{
$tree=get_catalogue_entries_tree($catalogue_name,$submitter,NULL,NULL,NULL,NULL,$editable_filter);
$out=''; // XHTMLXHTML
foreach ($tree as $category)
{
foreach ($category['entries'] as $eid=>$etitle)
{
$selected=($eid==$it);
$line=do_template('CATALOGUE_ENTRIES_LIST_LINE',array('_GUID'=>'0ccffeff5b80b1840188b83aaee8d9f2','TREE'=>$category['tree'],'NAME'=>$etitle));
$out.='<option value="'.strval($eid).'"'.($selected?'selected="selected"':'').'>'.$line->evaluate().'</option>';
}
}
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($out);
return make_string_tempcode($out);
}
array get_catalogue_entries_tree(ID_TEXT catalogue_name, ?AUTO_LINK submitter, ?AUTO_LINK category_id, ?string tree, ?ID_TEXT title, ?integer levels, boolean editable_filter)
Get a list of maps containing all the catalogue entries, and path information, under the specified category - and those beneath it, recursively.
Parameters…
| Name |
catalogue_name |
| Description |
The catalogue name |
| Type |
ID_TEXT |
| Name |
submitter |
| Description |
Only show entries submitted by this member (NULL: no filter) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
category_id |
| Description |
The category being at the root of our recursion (NULL: true root) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
tree |
| Description |
The tree up to this point in the recursion (NULL: blank, as we are starting the recursion) |
| Default value |
|
| Type |
?string |
| Name |
title |
| Description |
The name of the $category_id we are currently going through (NULL: look it up). This is here for efficiency reasons, as finding children IDs to recurse to also reveals the childs title |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
levels |
| Description |
The number of recursive levels to search (NULL: all) |
| Default value |
|
| Type |
?integer |
| Name |
editable_filter |
| Description |
Whether to only show for what may be edited by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A list of maps for all categories. Each map entry containins the fields 'id' (category ID) and 'tree' (tree path to the category, including the categories own title), and more. |
| Type |
array |
function get_catalogue_entries_tree($catalogue_name,$submitter=NULL,$category_id=NULL,$tree=NULL,$title=NULL,$levels=NULL,$editable_filter=false)
{
if ((is_null($category_id)) && (is_null($levels)))
{
if ($GLOBALS['SITE_DB']->query_value('catalogue_categories','COUNT(*)',array('c_name'=>$catalogue_name))>10000) return array(); // Too many!
}
if (is_null($category_id))
{
$is_tree=$GLOBALS['SITE_DB']->query_value_null_ok('catalogues','c_is_tree',array('c_name'=>$catalogue_name),'',1);
if (is_null($is_tree)) return array();
if ($is_tree==0)
{
$temp_rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('id','cc_title'),array('c_name'=>$catalogue_name,'cc_parent_id'=>NULL),'ORDER BY id DESC',300/*reasonable limit to stop it dying*/);
if (get_page_name()=='cms_catalogues')
{
if (count($temp_rows)==300) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY',escape_html(integer_format(300))),'warn');
}
$children=array();
foreach ($temp_rows as $row)
{
$children=array_merge(get_catalogue_entries_tree($catalogue_name,$submitter,$row['id'],NULL,get_translated_text($row['cc_title']),1,$editable_filter),$children);
}
return $children;
}
$temp_rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('id','cc_title'),array('c_name'=>$catalogue_name,'cc_parent_id'=>NULL),'ORDER BY id',1);
if (!array_key_exists(0,$temp_rows)) return array();
$category_id=$temp_rows[0]['id'];
$title=get_translated_text($temp_rows[0]['cc_title']);
}
if (is_null($tree)) $tree='';
if (!has_category_access(get_member(),'catalogues_catalogue',$catalogue_name)) return array();
if ((get_value('disable_cat_cat_perms')!=='1') && (!has_category_access(get_member(),'catalogues_category',strval($category_id)))) return array();
// Put our title onto our tree
if (is_null($title)) $title=get_translated_text($GLOBALS['SITE_DB']->query_value('catalogue_categories','cc_title',array('id'=>$category_id)));
$tree.=$title;
// We'll be putting all children in this entire tree into a single list
$children=array();
$children[0]=array();
$children[0]['id']=$category_id;
$children[0]['title']=$title;
$children[0]['tree']=$tree;
// Children of this category
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('id','cc_title'),array('cc_parent_id'=>$category_id),'',300/*reasonable limit to stop it dying*/);
if (get_page_name()=='cms_catalogues')
{
if (count($rows)==300) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY',escape_html(integer_format(300))),'warn');
}
$where=array('cc_id'=>$category_id);
if (!is_null($submitter)) $where['ce_submitter']=$submitter;
$erows=$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('id','ce_submitter'),$where,'ORDER BY ce_add_date DESC',1000/*reasonable limit*/);
if (get_page_name()=='cms_catalogues')
{
if (count($erows)==300) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY',escape_html(integer_format(300))),'warn');
}
$children[0]['entries']=array();
foreach ($erows as $row)
{
if (($editable_filter) && (!has_edit_permission('mid',get_member(),$row['ce_submitter'],'cms_catalogues',array('catalogues_catalogue',$catalogue_name,'catalogues_category',$category_id)))) continue;
$entry_fields=get_catalogue_entry_field_values($catalogue_name,$row['id'],array(0));
$name=$entry_fields[0]['effective_value']; // 'Name' is value of first field
$children[0]['entries'][$row['id']]=$name;
}
$children[0]['child_entry_count']=count($children[0]['entries']);
if ($levels===0) // We throw them away now because they're not on the desired level
{
$children[0]['entries']=array();
}
$children[0]['child_count']=count($rows);
$tree.=' > ';
if ($levels!==0)
{
foreach ($rows as $i=>$child)
{
$rows[$i]['_cc_title']=get_translated_text($child['cc_title']);
}
global $M_SORT_KEY;
$M_SORT_KEY='_cc_title';
usort($rows,'multi_sort');
foreach ($rows as $child)
{
$child_id=$child['id'];
$child_title=$child['_cc_title'];
$child_tree=$tree;
$child_children=get_catalogue_entries_tree($catalogue_name,$submitter,$child_id,$child_tree,$child_title,is_null($levels)?NULL:($levels-1),$editable_filter);
$children=array_merge($children,$child_children);
}
}
return $children;
}
tempcode nice_get_catalogue_category_tree(ID_TEXT catalogue_name, ?AUTO_LINK it, boolean addable_filter, boolean use_compound_list)
Get a nice, formatted XHTML list extending from the root, and showing all subcategories, and their subcategories (ad infinitum). The tree bit is because each entry in the list is shown to include the path through the tree that gets to it
Parameters…
| Name |
catalogue_name |
| Description |
The catalogue name |
| Type |
ID_TEXT |
| Name |
it |
| Description |
The currently selected entry (NULL: none) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
addable_filter |
| Description |
Whether to only show for what may be added to by the current member |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
use_compound_list |
| Description |
Whether to make the list elements store comma-separated child lists instead of IDs |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list of categories |
| Type |
tempcode |
function nice_get_catalogue_category_tree($catalogue_name,$it=NULL,$addable_filter=false,$use_compound_list=false)
{
if ($GLOBALS['SITE_DB']->query_value('catalogue_categories','COUNT(*)',array('c_name'=>$catalogue_name))>10000) return new ocp_tempcode(); // Too many!
$tree=array();
$temp_rows=$GLOBALS['SITE_DB']->query('SELECT id,cc_title FROM '.get_table_prefix().'catalogue_categories WHERE '.db_string_equal_to('c_name',$catalogue_name).' AND cc_parent_id IS NULL ORDER BY id DESC',300/*reasonable limit to stop it dying*/);
if (count($temp_rows)==300) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY',escape_html(integer_format(300))),'warn');
foreach ($temp_rows as $row)
{
$category_id=$row['id'];
$title=get_translated_text($row['cc_title']);
$subtree=get_catalogue_category_tree($catalogue_name,$category_id,NULL,$title,NULL,$addable_filter,$use_compound_list);
if (($use_compound_list) && (array_key_exists(0,$subtree))) $subtree=$subtree[0];
$tree=array_merge($tree,$subtree);
}
$out=new ocp_tempcode();
foreach ($tree as $category)
{
if (($addable_filter) && (!$category['addable'])) continue;
$selected=($category['id']==$it);
$line=do_template('CATALOGUE_CATEGORIES_LIST_LINE',array('_GUID'=>'9f6bfc4f28c154c8f5d8887ce0d47c1c','TREE'=>$category['tree'],'COUNT'=>integer_format($category['count'])));
$out->attach(form_input_list_entry(!$use_compound_list?strval($category['id']):$category['compound_list'],$selected,$line->evaluate()));
}
return $out;
}
array get_catalogue_category_tree(ID_TEXT catalogue_name, ?AUTO_LINK category_id, ?tempcode tree, ?string title, ?integer levels, boolean addable_filter, boolean use_compound_list)
Get a list of maps containing all the subcategories, and path information, of the specified category - and those beneath it, recursively.
Parameters…
| Name |
catalogue_name |
| Description |
The catalogue name |
| Type |
ID_TEXT |
| Name |
category_id |
| Description |
The category being at the root of our recursion (NULL: true root category) |
| Type |
?AUTO_LINK |
| Name |
tree |
| Description |
The tree up to this point in the recursion (NULL: blank, as we are starting the recursion) |
| Default value |
|
| Type |
?tempcode |
| Name |
title |
| Description |
The category name of the $category_id we are currently going through (NULL: look it up). This is here for efficiency reasons, as finding children IDs to recurse to also reveals the childs title |
| Default value |
|
| Type |
?string |
| Name |
levels |
| Description |
The number of recursive levels to search (NULL: all) |
| Default value |
|
| Type |
?integer |
| Name |
addable_filter |
| Description |
Whether to only show for what may be added to by the current member |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
use_compound_list |
| Description |
Whether to make the list elements store comma-separated child lists instead of IDs |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A list of maps for all subcategories. Each map entry containins the fields 'id' (category ID) and 'tree' (tree path to the category, including the categories own title), and 'count' (the number of entries in the category). |
| Type |
array |
function get_catalogue_category_tree($catalogue_name,$category_id,$tree=NULL,$title=NULL,$levels=NULL,$addable_filter=false,$use_compound_list=false)
{
if ($levels==-1) return array();
if (!has_category_access(get_member(),'catalogues_catalogue',$catalogue_name)) return array();
if ((!is_null($category_id)) && (get_value('disable_cat_cat_perms')!=='1') && (!has_category_access(get_member(),'catalogues_category',strval($category_id)))) return array();
if (is_null($tree)) $tree=new ocp_tempcode();
// Put our title onto our tree
if (is_null($title))
{
if (is_null($category_id))
{
$_title=$GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories','cc_title',array('id'=>$category_id));
} else
{
$_title=$GLOBALS['SITE_DB']->query_value('catalogue_categories','cc_title',array('id'=>$category_id));
}
$title=is_null($_title)?do_lang('HOME'):get_translated_text($_title);
}
$tree->attach($title);
// We'll be putting all children in this entire tree into a single list
$children=array();
$is_tree=$GLOBALS['SITE_DB']->query_value_null_ok('catalogues','c_is_tree',array('c_name'=>$catalogue_name));
if (is_null($is_tree)) warn_exit(do_lang_tempcode('_MISSING_RESOURCE','catalogue:'.escape_html($catalogue_name)));
if ((!is_null($category_id))/* || ($is_tree==1)*/)
{
$children[0]['id']=$category_id;
$children[0]['title']=$title;
$children[0]['tree']=$tree;
$children[0]['compound_list']=strval($category_id).',';
$children[0]['count']=$GLOBALS['SITE_DB']->query_value('catalogue_entries','COUNT(*)',array('cc_id'=>$category_id));
if ($addable_filter) $children[0]['addable']=has_submit_permission('mid',get_member(),get_ip_address(),'cms_catalogues',array('catalogues_catalogue',$catalogue_name,'catalogues_category',$category_id));
}
// Children of this category
$tree2=new ocp_tempcode();
$tree2->attach($tree);
$tree2->attach(do_template('BREADCRUMB'));
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('id','cc_title'),array('c_name'=>$catalogue_name,'cc_parent_id'=>$category_id),'ORDER BY id DESC',300/*reasonable limit to stop it dying*/);
foreach ($rows as $i=>$child)
{
$rows[$i]['text_original']=get_translated_text($child['cc_title']);
}
if (get_page_name()=='cms_catalogues')
{
if (count($rows)==300) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY',escape_html(integer_format(300))),'warn');
}
global $M_SORT_KEY;
$M_SORT_KEY='text_original';
usort($rows,'multi_sort');
$no_root=!array_key_exists(0,$children);
if (!$no_root) $children[0]['child_count']=count($rows);
if ($levels!==0)
{
foreach ($rows as $child)
{
$child_id=$child['id'];
$child_title=$child['text_original'];
$child_tree=new ocp_tempcode();
$child_tree->attach($tree2);
$child_children=get_catalogue_category_tree($catalogue_name,$child_id,$child_tree,$child_title,is_null($levels)?NULL:($levels-1),$addable_filter,$use_compound_list);
if ($child_children!=array())
{
if ($use_compound_list)
{
list($child_children,$_compound_list)=$child_children;
if (!$no_root) $children[0]['compound_list'].=$_compound_list;
}
$children=array_merge($children,$child_children);
}
}
}
return $use_compound_list?array($children,$no_root?'':$children[0]['compound_list']):$children;
}
tempcode catalogue_category_breadcrumbs(AUTO_LINK category_id, ?AUTO_LINK root, boolean no_link_for_me_sir)
Get a formatted XHTML string of the route back to the specified root, from the specified category.
Parameters…
| Name |
category_id |
| Description |
The category we are finding for |
| Type |
AUTO_LINK |
| Name |
root |
| Description |
The root of the tree (NULL: the true root) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
no_link_for_me_sir |
| Description |
Whether to include category links at this level (the recursed levels will always contain links - the top level is optional, hence this parameter) |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The tree route |
| Type |
tempcode |
function catalogue_category_breadcrumbs($category_id,$root=NULL,$no_link_for_me_sir=true)
{
$map=array('page'=>'catalogues','type'=>'category','id'=>$category_id);
if (!is_null($root)) $map['root']=$root;
$url=build_url($map,get_module_zone('catalogues'));
if (is_null($category_id)) return new ocp_tempcode();
if (($category_id!=$root) || (!$no_link_for_me_sir))
{
global $PT_PAIR_CACHE;
if (!array_key_exists($category_id,$PT_PAIR_CACHE))
{
$category_rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('cc_parent_id','cc_title'),array('id'=>$category_id),'',1);
if (!array_key_exists(0,$category_rows)) fatal_exit(do_lang_tempcode('CAT_NOT_FOUND',escape_html(strval($category_id))));
$PT_PAIR_CACHE[$category_id]=$category_rows[0];
}
if ($PT_PAIR_CACHE[$category_id]['cc_parent_id']==$category_id) fatal_exit(do_lang_tempcode('RECURSIVE_TREE_CHAIN',escape_html(strval($category_id))));
}
if ($category_id==$root)
{
$below=new ocp_tempcode();
} else
{
$below=catalogue_category_breadcrumbs($PT_PAIR_CACHE[$category_id]['cc_parent_id'],$root,false);
}
if (!$no_link_for_me_sir)
{
$title=get_translated_text($PT_PAIR_CACHE[$category_id]['cc_title']);
if (!$below->is_empty()) $tpl_url=do_template('BREADCRUMB_ESCAPED'); else $tpl_url=new ocp_tempcode();
$tpl_url->attach(hyperlink($url,escape_html($title),false,false,do_lang_tempcode('GO_BACKWARDS_TO',$title),NULL,NULL,'up'));
} else $tpl_url=new ocp_tempcode();
$below->attach($tpl_url);
return $below;
}
boolean is_ecommerce_catalogue(SHORT_TEXT catalogue_name)
Check the current catalogue is an ecommerce catalogue
Parameters…
| Name |
catalogue_name |
| Description |
Catalogue name |
| Type |
SHORT_TEXT |
Returns…
| Description |
Status of ecommerce catalogue check |
| Type |
boolean |
function is_ecommerce_catalogue($catalogue_name)
{
if (!addon_installed('ecommerce')) return false;
if (!addon_installed('shopping')) return false;
if (is_null($GLOBALS['SITE_DB']->query_value_null_ok('catalogues','c_name',array('c_name'=>$catalogue_name,'c_ecommerce'=>1))))
return false;
else
return true;
}
boolean is_ecommerce_catalogue_entry(AUTO_LINK entry_id)
Check selected entry is an ecommerce catalogue entry
Parameters…
| Name |
entry_id |
| Description |
Entry ID |
| Type |
AUTO_LINK |
Returns…
| Description |
Status of entry type check |
| Type |
boolean |
function is_ecommerce_catalogue_entry($entry_id)
{
$catalogue_name=$GLOBALS['SITE_DB']->query_value('catalogue_entries','c_name',array('id'=>$entry_id));
return is_ecommerce_catalogue($catalogue_name);
}
tempcode render_catalogue_entry_screen(AUTO_LINK id, boolean no_title)
Display a catalogue entry
Parameters…
| Name |
id |
| Description |
Entry ID |
| Type |
AUTO_LINK |
| Name |
no_title |
| Description |
Whether to skip rendering a title |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Tempcode interface to display an entry |
| Type |
tempcode |
function render_catalogue_entry_screen($id,$no_title=false)
{
require_code('feedback');
if (addon_installed('ecommerce'))
{
require_code('ecommerce');
}
require_code('images');
require_css('catalogues');
require_lang('catalogues');
$entries=$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('*'),array('id'=>$id),'',1);
if (!array_key_exists(0,$entries))
{
return warn_screen(get_page_title('CATALOGUES'),do_lang_tempcode('MISSING_RESOURCE'));
}
$entry=$entries[0];
$categories=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('*'),array('id'=>$entry['cc_id']),'',1);
if (!array_key_exists(0,$categories)) warn_exit(do_lang_tempcode('CAT_NOT_FOUND',strval($entry['cc_id'])));
$category=$categories[0];
$GLOBALS['FEED_URL']=find_script('backend').'?mode=catalogues&filter='.strval($entry['cc_id']);
$catalogue_name=$category['c_name'];
$catalogues=$GLOBALS['SITE_DB']->query_select('catalogues',array('*'),array('c_name'=>$catalogue_name),'',1);
if (!array_key_exists(0,$catalogues)) warn_exit(do_lang_tempcode('CATALOGUE_NOT_FOUND',$catalogue_name));
$catalogue=$catalogues[0];
// Permission for here?
if (!has_category_access(get_member(),'catalogues_catalogue',$catalogue_name))
{
access_denied('CATALOGUE_ACCESS');
}
if ((get_value('disable_cat_cat_perms')!=='1') && (!has_category_access(get_member(),'catalogues_category',strval($entry['cc_id']))))
{
access_denied('CATEGORY_ACCESS');
}
$ecommerce=is_ecommerce_catalogue($catalogue_name);
if($ecommerce)
$tpl_set = 'products';
else
$tpl_set = $catalogue_name;
$root=get_param_integer('root',NULL);
$map=get_catalogue_entry_map($entry,$catalogue,'PAGE',$tpl_set,$root,NULL,NULL,true,true);
if (get_db_type()!='xml')
{
$entry['ce_views']++;
$GLOBALS['SITE_DB']->query_update('catalogue_entries',array('ce_views'=>$entry['ce_views']),array('id'=>$id),'',1);
}
// Validation
if ($entry['ce_validated']==0)
{
if (!has_specific_permission(get_member(),'jump_to_unvalidated'))
access_denied('SPECIFIC_PERMISSION','jump_to_unvalidated');
$map['WARNINGS']=do_template('WARNING_TABLE',array('_GUID'=>'bf604859a572ca53e969bec3d91f9cfb','WARNING'=>do_lang_tempcode((get_param_integer('redirected',0)==1)?'UNVALIDATED_TEXT_NON_DIRECT':'UNVALIDATED_TEXT')));
} else $map['WARNINGS']='';
//Finding any hook exists for this product--------------------
if (addon_installed('ecommerce'))
{
$object=find_product(strval($id));
if (is_object($object) && method_exists($object,'get_custom_product_map_fields'))
{
$object->get_custom_product_map_fields($id,$map);
}
}
//------------------------------------------------------------
$map['ENTRY']=do_template('CATALOGUE_'.$tpl_set.'_ENTRY',$map,NULL,false,'CATALOGUE_DEFAULT_ENTRY');
$map['ADD_DATE']=get_timezoned_date($entry['ce_add_date']);
$map['ADD_DATE_RAW']=strval($entry['ce_add_date']);
$map['EDIT_DATE']=is_null($entry['ce_edit_date'])?'':get_timezoned_date($entry['ce_edit_date']);
$map['EDIT_DATE_RAW']=is_null($entry['ce_edit_date'])?'':strval($entry['ce_edit_date']);
$map['VIEWS']=integer_format($entry['ce_views']);
$title_to_use=do_lang_tempcode($catalogue_name.'__CATALOGUE_ENTRY',$map['FIELD_0']);
$title_to_use_2=do_lang($catalogue_name.'__CATALOGUE_ENTRY',$map['FIELD_0_PLAIN'],NULL,NULL,NULL,false);
if (is_null($title_to_use_2))
{
$title_to_use=do_lang_tempcode('DEFAULT__CATALOGUE_ENTRY',$map['FIELD_0']);
$title_to_use_2=do_lang('DEFAULT__CATALOGUE_ENTRY',$map['FIELD_0_PLAIN']);
}
if ($no_title)
{
$map['TITLE']=new ocp_tempcode();
} else
{
if (addon_installed('awards'))
{
require_code('awards');
$awards=find_awards_for('catalogue_entry',strval($id));
} else $awards=array();
$map['TITLE']=get_page_title($title_to_use,false,NULL,NULL,$awards);
}
$map['SUBMITTER']=strval($entry['ce_submitter']);
require_code('seo2');
if (is_object($title_to_use_2)) $title_to_use_2=$title_to_use_2->evaluate();
seo_meta_load_for('catalogue_entry',strval($id),strip_tags($title_to_use_2));
if ($map['TREE']==='')
{
$map['TREE']=new ocp_tempcode();
$url=build_url(array('page'=>'_SELF','type'=>'index','id'=>$catalogue_name),'_SELF');
$map['TREE']->attach(hyperlink($url,escape_html(get_translated_text($catalogue['c_title'])),false,false,do_lang('INDEX')));
$map['TREE']->attach(do_template('BREADCRUMB_ESCAPED'));
$url=build_url(array('page'=>'_SELF','type'=>'category','id'=>$category['id']),'_SELF');
$map['TREE']->attach(hyperlink($url,escape_html(get_translated_text($category['cc_title'])),false,false,do_lang('GO_BACKWARDS_TO',get_translated_text($category['cc_title'])),NULL,NULL,'up'));
}
$map['CATEGORY_TITLE']=get_translated_text($category['cc_title']);
$map['CAT']=strval($entry['cc_id']);
$map['TAGS']=get_loaded_tags('catalogue_entries');
breadcrumb_add_segment($map['TREE'],$title_to_use);
if (is_null($root)) breadcrumb_set_parents(array(array('_SELF:_SELF:misc'.($ecommerce?':ecommerce=1':''),do_lang('CATALOGUES'))));
$GLOBALS['META_DATA']+=array(
'created'=>date('Y-m-d',$entry['ce_add_date']),
'creator'=>$GLOBALS['FORUM_DRIVER']->get_username($entry['ce_submitter']),
'publisher'=>'', // blank means same as creator
'modified'=>is_null($entry['ce_edit_date'])?'':date('Y-m-d',$entry['ce_edit_date']),
'type'=>get_translated_text($catalogue['c_title']).' entry',
'title'=>$title_to_use_2,
'identifier'=>'_SEARCH:catalogues:entry:'.strval($id),
'description'=>'',
);
return do_template('CATALOGUE_'.$tpl_set.'_ENTRY_SCREEN',$map,NULL,false,'CATALOGUE_DEFAULT_ENTRY_SCREEN');
}
sources/catalogues2.php
Global_functions_catalogues2.php
Function summary
|
void
|
catalogue_to_tree (ID_TEXT catalogue_name)
|
|
void
|
catalogue_from_tree (ID_TEXT catalogue_name)
|
|
void
|
catalogue_file_script ()
|
|
?AUTO_LINK
|
actual_add_catalogue (ID_TEXT name, mixed title, mixed description, SHORT_INTEGER display_type, BINARY is_tree, LONG_TEXT notes, integer submit_points, BINARY ecommerce, ID_TEXT send_view_reports)
|
|
AUTO_LINK
|
actual_add_catalogue_field (ID_TEXT c_name, mixed name, mixed description, ID_TEXT type, integer order, BINARY defines_order, BINARY visible, BINARY searchable, LONG_TEXT default, BINARY required, BINARY put_in_category, BINARY put_in_search, ?AUTO_LINK id)
|
|
void
|
actual_edit_catalogue (ID_TEXT old_name, ID_TEXT name, SHORT_TEXT title, LONG_TEXT description, SHORT_INTEGER display_type, LONG_TEXT notes, integer submit_points, BINARY ecommerce, ID_TEXT send_view_reports)
|
|
void
|
actual_delete_catalogue (ID_TEXT name)
|
|
void
|
actual_edit_catalogue_field (AUTO_LINK id, ID_TEXT c_name, SHORT_TEXT name, LONG_TEXT description, integer order, BINARY defines_order, BINARY visible, BINARY searchable, LONG_TEXT default, BINARY required, BINARY put_in_category, BINARY put_in_search, ?ID_TEXT type)
|
|
void
|
actual_delete_catalogue_field (AUTO_LINK id)
|
|
AUTO_LINK
|
actual_add_catalogue_category (ID_TEXT catalogue_name, mixed title, mixed description, LONG_TEXT notes, ?AUTO_LINK parent_id, URLPATH rep_image, integer move_days_lower, integer move_days_higher, ?AUTO_LINK move_target, ?TIME add_date, ?AUTO_LINK id)
|
|
void
|
rebuild_catalogue_cat_treecache ()
|
|
void
|
store_in_catalogue_cat_treecache (AUTO_LINK id, ?AUTO_LINK parent_id, boolean cleanup_first)
|
|
void
|
calculate_category_child_count_cache (?AUTO_LINK cat_id, boolean recursive_updates)
|
|
void
|
actual_edit_catalogue_category (AUTO_LINK id, SHORT_TEXT title, LONG_TEXT description, LONG_TEXT notes, ?AUTO_LINK parent_id, SHORT_TEXT meta_keywords, LONG_TEXT meta_description, URLPATH rep_image, integer move_days_lower, integer move_days_higher, ?AUTO_LINK move_target)
|
|
void
|
actual_delete_catalogue_category (AUTO_LINK id, boolean deleting_all)
|
|
AUTO_LINK
|
actual_add_catalogue_entry (AUTO_LINK category_id, BINARY validated, LONG_TEXT notes, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, array map, ?TIME time, ?MEMBER submitter, ?TIME edit_date, integer views, ?AUTO_LINK id)
|
|
void
|
actual_edit_catalogue_entry (AUTO_LINK id, AUTO_LINK category_id, BINARY validated, LONG_TEXT notes, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, array map, ?SHORT_TEXT meta_keywords, ?LONG_TEXT meta_description)
|
|
void
|
actual_delete_catalogue_entry (AUTO_LINK id)
|
void catalogue_to_tree(ID_TEXT catalogue_name)
Converts a non-tree catalogue to a tree catalogue.
Parameters…
| Name |
catalogue_name |
| Description |
Catalogue name |
| Type |
ID_TEXT |
(No return value)
function catalogue_to_tree($catalogue_name)
{
$new_root=actual_add_catalogue_category($catalogue_name,do_lang('ROOT'),'','',NULL,'');
$GLOBALS['SITE_DB']->query('UPDATE '.get_table_prefix().'catalogue_categories SET cc_parent_id='.strval($new_root).' WHERE id<>'.strval($new_root).' AND '.db_string_equal_to('c_name',$catalogue_name));
$GLOBALS['SITE_DB']->query_update('catalogues',array('c_is_tree'=>1),array('c_name'=>$catalogue_name),'',1);
}
void catalogue_from_tree(ID_TEXT catalogue_name)
Converts a non-tree catalogue from a tree catalogue.
Parameters…
| Name |
catalogue_name |
| Description |
Catalogue name |
| Type |
ID_TEXT |
(No return value)
function catalogue_from_tree($catalogue_name)
{
$GLOBALS['SITE_DB']->query_update('catalogue_categories',array('cc_parent_id'=>NULL),array('c_name'=>$catalogue_name));
$GLOBALS['SITE_DB']->query_update('catalogues',array('c_is_tree'=>0),array('c_name'=>$catalogue_name),'',1);
}
void catalogue_file_script()
Farm out the files for catalogue entry fields.
Parameters…
(No return value)
function catalogue_file_script()
{
// Closed site
$site_closed=get_option('site_closed');
if (($site_closed=='1') && (!has_specific_permission(get_member(),'access_closed_site')) && (!$GLOBALS['IS_ACTUALLY_ADMIN']))
{
header('Content-Type: text/plain');
@exit(get_option('closed'));
}
$file=filter_naughty(get_param('file',false,true));
$_full=get_custom_file_base().'/uploads/catalogues/'.filter_naughty(rawurldecode($file));
if (!file_exists($_full)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$size=filesize($_full);
$original_filename=filter_naughty(get_param('original_filename',false,true));
// Send header
if ((strpos($original_filename,chr(10))!==false) || (strpos($original_filename,chr(13))!==false))
log_hack_attack_and_exit('HEADER_SPLIT_HACK');
header('Content-Type: application/octet-stream'.'; authoritative=true;');
if (get_option('immediate_downloads',true)==='1')
{
require_code('mime_types');
header('Content-Type: '.get_mime_type(get_file_extension($original_filename)).'; authoritative=true;');
header('Content-Disposition: filename="'.str_replace(chr(13),'',str_replace(chr(10),'',addslashes($original_filename))).'"');
} else
{
if (strstr(ocp_srv('HTTP_USER_AGENT'),'MSIE')!==false)
header('Content-Disposition: filename="'.str_replace(chr(13),'',str_replace(chr(10),'',addslashes($original_filename))).'"');
else
header('Content-Disposition: attachment; filename="'.str_replace(chr(13),'',str_replace(chr(10),'',addslashes($original_filename))).'"');
}
header('Accept-Ranges: bytes');
// Default to no resume
$from=0;
$new_length=$size;
@ini_set('zlib.output_compression','Off');
// They're trying to resume (so update our range)
$httprange=ocp_srv('HTTP_RANGE');
if (strlen($httprange)>0)
{
$_range=explode('=',ocp_srv('HTTP_RANGE'));
if (count($_range)==2)
{
if (strpos($_range[0],'-')===false) $_range=array_reverse($_range);
$range=$_range[0];
if (substr($range,0,1)=='-') $range=strval($size-intval(substr($range,1))-1).$range;
if (substr($range,-1,1)=='-') $range.=strval($size-1);
$bits=explode('-',$range);
if (count($bits)==2)
{
list($from,$to)=array_map('intval',$bits);
if (($to-$from!=0) || ($from==0)) // Workaround to weird behaviour on Chrome
{
$new_length=$to-$from+1;
header('HTTP/1.1 206 Partial Content');
header('Content-Range: bytes '.$range.'/'.strval($size));
} else
{
$from=0;
}
}
}
}
header('Content-Length: '.strval($new_length));
if (function_exists('set_time_limit')) @set_time_limit(0);
error_reporting(0);
// Send actual data
$myfile=fopen($_full,'rb');
fseek($myfile,$from);
/*if ($size==$new_length) Uses a lot of memory :S
{
fpassthru($myfile);
} else*/
{
$i=0;
flush(); // Works around weird PHP bug that sends data before headers, on some PHP versions
while ($i<$new_length)
{
$content=fread($myfile,min($new_length-$i,1048576));
echo $content;
$len=strlen($content);
if ($len==0) break;
$i+=$len;
}
fclose($myfile);
}
}
?AUTO_LINK actual_add_catalogue(ID_TEXT name, mixed title, mixed description, SHORT_INTEGER display_type, BINARY is_tree, LONG_TEXT notes, integer submit_points, BINARY ecommerce, ID_TEXT send_view_reports)
Add a catalogue using all the specified values.
Parameters…
| Name |
name |
| Description |
The codename of the catalogue |
| Type |
ID_TEXT |
| Name |
title |
| Description |
The title of the catalogue (either language code or string) |
| Type |
mixed |
| Name |
description |
| Description |
A description (either language code or string) |
| Type |
mixed |
| Name |
display_type |
| Description |
The display type |
| Type |
SHORT_INTEGER |
| Name |
is_tree |
| Description |
Whether the catalogue uses a tree system (as opposed to mere categories in an index) |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes pertaining to this catalogue |
| Type |
LONG_TEXT |
| Name |
submit_points |
| Description |
How many points a member gets by submitting to this catalogue |
| Type |
integer |
| Name |
ecommerce |
| Description |
Whether the catalogue is an eCommerce catalogue |
| Default value |
0 |
| Type |
BINARY |
| Name |
send_view_reports |
| Description |
How to send view reports |
| Default value |
never |
| Type |
ID_TEXT |
| Values restricted to |
never daily weekly monthly quarterly |
Returns…
| Description |
The ID of the first new catalogues root category (NULL: no root, as it's not a tree catalogue) |
| Type |
?AUTO_LINK |
function actual_add_catalogue($name,$title,$description,$display_type,$is_tree,$notes,$submit_points,$ecommerce=0,$send_view_reports='never')
{
require_code('type_validation');
if (!is_alphanumeric($name)) warn_exit(do_lang_tempcode('BAD_CODENAME'));
// Check doesn't already exist
$test=$GLOBALS['SITE_DB']->query_value_null_ok('catalogues','c_name',array('c_name'=>$name));
if (!is_null($test)) warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($name)));
// Create
if (!is_integer($description)) $description=insert_lang_comcode($description,2);
if (!is_integer($title)) $title=insert_lang($title,1);
$GLOBALS['SITE_DB']->query_insert('catalogues',array('c_name'=>$name,'c_title'=>$title,'c_send_view_reports'=>$send_view_reports,'c_ecommerce'=>$ecommerce,'c_description'=>$description,'c_display_type'=>$display_type,'c_is_tree'=>$is_tree,'c_notes'=>$notes,'c_add_date'=>time(),'c_submit_points'=>$submit_points));
if ($is_tree==1)
{
// Create root node
$root_title=($display_type==1)?do_lang('_HOME',get_translated_text($title)):get_translated_text($title);
$category=$GLOBALS['SITE_DB']->query_insert('catalogue_categories',array('cc_move_days_lower'=>30,'cc_move_days_higher'=>60,'cc_move_target'=>NULL,'rep_image'=>'','c_name'=>$name,'cc_title'=>insert_lang($root_title,1),'cc_description'=>insert_lang_comcode('',3),'cc_notes'=>'','cc_add_date'=>time(),'cc_parent_id'=>NULL),true);
} else $category=NULL;
log_it('ADD_CATALOGUE',$name);
return $category;
}
AUTO_LINK actual_add_catalogue_field(ID_TEXT c_name, mixed name, mixed description, ID_TEXT type, integer order, BINARY defines_order, BINARY visible, BINARY searchable, LONG_TEXT default, BINARY required, BINARY put_in_category, BINARY put_in_search, ?AUTO_LINK id)
Add a field to the specified catalogue, without disturbing any other data in that catalogue.
Parameters…
| Name |
c_name |
| Description |
The codename of the catalogue the field is for |
| Type |
ID_TEXT |
| Name |
name |
| Description |
The name of the field (either language code or string) |
| Type |
mixed |
| Name |
description |
| Description |
A description (either language code or string) |
| Type |
mixed |
| Name |
type |
| Description |
The type of the field |
| Type |
ID_TEXT |
| Name |
order |
| Description |
The field order (the field order determines what order the fields are displayed within an entry) |
| Type |
integer |
| Name |
defines_order |
| Description |
Whether this field defines the catalogue order |
| Type |
BINARY |
| Name |
visible |
| Description |
Whether this is a visible field |
| Type |
BINARY |
| Name |
searchable |
| Description |
Whether the field is usable as a search key |
| Type |
BINARY |
| Name |
default |
| Description |
The default value for the field |
| Type |
LONG_TEXT |
| Name |
required |
| Description |
Whether this field is required |
| Type |
BINARY |
| Name |
put_in_category |
| Description |
Whether the field is to be shown in category views (not applicable for the list display type) |
| Default value |
1 |
| Type |
BINARY |
| Name |
put_in_search |
| Description |
Whether the field is to be shown in search views (not applicable for the list display type) |
| Default value |
1 |
| Type |
BINARY |
| Name |
id |
| Description |
Force this ID (NULL: auto-increment as normal) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
Field ID |
| Type |
AUTO_LINK |
function actual_add_catalogue_field($c_name,$name,$description,$type,$order,$defines_order,$visible,$searchable,$default,$required,$put_in_category=1,$put_in_search=1,$id=NULL)
{
if (!is_integer($description)) $description=insert_lang($description,2);
if (!is_integer($name)) $name=insert_lang($name,2);
$map=array('c_name'=>$c_name,'cf_name'=>$name,'cf_description'=>$description,'cf_type'=>$type,'cf_order'=>$order,'cf_defines_order'=>$defines_order,'cf_visible'=>$visible,'cf_searchable'=>$searchable,'cf_default'=>$default,'cf_required'=>$required,'cf_put_in_category'=>$put_in_category,'cf_put_in_search'=>$put_in_search);
if (!is_null($id)) $map['id']=$id;
$cf_id=$GLOBALS['SITE_DB']->query_insert('catalogue_fields',$map,true);
if (!is_null($id)) $cf_id=$id;
require_code('fields');
$ob=get_fields_hook($type);
if (function_exists('set_time_limit')) @set_time_limit(0);
// Now add field values for all pre-existing entries (in the ideal world, there would be none yet)
$start=0;
do
{
$entries=collapse_1d_complexity('id',$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('id'),array('c_name'=>$c_name),'',300,$start));
foreach ($entries as $entry)
{
$_default=mixed();
list($raw_type,$_default,$_type)=$ob->get_field_value_row_bits($map+array('id'=>$cf_id),$required==1,$default);
if (strpos($raw_type,'trans')!==false) $_default=intval($_default);
if ($_type=='float')
{
$map=array('cf_id'=>$cf_id,'ce_id'=>$entry,'cv_value'=>((is_null($_default)) || ($_default==''))?NULL:floatval($_default));
}
elseif ($_type=='integer')
{
$map=array('cf_id'=>$cf_id,'ce_id'=>$entry,'cv_value'=>((is_null($_default)) || ($_default==''))?NULL:intval($_default));
} else
{
$map=array('cf_id'=>$cf_id,'ce_id'=>$entry,'cv_value'=>$_default);
}
$GLOBALS['SITE_DB']->query_insert('catalogue_efv_'.$_type,$map);
}
$start+=300;
}
while (array_key_exists(0,$entries));
return $cf_id;
}
void actual_edit_catalogue(ID_TEXT old_name, ID_TEXT name, SHORT_TEXT title, LONG_TEXT description, SHORT_INTEGER display_type, LONG_TEXT notes, integer submit_points, BINARY ecommerce, ID_TEXT send_view_reports)
Edit a catalogue.
Parameters…
| Name |
old_name |
| Description |
The current name of the catalogue |
| Type |
ID_TEXT |
| Name |
name |
| Description |
The new name of the catalogue |
| Type |
ID_TEXT |
| Name |
title |
| Description |
The human readable name/title of the catalogue |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description |
| Type |
LONG_TEXT |
| Name |
display_type |
| Description |
The display type |
| Type |
SHORT_INTEGER |
| Name |
notes |
| Description |
Admin notes |
| Type |
LONG_TEXT |
| Name |
submit_points |
| Description |
How many points are given to a member that submits to the catalogue |
| Type |
integer |
| Name |
ecommerce |
| Description |
Whether the catalogue is an eCommerce catalogue |
| Type |
BINARY |
| Name |
send_view_reports |
| Description |
How to send view reports |
| Type |
ID_TEXT |
| Values restricted to |
never daily weekly monthly quarterly |
(No return value)
function actual_edit_catalogue($old_name,$name,$title,$description,$display_type,$notes,$submit_points,$ecommerce,$send_view_reports)
{
if ($old_name!=$name)
{
// Check doesn't already exist
$test=$GLOBALS['SITE_DB']->query_value_null_ok('catalogues','c_name',array('c_name'=>$name));
if (!is_null($test)) warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($name)));
require_code('type_validation');
if (!is_alphanumeric($name)) warn_exit(do_lang_tempcode('BAD_CODENAME'));
}
$rows=$GLOBALS['SITE_DB']->query_select('catalogues',array('c_description','c_title'),array('c_name'=>$old_name),'',1);
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$myrow=$rows[0];
$_title=$myrow['c_title'];
$_description=$myrow['c_description'];
// Edit
$GLOBALS['SITE_DB']->query_update('catalogues',array('c_send_view_reports'=>$send_view_reports,'c_display_type'=>$display_type,'c_ecommerce'=>$ecommerce,'c_name'=>$name,'c_title'=>lang_remap($_title,$title),'c_description'=>lang_remap_comcode($_description,$description),'c_notes'=>$notes,'c_add_date'=>time(),'c_submit_points'=>$submit_points),array('c_name'=>$old_name),'',1);
// If we're renaming, then we better change a load of references
if ($name!=$old_name)
{
$GLOBALS['SITE_DB']->query_update('catalogue_categories',array('c_name'=>$name),array('c_name'=>$old_name));
$GLOBALS['SITE_DB']->query_update('catalogue_fields',array('c_name'=>$name),array('c_name'=>$old_name));
$GLOBALS['SITE_DB']->query_update('catalogue_entries',array('c_name'=>$name),array('c_name'=>$old_name));
$types=$GLOBALS['SITE_DB']->query_select('award_types',array('id'),array('a_content_type'=>'catalogue'));
foreach ($types as $type)
{
$GLOBALS['SITE_DB']->query_update('award_archive',array('content_id'=>$name),array('content_id'=>$old_name,'a_type_id'=>$type['id']));
}
}
decache('main_cc_embed');
decache('main_recent_cc_entries');
log_it('EDIT_CATALOGUE',$name);
}
void actual_delete_catalogue(ID_TEXT name)
Delete a catalogue.
Parameters…
| Name |
name |
| Description |
The name of the catalogue |
| Type |
ID_TEXT |
(No return value)
function actual_delete_catalogue($name)
{
// Delete lang
$rows=$GLOBALS['SITE_DB']->query_select('catalogues',array('c_description','c_title'),array('c_name'=>$name),'',1);
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$myrow=$rows[0];
// Delete anything involved (ha ha destruction!)
if (function_exists('set_time_limit')) @set_time_limit(0);
$start=0;
do
{
$entries=collapse_1d_complexity('id',$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('id'),array('c_name'=>$name),'',500,$start));
foreach ($entries as $entry)
{
actual_delete_catalogue_entry($entry);
}
$start+=500;
}
while (count($entries)==500);
$start=0;
do
{
$categories=collapse_1d_complexity('id',$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('id'),array('c_name'=>$name),'',30,$start));
foreach ($categories as $category)
{
actual_delete_catalogue_category($category,true);
}
$start+=30;
}
while (array_key_exists(0,$categories));
$fields=collapse_1d_complexity('id',$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('id'),array('c_name'=>$name)));
foreach ($fields as $field)
{
actual_delete_catalogue_field($field);
}
$GLOBALS['SITE_DB']->query_delete('catalogues',array('c_name'=>$name),'',1);
delete_lang($myrow['c_title']);
delete_lang($myrow['c_description']);
$GLOBALS['SITE_DB']->query_delete('group_category_access',array('module_the_name'=>'catalogues_catalogue','category_name'=>$name));
$GLOBALS['SITE_DB']->query_delete('gsp',array('module_the_name'=>'catalogues_catalogue','category_name'=>$name));
log_it('DELETE_CATALOGUE',$name);
}
void actual_edit_catalogue_field(AUTO_LINK id, ID_TEXT c_name, SHORT_TEXT name, LONG_TEXT description, integer order, BINARY defines_order, BINARY visible, BINARY searchable, LONG_TEXT default, BINARY required, BINARY put_in_category, BINARY put_in_search, ?ID_TEXT type)
Edit a catalogue field.
Parameters…
| Name |
id |
| Description |
The ID of the field |
| Type |
AUTO_LINK |
| Name |
c_name |
| Description |
The name of the catalogue |
| Type |
ID_TEXT |
| Name |
name |
| Description |
The name of the field |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
Description for the field |
| Type |
LONG_TEXT |
| Name |
order |
| Description |
The field order (the field order determines what order the fields are displayed within an entry) |
| Type |
integer |
| Name |
defines_order |
| Description |
Whether the field defines entry ordering |
| Type |
BINARY |
| Name |
visible |
| Description |
Whether the field is visible when an entry is viewed |
| Type |
BINARY |
| Name |
searchable |
| Description |
Whether the field is usable as a search key |
| Type |
BINARY |
| Name |
default |
| Description |
The default value for the field |
| Type |
LONG_TEXT |
| Name |
required |
| Description |
Whether the field is required |
| Type |
BINARY |
| Name |
put_in_category |
| Description |
Whether the field is to be shown in category views (not applicable for the list display type) |
| Default value |
1 |
| Type |
BINARY |
| Name |
put_in_search |
| Description |
Whether the field is to be shown in search views (not applicable for the list display type) |
| Default value |
1 |
| Type |
BINARY |
| Name |
type |
| Description |
The field type (NULL: do not change) |
| Default value |
|
| Type |
?ID_TEXT |
(No return value)
function actual_edit_catalogue_field($id,$c_name,$name,$description,$order,$defines_order,$visible,$searchable,$default,$required,$put_in_category=1,$put_in_search=1,$type=NULL) // You cannot edit a field type
{
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('cf_description','cf_name'),array('id'=>$id));
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$myrow=$rows[0];
$_name=$myrow['cf_name'];
$_description=$myrow['cf_description'];
$map=array('c_name'=>$c_name,'cf_name'=>lang_remap($_name,$name),'cf_description'=>lang_remap($_description,$description),'cf_order'=>$order,'cf_defines_order'=>$defines_order,'cf_visible'=>$visible,'cf_searchable'=>$searchable,'cf_default'=>$default,'cf_required'=>$required,'cf_put_in_category'=>$put_in_category,'cf_put_in_search'=>$put_in_search);
if (!is_null($type)) $map['cf_type']=$type;
$GLOBALS['SITE_DB']->query_update('catalogue_fields',$map,array('id'=>$id),'',1);
}
void actual_delete_catalogue_field(AUTO_LINK id)
Delete a catalogue field.
Parameters…
| Name |
id |
| Description |
The ID of the field |
| Type |
AUTO_LINK |
(No return value)
function actual_delete_catalogue_field($id)
{
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('cf_name','cf_description','cf_type'),array('id'=>$id));
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$myrow=$rows[0];
delete_lang($myrow['cf_name']);
delete_lang($myrow['cf_description']);
$GLOBALS['SITE_DB']->query_delete('catalogue_fields',array('id'=>$id),'',1);
}
AUTO_LINK actual_add_catalogue_category(ID_TEXT catalogue_name, mixed title, mixed description, LONG_TEXT notes, ?AUTO_LINK parent_id, URLPATH rep_image, integer move_days_lower, integer move_days_higher, ?AUTO_LINK move_target, ?TIME add_date, ?AUTO_LINK id)
Add a catalogue category
Parameters…
| Name |
catalogue_name |
| Description |
The codename of the catalogue the category is in |
| Type |
ID_TEXT |
| Name |
title |
| Description |
The title of this category (either language code or string) |
| Type |
mixed |
| Name |
description |
| Description |
A description (either language code or string) |
| Type |
mixed |
| Name |
notes |
| Description |
Hidden notes pertaining to this category |
| Type |
LONG_TEXT |
| Name |
parent_id |
| Description |
The ID of this categories parent (NULL: a root category, or not a tree catalogue) |
| Type |
?AUTO_LINK |
| Name |
rep_image |
| Description |
The representative image for the category (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
move_days_lower |
| Description |
The number of days before expiry (lower limit) |
| Default value |
30 |
| Type |
integer |
| Name |
move_days_higher |
| Description |
The number of days before expiry (higher limit) |
| Default value |
60 |
| Type |
integer |
| Name |
move_target |
| Description |
The expiry category (NULL: do not expire) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
add_date |
| Description |
The add time (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
The ID of the new category |
| Type |
AUTO_LINK |
function actual_add_catalogue_category($catalogue_name,$title,$description,$notes,$parent_id,$rep_image='',$move_days_lower=30,$move_days_higher=60,$move_target=NULL,$add_date=NULL,$id=NULL)
{
if (is_null($add_date)) $add_date=time();
if (!is_integer($description)) $description=insert_lang_comcode($description,3);
if (!is_integer($title)) $title=insert_lang($title,2);
$map=array('cc_move_days_lower'=>$move_days_lower,'cc_move_days_higher'=>$move_days_higher,'cc_move_target'=>$move_target,'rep_image'=>$rep_image,'cc_add_date'=>$add_date,'c_name'=>$catalogue_name,'cc_title'=>$title,'cc_description'=>$description,'cc_notes'=>$notes,'cc_parent_id'=>$parent_id);
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('catalogue_categories',$map,true);
calculate_category_child_count_cache($parent_id);
log_it('ADD_CATALOGUE_CATEGORY',strval($id),$title);
require_code('seo2');
if (!is_numeric($title)) seo_meta_set_for_implicit('catalogue_category',strval($id),array($title,$description),$title);
store_in_catalogue_cat_treecache($id,$parent_id);
return $id;
}
void rebuild_catalogue_cat_treecache()
Re-build the efficient catalogue category tree structure ancestry cache.
Parameters…
(No return value)
function rebuild_catalogue_cat_treecache()
{
if (function_exists('set_time_limit')) @set_time_limit(0);
$GLOBALS['SITE_DB']->query_delete('catalogue_cat_treecache');
$GLOBALS['SITE_DB']->query_delete('catalogue_childcountcache');
$GLOBALS['NO_QUERY_LIMIT']=true;
$max=1000;
$start=0;
do
{
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('id','cc_parent_id'),NULL,'',$max,$start);
foreach ($rows as $row)
{
store_in_catalogue_cat_treecache($row['id'],$row['cc_parent_id'],false);
calculate_category_child_count_cache($row['id'],false);
}
$start+=$max;
}
while (count($rows)!=0);
}
void store_in_catalogue_cat_treecache(AUTO_LINK id, ?AUTO_LINK parent_id, boolean cleanup_first)
Update the treecache for a catalogue category node.
Parameters…
| Name |
id |
| Description |
The ID of the category |
| Type |
AUTO_LINK |
| Name |
parent_id |
| Description |
The ID of the parent category (NULL: no parent) |
| Type |
?AUTO_LINK |
| Name |
cleanup_first |
| Description |
Whether to delete any possible pre-existing records for the category first |
| Default value |
boolean-true |
| Type |
boolean |
(No return value)
function store_in_catalogue_cat_treecache($id,$parent_id,$cleanup_first=true)
{
if ($cleanup_first)
{
$GLOBALS['SITE_DB']->query_delete('catalogue_cat_treecache',array('cc_id'=>$id));
}
// Self reference
$GLOBALS['SITE_DB']->query_insert('catalogue_cat_treecache',array(
'cc_id'=>$id,
'cc_ancestor_id'=>$id,
));
// Stored recursed referenced towards root
while (!is_null($parent_id))
{
$GLOBALS['SITE_DB']->query_insert('catalogue_cat_treecache',array(
'cc_id'=>$id,
'cc_ancestor_id'=>$parent_id,
));
$parent_id=$GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories','cc_parent_id',array('id'=>$parent_id));
}
}
void calculate_category_child_count_cache(?AUTO_LINK cat_id, boolean recursive_updates)
Update cache for a categories child counts.
Parameters…
| Name |
cat_id |
| Description |
The ID of the category (NULL: skip, called by some code that didn't realise it didn't impact a tree parent) |
| Type |
?AUTO_LINK |
| Name |
recursive_updates |
| Description |
Whether to recurse up the tree to force recalculations on other categories (recommended, unless you are doing a complete rebuild) |
| Default value |
boolean-true |
| Type |
boolean |
(No return value)
function calculate_category_child_count_cache($cat_id,$recursive_updates=true)
{
if (is_null($cat_id)) return;
$GLOBALS['SITE_DB']->query_delete('catalogue_childcountcache',array(
'cc_id'=>$cat_id,
),'',1);
$catalogue_name=$GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories','c_name',array('id'=>$cat_id));
$num_rec_children=$GLOBALS['SITE_DB']->query_value('catalogue_cat_treecache','COUNT(*)',array('cc_ancestor_id'=>$cat_id))-1;
$num_rec_entries=$GLOBALS['SITE_DB']->query_value('catalogue_cat_treecache t JOIN '.get_table_prefix().'catalogue_entries e ON e.cc_id=t.cc_id','COUNT(*)',array('t.cc_ancestor_id'=>$cat_id,'c_name'=>$catalogue_name/*important, else custom field cats could be included*/));
$GLOBALS['SITE_DB']->query_insert('catalogue_childcountcache',array(
'cc_id'=>$cat_id,
'c_num_rec_children'=>$num_rec_children,
'c_num_rec_entries'=>$num_rec_entries,
));
if ($recursive_updates)
{
$parent_id=$GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories','cc_parent_id',array('id'=>$cat_id));
if (!is_null($parent_id))
calculate_category_child_count_cache($parent_id);
}
}
void actual_edit_catalogue_category(AUTO_LINK id, SHORT_TEXT title, LONG_TEXT description, LONG_TEXT notes, ?AUTO_LINK parent_id, SHORT_TEXT meta_keywords, LONG_TEXT meta_description, URLPATH rep_image, integer move_days_lower, integer move_days_higher, ?AUTO_LINK move_target)
Edit a catalogue category.
Parameters…
| Name |
id |
| Description |
The ID of the category |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The title of the category |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
Description for the category |
| Type |
LONG_TEXT |
| Name |
notes |
| Description |
Admin notes |
| Type |
LONG_TEXT |
| Name |
parent_id |
| Description |
The ID of the parent category (NULL: no parent) |
| Type |
?AUTO_LINK |
| Name |
meta_keywords |
| Description |
Meta keywords for the category |
| Type |
SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description for the category |
| Type |
LONG_TEXT |
| Name |
rep_image |
| Description |
The representative image for the category (blank: none) |
| Type |
URLPATH |
| Name |
move_days_lower |
| Description |
The number of days before expiry (lower limit) |
| Type |
integer |
| Name |
move_days_higher |
| Description |
The number of days before expiry (higher limit) |
| Type |
integer |
| Name |
move_target |
| Description |
The expiry category (NULL: do not expire) |
| Type |
?AUTO_LINK |
(No return value)
function actual_edit_catalogue_category($id,$title,$description,$notes,$parent_id,$meta_keywords,$meta_description,$rep_image,$move_days_lower,$move_days_higher,$move_target)
{
$under_category_id=$parent_id;
while ((!is_null($under_category_id)) && ($under_category_id!=INTEGER_MAGIC_NULL))
{
if ($id==$under_category_id) warn_exit(do_lang_tempcode('OWN_PARENT_ERROR'));
$under_category_id=$GLOBALS['SITE_DB']->query_value('catalogue_categories','cc_parent_id',array('id'=>$under_category_id));
}
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories',array('cc_description','cc_title'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$myrow=$rows[0];
$_title=$myrow['cc_title'];
$_description=$myrow['cc_description'];
store_in_catalogue_cat_treecache($id,$parent_id);
$map=array('cc_move_days_lower'=>$move_days_lower,'cc_move_days_higher'=>$move_days_higher,'cc_move_target'=>$move_target,'cc_title'=>lang_remap($_title,$title),'cc_description'=>lang_remap_comcode($_description,$description),'cc_notes'=>$notes,'cc_parent_id'=>$parent_id);
if (!is_null($rep_image))
{
$map['rep_image']=$rep_image;
require_code('files2');
delete_upload('uploads/grepimages','catalogue_categories','rep_image','id',$id,$rep_image);
}
$old_parent_id=$GLOBALS['SITE_DB']->query_value('catalogue_categories','cc_parent_id',array('id'=>$id));
$GLOBALS['SITE_DB']->query_update('catalogue_categories',$map,array('id'=>$id),'',1);
require_code('urls2');
suggest_new_idmoniker_for('catalogues','category',strval($id),$title);
require_code('seo2');
seo_meta_set_for_explicit('catalogue_category',strval($id),$meta_keywords,$meta_description);
if ($old_parent_id!==$parent_id)
{
calculate_category_child_count_cache($old_parent_id);
calculate_category_child_count_cache($parent_id);
}
log_it('EDIT_CATALOGUE_CATEGORY',strval($id),$title);
}
void actual_delete_catalogue_category(AUTO_LINK id, boolean deleting_all)
Delete a catalogue category.
Parameters…
| Name |
id |
| Description |
The ID of the category |
| Type |
AUTO_LINK |
| Name |
deleting_all |
| Description |
Whether we're deleting everything under the category; if FALSE we will actively reassign child categories to be directly under the root |
| Default value |
boolean-false |
| Type |
boolean |
(No return value)
function actual_delete_catalogue_category($id,$deleting_all=false)
{
// Info about our category
$rows=$GLOBALS['SITE_DB']->query_select('catalogue_categories c LEFT JOIN '.$GLOBALS['SITE_DB']->get_table_prefix().'catalogues x ON c.c_name=x.c_name',array('c_is_tree','c.c_name','cc_description','cc_title','cc_parent_id'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$myrow=$rows[0];
// If we aren't deleting the entire catalogue, make sure we don't delete the root category
if ((!$deleting_all) && ($myrow['c_is_tree']==1))
{
$root_category=$GLOBALS['SITE_DB']->query_value('catalogue_categories','MIN(id)',array('c_name'=>$myrow['c_name'],'cc_parent_id'=>NULL));
if ($id==$root_category) warn_exit(do_lang_tempcode('CATALOGUE_NO_DELETE_ROOT'));
}
$GLOBALS['SITE_DB']->query_delete('catalogue_cat_treecache',array('cc_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_childcountcache',array('cc_id'=>$id));
require_code('files2');
delete_upload('uploads/grepimages','catalogue_categories','rep_image','id',$id);
if (!$deleting_all) // If not deleting the whole catalogue
{
if (function_exists('set_time_limit')) @set_time_limit(0);
// If we're in a tree
if ($myrow['c_is_tree']==1)
{
$GLOBALS['SITE_DB']->query_update('catalogue_categories',array('cc_parent_id'=>$myrow['cc_parent_id']),array('cc_parent_id'=>$id));
$GLOBALS['SITE_DB']->query_update('catalogue_entries',array('cc_id'=>$myrow['cc_parent_id']),array('cc_id'=>$id));
} else // If we're not in a tree catalogue we can't move them, we have to delete
{
if (function_exists('set_time_limit')) @set_time_limit(0);
$GLOBALS['SITE_DB']->query_delete('catalogue_categories',array('cc_parent_id'=>$id)); // Does nothing, in theory
$start=0;
do
{
$entries=$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('id'),array('cc_id'=>$id),'',500,$start);
foreach ($entries as $entry)
{
actual_delete_catalogue_entry($entry['id']);
}
$start+=500;
}
while (count($entries)==500);
}
$GLOBALS['SITE_DB']->query_update('catalogue_categories',array('cc_move_target'=>NULL),array('cc_move_target'=>$id));
}
require_code('seo2');
seo_meta_erase_storage('catalogue_category',strval($id));
log_it('DELETE_CATALOGUE_CATEGORY',strval($id),get_translated_text($myrow['cc_title']));
// Delete lang
delete_lang($myrow['cc_title']);
delete_lang($myrow['cc_description']);
/*$entries=collapse_1d_complexity('id',$GLOBALS['SITE_DB']->query_select('catalogue_entries',array('id'),array('cc_id'=>$id)));
foreach ($entries as $entry)
{
actual_delete_catalogue_entry($entry);
}*/
$old_parent_id=$GLOBALS['SITE_DB']->query_value('catalogue_categories','cc_parent_id',array('id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_categories',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('group_category_access',array('module_the_name'=>'catalogues_category','category_name'=>strval($id)));
$GLOBALS['SITE_DB']->query_delete('gsp',array('module_the_name'=>'catalogues_category','category_name'=>strval($id)));
calculate_category_child_count_cache($old_parent_id);
}
AUTO_LINK actual_add_catalogue_entry(AUTO_LINK category_id, BINARY validated, LONG_TEXT notes, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, array map, ?TIME time, ?MEMBER submitter, ?TIME edit_date, integer views, ?AUTO_LINK id)
Adds an entry to the specified catalogue.
Parameters…
| Name |
category_id |
| Description |
The ID of the category that the entry is in |
| Type |
AUTO_LINK |
| Name |
validated |
| Description |
Whether the entry has been validated |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes pertaining to the entry |
| Type |
LONG_TEXT |
| Name |
allow_rating |
| Description |
Whether the entry may be rated |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed (0=no, 1=yes, 2=review style) |
| Type |
SHORT_INTEGER |
| Name |
allow_trackbacks |
| Description |
Whether the entry may be trackbacked |
| Type |
BINARY |
| Name |
map |
| Description |
A map of field IDs, to values, that defines the entries settings |
| Type |
array |
| Name |
time |
| Description |
The time the entry was added (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
submitter |
| Description |
The entries submitter (NULL: current user) |
| Default value |
|
| Type |
?MEMBER |
| Name |
edit_date |
| Description |
The edit time (NULL: never) |
| Default value |
|
| Type |
?TIME |
| Name |
views |
| Description |
The number of views |
| Default value |
0 |
| Type |
integer |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
The ID of the newly added entry |
| Type |
AUTO_LINK |
function actual_add_catalogue_entry($category_id,$validated,$notes,$allow_rating,$allow_comments,$allow_trackbacks,$map,$time=NULL,$submitter=NULL,$edit_date=NULL,$views=0,$id=NULL)
{
if (is_null($time)) $time=time();
if (is_null($submitter)) $submitter=get_member();
$catalogue_name=$GLOBALS['SITE_DB']->query_value('catalogue_categories','c_name',array('id'=>$category_id));
$catalogue_title=$GLOBALS['SITE_DB']->query_value('catalogues','c_title',array('c_name'=>$catalogue_name));
$fields=collapse_2d_complexity('id','cf_type',$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('id','cf_type'),array('c_name'=>$catalogue_name)));
require_code('comcode_check');
require_code('fields');
if (!addon_installed('unvalidated')) $validated=1;
$imap=array('c_name'=>$catalogue_name,'ce_edit_date'=>$edit_date,'cc_id'=>$category_id,'ce_last_moved'=>time(),'ce_submitter'=>$submitter,'ce_add_date'=>$time,'ce_views'=>$views,'ce_views_prior'=>$views,'ce_validated'=>$validated,'notes'=>$notes,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks);
if (!is_null($id)) $imap['id']=$id;
$val=mixed();
foreach ($map as $field_id=>$val)
{
$type=$fields[$field_id];
$ob=get_fields_hook($type);
list($raw_type)=$ob->get_field_value_row_bits($fields[$field_id]);
if (strpos($raw_type,'_trans')!==false)
check_comcode($val);
}
$id=$GLOBALS['SITE_DB']->query_insert('catalogue_entries',$imap,true);
$title=NULL;
foreach ($map as $field_id=>$val)
{
if ($val==STRING_MAGIC_NULL) $val='';
if (is_null($title)) $title=$val;
$type=$fields[$field_id];
$ob=get_fields_hook($type);
list($raw_type,,$sup_table_name)=$ob->get_field_value_row_bits($fields[$field_id]);
if (strpos($raw_type,'_trans')!==false)
{
if ($type=='posting_field')
{
require_code('attachments2');
$val=insert_lang_comcode_attachments(3,$val,'catalogue_entry',strval($id));
} else
{
$val=insert_lang_comcode($val,3);
}
}
if ($sup_table_name=='short') $val=substr($val,0,255);
if ($sup_table_name=='float')
{
$map=array('cf_id'=>$field_id,'ce_id'=>$id,'cv_value'=>((is_null($val)) || ($val==''))?NULL:floatval($val));
}
elseif ($sup_table_name=='integer')
{
$map=array('cf_id'=>$field_id,'ce_id'=>$id,'cv_value'=>((is_null($val)) || ($val==''))?NULL:intval($val));
} else
{
$map=array('cf_id'=>$field_id,'ce_id'=>$id,'cv_value'=>$val);
}
$GLOBALS['SITE_DB']->query_insert('catalogue_efv_'.$sup_table_name,$map);
}
require_code('seo2');
seo_meta_set_for_implicit('catalogue_entry',strval($id),$map,'');
calculate_category_child_count_cache($category_id);
if ($catalogue_name[0]!='_')
{
if ($validated==1)
{
require_lang('catalogues');
require_code('notifications');
$subject=do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT',get_site_name(),strip_comcode($title),array($catalogue_title));
$self_url=build_url(array('page'=>'catalogues','type'=>'entry','id'=>$id),get_module_zone('catalogues'),NULL,false,false,true);
$mail=do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape(strip_comcode($title)),array(comcode_escape($self_url->evaluate()),comcode_escape($catalogue_title)));
dispatch_notification('catalogue_entry__'.$catalogue_name,strval($id),$subject,$mail);
}
log_it('ADD_CATALOGUE_ENTRY',strval($id),$title);
}
decache('main_cc_embed');
decache('main_recent_cc_entries');
return $id;
}
void actual_edit_catalogue_entry(AUTO_LINK id, AUTO_LINK category_id, BINARY validated, LONG_TEXT notes, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, array map, ?SHORT_TEXT meta_keywords, ?LONG_TEXT meta_description)
Edit the specified catalogue entry
Parameters…
| Name |
id |
| Description |
The ID of the entry being edited |
| Type |
AUTO_LINK |
| Name |
category_id |
| Description |
The ID of the category that the entry is in |
| Type |
AUTO_LINK |
| Name |
validated |
| Description |
Whether the entry has been validated |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes pertaining to the entry |
| Type |
LONG_TEXT |
| Name |
allow_rating |
| Description |
Whether the entry may be rated |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed (0=no, 1=yes, 2=review style) |
| Type |
SHORT_INTEGER |
| Name |
allow_trackbacks |
| Description |
Whether the entry may be trackbacked |
| Type |
BINARY |
| Name |
map |
| Description |
A map of field IDs, to values, that defines the entries settings |
| Type |
array |
| Name |
meta_keywords |
| Description |
Meta keywords for this resource (NULL: do not edit) |
| Default value |
|
| Type |
?SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description for this resource (NULL: do not edit) |
| Default value |
|
| Type |
?LONG_TEXT |
(No return value)
function actual_edit_catalogue_entry($id,$category_id,$validated,$notes,$allow_rating,$allow_comments,$allow_trackbacks,$map,$meta_keywords='',$meta_description='')
{
$catalogue_name=$GLOBALS['SITE_DB']->query_value('catalogue_categories','c_name',array('id'=>$category_id));
$catalogue_title=$GLOBALS['SITE_DB']->query_value('catalogues','c_title',array('c_name'=>$catalogue_name));
$fields=collapse_2d_complexity('id','cf_type',$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('id','cf_type'),array('c_name'=>$catalogue_name)));
$original_submitter=$GLOBALS['SITE_DB']->query_value('catalogue_entries','ce_submitter',array('id'=>$id));
$old_category_id=$GLOBALS['SITE_DB']->query_value('catalogue_entries','cc_id',array('id'=>$id));
if (!addon_installed('unvalidated')) $validated=1;
require_code('submit');
$just_validated=(!content_validated('catalogue_entry',strval($id))) && ($validated==1);
if ($just_validated)
{
send_content_validated_notification('catalogue_entry',strval($id));
}
$GLOBALS['SITE_DB']->query_update('catalogue_entries',array('ce_edit_date'=>time(),'cc_id'=>$category_id,'ce_validated'=>$validated,'notes'=>$notes,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks),array('id'=>$id),'',1);
require_code('fields');
$title=NULL;
foreach ($map as $field_id=>$val)
{
if (is_null($title)) $title=$val;
$type=$fields[$field_id];
$ob=get_fields_hook($type);
list(,,$sup_table_name)=$ob->get_field_value_row_bits($fields[$field_id]);
if (substr($sup_table_name,-6)=='_trans')
{
$_val=$GLOBALS['SITE_DB']->query_value_null_ok('catalogue_efv_'.$sup_table_name,'cv_value',array('cf_id'=>$field_id,'ce_id'=>$id));
if (is_null($_val))
{
$_val=insert_lang_comcode($val,3);
} else
{
if ($type=='posting_field')
{
require_code('attachments2');
require_code('attachments3');
$_val=update_lang_comcode_attachments($_val,$val,'catalogue_entry',strval($id),NULL,false,$original_submitter);
} else
{
$_val=lang_remap_comcode($_val,$val);
}
}
$GLOBALS['SITE_DB']->query_update('catalogue_efv_'.$sup_table_name,array('cv_value'=>$_val),array('cf_id'=>$field_id,'ce_id'=>$id),'',1);
} else
{
if ($sup_table_name=='float')
{
$map=array('cv_value'=>((is_null($val)) || ($val==''))?NULL:floatval($val));
}
elseif ($sup_table_name=='integer')
{
$map=array('cv_value'=>((is_null($val)) || ($val==''))?NULL:intval($val));
} else
{
$map=array('cv_value'=>$val);
}
$GLOBALS['SITE_DB']->query_update('catalogue_efv_'.$sup_table_name,$map,array('cf_id'=>$field_id,'ce_id'=>$id),'',1);
}
}
require_code('urls2');
suggest_new_idmoniker_for('catalogues','entry',strval($id),strip_comcode($title));
require_code('seo2');
seo_meta_set_for_explicit('catalogue_entry',strval($id),$meta_keywords,$meta_description);
$self_url=build_url(array('page'=>'catalogues','type'=>'entry','id'=>$id),get_module_zone('catalogues'),NULL,false,false,true);
if ($category_id!=$old_category_id)
{
calculate_category_child_count_cache($category_id);
calculate_category_child_count_cache($old_category_id);
}
decache('main_cc_embed');
decache('main_recent_cc_entries');
if ($catalogue_name[0]!='_')
{
log_it('EDIT_CATALOGUE_ENTRY',strval($id),$title);
if ($just_validated)
{
require_lang('catalogues');
require_code('notifications');
$subject=do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT',get_site_name(),strip_comcode($title),array($catalogue_title));
$mail=do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape(strip_comcode($title)),array(comcode_escape($self_url->evaluate()),comcode_escape($catalogue_title)));
dispatch_notification('catalogue_entry__'.$catalogue_name,strval($id),$subject,$mail);
}
}
require_code('feedback');
update_spacer_post($allow_comments!=0,'catalogues',strval($id),$self_url,$title,get_value('comment_forum__catalogues__'.$catalogue_name));
}
void actual_delete_catalogue_entry(AUTO_LINK id)
Delete a catalogue entry.
Parameters…
| Name |
id |
| Description |
The ID of the entry to delete |
| Type |
AUTO_LINK |
(No return value)
function actual_delete_catalogue_entry($id)
{
$old_category_id=$GLOBALS['SITE_DB']->query_value('catalogue_entries','cc_id',array('id'=>$id));
$catalogue_name=$GLOBALS['SITE_DB']->query_value('catalogue_entries','c_name',array('id'=>$id));
require_code('fields');
require_code('catalogues');
$fields=$GLOBALS['SITE_DB']->query_select('catalogue_fields',array('*'),array('c_name'=>$catalogue_name));
$title=NULL;
foreach ($fields as $field)
{
$object=get_fields_hook($field['cf_type']);
list(,,$storage_type)=$object->get_field_value_row_bits($field);
$value=_get_catalogue_entry_field($field['id'],$id,$storage_type);
if (method_exists($object,'cleanup'))
{
$object->cleanup($value);
}
if (is_null($title))
{
if (($storage_type=='long_trans') || ($storage_type=='short_trans'))
{
$title=get_translated_text(intval($value));
} else
{
$title=$value;
}
}
}
$lang1=$GLOBALS['SITE_DB']->query_select('catalogue_efv_long_trans',array('cv_value'),array('ce_id'=>$id));
$lang2=$GLOBALS['SITE_DB']->query_select('catalogue_efv_short_trans',array('cv_value'),array('ce_id'=>$id));
$lang=array_merge($lang1,$lang2);
foreach ($lang as $lang_to_delete)
{
if (true) // Always do this just in case it is for attachments
{
require_code('attachments2');
require_code('attachments3');
delete_lang_comcode_attachments($lang_to_delete['cv_value'],'catalogue_entry',strval($id));
} else
{
delete_lang($lang_to_delete['cv_value']);
}
}
$GLOBALS['SITE_DB']->query_delete('catalogue_efv_long_trans',array('ce_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_efv_short_trans',array('ce_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_efv_long',array('ce_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_efv_short',array('ce_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_efv_float',array('ce_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_efv_integer',array('ce_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('catalogue_entries',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('trackbacks',array('trackback_for_type'=>'catalogues','trackback_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'catalogues','rating_for_id'=>$id));
require_code('seo2');
seo_meta_erase_storage('catalogue_entry',strval($id));
calculate_category_child_count_cache($old_category_id);
decache('main_recent_cc_entries');
decache('main_cc_embed');
if ($catalogue_name[0]!='_')
log_it('DELETE_CATALOGUE_ENTRY',strval($id),$title);
}
0 reviews: Unrated (average)
There have been no comments yet