public function prepare_items()
 {
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Get Data
     $this->data = array();
     $pt_link_manager = new SP_Connection_Manager();
     /**
      * @todo Change te $pt_link_manager and the $link variables
      */
     foreach ($pt_link_manager->get_connections() as $link) {
         // Get parent
         $parent = get_post_types(array('name' => $link->get_parent()), 'object');
         $pt_parent = array_shift($parent);
         // Get child
         $child = get_post_types(array('name' => $link->get_child()), 'object');
         $pt_child = array_shift($child);
         $this->data[] = array('ID' => $link->get_id(), 'title' => $link->get_title(), 'slug' => $link->get_slug(), 'parent' => $pt_parent->labels->name, 'child' => $pt_child->labels->name);
     }
     // Sort
     if (count($this->data) > 0) {
         usort($this->data, array($this, 'custom_reorder'));
     }
     // Set
     $this->items = $this->data;
 }
 public function run()
 {
     $connection_manager = new SP_Connection_Manager();
     $pt_links = $connection_manager->get_connections();
     // Setup Meta Boxes
     if (count($pt_links) > 0) {
         foreach ($pt_links as $connection) {
             new SP_Meta_Box_Manage($connection);
             new SP_Meta_Box_Meta($connection);
             /**
              * Action: 'pc_meta_box_creation_after' - Allow actions to be added in meta box manage construct
              *
              * @api SP_Connection $connection The Connection used in this meta box
              */
             do_action('pc_meta_box_creation_after', $connection);
         }
     }
 }
 /**
  * the_content filter that will add linked posts to the bottom of the main post content
  *
  * @param $content
  *
  * @return string
  */
 public function run($content)
 {
     /**
      * Wow, what's going on here?! Well, setup_postdata() sets a lot of variables but does not change the $post variable.
      * All checks return the main queried ID but we want to check if this specific filter call is the for the 'main' content.
      * The method setup_postdata() does global and set the $id variable, so we're checking that.
      */
     global $id;
     // Only run on single
     if (!is_singular() || !is_main_query() || $id != get_queried_object_id()) {
         return $content;
     }
     $ptl_manager = new SP_Connection_Manager();
     // Add a meta query so we only get relations that have the PM_PTL_APDC or PM_PTL_APDP set to true (1)
     $args = array('meta_query' => array(array('key' => SP_Constants::PM_PTL_APDC, 'value' => '1')));
     // Get the connections
     $relations = $ptl_manager->get_connections($args);
     // Check relations
     if (count($relations) > 0) {
         // Post Link Manager
         $pl_manager = new SP_Post_Link_Manager();
         // Current post ID
         $post_id = get_the_ID();
         // Loop relations
         foreach ($relations as $relation) {
             // Check if this relation allows children links to show
             if ('1' === $relation->get_after_post_display_children()) {
                 $children_relations[] = $relation;
             }
         }
         // Opening the wrapper div
         $content .= "<div class='pc-post-children'>\n";
         foreach ($relations as $relation) {
             // Get the linked posts
             $pc_posts = $pl_manager->get_children($relation->get_slug(), $post_id);
             if (count($pc_posts) > 0) {
                 $content .= $this->create_post_list($relation->get_slug(), $relation->get_title(), $pc_posts);
             }
         }
         // Close the wrapper div
         $content .= "</div>\n";
     }
     return $content;
 }
 public function form($instance)
 {
     $instance = array_merge($this->default_vars, $instance);
     $selected_link = null;
     echo "<div class='pc_ajax_child'>\n";
     wp_nonce_field('sp_ajax_sc_gpp', 'sp_widget_child_nonce');
     echo "<p>";
     echo '<label for="' . $this->get_field_id('title') . '">' . __('Title', 'post-connector') . ':</label>';
     echo '<input class="widefat" id="' . $this->get_field_id('title') . '" type="text" name="' . $this->get_field_name('title') . '" value="' . esc_attr($instance['title']) . '" />';
     echo "</p>\n";
     echo "<p>";
     echo '<label for="' . $this->get_field_id('postlink') . '">' . __('Post Link', 'post-connector') . ':</label>';
     // Get the connections
     $connection_manager = new SP_Connection_Manager();
     $links = $connection_manager->get_connections();
     echo '<select class="widefat postlink" name="' . $this->get_field_name('postlink') . '" id="' . $this->get_field_id('postlink') . '" >';
     echo '<option value="0">' . __('Select Post Link', 'post-connector') . '</option>';
     if (count($links) > 0) {
         foreach ($links as $link) {
             echo '<option value="' . $link->get_id() . '"';
             if ($link->get_id() == $instance['postlink']) {
                 echo ' selected="selected"';
                 $selected_link = $link;
             }
             echo '>' . $link->get_title() . '</option>';
         }
     }
     echo '</select>';
     echo "</p>\n";
     echo "<p>";
     echo '<label for="' . $this->get_field_id('parent') . '">' . __('Parent', 'post-connector') . ':</label>';
     echo '<select class="widefat child" name="' . $this->get_field_name('parent') . '" id="' . $this->get_field_id('parent') . '" >';
     if ($selected_link != null) {
         $parent_posts = get_posts(array('post_type' => $selected_link->get_parent(), 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'));
         if (count($parent_posts) > 0) {
             echo "<option value='current'>" . __('Current page', 'post-connector') . "</option>\n";
             foreach ($parent_posts as $parent_post) {
                 echo "<option value='{$parent_post->ID}'";
                 if ($parent_post->ID == $instance['parent']) {
                     echo " selected='selected'";
                 }
                 echo ">{$parent_post->post_title}</option>\n";
             }
         }
     }
     echo '</select>';
     echo "</p>\n";
     echo "<p>";
     echo '<label for="' . $this->get_field_id('link') . '">' . __('Make children clickable', 'post-connector') . ':</label>';
     echo '<select class="widefat" name="' . $this->get_field_name('link') . '" id="' . $this->get_field_id('link') . '" >';
     echo '<option value="true"' . ($instance['link'] == true ? ' selected="selected"' : '') . '>' . __('Yes', 'post-connector') . '</option>';
     echo '<option value="false"' . ($instance['link'] == false ? ' selected="selected"' : '') . '>' . __('No', 'post-connector') . '</option>';
     echo '</select>';
     echo "</p>\n";
     echo "<p>";
     echo '<label for="' . $this->get_field_id('excerpt') . '">' . __('Display excerpt', 'post-connector') . ':</label>';
     echo '<select class="widefat" name="' . $this->get_field_name('excerpt') . '" id="' . $this->get_field_id('excerpt') . '" >';
     echo '<option value="true"' . ($instance['excerpt'] == true ? ' selected="selected"' : '') . '>' . __('Yes', 'post-connector') . '</option>';
     echo '<option value="false"' . ($instance['excerpt'] == false ? ' selected="selected"' : '') . '>' . __('No', 'post-connector') . '</option>';
     echo '</select>';
     echo "</p>\n";
     echo "<p>";
     echo '<label for="' . $this->get_field_id('thumbnail') . '">' . __('Display thumbnail', 'post-connector') . ':</label>';
     echo '<select class="widefat" name="' . $this->get_field_name('thumbnail') . '" id="' . $this->get_field_id('thumbnail') . '" >';
     echo '<option value="true"' . ($instance['thumbnail'] == true ? ' selected="selected"' : '') . '>' . __('Yes', 'post-connector') . '</option>';
     echo '<option value="false"' . ($instance['thumbnail'] == false ? ' selected="selected"' : '') . '>' . __('No', 'post-connector') . '</option>';
     echo '</select>';
     echo "</p>\n";
     echo "</div>\n";
 }
    public function run($post_id)
    {
        if (in_array(basename($_SERVER['SCRIPT_FILENAME']), array('post.php', 'page.php', 'page-new.php', 'post-new.php'))) {
            add_thickbox();
            ?>
			<div id="sp_tb_shortcode" style="height: 500px; display:none;">
				<div class="wrap">
					<div>
						<div style="padding:15px 15px 0 15px;">
							<h2><?php 
            _e('Insert Post Connector show_children shortcode', 'post-connector');
            ?>
</h2>
							<span><?php 
            _e('Use the form below to generate a show_children shortcode.', 'post-connector');
            ?>
</span>
						</div>
						<div style="padding:15px 15px 0 15px;">

							<?php 
            echo "<div class='sp_showchilds_ajax'>\n";
            wp_nonce_field('sp_ajax_sc_gpp', 'sp_widget_child_nonce');
            echo '<input type="hidden" name="by_slug" id="by_slug" value="true" />';
            echo "<p>";
            echo '<label for="sp_sc_postlink">' . __('Connection', 'post-connector') . ':</label>';
            // Get the connections
            $connection_manger = new SP_Connection_Manager();
            $connections = $connection_manger->get_connections();
            echo '<select class="widefat mandatory postlink" name="sp_sc_postlink" id="sp_sc_postlink" >';
            echo '<option value="0">' . __('Select Connection', 'post-connector') . '</option>';
            if (count($connections) > 0) {
                foreach ($connections as $connection) {
                    echo '<option value="' . get_post_meta($connection->get_id(), SP_Constants::PM_PTL_SLUG, true) . '">' . $connection->get_title() . '</option>';
                }
            }
            echo '</select>';
            echo "</p>\n";
            echo "<p>";
            echo '<label for="sp_sc_parent">' . __('Parent', 'post-connector') . ':</label>';
            echo '<select class="widefat mandatory parent" name="sp_sc_parent" id="sp_sc_parent" >';
            echo '</select>';
            echo "</p>\n";
            echo "<p>";
            echo '<label for="sp_sc_link">' . __('Make children clickable', 'post-connector') . ':</label>';
            echo '<select class="widefat" name="sp_sc_link" id="sp_sc_link" >';
            echo '<option value="true">Yes</option>';
            echo '<option value="false">No</option>';
            echo '</select>';
            echo "</p>\n";
            echo "<p>";
            echo '<label for="sp_sc_excerpt">' . __('Display excerpt', 'post-connector') . ':</label>';
            echo '<select class="widefat" name="sp_sc_excerpt" id="sp_sc_excerpt" >';
            echo '<option value="true">Yes</option>';
            echo '<option value="false">No</option>';
            echo '</select>';
            echo "</p>\n";
            echo "</div>\n";
            ?>

						</div>


						<div style="padding:15px 15px 0;">
							<input type="button" class="button-primary" value="<?php 
            _e('Insert Shortcode', 'post-connector');
            ?>
" onclick="insertShortcode_ShowChilds();" />&nbsp;&nbsp;&nbsp;
							<a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php 
            _e('Cancel', 'post-connector');
            ?>
</a>
						</div>
					</div>
				</div>
			</div>
		<?php 
        }
    }