forked from donnoman/minicms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodebase.php
executable file
·212 lines (173 loc) · 6.93 KB
/
codebase.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
204
205
206
207
208
209
210
211
212
<?php
/**************************************************
CPG MiniCMS Plugin for Coppermine Photo Gallery
***************************************************/
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
$superCage = Inspekt::makeSuperCage();
// Add an install action
$thisplugin->add_action('plugin_install','minicms_install');
$thisplugin->add_action('plugin_configure','minicms_configure');
// Add a action
$thisplugin->add_action('page_start','minicms_page_start');
// Add a NEW filter
//$thisplugin->add_filter('template_html','minicms_template_html');
//$thisplugin->add_filter('page_html','minicms_page_html');
// Add a filter
$thisplugin->add_action('post_breadcrumb','minicms_print'); //below the breadcrumb
$thisplugin->add_filter('plugin_block','minicms_plugin_block');
function minicms_template_html ()
{
//place additional minicms tags in the templates.
//search page
}
function minicms_page_html ()
{
//extract all minicms tags
//render them to string or array
//replace them in the stream
}
function minicms_plugin_block($content)
{
if (!strcasecmp($content[1],'minicms')) {
print(minicms());
}
//return $content;
if ($content[0]=='minicms') $content ="";
return $content;
}
function minicms_print()
{
global $CURRENT_PIC_DATA, $MINICMS;
if (defined('DISPLAYIMAGE_PHP')) { //$CURRENT_PIC_DATA isn't populated until the post_breadcrumb filter is called.
$MINICMS['conid']=$CURRENT_PIC_DATA['pid'];
}
print(minicms());
}
function minicms($content='')
{
global $MINICMS, $CONFIG, $cat, $album, $REFERER, $lang_minicms, $HTML_SUBST_DECODE, $cms_array;
if ($MINICMS['dbver']!=MINICMS_DBVER) {
echo "<h2>{$lang_minicms['minicms_full']} {$MINICMS['dbver']}</h2><br />{$lang_minicms['dbver_nomatch']}: ".MINICMS_DBVER."<br />";
minicms_configure(false); //auto-updater and dont print the "go" button
}
$where = (isset($MINICMS['ID'])) ? "ID='{$MINICMS['ID']}'" : "conid='{$MINICMS['conid']}' AND type='{$MINICMS['type']}'";
$query = "SELECT * FROM {$CONFIG['TABLE_CMS']} WHERE $where ORDER BY cpos";
$result = cpg_db_query($query);
$cms_array = cpg_db_fetch_rowset($result);
$counter=0;
foreach ($cms_array as $key => $cms) {
$cms_array[$key]['next_ID']=($counter<count($cms_array)-1 && $cms['type']==$cms_array[$counter+1]['type'] && $cms['conid']==$cms_array[$counter+1]['conid'] ) ? '&id2='.$cms_array[$counter+1]['ID'] : '';
$cms_array[$key]['prev_ID']=($counter>0 && $cms['type']==$cms_array[$counter-1]['type'] && $cms['conid']==$cms_array[$counter-1]['conid']) ? '&id2='.$cms_array[$counter-1]['ID'] : '';
$cms_array[$key]['content'] = html_entity_decode(stripslashes($cms['content']));
$counter++;
}
ob_start();
theme_minicms($cms_array);
//$content.=ob_get_clean();
$content =ob_get_clean();
return $content;
}
function minicms_add_admin_button($href,$title,$target,$link)
{
global $template_gallery_admin_menu;
$new_template=$template_gallery_admin_menu;
$button=template_extract_block($new_template,'documentation');
$params = array(
'{DOCUMENTATION_HREF}' => $href,
'{DOCUMENTATION_TITLE}' => $title,
'target="cpg_documentation"' => $target,
'{DOCUMENTATION_LNK}' => $link,
);
$new_button="<!-- BEGIN $link -->".template_eval($button,$params)."<!-- END $link -->\n";
template_extract_block($template_gallery_admin_menu,'documentation',"<!-- BEGIN documentation -->" . $button . "<!-- END documentation -->\n" . $new_button);
}
function minicms_page_start()
{
global $lang_minicms, $lang_minicms_config, $lang_minicms_config_related_size, $lang_minicms_config_editor;
global $CONFIG, $MINICMS, $album, $cat;
global $HTML_SUBST, $HTML_SUBST_DECODE, $template_minicms, $REFERER, $CURRENT_PIC_DATA;
require 'plugins/minicms/include/init.inc.php';
/*if ($MINICMS['redirect_index_php'] && empty($_SERVER["QUERY_STRING"]) && strstr($_SERVER["PHP_SELF"],'index.php')) {
header('Location: '.html_entity_decode($MINICMS['redirect_index_php']));
exit();
} */
if (GALLERY_ADMIN_MODE) {
minicms_add_admin_button('index.php?file=minicms/cms_admin',$lang_minicms['admin_title'],'',$lang_minicms['admin_title']);
//minicms_add_admin_button('index.php?file=minicms/cms_config',$lang_minicms['config_title'],'',$lang_minicms['config_title']);
}
}
// Install function
function minicms_install()
{
// Install
//if ($_REQUEST['submit']=='Go!') {
$superCage = Inspekt::makeSuperCage();
$action = $superCage->post->getRaw('submit');
if ($action == 'Go!') {
return true;
// Loop again
} else {
return 1;
}
}
/**
* custom query for minicms_configure to avoid Coppermine from aborting out on a failed query.
*
* @param string $q
* @return object mysql result
*/
function minicms_configure_query($query)
{
global $CONFIG, $query_stats, $queries;
$query_start = cpgGetMicroTime();
$result = mysql_query($query, $CONFIG['LINK_ID']);
$query_end = cpgGetMicroTime();
if (isset($CONFIG['debug_mode']) && (($CONFIG['debug_mode']==1) || ($CONFIG['debug_mode']==2) )) {
$duration = round($query_end - $query_start, 3);
$query_stats[] = $duration;
$queries[] = "$query ({$duration}s)";
}
return $result;
}
// Configure function
// Displays the form
function minicms_configure($stop=true)
{
global $errors, $CONFIG, $CPG_PHP_SELF;
require ('include/sql_parse.php');
$db_update = 'plugins/minicms/sql/basic.sql';
$sql_query = fread(fopen($db_update, 'r'), filesize($db_update));
// Update table prefix
$sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
$sql_query = remove_remarks($sql_query);
$sql_query = split_sql_file($sql_query, ';');
if(!stristr($CONFIG['main_page_layout'],'minicms')){
$sql_query[] = "UPDATE {$CONFIG['TABLE_CONFIG']} SET value = 'minicms/".$CONFIG['main_page_layout']."' WHERE name = 'main_page_layout'";
}
echo '
<h2>Performing Database Updates<h2>
<table class="maintable">
';
foreach($sql_query as $q) {
echo "<tr><td class='tableb'>$q</td>";
if (minicms_configure_query($q)) {
echo "<td class='updatesOK'>OK</td></tr>";
} else {
echo "<td class='updatesFail'>Already Done</td></tr>";
echo "<tr><td class='tablef'>";
echo mysql_errno($CONFIG['LINK_ID']) . ": " . mysql_error($CONFIG['LINK_ID']);
echo "</td><td class='tableh2_compact'>MySQL Said</td></tr>";
}
}
echo "</table>";
if ($stop) {
$superCage = Inspekt::makeSuperCage();
$request_uri = $superCage->server->getEscaped('REQUEST_URI');
echo <<< EOT
<form action="{$request_uri}" method="post">
<input type="submit" value="Go!" name="submit" />
</form>
EOT;
}
}
?>