/
authors.php
executable file
·205 lines (176 loc) · 6.99 KB
/
authors.php
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
199
200
201
202
203
<?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 authors
*/
/**
* Shows an HTML page of all authors clickably.
*/
function authors_script()
{
require_lang('authors');
global $NON_CANONICAL_PARAMS;
$NON_CANONICAL_PARAMS[]='max';
$start=get_param_integer('start',0);
$max=get_param_integer('max',300);
$author_fields=$GLOBALS['SITE_DB']->query('SELECT m_name,m_table FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'db_meta WHERE m_name LIKE \''.db_encode_like('%author').'\'');
$rows=array();
foreach ($author_fields as $field)
{
if (($field['m_table']!='addons') && ($field['m_table']!='blocks') && ($field['m_table']!='modules'))
{
$rows_new=$GLOBALS['SITE_DB']->query('SELECT DISTINCT '.$field['m_name'].' AS author FROM '.$GLOBALS['SITE_DB']->get_table_prefix().$field['m_table'].' WHERE '.db_string_not_equal_to($field['m_name'],'').' ORDER BY '.$field['m_name'],$max+$start);
foreach ($rows_new as $a)
{
if ((!array_key_exists($a['author'],$rows)) || ($field['m_table']=='authors'))
$rows[$a['author']]=$field['m_table'];
}
}
}
$rows=array_unique($rows);
$field_name=get_param('field_name');
$content=new ocp_tempcode();
$i=0;
foreach ($rows as $author=>$table)
{
if (($i>=$start) && ($i<$start+$max))
{
if ($table=='authors')
{
$content->attach(do_template('AUTHOR_POPUP_WINDOW_DEFINED',array('_GUID'=>'cffa9926cebd3ec2920677266a3299ea','FIELD_NAME'=>$field_name,'AUTHOR'=>$author)));
} else
{
$content->attach(do_template('AUTHOR_POPUP_WINDOW_UNDEFINED',array('_GUID'=>'6210be6d1eef4bc2bda7f49947301f97','FIELD_NAME'=>$field_name,'AUTHOR'=>$author)));
}
}
$i++;
}
if ($content->is_empty()) $content=paragraph(do_lang_tempcode('NO_ENTRIES'),'dfids09fi;lk;3');
if ($i>=$start+$max)
{
$keep=symbol_tempcode('KEEP');
$next_link=find_script('authors').'?field_name='.urlencode($field_name).'&start='.strval($start+$max).'&max='.strval($max).$keep->evaluate();
} else
{
$next_link=NULL;
}
$echo=do_template('STYLED_HTML_WRAP',array('_GUID'=>'ab8d8c9d276530d82ddd84202aacf32f','TITLE'=>do_lang_tempcode('CHOOSE_AUTHOR'),'NEXT_LINK'=>$next_link,'CONTENT'=>$content));
$echo->evaluate_echo();
}
/**
* Get a member ID from an author name. First by trying authors table, second by trying forum membernames.
*
* @param ID_TEXT The name of an author
* @return ?MEMBER The member ID (NULL: none found)
*/
function get_author_id_from_name($author)
{
$handle=$GLOBALS['SITE_DB']->query_value_null_ok('authors','forum_handle',array('author'=>$author));
if (!is_numeric($handle))
{
$handle=$GLOBALS['FORUM_DRIVER']->get_member_from_username($author);
}
return $handle;
}
/**
* Adds an author (re-creating them if they already exist - thus it also serves to edit; the reason for this is the fluidity of authors - members are automatically authors even before an author profile is made)
*
* @param ID_TEXT The name of an author
* @param URLPATH The URL to the authors home page
* @param ?MEMBER The member ID of the author (NULL: no forum profile)
* @param LONG_TEXT A description of the author
* @param LONG_TEXT A terse string showing author skills
* @param ?SHORT_TEXT Meta keywords for this resource (NULL: do not edit) (blank: implicit)
* @param ?LONG_TEXT Meta description for this resource (NULL: do not edit) (blank: implicit)
*/
function add_author($author,$url,$forum_handle,$description,$skills,$meta_keywords='',$meta_description='')
{
log_it('DEFINE_AUTHOR',$author,is_null($forum_handle)?'':strval($forum_handle));
$rows=$GLOBALS['SITE_DB']->query_select('authors',array('description','skills'),array('author'=>$author),'',1);
if (array_key_exists(0,$rows))
{
delete_lang($rows[0]['description']);
delete_lang($rows[0]['skills']);
$GLOBALS['SITE_DB']->query_delete('authors',array('author'=>$author),'',1);
}
require_code('seo2');
if (($meta_keywords=='') && ($meta_description==''))
{
seo_meta_set_for_implicit('authors',$author,array($author,$description,$skills),$description);
} else
{
seo_meta_set_for_explicit('authors',$author,$meta_keywords,$meta_description);
}
$GLOBALS['SITE_DB']->query_insert('authors',array('author'=>$author,'url'=>$url,'forum_handle'=>$forum_handle,'description'=>insert_lang_comcode($description,3),'skills'=>insert_lang_comcode($skills,3)));
}
/**
* Delete an author
*
* @param ID_TEXT The name of an author
*/
function delete_author($author)
{
$rows=$GLOBALS['SITE_DB']->query_select('authors',array('description','skills'),array('author'=>$author),'',1);
if (array_key_exists(0,$rows))
{
delete_lang($rows[0]['description']);
delete_lang($rows[0]['skills']);
$GLOBALS['SITE_DB']->query_delete('authors',array('author'=>$author),'',1);
} else warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
log_it('DELETE_AUTHOR',$author);
}
/**
* Find if a member's usergroup has permission to edit an author
*
* @param MEMBER The member being checked whether to have the access
* @param ID_TEXT An author
* @return boolean Whether the member can edit this author
*/
function has_edit_author_permission($member,$author)
{
if (is_guest($member)) return false;
if ((get_author_id_from_name($author)==$member) && (has_specific_permission($member,'set_own_author_profile'))) return true;
if (has_specific_permission($member,'edit_midrange_content','cms_authors')) return true;
return false;
}
/**
* Find if a member's usergroup has permission to delete an author
*
* @param MEMBER The member being checked whether to have the access
* @param ID_TEXT An author
* @return boolean Whether the member can edit this author
*/
function has_delete_author_permission($member,$author)
{
if (is_guest($member)) return false;
if ((get_author_id_from_name($author)==$member) && (has_specific_permission($member,'delete_own_midrange_content'))) return true;
if (has_specific_permission($member,'delete_midrange_content','cms_authors')) return true;
return false;
}
/**
* Merge two authors.
*
* @param ID_TEXT The first author (being removed effectively)
* @param ID_TEXT The second author (subsuming the first)
*/
function merge_authors($from,$to)
{
$author_fields=$GLOBALS['SITE_DB']->query('SELECT m_name,m_table FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'db_meta WHERE m_name LIKE \''.db_encode_like('%author').'\'');
foreach ($author_fields as $field)
{
if ($field['m_table']!='authors')
{
$GLOBALS['SITE_DB']->query_update($field['m_table'],array($field['m_name']=>$to),array($field['m_name']=>$from));
}
}
if ($from!=$to) $GLOBALS['SITE_DB']->query_delete('authors',array('author'=>$from),'',1);
log_it('MERGE_AUTHORS',$from,$to);
}