HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: /home/httpd/html/100livecam.com/DEAD/wp-content/plugins/dd-scheduled-post-shift.php
<?php
/*
Plugin Name: Scheduled Post Shift
Plugin URI: http://www.dagondesign.com/articles/scheduled-post-shift-plugin-for-wordpress/
Description: Automatically takes your oldest post and moves it to the front by updating its timestamp.
Author: Dagon Design
Version: 1.3
Author URI: http://www.dagondesign.com
*/


$ddps_version = '1.3';

add_action('admin_menu', 'ddps_add_option_pages');
add_action('ddps_postshift', 'ddps_postshift');



// Setup defaults if options do not exist
add_option('ddps_enabled', FALSE);
add_option('ddps_cat', '');
add_option('ddps_delay', 24);
add_option('ddps_logfile', ABSPATH . 'wp-content/plugins/dd-scheduled-draft-publish.log');

function ddps_add_option_pages() {
	if (function_exists('add_options_page')) {
		add_options_page('Post Shift', 'DDPostShift', 8, __FILE__, 'ddps_options_page');
	}		
}

function ddps_options_page() {

	global $ddps_version;

	if (isset($_POST['enable_post_shift'])) {

		?><div id="message" class="updated fade"><p><strong><?php 

		update_option('ddps_enabled', TRUE);
		update_option('ddps_cat', stripslashes((string)$_POST['ddps_cat']));
		update_option('ddps_delay', (int)$_POST['ddps_delay']);
		update_option('ddps_logfile', stripslashes((string)$_POST['ddps_logfile']));

		if ((int)$_POST['ddps_delay'] < 1) {
			update_option('ddps_delay', 1);
		}

		wp_clear_scheduled_hook('ddps_postshift');
		wp_schedule_event(((int)get_option('ddps_delay') * 3600), 'ddps_schedule', 'ddps_postshift' );

		echo "Post Shift Enabled!";

	    ?></strong></p></div><?php

	} else if (isset($_POST['disable_post_shift'])) {

		?><div id="message" class="updated fade"><p><strong><?php 

		update_option('ddps_enabled', FALSE);

		wp_clear_scheduled_hook('ddps_postshift');

		echo "Post Shift Disabled!";

	    ?></strong></p></div><?php

	} else if (isset($_POST['info_update'])) {

		?><div id="message" class="updated fade"><p><strong><?php 

		update_option('ddps_enabled', (bool) $_POST["ddps_enabled"]);
		update_option('ddps_cat', stripslashes((string)$_POST['ddps_cat']));
		update_option('ddps_delay', (int)$_POST['ddps_delay']);
		update_option('ddps_logfile', stripslashes((string)$_POST['ddps_logfile']));

		if ((int)$_POST['ddps_delay'] < 1) {
			update_option('ddps_delay', 1);
		}

		if (get_option('ddps_enabled') == TRUE) {
			wp_clear_scheduled_hook('ddps_postshift');
			wp_schedule_event( time()+10, 'ddps_schedule', 'ddps_postshift' );
		}

		echo "Configuration Updated!";

	    ?></strong></p></div><?php

	} else if (isset($_POST['clear_log'])) {
          $logfile=get_option('ddps_logfile');
          $fh = @fopen($logfile, "w");
          @fwrite($fh, strftime("%D %T")."\t<strong><font color=\"#FF0000\">Log file cleared</font></strong>\n\t&#9472;&#9472;&#9472;&#9472;&#9472;\n");
          @fclose($fh);
	  echo "<div id='message' class='updated fade'><p><strong>Log file cleared!</strong></p></div>";
        }
	?>

	<div class=wrap>

	<h2>Scheduled Post Shift v<?php echo $ddps_version; ?></h2>

	<p>For information and updates, please visit:<br />
	<a href="http://www.dagondesign.com/articles/scheduled-post-shift-plugin-for-wordpress/">http://www.dagondesign.com/articles/scheduled-post-shift-plugin-for-wordpress/</a></p>


	<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
	<input type="hidden" name="info_update" id="info_update" value="true" />


	<div style="padding: 0 0 30px 20px;">

	<h3>Current Status: <?php echo (get_option('ddps_enabled') == TRUE) ? 'Enabled' : 'Disabled'; ?></h3>

	<?php if (get_option('ddps_enabled') == TRUE) { ?>
		<input type="submit" name="disable_post_shift" value="<?php _e('Disable Post Shift'); ?> &raquo;" />
	<?php } else { ?>
		<input type="submit" name="enable_post_shift" value="<?php _e('Enable Post Shift'); ?> &raquo;" />
	<?php } ?>

	</div>

	<h3>Options</h3>

	<table width="100%" border="0" cellspacing="0" cellpadding="6">

	<tr valign="top"><td width="25%" align="right">
		<strong>Shift Delay</strong>
	</td><td align="left">
		<input name="ddps_delay" type="text" size="10" value="<?php echo htmlspecialchars(get_option('ddps_delay')); ?>"/>
		<br />The number of <strong>hours</strong> between post shifts
	</td></tr>

	<tr valign="top"><td width="25%" align="right">
		<strong>Category ID(s)</strong>
	</td><td align="left">
		<input name="ddps_cat" type="text" size="10" value="<?php echo htmlspecialchars(get_option('ddps_cat')); ?>"/>
		<br />If left blank, the plugin will use posts from all categories
		<br />If you enter one or more category IDs, it will only update posts from those categories
		<br />Separate multiple category IDs with commas
	</td></tr>
	
	
		<tr valign="top"><td width="25%" align="right">
                <strong>Log File</strong>
        </td><td align="left">
                <input name="ddps_logfile" type="text" size="100" value="<?php echo htmlspecialchars(get_option('ddps_logfile')); ?>"/>
                <br />You can leave this specific to this blog, or set up a global log for multiple blogs.
        </td></tr>
        

	</table>

	<div class="submit">
		<input type="submit" name="info_update" value="<?php _e('Update options'); ?> &raquo;" />
	        <input type="submit" name="clear_log" value="<?php _e('Clear Log File'); ?>" onclick="return confirm(\'Are you sure you want to clear the log file?\');" />
	</div>
	
	</form>
	
		
		<P>
        <h2>Scheduled Draft Publish log</h2>
        <p><code>
<?php
   PS_get_last_log_entries();
?>
	</code></p>
	
	
	</div><?php
}





