ocPortal Developer's Guide: News
» Return to Contents
sources/news.php
Global_functions_news.php
Function summary
|
AUTO_LINK
|
add_news_category (SHORT_TEXT title, ID_TEXT img, LONG_TEXT notes, ?MEMBER owner, ?AUTO_LINK id)
|
|
void
|
edit_news_category (AUTO_LINK id, ?SHORT_TEXT title, ?SHORT_TEXT img, ?LONG_TEXT notes, ?MEMBER owner)
|
|
void
|
delete_news_category (AUTO_LINK id)
|
|
AUTO_LINK
|
add_news (SHORT_TEXT title, LONG_TEXT news, ?ID_TEXT author, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, LONG_TEXT news_article, ?AUTO_LINK main_news_category, ?array news_category, ?TIME time, ?MEMBER submitter, integer views, ?TIME edit_date, ?AUTO_LINK id, URLPATH image)
|
|
void
|
edit_news (AUTO_LINK id, SHORT_TEXT title, LONG_TEXT news, ID_TEXT author, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, LONG_TEXT news_article, AUTO_LINK main_news_category, ?array news_category, SHORT_TEXT meta_keywords, LONG_TEXT meta_description, ?URLPATH image, ?TIME time)
|
|
void
|
dispatch_news_notification (AUTO_LINK id, SHORT_TEXT title, AUTO_LINK main_news_category)
|
|
void
|
delete_news (AUTO_LINK id)
|
|
tempcode
|
nice_get_news_categories (?mixed it, boolean show_all_personal_categories, boolean addable_filter, boolean only_existing, ?boolean only_blogs, boolean prefer_not_blog_selected)
|
|
tempcode
|
nice_get_news (?AUTO_LINK it, ?MEMBER only_owned, boolean editable_filter, boolean only_in_blog)
|
AUTO_LINK add_news_category(SHORT_TEXT title, ID_TEXT img, LONG_TEXT notes, ?MEMBER owner, ?AUTO_LINK id)
Add a news category of the specified details.
Parameters…
| Name |
title |
| Description |
The news category title |
| Type |
SHORT_TEXT |
| Name |
img |
| Description |
The theme image ID of the picture to use for the news category |
| Type |
ID_TEXT |
| Name |
notes |
| Description |
Notes for the news category |
| Type |
LONG_TEXT |
| Name |
owner |
| Description |
The owner (NULL: public) |
| Default value |
|
| Type |
?MEMBER |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
The ID of our new news category |
| Type |
AUTO_LINK |
function add_news_category($title,$img,$notes,$owner=NULL,$id=NULL)
{
$map=array('nc_title'=>insert_lang($title,1),'nc_img'=>$img,'notes'=>$notes,'nc_owner'=>$owner);
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('news_categories',$map,true);
log_it('ADD_NEWS_CATEGORY',strval($id),$title);
decache('side_news_categories');
return $id;
}
void edit_news_category(AUTO_LINK id, ?SHORT_TEXT title, ?SHORT_TEXT img, ?LONG_TEXT notes, ?MEMBER owner)
Edit a news category.
Parameters…
| Name |
id |
| Description |
The news category to edit |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The title (NULL: keep as-is) |
| Type |
?SHORT_TEXT |
| Name |
img |
| Description |
The image (NULL: keep as-is) |
| Type |
?SHORT_TEXT |
| Name |
notes |
| Description |
The notes (NULL: keep as-is) |
| Type |
?LONG_TEXT |
| Name |
owner |
| Description |
The owner (NULL: public) |
| Default value |
|
| Type |
?MEMBER |
(No return value)
function edit_news_category($id,$title,$img,$notes,$owner=NULL)
{
$myrows=$GLOBALS['SITE_DB']->query_select('news_categories',array('nc_title','nc_img','notes'),array('id'=>$id),'',1);
if (!array_key_exists(0,$myrows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$myrows[0];
require_code('urls2');
suggest_new_idmoniker_for('news','misc',strval($id),$title);
log_it('EDIT_NEWS_CATEGORY',strval($id),$title);
if (is_null($title)) $title=get_translated_text($myrow['nc_title']);
if (is_null($img)) $img=$myrow['nc_img'];
if (is_null($notes)) $notes=$myrow['notes'];
$GLOBALS['SITE_DB']->query_update('news_categories',array('nc_title'=>lang_remap($myrow['nc_title'],$title),'nc_img'=>$img,'notes'=>$notes,'nc_owner'=>$owner),array('id'=>$id),'',1);
require_code('themes2');
tidy_theme_img_code($img,$myrow['nc_img'],'news_categories','nc_img');
decache('main_news');
decache('side_news');
decache('side_news_archive');
decache('bottom_news');
decache('side_news_categories');
}
void delete_news_category(AUTO_LINK id)
Delete a news category.
Parameters…
| Name |
id |
| Description |
The news category to delete |
| Type |
AUTO_LINK |
(No return value)
function delete_news_category($id)
{
$rows=$GLOBALS['SITE_DB']->query_select('news_categories',array('nc_title','nc_img'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$rows[0];
$min=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT MIN(id) FROM '.get_table_prefix().'news_categories WHERE id<>'.strval((integer)$id));
if (is_null($min))
{
warn_exit(do_lang_tempcode('YOU_MUST_KEEP_ONE_NEWS_CAT'));
}
log_it('DELETE_NEWS_CATEGORY',strval($id),get_translated_text($myrow['nc_title']));
delete_lang($myrow['nc_title']);
$GLOBALS['SITE_DB']->query_update('news',array('news_category'=>$min),array('news_category'=>$id));
$GLOBALS['SITE_DB']->query_delete('news_categories',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('news_category_entries',array('news_entry_category'=>$id));
$GLOBALS['SITE_DB']->query_delete('group_category_access',array('module_the_name'=>'news','category_name'=>strval($id)));
$GLOBALS['SITE_DB']->query_delete('gsp',array('module_the_name'=>'news','category_name'=>strval($id)));
require_code('themes2');
tidy_theme_img_code(NULL,$myrow['nc_img'],'news_categories','nc_img');
decache('side_news_categories');
}
AUTO_LINK add_news(SHORT_TEXT title, LONG_TEXT news, ?ID_TEXT author, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, LONG_TEXT news_article, ?AUTO_LINK main_news_category, ?array news_category, ?TIME time, ?MEMBER submitter, integer views, ?TIME edit_date, ?AUTO_LINK id, URLPATH image)
Adds a news entry to the database, and send out the news to any RSS cloud listeners.
Parameters…
| Name |
title |
| Description |
The news title |
| Type |
SHORT_TEXT |
| Name |
news |
| Description |
The news summary (or if not an article, the full news) |
| Type |
LONG_TEXT |
| Name |
author |
| Description |
The news author (possibly, a link to an existing author in the system, but does not need to be) (NULL: current username) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
validated |
| Description |
Whether the news has been validated |
| Default value |
1 |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the news may be rated |
| Default value |
1 |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed (0=no, 1=yes, 2=review style) |
| Default value |
1 |
| Type |
SHORT_INTEGER |
| Name |
allow_trackbacks |
| Description |
Whether the news may have trackbacks |
| Default value |
1 |
| Type |
BINARY |
| Name |
notes |
| Description |
Notes for the news |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
news_article |
| Description |
The news entry (blank means no entry) |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
main_news_category |
| Description |
The primary news category (NULL: personal) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
news_category |
| Description |
The IDs of the news categories that this is in (NULL: none) |
| Default value |
|
| Type |
?array |
| Name |
time |
| Description |
The time of submission (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
submitter |
| Description |
The news submitter (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
| Name |
views |
| Description |
The number of views the article has had |
| Default value |
0 |
| Type |
integer |
| 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 |
| Name |
image |
| Description |
URL to the image for the news entry (blank: use cat image) |
| Default value |
|
| Type |
URLPATH |
Returns…
| Description |
The ID of the news just added |
| Type |
AUTO_LINK |
function add_news($title,$news,$author=NULL,$validated=1,$allow_rating=1,$allow_comments=1,$allow_trackbacks=1,$notes='',$news_article='',$main_news_category=NULL,$news_category=NULL,$time=NULL,$submitter=NULL,$views=0,$edit_date=NULL,$id=NULL,$image='')
{
if (is_null($author)) $author=$GLOBALS['FORUM_DRIVER']->get_username(get_member());
if (is_null($news_category)) $news_category=array();
if (is_null($time)) $time=time();
if (is_null($submitter)) $submitter=get_member();
$already_created_personal_category=false;
require_code('comcode_check');
check_comcode($news_article,NULL,false,NULL,true);
if (is_null($main_news_category))
{
$main_news_category_id=$GLOBALS['SITE_DB']->query_value_null_ok('news_categories','id',array('nc_owner'=>$submitter));
if (is_null($main_news_category_id))
{
if (!has_specific_permission(get_member(),'have_personal_category','cms_news')) fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
$p_nc_title=insert_lang(do_lang('MEMBER_CATEGORY',$GLOBALS['FORUM_DRIVER']->get_username($submitter)),2);
$main_news_category_id=$GLOBALS['SITE_DB']->query_insert('news_categories',array('nc_title'=>$p_nc_title,'nc_img'=>'newscats/community','notes'=>'','nc_owner'=>$submitter),true);
$already_created_personal_category=true;
$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'=>'news','category_name'=>strval($main_news_category_id),'group_id'=>$group_id));
}
}
else $main_news_category_id=$main_news_category;
if (!addon_installed('unvalidated')) $validated=1;
$map=array('news_image'=>$image,'edit_date'=>$edit_date,'news_category'=>$main_news_category_id,'news_views'=>$views,'news_article'=>0,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'submitter'=>$submitter,'validated'=>$validated,'date_and_time'=>$time,'title'=>insert_lang_comcode($title,1),'news'=>insert_lang_comcode($news,1),'author'=>$author);
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('news',$map,true);
if (!is_null($news_category))
{
foreach ($news_category as $value)
{
if ((is_null($value)) && (!$already_created_personal_category))
{
$p_nc_title=insert_lang(do_lang('MEMBER_CATEGORY',$GLOBALS['FORUM_DRIVER']->get_username($submitter)),2);
$news_category_id=$GLOBALS['SITE_DB']->query_insert('news_categories',array('nc_title'=>$p_nc_title,'nc_img'=>'newscats/community','notes'=>'','nc_owner'=>$submitter),true);
$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'=>'news','category_name'=>strval($news_category_id),'group_id'=>$group_id));
}
else $news_category_id=$value;
if (is_null($news_category_id)) continue; // Double selected
$GLOBALS['SITE_DB']->query_insert('news_category_entries',array('news_entry'=>$id,'news_entry_category'=>$news_category_id));
}
}
require_code('attachments2');
$map=array('news_article'=>insert_lang_comcode_attachments(2,$news_article,'news',strval($id)));
$GLOBALS['SITE_DB']->query_update('news',$map,array('id'=>$id),'',1);
log_it('ADD_NEWS',strval($id),$title);
if (function_exists('xmlrpc_encode'))
{
if (function_exists('set_time_limit')) @set_time_limit(0);
// Send out on RSS cloud
$GLOBALS['SITE_DB']->query('DELETE FROM '.get_table_prefix().'news_rss_cloud WHERE register_time<'.strval(time()-25*60*60));
$start=0;
do
{
$listeners=$GLOBALS['SITE_DB']->query_select('news_rss_cloud',array('*'),NULL,'',100,$start);
foreach ($listeners as $listener)
{
$data=$listener['watching_channel'];
if ($listener['rem_protocol']=='xml-rpc')
{
$request=xmlrpc_encode_request($listener['rem_procedure'],$data);
$length=strlen($request);
$_length=strval($length);
$packet=<<<END
POST /{$listener['rem_path']} HTTP/1.0
Host: {$listener['rem_ip']}
Content-Type: text/xml
Content-length: {$_length}
{$request}
END;
}
$errno=0;
$errstr='';
$mysock=@fsockopen($listener['rem_ip'],$listener['rem_port'],$errno,$errstr,6.0);
if ($mysock!==false)
{
@fwrite($mysock,$packet);
@fclose($mysock);
}
$start+=100;
}
}
while (array_key_exists(0,$listeners));
}
require_code('seo2');
seo_meta_set_for_implicit('news',strval($id),array($title,($news=='')?$news_article:$news/*,$news_article*/),($news=='')?$news_article:$news); // News article could be used, but it's probably better to go for the summary only to avoid crap
if ($validated==1)
{
decache('main_news');
decache('side_news');
decache('side_news_archive');
decache('bottom_news');
dispatch_news_notification($id,$title,$main_news_category_id);
}
if (($validated==1) && (get_option('site_closed')=='0') && (ocp_srv('HTTP_HOST')!='127.0.0.1') && (ocp_srv('HTTP_HOST')!='localhost') && (has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(),'news',strval($main_news_category_id))))
{
$_ping_url=str_replace('{url}',urlencode(get_base_url()),str_replace('{rss}',urlencode(find_script('backend')),str_replace('{title}',urlencode(get_site_name()),get_option('ping_url'))));
$ping_urls=explode(chr(10),$_ping_url);
foreach ($ping_urls as $ping_url)
{
$ping_url=trim($ping_url);
if ($ping_url!='') http_download_file($ping_url,NULL,false);
}
}
return $id;
}
void edit_news(AUTO_LINK id, SHORT_TEXT title, LONG_TEXT news, ID_TEXT author, BINARY validated, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, LONG_TEXT news_article, AUTO_LINK main_news_category, ?array news_category, SHORT_TEXT meta_keywords, LONG_TEXT meta_description, ?URLPATH image, ?TIME time)
Edit a news entry.
Parameters…
| Name |
id |
| Description |
The ID of the news to edit |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The news title |
| Type |
SHORT_TEXT |
| Name |
news |
| Description |
The news summary (or if not an article, the full news) |
| Type |
LONG_TEXT |
| Name |
author |
| Description |
The news author (possibly, a link to an existing author in the system, but does not need to be) |
| Type |
ID_TEXT |
| Name |
validated |
| Description |
Whether the news has been validated |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the news 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 news may have trackbacks |
| Type |
BINARY |
| Name |
notes |
| Description |
Notes for the news |
| Type |
LONG_TEXT |
| Name |
news_article |
| Description |
The news entry (blank means no entry) |
| Type |
LONG_TEXT |
| Name |
main_news_category |
| Description |
The primary news category (NULL: personal) |
| Type |
AUTO_LINK |
| Name |
news_category |
| Description |
The IDs of the news categories that this is in (NULL: do not change) |
| Type |
?array |
| Name |
meta_keywords |
| Description |
Meta keywords |
| Type |
SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description |
| Type |
LONG_TEXT |
| Name |
image |
| Description |
URL to the image for the news entry (blank: use cat image) (NULL: don't delete existing) |
| Type |
?URLPATH |
| Name |
time |
| Description |
Recorded add time (NULL: leave alone) |
| Default value |
|
| Type |
?TIME |
(No return value)
function edit_news($id,$title,$news,$author,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$news_article,$main_news_category,$news_category,$meta_keywords,$meta_description,$image,$time=NULL)
{
$rows=$GLOBALS['SITE_DB']->query_select('news',array('title','news','news_article','submitter'),array('id'=>$id),'',1);
$_title=$rows[0]['title'];
$_news=$rows[0]['news'];
$_news_article=$rows[0]['news_article'];
require_code('urls2');
suggest_new_idmoniker_for('news','view',strval($id),$title);
require_code('attachments2');
require_code('attachments3');
if (!addon_installed('unvalidated')) $validated=1;
require_code('submit');
$just_validated=(!content_validated('news',strval($id))) && ($validated==1);
if ($just_validated)
{
send_content_validated_notification('news',strval($id));
}
$map=array('news_category'=>$main_news_category,'news_article'=>update_lang_comcode_attachments($_news_article,$news_article,'news',strval($id),NULL,false,$rows[0]['submitter']),'edit_date'=>time(),'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'validated'=>$validated,'title'=>lang_remap_comcode($_title,$title),'news'=>lang_remap_comcode($_news,$news),'author'=>$author);
if (!is_null($time)) $map['date_and_time']=$time;
if (!is_null($image))
{
$map['news_image']=$image;
require_code('files2');
delete_upload('uploads/grepimages','news','news_image','id',$id,$image);
}
/*$news_categories=$news_category[0];
foreach ($news_category as $key=>$value)
{
if($key>0) $news_categories.=','.$value;
}*/
if (!is_null($news_category))
{
$GLOBALS['SITE_DB']->query_delete('news_category_entries',array('news_entry'=>$id));
foreach ($news_category as $value)
{
$GLOBALS['SITE_DB']->query_insert('news_category_entries',array('news_entry'=>$id,'news_entry_category'=>$value));
}
}
log_it('EDIT_NEWS',strval($id),$title);
$GLOBALS['SITE_DB']->query_update('news',$map,array('id'=>$id),'',1);
$self_url=build_url(array('page'=>'news','type'=>'view','id'=>$id),get_module_zone('news'),NULL,false,false,true);
if ($just_validated)
{
dispatch_news_notification($id,$title,$main_news_category);
}
require_code('seo2');
seo_meta_set_for_explicit('news',strval($id),$meta_keywords,$meta_description);
decache('main_news');
decache('side_news');
decache('side_news_archive');
decache('bottom_news');
if (($validated==1) && (has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(),'news',strval($main_news_category))))
{
$_ping_url=str_replace('{url}',urlencode(get_base_url()),str_replace('{rss}',urlencode(find_script('backend')),str_replace('{title}',urlencode(get_site_name()),get_option('ping_url'))));
$ping_urls=explode(',',$_ping_url);
foreach ($ping_urls as $ping_url)
{
$ping_url=trim($ping_url);
if ($ping_url!='') http_download_file($ping_url,NULL,false);
}
}
require_code('feedback');
update_spacer_post($allow_comments!=0,'news',strval($id),$self_url,$title,get_value('comment_forum__news'));
}
void dispatch_news_notification(AUTO_LINK id, SHORT_TEXT title, AUTO_LINK main_news_category)
Send out a notification of some new news.
Parameters…
| Name |
id |
| Description |
The ID of the news |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The title |
| Type |
SHORT_TEXT |
| Name |
main_news_category |
| Description |
The main news category |
| Type |
AUTO_LINK |
(No return value)
function dispatch_news_notification($id,$title,$main_news_category)
{
$self_url=build_url(array('page'=>'news','type'=>'view','id'=>$id),get_module_zone('news'),NULL,false,false,true);
$is_blog=!is_null($GLOBALS['SITE_DB']->query_value('news_categories','nc_owner',array('id'=>$main_news_category)));
require_code('notifications');
require_lang('news');
if ($is_blog)
{
$subject=do_lang('BLOG_NOTIFICATION_MAIL_SUBJECT',get_site_name(),$title);
$mail=do_lang('BLOG_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($title),array($self_url->evaluate()));
dispatch_notification('news_entry',strval($main_news_category),$subject,$mail);
} else
{
$subject=do_lang('NEWS_NOTIFICATION_MAIL_SUBJECT',get_site_name(),$title);
$mail=do_lang('NEWS_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($title),array($self_url->evaluate()));
dispatch_notification('news_entry',strval($main_news_category),$subject,$mail);
}
}
void delete_news(AUTO_LINK id)
Delete a news entry.
Parameters…
| Name |
id |
| Description |
The ID of the news to edit |
| Type |
AUTO_LINK |
(No return value)
function delete_news($id)
{
$rows=$GLOBALS['SITE_DB']->query_select('news',array('title','news','news_article'),array('id'=>$id),'',1);
$title=$rows[0]['title'];
$news=$rows[0]['news'];
$news_article=$rows[0]['news_article'];
$_title=get_translated_text($title);
log_it('DELETE_NEWS',strval($id),$_title);
require_code('files2');
delete_upload('uploads/grepimages','news','news_image','id',$id);
$GLOBALS['SITE_DB']->query_delete('news',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('news_category_entries',array('news_entry'=>$id));
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'news','rating_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('trackbacks',array('trackback_for_type'=>'news','trackback_for_id'=>$id));
delete_lang($title);
delete_lang($news);
require_code('attachments2');
require_code('attachments3');
if (!is_null($news_article)) delete_lang_comcode_attachments($news_article,'news',strval($id));
require_code('seo2');
seo_meta_erase_storage('news',strval($id));
decache('main_news');
decache('side_news');
decache('side_news_archive');
decache('bottom_news');
}
tempcode nice_get_news_categories(?mixed it, boolean show_all_personal_categories, boolean addable_filter, boolean only_existing, ?boolean only_blogs, boolean prefer_not_blog_selected)
Get a nice formatted XHTML list of news categories.
Parameters…
| Name |
it |
| Description |
The selected news category. Array or AUTO_LINK (NULL: personal) |
| Default value |
|
| Type |
?mixed |
| Name |
show_all_personal_categories |
| Description |
Whether to add all personal categories into the list (for things like the adminzone, where all categories must be shown, regardless of permissions) |
| 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 |
| Name |
only_existing |
| Description |
Whether to limit to only existing cats (otherwise we dynamically add unstarted blogs) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
only_blogs |
| Description |
Whether to limit to only show blog categories (NULL: don't care, true: blogs only, false: no blogs) |
| Default value |
|
| Type |
?boolean |
| Name |
prefer_not_blog_selected |
| Description |
Whether to prefer to choose a non-blog category as the default |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The tempcode for the news category select list |
| Type |
tempcode |
function nice_get_news_categories($it=NULL,$show_all_personal_categories=false,$addable_filter=false,$only_existing=false,$only_blogs=NULL,$prefer_not_blog_selected=false)
{
if (!is_array($it)) $it=array($it);
if ($only_blogs===true)
{
$where='WHERE nc_owner IS NOT NULL';
}
elseif ($only_blogs===false)
{
$where='WHERE nc_owner IS NULL';
} else
{
$where='WHERE 1=1';
}
$count=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.get_table_prefix().'news_categories '.$where.' ORDER BY id');
if ($count>500) // Uh oh, loads, need to limit things more
{
$where.=' AND (nc_owner IS NULL OR nc_owner='.strval(get_member()).')';
}
$_cats=$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'news_categories '.$where.' ORDER BY id');
foreach ($_cats as $i=>$cat)
{
$_cats[$i]['nice_title']=get_translated_text($cat['nc_title']);
}
global $M_SORT_KEY;
$M_SORT_KEY='nice_title';
usort($_cats,'multi_sort');
$categories=new ocp_tempcode();
$add_cat=true;
foreach ($_cats as $cat)
{
if ($cat['nc_owner']==get_member()) $add_cat=false;
if (!has_category_access(get_member(),'news',strval($cat['id']))) continue;
if (($addable_filter) && (!has_submit_permission('high',get_member(),get_ip_address(),'cms_news',array('news',$cat['id'])))) continue;
if (is_null($cat['nc_owner']))
{
$li=form_input_list_entry(strval($cat['id']),($it!=array(NULL)) && in_array($cat['id'],$it),$cat['nice_title'].' (#'.strval($cat['id']).')');
$categories->attach($li);
} else
{
if ((((!is_null($cat['nc_owner'])) && (has_specific_permission(get_member(),'can_submit_to_others_categories'))) || (($cat['nc_owner']==get_member()) && (!is_guest()))) || ($show_all_personal_categories))
$categories->attach(form_input_list_entry(strval($cat['id']),(($cat['nc_owner']==get_member()) && ((!$prefer_not_blog_selected) && (in_array(NULL,$it)))) || (in_array($cat['id'],$it)),do_lang('MEMBER_CATEGORY',$GLOBALS['FORUM_DRIVER']->get_username($cat['nc_owner'])).' (#'.strval($cat['id']).')'));
}
}
if ((!$only_existing) && (has_specific_permission(get_member(),'have_personal_category','cms_news')) && ($add_cat) && (!is_guest()))
{
$categories->attach(form_input_list_entry('personal',(!$prefer_not_blog_selected) && in_array(NULL,$it),do_lang_tempcode('MEMBER_CATEGORY',do_lang_tempcode('_NEW',escape_html($GLOBALS['FORUM_DRIVER']->get_username(get_member()))))));
}
return $categories;
}
tempcode nice_get_news(?AUTO_LINK it, ?MEMBER only_owned, boolean editable_filter, boolean only_in_blog)
Get a nice formatted XHTML list of news.
Parameters…
| Name |
it |
| Description |
The selected news entry (NULL: none) |
| Type |
?AUTO_LINK |
| Name |
only_owned |
| Description |
Limit news to those submitted by this member (NULL: show all) |
| Default value |
|
| Type |
?MEMBER |
| Name |
editable_filter |
| Description |
Whether to only show for what may be edited by the current member |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
only_in_blog |
| Description |
Whether to only show blog posts |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list |
| Type |
tempcode |
function nice_get_news($it,$only_owned=NULL,$editable_filter=false,$only_in_blog=false)
{
$where=is_null($only_owned)?'1':'submitter='.strval($only_owned);
if ($only_in_blog)
{
$rows=$GLOBALS['SITE_DB']->query('SELECT n.* FROM '.get_table_prefix().'news n JOIN '.get_table_prefix().'news_categories c ON c.id=n.news_category AND '.$where.' AND nc_owner IS NOT NULL ORDER BY date_and_time DESC',300/*reasonable limit*/);
} else
{
$rows=$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'news WHERE '.$where.' ORDER BY date_and_time DESC',300/*reasonable limit*/);
}
if (count($rows)==300) attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY',escape_html(integer_format(300))),'warn');
$out=new ocp_tempcode();
foreach ($rows as $myrow)
{
if (!has_category_access(get_member(),'news',strval($myrow['news_category']))) continue;
if (($editable_filter) && (!has_edit_permission('high',get_member(),$myrow['submitter'],'cms_news',array('news',$myrow['news_category'])))) continue;
$selected=($myrow['id']==$it);
$out->attach(form_input_list_entry(strval($myrow['id']),$selected,get_translated_text($myrow['title'])));
}
return $out;
}
sources/newsletter.php
Global_functions_newsletter.php
Function summary
|
string
|
basic_newsletter_join (EMAIL email, integer interest_level, ?LANGUAGE_NAME lang, boolean get_confirm_mail, ?AUTO_LINK newsletter_id, string forename, string surname)
|
|
void
|
actual_send_newsletter (LONG_TEXT message, SHORT_TEXT subject, LANGUAGE_NAME lang, array send_details, BINARY html_only, string from_email, string from_name, integer priority, string csv_data, ID_TEXT mail_template)
|
|
array
|
newsletter_who_send_to (array send_details, LANGUAGE_NAME lang, integer start, integer max, boolean get_raw_rows, string csv_data)
|
|
string
|
newsletter_variable_substitution (string message, SHORT_TEXT subject, SHORT_TEXT forename, SHORT_TEXT surname, SHORT_TEXT name, EMAIL email_address, ID_TEXT sendid, SHORT_TEXT hash)
|
|
void
|
newsletter_shutdown_function ()
|
|
AUTO_LINK
|
add_newsletter (SHORT_TEXT title, LONG_TEXT description)
|
|
void
|
edit_newsletter (AUTO_LINK id, SHORT_TEXT title, LONG_TEXT description)
|
|
void
|
delete_newsletter (AUTO_LINK id)
|
string basic_newsletter_join(EMAIL email, integer interest_level, ?LANGUAGE_NAME lang, boolean get_confirm_mail, ?AUTO_LINK newsletter_id, string forename, string surname)
Add to the newsletter, in the simplest way.
Parameters…
| Name |
email |
| Description |
The email address of the subscriber |
| Type |
EMAIL |
| Name |
interest_level |
| Description |
The interest level |
| Default value |
4 |
| Type |
integer |
| Value range |
1 4 |
| Name |
lang |
| Description |
The language (NULL: users) |
| Default value |
|
| Type |
?LANGUAGE_NAME |
| Name |
get_confirm_mail |
| Description |
Whether to require a confirmation mail |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
newsletter_id |
| Description |
The newsletter to join (NULL: the first) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
forename |
| Description |
Subscribers forename |
| Default value |
|
| Type |
string |
| Name |
surname |
| Description |
Subscribers surname |
| Default value |
|
| Type |
string |
Returns…
| Description |
Newsletter password |
| Type |
string |
function basic_newsletter_join($email,$interest_level=4,$lang=NULL,$get_confirm_mail=false,$newsletter_id=NULL,$forename='',$surname='')
{
if (is_null($lang)) $lang=user_lang();
if (is_null($newsletter_id)) $newsletter_id=db_get_first_id();
$password=get_rand_password();
$code_confirm=$get_confirm_mail?mt_rand(1,9999999):0;
$test=$GLOBALS['SITE_DB']->query_value_null_ok('newsletter_subscribe','the_level',array('newsletter_id'=>$newsletter_id,'email'=>$email));
if ($test===0)
{
$GLOBALS['SITE_DB']->query_delete('newsletter_subscribe',array('newsletter_id'=>$newsletter_id,'email'=>$email),'',1);
$test=NULL;
}
if (is_null($test))
{
require_lang('newsletter');
$test=$GLOBALS['SITE_DB']->query_value_null_ok('newsletter','email',array('email'=>$email));
if (is_null($test))
{
$salt=produce_salt();
$GLOBALS['SITE_DB']->query_insert('newsletter',array('n_forename'=>$forename,'n_surname'=>$surname,'join_time'=>time(),'email'=>$email,'code_confirm'=>$code_confirm,'pass_salt'=>$salt,'the_password'=>md5($password.$salt),'language'=>$lang),false,true); // race condition
if ($get_confirm_mail)
{
$_url=build_url(array('page'=>'newsletter','type'=>'confirm','email'=>$email,'confirm'=>$code_confirm),get_module_zone('newsletter'));
$url=$_url->evaluate();
$message=do_lang('NEWSLETTER_SIGNUP_TEXT',comcode_escape($url),comcode_escape($password),array($forename,$surname,$email,get_site_name()),$lang);
require_code('mail');
mail_wrap(do_lang('NEWSLETTER_SIGNUP',NULL,NULL,NULL,$lang),$message,array($email));
}
} else
{
$GLOBALS['SITE_DB']->query_update('newsletter',array('join_time'=>time()),array('email'=>$email),'',1);
$password='';
}
$GLOBALS['SITE_DB']->query_insert('newsletter_subscribe',array('newsletter_id'=>$newsletter_id,'the_level'=>$interest_level,'email'=>$email),false,true); // race condition
return $password;
}
return do_lang('NA');
}
void actual_send_newsletter(LONG_TEXT message, SHORT_TEXT subject, LANGUAGE_NAME lang, array send_details, BINARY html_only, string from_email, string from_name, integer priority, string csv_data, ID_TEXT mail_template)
Send out the newsletter.
Parameters…
| Name |
message |
| Description |
The newsletter message |
| Type |
LONG_TEXT |
| Name |
subject |
| Description |
The newsletter subject |
| Type |
SHORT_TEXT |
| Name |
lang |
| Description |
The language |
| Type |
LANGUAGE_NAME |
| Name |
send_details |
| Description |
A map describing what newsletters and newsletter levels the newsletter is being sent to |
| Type |
array |
| Name |
html_only |
| Description |
Whether to only send in HTML format |
| Default value |
0 |
| Type |
BINARY |
| Name |
from_email |
| Description |
Override the email address the mail is sent from (blank: staff address) |
| Default value |
|
| Type |
string |
| Name |
from_name |
| Description |
Override the name the mail is sent from (blank: site name) |
| Default value |
|
| Type |
string |
| Name |
priority |
| Description |
The message priority (1=urgent, 3=normal, 5=low) |
| Default value |
3 |
| Type |
integer |
| Value range |
1 5 |
| Name |
csv_data |
| Description |
CSV data of extra subscribers (blank: none). This is in the same ocPortal newsletter CSV format that we export elsewhere. |
| Default value |
|
| Type |
string |
| Name |
mail_template |
| Description |
The template used to show the email |
| Default value |
MAIL |
| Type |
ID_TEXT |
(No return value)
function actual_send_newsletter($message,$subject,$lang,$send_details,$html_only=0,$from_email='',$from_name='',$priority=3,$csv_data='',$mail_template='MAIL')
{
require_lang('newsletter');
// Put in archive
$GLOBALS['SITE_DB']->query_insert('newsletter_archive',array('date_and_time'=>time(),'subject'=>$subject,'newsletter'=>$message,'language'=>$lang,'importance_level'=>1));
// Mark as done
log_it('NEWSLETTER_SEND',$subject);
set_value('newsletter_send_time',strval(time()));
// Schedule the background send
require_code('mail');
if (function_exists('set_time_limit')) @set_time_limit(0);
global $NEWSLETTER_SUBJECT,$NEWSLETTER_MESSAGE,$NEWSLETTER_HTML_ONLY,$NEWSLETTER_FROM_EMAIL,$NEWSLETTER_FROM_NAME,$NEWSLETTER_PRIORITY,$NEWSLETTER_SEND_DETAILS,$NEWSLETTER_LANGUAGE,$NEWSLETTER_MAIL_TEMPLATE,$CSV_DATA;
$NEWSLETTER_SUBJECT=$subject;
$NEWSLETTER_MESSAGE=$message;
$NEWSLETTER_HTML_ONLY=$html_only;
$NEWSLETTER_FROM_EMAIL=$from_email;
$NEWSLETTER_FROM_NAME=$from_name;
$NEWSLETTER_PRIORITY=$priority;
$NEWSLETTER_SEND_DETAILS=$send_details;
$NEWSLETTER_LANGUAGE=$lang;
$NEWSLETTER_MAIL_TEMPLATE=$mail_template;
$CSV_DATA=$csv_data;
if (get_param_integer('keep_send_immediately',0)==1) newsletter_shutdown_function(); else register_shutdown_function('newsletter_shutdown_function');
}
array newsletter_who_send_to(array send_details, LANGUAGE_NAME lang, integer start, integer max, boolean get_raw_rows, string csv_data)
Find a group of members the newsletter will go to.
Parameters…
| Name |
send_details |
| Description |
A map describing what newsletters and newsletter levels the newsletter is being sent to |
| Type |
array |
| Name |
lang |
| Description |
The language |
| Type |
LANGUAGE_NAME |
| Name |
start |
| Description |
Start position in result set (results are returned in parallel for each category of result) |
| Type |
integer |
| Name |
max |
| Description |
Maximum records to return from each category |
| Type |
integer |
| Name |
get_raw_rows |
| Description |
Whether to get raw rows rather than mailer-ready correspondance lists |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
csv_data |
| Description |
Serialized CSV data to also consider |
| Default value |
|
| Type |
string |
Returns…
| Description |
Returns a tuple of corresponding detail lists, emails,hashes,usernames,forenames,surnames,ids, and a record count for levels (depending on requests: csv, 1, <newsletterID>, g<groupID>) [record counts not returned if $start is not zero, for performance reasons] |
| Type |
array |
function newsletter_who_send_to($send_details,$lang,$start,$max,$get_raw_rows=false,$csv_data='')
{
// Find who to send to
$level=0;
$usernames=array();
$forenames=array();
$surnames=array();
$emails=array();
$ids=array();
$hashes=array();
$total=array();
$raw_rows=array();
// Standard newsletter subscribers
$newsletters=$GLOBALS['SITE_DB']->query_select('newsletters',array('*'));
foreach ($newsletters as $newsletter)
{
$this_level=array_key_exists(strval($newsletter['id']),$send_details)?$send_details[strval($newsletter['id'])]:0;
if ($this_level!=0)
{
$where_lang=multi_lang()?(db_string_equal_to('language',$lang).' AND '):'';
$query=' FROM '.get_table_prefix().'newsletter_subscribe s LEFT JOIN '.get_table_prefix().'newsletter n ON n.email=s.email WHERE '.$where_lang.'code_confirm=0 AND s.newsletter_id='.strval($newsletter['id']).' AND the_level>='.strval((integer)$this_level);
$temp=$GLOBALS['SITE_DB']->query('SELECT n.id,n.email,the_password,n_forename,n_surname'.$query,$max,$start);
if ($start==0)
{
$test=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.get_table_prefix().'newsletter_subscribe WHERE newsletter_id='.strval($newsletter['id']).' AND the_level>='.strval((integer)$this_level));
if ($test>10000) // Inaccurace, for performance reasons
{
$total[strval($newsletter['id'])]=$test;
} else
{
$total[strval($newsletter['id'])]=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*)'.$query);
}
}
foreach ($temp as $_temp)
{
if (!in_array($_temp['email'],$emails)) // If not already added
{
if (!$get_raw_rows)
{
$emails[]=$_temp['email'];
$forenames[]=$_temp['n_forename'];
$surnames[]=$_temp['n_surname'];
$username=trim($_temp['n_forename'].' '.$_temp['n_surname']);
if ($username=='') $username=do_lang('NEWSLETTER_SUBSCRIBER',get_site_name());
$usernames[]=$username;
$ids[]='n'.strval($_temp['id']);
$hashes[]=best_hash($_temp['the_password'],'xunsub');
} else
{
$raw_rows[]=$_temp;
}
}
}
}
$level=max($level,$this_level);
}
// OCF imports
if (get_forum_type()=='ocf')
{
// Usergroups
$groups=$GLOBALS['FORUM_DRIVER']->get_usergroup_list();
foreach ($send_details as $_id=>$is_on)
{
if ((substr($_id,0,1)=='g') && ($is_on==1))
{
$id=intval(substr($_id,1));
global $SITE_INFO;
if (((isset($SITE_INFO['mysql_old'])) && ($SITE_INFO['mysql_old']=='1')) || ((!isset($SITE_INFO['mysql_old'])) && (is_file(get_file_base().'/mysql_old'))))
{
$query='SELECT xxxxx FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members m LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_group_members g ON m.id=g.gm_member_id AND g.gm_validated=1 WHERE '.db_string_not_equal_to('m_email_address','').' AND ('.db_string_equal_to('m_language',$lang).' OR '.db_string_equal_to('m_language','').') AND m_validated=1 AND (gm_group_id='.strval($id).' OR m_primary_group='.strval($id).')';
if (get_option('allow_email_from_staff_disable')=='1') $query.=' AND m_allow_emails=1';
} else
{
$query='SELECT xxxxx FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members m LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_group_members g ON m.id=g.gm_member_id AND g.gm_validated=1 WHERE '.db_string_not_equal_to('m_email_address','').' AND ('.db_string_equal_to('m_language',$lang).' OR '.db_string_equal_to('m_language','').') AND m_validated=1 AND gm_group_id='.strval($id);
if (get_option('allow_email_from_staff_disable')=='1') $query.=' AND m_allow_emails=1';
$query.=' UNION SELECT xxxxx FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members m WHERE '.db_string_not_equal_to('m_email_address','').' AND ('.db_string_equal_to('m_language',$lang).' OR '.db_string_equal_to('m_language','').') AND m_validated=1 AND m_primary_group='.strval($id);
if (get_option('allow_email_from_staff_disable')=='1') $query.=' AND m_allow_emails=1';
}
$_rows=$GLOBALS['FORUM_DB']->query(str_replace('xxxxx','m.id,m.m_email_address,m.m_username',$query),$max,$start,false,true);
if ($start==0)
$total['g'.strval($id)]=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT ('.str_replace(' UNION ',') + (',str_replace('xxxxx','COUNT(*)',$query)).')',false,true);
foreach ($_rows as $row) // For each member
{
if (!in_array($row['m_email_address'],$emails)) // If not already added
{
if (!$get_raw_rows)
{
$emails[]=$row['m_email_address'];
$forenames[]='';
$surnames[]='';
$usernames[]=$row['m_username'];
$ids[]='m'.strval($row['id']);
$hashes[]='';
} else
{
$raw_rows[]=$row;
}
}
}
}
}
// *All* OCF members (we could have chosen all usergroups, but for legacy reasons we still have this option)
if (array_key_exists('-1',$send_details)?$send_details['-1']:0==1)
{
$query=' FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members WHERE '.db_string_not_equal_to('m_email_address','').' AND ('.db_string_equal_to('m_language',$lang).' OR '.db_string_equal_to('m_language','').') AND m_validated=1';
if (get_option('allow_email_from_staff_disable')=='1') $query.=' AND m_allow_emails=1';
$_rows=$GLOBALS['FORUM_DB']->query('SELECT id,m_email_address,m_username'.$query,$max,$start);
if ($start==0)
$total['-1']=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*)'.$query);
foreach ($_rows as $_temp)
{
if (!in_array($_temp['m_email_address'],$emails)) // If not already added
{
if (!$get_raw_rows)
{
$emails[]=$_temp['m_email_address'];
$forenames[]='';
$surnames[]='';
$usernames[]=$_temp['m_username'];
$ids[]='m'.strval($_temp['id']);
$hashes[]='';
} else
{
$raw_rows[]=$_temp;
}
}
}
}
}
// From CSV
if ($csv_data!='')
{
$_csv_data=unserialize($csv_data);
$email_index=0;
$forename_index=1;
$surname_index=2;
$username_index=3;
$id_index=4;
$hash_index=5;
if ($start==0)
$total['csv']=0;
$pos=0;
foreach ($_csv_data as $i=>$csv_line)
{
if (($i<=1) && (count($csv_line)>=1) && (isset($csv_line[0])) && (strpos($csv_line[0],'@')===false) && (isset($csv_line[1])) && (strpos($csv_line[1],'@')===false))
{
foreach ($csv_line as $j=>$val)
{
if (in_array(strtolower($val),array('e-mail','email','email address','e-mail address'))) $email_index=$j;
if (in_array(strtolower($val),array('forename','forenames','first name'))) $forename_index=$j;
if (in_array(strtolower($val),array('surname','surnames','last name'))) $surname_index=$j;
if (in_array(strtolower($val),array('username'))) $username_index=$j;
if (in_array(strtolower($val),array('id','identifier'))) $id_index=$j;
if (in_array(strtolower($val),array('hash','password','pass','code','secret'))) $hash_index=$j;
}
continue;
}
if ((count($csv_line)>=1) && (!is_null($csv_line[$email_index])) && (strpos($csv_line[$email_index],'@')!==false))
{
if (($pos>=$start) && ($pos-$start<$max))
{
if (!$get_raw_rows)
{
$emails[]=$csv_line[$email_index];
$forenames[]=array_key_exists($forename_index,$csv_line)?$csv_line[$forename_index]:'';
$surnames[]=array_key_exists($surname_index,$csv_line)?$csv_line[$surname_index]:'';
$usernames[]=array_key_exists($username_index,$csv_line)?$csv_line[$username_index]:'';
$ids[]=array_key_exists($id_index,$csv_line)?$csv_line[$id_index]:'';
$hashes[]=array_key_exists($hash_index,$csv_line)?$csv_line[$hash_index]:'';
} else
{
$raw_rows[]=$csv_line;
}
}
if ($start==0)
$total['csv']++;
$pos++;
}
}
}
return array($emails,$hashes,$usernames,$forenames,$surnames,$ids,$total,$raw_rows);
}
string newsletter_variable_substitution(string message, SHORT_TEXT subject, SHORT_TEXT forename, SHORT_TEXT surname, SHORT_TEXT name, EMAIL email_address, ID_TEXT sendid, SHORT_TEXT hash)
Sub in newsletter variables.
Parameters…
| Name |
message |
| Description |
The original newsletter message |
| Type |
string |
| Name |
subject |
| Description |
The newsletter subject |
| Type |
SHORT_TEXT |
| Name |
forename |
| Description |
Subscribers forename (blank: unknown) |
| Type |
SHORT_TEXT |
| Name |
surname |
| Description |
Subscribers surname (blank: unknown) |
| Type |
SHORT_TEXT |
| Name |
name |
| Description |
Subscribers name (or username) |
| Type |
SHORT_TEXT |
| Name |
email_address |
| Description |
Subscribers email address |
| Type |
EMAIL |
| Name |
sendid |
| Description |
Specially encoded ID of subscriber (begins either 'n' for newsletter subscriber, or 'm' for member - then has normal subscriber/member ID following) |
| Type |
ID_TEXT |
| Name |
hash |
| Description |
Double encoded password hash of subscriber (blank: can not unsubscribe by URL) |
| Type |
SHORT_TEXT |
Returns…
| Description |
The new newsletter message |
| Type |
string |
function newsletter_variable_substitution($message,$subject,$forename,$surname,$name,$email_address,$sendid,$hash)
{
if ($hash=='')
{
$unsub_url=build_url(array('page'=>'members','type'=>'view'),get_module_zone('members'),NULL,false,false,true,'tab__edit');
} else
{
$unsub_url=build_url(array('page'=>'newsletter','type'=>'unsub','id'=>substr($sendid,1),'hash'=>$hash),get_module_zone('newsletter'),NULL,false,false,true);
}
$member_id=$GLOBALS['FORUM_DRIVER']->get_member_from_username($name);
$vars=array(
'title'=>$subject,
'forename'=>$forename,
'surname'=>$surname,
'name'=>$name,
'member_id'=>is_null($member_id)?'':strval($member_id),
'email_address'=>$email_address,
'sendid'=>$sendid,
'unsub_url'=>$unsub_url,
);
foreach ($vars as $var=>$sub)
{
$message=str_replace('{'.$var.'}',is_object($sub)?$sub->evaluate():$sub,$message);
$message=str_replace('{'.$var.'*}',escape_html(is_object($sub)?$sub->evaluate():$sub),$message);
}
return $message;
}
void newsletter_shutdown_function()
Actually send out the newsletter in the background.
Parameters…
(No return value)
function newsletter_shutdown_function()
{
global $NEWSLETTER_SUBJECT,$NEWSLETTER_MESSAGE,$NEWSLETTER_HTML_ONLY,$NEWSLETTER_FROM_EMAIL,$NEWSLETTER_FROM_NAME,$NEWSLETTER_PRIORITY,$NEWSLETTER_SEND_DETAILS,$NEWSLETTER_LANGUAGE,$CSV_DATA,$NEWSLETTER_MAIL_TEMPLATE;
//mail_wrap($NEWSLETTER_SUBJECT,$NEWSLETTER_MESSAGE,$NEWSLETTER_ADDRESSES,$NEWSLETTER_USERNAMES,$NEWSLETTER_FROM_EMAIL,$NEWSLETTER_FROM_NAME,3,NULL,true,NULL,true,$NEWSLETTER_HTML_ONLY==1); Not so easy any more as message needs tailoring per subscriber
$last_cron=get_value('last_cron');
$start=0;
do
{
list($addresses,$hashes,$usernames,$forenames,$surnames,$ids,)=newsletter_who_send_to($NEWSLETTER_SEND_DETAILS,$NEWSLETTER_LANGUAGE,$start,100,false,$CSV_DATA);
// Send to all
foreach ($addresses as $i=>$email_address)
{
// Variable substitution in body
$newsletter_message_substituted=newsletter_variable_substitution($NEWSLETTER_MESSAGE,$NEWSLETTER_SUBJECT,$forenames[$i],$surnames[$i],$usernames[$i],$email_address,$ids[$i],$hashes[$i]);
$in_html=false;
if (strpos($newsletter_message_substituted,'<html')===false)
{
if ($NEWSLETTER_HTML_ONLY==1)
{
$_m=comcode_to_tempcode($newsletter_message_substituted,get_member(),true);
$newsletter_message_substituted=$_m->evaluate($NEWSLETTER_LANGUAGE);
$in_html=true;
}
} else
{
require_code('tempcode_compiler');
$_m=template_to_tempcode($newsletter_message_substituted);
$newsletter_message_substituted=$_m->evaluate($NEWSLETTER_LANGUAGE);
$in_html=true;
}
if (!is_null($last_cron))
{
$GLOBALS['SITE_DB']->query_insert('newsletter_drip_send',array(
'd_inject_time'=>time(),
'd_subject'=>$NEWSLETTER_SUBJECT,
'd_message'=>$newsletter_message_substituted,
'd_html_only'=>$NEWSLETTER_HTML_ONLY,
'd_to_email'=>$email_address,
'd_to_name'=>$usernames[$i],
'd_from_email'=>$NEWSLETTER_FROM_EMAIL,
'd_from_name'=>$NEWSLETTER_FROM_NAME,
'd_priority'=>$NEWSLETTER_PRIORITY,
'd_template'=>$NEWSLETTER_MAIL_TEMPLATE,
));
} else
{
mail_wrap($NEWSLETTER_SUBJECT,$newsletter_message_substituted,array($email_address),array($usernames[$i]),$NEWSLETTER_FROM_EMAIL,$NEWSLETTER_FROM_NAME,$NEWSLETTER_PRIORITY,NULL,true,NULL,true,$in_html,false,$NEWSLETTER_MAIL_TEMPLATE);
}
}
$start+=100;
}
while (array_key_exists(0,$addresses));
}
AUTO_LINK add_newsletter(SHORT_TEXT title, LONG_TEXT description)
Make a newsletter.
Parameters…
| Name |
title |
| Description |
The title |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description |
| Type |
LONG_TEXT |
Returns…
| Description |
The ID |
| Type |
AUTO_LINK |
function add_newsletter($title,$description)
{
$id=$GLOBALS['SITE_DB']->query_insert('newsletters',array('title'=>insert_lang($title,2),'description'=>insert_lang($description,2)),true);
log_it('ADD_NEWSLETTER',strval($id),$title);
return $id;
}
void edit_newsletter(AUTO_LINK id, SHORT_TEXT title, LONG_TEXT description)
Edit a newsletter.
Parameters…
| Name |
id |
| Description |
The ID |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The title |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description |
| Type |
LONG_TEXT |
(No return value)
function edit_newsletter($id,$title,$description)
{
$_title=$GLOBALS['SITE_DB']->query_value('newsletters','title',array('id'=>$id));
$_description=$GLOBALS['SITE_DB']->query_value('newsletters','description',array('id'=>$id));
$GLOBALS['SITE_DB']->query_update('newsletters',array('title'=>lang_remap($_title,$title),'description'=>lang_remap($_description,$description)),array('id'=>$id),'',1);
log_it('EDIT_NEWSLETTER',strval($id),$_title);
}
void delete_newsletter(AUTO_LINK id)
Delete a newsletter.
Parameters…
| Name |
id |
| Description |
The ID |
| Type |
AUTO_LINK |
(No return value)
function delete_newsletter($id)
{
$_title=$GLOBALS['SITE_DB']->query_value('newsletters','title',array('id'=>$id));
$_description=$GLOBALS['SITE_DB']->query_value('newsletters','description',array('id'=>$id));
log_it('DELETE_NEWSLETTER',strval($id),get_translated_text($_title));
$GLOBALS['SITE_DB']->query_delete('newsletters',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('newsletter_subscribe',array('newsletter_id'=>$id));
delete_lang($_title);
delete_lang($_description);
}
0 reviews: Unrated (average)
There have been no comments yet