diff -r 000000000000 -r d970ebf37754 wp/wp-content/plugins/page-columnist/page-columnist.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wp/wp-content/plugins/page-columnist/page-columnist.php Wed Nov 06 03:21:17 2013 +0000
@@ -0,0 +1,830 @@
+_get_version_errors();
+ if (is_array($version_error) && count($version_error) != 0) {
+ $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'active_plugins' ) );
+ if ( is_object( $row ) ) {
+ $current = maybe_unserialize( $row->option_value );
+ if (array_search($page_columnist_plug->basename, $current) !== false) {
+ array_splice($current, array_search($page_columnist_plug->basename, $current), 1 );
+ update_option('active_plugins', $current);
+ }
+ }
+ exit();
+ }
+ }
+ if (!get_option('cspc_page_columnist'))
+ update_option('cspc_page_columnist', get_option('cspc_page_columnist', $page_columnist_plug->defaults));
+}
+function cspc_on_deactivate_plugin() {
+ //currently empty
+}
+register_activation_hook(plugin_basename(__FILE__), 'cspc_on_activate_plugin');
+register_deactivation_hook(plugin_basename(__FILE__), 'cspc_on_deactivate_plugin');
+
+
+class Page_columnist_page_transition {
+
+ function Page_columnist_page_transition(&$plugin, $page_id = false) {
+ $this->plugin = $plugin; //reference to owner plugin
+ $this->transition = $this->plugin->page_default_trans;
+ $this->data = array();
+ $this->data_keys = array('spacing', 'columns', 'overflow', 'multiposts');
+ $this->padding = ''.__('* content missing', $this->plugin->textdomain).' ';
+ if ($page_id) $this->load($page_id);
+ else $this->page_id = 0;
+ }
+
+ function load($page_id) {
+ $this->page_id = ($page_id ? $page_id : 0);
+ $this->transition = $this->plugin->page_default_trans;
+ $this->data = array();
+ $res = explode('|', get_post_meta($this->page_id, '_cspc-page-transitions', true));
+ $num = count($res);
+ if ($num > 0) {
+ if (in_array($res[0], array_keys($this->plugin->page_transitions))) {
+ $this->transition = $res[0];
+ if ($num > 1) {
+ $this->data = unserialize($res[1]);
+ }
+ }
+ }
+ }
+
+ function save() {
+ if ($this->page_id > 0) {
+ $value = $this->transition.'|'.serialize($this->data);
+ update_post_meta($this->page_id, '_cspc-page-transitions', $value);
+ }
+ }
+
+ function update_and_save() {
+ if (isset($_POST['cspc-page-transition']) && in_array($_POST['cspc-page-transition'], array_keys($this->plugin->page_transitions))) {
+ $this->transition = $_POST['cspc-page-transition'];
+ }
+ if (isset($_POST['cspc-count-columns'])) {
+ $this->data['columns'] = (int)$_POST['cspc-count-columns'];
+ }
+ if (isset($_POST['cspc-overflow-paging'])) {
+ $this->data['overflow'] = $_POST['cspc-overflow-paging'];
+ if($this->data['overflow'] != 'hidden' && $this->data['overflow'] != 'virtual') {
+ $this->data['overflow'] = 'hidden';
+ }
+ }
+ if (isset($_POST['cspc-multiposts-paging']) && in_array($_POST['cspc-multiposts-paging'], $this->plugin->multiposts_style)) {
+ $this->data['multiposts'] = $_POST['cspc-multiposts-paging'];
+ }
+ if (!isset($this->data['distribution']) || !is_array($this->data['distribution'])) $this->data['distribution'] = array();
+ $this->save();
+ }
+
+
+ function spacing() {
+ return (isset($this->data['spacing']) ? (float)$this->data['spacing'] : (float)$this->plugin->options->spacing);
+ }
+
+ function columns() {
+ return (isset($this->data['columns']) ? (int)$this->data['columns'] : 2);
+ }
+
+ function overflow() {
+ return (isset($this->data['overflow']) ? $this->data['overflow'] : 'hidden');
+ }
+
+ function multiposts() {
+ return (isset($this->data['multiposts']) ? $this->data['multiposts'] : 'same');
+ }
+
+ function execute(&$pages) {
+ return call_user_func(array(&$this, '_exec_'.str_replace('-','_',$this->transition)), $pages);
+ }
+
+ function _padding_pages($needed, &$pages) {
+ $res = array();
+ while(count($pages) % $needed != 0) $pages[] = $this->padding; //padding count of sub pages
+ if ($this->overflow() == 'hidden') {
+ $res[] = array_slice($pages, 0, $needed);
+ }else{
+ $res = array_chunk($pages, $needed);
+ }
+ return $res;
+ }
+
+ function _get_distribution($num, $remaining) {
+ $res = array();
+ if (!is_array($this->data['distribution']) || !isset($this->data['distribution'][$num])) {
+ $perc = $remaining / $num;
+ for ($i=0; $i<$num; $i++) $res[] = $perc;
+ }
+ else{
+ $sum = 0.0;
+ for ($i=0; $i<$num; $i++) $sum += (float)$this->data['distribution'][$num][$i];
+ for ($i=0; $i<$num; $i++) {
+ $res[]= ($remaining * ((float)$this->data['distribution'][$num][$i] / $sum));
+ }
+ }
+ return $res;
+ }
+
+ function _columnize_pages($num, $pages) {
+ $res = '';
+ $base = 100.0;
+ $spacing = $this->spacing();
+ $remaining = ($base - ($num - 1) * $spacing);
+ $dist = $this->_get_distribution($num, $remaining);
+ $lorr = 'left';
+ global $wp_locale;
+ if ($wp_locale->text_direction == 'rtl') {
+ $lorr = 'right'; //make it work at RTL languages
+ }
+ for ($i=0; $i<$num; $i++) {
+ $page = $pages[$i];
+ $perc = $dist[$i];
+ if ($this->plugin->is_MSIE()) {
+ //IE is not able to calculate column sizes well, several 100% sums leads to get the last column display wrapped under the first
+ //in several cases (mostly where a periodic fraction of 1/3 or 1/6 occures) , IE seems to reach by internal rounding errors more than 100% of available width
+ $margin_left_i = ($i==0 ? 0 : $spacing * 0.66);
+ }
+ else{
+ $margin_left_i = ($i==0 ? 0 : $spacing);
+ }
+ $extend = $this->plugin->is_page_preview() ? ' data="'.$perc.'"' : '';
+ $res .= "
";
+ if (has_filter('the_content', 'wpautop') && !preg_match('/^\s*
\s*$/', $page)) $res .= '';
+ $res .= '
';
+ }
+ return $res;
+ }
+
+ function _columnize_fullsize($page, $clearleft = false) {
+ if (empty($page)) return '';
+ $res = ($clearleft ? '';
+ $out[] = $res;
+ }
+ return $out;
+ }
+
+ function _exec_cspc_trans_footer(&$pages) {
+ $work = $this->_padding_pages($this->columns() + 1, $pages);
+ $out = array();
+ for ($i=0; $i
0 ? array_slice($work[$i],0,$num) : array());
+ $res = "transition-wrap\" class=\"cspc-wrapper\">";
+ $res .= '
';
+ $res .= $this->_columnize_pages($num, $work[$i]);
+ $res .= '
';
+ $res .= $this->_columnize_fullsize($last, true);
+ $res .= '
';
+ $out[] = $res;
+ }
+ return $out;
+ }
+
+ function _exec_cspc_trans_interior(&$pages) {
+ $work = $this->_padding_pages($this->columns() + 2, $pages);
+ $out = array();
+ for ($i=0; $i 0 ? end($work[$i]) : '');
+ $work[$i] = ($num > 0 ? array_slice($work[$i],0,$num) : array());
+ $res = "transition-wrap\" class=\"cspc-wrapper\">";
+ $res .= $this->_columnize_fullsize($top);
+ $res .= '
';
+ $res .= $this->_columnize_pages($num, $work[$i]);
+ $res .= '
';
+ $res .= $this->_columnize_fullsize($last, true);
+ $res .= '
';
+ $out[] = $res;
+ }
+ return $out;
+ }
+}
+
+
+//page_columnist Plugin class
+class Plugin_page_columnist {
+
+ //initializes the whole plugin and enables the activation/deactivation handling
+ function Plugin_page_columnist() {
+ global $wp_version;
+
+ $this->l10n_ready = false;
+
+ //own plugin data
+ $this->basename = plugin_basename(__FILE__);
+ $this->url = WP_PLUGIN_URL.'/'.dirname($this->basename);
+ $this->textdomain = basename($this->basename);
+ $this->textdomain = substr($this->textdomain, 0, strrpos($this->textdomain, '.'));
+ $this->versions = new stdClass;
+ $this->versions->required = array( 'php' => '4.4.2', 'wp' => '2.7');
+ $this->versions->found = array( 'php' => phpversion(), 'wp' => $wp_version);
+ $this->versions->above_27 = !version_compare($this->versions->found['wp'], '2.8alpha', '<');
+ $this->do_resample_page = false;
+ $this->multiposts_style = array('flat', 'same', 'wp');
+
+ $this->page_default_trans = 'cspc-trans-wordpress';
+
+ $this->defaults = new stdClass;
+ $this->defaults->spacing = 3.0;
+ $this->defaults->preview_assistent = false;
+
+ $this->options = get_option('cspc_page_columnist', $this->defaults);
+ $stored = get_object_vars($this->options);
+ $defaults = get_object_vars($this->defaults);
+ foreach($defaults as $key => $value) {
+ if (!isset($stored[$key])) $this->options->$key = $value;
+ }
+
+ add_action('init', array(&$this, 'on_init'));
+ add_action('admin_init', array(&$this, 'on_admin_init'));
+ add_action('wp_head', array(&$this, 'on_wp_head'));
+ add_action('wp_footer', array(&$this, 'on_wp_footer'));
+ add_action('admin_head', array(&$this, 'on_admin_head'));
+ add_action('edit_page_form', array(&$this, 'on_extend_html_editor'));
+ add_action('edit_form_advanced', array(&$this, 'on_extend_html_editor'));
+ add_action('manage_pages_custom_column', array(&$this, 'on_manage_custom_column'), 10, 2);
+ add_action('manage_posts_custom_column', array(&$this, 'on_manage_custom_column'), 10, 2);
+ add_action('wp_insert_post', array(&$this, 'on_wp_insert_post'), 10, 2);
+ add_action('loop_start', array(&$this, 'on_loop_start'), 0 );
+ add_action('the_post', array(&$this, 'on_the_post'), 0 );
+ add_action('template_redirect', array(&$this, 'on_template_redirect'));
+ add_filter('mce_buttons', array(&$this, 'on_filter_mce_buttons'));
+
+ $this->_display_version_errors();
+
+ //TODO: future development should be able to deal with removing the ugly wpautop algorithm
+ //remove_filter('the_content', 'wpautop');
+ }
+
+ function _get_version_errors() {
+ $res = array();
+ foreach($this->versions->required as $key => $value) {
+ if (!version_compare($this->versions->found[$key], $value, '>=')) {
+ $res[strtoupper($key).' Version'] = array('required' => $value, 'found' => $this->versions->found[$key]);
+ }
+ }
+ return $res;
+ }
+
+ function _display_version_errors() {
+ if (isset($_GET['action']) && isset($_GET['plugin']) && ($_GET['action'] == 'error_scrape') && ($_GET['plugin'] == $this->basename )) {
+ $this->setup_translation();
+ $version_error = $this->_get_version_errors();
+ if (count($version_error) != 0) {
+ echo "";
+ echo "".__('Plugin can not be activated.', $this->textdomain)." | ".__('required', $this->textdomain)." | ".__('actual', $this->textdomain)." ";
+ foreach($version_error as $key => $value) {
+ echo "$key >= ".$value['required']." ".$value['found']." ";
+ }
+ echo "
";
+ }
+ }
+ }
+
+ //load and setup the necessary translation files
+ function setup_translation() {
+ if (!$this->l10n_ready) {
+ $abs_rel_path = str_replace(ABSPATH, '', WP_PLUGIN_DIR.'/'.dirname($this->basename));
+ $plugin_rel_path = dirname($this->basename);
+ load_plugin_textdomain($this->textdomain, $abs_rel_path, $plugin_rel_path);
+ $this->l10n_ready = true;
+ }
+ }
+
+ //is the browser of current user IE ?
+ function is_MSIE() {
+ return preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT']) && !preg_match('/opera/i', $_SERVER['HTTP_USER_AGENT']);
+ }
+
+ //do we show a frontend page in preview mode ?
+ function is_page_preview() {
+ $id = (isset($_GET['preview_id']) ? (int)$_GET['preview_id'] : 0);
+ if ($id == 0 && isset($_GET['post_id'])) $id = (int)$_GET['post_id'];
+ if ($id == 0 && isset($_GET['page_id'])) $id = (int)$_GET['page_id'];
+ if ($id == 0 && isset($_GET['p'])) $id = (int)$_GET['p'];
+ $preview = (isset($_GET['preview']) ? $_GET['preview'] : '');
+ if ($id > 0 && $preview == 'true' && $this->options->preview_assistent) {
+ global $wpdb;
+ $type = $wpdb->get_results("SELECT post_type FROM $wpdb->posts WHERE ID=$id");
+ if (count($type) && ($type[0]->post_type == 'page' || $type[0]->post_type == 'post')){
+ switch($type[0]->post_type) {
+ case 'post':
+ return current_user_can('edit_post', $id);
+ break;
+ case 'page':
+ return current_user_can('edit_page', $id);
+ break;
+ default:
+ return false;
+ break;
+ }
+ }
+ }
+ return false;
+ }
+
+ //detects if we a currently render the posts or pages edit overview table page
+ function is_page_overview() {
+ global $pagenow;
+ return (is_admin() && ($pagenow == 'edit-pages.php' || $pagenow == 'edit.php'));
+ }
+
+ //detects if we a currently render the posts or pages editor page
+ function is_page_editor() {
+ global $pagenow;
+ return (is_admin() && (
+ ($pagenow == 'page.php') || ($pagenow == 'page-new.php')
+ ||
+ ($pagenow == 'post.php') || ($pagenow == 'post-new.php')
+ )
+ );
+ }
+
+ //gets called by WordPress action "init" after WordPress core is up and running
+ function on_init() {
+ //ensures the correct matching translation file gets loaded
+ $this->setup_translation();
+
+ $this->page_transitions = array(
+ 'cspc-trans-wordpress' => array('img-pos' => 0, 'text' => __('WordPress - Next Page (default)', $this->textdomain), 'default' => true),
+ 'cspc-trans-ordinary' => array('img-pos' => -16, 'text' => __('Ordinary Plain Page', $this->textdomain)),
+ 'cspc-trans-columns' => array('img-pos' => -32, 'text' => __('Every Sub Page as Column', $this->textdomain)),
+ 'cspc-trans-header' => array('img-pos' => -48, 'text' => __('First Sub Page as Header', $this->textdomain)),
+ 'cspc-trans-footer' => array('img-pos' => -64, 'text' => __('Last Sub Page as Footer', $this->textdomain)),
+ 'cspc-trans-interior' => array('img-pos' => -80, 'text' => __('Interior as Columns', $this->textdomain)),
+ );
+
+ if ($this->is_page_preview() && !defined('DOING_AJAX')) {
+ wp_enqueue_script('jquery-spin', $this->url.'/jquery.spin.js', array('jquery'));
+ wp_enqueue_script('cspc_page_columnist_assistance', $this->url.'/page-columnist-assistance.js', array('jquery', 'jquery-ui-draggable', 'jquery-spin'));
+ wp_enqueue_style('cspc_page_columnist_assistance', $this->url.'/page-columnist-assistance.css');
+ }
+
+ if(defined('DOING_AJAX')) {
+ add_action('wp_ajax_cspc_save_changes', array(&$this, 'on_ajax_save_changes'));
+ }
+ }
+
+ //gets called by WordPress action "admin_init" to be able to setup correctly in backend mode
+ function on_admin_init() {
+
+ if ($this->is_page_overview()) {
+ add_filter('manage_edit-pages_columns', array(&$this,'on_filter_manage_columns'));
+ add_filter('manage_posts_columns', array(&$this,'on_filter_manage_columns'));
+ }
+
+ if ($this->is_page_editor()) {
+ add_meta_box('cspc-page-transitions', __('Page Columnist', $this->textdomain) , array(&$this, 'on_print_metabox_content_cspc_page_transitions'), 'page', 'side', 'core');
+ add_meta_box('cspc-page-transitions', __('Page Columnist', $this->textdomain) , array(&$this, 'on_print_metabox_content_cspc_page_transitions'), 'post', 'side', 'core');
+ wp_enqueue_script('jquery-spin', $this->url.'/jquery.spin.js', array('jquery'));
+ }
+ }
+
+ //gets called by action "wp_head" to configure the preview assistance
+ function on_wp_head() {
+ if ($this->is_page_preview()) {
+ $id = (isset($_GET['preview_id']) ? (int)$_GET['preview_id'] : 0);
+ if ($id == 0 && isset($_GET['post_id'])) $id = (int)$_GET['post_id'];
+ if ($id == 0 && isset($_GET['page_id'])) $id = (int)$_GET['page_id'];
+ if ($id == 0 && isset($_GET['p'])) $id = (int)$_GET['p'];
+ $pt = new Page_columnist_page_transition($this, $id);
+ ?>
+
+ is_page_preview()) {
+ $id = (isset($_GET['preview_id']) ? (int)$_GET['preview_id'] : 0);
+ if ($id == 0 && isset($_GET['post_id'])) $id = (int)$_GET['post_id'];
+ if ($id == 0 && isset($_GET['page_id'])) $id = (int)$_GET['page_id'];
+ if ($id == 0 && isset($_GET['p'])) $id = (int)$_GET['p'];
+ $pt = new Page_columnist_page_transition($this, $id);
+ ?>
+
+
+
+
+ textdomain); ?>
+
+
+
+
+
textdomain); ?>
+
+ is_page_overview() || $this->is_page_editor()) : ?>
+
+ is_page_editor()) : ?>
+
+
+ is_page_editor()) {
+ if (!in_array('wp_page', $buttons)) {
+ if (!in_array('wp_more', $buttons)) {
+ $last = array_pop($buttons);
+ $buttons[] = "wp_page";
+ $buttons[] = $last;
+ }else{
+ $txt = implode('|', $buttons);
+ $txt = str_replace('wp_more|','wp_more|wp_page|', $txt);
+ $buttons = explode('|', $txt);
+ }
+ }
+ }
+ return $buttons;
+ }
+
+ //insert nextpage button to HTML editor, if not already present there
+ function on_extend_html_editor() {
+ if ($this->is_page_editor()) : ?>
+
+ textdomain);
+ return $columns;
+ }
+
+ //add content to the new edit posts / pages overview column
+ function on_manage_custom_column($column_name, $id) {
+ if ($column_name == 'cspc-page-transition-col') {
+ $pt = new Page_columnist_page_transition($this, $id);
+ if ($pt->transition != 'cspc-trans-wordpress' && $pt->transition != 'cspc-trans-ordinary') {
+ echo "transition\"> (".$pt->columns().")
";
+ }
+ else{
+ echo "transition\"> (-)
";
+ }
+ }
+ }
+
+ //save the page transition mode setting of page/post, if something has been saved
+ function on_wp_insert_post($post_ID, $post) {
+ $my_id = ((isset($_POST['wp-preview']) && $_POST['wp-preview'] == 'dopreview') ? $_POST['post_ID'] : $post_ID);
+ $my_type = ((isset($_POST['wp-preview']) && $_POST['wp-preview'] == 'dopreview') ? $_POST['post_type'] : $post->post_type);
+
+ switch($my_type) {
+ case 'post':
+ if(!current_user_can('edit_post', $my_id)) return;
+ break;
+ case 'page':
+ if (!current_user_can('edit_page', $my_id)) return;
+ break;
+ default:
+ return;
+ break;
+ }
+
+ if (($my_type == 'page') || ($my_type == 'post')) {
+
+ $pt = new Page_columnist_page_transition($this, $my_id);
+ $pt->update_and_save();
+
+ $this->options->preview_assistent = (isset($_POST['cspc-preview-assistent']) ? (bool)$_POST['cspc-preview-assistent'] : $this->defaults->preview_assistent);
+ $this->options->spacing = (isset($_POST['cspc-default-column-spacing']) ? (float)$_POST['cspc-default-column-spacing'] : $this->defaults->spacing);
+ update_option('cspc_page_columnist', $this->options);
+ }
+ }
+
+ //save the changes the user made at preview assistent
+ function on_ajax_save_changes() {
+ $page_id = (int)$_POST['page_id'];
+ $spacing = (float)$_POST['spacing'];
+ $default_spacing = ($_POST['default_spacing'] == 'true' ? true : false);
+
+ global $wpdb;
+ $type = $wpdb->get_results("SELECT post_type FROM $wpdb->posts WHERE ID=$page_id");
+ if (count($type) && ($type[0]->post_type == 'page' || $type[0]->post_type == 'post')){
+ $checked = false;
+ switch($type[0]->post_type) {
+ case 'post':
+ $checked = current_user_can('edit_post', $page_id);
+ break;
+ case 'page':
+ $checked = current_user_can('edit_page', $page_id);
+ break;
+ default:
+ $checked = false;
+ break;
+ }
+ if ($checked) {
+ $pt = new Page_columnist_page_transition($this, $page_id);
+ $pt->data['spacing'] = $spacing;
+ if (!is_array($pt->data['distribution'])) $pt->data['distribution'] = array();
+ $pt->data['distribution'][$pt->columns()] = explode('|',$_POST['distribution']);
+ $pt->save();
+ if ($default_spacing) {
+ $this->options->spacing = $spacing;
+ update_option('cspc_page_columnist', $this->options);
+ }
+ exit();
+ }
+ }
+ header('Status: 404 Not Found');
+ header('HTTP/1.1 404 Not Found');
+ _e('You do not have the permission to edit this page.', $this->textdomain);
+ exit();
+ }
+
+
+ //ouput the content of new one sidebar box at page/post editing
+ function on_print_metabox_content_cspc_page_transitions($data) {
+ $pt = new Page_columnist_page_transition($this, $data->ID); ?>
+
+
+
+
+ ID);
+ //user can change overview pages to support also columnization, default is off
+ if (!is_single()) {
+ switch($pt->multiposts()) {
+ case 'wp':
+ $pt->transition = $this->page_default_trans;
+ break;
+ case 'flat':
+ $pt->transition = 'cspc-trans-ordinary';
+ break;
+ }
+ }
+ if($pt->transition == $this->page_default_trans) return;
+ $pages = $pt->execute($pages);
+
+ if (count($pages) > 1) {
+ $multipage = 1;
+ $numpages = count($pages);
+ }
+ else{
+ $multipage = 0;
+ $numpages = 1;
+ }
+
+/*
+ //TODO: future versions should check ugly invalid based at shortcode api if possible
+ if (has_filter('the_content', 'wpautop')) {
+ preg_match('/'.get_shortcode_regex().'(\s\s|)/', $pages[0],$hits);
+ var_dump($hits);
+ }
+*/
+ }
+
+ //beginning WP 2.8 the order of how hooks been called have been change
+ //that's why the handling of resampling the page if different for 2.7 and 2.8, this have to be respected
+ function on_the_post() {
+ if ($this->versions->above_27) {
+ $this->resample_page_content();
+ }
+ }
+
+ //beginning WP 2.8 the order of how hooks been called have been change
+ //that's why the handling of resampling the page if different for 2.7 and 2.8, this have to be respected
+ function on_loop_start() {
+ if ($this->versions->above_27 == false) {
+ if (is_page() || is_single()) {
+ $this->resample_page_content();
+ }
+ }
+ }
+
+ //if we are in none standard page mode, ensure a redirect to main page slug, if sub-page has been requested directly and doesn't support virtual paging
+ function on_template_redirect(){
+ global $post, $page;
+ if ($post->post_type == 'page' || $post->post_type == 'post') {
+ $pt = new Page_columnist_page_transition($this, $post->ID);
+ if (($pt->transition != $this->page_default_trans) && $page && $pt->overflow() == 'hidden') {
+ wp_redirect(get_permalink($post->ID));
+ exit();
+ }
+ }
+ }
+
+}
+
+//nothing more remains to do as to create an instance of the plugin itself :-)
+global $page_columnist_plug;
+$page_columnist_plug = new Plugin_page_columnist();
+
+}// if !function_exists('cspc_on_activate_plugin')) {
+?>
\ No newline at end of file