/** * Commits prefs to the database. */ function prefs_save() { global $prefs, $gmtoffset, $is_dst, $auto_dst, $timezone_key, $txp_user; // Update custom fields count from database schema and cache it as a hidden pref. // TODO: move this when custom fields are refactored. $max_custom_fields = count(preg_grep('/^custom_\\d+/', getThings("DESCRIBE " . safe_pfx('textpattern')))); set_pref('max_custom_fields', $max_custom_fields, 'publish', 2); $sql = array(); $sql[] = "prefs_id = 1 AND event != '' AND type IN (" . PREF_CORE . ", " . PREF_PLUGIN . ", " . PREF_HIDDEN . ")"; $sql[] = "(user_name = '' OR (user_name = '" . doSlash($txp_user) . "' AND name NOT IN (\n SELECT name FROM " . safe_pfx('txp_prefs') . " WHERE user_name = ''\n )))"; if (!get_pref('use_comments', 1, 1)) { $sql[] = "event != 'comments'"; } $prefnames = safe_rows_start("name, event, user_name, val", 'txp_prefs', join(" AND ", $sql)); $post = stripPost(); if (isset($post['tempdir']) && empty($post['tempdir'])) { $post['tempdir'] = find_temp_dir(); } if (!empty($post['file_max_upload_size'])) { $post['file_max_upload_size'] = real_max_upload_size($post['file_max_upload_size']); } if (isset($post['auto_dst'])) { $prefs['auto_dst'] = $auto_dst = $post['auto_dst']; if (isset($post['is_dst']) && !$post['auto_dst']) { $is_dst = $post['is_dst']; } } // Forge $gmtoffset and $is_dst from $timezone_key if present. if (isset($post['timezone_key'])) { $key = $post['timezone_key']; $tzd = Txp::get('\\Textpattern\\Date\\Timezone')->getTimeZones(); if (isset($tzd[$key])) { $prefs['timezone_key'] = $timezone_key = $key; $post['gmtoffset'] = $prefs['gmtoffset'] = $gmtoffset = $tzd[$key]['offset']; $post['is_dst'] = $prefs['is_dst'] = $is_dst = Txp::get('\\Textpattern\\Date\\Timezone')->isDst(null, $key); } } if (isset($post['siteurl'])) { $post['siteurl'] = preg_replace('#^https?://#', '', rtrim($post['siteurl'], '/ ')); } while ($a = nextRow($prefnames)) { extract($a); if (!isset($post[$name]) || !has_privs('prefs.' . $event)) { continue; } if ($name === 'logging' && $post[$name] === 'none' && $post[$name] !== $val) { safe_truncate('txp_log'); } if ($name === 'expire_logs_after' && (int) $post[$name] !== (int) $val) { safe_delete('txp_log', "time < DATE_SUB(NOW(), INTERVAL " . intval($post[$name]) . " DAY)"); } update_pref($name, (string) $post[$name], null, null, null, null, (string) $user_name); } update_lastmod('preferences_saved'); prefs_list(gTxt('preferences_saved')); }
/** * Commits prefs to the database. */ function prefs_save() { global $prefs, $gmtoffset, $is_dst, $auto_dst, $timezone_key, $txp_user; // Update custom fields count from database schema and cache it as a hidden pref. // TODO: move this when custom fields are refactored. $max_custom_fields = count(preg_grep('/^custom_\\d+/', getThings('describe ' . safe_pfx('textpattern')))); set_pref('max_custom_fields', $max_custom_fields, 'publish', 2); $sql = array(); $sql[] = 'prefs_id = 1 and event != "" and type in(' . PREF_CORE . ', ' . PREF_PLUGIN . ', ' . PREF_HIDDEN . ')'; $sql[] = "(user_name = '' or (user_name='" . doSlash($txp_user) . "' and name not in(\n select name from " . safe_pfx('txp_prefs') . " where user_name = ''\n )))"; if (!get_pref('use_comments', 1, 1)) { $sql[] = "event != 'comments'"; } $prefnames = safe_rows_start("name, event, user_name, val", 'txp_prefs', join(' and ', $sql)); $post = stripPost(); if (isset($post['tempdir']) && empty($post['tempdir'])) { $post['tempdir'] = find_temp_dir(); } if (!empty($post['file_max_upload_size'])) { $post['file_max_upload_size'] = real_max_upload_size($post['file_max_upload_size']); } if (isset($post['auto_dst'])) { $prefs['auto_dst'] = $auto_dst = $post['auto_dst']; if (isset($post['is_dst']) && !$post['auto_dst']) { $is_dst = $post['is_dst']; } } // Forge $gmtoffset and $is_dst from $timezone_key if present. if (isset($post['timezone_key'])) { $key = $post['timezone_key']; $tzd = Txp::get('Textpattern_Date_Timezone')->getTimeZones(); if (isset($tzd[$key])) { $prefs['timezone_key'] = $timezone_key = $key; $post['gmtoffset'] = $prefs['gmtoffset'] = $gmtoffset = $tzd[$key]['offset']; $post['is_dst'] = $prefs['is_dst'] = $is_dst = Txp::get('Textpattern_Date_Timezone')->isDst(null, $key); } } if (isset($post['siteurl'])) { $post['siteurl'] = preg_replace('#^https?://#', '', rtrim($post['siteurl'], '/ ')); } while ($a = nextRow($prefnames)) { extract($a); if (!isset($post[$name]) || !has_privs('prefs.' . $event)) { continue; } if ($name === 'logging' && $post[$name] === 'none' && $post[$name] !== $val) { safe_truncate('txp_log'); } if ($name === 'expire_logs_after' && (int) $post[$name] !== (int) $val) { safe_delete('txp_log', 'time < date_sub(now(), interval ' . intval($post[$name]) . ' day)'); } update_pref($name, (string) $post[$name], null, null, null, null, (string) $user_name); } update_lastmod(); prefs_list(gTxt('preferences_saved')); }
function advanced_prefs_save() { // update custom fields count from database schema and cache it as a hidden pref $max_custom_fields = count(preg_grep('/^custom_\\d+/', getThings('describe `' . PFX . 'textpattern`'))); set_pref('max_custom_fields', $max_custom_fields, 'publish', 2); // safe all regular advanced prefs $prefnames = safe_column("name", "txp_prefs", "prefs_id = 1 AND type = 1"); $post = doSlash(stripPost()); if (empty($post['tempdir'])) { $post['tempdir'] = doSlash(find_temp_dir()); } if (!empty($post['file_max_upload_size'])) { $post['file_max_upload_size'] = real_max_upload_size($post['file_max_upload_size']); } foreach ($prefnames as $prefname) { if (isset($post[$prefname])) { safe_update("txp_prefs", "val = '" . $post[$prefname] . "'", "name = '" . doSlash($prefname) . "' and prefs_id = 1"); } } update_lastmod(); advanced_prefs(gTxt('preferences_saved')); }
function zem_event_install() { if (!getThings("show tables like '" . safe_pfx('zem_event_calendar') . "'")) { safe_query("create table if not exists " . safe_pfx('zem_event_calendar') . " (\n\n\t\t\tid bigint auto_increment not null primary key,\n\t\t\tarticle_id bigint not null,\n\n\t\t\tmodified timestamp,\n\t\t\tcreated timestamp,\n\n\t\t\tevent_date date default null,\n\t\t\tevent_time time default null,\n\n\t\t\tname varchar(255)\n\n\t\t\t);"); } if (!safe_field('name', 'txp_form', "name='zem_event_display'")) { $form = <<<EOF <txp:zem_event_permlink wraptag="" ><txp:zem_event_name label="Event" wraptag="" /></txp:zem_event_permlink> <txp:zem_event_date label="Date" wraptag="" /> <txp:zem_event_time label="Time" wraptag="" /> EOF; safe_insert('txp_form', "name='zem_event_display',\n\t\t\ttype='misc',\n\t\t\tForm='" . doSlash($form) . "'"); } if (!safe_field('name', 'txp_form', "name='zem_event_display_feed'")) { $form = <<<EOF <txp:zem_event_permlink wraptag="" ><txp:zem_event_name label="Event" wraptag="" /></txp:zem_event_permlink> <txp:zem_event_date label="Date" wraptag="" /> <txp:zem_event_time label="Time" wraptag="" /> EOF; safe_insert('txp_form', "name='zem_event_display_feed',\n\t\t\ttype='misc',\n\t\t\tForm='" . doSlash($form) . "'"); } if (!safe_field('name', 'txp_form', "name='zem_event_cal_entry'")) { $form = <<<EOF <txp:zem_event_permlink wraptag="" ><txp:zem_event_name label="Event" wraptag="" /></txp:zem_event_permlink> <txp:zem_event_time label="Time" wraptag="" /> EOF; safe_insert('txp_form', "name='zem_event_cal_entry',\n\t\t\ttype='misc',\n\t\t\tForm='" . doSlash($form) . "'"); } // add finish date and time fields $cal = getThings('describe ' . safe_pfx('zem_event_calendar')); if (!in_array('finish_date', $cal)) { zem_alter('zem_event_calendar', 'add finish_date date default null'); } if (!in_array('finish_time', $cal)) { zem_alter('zem_event_calendar', 'add finish_time time default null'); } if (!in_array('location', $cal)) { zem_alter('zem_event_calendar', 'add location varchar(255)'); } if (!in_array('location_url', $cal)) { zem_alter('zem_event_calendar', 'add location_url varchar(255)'); } if (!in_array('url', $cal)) { zem_alter('zem_event_calendar', 'add url varchar(255)'); } if (!in_array('email', $cal)) { zem_alter('zem_event_calendar', 'add email varchar(128)'); } if (!in_array('description', $cal)) { zem_alter('zem_event_calendar', 'add description text'); } if (!in_array('description_html', $cal)) { zem_alter('zem_event_calendar', 'add description_html text'); } if (!in_array('repeat_n', $cal)) { zem_alter('zem_event_calendar', 'add repeat_n int'); } if (!in_array('repeat_period', $cal)) { zem_alter('zem_event_calendar', 'add repeat_period varchar(16)'); } if (!in_array('repeat_to', $cal)) { zem_alter('zem_event_calendar', 'add repeat_to date default null'); } if (!safe_row('id', 'txp_category', "type = 'event' and name = 'root'")) { safe_insert('txp_category', "type = 'event', name = 'root', title = 'root'"); } // event m->m category if (!getThings("show tables like '" . safe_pfx('zem_event_category') . "'")) { safe_query("create table if not exists " . safe_pfx('zem_event_category') . " (\n\t\t\t\tk1 int not null,\n\t\t\t\tk2 int not null,\n\t\t\t\tPRIMARY KEY (k1,k2)\n\t\t\t)"); } if (!getThings("show tables like '" . safe_pfx('zem_event_date') . "'")) { safe_query("create table if not exists " . safe_pfx('zem_event_date') . " (\n\t\t\t\tevent_id bigint not null,\n\t\t\t\tevent_date date not null,\n\t\t\t\tevent_time time default null,\n\t\t\t\tfinish_date date default null,\n\t\t\t\tfinish_time time default null,\n\n\t\t\t\tPRIMARY KEY (event_id, event_date)\n\t\t\t)"); if (in_array('event_date', $cal)) { // copy dates and times to the new zem_event_date table $rs = safe_rows('id, event_date, event_time, finish_date, finish_time', 'zem_event_calendar', '1=1'); foreach ($rs as $row) { extract($row); safe_insert('zem_event_date', "event_id='" . doSlash($id) . "',\n\t\t\t\t\tevent_date=" . ($event_date ? "'" . doSlash($event_date) . "'" : "NULL") . ",\n\t\t\t\t\tevent_time=" . ($event_time ? "'" . doSlash($event_time) . "'" : "NULL") . ",\n\t\t\t\t\tfinish_date=" . ($finish_date ? "'" . doSlash($finish_date) . "'" : "NULL") . ",\n\t\t\t\t\tfinish_time=" . ($finish_time ? "'" . doSlash($finish_time) . "'" : "NULL")); } } } }
} // Plugin flags. $cols = getThings('describe `' . PFX . 'txp_plugin`'); if (!in_array('flags', $cols)) { safe_alter('txp_plugin', "ADD flags SMALLINT UNSIGNED NOT NULL DEFAULT 0"); } // Default theme. if (!safe_field('name', 'txp_prefs', "name = 'theme_name'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'theme_name', val = 'classic', type = '1', event = 'admin', html = 'themename', position = '160'"); } safe_alter('txp_plugin', 'CHANGE code code MEDIUMTEXT NOT NULL, CHANGE code_restore code_restore MEDIUMTEXT NOT NULL'); safe_alter('txp_prefs', 'CHANGE val val TEXT NOT NULL'); // Add author column to files and links, // Boldy assuming that the publisher in charge of updating this site is the author of any existing content items. foreach (array('txp_file', 'txp_link') as $table) { $cols = getThings('describe `' . PFX . $table . '`'); if (!in_array('author', $cols)) { safe_alter($table, "ADD author varchar(255) NOT NULL default '', ADD INDEX author_idx (author)"); safe_update($table, "author='" . doSlash($txp_user) . "'", '1=1'); } } // Add indices on author columns. foreach (array('textpattern' => 'AuthorID', 'txp_image' => 'author') as $table => $col) { $has_idx = 0; $rs = getRows('show index from `' . PFX . $table . '`'); foreach ($rs as $row) { if ($row['Key_name'] == 'author_idx') { $has_idx = 1; } } if (!$has_idx) {
function section_edit() { global $event, $step, $txp_user, $all_pages, $all_styles; $name = gps('name'); $is_edit = $name && $step == 'section_edit'; if ($is_edit) { $name = assert_string($name); $rs = safe_row('*', 'txp_section', "name = '" . doSlash($name) . "'"); } else { $rs = array_flip(getThings('describe `' . PFX . 'txp_section`')); } if ($rs) { if (!has_privs('section.edit')) { sec_section_list(gTxt('restricted_area')); return; } pagetop(gTxt('tab_sections')); extract($rs, EXTR_PREFIX_ALL, 'sec'); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); $is_default_section = $is_edit && $sec_name == 'default'; $caption = gTxt($is_default_section ? 'edit_default_section' : ($is_edit ? 'edit_section' : 'create_section')); if (!$is_edit) { // Pulling out the radio items from the default entry might seem pointless since they can't be directly // edited, but they will take on either: // a) the default (SQL) values as defined at table creation time, or // b) the values set when a multi-edit was performed that included the default section (because the values are silently updated then) $default = doSlash(safe_row('page, css, on_frontpage, in_rss, searchable', 'txp_section', "name = 'default'")); $sec_name = $sec_title = ''; $sec_page = $default['page']; $sec_css = $default['css']; $sec_on_frontpage = $default['on_frontpage']; $sec_in_rss = $default['in_rss']; $sec_searchable = $default['searchable']; } echo '<div id="' . $event . '_container" class="txp-container">'; echo form('<div class="txp-edit">' . hed($caption, 2) . ($is_default_section ? hInput('name', 'default') : inputLabel('section_name', fInput('text', 'name', $sec_name, '', '', '', INPUT_REGULAR, '', 'section_name'), 'section_name')) . ($is_default_section ? '' : inputLabel('section_title', fInput('text', 'title', $sec_title, '', '', '', INPUT_REGULAR, '', 'section_title'), 'section_longtitle')) . inputLabel('section_page', selectInput('section_page', $all_pages, $sec_page, '', '', 'section_page'), 'uses_page', 'section_uses_page') . inputLabel('section_css', selectInput('css', $all_styles, $sec_css, '', '', 'section_css'), 'uses_style', 'section_uses_css') . ($is_default_section ? '' : inputLabel('on_front_page', yesnoradio('on_frontpage', $sec_on_frontpage, '', $sec_name), '', 'section_on_frontpage')) . ($is_default_section ? '' : inputLabel('syndicate', yesnoradio('in_rss', $sec_in_rss, '', $sec_name), '', 'section_syndicate')) . ($is_default_section ? '' : inputLabel('include_in_search', yesnoradio('searchable', $sec_searchable, '', $sec_name), '', 'section_searchable')) . pluggable_ui('section_ui', 'extend_detail_form', '', $rs) . graf(fInput('submit', '', gTxt('save'), 'publish')) . eInput('section') . sInput('section_save') . hInput('old_name', $sec_name) . hInput('search_method', $search_method) . hInput('crit', $crit) . hInput('page', $page) . hInput('sort', $sort) . hInput('dir', $dir) . '</div>', '', '', 'post', 'edit-form', '', 'section_details'); echo '</div>'; } }
} if (safe_count('txp_category', "title=''") > 0) { safe_update('txp_category', 'title=name', "title=''"); } // 1.0: Unique key and 'type' field for the txp_prefs table $has_prefs_idx = 0; $rs = getRows('show index from `' . PFX . 'txp_prefs`'); foreach ($rs as $row) { if ($row['Key_name'] == 'prefs_idx') { $has_prefs_idx = 1; } } if (!$has_prefs_idx) { safe_query('alter ignore table `' . PFX . 'txp_prefs` add unique prefs_idx(prefs_id,name)'); } $txpprefs = getThings('describe `' . PFX . 'txp_prefs`'); if (!in_array('type', $txpprefs)) { safe_alter('txp_prefs', "add `type` smallint unsigned not null default '2'"); } # update the updated with default hidden type for old plugins prefs safe_alter('txp_prefs', "change `type` `type` smallint unsigned not null default '2'"); if (!in_array('event', $txpprefs)) { safe_alter('txp_prefs', "add `event` varchar(12) not null default 'publish'"); } if (!in_array('html', $txpprefs)) { safe_alter('txp_prefs', "add `html` varchar(64) not null default ''"); } if (!in_array('position', $txpprefs)) { safe_alter('txp_prefs', "add `position` smallint unsigned not null default '0'"); # add new column values to prefs $prefs_new_cols = array('attach_titles_to_permalinks' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '1', 'position' => '1'), 'sitename' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '1'), 'siteurl' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '2'), 'site_slogan' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '3'), 'language' => array('html' => 'languages', 'event' => 'publish', 'type' => '0', 'position' => '4'), 'gmtoffset' => array('html' => 'gmtoffset_select', 'event' => 'publish', 'type' => '0', 'position' => '5'), 'is_dst' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '0', 'position' => '6'), 'dateformat' => array('html' => 'dateformats', 'event' => 'publish', 'type' => '0', 'position' => '7'), 'archive_dateformat' => array('html' => 'dateformats', 'event' => 'publish', 'type' => '0', 'position' => '8'), 'permlink_mode' => array('html' => 'permlinkmodes', 'event' => 'publish', 'type' => '0', 'position' => '9'), 'send_lastmod' => array('html' => 'yesnoradio', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'ping_weblogsdotcom' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '1', 'position' => '0'), 'use_comments' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '0', 'position' => '12'), 'logging' => array('html' => 'logging', 'event' => 'publish', 'type' => '0', 'position' => '10'), 'use_textile' => array('html' => 'pref_text', 'event' => 'publish', 'type' => '0', 'position' => '11'), 'tempdir' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'file_base_path' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'file_max_upload_size' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'comments_moderate' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '13'), 'comments_on_default' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '14'), 'comments_are_ol' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '15'), 'comments_sendmail' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '16'), 'comments_disallow_images' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '17'), 'comments_default_invite' => array('html' => 'text_input', 'event' => 'comments', 'type' => '0', 'position' => '18'), 'comments_dateformat' => array('html' => 'dateformats', 'event' => 'comments', 'type' => '0', 'position' => '19'), 'comments_mode' => array('html' => 'commentmode', 'event' => 'comments', 'type' => '0', 'position' => '20'), 'comments_disabled_after' => array('html' => 'weeks', 'event' => 'comments', 'type' => '0', 'position' => '21'), 'img_dir' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'rss_how_many' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'));
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Textpattern. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('TXP_UPDATE')) { exit("Nothing here. You can't access this file directly."); } safe_alter('txp_lang', 'DELAY_KEY_WRITE = 0'); if (!safe_field("name", 'txp_prefs', "name = 'lastmod_keepalive'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'lastmod_keepalive', val = '0', type = '1', html = 'yesnoradio'"); } // New status field for file downloads. $txpfile = getThings("DESCRIBE `" . PFX . "txp_file`"); if (!in_array('status', $txpfile)) { safe_alter('txp_file', "ADD status SMALLINT NOT NULL DEFAULT '4'"); } $update_files = 0; if (!in_array('modified', $txpfile)) { safe_alter('txp_file', "ADD modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'"); $update_files = 1; } if (!in_array('created', $txpfile)) { safe_alter('txp_file', "ADD created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'"); $update_files = 1; } if (!in_array('size', $txpfile)) { safe_alter('txp_file', "ADD size BIGINT"); $update_files = 1;
function bot_admin_tooltips_check_install() { // Check if the bot_admin_tooltips table already exists if (getThings("Show tables like '" . PFX . "bot_admin_tooltips'")) { return true; } return false; }
if (!defined('TXP_UPDATE')) { exit("Nothing here. You can't access this file directly."); } $txpplugin = getThings('DESCRIBE `' . PFX . 'txp_plugin`'); if (!in_array('load_order', $txpplugin)) { safe_alter('txp_plugin', "ADD load_order TINYINT UNSIGNED NOT NULL DEFAULT 5"); } // Enable XML-RPC server? if (!safe_field("name", 'txp_prefs', "name = 'enable_xmlrpc_server'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'enable_xmlrpc_server', val = 0, type = 1, event = 'admin', html = 'yesnoradio', position = 130"); } if (!safe_field("name", 'txp_prefs', "name = 'smtp_from'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'smtp_from', val = '', type = 1, event = 'admin', position = 110"); } if (!safe_field("val", 'txp_prefs', "name = 'author_list_pageby'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'author_list_pageby', val = 25, type = 2"); } // Expiry datetime for articles. $txp = getThings("DESCRIBE `" . PFX . "textpattern`"); if (!in_array('Expires', $txp)) { safe_alter('textpattern', "ADD Expires DATETIME AFTER Posted"); } safe_create_index('textpattern', 'Expires', 'Expires_idx'); // Publish expired articles, or return 410? if (!safe_field("name", 'txp_prefs', "name = 'publish_expired_articles'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'publish_expired_articles', val = '0', type = '1', event = 'publish', html = 'yesnoradio', position = '130'"); } // Searchable article fields hidden preference. if (!safe_field("name", 'txp_prefs', "name = 'searchable_article_fields'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'searchable_article_fields', val = 'Title, Body', type = '2', event = 'publish', html = 'text_input', position = '0'"); }
} if (safe_count('txp_category', "title=''") > 0) { safe_update('txp_category', 'title=name', "title=''"); } // 1.0: Unique key and 'type' field for the txp_prefs table $has_prefs_idx = 0; $rs = getRows('show index from ' . PFX . 'txp_prefs'); foreach ($rs as $row) { if ($row['Key_name'] == 'prefs_idx') { $has_prefs_idx = 1; } } if (!$has_prefs_idx) { safe_query('alter ignore table ' . PFX . 'txp_prefs add unique prefs_idx(prefs_id,name)'); } $txpprefs = getThings('describe ' . PFX . 'txp_prefs'); if (!in_array('type', $txpprefs)) { safe_alter('txp_prefs', "add `type` smallint unsigned not null default '2'"); } # update the updated with default hidden type for old plugins prefs safe_alter('txp_prefs', "change `type` `type` smallint unsigned not null default '2'"); if (!in_array('event', $txpprefs)) { safe_alter('txp_prefs', "add `event` varchar(12) not null default 'publish'"); } if (!in_array('html', $txpprefs)) { safe_alter('txp_prefs', "add `html` varchar(64) not null default ''"); } if (!in_array('position', $txpprefs)) { safe_alter('txp_prefs', "add `position` smallint unsigned not null default '0'"); # add new column values to prefs $prefs_new_cols = array('attach_titles_to_permalinks' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '1', 'position' => '1'), 'sitename' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '1'), 'siteurl' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '2'), 'site_slogan' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '3'), 'language' => array('html' => 'languages', 'event' => 'publish', 'type' => '0', 'position' => '4'), 'gmtoffset' => array('html' => 'gmtoffset_select', 'event' => 'publish', 'type' => '0', 'position' => '5'), 'is_dst' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '0', 'position' => '6'), 'dateformat' => array('html' => 'dateformats', 'event' => 'publish', 'type' => '0', 'position' => '7'), 'archive_dateformat' => array('html' => 'dateformats', 'event' => 'publish', 'type' => '0', 'position' => '8'), 'permlink_mode' => array('html' => 'permlinkmodes', 'event' => 'publish', 'type' => '0', 'position' => '9'), 'send_lastmod' => array('html' => 'yesnoradio', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'ping_weblogsdotcom' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '1', 'position' => '0'), 'use_comments' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '0', 'position' => '12'), 'logging' => array('html' => 'logging', 'event' => 'publish', 'type' => '0', 'position' => '10'), 'use_textile' => array('html' => 'text', 'event' => 'publish', 'type' => '0', 'position' => '11'), 'tempdir' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'file_base_path' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'file_max_upload_size' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'comments_moderate' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '13'), 'comments_on_default' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '14'), 'comments_are_ol' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '15'), 'comments_sendmail' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '16'), 'comments_disallow_images' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '17'), 'comments_default_invite' => array('html' => 'text_input', 'event' => 'comments', 'type' => '0', 'position' => '18'), 'comments_dateformat' => array('html' => 'dateformats', 'event' => 'comments', 'type' => '0', 'position' => '19'), 'comments_mode' => array('html' => 'commentmode', 'event' => 'comments', 'type' => '0', 'position' => '20'), 'comments_disabled_after' => array('html' => 'weeks', 'event' => 'comments', 'type' => '0', 'position' => '21'), 'img_dir' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'rss_how_many' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'));
function can_install() { global $txpcfg; $host = $txpcfg['host']; $user = $txpcfg['user']; $version = mysql_get_server_info(); $matched = false; $debug = gps('debugwiz'); $debug = !empty($debug); # # Make sure we escape the MySQL special name characters... # $db_lean = $txpcfg['db']; $db = strtr($db_lean, array('_' => '\\_', '%' => '\\%')); if ($debug) { echo br, "Testing for privs to DB:`{$db}` on Server:{$host}, v:{$version}. Connected using user: {$user}."; } # # Test the privilages of the user used to connect to the TxP DB... # if ($user === 'root') { if ($debug) { echo br, 'Using root - skipping privileges checking.'; } return true; } # # This should work for all versions of MySQL... # $sql = "SHOW GRANTS FOR '{$user}'@'{$host}';"; if ($debug) { $rows = getThings($sql, 1); } else { $rows = @getThings($sql); } # # But, if it failed then retry using a different command (if possible)... # if (empty($rows)) { if ($debug) { echo br, "Initial SHOW GRANTS query failed"; } if (version_compare($version, '4.1.2', '>=')) { $sql = "SHOW GRANTS;"; if ($debug) { echo ', re-trying.'; $rows = getThings($sql, 1); } else { $rows = @getThings($sql); } } } if (!empty($rows)) { $rows = $this->strip_pws($rows); if ($debug) { echo dmp($rows); } $global_row = ''; foreach ($rows as $row) { if (false !== strpos($row, 'GRANT USAGE')) { continue; } if (false !== strpos($row, 'ON *.*')) { $global_row = $row; if ($debug) { echo br, "Storing global row for processing later."; } } elseif (false !== strpos($row, "ON `{$db}`") or false !== strpos($row, "ON `{$db_lean}`")) { $matched = $this->check_row($row); if ($matched === true) { break; } } elseif (false !== strpos($row, '%')) { # # Check for wildcard DB cases in the grants list. # $matches = array(); $pattern = "/ ON `(.*)`/"; # # Extract the DB name... # if ($debug) { echo br, "Extracting DB name pattern [{$pattern}] from {$row}."; } $count = preg_match($pattern, $row, $matches); if ($count !== 1) { if ($debug) { echo br, "Could not match DB name pattern."; } continue; } $name = $matches[1]; if ($debug) { echo br, "Matched db name: [{$name}] - "; } # # Get start of the name... # $s = strpos($name, '%'); $name = substr($name, 0, $s); if ($debug) { echo "Stripped down to [{$name}] - "; } $len = strlen($name); # # Strip escape sequences... # if ($len > 0) { $name = strtr($name, array("\\\\" => '', "\\" => '')); if ($debug) { echo "Stripped down to [{$name}] - "; } } # # Prepare the comparison string... # $len = strlen($name); $cmp = substr($db_lean, 0, $len); # # Compare to the db name we are testing for... # if ($debug) { echo "Comparing [{$name}] with [{$cmp}] ... "; } if ($name === $cmp) { if ($debug) { echo "matched! Checking privs as usual... "; } $matched = $this->check_row($row); if ($matched === true) { break; } } } } if ($matched !== true and !empty($global_row)) { if ($debug) { echo br, "Processing global row: {$global_row}"; } $matched = $this->check_row($global_row); } } else { # # The SHOW GRANTS query failed. So we cannot check anything using that. # Instead, allow installation to continue. Should we show a warning to the user # At the head of the setup wizard? # $matched = true; if ($debug) { echo br, 'Could not determine your user grants on the database; will continue anyway.'; } } if ($matched === false) { $matched = gTxt('l10n-missing_all_privs', array('{escaped_db}' => $db, '{db}' => $db_lean)); } if ($debug) { echo br, br, 'Matched: ', var_dump($matched); } return $matched; }
* This file is part of Textpattern. * * Textpattern is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, version 2. * * Textpattern is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Textpattern. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('TXP_UPDATE')) { exit("Nothing here. You can't access this file directly."); } // Raw CSS is now the only option. safe_delete('txp_prefs', "event = 'css' AND name = 'edit_raw_css_by_default'"); $rs = getRows("SELECT name, css FROM `" . PFX . "txp_css`"); foreach ($rs as $row) { if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $row['css'])) { // Data is still base64 encoded. safe_update('txp_css', "css = '" . doSlash(base64_decode($row['css'])) . "'", "name = '" . doSlash($row['name']) . "'"); } } // Add column for file title. $cols = getThings("DESCRIBE `" . PFX . "txp_file`"); if (!in_array('title', $cols)) { safe_alter('txp_file', "ADD title VARCHAR(255) NULL AFTER filename"); }
safe_update('txp_prefs', "position = '160'", "name = 'comments_sendmail'"); safe_update('txp_prefs', "position = '180'", "name = 'comments_are_ol'"); safe_update('txp_prefs', "position = '200'", "name = 'comment_means_site_updated'"); safe_update('txp_prefs', "position = '220'", "name = 'comments_require_name'"); safe_update('txp_prefs', "position = '240'", "name = 'comments_require_email'"); safe_update('txp_prefs', "position = '260'", "name = 'never_display_email'"); safe_update('txp_prefs', "position = '280'", "name = 'comment_nofollow'"); safe_update('txp_prefs', "position = '300'", "name = 'comments_disallow_images'"); safe_update('txp_prefs', "position = '320'", "name = 'comments_use_fat_textile'"); safe_update('txp_prefs', "position = '340'", "name = 'spam_blacklists'"); // Updates comment email length. safe_alter('txp_discuss', "MODIFY email VARCHAR(254) NOT NULL default ''"); // Store IPv6 properly in logs. safe_alter('txp_log', "MODIFY ip VARCHAR(45) NOT NULL default ''"); // Support for l10n string owners. $cols = getThings('describe `' . PFX . 'txp_lang`'); if (!in_array('owner', $cols)) { safe_alter('txp_lang', "ADD owner VARCHAR(64) NOT NULL DEFAULT '' AFTER event, ADD INDEX owner (owner)"); } // Keep all comment-related forms together. The loss of 'preview' ability on the // comments_display Form is of little consequence compared with the benefit of // tucking them away neatly when not required. safe_update('txp_form', "type = 'comment'", "name = 'comments_display'"); // Adds protocol to logged HTTP referers. safe_update('txp_log', "refer = CONCAT('http://', refer)", "refer != '' and refer NOT LIKE 'http://%' and refer NOT LIKE 'https://%'"); // Usernames can be 64 characters long at most. safe_alter('txp_file', "MODIFY author VARCHAR(64) NOT NULL default ''"); safe_alter('txp_image', "MODIFY author VARCHAR(64) NOT NULL default ''"); // Consistent name length limitations for presentation items. safe_alter('txp_form', "MODIFY name VARCHAR(255) NOT NULL"); safe_alter('txp_page', "MODIFY name VARCHAR(255) NOT NULL");
/** * Outputs a diagnostics report. * * This is the main panel. */ function doDiagnostics() { global $prefs, $files, $txpcfg, $event, $step, $theme, $DB; extract(get_prefs()); $urlparts = parse_url(hu); $mydomain = $urlparts['host']; $is_apache = stristr(serverSet('SERVER_SOFTWARE'), 'Apache') || is_callable('apache_get_version'); $real_doc_root = isset($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT']) : ''; // ini_get() returns string values passed via php_value as a string, not boolean. $is_register_globals = (strcasecmp(ini_get('register_globals'), 'on') === 0 or ini_get('register_globals') === '1'); // Check for Textpattern updates, at most once every 24 hours. $now = time(); $updateInfo = unserialize(get_pref('last_update_check', '')); if (!$updateInfo || $now > $updateInfo['when'] + 60 * 60 * 24) { $updates = checkUpdates(); $updateInfo['msg'] = $updates ? gTxt($updates['msg'], array('{version}' => $updates['version'])) : ''; $updateInfo['when'] = $now; set_pref('last_update_check', serialize($updateInfo), 'publish', PREF_HIDDEN, 'text_input'); } $fail = array(); if (!empty($updateInfo['msg'])) { $fail['textpattern_version_update'] = diag_msg_wrap($updateInfo['msg'], 'information'); } if (!is_callable('version_compare') || version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) { $fail['php_version_required'] = diag_msg_wrap(gTxt('php_version_required', array('{version}' => REQUIRED_PHP_VERSION))); } if (!isset($path_to_site)) { $fail['path_to_site_missing'] = diag_msg_wrap(gTxt('path_to_site_missing'), 'warning'); } if (@gethostbyname($mydomain) === $mydomain) { $fail['dns_lookup_fails'] = diag_msg_wrap(gTxt('dns_lookup_fails') . cs . $mydomain, 'warning'); } if (!@is_dir($path_to_site)) { $fail['path_to_site_inacc'] = diag_msg_wrap(gTxt('path_to_site_inacc') . cs . $path_to_site); } if (rtrim($siteurl, '/') != $siteurl) { $fail['site_trailing_slash'] = diag_msg_wrap(gTxt('site_trailing_slash') . cs . $path_to_site, 'warning'); } if (!@is_file($path_to_site . "/index.php") || !@is_readable($path_to_site . "/index.php")) { $fail['index_inaccessible'] = diag_msg_wrap("{$path_to_site}/index.php " . gTxt('is_inaccessible')); } $not_readable = array(); if (!@is_writable($path_to_site . '/' . $img_dir)) { $not_readable[] = diag_msg_wrap(str_replace('{dirtype}', gTxt('img_dir'), gTxt('dir_not_writable')) . ": {$path_to_site}/{$img_dir}", 'warning'); } if (!@is_writable($file_base_path)) { $not_readable[] = diag_msg_wrap(str_replace('{dirtype}', gTxt('file_base_path'), gTxt('dir_not_writable')) . ": {$file_base_path}", 'warning'); } if (!@is_writable($tempdir)) { $not_readable[] = diag_msg_wrap(str_replace('{dirtype}', gTxt('tempdir'), gTxt('dir_not_writable')) . ": {$tempdir}", 'warning'); } if ($not_readable) { $fail['dir_not_writable'] = join(n, $not_readable); } if ($permlink_mode != 'messy' && !$is_apache) { $fail['cleanurl_only_apache'] = diag_msg_wrap(gTxt('cleanurl_only_apache'), 'information'); } if ($permlink_mode != 'messy' and !@is_readable($path_to_site . '/.htaccess')) { $fail['htaccess_missing'] = diag_msg_wrap(gTxt('htaccess_missing')); } if ($permlink_mode != 'messy' and is_callable('apache_get_modules') and !apache_module('mod_rewrite')) { $fail['mod_rewrite_missing'] = diag_msg_wrap(gTxt('mod_rewrite_missing')); } if (!ini_get('file_uploads')) { $fail['file_uploads_disabled'] = diag_msg_wrap(gTxt('file_uploads_disabled'), 'information'); } if (@is_dir(txpath . DS . 'setup')) { $fail['setup_still_exists'] = diag_msg_wrap(txpath . DS . "setup" . DS . ' ' . gTxt('still_exists'), 'warning'); } if (empty($tempdir)) { $fail['no_temp_dir'] = diag_msg_wrap(gTxt('no_temp_dir'), 'warning'); } if (is_disabled('mail')) { $fail['warn_mail_unavailable'] = diag_msg_wrap(gTxt('warn_mail_unavailable'), 'warning'); } if ($is_register_globals) { $fail['warn_register_globals_or_update'] = diag_msg_wrap(gTxt('warn_register_globals_or_update'), 'warning'); } if ($permlink_mode != 'messy') { $rs = safe_column("name", "txp_section", "1"); foreach ($rs as $name) { if ($name and @file_exists($path_to_site . '/' . $name)) { $fail['old_placeholder_exists'] = diag_msg_wrap(gTxt('old_placeholder') . ": {$path_to_site}/{$name}"); } } } $cs = check_file_integrity(INTEGRITY_REALPATH); if (!$cs) { $cs = array(); } // Files that don't match their checksums. if ($modified_files = array_keys($cs, INTEGRITY_MODIFIED)) { $fail['modified_files'] = diag_msg_wrap(gTxt('modified_files') . cs . n . t . join(', ' . n . t, $modified_files), 'warning'); } // Running development code in live mode is not recommended. if (preg_match('/-dev$/', txp_version) and $production_status == 'live') { $fail['dev_version_live'] = diag_msg_wrap(gTxt('dev_version_live'), 'warning'); } // Missing files. if ($missing = array_merge(array_keys($cs, INTEGRITY_MISSING), array_keys($cs, INTEGRITY_NOT_FILE), array_keys($cs, INTEGRITY_NOT_READABLE))) { $fail['missing_files'] = diag_msg_wrap(gTxt('missing_files') . cs . n . t . join(', ' . n . t, $missing)); } // Anything might break if arbitrary functions are disabled. if (ini_get('disable_functions')) { $disabled_funcs = array_map('trim', explode(',', ini_get('disable_functions'))); // Commonly disabled functions that we don't need. $disabled_funcs = array_diff($disabled_funcs, array('imagefilltoborder', 'escapeshellarg', 'escapeshellcmd', 'exec', 'passthru', 'proc_close', 'proc_get_status', 'proc_nice', 'proc_open', 'proc_terminate', 'shell_exec', 'system', 'popen', 'dl', 'chown')); if ($disabled_funcs) { $fail['some_php_functions_disabled'] = diag_msg_wrap(gTxt('some_php_functions_disabled') . cs . join(', ', $disabled_funcs), 'warning'); } } // Not sure about this one. // if (strncmp(php_sapi_name(), 'cgi', 3) == 0 and ini_get('cgi.rfc2616_headers')) // $fail['cgi_header_config'] = gTxt('cgi_header_config'); $guess_site_url = $_SERVER['HTTP_HOST'] . preg_replace('#[/\\\\]$#', '', dirname(dirname($_SERVER['SCRIPT_NAME']))); if ($siteurl and strip_prefix($siteurl, 'www.') != strip_prefix($guess_site_url, 'www.')) { $fail['site_url_mismatch'] = diag_msg_wrap(gTxt('site_url_mismatch') . cs . $guess_site_url, 'warning'); } // Test clean URL server vars. if (hu) { if (ini_get('allow_url_fopen') and $permlink_mode != 'messy') { $s = md5(uniqid(rand(), true)); ini_set('default_socket_timeout', 10); $pretext_data = @file(hu . $s . '/?txpcleantest=1'); if ($pretext_data) { $pretext_req = trim(@$pretext_data[0]); if ($pretext_req != md5('/' . $s . '/?txpcleantest=1')) { $fail['clean_url_data_failed'] = diag_msg_wrap(gTxt('clean_url_data_failed') . cs . txpspecialchars($pretext_req), 'warning'); } } else { $fail['clean_url_test_failed'] = diag_msg_wrap(gTxt('clean_url_test_failed'), 'warning'); } } } if ($tables = list_txp_tables()) { $table_errors = check_tables($tables); if ($table_errors) { $fail['mysql_table_errors'] = diag_msg_wrap(gTxt('mysql_table_errors') . cs . n . t . join(', ' . n . t, $table_errors)); } } $active_plugins = array(); if ($rows = safe_rows('name, version, code_md5, md5(code) as md5', 'txp_plugin', 'status > 0')) { foreach ($rows as $row) { $n = $row['name'] . '-' . $row['version']; if (strtolower($row['md5']) != strtolower($row['code_md5'])) { $n .= 'm'; } $active_plugins[] = $n; } } $theme_manifest = $theme->manifest(); // Check GD info. if (function_exists('gd_info')) { $gd_info = gd_info(); $gd_support = array(); if ($gd_info['GIF Create Support']) { $gd_support[] = 'GIF'; } // Aside: In PHP 5.3, they chose to add a previously unemployed capital "E" to the array key. if (!empty($gd_info['JPEG Support']) || !empty($gd_info['JPG Support'])) { $gd_support[] = 'JPG'; } if ($gd_info['PNG Support']) { $gd_support[] = 'PNG'; } if ($gd_support) { $gd_support = join(', ', $gd_support); } else { $gd_support = gTxt('none'); } $gd = gTxt('gd_info', array('{version}' => $gd_info['GD Version'], '{supported}' => $gd_support)); } else { $gd = gTxt('gd_unavailable'); } if (realpath($prefs['tempdir']) === realpath($prefs['plugin_cache_dir'])) { $fail['tmp_plugin_paths_match'] = diag_msg_wrap(gTxt('tmp_plugin_paths_match')); } // Database server time. extract(doSpecial(getRow('select @@global.time_zone as db_global_timezone, @@session.time_zone as db_session_timezone, now() as db_server_time, unix_timestamp(now()) as db_server_timestamp'))); $db_server_timeoffset = $db_server_timestamp - $now; echo pagetop(gTxt('tab_diagnostics'), ''); echo hed(gTxt('tab_diagnostics'), 1, array('class' => 'txp-heading')); echo n . '<div id="' . $event . '_container" class="txp-container">' . n . '<div id="pre_flight_check">' . hed(gTxt('preflight_check'), 2); if ($fail) { foreach ($fail as $help => $message) { echo graf(nl2br($message) . popHelp($help)); } } else { echo graf(diag_msg_wrap(gTxt('all_checks_passed'), 'success')); } echo '</div>'; echo '<div id="diagnostics">', hed(gTxt('diagnostic_info'), 2); $fmt_date = '%Y-%m-%d %H:%M:%S'; $out = array('<p><textarea class="code" id="diagnostics-detail" cols="' . INPUT_LARGE . '" rows="' . TEXTAREA_HEIGHT_LARGE . '" dir="ltr" readonly>', gTxt('txp_version') . cs . txp_version . ' (' . check_file_integrity(INTEGRITY_DIGEST) . ')' . n, gTxt('last_update') . cs . gmstrftime($fmt_date, $dbupdatetime) . '/' . gmstrftime($fmt_date, @filemtime(txpath . '/update/_update.php')) . n, gTxt('document_root') . cs . @$_SERVER['DOCUMENT_ROOT'] . ($real_doc_root != @$_SERVER['DOCUMENT_ROOT'] ? ' (' . $real_doc_root . ')' : '') . n, '$path_to_site' . cs . $path_to_site . n, gTxt('txp_path') . cs . txpath . n, gTxt('permlink_mode') . cs . $permlink_mode . n, ini_get('open_basedir') ? 'open_basedir: ' . ini_get('open_basedir') . n : '', ini_get('upload_tmp_dir') ? 'upload_tmp_dir: ' . ini_get('upload_tmp_dir') . n : '', gTxt('tempdir') . cs . $tempdir . n, gTxt('web_domain') . cs . $siteurl . n, gTxt('php_version') . cs . phpversion() . n, $is_register_globals ? gTxt('register_globals') . cs . $is_register_globals . n : '', gTxt('gd_library') . cs . $gd . n, gTxt('server') . ' TZ: ' . Txp::get('Textpattern_Date_Timezone')->getTimeZone() . n, gTxt('server_time') . cs . strftime('%Y-%m-%d %H:%M:%S') . n, strip_tags(gTxt('is_dst')) . cs . $is_dst . n, strip_tags(gTxt('auto_dst')) . cs . $auto_dst . n, strip_tags(gTxt('gmtoffset')) . cs . $timezone_key . sp . "({$gmtoffset})" . n, 'MySQL' . cs . mysql_get_server_info() . n, gTxt('db_server_time') . cs . $db_server_time . n, gTxt('db_server_timeoffset') . cs . $db_server_timeoffset . ' s' . n, gTxt('db_global_timezone') . cs . $db_global_timezone . n, gTxt('db_session_timezone') . cs . $db_session_timezone . n, gTxt('locale') . cs . $locale . n, isset($_SERVER['SERVER_SOFTWARE']) ? gTxt('server') . cs . $_SERVER['SERVER_SOFTWARE'] . n : '', is_callable('apache_get_version') ? gTxt('apache_version') . cs . @apache_get_version() . n : '', gTxt('php_sapi_mode') . cs . PHP_SAPI . n, gTxt('rfc2616_headers') . cs . ini_get('cgi.rfc2616_headers') . n, gTxt('os_version') . cs . php_uname('s') . ' ' . php_uname('r') . n, $active_plugins ? gTxt('active_plugins') . cs . join(', ', $active_plugins) . n : '', gTxt('theme_name') . cs . $theme_name . sp . $theme_manifest['version'] . n, $fail ? n . gTxt('preflight_check') . cs . n . ln . join("\n", doStripTags($fail)) . n . ln : '', is_readable($path_to_site . '/.htaccess') ? n . gTxt('htaccess_contents') . cs . n . ln . txpspecialchars(join('', file($path_to_site . '/.htaccess'))) . n . ln : ''); if ($step == 'high') { $out[] = n . 'Charset (default/config)' . cs . $DB->default_charset . '/' . $DB->charset . n; $result = safe_query("SHOW variables like 'character_se%'"); while ($row = mysql_fetch_row($result)) { $out[] = $row[0] . cs . $row[1] . n; if ($row[0] == 'character_set_connection') { $conn_char = $row[1]; } } $table_names = array(PFX . 'textpattern'); $result = safe_query("SHOW TABLES LIKE '" . PFX . "txp\\_%'"); while ($row = mysql_fetch_row($result)) { $table_names[] = $row[0]; } $table_msg = array(); foreach ($table_names as $table) { $ctr = safe_query("SHOW CREATE TABLE " . $table . ""); if (!$ctr) { unset($table_names[$table]); continue; } $ctcharset = preg_replace('#^CREATE TABLE.*SET=([^ ]+)[^)]*$#is', '\\1', mysql_result($ctr, 0, 'Create Table')); if (isset($conn_char) && !stristr($ctcharset, 'CREATE') && $conn_char != $ctcharset) { $table_msg[] = "{$table} is {$ctcharset}"; } $ctr = safe_query("CHECK TABLE " . $table); if (in_array(mysql_result($ctr, 0, 'Msg_type'), array('error', 'warning'))) { $table_msg[] = $table . cs . mysql_result($ctr, 0, 'Msg_Text'); } } if ($table_msg == array()) { $table_msg = count($table_names) < 17 ? array('-') : array('OK'); } $out[] = count($table_names) . ' Tables' . cs . implode(', ', $table_msg) . n; $cf = preg_grep('/^custom_\\d+/', getThings('describe `' . PFX . 'textpattern`')); $out[] = n . get_pref('max_custom_fields', 10) . sp . gTxt('custom') . cs . implode(', ', $cf) . sp . '(' . count($cf) . ')' . n; $extns = get_loaded_extensions(); $extv = array(); foreach ($extns as $e) { $extv[] = $e . (phpversion($e) ? '/' . phpversion($e) : ''); } $out[] = n . gTxt('php_extensions') . cs . join(', ', $extv) . n; if (is_callable('apache_get_modules')) { $out[] = n . gTxt('apache_modules') . cs . join(', ', apache_get_modules()) . n; } if (@is_array($pretext_data) and count($pretext_data) > 1) { $out[] = n . gTxt('pretext_data') . cs . txpspecialchars(join('', array_slice($pretext_data, 1, 20))) . n; } $out[] = n; if ($md5s = check_file_integrity(INTEGRITY_MD5)) { foreach ($md5s as $f => $checksum) { $out[] = $f . cs . n . t . (!$checksum ? gTxt('unknown') : $checksum) . n; } } $out[] = n . ln; } $out[] = callback_event('diag_results', $step) . n; $out[] = '</textarea></p>'; $dets = array('low' => gTxt('low'), 'high' => gTxt('high')); $out[] = form(graf(eInput('diag') . n . '<label>' . gTxt('detail') . '</label>' . selectInput('step', $dets, $step, 0, 1))); echo join('', $out), '</div>', '</div>'; }
* along with Textpattern. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('TXP_UPDATE')) { exit("Nothing here. You can't access this file directly."); } // Doctype prefs. if (!safe_field("name", 'txp_prefs', "name = 'doctype'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'doctype', val = 'xhtml', type = '0', event = 'publish', html = 'doctypes', position = '190'"); } // Publisher's email address. if (!safe_field("name", 'txp_prefs', "name = 'publisher_email'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'publisher_email', val = '', type = 1, event = 'admin', position = 115"); } // Goodbye raw ?php support. if (safe_field("name", 'txp_prefs', "name = 'allow_raw_php_scripting'")) { safe_delete('txp_prefs', "name = 'allow_raw_php_scripting'"); } safe_alter('txp_users', "\n MODIFY RealName VARCHAR(255) NOT NULL DEFAULT '',\n MODIFY email VARCHAR(254) NOT NULL DEFAULT ''"); // Remove any setup strings from lang table. safe_delete('txp_lang', "event = 'setup'"); safe_create_index('textpattern', 'url_title', 'url_title_idx'); // Remove is_default from txp_section table and make it a preference. if (!safe_field("name", 'txp_prefs', "name = 'default_section'")) { $current_default_section = safe_field("name", 'txp_section', "is_default = 1"); safe_insert('txp_prefs', "prefs_id = 1, name = 'default_section', val = '" . doSlash($current_default_section) . "', type = '2', event = 'section', html = 'text_input', position = '0'"); } $cols = getThings("DESCRIBE `" . PFX . "txp_section`"); if (in_array('is_default', $cols)) { safe_alter('txp_section', "DROP is_default"); } safe_alter('txp_css', "MODIFY css MEDIUMTEXT NOT NULL");
safe_alter("textpattern", "add `custom_7` varchar(255) not null"); } if (!in_array('custom_8', $txp)) { safe_alter("textpattern", "add `custom_8` varchar(255) not null"); } if (!in_array('custom_9', $txp)) { safe_alter("textpattern", "add `custom_9` varchar(255) not null"); } if (!in_array('custom_10', $txp)) { safe_alter("textpattern", "add `custom_10` varchar(255) not null"); } $txpsect = getThings('describe ' . PFX . 'txp_section'); if (!in_array('searchable', $txpsect)) { safe_alter("txp_section", "add `searchable` int(2) not null default 1"); } $txpuser = getThings('describe ' . PFX . 'txp_users'); if (!in_array('nonce', $txpuser)) { safe_alter("txp_users", "add `nonce` varchar(64) not null"); } // 1.0rc: checking nonce in txp_users table $txpusers = safe_rows('name, nonce', 'txp_users', '1'); if ($txpusers) { foreach ($txpusers as $a) { extract($a); if (!$nonce) { $nonce = md5(uniqid(rand(), true)); safe_update('txp_users', "nonce='{$nonce}'", "name = '{$name}'"); } } } // 1.0rc: expanding password field in txp_users
// 1.0: Human-friendly title for sections and categories, to solve i18n problems. if (!in_array('title', $txpsect)) { safe_alter('txp_section', "ADD title VARCHAR(255) NOT NULL DEFAULT ''"); } if (!in_array('title', $txpcat)) { safe_alter('txp_category', "ADD title VARCHAR(255) NOT NULL DEFAULT ''"); } if (safe_count('txp_section', "title = ''") > 0) { safe_update('txp_section', "title = name", "title = ''"); } if (safe_count('txp_category', "title = ''") > 0) { safe_update('txp_category', "title = name", "title = ''"); } // 1.0: Unique key and 'type' field for the txp_prefs table. safe_create_index('txp_prefs', 'prefs_id, name', 'prefs_idx', 'unique'); $txpprefs = getThings('DESCRIBE `' . PFX . 'txp_prefs`'); if (!in_array('type', $txpprefs)) { safe_alter('txp_prefs', "ADD type SMALLINT UNSIGNED NOT NULL DEFAULT '2'"); } // Update the updated with default hidden type for old plugins prefs. safe_alter('txp_prefs', "CHANGE type type SMALLINT UNSIGNED NOT NULL DEFAULT '2'"); if (!in_array('event', $txpprefs)) { safe_alter('txp_prefs', "ADD event VARCHAR(12) NOT NULL DEFAULT 'publish'"); } if (!in_array('html', $txpprefs)) { safe_alter('txp_prefs', "ADD html VARCHAR(64) NOT NULL DEFAULT ''"); } if (!in_array('position', $txpprefs)) { safe_alter('txp_prefs', "ADD position SMALLINT UNSIGNED NOT NULL DEFAULT '0'"); // Add new column values to prefs. $prefs_new_cols = array('attach_titles_to_permalinks' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '1', 'position' => '1'), 'sitename' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '1'), 'siteurl' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '2'), 'site_slogan' => array('html' => 'text_input', 'event' => 'publish', 'type' => '0', 'position' => '3'), 'language' => array('html' => 'languages', 'event' => 'publish', 'type' => '0', 'position' => '4'), 'gmtoffset' => array('html' => 'gmtoffset_select', 'event' => 'publish', 'type' => '0', 'position' => '5'), 'is_dst' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '0', 'position' => '6'), 'dateformat' => array('html' => 'dateformats', 'event' => 'publish', 'type' => '0', 'position' => '7'), 'archive_dateformat' => array('html' => 'dateformats', 'event' => 'publish', 'type' => '0', 'position' => '8'), 'permlink_mode' => array('html' => 'permlinkmodes', 'event' => 'publish', 'type' => '0', 'position' => '9'), 'send_lastmod' => array('html' => 'yesnoradio', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'ping_weblogsdotcom' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '1', 'position' => '0'), 'use_comments' => array('html' => 'yesnoradio', 'event' => 'publish', 'type' => '0', 'position' => '12'), 'logging' => array('html' => 'logging', 'event' => 'publish', 'type' => '0', 'position' => '10'), 'use_textile' => array('html' => 'pref_text', 'event' => 'publish', 'type' => '0', 'position' => '11'), 'tempdir' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'file_base_path' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'file_max_upload_size' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'comments_moderate' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '13'), 'comments_on_default' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '14'), 'comments_are_ol' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '15'), 'comments_sendmail' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '16'), 'comments_disallow_images' => array('html' => 'yesnoradio', 'event' => 'comments', 'type' => '0', 'position' => '17'), 'comments_default_invite' => array('html' => 'text_input', 'event' => 'comments', 'type' => '0', 'position' => '18'), 'comments_dateformat' => array('html' => 'dateformats', 'event' => 'comments', 'type' => '0', 'position' => '19'), 'comments_mode' => array('html' => 'commentmode', 'event' => 'comments', 'type' => '0', 'position' => '20'), 'comments_disabled_after' => array('html' => 'weeks', 'event' => 'comments', 'type' => '0', 'position' => '21'), 'img_dir' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'), 'rss_how_many' => array('html' => 'text_input', 'event' => 'admin', 'type' => '1', 'position' => '0'));
if (!safe_field("name", 'txp_prefs', "name = 'default_event'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'default_event', val = 'article', type = '1', event = 'admin', html = 'default_event', position = '150'"); } // Add columns for thumbnail dimensions. $cols = getThings("DESCRIBE `" . PFX . "txp_image`"); if (!in_array('thumb_w', $cols)) { safe_alter('txp_image', "\n ADD thumb_w int(8) NOT NULL DEFAULT 0,\n ADD thumb_h int(8) NOT NULL DEFAULT 0"); } // Plugin flags. $cols = getThings('DESCRIBE `' . PFX . 'txp_plugin`'); if (!in_array('flags', $cols)) { safe_alter('txp_plugin', "ADD flags SMALLINT UNSIGNED NOT NULL DEFAULT 0"); } // Default theme. if (!safe_field("name", 'txp_prefs', "name = 'theme_name'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'theme_name', val = 'classic', type = '1', event = 'admin', html = 'themename', position = '160'"); } safe_alter('txp_plugin', "\n CHANGE code code MEDIUMTEXT NOT NULL,\n CHANGE code_restore code_restore MEDIUMTEXT NOT NULL"); safe_alter('txp_prefs', "CHANGE val val TEXT NOT NULL"); // Add author column to files and links, boldy assuming that the publisher in // charge of updating this site is the author of any existing content items. foreach (array('txp_file', 'txp_link') as $table) { $cols = getThings("DESCRIBE `" . PFX . $table . "`"); if (!in_array('author', $cols)) { safe_alter($table, "\n ADD author varchar(64) NOT NULL DEFAULT '',\n ADD INDEX author_idx (author)"); safe_update($table, "author = '" . doSlash($txp_user) . "'", '1 = 1'); } } // Add indices on author columns. safe_create_index('textpattern', 'AuthorID', 'author_idx'); safe_create_index('txp_image', 'author', 'author_idx');
<?php /* $HeadURL: https://textpattern.googlecode.com/svn/releases/4.5.7/source/textpattern/update/_to_4.3.0.php $ $LastChangedRevision: 4011 $ */ if (!defined('TXP_UPDATE')) { exit("Nothing here. You can't access this file directly."); } // Raw CSS is now the only option safe_delete('txp_prefs', "event='css' and name='edit_raw_css_by_default'"); $rs = getRows('select name,css from `' . PFX . 'txp_css`'); foreach ($rs as $row) { if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $row['css'])) { // Data is still base64 encoded safe_update('txp_css', "css = '" . doSlash(base64_decode($row['css'])) . "'", "name = '" . doSlash($row['name']) . "'"); } } // add column for file title $cols = getThings('describe `' . PFX . 'txp_file`'); if (!in_array('title', $cols)) { safe_alter('txp_file', "ADD `title` VARCHAR( 255 ) NULL AFTER `filename`"); }
function bot_wtc_check_install() { // Check if the bot_wtc table exists if (getThings("Show tables like '" . PFX . "bot_wtc'")) { return true; } return false; }
$txpplugin = getThings('describe `' . PFX . 'txp_plugin`'); if (!in_array('load_order', $txpplugin)) { safe_alter('txp_plugin', "ADD load_order TINYINT UNSIGNED NOT NULL DEFAULT 5"); } # Enable XML-RPC server? if (!safe_field('name', 'txp_prefs', "name = 'enable_xmlrpc_server'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'enable_xmlrpc_server', val = 0, type = 1, event = 'admin', html = 'yesnoradio', position = 130"); } if (!safe_field('name', 'txp_prefs', "name = 'smtp_from'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'smtp_from', val = '', type = 1, event = 'admin', position = 110"); } if (!safe_field('val', 'txp_prefs', "name='author_list_pageby'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'author_list_pageby', val = 25, type = 2"); } # Expiry datetime for articles $txp = getThings('describe `' . PFX . 'textpattern`'); if (!in_array('Expires', $txp)) { safe_alter("textpattern", "add `Expires` datetime NOT NULL default '0000-00-00 00:00:00' after `Posted`"); } $has_expires_idx = 0; $rs = getRows('show index from `' . PFX . 'textpattern`'); foreach ($rs as $row) { if ($row['Key_name'] == 'Expires_idx') { $has_expires_idx = 1; } } if (!$has_expires_idx) { safe_query('alter ignore table `' . PFX . 'textpattern` add index Expires_idx(Expires)'); } # Publish expired articles, or return 410? if (!safe_field('name', 'txp_prefs', "name = 'publish_expired_articles'")) {
function doDiagnostics() { global $prefs, $files, $txpcfg, $event, $step, $theme; extract(get_prefs()); $urlparts = parse_url(hu); $mydomain = $urlparts['host']; $server_software = @$_SERVER['SERVER_SOFTWARE'] || @$_SERVER['HTTP_HOST'] ? @$_SERVER['SERVER_SOFTWARE'] ? @$_SERVER['SERVER_SOFTWARE'] : $_SERVER['HTTP_HOST'] : ''; $is_apache = ($server_software and stristr($server_software, 'Apache')) or is_callable('apache_get_version'); $real_doc_root = isset($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT']) : ''; // ini_get() returns string values passed via php_value as a string, not boolean $is_register_globals = (strcasecmp(ini_get('register_globals'), 'on') === 0 or ini_get('register_globals') === '1'); $fail = array('php_version_4_3_0_required' => (!is_callable('version_compare') or version_compare(PHP_VERSION, '4.3.0', '<')) ? gTxt('php_version_4_3_0_required') : '', 'path_to_site_missing' => !isset($path_to_site) ? gTxt('path_to_site_missing') : '', 'dns_lookup_fails' => @gethostbyname($mydomain) == $mydomain ? gTxt('dns_lookup_fails') . cs . $mydomain : '', 'path_to_site_inacc' => !@is_dir($path_to_site) ? gTxt('path_to_site_inacc') . cs . $path_to_site : '', 'site_trailing_slash' => rtrim($siteurl, '/') != $siteurl ? gTxt('site_trailing_slash') . cs . $path_to_site : '', 'index_inaccessible' => (!@is_file($path_to_site . "/index.php") or !@is_readable($path_to_site . "/index.php")) ? "{$path_to_site}/index.php " . gTxt('is_inaccessible') : '', 'dir_not_writable' => trim((!@is_writable($path_to_site . '/' . $img_dir) ? str_replace('{dirtype}', gTxt('img_dir'), gTxt('dir_not_writable')) . ": {$path_to_site}/{$img_dir}" . n : '') . (!@is_writable($file_base_path) ? str_replace('{dirtype}', gTxt('file_base_path'), gTxt('dir_not_writable')) . ": {$file_base_path}" . n : '') . (!@is_writable($tempdir) ? str_replace('{dirtype}', gTxt('tempdir'), gTxt('dir_not_writable')) . ": {$tempdir}" . n : '')), 'cleanurl_only_apache' => ($permlink_mode != 'messy' and !$is_apache) ? gTxt('cleanurl_only_apache') : '', 'htaccess_missing' => ($permlink_mode != 'messy' and !@is_readable($path_to_site . '/.htaccess')) ? gTxt('htaccess_missing') : '', 'mod_rewrite_missing' => ($permlink_mode != 'messy' and is_callable('apache_get_modules') and !apache_module('mod_rewrite')) ? gTxt('mod_rewrite_missing') : '', 'file_uploads_disabled' => !ini_get('file_uploads') ? gTxt('file_uploads_disabled') : '', 'setup_still_exists' => @is_dir(txpath . DS . 'setup') ? txpath . DS . "setup" . DS . ' ' . gTxt('still_exists') : '', 'no_temp_dir' => empty($tempdir) ? gTxt('no_temp_dir') : '', 'warn_mail_unavailable' => is_disabled('mail') ? gTxt('warn_mail_unavailable') : '', 'warn_register_globals_or_update' => $is_register_globals && (version_compare(phpversion(), '4.4.0', '<=') or version_compare(phpversion(), '5.0.0', '>=') and version_compare(phpversion(), '5.0.5', '<=')) ? gTxt('warn_register_globals_or_update') : ''); if ($permlink_mode != 'messy') { $rs = safe_column("name", "txp_section", "1"); foreach ($rs as $name) { if ($name and @file_exists($path_to_site . '/' . $name)) { $fail['old_placeholder_exists'] = gTxt('old_placeholder') . ": {$path_to_site}/{$name}"; } } } $missing = array(); foreach ($files as $f) { $realpath = realpath(txpath . $f); if (is_readable($realpath)) { $found[] = $realpath; } else { $missing[] = txpath . $f; } } $files = $found; unset($found); if ($missing) { $fail['missing_files'] = gTxt('missing_files') . cs . n . t . join(', ' . n . t, $missing); } foreach ($fail as $k => $v) { if (empty($v)) { unset($fail[$k]); } } # Find the highest revision number $file_revs = $file_md5 = array(); $rev = 0; foreach ($files as $f) { $content = @file_get_contents($f); if ($content !== FALSE) { if (preg_match('/^\\$' . 'LastChangedRevision: (\\d+) \\$/m', $content, $match)) { $file_revs[$f] = $match[1]; if ($match[1] > $rev) { $rev = $match[1]; } } $file_md5[$f] = md5(str_replace('$' . 'HeadURL: http:', '$' . 'HeadURL: https:', str_replace("\r\n", "\n", $content))); } } # Check revs & md5 against stable release, if possible $dev_files = $old_files = $modified_files = array(); if ($cs = @file(txpath . '/checksums.txt')) { foreach ($cs as $c) { if (preg_match('@^(\\S+): r?(\\S+) \\((.*)\\)$@', trim($c), $m)) { list(, $file, $r, $md5) = $m; $file = realpath(txpath . $file); if (!empty($file_revs[$file]) and $r and $file_revs[$file] < $r) { $old_files[] = $file; } elseif (!empty($file_revs[$file]) and $r and $file_revs[$file] > $r) { $dev_files[] = $file; } elseif (!empty($file_md5[$file]) and $file_md5[$file] != $md5) { $modified_files[] = $file; } } } } # files that haven't been updated if ($old_files) { $fail['old_files'] = gTxt('old_files') . cs . n . t . join(', ' . n . t, $old_files); } # files that don't match their checksums if ($modified_files) { $fail['modified_files'] = gTxt('modified_files') . cs . n . t . join(', ' . n . t, $modified_files); } # running development code in live mode is not recommended if ($dev_files and $production_status == 'live') { $fail['dev_version_live'] = gTxt('dev_version_live') . cs . n . t . join(', ' . n . t, $dev_files); } # anything might break if arbitrary functions are disabled if (ini_get('disable_functions')) { $disabled_funcs = array_map('trim', explode(',', ini_get('disable_functions'))); # commonly disabled functions that we don't need $disabled_funcs = array_diff($disabled_funcs, array('imagefilltoborder', 'exec', 'system', 'dl', 'passthru', 'chown', 'shell_exec', 'popen', 'proc_open')); if ($disabled_funcs) { $fail['some_php_functions_disabled'] = gTxt('some_php_functions_disabled') . cs . join(', ', $disabled_funcs); } } # not sure about this one #if (strncmp(php_sapi_name(), 'cgi', 3) == 0 and ini_get('cgi.rfc2616_headers')) # $fail['cgi_header_config'] = gTxt('cgi_header_config'); $guess_site_url = $_SERVER['HTTP_HOST'] . preg_replace('#[/\\\\]$#', '', dirname(dirname($_SERVER['SCRIPT_NAME']))); if ($siteurl and strip_prefix($siteurl, 'www.') != strip_prefix($guess_site_url, 'www.')) { $fail['site_url_mismatch'] = gTxt('site_url_mismatch') . cs . $guess_site_url; } # test clean URL server vars if (hu) { if (ini_get('allow_url_fopen') and $permlink_mode != 'messy') { $s = md5(uniqid(rand(), true)); ini_set('default_socket_timeout', 10); $pretext_data = @file(hu . $s . '/?txpcleantest=1'); if ($pretext_data) { $pretext_req = trim(@$pretext_data[0]); if ($pretext_req != md5('/' . $s . '/?txpcleantest=1')) { $fail['clean_url_data_failed'] = gTxt('clean_url_data_failed') . cs . htmlspecialchars($pretext_req); } } else { $fail['clean_url_test_failed'] = gTxt('clean_url_test_failed'); } } } if ($tables = list_txp_tables()) { $table_errors = check_tables($tables); if ($table_errors) { $fail['mysql_table_errors'] = gTxt('mysql_table_errors') . cs . n . t . join(', ' . n . t, $table_errors); } } $active_plugins = array(); if ($rows = safe_rows('name, version, code_md5, md5(code) as md5', 'txp_plugin', 'status > 0')) { foreach ($rows as $row) { $n = $row['name'] . '-' . $row['version']; if (strtolower($row['md5']) != strtolower($row['code_md5'])) { $n .= 'm'; } $active_plugins[] = $n; } } $theme_manifest = $theme->manifest(); // check GD info if (function_exists('gd_info')) { $gd_info = gd_info(); $gd_support = array(); if ($gd_info['GIF Create Support']) { $gd_support[] = 'GIF'; } // Aside: In PHP 5.3, they chose to add a previously unemployed capital "E" to the array key. if (!empty($gd_info['JPEG Support']) || !empty($gd_info['JPG Support'])) { $gd_support[] = 'JPG'; } if ($gd_info['PNG Support']) { $gd_support[] = 'PNG'; } if ($gd_support) { $gd_support = join(', ', $gd_support); } else { $gd_support = gTxt('none'); } $gd = gTxt('gd_info', array('{version}' => $gd_info['GD Version'], '{supported}' => $gd_support)); } else { $gd = gTxt('gd_unavailable'); } if (realpath($prefs['tempdir']) == realpath($prefs['plugin_cache_dir'])) { $fail['tmp_plugin_paths_match'] = gTxt('tmp_plugin_paths_match'); } echo pagetop(gTxt('tab_diagnostics'), ''), '<div id="' . $event . '_container" class="txp-container txp-list">', '<div id="pre_flight_check">', startTable('list', '', 'list', '', '510px'), '<thead>', tr(td(hed(gTxt('preflight_check'), 2))), '</thead>'; echo '<tbody>'; if ($fail) { foreach ($fail as $help => $message) { echo tr(tda(nl2br($message) . sp . popHelp($help), ' class="not-ok"')); } } else { echo tr(tda(gTxt('all_checks_passed'), ' class="ok"')); } echo '</tbody>', endTable(), '</div>'; echo '<div id="diagnostics">', startTable('list', '', 'list'), '<thead>', tr(td(hed(gTxt('diagnostic_info'), 2))), '</thead>'; $fmt_date = '%Y-%m-%d %H:%M:%S'; $out = array('<textarea cols="78" rows="18" readonly="readonly" style="width: 500px; height: 300px;">', gTxt('txp_version') . cs . txp_version . ' (' . ($rev ? 'r' . $rev : 'unknown revision') . ')' . n, gTxt('last_update') . cs . gmstrftime($fmt_date, $dbupdatetime) . '/' . gmstrftime($fmt_date, @filemtime(txpath . '/update/_update.php')) . n, gTxt('document_root') . cs . @$_SERVER['DOCUMENT_ROOT'] . ($real_doc_root != @$_SERVER['DOCUMENT_ROOT'] ? ' (' . $real_doc_root . ')' : '') . n, '$path_to_site' . cs . $path_to_site . n, gTxt('txp_path') . cs . txpath . n, gTxt('permlink_mode') . cs . $permlink_mode . n, ini_get('open_basedir') ? 'open_basedir: ' . ini_get('open_basedir') . n : '', ini_get('upload_tmp_dir') ? 'upload_tmp_dir: ' . ini_get('upload_tmp_dir') . n : '', gTxt('tempdir') . cs . $tempdir . n, gTxt('web_domain') . cs . $siteurl . n, gTxt('php_version') . cs . phpversion() . n, $is_register_globals ? gTxt('register_globals') . cs . $is_register_globals . n : '', gTxt('gd_library') . cs . $gd . n, gTxt('server') . ' TZ: ' . (timezone::is_supported() ? date_default_timezone_get() : (getenv('TZ') ? getenv('TZ') : '-')) . n, gTxt('server_time') . cs . strftime('%Y-%m-%d %H:%M:%S') . n, strip_tags(gTxt('is_dst')) . cs . $is_dst . n, strip_tags(gTxt('auto_dst')) . cs . $auto_dst . n, strip_tags(gTxt('gmtoffset')) . cs . $timezone_key . sp . "({$gmtoffset})" . n, 'MySQL' . cs . mysql_get_server_info() . n, gTxt('locale') . cs . $locale . n, isset($_SERVER['SERVER_SOFTWARE']) ? gTxt('server') . cs . $_SERVER['SERVER_SOFTWARE'] . n : '', is_callable('apache_get_version') ? gTxt('apache_version') . cs . apache_get_version() . n : '', gTxt('php_sapi_mode') . cs . PHP_SAPI . n, gTxt('rfc2616_headers') . cs . ini_get('cgi.rfc2616_headers') . n, gTxt('os_version') . cs . php_uname('s') . ' ' . php_uname('r') . n, $active_plugins ? gTxt('active_plugins') . cs . join(', ', $active_plugins) . n : '', gTxt('theme_name') . cs . $theme_name . sp . $theme_manifest['version'] . n, $fail ? n . gTxt('preflight_check') . cs . n . ln . join("\n", $fail) . n . ln : '', is_readable($path_to_site . '/.htaccess') ? n . gTxt('htaccess_contents') . cs . n . ln . htmlspecialchars(join('', file($path_to_site . '/.htaccess'))) . n . ln : ''); if ($step == 'high') { $mysql_client_encoding = is_callable('mysql_client_encoding') ? mysql_client_encoding() : '-'; $out[] = n . 'Charset (default/config)' . cs . $mysql_client_encoding . '/' . @$txpcfg['dbcharset'] . n; $result = safe_query("SHOW variables like 'character_se%'"); while ($row = mysql_fetch_row($result)) { $out[] = $row[0] . cs . $row[1] . n; if ($row[0] == 'character_set_connection') { $conn_char = $row[1]; } } $table_names = array(PFX . 'textpattern'); $result = safe_query("SHOW TABLES LIKE '" . PFX . "txp\\_%'"); while ($row = mysql_fetch_row($result)) { $table_names[] = $row[0]; } $table_msg = array(); foreach ($table_names as $table) { $ctr = safe_query("SHOW CREATE TABLE " . $table . ""); if (!$ctr) { unset($table_names[$table]); continue; } $ctcharset = preg_replace('#^CREATE TABLE.*SET=([^ ]+)[^)]*$#is', '\\1', mysql_result($ctr, 0, 'Create Table')); if (isset($conn_char) && !stristr($ctcharset, 'CREATE') && $conn_char != $ctcharset) { $table_msg[] = "{$table} is {$ctcharset}"; } $ctr = safe_query("CHECK TABLE " . $table); if (in_array(mysql_result($ctr, 0, 'Msg_type'), array('error', 'warning'))) { $table_msg[] = $table . cs . mysql_result($ctr, 0, 'Msg_Text'); } } if ($table_msg == array()) { $table_msg = count($table_names) < 17 ? array('-') : array('OK'); } $out[] = count($table_names) . ' Tables' . cs . implode(', ', $table_msg) . n; $cf = preg_grep('/^custom_\\d+/', getThings('describe `' . PFX . 'textpattern`')); $out[] = n . get_pref('max_custom_fields', 10) . sp . gTxt('custom') . cs . implode(', ', $cf) . sp . '(' . count($cf) . ')' . n; $extns = get_loaded_extensions(); $extv = array(); foreach ($extns as $e) { $extv[] = $e . (phpversion($e) ? '/' . phpversion($e) : ''); } $out[] = n . gTxt('php_extensions') . cs . join(', ', $extv) . n; if (is_callable('apache_get_modules')) { $out[] = n . gTxt('apache_modules') . cs . join(', ', apache_get_modules()) . n; } if (@is_array($pretext_data) and count($pretext_data) > 1) { $out[] = n . gTxt('pretext_data') . cs . htmlspecialchars(join('', array_slice($pretext_data, 1, 20))) . n; } $out[] = n; foreach ($files as $f) { $checksum = isset($file_md5[$f]) ? $file_md5[$f] : gTxt('unknown'); $revision = isset($file_revs[$f]) ? 'r' . $file_revs[$f] : gTxt('unknown'); $out[] = "{$f}" . cs . n . t . $revision . ' (' . $checksum . ')' . n; } $out[] = n . ln; } $out[] = callback_event('diag_results', $step) . n; $out[] = '</textarea>' . br; $dets = array('low' => gTxt('low'), 'high' => gTxt('high')); $out[] = form(eInput('diag') . n . gTxt('detail') . cs . selectInput('step', $dets, $step, 0, 1)); echo '<tbody>', tr(td(join('', $out))), '</tbody>', endTable(), '</div>', '</div>'; }
<?php /* $HeadURL: https://textpattern.googlecode.com/svn/releases/4.4.0/source/textpattern/update/_to_4.0.5.php $ $LastChangedRevision: 2894 $ */ if (!defined('TXP_UPDATE')) { exit("Nothing here. You can't access this file directly."); } safe_alter('txp_lang', 'DELAY_KEY_WRITE = 0'); if (!safe_field('name', 'txp_prefs', "name = 'lastmod_keepalive'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'lastmod_keepalive', val = '0', type = '1', html='yesnoradio'"); } // new Status field for file downloads $txpfile = getThings('describe `' . PFX . 'txp_file`'); if (!in_array('status', $txpfile)) { safe_alter('txp_file', "add status smallint NOT NULL DEFAULT '4'"); } $update_files = 0; if (!in_array('modified', $txpfile)) { safe_alter('txp_file', "add modified datetime NOT NULL default '0000-00-00 00:00:00'"); $update_files = 1; } if (!in_array('created', $txpfile)) { safe_alter('txp_file', "add created datetime NOT NULL default '0000-00-00 00:00:00'"); $update_files = 1; } if (!in_array('size', $txpfile)) { safe_alter('txp_file', "add size bigint"); $update_files = 1; }
function check_install() { // Check if the hak_tinymce table already exists if (getThings("Show tables like '" . PFX . "txp_hak_tinymce'")) { // if it does check if we need to upgrade $pluginversion = safe_field('version', 'txp_plugin', "name = 'hak_tinymce'"); $prefs = hak_tinymce::getPrefs(); $version = array_key_exists('version', $prefs) ? $prefs['version'] : "0.0"; if (!empty($version) && $version != $pluginversion) { // if the versions don't match send off to upgrade. hak_tinymce::upgrade($version); } return true; } return false; }
// publisher's email address if (!safe_field('name', 'txp_prefs', "name = 'publisher_email'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'publisher_email', val = '', type = 1, event = 'admin', position = 115"); } // goodbye raw ?php support if (safe_field('name', 'txp_prefs', "name = 'allow_raw_php_scripting'")) { safe_delete('txp_prefs', "name = 'allow_raw_php_scripting'"); } safe_alter('txp_users', "MODIFY RealName VARCHAR(255) NOT NULL default '', MODIFY email VARCHAR(254) NOT NULL default ''"); // Remove any setup strings from lang table safe_delete('txp_lang', "event='setup'"); $has_idx = 0; $rs = getRows('show index from `' . PFX . 'textpattern`'); foreach ($rs as $row) { if ($row['Key_name'] == 'url_title_idx') { $has_idx = 1; } } if (!$has_idx) { safe_query('alter ignore table `' . PFX . 'textpattern` add index url_title_idx(`url_title`)'); } // Remove is_default from txp_section table and make it a preference if (!safe_field('name', 'txp_prefs', "name = 'default_section'")) { $current_default_section = safe_field('name', 'txp_section', 'is_default=1'); safe_insert('txp_prefs', "prefs_id = 1, name = 'default_section', val = '" . doSlash($current_default_section) . "', type = '2', event = 'section', html = 'text_input', position = '0'"); } $cols = getThings('describe `' . PFX . 'txp_section`'); if (in_array('is_default', $cols)) { safe_alter('txp_section', "DROP `is_default`"); } safe_alter('txp_css', 'MODIFY css MEDIUMTEXT NOT NULL');
// support for per-user private prefs $cols = getThings('describe `' . PFX . 'txp_prefs`'); if (!in_array('user_name', $cols)) { safe_alter('txp_prefs', "ADD `user_name` varchar(64) NOT NULL default '', DROP INDEX `prefs_idx`, ADD UNIQUE `prefs_idx` (`prefs_id`, `name`, `user_name`), ADD INDEX `user_name` (`user_name`)"); } // remove a few global prefs in favour of future private ones safe_delete('txp_prefs', "user_name = '' AND name in ('article_list_pageby', 'author_list_pageby', 'comment_list_pageby', 'file_list_pageby', 'image_list_pageby', 'link_list_pageby', 'log_list_pageby')"); // use dedicated prefs function for setting custom fields safe_update('txp_prefs', "html='custom_set'", "name IN ('custom_1_set', 'custom_2_set', 'custom_3_set', 'custom_4_set', 'custom_5_set', 'custom_6_set', 'custom_7_set', 'custom_8_set', 'custom_9_set', 'custom_10_set') AND html='text_input'"); // send comments prefs safe_update('txp_prefs', "html='commentsendmail'", "name='comments_sendmail' AND html='yesnoradio'"); // default event admin pref if (!safe_field('name', 'txp_prefs', "name = 'default_event'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'default_event', val = 'article', type = '1', event = 'admin', html = 'default_event', position = '150'"); } // add columns for thumbnail dimensions $cols = getThings('describe `' . PFX . 'txp_image`'); if (!in_array('thumb_w', $cols)) { safe_alter('txp_image', "ADD `thumb_w` int(8) NOT NULL default 0, ADD `thumb_h` int(8) NOT NULL default 0"); } // plugin flags $cols = getThings('describe `' . PFX . 'txp_plugin`'); if (!in_array('flags', $cols)) { safe_alter('txp_plugin', "ADD flags SMALLINT UNSIGNED NOT NULL DEFAULT 0"); } // default theme if (!safe_field('name', 'txp_prefs', "name = 'theme_name'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'theme_name', val = 'classic', type = '1', event = 'admin', html = 'themename', position = '160'"); } safe_alter('txp_plugin', 'CHANGE code code MEDIUMTEXT NOT NULL, CHANGE code_restore code_restore MEDIUMTEXT NOT NULL'); safe_alter('txp_prefs', 'CHANGE val val TEXT NOT NULL');