public function init()
 {
     $is_stage = get_option('sme_cs_is_stage');
     $is_stage = $is_stage ? true : false;
     $data = array('endpoint' => get_option('sme_cs_endpoint'), 'secret_key' => get_option('sme_cs_secret_key'), 'is_stage' => $is_stage);
     $this->template->render('settings', $data);
 }
 public function init()
 {
     // Get options available for sync.
     $options = $this->get_whitelisted_options();
     // Options already selected for syncing.
     $selected_options = get_option('sme_wp_options', array());
     // Prepare options for presentation layer.
     $option_items = $this->prepare_options_for_view($options, $selected_options);
     $this->template->render('options', array('options' => $option_items));
 }
 /**
  * Render table of deleted posts.
  */
 public function render(Batch $batch)
 {
     /**
      * @var Custom_DAO $custom_dao
      */
     $custom_dao = Helper_Factory::get_instance()->get_dao('Custom');
     // Get deleted posts.
     $deleted_posts = $custom_dao->get_deleted_posts();
     // No deleted posts exists.
     if (empty($deleted_posts)) {
         return;
     }
     // Deleted posts previously scheduled to be synced to production.
     $selected_posts = $batch->get_custom_data($this->extension);
     if (!$selected_posts) {
         $selected_posts = array();
     }
     $selected_posts = array_map(function ($post) {
         return $post['id'];
     }, $selected_posts);
     $deleted_posts = array_map(function ($post) use($selected_posts) {
         $post['checked'] = in_array($post['id'], $selected_posts) ? 'checked="checked"' : '';
         return $post;
     }, $deleted_posts);
     $data = array('deleted_posts' => $deleted_posts);
     $this->template->render('delete-post', $data);
 }
 public function init()
 {
     $order_by = 'post_modified';
     $order = 'desc';
     $per_page = 10;
     $paged = 1;
     $status = array('draft');
     $posts = array();
     if (isset($_GET['orderby'])) {
         $order_by = $_GET['orderby'];
     }
     if (isset($_GET['order'])) {
         $order = $_GET['order'];
     }
     if (isset($_GET['per_page'])) {
         $per_page = $_GET['per_page'];
     }
     if (isset($_GET['paged'])) {
         $paged = $_GET['paged'];
     }
     $count = $this->batch_dao->count($status);
     $batches = $this->batch_dao->get_batches($status, $order_by, $order, $per_page, $paged);
     foreach ($batches as $batch) {
         // Get IDs of posts user selected to include in this batch.
         $post_ids = $this->batch_dao->get_post_meta($batch->get_id(), 'sme_selected_post');
         if (!is_array($post_ids)) {
             $post_ids = array();
         }
         $posts = $this->post_dao->find_by_ids($post_ids);
         $batch->set_posts($posts);
     }
     // Prepare table of batches.
     $table = new Batch_History_Table();
     $table->items = $batches;
     $table->set_pagination_args(array('total_items' => $count, 'per_page' => $per_page));
     $table->prepare_items();
     $data = array('table' => $table);
     $this->template->render('batch-history', $data);
 }
Ejemplo n.º 5
0
 /**
  * Deploy batch.
  *
  * Send batch from content staging environment to production. Data is
  * stored on the production environment.
  *
  * Display any messages that is returned by production.
  */
 public function deploy()
 {
     // Check that the current request carries a valid nonce.
     check_admin_referer('sme-deploy-batch', 'sme_deploy_batch_nonce');
     $batch = null;
     // Requested batch ID.
     $batch_id = intval($_GET['id']);
     // Get batch.
     $batch = $this->batch_dao->find($batch_id);
     // Make sure a valid batch has been requested.
     if (!$batch instanceof Batch || $batch->get_status() !== 'publish') {
         wp_die(__('No batch found.', 'sme-content-staging'));
     }
     // Deploy the batch.
     $response = $this->api->deploy($batch);
     // Get messages received from production.
     $status = isset($response['status']) ? $response['status'] : 0;
     $messages = isset($response['messages']) ? $response['messages'] : array();
     // Render page.
     $this->template->render('deploy-batch', array('status' => $status, 'messages' => $messages));
 }