_types = get_post_types(array('public' => true)); SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->init(); array_push($this->_types, 'posts'); array_push($this->_types, 'pages'); array_push($this->_types, 'media'); $this->_taxonomies = get_taxonomies(array('public' => true)); //SQ_Debug::dump($this->_types,$this->_taxonomies); if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') { return; } foreach ($this->_types as $type) { add_filter('manage_' . $type . '_columns', array($this, 'add_post_column'), 10, 1); add_action('manage_' . $type . '_custom_column', array($this, 'add_post_row'), 10, 2); } foreach ($this->_taxonomies as $taxonomy) { add_filter('manage_edit-' . $taxonomy . '_columns', array($this, 'add_tax_column'), 10, 1); add_action('manage_' . $taxonomy . '_custom_column', array($this, 'add_tax_row'), 10, 3); } //Update post status on API add_action('before_delete_post', array($this->model, 'hookUpdateStatus')); add_action('untrashed_post', array($this->model, 'hookUpdateStatus')); add_action('trashed_post', array($this->model, 'hookUpdateStatus')); } /** * Hook the Wordpress header only on postslist header table */ public function loadHead() { SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('postslist'); } /** * Add the Squirrly column in the Post List * * @param array $columns * @return array */ public function add_post_column($columns) { $this->loadHead(); //load the js only for post list $columns = $this->insert($columns, array($this->_column_id => __('SQ Snippet', _SQ_PLUGIN_NAME_)), $this->_pos); $columns = $this->insert($columns, array($this->_slacolumn_id => __('Optimized', _SQ_PLUGIN_NAME_)), $this->_pos); return $columns; } /** * Add row in Post list * * @param object $column * @param integer $post_id */ public function add_post_row($column, $post_id) { if (!$post_type = get_post_type($post_id)) { $post_type = 'post'; } if ($column == $this->_slacolumn_id) { $cached = false; if (isset($_COOKIE[$this->_slacolumn_id . $post_id]) && $_COOKIE[$this->_slacolumn_id . $post_id] <> '') { $cached = true; } else { if (get_post_status($post_id) == 'publish') array_push($this->posts, $post_id); } echo '
' . (($cached) ? $_COOKIE[$this->_slacolumn_id . $post_id] : 'loading ...') . '
'; } if ($column == $this->_column_id) { echo '
' . $this->model->getPostButton($post_id, $post_type) . '
'; } } /** * Add the Squirrly column in the Post List * * @param array $columns * @return array */ public function add_tax_column($columns) { $this->loadHead(); //load the js only for post list $columns = $this->insert($columns, array($this->_column_id => __('SQ Snippet', _SQ_PLUGIN_NAME_)), $this->_pos); return $columns; } /** * Add row in Categories and Tags * * @param string $html * @param object $column * @param integer $post_id */ public function add_tax_row($html = '', $column, $tax_id) { $term = get_term($tax_id); if (!is_wp_error($term) && $column == $this->_column_id) { return '
' . $this->model->getTaxButton($term->term_id, 'tax-' . $term->taxonomy) . '
'; } return $html; } /** * Push the array to a specific index * @param array $src * @param array $in * @param integer $pos * @return array */ public function insert($src, $in, $pos) { $array = array(); if (is_int($pos)) $array = array_merge(array_slice($src, 0, $pos), $in, array_slice($src, $pos)); else { foreach ($src as $k => $v) { if ($k == $pos) $array = array_merge($array, $in); $array[$k] = $v; } } return $array; } /** * Hook Get/Post action * @return void */ public function action() { switch (SQ_Classes_Helpers_Tools::getValue('action')) { case 'inline-save': check_ajax_referer('inlineeditnonce', '_inline_edit'); if (isset($_POST['post_ID']) && ($post_id = (int)$_POST['post_ID']) && isset($_POST['_status']) && $_POST['_status'] <> '') { $args = array(); $args['status'] = $_POST['_status']; $args['post_id'] = $post_id; SQ_Classes_RemoteController::updatePost($args); } return; } parent::action(); switch (SQ_Classes_Helpers_Tools::getValue('action')) { case 'sq_ajax_postslist': if (!current_user_can('sq_manage_snippet')) { $response['error'] = SQ_Classes_Error::showNotices(__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error'); SQ_Classes_Helpers_Tools::setHeader('json'); echo json_encode($response); exit(); } SQ_Classes_Helpers_Tools::setHeader('json'); $args = array(); $posts = SQ_Classes_Helpers_Tools::getValue('posts'); if (is_array($posts) && !empty($posts)) { $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post'); $args['posts'] = join(',', SQ_Classes_Helpers_Tools::getValue('posts', array())); if ($json = SQ_Classes_RemoteController::getPostOptimization($args)) { $posts = $this->model->processPost($json, $post_type); echo json_encode(array('posts' => $posts)); exit(); } } echo json_encode(array('posts' => array())); exit(); } } /** * Hook the Footer * */ public function hookFooter() { $posts = ''; foreach ($this->posts as $post) { $posts .= '"' . $post . '",'; } if (strlen($posts) > 0) $posts = substr($posts, 0, strlen($posts) - 1); echo ''; } }