0
- * check_input() - Checks input is of correct type
0
- * Always returns true when WP_DEBUG is true, to allow for easier debugging
0
- * in the development environment while handling erroneous input more
0
- * robustly in the production environment.
0
- * @see http://uk3.php.net/manual/en/function.gettype.php
0
-function check_input($input, $type, $name = '') {
0
- if ( WP_DEBUG === true )
0
- if ( $type == 'object' && strlen($name) > 0 )
0
- return is_a($input, $name);
0
- return call_user_func("is_$type", $input);
0
- * detectWPMU() - Detects whether WordPress Multi-User is in use.
0
-function detectWPMU() {
0
- return function_exists('is_site_admin');
0
* detectWPMUadmin() - Detect whether the current user is a WPMU site administrator.
0
@@ -69,72 +35,13 @@ function can_get_remote() {
0
function cache_is_writable($file = false) {
0
$cachefile = TARSKICACHE . '/' . $file;
0
- if(is_writable($cachefile) || (is_writable(TARSKICACHE) && !file_exists($cachefile)))
0
- * version_to_integer() - Turns Tarski version numbers into integers.
0
- * @param string $version
0
-function version_to_integer($version) {
0
- // Remove all non-numeric characters
0
- $version = preg_replace('/\D/', '', $version);
0
- if($version && strlen($version) >= 1) {
0
- // Make the string exactly three characters (numerals) long
0
- if(strlen($version) < 2) {
0
- $version_int = $version . '00';
0
- } elseif(strlen($version) < 3) {
0
- $version_int = $version . '0';
0
- } elseif(strlen($version) == 3) {
0
- $version_int = $version;
0
- } elseif(strlen($version) > 3) {
0
- $version_int = substr($version, 0, 3);
0
- return (int) $version_int;
0
- * version_newer_than() - Returns true if current version is greater than given version.
0
- * @param mixed $version
0
-function version_newer_than($version) {
0
- $version = version_to_integer($version);
0
- $current = version_to_integer(theme_version('current'));
0
- if($version && $current) {
0
- return (bool) ($current > $version);
0
- * is_valid_tarski_style() - Checks whether a given file name is a valid Tarski stylesheet name.
0
- * It must be a valid CSS identifier, followed by the .css file extension,
0
- * and it cannot have a name that is already taken by Tarski's CSS namepsace.
0
-function is_valid_tarski_style($file) {
0
- !preg_match('/^\.+$/', $file)
0
- && preg_match('/^[A-Za-z][A-Za-z0-9\-]*.css$/', $file)
0
- && !preg_match('/^janus.css$|^centre.css$|^rtl.css$/', $file)
0
+ if ( file_exists($cachefile) )
0
+ return is_writable($cachefile);
0
+ return is_writable(TARSKICACHE);
0
@@ -166,9 +73,8 @@ function ready_to_delete_options($del_time) {
0
function tarski_upgrade_needed() {
0
if ( get_option('tarski_options') ) {
0
- $version = get_tarski_option('installed');
0
- $current = theme_version('current');
0
- return (bool) empty($version) || (version_to_integer($version) < version_to_integer($current));
0
+ $installed = get_tarski_option('installed');
0
+ return empty($installed) || version_compare($installed, theme_version('current')) === -1;
0
@@ -188,6 +94,86 @@ function tarski_upgrade_and_flush_options() {
0
+ * tarski_upgrade_special() - Upgrades Tarski options special cases.
0
+ * @see tarski_upgrade()
0
+ * @param object $options
0
+ * @param object $defaults
0
+function tarski_upgrade_special($options, $defaults) {
0
+ if ( tarski_should_show_authors() )
0
+ $options->show_authors = true;
0
+ if ( empty($options->centred_theme) && isset($options->centered_theme) )
0
+ $options->centred_theme = true;
0
+ if ( empty($options->show_categories) && isset($options->hide_categories) && ($options->hide_categories == 1) )
0
+ $options->show_categories = false;
0
+ * tarski_upgrade_widgets() - Upgrades old Tarski sidebar options to use widgets.
0
+ * @see tarski_upgrade()
0
+ * @param object $options
0
+ * @param object $defaults
0
+function tarski_upgrade_widgets($options, $defaults) {
0
+ $widgets = wp_get_sidebars_widgets(false);
0
+ $widget_text = get_option('widget_text');
0
+ // Change sidebar names and initialise new sidebars
0
+ if ( empty($widgets['sidebar-main']) && !empty($widgets['sidebar-1']) )
0
+ $widgets['sidebar-main'] = $widgets['sidebar-1'];
0
+ if ( empty($widgets['footer-sidebar']) && !empty($widgets['sidebar-2']) )
0
+ $widgets['footer-sidebar'] = $widgets['sidebar-2'];
0
+ // Main footer widgets
0
+ if ( empty($widgets['footer-main']) ) {
0
+ $widgets['footer-main'] = array();
0
+ if ( strlen(trim($options->blurb)) ) {
0
+ $widget_text[] = array( 'title' => '', 'text' => $options->blurb );
0
+ $wt_num = (int) end(array_keys($widget_text));
0
+ $widgets['footer-main'][] = "text-$wt_num";
0
+ if ( $options->footer_recent )
0
+ $widgets['footer-main'][] = 'recent-articles';
0
+ if ( empty($widgets['sidebar-main']) && $options->sidebar_type == 'tarski' ) {
0
+ $widgets['sidebar-main'] = array();
0
+ // Custom text -> text widget
0
+ if( strlen(trim($options->sidebar_custom)) ) {
0
+ $widget_text[] = array( 'title' => '', 'text' => $options->sidebar_custom );
0
+ $wt_num = (int) end(array_keys($widget_text));
0
+ $widgets['sidebar-main'][] = "text-$wt_num";
0
+ // Pages list -> pages widget
0
+ if($options->sidebar_pages)
0
+ $widgets['sidebar-main'][] = 'pages';
0
+ // Links list -> links widget
0
+ if($options->sidebar_links)
0
+ $widgets['sidebar-main'][] = 'links';
0
+ update_option('widget_text', $widget_text);
0
+ wp_set_sidebars_widgets($widgets);
0
* function tarski_upgrade() - Upgrades Tarski's options where appropriate.
0
* Tarski preferences sometimes change between versions, and need to
0
@@ -205,95 +191,14 @@ function tarski_upgrade() {
0
$defaults = new Options;
0
$defaults->tarski_options_defaults();
0
- // Handle special cases first
0
// Update the options version so we don't run this code more than once
0
- $old_version = $options->installed;
0
$options->installed = theme_version('current');
0
- if (version_to_integer($old_version) < 210) {
0
- // If they had hidden the sidebar previously for non-index pages, preserve that setting
0
- empty($options->sidebar_pp_type)
0
- && isset($options->sidebar_onlyhome)
0
- && $options->sidebar_onlyhome == 1
0
- $options->sidebar_pp_type = 'none';
0
- // If there's more than one author, show authors
0
- if(tarski_should_show_authors()) {
0
- $options->show_authors = true;
0
- // If categories are hidden, respect that option
0
- empty($options->show_categories)
0
- && isset($options->hide_categories)
0
- && ($options->hide_categories == 1)
0
- $options->show_categories = false;
0
- // Change American English to British English, sorry Chris
0
- if(empty($options->centred_theme) && isset($options->centered_theme)) {
0
- $options->centred_theme = true;
0
- // Upgrade old display options to use widgets instead
0
- // Get current widgets settings
0
- $widgets = wp_get_sidebars_widgets();
0
- $widget_text = get_option('widget_text');
0
- // Change sidebar names and initialise new sidebars
0
- $widgets['sidebar-main'] = $widgets['sidebar-1'];
0
- $widgets['footer-sidebar'] = $widgets['sidebar-2'];
0
- $widgets['footer-main'] = array();
0
- if ( strlen(trim($options->blurb)) ) {
0
- $widget_text[] = array( 'title' => '', 'text' => $options->blurb );
0
- $wt_num = (int) end(array_keys($widget_text));
0
- $widgets['footer-main'][] = "text-$wt_num";
0
- if ( $options->footer_recent ) {
0
- $widgets['footer-main'][] = 'recent-articles';
0
- // Footer sidebar default
0
- if ( empty($widgets['footer-sidebar']) ) {
0
- $widgets['footer-sidebar'] = array('search');
0
- if ( $options->sidebar_type == 'tarski' ) {
0
- if ( empty($widgets['sidebar-main']) )
0
- $widgets['sidebar-main'] = array();
0
- // Custom text -> text widget
0
- if( strlen(trim($options->sidebar_custom)) ) {
0
- $widget_text[] = array( 'title' => '', 'text' => $options->sidebar_custom );
0
- $wt_num = (int) end(array_keys($widget_text));
0
- $widgets['sidebar-main'][] = "text-$wt_num";
0
- // Pages list -> pages widget
0
- if($options->sidebar_pages) {
0
- $widgets['sidebar-main'][] = 'pages';
0
- // Links list -> links widget
0
- if($options->sidebar_links) {
0
- $widgets['sidebar-main'][] = 'links';
0
+ // Handle special cases first
0
+ tarski_upgrade_special($options, $defaults);
0
- // Unset defunct values
0
- unset($widgets['sidebar-1'], $widgets['sidebar-2']);
0
+ // Upgrade old display options to use widgets instead
0
+ tarski_upgrade_widgets($options, $defaults);
0
// Conform our options to the expected values, types, and defaults
0
foreach($options as $name => $value) {
0
@@ -311,20 +216,17 @@ function tarski_upgrade() {
0
$options->$name = array($options->$name);
0
- // Save our upgraded options
0
- if (version_to_integer($old_version) < 210) {
0
- update_option('widget_text', $widget_text);
0
- wp_set_sidebars_widgets($widgets);
0
- update_option('tarski_options', serialize($options));
0
+ // Save our upgraded options
0
+ update_option('tarski_options', $options);
0
* tarski_messages() - Adds messages about Tarski to the WordPress admin panel.
0
+ * @hook filter tarski_messages
0
+ * Filter the messages Tarski prints to the WordPress admin panel.
0
function tarski_messages() {
0
$messages = apply_filters('tarski_messages', array());
0
@@ -349,11 +251,13 @@ function tarski_addmenu() {
0
function tarski_admin() {
0
- save_tarski_options();
0
- tarski_update_notifier('options_page');
0
- $widgets_link = get_bloginfo('wpurl') . '/wp-admin/widgets.php';
0
- $tarski_options_link = get_bloginfo('wpurl') . '/wp-admin/themes.php?page=tarski-options';
0
- include(TARSKIDISPLAY . '/options_page.php');
0
+ if (current_user_can('edit_themes')) {
0
+ save_tarski_options();
0
+ tarski_update_notifier('options_page');
0
+ $widgets_link = admin_url('widgets.php');
0
+ $tarski_options_link = admin_url('themes.php?page=tarski-options');
0
+ include(TARSKIDISPLAY . '/options_page.php');
0
@@ -379,7 +283,11 @@ function tarski_admin_header_style() { ?>
0
function tarski_admin_style() {
0
- echo '<link rel="stylesheet" href="' . get_bloginfo('template_directory'). '/library/css/admin.css" type="text/css" media="all" />';
0
+ get_bloginfo('template_directory') . '/library/css/admin.css',
0
+ array(), false, 'screen'
0
@@ -388,7 +296,11 @@ function tarski_admin_style() {
0
function tarski_inject_styles() {
0
- echo '<link rel="stylesheet" href="' . get_bloginfo('template_directory'). '/library/css/options.css" type="text/css" media="screen" />';
0
+ get_bloginfo('template_directory') . '/library/css/options.css',
0
+ array(), false, 'screen'
0
@@ -397,23 +309,24 @@ function tarski_inject_styles() {
0
function tarski_inject_scripts() {
0
- $js_dir = get_bloginfo('template_directory') . '/library/js';
0
- wp_enqueue_script('crir', $js_dir . '/crir.js');
0
+ $js_dir = get_bloginfo('template_directory') . '/app/js';
0
+ wp_enqueue_script('page_select', "$js_dir/page_select.js");
0
+ wp_enqueue_script('crir', "$js_dir/crir.js");
0
- * tarski_count_authors() - Returns the number of authors
on a site.
0
+ * tarski_count_authors() - Returns the number of authors
who have published posts.
0
- * This function returns the number of users on a site with a user
0
- * level of greater than 1, i.e. Authors, Editors and Administrators.
0
+ * This function returns the number of author ids associated with published posts.
0
function tarski_count_authors() {
0
- $count_users = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->usermeta WHERE `meta_key` = '" . $wpdb->prefix . "user_level' AND `meta_value` > 1");
0
- return (int) $count_users;
0
+ return count($wpdb->get_col($wpdb->prepare(
0
+ "SELECT post_author, COUNT(DISTINCT post_author) FROM $wpdb->posts WHERE post_status = 'publish' GROUP BY post_author"
0
@@ -423,6 +336,8 @@ function tarski_count_authors() {
0
* @see tarski_count_authors()
0
+ * @hook filter tarski_show_authors
0
+ * Allows other components to decide whether or not Tarski should show authors.
0
function tarski_should_show_authors() {
0
$show_authors = tarski_count_authors() > 1;
0
@@ -443,4 +358,98 @@ function tarski_resave_show_authors() {
0
+ * tarski_navbar_select() - Generates a list of checkboxes for the site's pages.
0
+ * Walks the tree of pages and generates nested ordered lists of pages, with
0
+ * corresponding checkboxes to allow the selection of pages for the navbar.
0
+ * @param array $selected
0
+function tarski_navbar_select($pages) {
0
+ $nav_pages = explode(',', get_tarski_option('nav_pages'));
0
+ $collapsed_pages = explode(',', get_tarski_option('collapsed_pages'));
0
+ $walker = new WalkerPageSelect($nav_pages, $collapsed_pages);
0
+ if ( !empty($pages) ) {
0
+ $return = "<ol id=\"navbar-select\">\n" . $walker->walk($pages, 0, 0, array()) . "\n</ol>\n\n";
0
+ * tarski_update_notifier() - Performs version checks and outputs the update notifier.
0
+ * Creates a new Version object, checks the latest and current
0
+ * versions, and lets the user know whether or not their version
0
+ * of Tarski needs updating. The way it displays varies slightly
0
+ * between the WordPress Dashboard and the Tarski Options page.
0
+ * @param string $location
0
+function tarski_update_notifier($messages) {
0
+ if ( !is_array($messages) )
0
+ $version = new Version;
0
+ $version->current_version_number();
0
+ $svn_link = 'http://tarskitheme.com/help/updates/svn/';
0
+ // Update checking only performed when remote files can be accessed
0
+ if ( can_get_remote() ) {
0
+ // Only performs the update check when notification is enabled
0
+ if ( get_tarski_option('update_notification') ) {
0
+ $version->latest_version_number();
0
+ $version->latest_version_link();
0
+ $version->version_status();
0
+ if ( $version->status == 'older' ) {
0
+ $messages[] = sprintf(
0
+ __('A new version of the Tarski theme, version %1$s %2$s. Your installed version is %3$s.','tarski'),
0
+ "<strong>$version->latest</strong>",
0
+ '<a href="' . $version->latest_link . '">' . __('is now available','tarski') . '</a>',
0
+ "<strong>$version->current</strong>"
0
+ } elseif ( $plugin_page == 'tarski-options' ) {
0
+ switch($version->status) {
0
+ $messages[] = sprintf(
0
+ __('Your version of Tarski (%s) is up to date.','tarski'),
0
+ "<strong>$version->current</strong>"
0
+ $messages[] = sprintf(
0
+ __('You appear to be running a development version of Tarski (%1$s). Please ensure you %2$s.','tarski'),
0
+ "<strong>$version->current</strong>",
0
+ "<a href=\"$svn_link\">" . __('stay updated','tarski') . '</a>'
0
+ $messages[] = sprintf(
0
+ __('No connection to update server. Your installed version is %s.','tarski'),
0
+ "<strong>$version->current</strong>"
0
+ } elseif ( $plugin_page == 'tarski-options' ) {
0
+ $messages[] = sprintf(
0
+ __('Update notification for Tarski is disabled. Your installed version is %s.','tarski'),
0
+ "<strong>$version->current</strong>"
0
\ No newline at end of file