function ddps_postshift() {

	global $wpdb;


	$tp = $wpdb->prefix;

	// Currently using a work-around for the version system
	// determines if pre or post 2.3 from wp_term_taxonomy 

	$ver = 2.2;
	$wpv = $wpdb->get_results("show tables like '{$tp}term_taxonomy'");
	if (count($wpv) > 0) {
		$ver = 2.3;
	}


	$the_cat = '(' . trim(get_option('ddps_cat'), ',') . ')';


	if ($the_cat == "()") {

		$oldest_post = $wpdb->get_var("
		SELECT ID 
		FROM {$tp}posts
		WHERE post_type = 'post'
		AND post_status = 'publish' 
		GROUP BY post_date asc
		");


	} else {

		if ($ver < 2.3) {

			$oldest_post = $wpdb->get_var("
			SELECT ID 
			FROM {$tp}posts, {$tp}post2cat
			WHERE {$tp}post2cat.category_id IN " . $the_cat . "  
			AND post_type = 'post'
			AND {$tp}posts.post_status = 'publish' 
			AND {$tp}post2cat.post_id = {$tp}posts.ID
			GROUP BY post_date asc 
			");

		} else { // post 2.3+

			$oldest_post = $wpdb->get_var("
			SELECT ID 
			FROM {$tp}posts, {$tp}term_relationships, {$tp}term_taxonomy 
			WHERE {$tp}term_taxonomy.term_id IN " . $the_cat . "  
			AND {$tp}term_taxonomy.term_taxonomy_id = {$tp}term_relationships.term_taxonomy_id 
			AND {$tp}term_relationships.object_id = {$tp}posts.ID 
			AND {$tp}posts.post_type = 'post' 
			AND {$tp}posts.post_status = 'publish' 
			GROUP BY post_date asc
			");

		}

	}
	
	

	if ($oldest_post > 0) { # we have a post to shift

		# what wordpress func to call for setting post_name instead?
		$post_title = $wpdb->get_var("
		SELECT post_title
		FROM {$tp}posts
		WHERE ID = '$oldest_post'
		");
        
		# what wordpress func to call for setting post_name instead?

		$new_time = date('Y-m-d H:i:s');
		$wpdb->query("UPDATE $wpdb->posts SET post_date = '$new_time' WHERE ID = '$oldest_post'");
		
		wp_publish_post($oldest_post);
		
		SDP_log(strftime("%D %T") . "\t" . $tp . "\tPOST id " . $selected_draft . " SHIFTED  '" . $post_title . "'\n");

	} else {
		  PS_log(strftime("%D %T") . "\t\t" . $tp . "\tUnable to find a post to shift.\n");
	}
}




function more_reccurences() {
    return array(
        'ddps_schedule' => array('interval' => ((int)get_option('ddps_delay') * 3600), 'display' => 'Post Shift Schedule')
    );
}


function PS_log($PS_log_output)
{
   $logfile=get_option('ddps_logfile');
   $fh = @fopen($logfile, "a");
   @fwrite($fh, $PS_log_output);
   @fclose($fh);
}

function PS_get_last_log_entries()
{
   $logfile=get_option('ddps_logfile');
   $lines = @file($logfile);
    if($lines === false){
	 echo "Error reading log file (".$logfile."). <strong>Most likely you have manually removed the log file</strong>, or alternatively this could mean that the logfile is read-protected (change the rights of this file to 777)')";
    }else{
      $msg = "";
      foreach($lines as $line){
         $msg.=trim($line)."<br />";
      }
      echo $msg;
    }
}


add_filter('cron_schedules', 'more_reccurences');

?>