Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 199 lines (173 sloc) 6.344 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
<?php /*

ocPortal
Copyright (c) ocProducts, 2004-2012

See text/EN/licence.txt for full licencing information.


NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core
*/

/**
* Find a different content type code from the one had. In future we intend to change everything to be cma_hook internally.
*
* @param ID_TEXT Content type type we know
* @set addon cma_hook award_hook search_hook table seo_type_code feedback_type_code permissions_type_code module
* @param ID_TEXT Content type ID we know
* @param ID_TEXT Desired content type
* @set addon cma_hook search_hook table seo_type_code feedback_type_code permissions_type_code module
* @return ID_TEXT Corrected content type type (blank: could not find)
*/
function convert_ocportal_type_codes($type_has,$type_id,$type_wanted)
{
$real_type_wanted=$type_wanted;
if ($type_wanted=='award_hook') $type_wanted='cma_hook';

// TODO: remove legacy later
if ($type_has=='award_hook')
{
if ($type_id=='seedy_page') $type_id='cedi_page';
if ($type_id=='seedy_post') $type_id='cedi_post';
$type_has='cma_hook';
}

// Search content-meta-aware hooks
$found_type_id='';
$cma_hooks=find_all_hooks('systems','content_meta_aware');
foreach (array_keys($cma_hooks) as $cma_hook)
{
if ((($type_has=='cma_hook') && ($cma_hook==$type_id)) || ($type_has!='cma_hook'))
{
require_code('hooks/systems/content_meta_aware/'.$cma_hook);
$cms_ob=object_factory('Hook_content_meta_aware_'.$cma_hook);
$cma_info=$cms_ob->info();
$cma_info['cma_hook']=$cma_hook;
if ((isset($cma_info[$type_has])) && (isset($cma_info[$type_wanted])) && ($cma_info[$type_has]==$type_id))
{
$found_type_id=$cma_info[$type_wanted];
break;
}
}
}

if ($real_type_wanted=='award_hook')
{
// TODO: remove legacy later
if ($found_type_id=='cedi_page') $found_type_id='seedy_page';
if ($found_type_id=='cedi_post') $found_type_id='seedy_post';
if ($found_type_id=='iotd') $found_type_id=''; // TODO: No award hook right now
}

return $found_type_id;
}

/**
* Get meta details of a content item
*
* @param ID_TEXT Content type
* @param ID_TEXT Content ID
* @return array Tuple: title, submitter, content hook info, URL (for use within current browser session), URL (for use in emails / sharing)
*/
function content_get_details($content_type,$content_id)
{
require_code('hooks/systems/content_meta_aware/'.$content_type);
$cma_ob=object_factory('Hook_content_meta_aware_'.$content_type);
$cma_info=$cma_ob->info();

$db=$GLOBALS[(substr($cma_info['table'],0,2)=='f_')?'FORUM_DB':'SITE_DB'];

$content_row=content_get_row($content_id,$cma_info);
if (is_null($content_row))
{
if (($content_type=='comcode_page') && (strpos($content_id,':')!==false))
{
list($zone,$page)=explode(':',$content_id,2);

$members=$GLOBALS['FORUM_DRIVER']->member_group_query($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(),1);
if (count($members)!=0)
{
$submitter_id=$GLOBALS['FORUM_DRIVER']->pname_id($members[key($members)]);
} else
{
$submitter_id=db_get_first_id()+1; // On OCF and most forums, this is the first admin member
}

$content_row=array(
'the_zone'=>$zone,
'the_page'=>$page,
'p_parent_page'=>'',
'p_validated'=>1,
'p_edit_date'=>NULL,
'p_add_date'=>time(),
'p_submitter'=>$submitter_id,
'p_show_as_edit'=>0
);

$content_url=build_url(array('page'=>$page),$zone,NULL,false,false,false);
$content_url_email_safe=build_url(array('page'=>$page),$zone,NULL,false,false,true);

return array($zone.':'.$page,$submitter_id,$cma_info,$content_row,$content_url,$content_url_email_safe);
}

return array(NULL,NULL,NULL,NULL,NULL,NULL);
}

if (is_null($cma_info['title_field']))
{
$content_title=do_lang($cma_info['content_type_label']);
} else
{
if (strpos($cma_info['title_field'],'CALL:')!==false)
{
$content_title=call_user_func(trim(substr($cma_info['title_field'],5)),array('id'=>$content_id));
} else
{
$_content_title=$content_row[$cma_info['title_field']];
$content_title=$cma_info['title_field_dereference']?get_translated_text($_content_title,$db):$_content_title;
}
}

if (isset($cma_info['submitter_field']))
{
if (strpos($cma_info['submitter_field'],':')!==false)
{
$bits=explode(':',$cma_info['submitter_field']);
$matches=array();
if (preg_match('#'.$bits[1].'#',$content_row[$bits[0]],$matches)!=0)
{
$submitter_id=intval($matches[1]);
} else $submitter_id=$GLOBALS['FORUM_DRIVER']->get_guest_id();
} else
{
$submitter_id=$content_row[$cma_info['submitter_field']];
}
} else
{
$submitter_id=$GLOBALS['FORUM_DRIVER']->get_guest_id();
}

list($zone,$url_bits,$hash)=page_link_decode(str_replace('_WILD',$content_id,$cma_info['view_pagelink_pattern']));
$content_url=build_url($url_bits,$zone,NULL,false,false,false,$hash);
$content_url_email_safe=build_url($url_bits,$zone,NULL,false,false,true,$hash);

return array($content_title,$submitter_id,$cma_info,$content_row,$content_url,$content_url_email_safe);
}

/**
* Get the content row of a content item.
*
* @param ID_TEXT The content ID
* @param array The info array for the content type
* @return ?array The row (NULL: not found)
*/
function content_get_row($content_id,$cma_info)
{
$db=$GLOBALS[(substr($cma_info['table'],0,2)=='f_')?'FORUM_DB':'SITE_DB'];

$id_field_numeric=array_key_exists('id_field_numeric',$cma_info)?$cma_info['id_field_numeric']:true;
if (is_array($cma_info['id_field']))
{
$bits=explode(':',$content_id);
$where=array();
foreach ($bits as $i=>$bit)
{
$where[$cma_info['id_field'][$i]]=$id_field_numeric?intval($bit):$bit;
}
} else
{
if ($id_field_numeric)
{
$where=array($cma_info['id_field']=>intval($content_id));
} else
{
$where=array($cma_info['id_field']=>$content_id);
}
}
$_content=$db->query_select($cma_info['table'].' r',array('r.*'),$where,'',1);
return array_key_exists(0,$_content)?$_content[0]:NULL;
}
Something went wrong with that request. Please try again.