. */ // Prevent direct access to the plugin if (!defined('ABSPATH')) { exit(); } // Version number, may be used to update things in the future global $asideshop_version; $asideshop_version = '1.0.8'; // Domain for I18N global $asideshop_domain; $asideshop_domain = 'asideshop'; // Variable lets us know whether the loop has been ended. global $asideshop_loop_ended; $asideshop_loop_ended = FALSE; // Variable which permits one ob_end_clean() for every ob_start(). Without it other plugins which use ob_start() break AsideShop. global $asideshop_ob_started; $asideshop_ob_started = 0; // Template tags, used in templates global $asideshop_patterns; $asideshop_patterns = array( "%post_id%" => 'get_the_ID()', "%post_title%" => '$post->post_title', "%post_content%" => 'get_the_content(\'\')', "%post_content_filtered%" => 'apply_filters(\'the_content\', get_the_content(\'\'))', "%post_excerpt%" => '$post->post_excerpt', "%post_excerpt_filtered%" => 'apply_filters(\'get_the_excerpt\', $post->post_excerpt)', "%post_permalink%" => 'get_permalink()', "%post_date%" => 'the_date(\'\', \'\', \'\', FALSE)', "%post_date_regular%" => 'get_the_time(get_option(\'date_format\'))', "%post_time%" => 'get_the_time()', "%post_author%" => 'get_the_author()', "%post_categories%" => 'get_the_category_list(\', \')', "%post_tags%" => '((float)$wp_version >= (float)"2.3" ? get_the_term_list(0, \'post_tag\', \'\', \', \') : \'\') ', "%comments_url%" => '($post->comment_count == 0) ? get_permalink() . \'#respond\' : get_comments_link()', "%comments_count%" => '$post->comment_count', "%trackback_url%" => 'trackback_url(FALSE)', ); // Options where to display aside posts global $asideshop_show_on_array; $asideshop_show_on_array = array('front_page' => 1, 'category_view' => 0, 'tag_view' => 0, 'archive_view' => 0, 'date_view' => 0, 'author_view' => 0, 'search_view' => 1); /** // This plugin uses these options created upon plugin installation. $as_options = array( 'enabled' => '', // 0 - disabled || 1 - enabled || 2 - testing 'version' => '', // string (e.g. 1.0) 'show_asides' => array(), // array(category_id => 1) 'templates' => array( array( 'title' => '', // string 'content' => '', // string ), ), 'show_asides_on' => array( 'front_page' => 1, // integer 'category_view' => 0, // integer 'tag_view' => 0, // integer 'archive_view' => 0, // integer 'date_view' => 0, // integer 'author_view' => 0, // integer 'search_view' => 1, // integer ), 'category_to_template' => array( '' => '' // array(category_id => template_id) ), ); */ /** * asideshop_install() - Install plugin * * @global string $asideshop_version * @global string $asideshop_show_on_array * @return void */ function asideshop_install() { global $asideshop_version, $asideshop_show_on_array; add_option('asideshop_options', array('enabled' => 0, 'version' => $asideshop_version, 'show_asides' => array(), 'templates' => array(), 'category_to_template' => array(), 'show_asides_on' => $asideshop_show_on_array)); } /** * asideshop_uninstall() - Uninstall plugin and remove all the options * * @return void */ function asideshop_uninstall() { delete_option('asideshop_options'); } /** * asideshop_create_options_page() - Initialize options page * * @return void */ function asideshop_create_options_page() { add_options_page('AsideShop', 'AsideShop', 9, basename(__FILE__), 'asideshop_conf'); } /** * $asideshop_has_loop_ended() - Check whether we are in The Loop * * @global bool $asideshop_loop_ended */ function asideshop_has_loop_ended() { global $asideshop_loop_ended; if ($asideshop_loop_ended === TRUE) { return TRUE; } return FALSE; } /** * asideshop_is_enabled() - Check whether plugin is enabled * * @return bool */ function asideshop_is_enabled() { $asideshop_options = get_option('asideshop_options'); if ((asideshop_has_loop_ended() === FALSE && $asideshop_options['enabled'] == 1) || ($asideshop_options['enabled'] == 2 && current_user_can('activate_plugins'))) { return TRUE; } return FALSE; } /** * asideshop_is_displayable() - Check whether asides should be displayed * * @global array $asideshop_version * @return bool */ function asideshop_is_displayable() { global $asideshop_version; $asideshop_options = get_option('asideshop_options'); if (!array_key_exists('show_asides_on', $asideshop_options)) { return asideshop_is_frontpage(); } else { if ($asideshop_options['show_asides_on']['front_page'] == 1 && asideshop_is_frontpage()) { return TRUE; } else if ($asideshop_options['show_asides_on']['search_view'] == 1 && is_search()) { return TRUE; } else if ($asideshop_options['show_asides_on']['archive_view'] == 1 && is_archive()) { return TRUE; } else if ($asideshop_options['show_asides_on']['category_view'] == 1 && is_category()) { return TRUE; } else if (function_exists('is_tag') && $asideshop_options['show_asides_on']['tag_view'] == 1 && is_tag()) { return TRUE; } else if ($asideshop_options['show_asides_on']['date_view'] == 1 && is_date()) { return TRUE; } else if ($asideshop_options['show_asides_on']['author_view'] == 1 && is_author()) { return TRUE; } } return FALSE; } /** * asideshop_is_frontpage() - Check whether current page is a frontpage * * @return bool */ function asideshop_is_frontpage() { // Backward compatibility with 2.2, pre-taxonomy version. $is_tag = FALSE; if (function_exists('is_tag') && is_tag()) { $is_tag = TRUE; } if (!is_archive() && !is_single() && !$is_tag && !is_search()) { return TRUE; } return FALSE; } /** * asideshop_get_categories() - Get categories * * This function is used to get post categories rather than all categories. * * @global string $wp_version * @global object $wpdb * @return array */ function asideshop_get_categories() { global $wp_version, $wpdb; // If 2.2.x if ((float)$wp_version < (float)"2.3") { $categories = $wpdb->get_results("SELECT `cat_ID`, `cat_name`, `category_parent` FROM `{$wpdb->categories}` WHERE `link_count` = 0 ORDER BY `cat_name` ASC"); } else { // If 2.3 and later $categories = get_categories('hide_empty=0'); } $result = array(); if (!empty($categories) && is_array($categories)) { foreach ($categories AS $_cat) { // Backward compatibility with 2.2, pre-taxonomy version. if (empty($_cat->term_id)) { $cat_id = $_cat->cat_ID; $cat_name = $_cat->cat_name; $cat_parent = $_cat->category_parent; } else { $cat_id = $_cat->term_id; $cat_name = $_cat->name; $cat_parent = $_cat->category_parent; } $result[] = array( 'cat_id' => $cat_id, 'cat_name' => $cat_name, 'cat_parent' => $cat_parent, ); } } return $result; } /** * asideshop_setup() - Run misc. things before configuration panel appears * * @global string $asideshop_domain * @return string */ function asideshop_setup() { global $asideshop_domain; asideshop_upgrade(); load_plugin_textdomain($asideshop_domain, 'wp-content/plugins/' . $asideshop_domain); } /** * asideshop_upgrade() - Upgrade AsideShop options * * @return void */ function asideshop_upgrade() { global $asideshop_show_on_array; $asideshop_options = get_option('asideshop_options'); // Upgrade if (is_array($asideshop_options)) { if (!array_key_exists('show_asides_on', $asideshop_options)) { update_option('asideshop_options', $asideshop_options + array('show_asides_on' => $asideshop_show_on_array)); } else { $asideshop_options['show_asides_on'] = $asideshop_options['show_asides_on'] + $asideshop_show_on_array; update_option('asideshop_options', $asideshop_options); } } else { asideshop_install(); } } /** * asideshop_nonce_field() - Show nonce field if available * * @return mixed */ function asideshop_nonce_field() { if (!function_exists('wp_nonce_field')) { return; } else { return wp_nonce_field('asideshop-options'); } } /** * asideshop_conf() - Display options page * * @global array $asideshop_patterns * @global string $asideshop_domain * @global string $wp_version * @global string $asideshop_show_on_array * @return string */ function asideshop_conf() { global $asideshop_patterns, $asideshop_domain, $wp_version, $asideshop_show_on_array; asideshop_setup(); if (!empty($_POST)) { check_admin_referer('asideshop-options'); $asideshop_options = get_option('asideshop_options'); $new_options = $_POST['asideshop_options']; if (!empty($new_options)) { $options_to_update = array('templates' => array(), 'version' => $asideshop_options['version']); if (isset($new_options['enabled'])) { $options_to_update['enabled'] = $new_options['enabled']; } if (!empty($new_options['show_asides'])) { $options_to_update['show_asides'] = $new_options['show_asides']; } if (!empty($new_options['show_asides_on'])) { $options_to_update['show_asides_on'] = $new_options['show_asides_on']; } // Delete templates $c2t_to_remove = array(); if (!empty($asideshop_options['templates'])) { foreach ($asideshop_options['templates'] AS $current_template_key => $current_template) { if (!empty($new_options['delete_templates'][$current_template_key])) { unset( // Delete templates which were not edited $asideshop_options['templates'][$current_template_key], // Delete templates which were edited $new_options['templates'][$current_template_key] ); $c2t_to_remove[] = $current_template_key; } } $options_to_update['templates'] = $asideshop_options['templates']; } // Category to template, if template is deleted, remove from category/template relation if (!empty($new_options['category_to_template'])) { foreach ($new_options['category_to_template'] AS $c2t_key => $c2t) { // If default template, display post as regular if (empty($c2t)) { unset($options_to_update['show_asides'][$c2t_key]); } // If template is deleted, remove from category/template relation if (in_array($c2t, $c2t_to_remove)) { $options_to_update['category_to_template'][$c2t_key] = ''; // Display also post as regular unset($options_to_update['show_asides'][$c2t_key]); } else { $options_to_update['category_to_template'][$c2t_key] = $c2t; } } } // New templates would be added, edited templates would be overwritten if (!empty($new_options['templates'])) { foreach ($new_options['templates'] AS $new_template_key => $new_template) { if ($new_template['title'] == '') { // Do not add empty templates if ($new_template['content'] == '') { continue; } // Add default title if title is empty $new_template['title'] = 'Template-' . $new_template_key; } // Strip slashes from title and content array_walk($new_template, create_function('&$a', '$a = stripslashes($a);')); $options_to_update['templates'][$new_template_key] = $new_template; } } // Update 'show_asides_on' option foreach ($asideshop_show_on_array AS $new_show_on_key => $show_on_value) { if (isset($new_options['show_asides_on'][$new_show_on_key])) { $new_show_on_value = 1; } else { $new_show_on_value = 0; } $options_to_update['show_asides_on'][$new_show_on_key] = $new_show_on_value; } // Update all options update_option('asideshop_options', $options_to_update); } ?>
' . __('No categories were found.', $asideshop_domain) . '
'; $return_html['errors'] .= '' . printf( __('%s operates only with post entries which are placed in categories.', $asideshop_domain), 'AsideShop') . '
'; } ?>