Skip to content

Commit

Permalink
log view added in edit-page for ifeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Shayan committed Aug 28, 2016
1 parent 6a36015 commit b686c4f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 19 deletions.
Binary file added assets/arrow_right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/ifeed-script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var query_presenter = jQuery(".ifeed-preview tbody");
var query_presenter = jQuery(".ifeed-post-viewer .ifeed-preview tbody");

jQuery(document).ready(function($){

Expand Down
7 changes: 6 additions & 1 deletion assets/ifeed-style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.ifeed-post-generator > tbody > tr > .left, .ifeed-post-generator > tbody > tr > .right {vertical-align:top;}
.ifeed-post-generator > tbody > tr > .left, .ifeed-post-generator > tbody > tr > .center, .ifeed-post-generator > tbody > tr > .right {vertical-align:top;}
.ifeed-post-generator .ifeed-preview > h2 em {font-size: 11px!important; font-weight: normal!important;}
.ifeed-post-generator .ifeed-preview > em.caution {font-size: 14px!important;}
.ifeed-post-generator .ifeed-preview > button {margin:5px 0;}
Expand All @@ -15,6 +15,11 @@
.ifeed-post-generator .ifeed-preview > table > tbody > tr > td.img-wrapper {width:60px; height:60px;}
.ifeed-post-generator .ifeed-preview > table > tbody > tr > td.img-wrapper > img {width:60px; height:60px;}
.ifeed-post-generator .ifeed-preview > table > tbody > tr > td.execution-time-wrapper > input {width: 130px;}
/* .ifeed-post-generator .ifeed-log-viewer .ifeed-preview {background: transparent url("arrow_right.png") no-repeat scroll 0 65px / 75px auto;margin-top: 119px;padding-left: 90px;} */
.ifeed-post-generator .ifeed-log-viewer .ifeed-preview {position:relative;}
.ifeed-post-generator .ifeed-log-viewer .ifeed-preview em.caution {left: 0;position: absolute;top: -70px;}
.ifeed-post-generator .ifeed-log-viewer .ifeed-preview table {margin-top: 119px;}
.ifeed-post-generator th.ifeed-log-viewer {padding-left:90px;}

/** GENERAL **/
[name="ifeed-settings"] input.error {border-color: #d9534f!important;}
Expand Down
23 changes: 19 additions & 4 deletions ifeed_ajax_post_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ function ifeed_ajax_post_loader() {
// }
}

if(isset($query['post__not_in']) && $query['post__not_in'] !== false) {
$query['post__not_in'] = json_decode($query['post__not_in'], true);
if(isset($query['post__not_in']) && $query['post__not_in']=="sticky" ) {
$query['post__not_in'] = get_option( 'sticky_posts' );
$query['ignore_sticky_posts'] = 1;
}

$query['caller_get_posts'] = 1;

$posts = null;
try{
// wp_reset_query();
$posts = new WP_Query($query);
// var_dump($query);
// var_dump($posts);
Expand All @@ -71,7 +75,7 @@ function ifeed_ajax_post_loader() {
if ( strlen(serialize($posts))>0 && $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();

if( in_array(get_the_ID(), $query['post__not_in'] ) ) continue;
// if( in_array(get_the_ID(), $query['post__not_in'] ) ) continue;
$execution_string = "Unknown";
if($hours_set!==false) {
$execution_string = $ifeed_execution_date->format('Y-m-d') .' '. $hours_set[$ifeed_execution_hour_index].':00';
Expand All @@ -86,6 +90,7 @@ function ifeed_ajax_post_loader() {
ifeed_print_post_row(get_the_ID(), get_the_title(), get_the_permalink(), gmdate("Y-m-d", get_the_time('U')), get_the_post_thumbnail(null,'thumbnail'), $index, $execution_string, (!isset($query['p'])));
$index++;
endwhile;
wp_reset_query();
else :
die("empty_post");
endif;
Expand All @@ -95,16 +100,26 @@ function ifeed_ajax_post_loader() {


if(function_exists('ifeed_print_post_row')) {wp_die( __('iFeed-error: Duplicate function name, remove function: "ifeed_print_post_row"') );} else {
function ifeed_print_post_row($id, $title, $permalink, $created_time, $thumbnail, $index, $execution_string, $with_tr=true) {
function ifeed_print_post_row($id, $title, $permalink, $created_time, $thumbnail, $index, $execution_string, $with_tr=true, $actions=true) {
if($with_tr) : ?>
<tr>
<?php endif; ?>
<?php if($actions) { ?>
<td class="post-id-wrapper"><input type="text" value="<?php echo $id ?>" /></td>
<?php } else { ?>
<td class="post-id-wrapper"><?php echo $id ?></td>
<?php } ?>
<td class='title-wrapper'><a title="<?php echo $title ?>" href="<?php echo $permalink ?>"><?php echo $title ?></a></td>
<td><?php echo $created_time; ?></td>
<td class='img-wrapper'><?php echo $thumbnail ?></td>
<?php if($actions) { ?>
<td class='execution-time-wrapper'><input type="text" data-name="exec-time" data-id="<?php echo $index; ?>" value="<?php echo $execution_string; ?>" /></td>
<?php } else { ?>
<td class='execution-time-wrapper'><?php echo $execution_string; ?></td>
<?php } ?>
<?php if($actions) { ?>
<td class='remove'><button type="button" data-action="remove-post-query" class="button-secondary"><?php _e("X"); ?></button></td>
<?php } ?>
<?php if( $with_tr ) : ?>
</tr>
<?php
Expand Down
46 changes: 43 additions & 3 deletions ifeed_edit_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ function ifeed_options_page_edit() {
<tr valign="top">
<th scope="row"><?php _e("iFeed Slug:"); ?></th>
<td><fieldset><p>
<input type="text" name="ifeed-slug" class="<?php echo (isset($input_errors['ifeed-slug']))? 'error '.$input_errors['ifeed-slug'] : ''; ?>" <?php echo ($ifeed_ID=="")? "" : 'readonly="readonly"' ?> size="20" placeholder="Unique name for iFeed" value="<?php echo $vals['ifeed-slug']; ?>"/>
<input type="text" name="ifeed-slug" class="<?php echo (isset($input_errors['ifeed-slug']))? 'error '.$input_errors['ifeed-slug'] : ''; ?>" <?php echo ($ifeed_ID=="")? "" : 'readonly="readonly"'; ?> size="20" placeholder="Unique name for iFeed" value="<?php echo $vals['ifeed-slug']; ?>"/>
&nbsp;<em><?php _e("Unique name for ifeed, also will be used for calling ifeed by URL"); ?></em>
<?php if($ifeed_ID!="") { $ifeed_url = get_bloginfo('rss2_url')."ifeed?title=".$vals['ifeed-slug']; ?>
<br />
<a href="<?php echo $ifeed_url ?>"><?php echo $ifeed_url ?></a>
<?php } ?>
</fieldset></td></p>
</tr>
<tr valign="top">
Expand All @@ -123,6 +127,7 @@ function ifeed_options_page_edit() {
<thead><tr>
<th><?php _e("Automatic Query"); ?></th>
<th><?php _e("Preview / Manual"); ?></th>
<th class="ifeed-log-viewer"><?php _e("iFeed Log"); ?></th>
</tr></thead>
<tbody>
<tr><td class="left ifeed-query-builder">
Expand Down Expand Up @@ -214,14 +219,14 @@ function ifeed_options_page_edit() {
<td><fieldset><p>
<select class="ifeed-query-builder" data-name="post__not_in">
<option value="" <?php echo (!isset($vals['ifeed-auto-query']['post__not_in']))? 'selected="selected"' : ''; ?>><?php _e("ignore"); ?></option>
<option value="<?php echo json_encode(get_option('sticky_posts')); ?>" <?php echo ($vals['ifeed-auto-query']['post__not_in']=="get_option('sticky_posts')")? 'selected="selected"' : ''; ?> ><?php _e("Sticky Posts"); ?></option>
<option value="sticky" <?php echo ($vals['ifeed-auto-query']['post__not_in']=="get_option('sticky_posts')")? 'selected="selected"' : ''; ?> ><?php _e("Sticky Posts"); ?></option>
</select>
<br /><em><b><?php _e("Caution"); ?></b>:&nbsp;<?php _e("changing this value will reset the offset."); ?></em>
</fieldset></td></p>
</tr>
</tbody>
</table>
</td><td class="right ifeed-post-viewer">
</td><td class="center ifeed-post-viewer">
<div class="ifeed-preview">
<h2><label><input type="checkbox" name="ifeed-query-manual" <?php echo (isset($vals['ifeed-query-manual'])&&$vals['ifeed-query-manual']!==null)? 'checked="checked"' : ""; ?>><span><?php _e("Manual select posts"); ?></span></label><em>&nbsp; (will inhibit automatic query)</em></h2>
<em class='caution'><b><?php _e("Note"); ?>:</b>&nbsp;<?php _e("Every change on box below (change in post-id or clearing the list) will tick the \"Manual select posts\"."); ?></em>
Expand Down Expand Up @@ -260,6 +265,41 @@ function ifeed_options_page_edit() {
</table>
<button type="button" data-action="add-post-query" class="button-primary"><?php _e("add post"); ?></button>
</div>
</td>
<td class="right ifeed-log-viewer">
<div class="ifeed-preview">
<em class='caution'><b><?php _e("Note"); ?>:</b>&nbsp;<?php _e("First element of below table is showing the post that is live on rss-ifeed right now, others shows previous posts were in ifeed."); ?></em>
<table>
<thead><tr>
<th><?php _e("post ID"); ?></th>
<th><?php _e("Title"); ?></th>
<th><?php _e("Created Date"); ?></th>
<th><?php _e("Image"); ?></th>
<th><?php _e("Executed Time"); ?></th>
</tr></thead>
<tbody>
<?php
if(isset($vals['log_posts']))
$vals['log_posts'] = json_decode($vals['log_posts'], true);
if( is_array($vals['log_posts']) && count($vals['log_posts'])>0 ) {
foreach( array_reverse($vals['log_posts']) as $index=>$log_post ) {
$post = null;
try{
$post = new WP_Query(array('p'=> $log_post['post_id'] ));
} catch(Exception $e) { echo "Exception:". $e->getMessage();}
if ( strlen(serialize($post))>0 && $post->have_posts() ) :
while ( $post->have_posts() ) : $post->the_post();

$execution_string = (isset($log_post['added_time']))? $log_post['added_time'] : "Unknown";
ifeed_print_post_row(get_the_ID(), get_the_title(), get_the_permalink(), gmdate("Y-m-d", get_the_time('U')), get_the_post_thumbnail(null,'thumbnail'), $index, $execution_string, (!isset($query['p'])), false);
endwhile;
endif;
}
}
?>
</tbody>
</table>
</div>
</td></tr>
</tbody>
</table>
Expand Down
6 changes: 4 additions & 2 deletions ifeed_list_class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
if ( !class_exists( 'WP_List_Table_ifeed' ) ) {
include_once( plugin_dir_path( __FILE__ ) . 'class-wp-list-table-ifeed.php' );
include_once( plugin_dir_path( __FILE__ ) . '/includes/class-wp-list-table-ifeed.php' );
if(!class_exists( 'WP_List_Table_ifeed' )) {wp_die( __('iFeed-error: class not found: "WP_List_Table_ifeed"') );}
}

Expand Down Expand Up @@ -125,9 +125,11 @@ public function column_default( $item, $column_name ) {
return $this->column_name($item,$column_name);
case 'utm':
case 'description':
return $item[ $column_name ];
case 'manual':
return ($item[ $column_name ]==1)? "Manual" : "Auto";
case 'active':
return $item[ $column_name ];
return ($item[ $column_name ]==1)? "Active" : "Deactive";
default:
return print_r( $item, true ); //Show the whole array for troubleshooting purposes
}
Expand Down
11 changes: 3 additions & 8 deletions ifeed_refresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ function ifeed_refresher() {
$now = new DateTime(null, new DateTimeZone('Asia/Tehran'));
$curr_day_hour = $now->format('Y-m-d H:00');
echo $curr_day_hour;
echo "<br />agent: ";
var_dump($ifeed['agent']);
if( isset($manual_post_next['exec_time']) && $curr_day_hour == $manual_post_next['exec_time'] ) {
// now it's the time!
echo "<br />now its the time!";
array_shift($manual_posts);
// pop from beginning of online_posts
array_shift($online_posts);
// add at end of online_posts
array_push($online_posts, $manual_post_next['post_id']);
array_push($online_posts, intval($manual_post_next['post_id']));
// log this addition to ifeed
array_push($log_posts, array(
'post_id' => $manual_post_next['post_id'],
Expand Down Expand Up @@ -55,18 +53,15 @@ function ifeed_refresher() {
}
} else {
// auto query
echo "<br />auto: ";
$query = json_decode($ifeed['query'], true);
$hours_set = json_decode($query['hours_set']);
unset($query['hours_set']);
var_dump($hours_set);
$now = new DateTime(null, new DateTimeZone('Asia/Tehran'));
$curr_hour = (int)$now->format('H');
$curr_day_hour = $now->format('Y-m-d H:00');

$log_posts = (isset($ifeed['log_posts']) && $ifeed['log_posts']!=null)? json_decode($ifeed['log_posts'], true) : array();
$last_log_post = reset($log_posts);
echo "<br />Current Hour: ". $curr_hour;
$last_log_post = end($log_posts);
// var_dump($query);
if( in_array($curr_hour, $hours_set) &&
(!isset($last_log_post['promissed_exec_time']) || $last_log_post['promissed_exec_time'] != $curr_day_hour) ) {
Expand Down Expand Up @@ -114,7 +109,7 @@ function ifeed_refresher() {
// pop from beginning of online_posts
array_shift($online_posts);
// add at end of online_posts
array_push($online_posts, $next_post_id);
array_push($online_posts, intval($next_post_id));
// log this addition to ifeed
array_push($log_posts, array(
'post_id' => $next_post_id,
Expand Down
File renamed without changes.

0 comments on commit b686c4f

Please sign in to comment.