Skip to content

Commit

Permalink
Merge pull request #380 from PressForward/control-by-folder-345
Browse files Browse the repository at this point in the history
Control feed-item display by folder for #345
  • Loading branch information
AramZS committed Oct 20, 2014
2 parents 6afbe0b + a820e24 commit 01b26f5
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 41 deletions.
5 changes: 5 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ h3 {
#tools {
display:none;
}

#feed-folders {
display:none;
}

.primary-btn-tools .btn {
width:100%;
border-radius: 0;
Expand Down
6 changes: 3 additions & 3 deletions assets/css/susy.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
display: block;
}

#tools {
#tools, #feed-folders {
float: right;
width: 25%;
padding: 40px;
}
#tools h2 {
#tools h2, #feed-folders h2 {
font-size: 1.125em;
line-height: 1.55556em;
}
Expand Down Expand Up @@ -198,4 +198,4 @@
font-size: 1.75em;
line-height: 2em;
}
}
}
2 changes: 1 addition & 1 deletion assets/js/sort-imp.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jQuery(window).load(function() {


function pf_show_unsort(){
console.log('b');
//console.log('b');
jQuery('.feedsort').on('click', function() {
console.log('a');
jQuery('#sort-reset').show();
Expand Down
56 changes: 55 additions & 1 deletion assets/js/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,71 @@ jQuery(window).load(function() {
}
);

jQuery('#gomenu').click(function (evt){
evt.preventDefault();
jQuery('#feed-folders').hide('slide',{direction:'right', easing:'linear'},150);
});

jQuery('#gomenu').toggle(function (evt){
evt.preventDefault();
var toolswin = jQuery('#tools');
jQuery("div.pf_container").removeClass('full');
jQuery('#feed-folders').hide('slide',{direction:'right', easing:'linear'},150);
jQuery(toolswin).show('slide',{direction:'right', easing:'linear'},150);
}, function() {
}, function() {
var toolswin = jQuery('#tools');
//jQuery('#feed-folders').hide('slide',{direction:'right', easing:'linear'},150);
jQuery(toolswin).hide('slide',{direction:'right', easing:'linear'},150);
jQuery("div.pf_container").addClass('full');
});
jQuery('#gofolders').click(function (evt){
evt.preventDefault();
jQuery('#tools').hide('slide',{direction:'right', easing:'linear'},150);
});
jQuery('#gofolders').toggle(function (evt){
evt.preventDefault();
var folderswin = jQuery('#feed-folders');
jQuery("div.pf_container").removeClass('full');

jQuery(folderswin).show('slide',{direction:'right', easing:'linear'},150);
}, function() {
var folderswin = jQuery('#feed-folders');
//jQuery('#tools').hide('slide',{direction:'right', easing:'linear'},150);
jQuery(folderswin).hide('slide',{direction:'right', easing:'linear'},150);
jQuery("div.pf_container").addClass('full');
});



jQuery('#feed-folders .folder').click(function (evt){
evt.preventDefault();
var obj = jQuery(this);
var id = obj.attr('href');
var url = window.location.origin+window.location.pathname+'?page=pf-menu';
//url = url.replace('#','');
if (url.indexOf('?') > -1){
url += '&folder='+id;
}else{
url += '?folder='+id;
}
window.location.href = url;
});

jQuery('#feed-folders .feed').click(function (evt){
evt.preventDefault();
var obj = jQuery(this);
var id = obj.children('a').attr('href');
var url = window.location.origin+window.location.pathname+'?page=pf-menu';
//url = url.replace('#','');
if (url.indexOf('?') > -1){
url += '&feed='+id;
}else{
url += '?feed='+id;
}
window.location.href = url;
});


jQuery(".refreshfeed").click(function (evt){
evt.preventDefault();
jQuery('.loading-top').show();
Expand Down
12 changes: 12 additions & 0 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ function add_pf_body_class($classes) {
return $classes;
}

public function folderbox(){
?>
<div id="feed-folders">
<?php printf(__('<h3>Folders</h3>'));
pressforward()->pf_feeds->the_feed_folders();
?>
</div>
<?php
}

public function toolbox($slug = 'allfeed', $version = 0, $deck = false){
global $hook_suffix;
if(!empty($hook_suffix)){
Expand Down Expand Up @@ -665,6 +675,7 @@ public function display_reader_builder() {
</header><!-- End Header -->
<div role="main">
<?php $this->toolbox(); ?>
<?php $this->folderbox(); ?>
<div id="entries">
<?php echo '<img class="loading-top" src="' . PF_URL . 'assets/images/ajax-loader.gif" alt="Loading..." style="display: none" />'; ?>
<div id="errors">
Expand Down Expand Up @@ -704,6 +715,7 @@ public function display_reader_builder() {
} else {
echo '<a class="btn btn-small" id="gomenu" href="#">' . __('Menu', 'pf') . ' <i class="icon-tasks"></i></a>';
}
echo '<a class="btn btn-small" id="gofolders" href="#">' . __('Folders', 'pf') . '</a>';
?>

</div>
Expand Down
30 changes: 16 additions & 14 deletions includes/feed-items.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,23 @@ public static function archive_feed_to_display( $pageTop = 0, $pagefull = 20, $f
}

if (isset($_GET['feed'])) {
$post_args['post_parent'] = pressforward()->pf_feeds->post_type;
$post_args['post_parent'] = $_GET['feed'];
} elseif (isset($_GET['folder'])){
$parents_in_folder = new WP_Query(array(
'post_type' => 'pf_feeds',
'fields' => 'ids',
'update_post_meta_cache' => false,
'tax_query' => array(
array(
'taxonomy' => pressforward()->pf_feeds->tag_taxonomy,
'field' => 'term_id',
'terms' => $_GET['folder']
)
)
));
$post_args['post_parent__in'] = $parents_in_folder;
$parents_in_folder = new WP_Query( array(
'post_type' => pressforward()->pf_feeds->post_type,
'fields'=> 'ids',
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'tax_query' => array(
array(
'taxonomy' => pressforward()->pf_feeds->tag_taxonomy,
'field' => 'term_id',
'terms' => $_GET['folder']
),
),
) );
#var_dump('<pre>'); var_dump($parents_in_folder); die();
$post_args['post_parent__in'] = $parents_in_folder->posts;
}

$feed_items = new WP_Query( $post_args );
Expand Down
136 changes: 114 additions & 22 deletions includes/feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ public function move_feed_tags_submenu( $pf ) {
}

public function is_feed_term($id){
if (!term_exists($id, $this->tag_taxonomy)){
#var_dump($id);
$termcheck = term_exists((int) $id, $this->tag_taxonomy);
if (empty($termcheck)){
return false;
} else {
return true;
Expand Down Expand Up @@ -176,12 +178,17 @@ public function get_child_feed_folders($ids = false){
}
} elseif (is_numeric($ids) || is_string($ids)) {
if(!$this->is_feed_term($ids)){
var_dump($ids.' not a term in '.$this->tag_taxonomy);
return false;
}
$children[$ids] = $this->get_feed_folders($ids);
$children_terms = get_term_children( $ids, $this->tag_taxonomy );
#var_dump($children_terms);
foreach ($children_terms as $child){
$children[$child] = $this->get_feed_folders($child);
}
} elseif (is_array($ids)){
foreach ($ids as $id){
$children[$id] = $this->get_child_feed_folders($id);
$children[$id] = $this->get_feed_folders($id);
}
} elseif (is_object($ids)) {
$children[$ids->term_id] = get_term_children($ids->term_id, $this->tag_taxonomy);
Expand All @@ -192,25 +199,12 @@ public function get_child_feed_folders($ids = false){
}

public function get_child_folders($folder){
$child_folders = array();
if (is_object($folder)){
$children = $this->get_child_feed_folders($folder->term_id);
} else if (is_string($folder) || is_numeric($folder)) {
$children = $this->get_term_children($folder, $this->tag_taxonomy);
} else {
$children = false;
}
#return $children;
if (!$children){
$child_folders = false;
} elseif (is_array($children)) {
$children = get_term_children($folder->term_id, $this->tag_taxonomy);
$folders = array();
foreach ($children as $child){
$child_folders[$child->term_id] = $this->get_feed_folders($child->term_id);
$folders[$child] = $this->get_feed_folders($child);
}
} else {
$child_folders[$folder] = $children;
}
return $child_folders;
return $folders;
}

public function get_feed_folders($ids = false){
Expand All @@ -221,6 +215,7 @@ public function get_feed_folders($ids = false){

$folder_set[$folder->term_id] = array(
'term' => $folder,
'term_id' => $folder->term_id,
'children' => array(
'feeds' => get_objects_in_term($folder->term_id, $this->tag_taxonomy),
'folders' => $this->get_child_folders($folder)
Expand All @@ -229,14 +224,16 @@ public function get_feed_folders($ids = false){
}
} elseif (is_numeric($ids)) {
$folder = get_term($ids, $this->tag_taxonomy);
$folder_set[$ids] = array(
$folder_set = array(
'term' => $folder,
'term_id' => $folder->term_id,
'children' => array(
'feeds' => get_objects_in_term($folder->term_id, $this->tag_taxonomy),
'folders' => $this->get_child_folders($folder)
)
);
} elseif (is_array($ids)){
#var_dump($ids); die();
foreach ($ids as $id){
$folder_set[$id] = $this->get_feed_folders($id);
}
Expand All @@ -248,7 +245,102 @@ public function get_feed_folders($ids = false){

}

public function disallow_add_new(){
public function the_feed_folders($obj = false){
if(!$obj){
$obj = $this->get_feed_folders();
}
?><ul class="feed_folders">
<?php
#var_dump($obj);
foreach($obj as $folder){
?>
<li class="feed_folder" id="folder-<?php echo $folder['term_id']; ?>">
<?php
$this->the_inside_of_folder($folder);
?>
</li>
<?php
}
?>
</ul>
<?php
}

public function the_inside_of_folder($folder, $wrapped = false){
if ($wrapped){
?>
<li class="feed_folder" id="folder-<?php echo $folder['term_id']; ?>">
<?php
}
$this->the_folder($folder);

#var_dump($folder);
if (!empty($folder['children']['folders'])){
foreach ($folder['children']['folders'] as $subfolder){
?>
<ul class="feed_inner_folders">
<?php
$this->the_inside_of_folder($subfolder, true);
?>
</ul>
<?php

}
}

if (!empty($folder['children']['feeds'])){
?>
<ul class="feed_inner_feeds">
<?php
foreach ($folder['children']['feeds'] as $feed){
?>
<?php
$this->the_feed($feed);
?>
<?php
}
?>
</ul>
<?php
}
if ($wrapped){
?>
</li>
<?php
}
}

public function the_folder($folder){
#var_dump($folder);
if(is_array($folder)){
$term_obj = $folder['term'];
} else {
$term_obj = $folder;
}
?>

<?php
printf('<a href="%s" class="folder" title="%s">%s</a>', $term_obj->term_id, $term_obj->name, $term_obj->name );

?>

<?php
}

public function the_feed($feed){
$feed_obj = get_post($feed);
?>
<li class="feed" id="feed-<?php echo $feed_obj->ID; ?>">
<?php

printf('<a href="%s" title="%s">%s</a>', $feed_obj->ID, $feed_obj->post_title, $feed_obj->post_title );

?>
</li>
<?php
}

public function disallow_add_new(){
global $pagenow;
/* Check current admin page. */
if($pagenow == 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] == $this->post_type){
Expand Down

0 comments on commit 01b26f5

Please sign in to comment.