ocPortal Developer's Guide: Downloads
» Return to Contents
sources/downloads.php
Global_functions_downloads.php
Function summary
|
void
|
init__downloads ()
|
|
void
|
download_licence_script ()
|
|
tempcode
|
get_download_html (array row, boolean pic, boolean breadcrumbs, ?ID_TEXT zone, ?string text_summary)
|
|
tempcode
|
get_download_category_html (array row, ID_TEXT zone, boolean put_in_box)
|
|
tempcode
|
nice_get_downloads_tree (?AUTO_LINK it, ?AUTO_LINK submitter, ?AUTO_LINK shun, boolean use_compound_list, boolean editable_filter)
|
|
array
|
get_downloads_tree (?MEMBER submitter, ?AUTO_LINK category_id, ?string tree, ?ID_TEXT title, ?integer shun, ?AUTO_LINK levels, boolean use_compound_list, boolean editable_filter, boolean tar_filter)
|
|
tempcode
|
nice_get_download_category_tree (?AUTO_LINK it, boolean use_compound_list, boolean addable_filter)
|
|
tempcode
|
nice_get_download_licences (?AUTO_LINK it, boolean allow_na)
|
|
array
|
get_download_category_tree (?AUTO_LINK category_id, ?string tree, ?ID_TEXT title, boolean do_stats, boolean use_compound_list, ?integer levels, boolean addable_filter)
|
|
tempcode
|
download_breadcrumbs (AUTO_LINK category_id, ?AUTO_LINK root, boolean no_link_for_me_sir, ?ID_TEXT zone)
|
|
array
|
count_download_category_children (AUTO_LINK category_id)
|
|
tempcode
|
get_category_downloads (AUTO_LINK category_id, AUTO_LINK root, ?string order)
|
|
tempcode
|
get_download_sub_categories (AUTO_LINK category_id, ?AUTO_LINK root, ?ID_TEXT zone, ?string order)
|
void init__downloads()
Standard code module initialisation function.
Parameters…
(No return value)
function init__downloads()
{
global $PT_PAIR_CACHE_D;
$PT_PAIR_CACHE_D=array();
}
void download_licence_script()
Show a download licence for display
Parameters…
(No return value)
function download_licence_script()
{
$id=get_param_integer('id');
$rows=$GLOBALS['SITE_DB']->query_select('download_licences',array('*'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows))
{
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$licence_title=$rows[0]['l_title'];
$licence_text=$rows[0]['l_text'];
$echo=do_template('POPUP_HTML_WRAP',array('_GUID'=>'d8f60d5f6f56b08589ed6f4b874dad85','TITLE'=>$licence_title,'CONTENT'=>comcode_to_tempcode($licence_text,$GLOBALS['FORUM_DRIVER']->get_guest_id(),false)));
$echo->evaluate_echo();
}
tempcode get_download_html(array row, boolean pic, boolean breadcrumbs, ?ID_TEXT zone, ?string text_summary)
Get tempcode for a download 'feature box' for the sgiven row
Parameters…
| Name |
row |
| Description |
The database field row of this download |
| Type |
array |
| Name |
pic |
| Description |
Whether to show a picture |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
breadcrumbs |
| Description |
Whether to show breadcrumbs |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
zone |
| Description |
The zone the download module we're using is in (NULL: find it) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
text_summary |
| Description |
Text summary for result (e.g. highlighted portion of actual file from search result) (NULL: none) |
| Default value |
|
| Type |
?string |
Returns…
| Description |
A box for this download, linking to the full download page |
| Type |
tempcode |
function get_download_html($row,$pic=true,$breadcrumbs=true,$zone=NULL,$text_summary=NULL)
{
require_css('downloads');
if (is_null($zone)) $zone=get_module_zone('downloads');
// Details
$filesize=$row['file_size'];
$filesize=($filesize>0)?clean_file_size($filesize):do_lang('UNKNOWN');
$description=get_translated_tempcode($row['description']);
$root=get_param_integer('root',db_get_first_id(),true);
$download_url=build_url(array('page'=>'downloads','type'=>'entry','id'=>$row['id'],'root'=>($root==db_get_first_id())?NULL:$root),$zone);
$date=get_timezoned_date($row['add_date'],false);
$date_raw=$row['add_date'];
$tree=((get_option('show_dload_trees')=='1') && ($breadcrumbs))?download_breadcrumbs($row['category_id'],NULL,false,$zone):new ocp_tempcode();
$pic_suffix='';
$thumb_url='';
$full_img_url='';
if ((addon_installed('galleries')) && ($pic))
{
// Images
$rows=$GLOBALS['SITE_DB']->query_select('images',array('url','thumb_url','id'),array('cat'=>'download_'.strval($row['id'])),'',1,$row['default_pic']-1);
if (array_key_exists(0,$rows))
{
$pic_suffix='_pic';
require_code('images');
$full_img_url=$rows[0]['url'];
$thumb_url=ensure_thumbnail($rows[0]['url'],$rows[0]['thumb_url'],'galleries','images',$rows[0]['id']);
$imgcode=do_image_thumb($thumb_url,/*'['.*/do_lang('DOWNLOAD_THUMBNAIL')/*.'] '.get_translated_text($row['description'])*/);
} else $imgcode=new ocp_tempcode();
} else $imgcode=new ocp_tempcode();
require_code('feedback');
$rating=($row['allow_rating']==1)?display_rating($download_url,get_translated_text($row['name']),'downloads',strval($row['id']),'RATING_INLINE_STATIC',$row['submitter']):NULL;
if (!is_null($rating))
if (trim($rating->evaluate())=='') $rating=NULL;
$licence_title=NULL;
$licence_url=NULL;
$licence_hyperlink=NULL;
$licence=$row['download_licence'];
if (!is_null($licence))
{
$licence_title=$GLOBALS['SITE_DB']->query_value_null_ok('download_licences','l_title',array('id'=>$licence));
if (!is_null($licence_title))
{
$keep=symbol_tempcode('KEEP');
$licence_url=find_script('download_licence').'?id='.strval($licence).$keep->evaluate();
$licence_hyperlink=do_template('HYPERLINK_POPUP_WINDOW',array('_GUID'=>'10582f28c37ee7e9e462fdbd6a2cb8dd','TITLE'=>'','CAPTION'=>$licence_title,'URL'=>$licence_url,'WIDTH'=>'600','HEIGHT'=>'500','REL'=>'license'));
} else
{
$licence=NULL; // Orphaned
}
}
// Final template
if (($full_img_url!='') && (url_is_local($full_img_url))) $full_img_url=get_custom_base_url().'/'.$full_img_url;
return do_template('DOWNLOAD_BOX',array('TEXT_SUMMARY'=>$text_summary,'AUTHOR'=>$row['author'],'ID'=>strval($row['id']),'RATING'=>$rating,'VIEWS'=>integer_format($row['download_views']),'SUBMITTER'=>strval($row['submitter']),'DESCRIPTION'=>$description,'FILE_SIZE'=>$filesize,'DOWNLOADS'=>integer_format($row['num_downloads']),'DATE_RAW'=>strval($date_raw),'DATE'=>$date,'EDIT_DATE_RAW'=>is_null($row['edit_date'])?'':strval($row['edit_date']),'SIZE'=>$filesize,'URL'=>$download_url,'NAME'=>get_translated_text($row['name']),'TREE'=>$tree,'IMG_URL'=>$thumb_url,'FULL_IMG_URL'=>$full_img_url,'IMGCODE'=>$imgcode,'LICENCE'=>is_null($licence)?NULL:strval($licence),'LICENCE_TITLE'=>$licence_title,'LICENCE_HYPERLINK'=>$licence_hyperlink));
}
tempcode get_download_category_html(array row, ID_TEXT zone, boolean put_in_box)
Get tempcode for a download 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_download_category_html($row,$zone='_SEARCH',$put_in_box=true)
{
$url=build_url(array('page'=>'downloads','type'=>'misc','id'=>($row['id']==db_get_first_id())?NULL:$row['id']),$zone);
$content=do_template('SIMPLE_PREVIEW_BOX',array('SUMMARY'=>get_translated_tempcode($row['description']),'URL'=>$url));
if (!$put_in_box) return $content;
if (!is_null($row['parent_id']))
{
$tree=download_breadcrumbs($row['parent_id'],NULL,false,$zone);
if (!$tree->is_empty()) $content->attach(paragraph(do_lang_tempcode('LOCATED_IN',$tree)));
}
return put_in_standard_box($content,get_translated_text($row['category']));
}
tempcode nice_get_downloads_tree(?AUTO_LINK it, ?AUTO_LINK submitter, ?AUTO_LINK shun, boolean use_compound_list, boolean editable_filter)
Get a nice, formatted XHTML list of downloads, in download tree structure
Parameters…
| 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 |
shun |
| Description |
Download we do not want to show (NULL: none to not show) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
use_compound_list |
| Description |
Whether to get a list of child categories (not just direct ones, recursively), instead of just IDs |
| Default value |
boolean-false |
| Type |
boolean |
| 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_downloads_tree($it=NULL,$submitter=NULL,$shun=NULL,$use_compound_list=false,$editable_filter=false)
{
$tree=get_downloads_tree($submitter,NULL,NULL,NULL,$shun,NULL,$use_compound_list,$editable_filter);
if ($use_compound_list) $tree=$tree[0];
$out=''; // XHTMLXHMTML
foreach ($tree as $category)
{
foreach ($category['entries'] as $eid=>$etitle)
{
$selected=($eid==$it);
$line=do_template('DOWNLOAD_LIST_LINE',array('_GUID'=>'7bb13e4418b500cb2b330e629710138a','TREE'=>$category['tree'],'DOWNLOAD'=>$etitle));
$out.='<option value="'.(!$use_compound_list?strval($eid):$category['compound_list']).'"'.($selected?' selected="selected"':'').'>'.$line->evaluate().'</option>';
}
}
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($out);
return make_string_tempcode($out);
}
array get_downloads_tree(?MEMBER submitter, ?AUTO_LINK category_id, ?string tree, ?ID_TEXT title, ?integer shun, ?AUTO_LINK levels, boolean use_compound_list, boolean editable_filter, boolean tar_filter)
Get a list of maps containing all the downloads, and path information, under the specified category - and those beneath it, recursively.
Parameters…
| Name |
submitter |
| Description |
Only show images/videos submitted by this member (NULL: no filter) |
| Default value |
|
| Type |
?MEMBER |
| 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 |
shun |
| Description |
The number of recursive levels to search (NULL: all) |
| Default value |
|
| Type |
?integer |
| Name |
levels |
| Description |
Download we do not want to show (NULL: none to not show) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
use_compound_list |
| Description |
Whether to get a list of child categories (not just direct ones, recursively), instead of just IDs |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
editable_filter |
| Description |
Whether to only show for what may be edited by the current member |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
tar_filter |
| Description |
Whether to only show entries that are tar files (addons) |
| 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. Or if $use_compound_list, the tree structure built with pairs containing the compound list in addition to the child branches |
| Type |
array |
function get_downloads_tree($submitter=NULL,$category_id=NULL,$tree=NULL,$title=NULL,$shun=NULL,$levels=NULL,$use_compound_list=false,$editable_filter=false,$tar_filter=false)
{
if (is_null($category_id)) $category_id=db_get_first_id();
if (!has_category_access(get_member(),'downloads',strval($category_id))) return array();
if (is_null($tree)) $tree='';
// Put our title onto our tree
if (is_null($title)) $title=get_translated_text($GLOBALS['SITE_DB']->query_value('download_categories','category',array('id'=>$category_id)));
$tree.=$title;
$compound_list=strval($category_id).',';
// 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('download_categories',array('id','category'),array('parent_id'=>$category_id),'',300/*reasonable limit*/);
if (count($rows)==300) $rows=array();
$where=array('category_id'=>$category_id);
if (!is_null($submitter)) $where['submitter']=$submitter;
$erows=$GLOBALS['SITE_DB']->query_select('download_downloads',array('id','name','submitter','original_filename'),$where,'ORDER BY add_date DESC',300/*reasonable limit*/);
$children[0]['entries']=array();
foreach ($erows as $row)
{
if (($tar_filter) && (substr(strtolower($row['original_filename']),-4)!='.tar')) continue;
if (($editable_filter) && (!has_edit_permission('mid',get_member(),$row['submitter'],'cms_downloads',array('download_downloads',$category_id)))) continue;
if ((!is_null($shun)) && ($shun==$row['id'])) continue;
$children[0]['entries'][$row['id']]=get_translated_text($row['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) || ($use_compound_list))
{
foreach ($rows as $child)
{
$child_id=$child['id'];
$child_title=get_translated_text($child['category']);
$child_tree=$tree;
$child_children=get_downloads_tree($submitter,$child_id,$child_tree,$child_title,$shun,is_null($levels)?NULL:max(0,$levels-1),$use_compound_list,$editable_filter,$tar_filter);
if ($use_compound_list)
{
list($child_children,$_compound_list)=$child_children;
$compound_list.=$_compound_list;
}
if ($levels!==0)
$children=array_merge($children,$child_children);
}
}
$children[0]['compound_list']=$compound_list;
return $use_compound_list?array($children,$compound_list):$children;
}
tempcode nice_get_download_category_tree(?AUTO_LINK it, boolean use_compound_list, boolean addable_filter)
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 |
it |
| Description |
The currently selected category (NULL: none selected) |
| Default value |
|
| Type |
?AUTO_LINK |
| 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 |
| Name |
addable_filter |
| Description |
Whether to only show for what may be added to by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list of categories |
| Type |
tempcode |
function nice_get_download_category_tree($it=NULL,$use_compound_list=false,$addable_filter=false)
{
$tree=get_download_category_tree(NULL,NULL,NULL,false,$use_compound_list,NULL,$addable_filter);
if ($use_compound_list) $tree=$tree[0];
$out=''; // XHTMLXHTML
foreach ($tree as $category)
{
if (($addable_filter) && (!$category['addable'])) continue;
$selected=($category['id']==$it);
$line=do_template('DOWNLOAD_LIST_LINE_2',array('_GUID'=>'0ccffeff5b80b1840188b839aee8d9f2','TREE'=>$category['tree'],'FILECOUNT'=>'?'));
$out.='<option value="'.(!$use_compound_list?strval($category['id']):$category['compound_list']).'"'.($selected?' selected="selected"':'').'>'.$line->evaluate().'</option>';
}
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($out);
return make_string_tempcode($out);
}
tempcode nice_get_download_licences(?AUTO_LINK it, boolean allow_na)
Get a nice, formatted XHTML list to select a download licence
Parameters…
| Name |
it |
| Description |
The currently selected licence (NULL: none selected) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
allow_na |
| Description |
Whether to allow an N/A selection |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list of categories |
| Type |
tempcode |
function nice_get_download_licences($it=NULL,$allow_na=false)
{
$list=new ocp_tempcode();
if ($allow_na) $list->attach(form_input_list_entry('-1',false,do_lang_tempcode('NA_EM')));
$rows=$GLOBALS['SITE_DB']->query_select('download_licences',array('id','l_title'));
foreach ($rows as $row)
{
$list->attach(form_input_list_entry(strval($row['id']),$it==$row['id'],$row['l_title']));
}
return $list;
}
array get_download_category_tree(?AUTO_LINK category_id, ?string tree, ?ID_TEXT title, boolean do_stats, boolean use_compound_list, ?integer levels, boolean addable_filter)
Get a list of maps containing all the subcategories, and path information, of the specified category - and those beneath it, recursively.
Parameters…
| Name |
category_id |
| Description |
The category being at the root of our recursion (NULL: true root category) |
| 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 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 |
?ID_TEXT |
| Name |
do_stats |
| Description |
Whether to collect download counts with our tree information |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
use_compound_list |
| Description |
Whether to make a compound list (a pair of a comma-separated list of children, and the child array) |
| Default value |
boolean-false |
| Type |
boolean |
| 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 |
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). There is also an additional 'downloadcount' entry if stats were requested |
| Type |
array |
function get_download_category_tree($category_id=NULL,$tree=NULL,$title=NULL,$do_stats=true,$use_compound_list=false,$levels=NULL,$addable_filter=false)
{
if ($levels==-1) return array();
// if (!has_category_access(get_member(),'downloads',strval($category_id))) return array();
if (is_null($category_id)) $category_id=db_get_first_id();
if (is_null($tree)) $tree='';
// Put our title onto our tree
if (is_null($title)) $title=get_translated_text($GLOBALS['SITE_DB']->query_value('download_categories','category',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[0]['compound_list']=strval($category_id).',';
if ($addable_filter) $children[0]['addable']=has_submit_permission('mid',get_member(),get_ip_address(),'cms_downloads',array('downloads',$category_id));
if ($do_stats) $children[0]['filecount']=$GLOBALS['SITE_DB']->query_value('download_downloads','COUNT(*)',array('category_id'=>$category_id));
// Children of this category
$rows=$GLOBALS['SITE_DB']->query_select('download_categories',array('id','category'),array('parent_id'=>$category_id),'',300/*reasonable*/);
if (count($rows)==300) $rows=array();
$children[0]['child_count']=count($rows);
$tree.=' > ';
if ($levels!==0)
{
foreach ($rows as $child)
{
$child_id=$child['id'];
$child_title=get_translated_text($child['category']);
$child_tree=$tree;
$child_children=get_download_category_tree($child_id,$child_tree,$child_title,$do_stats,$use_compound_list,is_null($levels)?NULL:max(0,$levels-1),$addable_filter);
if ($use_compound_list)
{
list($child_children,$_compound_list)=$child_children;
$children[0]['compound_list'].=$_compound_list;
}
$children=array_merge($children,$child_children);
}
}
return $use_compound_list?array($children,$children[0]['compound_list']):$children;
}
tempcode download_breadcrumbs(AUTO_LINK category_id, ?AUTO_LINK root, boolean no_link_for_me_sir, ?ID_TEXT zone)
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 |
| Name |
zone |
| Description |
The zone the download module we're using is in (NULL: find it) |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
The tree route |
| Type |
tempcode |
function download_breadcrumbs($category_id,$root=NULL,$no_link_for_me_sir=true,$zone=NULL)
{
if (is_null($root)) $root=db_get_first_id();
if (is_null($zone)) $zone=get_module_zone('downloads');
$url=build_url(array('page'=>'downloads','type'=>'misc','id'=>($category_id==db_get_first_id())?NULL:$category_id,'root'=>($root==db_get_first_id())?NULL:$root),$zone);
if (($category_id==$root) || ($category_id==db_get_first_id()))
{
if ($no_link_for_me_sir) return new ocp_tempcode();
$title=get_translated_text($GLOBALS['SITE_DB']->query_value('download_categories','category',array('id'=>$category_id)));
return hyperlink($url,escape_html($title),false,false,do_lang_tempcode('GO_BACKWARDS_TO',$title),NULL,NULL,'up');
}
global $PT_PAIR_CACHE_D;
if (!array_key_exists($category_id,$PT_PAIR_CACHE_D))
{
$category_rows=$GLOBALS['SITE_DB']->query_select('download_categories',array('parent_id','category'),array('id'=>$category_id),'',1);
if (!array_key_exists(0,$category_rows)) warn_exit(do_lang_tempcode('CAT_NOT_FOUND',strval($category_id)));
$PT_PAIR_CACHE_D[$category_id]=$category_rows[0];
}
$title=get_translated_text($PT_PAIR_CACHE_D[$category_id]['category']);
if (!$no_link_for_me_sir)
{
$tpl_url=do_template('BREADCRUMB_ESCAPED');
$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();
if ($PT_PAIR_CACHE_D[$category_id]['parent_id']==$category_id) fatal_exit(do_lang_tempcode('RECURSIVE_TREE_CHAIN',strval($category_id)));
$below=download_breadcrumbs($PT_PAIR_CACHE_D[$category_id]['parent_id'],$root,false,$zone);
$below->attach($tpl_url);
return $below;
}
array count_download_category_children(AUTO_LINK category_id)
Count the downloads 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 downloads is returned in $output['num_downloads'], and the number of subcategories is returned in $output['num_children'], and the (possibly recursive) number of downloads is returned in $output['num_downloads_children']. |
| Type |
array |
function count_download_category_children($category_id)
{
static $total_categories=NULL;
if (is_null($total_categories)) $total_categories=$GLOBALS['SITE_DB']->query_value('download_categories','COUNT(*)');
$out=array();
$out['num_children']=$GLOBALS['SITE_DB']->query_value('download_categories','COUNT(*)',array('parent_id'=>$category_id));
$out['num_downloads']=$GLOBALS['SITE_DB']->query_value('download_downloads','COUNT(*)',array('category_id'=>$category_id,'validated'=>1));
$out['num_downloads_children']=$out['num_downloads'];
if ($total_categories<200) // Make sure not too much, performance issue
{
$rows=$GLOBALS['SITE_DB']->query_select('download_categories',array('id'),array('parent_id'=>$category_id));
foreach ($rows as $child)
{
$temp=count_download_category_children($child['id']);
$out['num_downloads_children']+=$temp['num_downloads_children'];
}
}
return $out;
}
tempcode get_category_downloads(AUTO_LINK category_id, AUTO_LINK root, ?string order)
Get tempcode to view the downloads in a download category.
Parameters…
| Name |
category_id |
| Description |
The download category ID |
| Type |
AUTO_LINK |
| Name |
root |
| Description |
The virtual root |
| Type |
AUTO_LINK |
| Name |
order |
| Description |
Force an order (NULL: don't) |
| Default value |
|
| Type |
?string |
Returns…
| Description |
The UI |
| Type |
tempcode |
function get_category_downloads($category_id,$root,$order=NULL)
{
$max=get_param_integer('max',30);
$start=get_param_integer('start',0);
// How many might there have been? (So we know how to browse pages nicely)
$map=array('category_id'=>$category_id);
if (!has_specific_permission(get_member(),'see_unvalidated')) $map['validated']=1;
$max_rows=$GLOBALS['SITE_DB']->query_value('download_downloads','COUNT(*)',$map);
// Quick security check
if (is_null($order))
{
$order=get_param('order',NULL);
if (is_null($order))
{
if ($max_rows<1000)
{
$order='t.text_original ASC';
} else
{
$order='num_downloads DESC';
}
}
}
if ((strtoupper($order)!=strtoupper('t.text_original ASC')) && (strtoupper($order)!=strtoupper('t.text_original DESC')) && (strtoupper($order)!=strtoupper('file_size ASC')) && (strtoupper($order)!=strtoupper('file_size DESC'))
&& (strtoupper($order)!=strtoupper('num_downloads DESC')) && (strtoupper($order)!=strtoupper('add_date ASC'))
&& (strtoupper($order)!=strtoupper('add_date DESC'))) log_hack_attack_and_exit('ORDERBY_HACK');
global $NON_CANONICAL_PARAMS;
$NON_CANONICAL_PARAMS[]='order';
// Fetch
$rows=$GLOBALS['SITE_DB']->query_select('download_downloads d LEFT JOIN '.get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND d.name=t.id',array('d.*','text_original'),$map,'ORDER BY '.$order,$max,$start);
$out=new ocp_tempcode();
foreach ($rows as $myrow)
{
if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($myrow['text_original'])) $myrow['text_original']=get_translated_text($myrow['description']);
$out->attach(get_download_html($myrow,true,false));
$out->attach(do_template('BLOCK_SEPARATOR',array('_GUID'=>'ea7sddsdsfds5bsddsdsdsc586e6e6536')));
}
if ($out->is_empty()) return $out;
require_code('templates_results_browser');
$out->attach(results_browser(do_lang_tempcode('SECTION_DOWNLOADS'),$category_id,$start,'start',$max,'max',$max_rows,$root,'misc'));
return $out;
}
tempcode get_download_sub_categories(AUTO_LINK category_id, ?AUTO_LINK root, ?ID_TEXT zone, ?string order)
Get a templated view of the subcategories directly under the specified category.
Parameters…
| Name |
category_id |
| Description |
The category the subcategories are being found for |
| Type |
AUTO_LINK |
| Name |
root |
| Description |
The pretend root of our download system (NULL: true root). This system is provided for large sites to be able to do virtually seperated download systems |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
zone |
| Description |
The zone the download module we're using is in (NULL: find it) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
order |
| Description |
The order to show results in (NULL: default) |
| Default value |
|
| Type |
?string |
Returns…
| Description |
The templated view |
| Type |
tempcode |
function get_download_sub_categories($category_id,$root=NULL,$zone=NULL,$order=NULL)
{
if (is_null($order)) $order='t.text_original ASC';
if (is_null($root)) $root=db_get_first_id();
if (is_null($zone)) $zone=get_module_zone('downloads');
$rows=$GLOBALS['SITE_DB']->query_select('download_categories c LEFT JOIN '.get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND c.category=t.id',array('rep_image','c.id','category','text_original','description'),array('parent_id'=>$category_id),(($order=='t.text_original ASC')?'':('ORDER BY '.$order)),400/*reasonable limit*/);
if ($order=='t.text_original ASC')
{
global $M_SORT_KEY;
$M_SORT_KEY='text_original';
usort($rows,'multi_sort');
}
if (count($rows)==400) $rows=array(); // Too much, performance issue
$out=new ocp_tempcode();
foreach ($rows as $myrow)
{
if (!has_category_access(get_member(),'downloads',strval($myrow['id']))) continue;
if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($myrow['text_original'])) $myrow['text_original']=get_translated_text($myrow['category']);
$child_id=$myrow['id'];
$child_title=$myrow['text_original'];
$info=count_download_category_children($child_id);
$num_children=$info['num_children'];
$num_downloads=$info['num_downloads_children'];
$display_string=do_lang_tempcode('CATEGORY_SUBORDINATE',integer_format($num_downloads),integer_format($num_children));
$url=build_url(array('page'=>'downloads','type'=>'misc','id'=>($child_id==db_get_first_id())?NULL:$child_id,'root'=>($root==db_get_first_id())?NULL:$root,'order'=>get_param('order',NULL)),$zone);
if ($myrow['rep_image']!='')
{
require_code('images');
$rep_image=do_image_thumb($myrow['rep_image'],'');
} else $rep_image=new ocp_tempcode();
$ajax_edit_url='_SEARCH:cms_downloads:type=__ec:id='.strval($child_id);
$description=get_translated_tempcode($myrow['description']);
$out->attach(do_template('CATEGORY_ENTRY',array('_GUID'=>'8bfb36d75a85e2a7fbf5222f8fc61c7d','DESCRIPTION'=>$description,'ID'=>strval($child_id),'NAME_FIELD'=>'category','AJAX_EDIT_URL'=>$ajax_edit_url,'URL'=>$url,'REP_IMAGE'=>$rep_image,'CHILDREN'=>$display_string,'NAME'=>$child_title,'NAME_PLAIN'=>$child_title)));
}
if ($out->is_empty()) return $out;
return do_template('CATEGORY_LIST',array('_GUID'=>'2de3e2cdd0180a584b4f4ec72652716f','CONTENT'=>$out));
}
sources/downloads2.php
Global_functions_downloads2.php
Function summary
|
void
|
init__downloads2 ()
|
|
void
|
dload_script ()
|
|
AUTO_LINK
|
add_download_category (SHORT_TEXT category, AUTO_LINK parent_id, LONG_TEXT description, LONG_TEXT notes, URLPATH rep_image, ?AUTO_LINK id)
|
|
void
|
edit_download_category (SHORT_TEXT category, AUTO_LINK parent_id, LONG_TEXT description, AUTO_LINK category_id, LONG_TEXT notes, URLPATH rep_image, ?SHORT_TEXT meta_keywords, ?LONG_TEXT meta_description)
|
|
void
|
delete_download_category (AUTO_LINK category_id)
|
|
LONG_TEXT
|
create_data_mash (URLPATH url, ?string data, ?ID_TEXT extension, boolean direct_path)
|
|
AUTO_LINK
|
add_download (AUTO_LINK category_id, SHORT_TEXT name, URLPATH url, LONG_TEXT description, ID_TEXT author, LONG_TEXT comments, ?AUTO_LINK out_mode_id, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, SHORT_TEXT original_filename, integer file_size, integer cost, BINARY submitter_gets_points, ?AUTO_LINK licence, ?TIME add_date, integer num_downloads, integer views, ?MEMBER submitter, ?TIME edit_date, ?AUTO_LINK id)
|
|
void
|
set_download_gallery_permissions (AUTO_LINK id, ?MEMBER submitter)
|
|
void
|
edit_download (AUTO_LINK id, AUTO_LINK category_id, SHORT_TEXT name, URLPATH url, LONG_TEXT description, ID_TEXT author, LONG_TEXT comments, AUTO_LINK out_mode_id, integer default_pic, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, SHORT_TEXT original_filename, integer file_size, integer cost, BINARY submitter_gets_points, ?AUTO_LINK licence, SHORT_TEXT meta_keywords, LONG_TEXT meta_description)
|
|
void
|
delete_download (AUTO_LINK id, boolean leave)
|
|
AUTO_LINK
|
add_download_licence (SHORT_TEXT title, LONG_TEXT text)
|
|
void
|
edit_download_licence (AUTO_LINK id, SHORT_TEXT title, LONG_TEXT text)
|
|
void
|
delete_download_licence (AUTO_LINK id)
|
|
void
|
log_download (AUTO_LINK id, integer size, boolean got_before)
|
void init__downloads2()
Standard code module initialisation function.
Parameters…
(No return value)
function init__downloads2()
{
global $PT_PAIR_CACHE;
$PT_PAIR_CACHE=array();
}
void dload_script()
Farm out the files for downloads.
Parameters…
(No return value)
function dload_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'));
}
global $SITE_INFO;
if ((!is_guest()) || (!isset($SITE_INFO['any_guest_cached_too'])) || ($SITE_INFO['any_guest_cached_too']=='0'))
{
if ((get_param('for_session','-1')!=md5(strval(get_session_id()))) && (get_option('anti_leech')=='1') && (ocp_srv('HTTP_REFERER')!=''))
warn_exit(do_lang_tempcode('LEECH_BLOCK'));
}
require_lang('downloads');
$id=get_param_integer('id',0);
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Platform-Installer')!==false && $id==770)
$id=771;
// Lookup
$rows=$GLOBALS['SITE_DB']->query_select('download_downloads',array('*'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$rows[0];
// Permission
if (!has_category_access(get_member(),'downloads',strval($myrow['category_id'])))
access_denied('CATEGORY_ACCESS');
// Cost?
$got_before=$GLOBALS['SITE_DB']->query_value_null_ok('download_logging','the_user',array('the_user'=>get_member(),'id'=>$id));
if (addon_installed('points'))
{
if ($myrow['download_cost']>0)
{
require_code('points2');
$member=get_member();
if (is_guest($member))
access_denied('NOT_AS_GUEST');
// Check they haven't downloaded this before (they only get charged once - maybe they are resuming)
if (is_null($got_before))
{
$cost=$myrow['download_cost'];
$member=get_member();
if (is_guest($member))
access_denied('NOT_AS_GUEST');
$dif=$cost-available_points($member);
if (($dif>0) && (!has_specific_permission(get_member(),'have_negative_gift_points')))
warn_exit(do_lang_tempcode('LACKING_POINTS',integer_format($dif)));
require_code('points2');
charge_member($member,$cost,do_lang('DOWNLOADED_THIS',get_translated_text($myrow['name'])));
if ($myrow['download_submitter_gets_points']==1)
{
system_gift_transfer(do_lang('THEY_DOWNLOADED_THIS',get_translated_text($myrow['name'])),$cost,$myrow['submitter']);
}
}
}
}
// Filename
$full=$myrow['url'];
$breakdown=@pathinfo($full) OR warn_exit(do_lang_tempcode('HTTP_DOWNLOAD_NO_SERVER',$full));
// $filename=$breakdown['basename'];
if (!array_key_exists('extension',$breakdown)) $extension=''; else $extension=strtolower($breakdown['extension']);
if (url_is_local($full)) $_full=get_custom_file_base().'/'.rawurldecode(/*filter_naughty*/($full)); else $_full=rawurldecode($full);
// Is it non-local? If so, redirect
if ((!url_is_local($full)) || (!file_exists(get_file_base().'/'.rawurldecode(filter_naughty($full)))))
{
if (url_is_local($full)) $full=get_custom_base_url().'/'.$full;
if ((strpos($full,chr(10))!==false) || (strpos($full,chr(13))!==false))
log_hack_attack_and_exit('HEADER_SPLIT_HACK');
header('Location: '.$full);
log_download($id,0,!is_null($got_before)); // Bandwidth used is 0 for an external download
return;
}
// Some basic security: don't fopen php files
if ($extension=='php') log_hack_attack_and_exit('PHP_DOWNLOAD_INNOCENT',integer_format($id));
// Size, bandwidth, logging
$size=filesize($_full);
if (is_null($got_before))
{
$bandwidth=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT SUM(file_size) AS answer FROM '.get_table_prefix().'download_logging l LEFT JOIN '.get_table_prefix().'download_downloads d ON l.id=d.id WHERE date_and_time>'.strval(time()-24*60*60*32));
if ((($bandwidth+floatval($size))>(floatval(get_option('maximum_download'))*1024*1024*1024)) && (!has_specific_permission(get_member(),'bypass_bandwidth_restriction')))
warn_exit(do_lang_tempcode('TOO_MUCH_DOWNLOAD'));
require_code('files2');
check_shared_bandwidth_usage($size);
}
log_download($id,$size,!is_null($got_before));
// Send header
if ((strpos($myrow['original_filename'],chr(10))!==false) || (strpos($myrow['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')=='1')
{
require_code('mime_types');
header('Content-Type: '.get_mime_type(get_file_extension($myrow['original_filename'])).'; authoritative=true;');
header('Content-Disposition: filename="'.str_replace(chr(13),'',str_replace(chr(10),'',addslashes($myrow['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($myrow['original_filename']))).'"');
else
header('Content-Disposition: attachment; filename="'.str_replace(chr(13),'',str_replace(chr(10),'',addslashes($myrow['original_filename']))).'"');
}
header('Accept-Ranges: bytes');
// Caching
header("Pragma: private");
header("Cache-Control: private");
header('Expires: '.gmdate('D, d M Y H:i:s',time()+60*60*24*365).' GMT');
$time=is_null($myrow['edit_date'])?$myrow['add_date']:$myrow['edit_date'];
$time=max($time,filemtime($_full));
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$time).' GMT');
// 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);
}
/*
Security note... at the download adding/editing stage, we ensured that
only files accessible to the web server (in raw form) could end up in
our database.
Therefore we did not check here that our file was accessible in raw
form.
*/
}
AUTO_LINK add_download_category(SHORT_TEXT category, AUTO_LINK parent_id, LONG_TEXT description, LONG_TEXT notes, URLPATH rep_image, ?AUTO_LINK id)
Add a download category
Parameters…
| Name |
category |
| Description |
The name of the download category |
| Type |
SHORT_TEXT |
| Name |
parent_id |
| Description |
The parent download category |
| Type |
AUTO_LINK |
| Name |
description |
| Description |
A description |
| Type |
LONG_TEXT |
| Name |
notes |
| Description |
Hidden notes pertaining to this download category |
| Type |
LONG_TEXT |
| Name |
rep_image |
| Description |
The representative image for the category (blank: none) |
| Default value |
|
| Type |
URLPATH |
| 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 download category |
| Type |
AUTO_LINK |
function add_download_category($category,$parent_id,$description,$notes,$rep_image='',$id=NULL)
{
$map=array('rep_image'=>$rep_image,'add_date'=>time(),'notes'=>$notes,'category'=>insert_lang($category,2),'parent_id'=>$parent_id,'description'=>insert_lang_comcode($description,2));
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('download_categories',$map,true);
log_it('ADD_DOWNLOAD_CATEGORY',strval($id),$category);
require_code('seo2');
seo_meta_set_for_implicit('downloads_category',strval($id),array($category,$description),$description);
decache('main_download_category');
return $id;
}
void edit_download_category(SHORT_TEXT category, AUTO_LINK parent_id, LONG_TEXT description, AUTO_LINK category_id, LONG_TEXT notes, URLPATH rep_image, ?SHORT_TEXT meta_keywords, ?LONG_TEXT meta_description)
Edit the given download category with the new details given
Parameters…
| Name |
category |
| Description |
The name of the download category |
| Type |
SHORT_TEXT |
| Name |
parent_id |
| Description |
The parent download category |
| Type |
AUTO_LINK |
| Name |
description |
| Description |
A description |
| Type |
LONG_TEXT |
| Name |
category_id |
| Description |
The ID of the category being edited |
| Type |
AUTO_LINK |
| Name |
notes |
| Description |
Hidden notes pertaining to this download category |
| Type |
LONG_TEXT |
| Name |
rep_image |
| Description |
The representative image for the category (blank: none) |
| Type |
URLPATH |
| Name |
meta_keywords |
| Description |
Meta keywords for this resource (NULL: do not edit) |
| Type |
?SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description for this resource (NULL: do not edit) |
| Type |
?LONG_TEXT |
(No return value)
function edit_download_category($category,$parent_id,$description,$category_id,$notes,$rep_image,$meta_keywords,$meta_description)
{
$under_category_id=$parent_id;
while ((!is_null($under_category_id)) && ($under_category_id!=INTEGER_MAGIC_NULL))
{
if ($category_id==$under_category_id) warn_exit(do_lang_tempcode('OWN_PARENT_ERROR'));
$under_category_id=$GLOBALS['SITE_DB']->query_value('download_categories','parent_id',array('id'=>$under_category_id));
}
require_code('urls2');
suggest_new_idmoniker_for('downloads','misc',strval($category_id),$category);
$rows=$GLOBALS['SITE_DB']->query_select('download_categories',array('category','description'),array('id'=>$category_id),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$_category=$rows[0]['category'];
$_description=$rows[0]['description'];
$map=array('notes'=>$notes,'category'=>lang_remap($_category,$category),'parent_id'=>$parent_id,'description'=>lang_remap_comcode($_description,$description));
if (!is_null($rep_image))
{
$map['rep_image']=$rep_image;
require_code('files2');
delete_upload('uploads/grepimages','download_categories','rep_image','id',$category_id,$rep_image);
}
$GLOBALS['SITE_DB']->query_update('download_categories',$map,array('id'=>$category_id),'',1);
log_it('EDIT_DOWNLOAD_CATEGORY',strval($category_id),$category);
require_code('seo2');
seo_meta_set_for_explicit('downloads_category',strval($category_id),$meta_keywords,$meta_description);
decache('main_download_category');
}
void delete_download_category(AUTO_LINK category_id)
Delete a download category.
Parameters…
| Name |
category_id |
| Description |
The download category to delete |
| Type |
AUTO_LINK |
(No return value)
function delete_download_category($category_id)
{
$root_category=$GLOBALS['SITE_DB']->query_value('download_categories','MIN(id)');
if ($category_id==$root_category) warn_exit(do_lang_tempcode('NO_DELETE_ROOT'));
$rows=$GLOBALS['SITE_DB']->query_select('download_categories',array('category','description','parent_id'),array('id'=>$category_id),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$category=$rows[0]['category'];
$description=$rows[0]['description'];
require_code('files2');
delete_upload('uploads/grepimages','download_categories','rep_image','id',$category_id);
log_it('DELETE_DOWNLOAD_CATEGORY',strval($category_id),get_translated_text($category));
$GLOBALS['SITE_DB']->query_delete('download_categories',array('id'=>$category_id),'',1);
$GLOBALS['SITE_DB']->query_update('download_downloads',array('category_id'=>$rows[0]['parent_id']),array('category_id'=>$category_id));
$GLOBALS['SITE_DB']->query_update('download_categories',array('parent_id'=>$rows[0]['parent_id']),array('parent_id'=>$category_id));
delete_lang($category);
delete_lang($description);
require_code('seo2');
seo_meta_erase_storage('downloads_category',strval($category_id));
$GLOBALS['SITE_DB']->query_delete('group_category_access',array('module_the_name'=>'downloads','category_name'=>strval($category_id)));
$GLOBALS['SITE_DB']->query_delete('gsp',array('module_the_name'=>'downloads','category_name'=>strval($category_id)));
decache('main_download_category');
}
LONG_TEXT create_data_mash(URLPATH url, ?string data, ?ID_TEXT extension, boolean direct_path)
Create a data-mash from the file at a URL. This is data useful for the search engine.
Parameters…
| Name |
url |
| Description |
The URL to make a data-mash of, or a filename if $data isn't blank |
| Type |
URLPATH |
| Name |
data |
| Description |
Data (NULL: use URL) |
| Default value |
|
| Type |
?string |
| Name |
extension |
| Description |
File extension (NULL: get from URL) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
direct_path |
| Description |
Whether a direct file path was given instead of a URL |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The data-mash |
| Type |
LONG_TEXT |
function create_data_mash($url,$data=NULL,$extension=NULL,$direct_path=false)
{
if (function_exists('set_time_limit')) @set_time_limit(300);
if (get_value('no_dload_search_index')==='1') return '';
if (running_script('stress_test_loader')) return '';
if ((function_exists('memory_get_usage')) && (ini_get('memory_usage')=='8M'))
return ''; // Some cowardice... don't want to tempt fate
if (is_null($extension))
$extension=get_file_extension($url);
$tmp_file=NULL;
if (is_null($data))
{
if (($direct_path) || (url_is_local($url)))
{
$actual_path=$direct_path?$url:get_custom_file_base().'/'.rawurldecode($url);
if (file_exists($actual_path))
{
switch ($extension)
{
case 'zip':
case 'odt':
case 'odp':
case 'docx':
case 'tar':
case 'gz':
if (filesize($actual_path)>1024*1024*3) return '';
break;
}
$tmp_file=$actual_path;
if (filesize($actual_path)>1024*1024*3)
{
$myfile=fopen($actual_path,'rb');
$data='';
for ($i=0;$i<384;$i++)
$data.=fread($myfile,8192);
fclose($myfile);
} else
{
$data=file_get_contents($actual_path);
}
} else
{
$data='';
}
} else
{
switch ($extension)
{
case 'txt':
case '1st':
case 'rtf':
case 'pdf':
case 'htm':
case 'html':
case 'xml':
case 'doc':
case 'xls':
break; // Continue through to download good stuff
default:
return ''; // Don't download, it's not worth it
break;
}
$data=http_download_file($url,3*1024*1024,false); // 3MB is enough
if (is_null($data)) return '';
}
}
$mash='';
switch ($extension)
{
case 'zip':
case 'odt':
case 'odp':
case 'docx':
require_code('m_zip');
$tmp_file=ocp_tempnam('dcdm_');
$myfile2=fopen($tmp_file,'wb');
fwrite($myfile2,$data);
fclose($myfile2);
$myfile_zip=@zip_open($tmp_file);
if (!is_integer($myfile_zip))
{
while (($entry=(@zip_read($myfile_zip)))!==false) // Temporary file may be cleaned up before this can complete, hence @
{
$entry_name=@zip_entry_name($entry);
$mash.=' '.$entry_name;
if (substr($entry_name,-1)!='/')
{
$_entry=@zip_entry_open($myfile_zip,$entry);
if ($_entry!==false)
{
$file_data='';
while (true)
{
$it=@zip_entry_read($entry,1024);
if (($it===false) || ($it=='')) break;
$file_data.=$it;
if (strlen($file_data)>=3*1024*1024) break; // 3MB is enough
}
@zip_entry_close($entry);
$mash.=' '.create_data_mash($entry_name,$file_data);
if (strlen($mash)>=3*1024*1024) break; // 3MB is enough
}
}
}
@zip_close($myfile_zip);
}
unlink($tmp_file);
break;
case 'tar':
require_code('tar');
$tmp_file=ocp_tempnam('dcdm_');
$myfile=fopen($tmp_file,'wb');
fwrite($myfile,$data);
fclose($myfile);
$myfile_tar=tar_open($tmp_file,'rb');
if ($myfile_tar!==false)
{
$directory=tar_get_directory($myfile_tar);
foreach ($directory as $entry)
{
$entry_name=$entry['path'];
$mash.=' '.$entry_name;
if ($entry['size']>=3*1024*1024) continue; // 3MB is enough
$_entrya=tar_get_file($myfile_tar,$entry['path']);
if (!is_null($_entrya))
{
$mash.=' '.create_data_mash($entry_name,$_entrya['data']);
if (strlen($mash)>=3*1024*1024) break; // 3MB is enough
}
}
tar_close($myfile_tar);
}
unlink($tmp_file);
break;
case 'gz':
if (function_exists('gzopen'))
{
if (function_exists('gzeof'))
{
if (function_exists('gzread'))
{
$tmp_file=ocp_tempnam('dcdm_');
$myfile=fopen($tmp_file,'wb');
fwrite($myfile,$data);
fclose($myfile);
$myfile=gzopen($tmp_file,'rb');
if ($myfile!==false)
{
$file_data='';
while (!gzeof($myfile))
{
$it=gzread($myfile,1024);
$file_data.=$it;
if (strlen($file_data)>=3*1024*1024) break; // 3MB is enough
}
$mash=' '.create_data_mash(preg_replace('#\.gz#i','',$url),$file_data);
}
}
}
}
break;
case 'txt':
case '1st':
$mash.=$data;
break;
case 'rtf':
$len=strlen($data);
$skipping_section_depth=0;
$escape=false;
for ($i=0;$i<$len;$i++)
{
$byte=$data[$i];
if ((!$escape) && ($byte=="\\"))
{
$escape=true;
}
elseif ((!$escape) && ($byte=='{'))
{
if ($skipping_section_depth!=0) $skipping_section_depth++;
}
elseif ((!$escape) && ($byte=='}'))
{
if ($skipping_section_depth!=0) $skipping_section_depth--;
}
elseif (($escape) && ($byte!='{') && ($byte!="\\") && ($byte!='}'))
{
$end_pos_1=strpos($data,"\\",$i+1);
if ($end_pos_1===false) $end_pos_1=$len;
$end_pos_2=strpos($data,chr(10),$i+1);
if ($end_pos_2===false) $end_pos_2=$len;
$end_pos_3=strpos($data,' ',$i+1);
if ($end_pos_3===false) $end_pos_3=$len;
$end_pos_4=strpos($data,"\t",$i+1);
if ($end_pos_4===false) $end_pos_4=$len;
$end_pos_5=strpos($data,'{',$i+1);
if ($end_pos_5===false) $end_pos_5=$len;
$end_pos_6=strpos($data,'}',$i+1);
if ($end_pos_6===false) $end_pos_6=$len;
$end_pos=min($end_pos_1,$end_pos_2,$end_pos_3,$end_pos_4,$end_pos_5,$end_pos_6);
$tag=substr($data,$i,$end_pos-$i);
$tag=preg_replace('#[\-0-9]*#','',$tag);
if (($skipping_section_depth==0) && (($tag=='pgdsc') || ($tag=='comment') || ($tag=='object') || ($tag=='pict') || ($tag=='stylesheet') || ($tag=='fonttbl')))
{
$skipping_section_depth=1;
}
if ($tag=='par') $mash.=chr(10);
$i=$end_pos-1;
$escape=false;
}
elseif ($skipping_section_depth==0)
{
if (($byte!=chr(13)) && ($byte!=chr(10))) $mash.=$byte;
$escape=false;
} else $escape=false;
}
break;
case 'pdf':
if ((ini_get('safe_mode')!='1') && (strpos(@ini_get('disable_functions'),'shell_exec')===false) && (!is_null($tmp_file)))
{
$enc=(get_charset()=='utf-8')?' -enc UTF-8':'';
$path='pdftohtml -i -noframes -stdout -hidden'.$enc.' -q -xml '.@escapeshellarg($tmp_file);
if (strpos(strtolower(PHP_OS),'win')!==false)
if (file_exists(get_file_base().'/data_custom/pdftohtml.exe')) $path='"'.get_file_base().DIRECTORY_SEPARATOR.'data_custom'.DIRECTORY_SEPARATOR.'"'.$path;
$tmp_file_2=ocp_tempnam('pdfxml_');
@shell_exec($path.' > '.$tmp_file_2);
$mash=create_data_mash($tmp_file_2,NULL,'xml',true);
unlink($tmp_file_2);
}
break;
case 'htm':
case 'html':
$head_patterns=array('#<\s*script.*<\s*/\s*script\s*>#misU','#<\s*link[^<>]*>#misU','#<\s*style.*<\s*/\s*style\s*>#misU');
foreach ($head_patterns as $pattern)
{
$data=preg_replace($pattern,'',$data);
}
case 'xml':
$mash=str_replace(''','\'',str_replace(' false ',' ',str_replace(' true ',' ',@html_entity_decode(preg_replace('#\<[^\<\>]*\>#',' ',$data),ENT_QUOTES,get_charset()))));
$mash=preg_replace('#Error : Bad \w+#','',$mash);
break;
case 'xls':
case 'doc':
case 'ppt':
case 'hlp':
// default: // Binary formats are complex to parse, but whatsmore, as textual tagging isn't used, extraction can be done automatically as all identified text is good.
// Strip out interleaved nulls because they are used in wide-chars, obscuring the data
$sstring_regexp='[a-zA-Z0-9\'\-\x91\x92\x93\x94]';
$data=preg_replace('#('.$sstring_regexp.')\x00('.$sstring_regexp.')\x00#','${1}${2}',$data);
// Now try and extract strings
$matches=array();
$count=preg_match_all('#([a-zA-Z0-9\'\-\x91\x92\x93\x94\s]+)#',$data,$matches);
$min_length=10;
if ($extension=='xls') $min_length=4;
for ($i=0;$i<$count;$i++)
{
$x=$matches[1][$i];
if ((strlen($x)>$min_length) && ($x!=strtoupper($x)) && ($x!='Microsoft Word Document') && ($x!='WordDocument') && ($x!='SummaryInformation') && ($x!='DocumentSummaryInformation'))
$mash.=' '.$matches[1][$i];
}
break;
}
if (strlen($mash)>1024*1024*3) $mash=substr($mash,0,1024*1024*3);
$mash=preg_replace('# +#',' ',preg_replace('#[^\w\d-\-\']#',' ',$mash));
if (strlen($mash)>1024*1024*1*0.4) $mash=substr($mash,0,1024*1024*0.4);
return $mash;
}
AUTO_LINK add_download(AUTO_LINK category_id, SHORT_TEXT name, URLPATH url, LONG_TEXT description, ID_TEXT author, LONG_TEXT comments, ?AUTO_LINK out_mode_id, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, SHORT_TEXT original_filename, integer file_size, integer cost, BINARY submitter_gets_points, ?AUTO_LINK licence, ?TIME add_date, integer num_downloads, integer views, ?MEMBER submitter, ?TIME edit_date, ?AUTO_LINK id)
Add a download.
Parameters…
| Name |
category_id |
| Description |
The ID of the category the download is to be in |
| Type |
AUTO_LINK |
| Name |
name |
| Description |
The name of the download |
| Type |
SHORT_TEXT |
| Name |
url |
| Description |
The URL to the download |
| Type |
URLPATH |
| Name |
description |
| Description |
The description of the download |
| Type |
LONG_TEXT |
| Name |
author |
| Description |
The author of the download (not necessarily same as the submitter) |
| Type |
ID_TEXT |
| Name |
comments |
| Description |
The comments for the download |
| Type |
LONG_TEXT |
| Name |
out_mode_id |
| Description |
The out-mode-id (the ID of a download that this download is an old version of). Often people wonder why this is specified with the old version, and not the opposite with the new version - it is because statistically, we perceive more chance of downloads merging than splitting (NULL: none) |
| Type |
?AUTO_LINK |
| Name |
validated |
| Description |
Whether the download has been validated |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the download 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 download may be trackbacked |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes pertaining to the download |
| Type |
LONG_TEXT |
| Name |
original_filename |
| Description |
The downloads original filename (the URL may be obfuscated) |
| Type |
SHORT_TEXT |
| Name |
file_size |
| Description |
The file size of the download (we can't really detect this in real-time for remote URLs) |
| Type |
integer |
| Name |
cost |
| Description |
The cost of the download that members will have to pay to get it |
| Type |
integer |
| Name |
submitter_gets_points |
| Description |
Whether the submitter gets the points for the download (they are selling it) (otherwise they are just thrown out, which is an alternative model - one of enforcing community point building) |
| Type |
BINARY |
| Name |
licence |
| Description |
The licence to use (NULL: none) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
add_date |
| Description |
The add date for the download (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
num_downloads |
| Description |
The number of downloads that this download has had |
| Default value |
0 |
| Type |
integer |
| Name |
views |
| Description |
The number of views that this download has had |
| Default value |
0 |
| Type |
integer |
| Name |
submitter |
| Description |
The submitter (NULL: current user) |
| Default value |
|
| Type |
?MEMBER |
| Name |
edit_date |
| Description |
The edit date (NULL: never) |
| 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 newly added download |
| Type |
AUTO_LINK |
function add_download($category_id,$name,$url,$description,$author,$comments,$out_mode_id,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$original_filename,$file_size,$cost,$submitter_gets_points,$licence=NULL,$add_date=NULL,$num_downloads=0,$views=0,$submitter=NULL,$edit_date=NULL,$id=NULL)
{
if (is_null($add_date)) $add_date=time();
if (is_null($submitter)) $submitter=get_member();
if (($file_size==0) || (url_is_local($url)))
{
if (url_is_local($url))
{
$file_size=@filesize(get_custom_file_base().'/'.rawurldecode($url)) OR $file_size=NULL;
} else
{
$file_size=@filesize($url) OR $file_size=NULL;
}
}
$met=@ini_get('max_execution_time');
$data_mash=($url=='')?'':create_data_mash($url,NULL,get_file_extension($original_filename));
if (function_exists('set_time_limit')) @set_time_limit($met);
if (!addon_installed('unvalidated')) $validated=1;
$map=array('download_data_mash'=>$data_mash,'download_licence'=>$licence,'rep_image'=>'','edit_date'=>$edit_date,'download_submitter_gets_points'=>$submitter_gets_points,'download_cost'=>$cost,'original_filename'=>$original_filename,'download_views'=>$views,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'submitter'=>$submitter,'default_pic'=>1,'num_downloads'=>$num_downloads,'out_mode_id'=>$out_mode_id,'category_id'=>$category_id,'name'=>insert_lang($name,2),'url'=>$url,'description'=>insert_lang_comcode($description,3),'author'=>$author,'comments'=>insert_lang_comcode($comments,3),'validated'=>$validated,'add_date'=>$add_date,'file_size'=>$file_size);
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('download_downloads',$map,true);
require_code('seo2');
seo_meta_set_for_implicit('downloads_download',strval($id),array($name,$description,$comments),$description);
// Make its gallery
if ((addon_installed('galleries')) && (!running_script('stress_test_loader')))
{
$test=$GLOBALS['SITE_DB']->query_value_null_ok('galleries','name',array('name'=>'download_'.strval($id)));
if (is_null($test))
{
require_code('galleries2');
$download_gallery_root=get_option('download_gallery_root');
if (is_null($download_gallery_root)) $download_gallery_root='root';
add_gallery('download_'.strval($id),do_lang('GALLERY_FOR_DOWNLOAD',$name),'','','',$download_gallery_root);
set_download_gallery_permissions($id,$submitter);
}
}
// Stat
update_stat('num_archive_downloads',1);
if ($file_size>0) update_stat('archive_size',$file_size);
if ($validated==1)
{
require_lang('downloads');
require_code('notifications');
$subject=do_lang('DOWNLOAD_NOTIFICATION_MAIL_SUBJECT',get_site_name(),$name);
$self_url=build_url(array('page'=>'downloads','type'=>'entry','id'=>$id),get_module_zone('downloads'),NULL,false,false,true);
$mail=do_lang('DOWNLOAD_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($name),array(comcode_escape($self_url->evaluate())));
dispatch_notification('download',strval($category_id),$subject,$mail);
}
log_it('ADD_DOWNLOAD',strval($id),$name);
decache('main_recent_downloads');
decache('main_top_downloads');
decache('main_download_category');
decache('main_download_tease');
return $id;
}
void set_download_gallery_permissions(AUTO_LINK id, ?MEMBER submitter)
Set the permissions for a download gallery.
Parameters…
| Name |
id |
| Description |
The ID of the download |
| Type |
AUTO_LINK |
| Name |
submitter |
| Description |
The submitter (NULL: work out automatically) |
| Default value |
|
| Type |
?MEMBER |
(No return value)
function set_download_gallery_permissions($id,$submitter=NULL)
{
if (is_null($submitter)) $submitter=$GLOBALS['SITE_DB']->query_value('download_downloads','submitter',array('id'=>$id));
$download_gallery_root=get_option('download_gallery_root');
if (is_null($download_gallery_root)) $download_gallery_root='root';
// Copy through requisite permissions
// TODO: This code will need updating in v10
$GLOBALS['SITE_DB']->query_delete('group_category_access',array('module_the_name'=>'galleries','category_name'=>'download_'.strval($id)));
$perms=$GLOBALS['SITE_DB']->query_select('group_category_access',array('*'),array('module_the_name'=>'galleries','category_name'=>$download_gallery_root));
foreach ($perms as $perm)
{
$perm['category_name']='download_'.strval($id);
$GLOBALS['SITE_DB']->query_insert('group_category_access',$perm);
}
$GLOBALS['SITE_DB']->query_delete('gsp',array('module_the_name'=>'galleries','category_name'=>'download_'.strval($id)));
$perms=$GLOBALS['SITE_DB']->query_select('gsp',array('*'),array('module_the_name'=>'galleries','category_name'=>$download_gallery_root));
foreach ($perms as $perm)
{
$perm['category_name']='download_'.strval($id);
$GLOBALS['SITE_DB']->query_insert('gsp',$perm);
}
// If they were able to submit the download, they should be able to submit extra images
$GLOBALS['SITE_DB']->query_delete('msp',array('module_the_name'=>'galleries','category_name'=>'download_'.strval($id)));
foreach (array('submit_midrange_content') as $privilege)
{
$GLOBALS['SITE_DB']->query_insert('msp',array('active_until'=>2147483647/*FUDGEFUDGE*/,'member_id'=>$submitter,'specific_permission'=>$privilege,'the_page'=>'','module_the_name'=>'galleries','category_name'=>'download_'.strval($id),'the_value'=>'1'));
}
}
void edit_download(AUTO_LINK id, AUTO_LINK category_id, SHORT_TEXT name, URLPATH url, LONG_TEXT description, ID_TEXT author, LONG_TEXT comments, AUTO_LINK out_mode_id, integer default_pic, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, SHORT_TEXT original_filename, integer file_size, integer cost, BINARY submitter_gets_points, ?AUTO_LINK licence, SHORT_TEXT meta_keywords, LONG_TEXT meta_description)
Edit a download.
Parameters…
| Name |
id |
| Description |
The ID of the download to edit |
| Type |
AUTO_LINK |
| Name |
category_id |
| Description |
The ID of the category the download is to be in |
| Type |
AUTO_LINK |
| Name |
name |
| Description |
The name of the download |
| Type |
SHORT_TEXT |
| Name |
url |
| Description |
The URL to the download |
| Type |
URLPATH |
| Name |
description |
| Description |
The description of the download |
| Type |
LONG_TEXT |
| Name |
author |
| Description |
The author of the download (not necessarily same as the submitter) |
| Type |
ID_TEXT |
| Name |
comments |
| Description |
The comments for the download |
| Type |
LONG_TEXT |
| Name |
out_mode_id |
| Description |
The out-mode-id (the ID of a download that this download is an old version of). Often people wonder why this is specified with the old version, and not the opposite with the new version - it is because statistically, we perceive more chance of downloads merging than splitting |
| Type |
AUTO_LINK |
| Name |
default_pic |
| Description |
The ordered number of the gallery image to use as the download representative image |
| Type |
integer |
| Name |
validated |
| Description |
Whether the download has been validated |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the download 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 download may be trackbacked |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes pertaining to the download |
| Type |
LONG_TEXT |
| Name |
original_filename |
| Description |
The downloads original filename (the URL may be obfuscated) |
| Type |
SHORT_TEXT |
| Name |
file_size |
| Description |
The file size of the download (we can't really detect this in real-time for remote URLs) |
| Type |
integer |
| Name |
cost |
| Description |
The cost of the download that members will have to pay to get it |
| Type |
integer |
| Name |
submitter_gets_points |
| Description |
Whether the submitter gets the points for the download (they are selling it) (otherwise they are just thrown out, which is an alternative model - one of enforcing community point building) |
| Type |
BINARY |
| Name |
licence |
| Description |
The licence to use (NULL: none) |
| Type |
?AUTO_LINK |
| Name |
meta_keywords |
| Description |
Meta keywords |
| Type |
SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description |
| Type |
LONG_TEXT |
(No return value)
function edit_download($id,$category_id,$name,$url,$description,$author,$comments,$out_mode_id,$default_pic,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$original_filename,$file_size,$cost,$submitter_gets_points,$licence,$meta_keywords,$meta_description)
{
require_code('urls2');
suggest_new_idmoniker_for('downloads','view',strval($id),$name);
if (($file_size==0) || (url_is_local($url)))
{
if (url_is_local($url))
{
$file_size=filesize(get_custom_file_base().'/'.rawurldecode($url));
} else
{
$file_size=@filesize($url) OR $file_size=NULL;
}
}
$myrows=$GLOBALS['SITE_DB']->query_select('download_downloads',array('name','description','comments'),array('id'=>$id),'',1);
if (!array_key_exists(0,$myrows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$myrows[0];
require_code('seo2');
seo_meta_set_for_explicit('downloads_download',strval($id),$meta_keywords,$meta_description);
require_code('files2');
delete_upload('uploads/downloads','download_downloads','url','id',$id,$url);
$met=@ini_get('max_execution_time');
$data_mash=create_data_mash($url,NULL,get_file_extension($original_filename));
if (function_exists('set_time_limit')) @set_time_limit($met);
if (!addon_installed('unvalidated')) $validated=1;
require_code('submit');
$just_validated=(!content_validated('download',strval($id))) && ($validated==1);
if ($just_validated)
{
send_content_validated_notification('download',strval($id));
}
$map=array('download_data_mash'=>$data_mash,'download_licence'=>$licence,'original_filename'=>$original_filename,'download_submitter_gets_points'=>$submitter_gets_points,'download_cost'=>$cost,'edit_date'=>time(),'file_size'=>$file_size,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'name'=>lang_remap($myrow['name'],$name),'description'=>lang_remap_comcode($myrow['description'],$description),'comments'=>lang_remap_comcode($myrow['comments'],$comments),'validated'=>$validated,'category_id'=>$category_id,'url'=>$url,'author'=>$author,'default_pic'=>$default_pic,'out_mode_id'=>$out_mode_id);
$GLOBALS['SITE_DB']->query_update('download_downloads',$map,array('id'=>$id),'',1);
$self_url=build_url(array('page'=>'downloads','type'=>'entry','id'=>$id),get_module_zone('downloads'),NULL,false,false,true);
if ($just_validated)
{
require_lang('downloads');
require_code('notifications');
$subject=do_lang('DOWNLOAD_NOTIFICATION_MAIL_SUBJECT',get_site_name(),$name);
$mail=do_lang('DOWNLOAD_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($name),array(comcode_escape($self_url->evaluate())));
dispatch_notification('download',strval($category_id),$subject,$mail);
}
log_it('EDIT_DOWNLOAD',strval($id),get_translated_text($myrow['name']));
if (addon_installed('galleries'))
{
// Change its gallery
require_code('galleries2');
$download_gallery_root=get_option('download_gallery_root');
if (is_null($download_gallery_root)) $download_gallery_root='root';
$test=$GLOBALS['SITE_DB']->query_value('galleries','parent_id',array('name'=>'download_'.strval($id)));
if (!is_null($test))
edit_gallery('download_'.strval($id),'download_'.strval($id),do_lang('GALLERY_FOR_DOWNLOAD',$name),'','','',$download_gallery_root);
}
decache('main_recent_downloads');
decache('main_top_downloads');
decache('main_download_category');
decache('main_download_tease');
require_code('feedback');
update_spacer_post($allow_comments!=0,'downloads',strval($id),$self_url,$name,get_value('comment_forum__downloads'));
}
void delete_download(AUTO_LINK id, boolean leave)
Delete a download.
Parameters…
| Name |
id |
| Description |
The ID of the download to delete |
| Type |
AUTO_LINK |
| Name |
leave |
| Description |
Whether to leave the actual file behind |
| Default value |
boolean-false |
| Type |
boolean |
(No return value)
function delete_download($id,$leave=false)
{
$myrows=$GLOBALS['SITE_DB']->query_select('download_downloads',array('name','description','comments'),array('id'=>$id),'',1);
if (!array_key_exists(0,$myrows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$myrows[0];
log_it('DELETE_DOWNLOAD',strval($id),get_translated_text($myrow['name']));
delete_lang($myrow['name']);
delete_lang($myrow['description']);
delete_lang($myrow['comments']);
require_code('seo2');
seo_meta_erase_storage('downloads_download',strval($id));
if (!$leave)
{
require_code('files2');
delete_upload('uploads/downloads','download_downloads','url','id',$id);
}
// Delete from database
$GLOBALS['SITE_DB']->query_delete('download_downloads',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'downloads','rating_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('trackbacks',array('trackback_for_type'=>'downloads','trackback_for_id'=>$id));
$GLOBALS['SITE_DB']->query_update('download_downloads',array('out_mode_id'=>NULL),array('out_mode_id'=>$id),'',1);
if (addon_installed('galleries'))
{
// Delete gallery
$name='download_'.strval($id);
require_code('galleries2');
$test=$GLOBALS['SITE_DB']->query_value('galleries','parent_id',array('name'=>'download_'.strval($id)));
if (!is_null($test))
delete_gallery($name);
}
decache('main_recent_downloads');
decache('main_top_downloads');
decache('main_download_category');
decache('main_download_tease');
}
AUTO_LINK add_download_licence(SHORT_TEXT title, LONG_TEXT text)
Add a download licence.
Parameters…
| Name |
title |
| Description |
The title of the download licence |
| Type |
SHORT_TEXT |
| Name |
text |
| Description |
The text of the download licence |
| Type |
LONG_TEXT |
Returns…
| Description |
The ID of the new download licence |
| Type |
AUTO_LINK |
function add_download_licence($title,$text)
{
$id=$GLOBALS['SITE_DB']->query_insert('download_licences',array('l_title'=>$title,'l_text'=>$text),true);
log_it('ADD_DOWNLOAD_LICENCE',strval($id),$title);
return $id;
}
void edit_download_licence(AUTO_LINK id, SHORT_TEXT title, LONG_TEXT text)
Edit a download licence.
Parameters…
| Name |
id |
| Description |
The ID of the download licence to edit |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The title of the download licence |
| Type |
SHORT_TEXT |
| Name |
text |
| Description |
The text of the download licence |
| Type |
LONG_TEXT |
(No return value)
function edit_download_licence($id,$title,$text)
{
$GLOBALS['SITE_DB']->query_update('download_licences',array('l_title'=>$title,'l_text'=>$text),array('id'=>$id),'',1);
log_it('EDIT_DOWNLOAD_LICENCE',strval($id),$title);
}
void delete_download_licence(AUTO_LINK id)
Delete a download licence.
Parameters…
| Name |
id |
| Description |
The ID of the download licence to delete |
| Type |
AUTO_LINK |
(No return value)
function delete_download_licence($id)
{
$myrows=$GLOBALS['SITE_DB']->query_select('download_licences',array('l_title'),array('id'=>$id),'',1);
if (!array_key_exists(0,$myrows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$myrows[0];
$GLOBALS['SITE_DB']->query_delete('download_licences',array('id'=>$id),'',1);
log_it('DELETE_DOWNLOAD_LICENCE',strval($id),$myrow['l_title']);
$GLOBALS['SITE_DB']->query_update('download_downloads',array('download_licence'=>NULL),array('download_licence'=>$id));
}
void log_download(AUTO_LINK id, integer size, boolean got_before)
Log a file download, update the downloads counter and the download bandwidth counter.
Parameters…
| Name |
id |
| Description |
The ID of the download being downloaded |
| Type |
AUTO_LINK |
| Name |
size |
| Description |
The size of the download (if zero, no bandwidth will be done - zero implies either an empty file, or a remote file that doesn't affect our bandwidth) |
| Type |
integer |
| Name |
got_before |
| Description |
Whether the download has been downloaded before |
| Type |
boolean |
(No return value)
function log_download($id,$size,$got_before)
{
// Log
if (!$got_before)
$GLOBALS['SITE_DB']->query_insert('download_logging',array('id'=>$id,'the_user'=>get_member(),'ip'=>get_ip_address(),'date_and_time'=>time()),false,true); // Supress errors in case of race condition
// Update download count
$GLOBALS['SITE_DB']->query('UPDATE '.get_table_prefix().'download_downloads SET num_downloads=(num_downloads+1) WHERE id='.strval((integer)$id),1);
// Update stats
$GLOBALS['SITE_DB']->query('UPDATE '.get_table_prefix().'values SET the_value=(the_value+1) WHERE the_name=\'num_downloads_downloaded\'',1);
if ($size!=0) $GLOBALS['SITE_DB']->query('UPDATE '.get_table_prefix().'values SET the_value=(the_value+'.strval((integer)$size).') WHERE the_name=\'download_bandwidth\'',1);
}
0 reviews: Unrated (average)
There have been no comments yet