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/yayotube.com/wp-content/plugins/wp-ayb-aspsharedlogins.php
<?php
/*
Plugin Name: AYB AutoSocialPoster Shared Logins
Plugin URI: http://www.automateyourbusiness.com/wp-ayb-asp-shared-logins/
Description: Updates your ASP logins from a shared option
Version: 1.0
Author: Andrew Peacock
Author URI: http://www.automateyourbusiness.com
*/

/*  Copyright 2007  Andrew Peacock  (email : http://www.automateyourbusiness.com/contact/)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/*

HISTORY
1.1		- Increased user-friendliness
		- 
1.0 	- Initial version (not publicly released)

TO DO
- Add username/password protection option
- 

*/





// ASP Integration --------------------------------------------------------------------------------
function ayb_aspsharedlogins_get_conf_file() {
	// Get the list of plugins
	global $current_plugins;
	
	// Work out the install folder
	foreach ( $current_plugins as $plugin_file) {
		$wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;
	
		if (preg_match("|(.*?)\/mm_post\.php|", $plugin_file, $matches)) {
			$ASPfolder = $matches[1];
		}
	}
	
	if ($ASPfolder <> "") {
		define('MM_CONF_FILE', $ASPfolder . '/mm_conf.php');
		define('ASP_FOLDER', $ASPfolder);
	} else {
		define('MM_CONF_FILE', '');
		define('ASP_FOLDER', '.');
	}
}

function ayb_aspsharedlogins_import() {

	$url = get_option("ayb_aspsharedlogins_url");

	$host = parse_url($url);
	
	$url = str_replace("http://" . $host["host"], "", $url);
	
	if ($url) {
		$fp = fsockopen($host["host"], 80, $errno, $errstr, 30);
		if (!$fp) {
	   		//echo "Error opening $url: $errstr ($errno)<br />\n";
	   		return false;
		} else {
		   	$out = "GET $url HTTP/1.1\r\n";
		   	$out .= "Host: ". $host["host"]. "\r\n";
		   	$out .= "Connection: Close\r\n\r\n";
		
		   	fwrite($fp, $out);
	   		while (!feof($fp)) {
	       		$response .= fgets($fp, 128);
	   		}
		   	fclose($fp);
		}
		
		$response=split("\r\n\r\n",$response);
		$header=$response[0];
        $content=$response[1];
		
		// Now write to the conf file
		$fh = fopen(MM_CONF_FILE,'w');
		fwrite($fh, $content);
		fclose($fh);
			
		update_option("ayb_aspsharedlogins_logins", $content);
	}

	return true;
}

function ayb_aspsharedlogins_export() {
	$content = file_get_contents(MM_CONF_FILE);
	return $content;
}


// Admin Screens ----------------------------------------------------------------------------------
function ayb_aspsharedlogins_add_option_page() {
    if (function_exists('add_options_page')) {
		add_options_page('ASP Shared Logins', 'ASP Shared Logins', 5, basename(__FILE__), 'ayb_asp_show_option_page');
    }
}

function ayb_asp_show_option_page() {
	
	if(isset($_POST["submit"])) {
		switch($_POST["type"]) {
			case "import":
				if (ayb_aspsharedlogins_import($_POST["ayb_aspsharedlogins_url"])) {
					echo '<div class="updated"><p><strong>Import successful.</strong></p>';
					require_once(ABSPATH . PLUGINDIR . '/' . ASP_FOLDER . '/spyc.php');
					$spyc =& new Spyc;
					$mm_opt = array();
					$mm_opt = $spyc->load(MM_CONF_FILE);
					if (count($mm_opt)) {
						$i = 0;
						echo "<table>";
						echo "<tbody><tr><th scope=\"col\">Service</th><th scope=\"col\">&nbsp;</th><th scope=\"col\">Account</th></tr>";
						foreach ($mm_opt as $service => $accounts) {
							foreach ($accounts as $account) {
								$i++;			
								echo sprintf("<tr><td>%s</td><td>&nbsp;</td><td>%s</td></tr>",
										$service, $account['username']);

							}
						}
						if ($i == 0) {
							echo "<tr><td colspan=\"3\">None</td></tr>";
						}
						echo "</table>";
					}
					echo '</div>';
				} else {
					echo '<div class="error"><p><strong>Import failed.</strong></p></div>';
					if (!is_writable(MM_CONF_FILE)) {
						echo '<div class="error"><p><strong>The configuration file ' . MM_CONF_FILE . ' must be writable in order to save account settings.</strong></p></div>';
					}
				}
				break;

			case "export":
				$content = ayb_aspsharedlogins_export();
				echo '
					<div class="updated"><p><strong>Exported Data.</strong></p>
					<p>The following content should be saved to a text file in a secure location accessible via the web:
					<br />
					<textarea cols="60" rows="15">' . $content . '</textarea></p>
					</div>
					';
					
				break;

			case "update":
				$ayb_aspsharedlogins_url = $_POST["ayb_aspsharedlogins_url"];
				update_option("ayb_aspsharedlogins_url", $ayb_aspsharedlogins_url);
				break;
		}
	}
	

	
	$ayb_aspsharedlogins_url = get_option("ayb_aspsharedlogins_url");
	echo '
		<div class="wrap">
	';
	
	echo $message;
	
	if (MM_CONF_FILE == '') {
		echo '<div class="error"><p><strong>The Auto Social Poster file cannot be found. Please activate that plugin and try again.</strong></p></div>';
	} else {

		
		echo '
			<h2>Update Auto Social Poster Shared Login URL</h2>
			<form method="post">
			<input type="hidden" name="type" value="update">
			<p>Enter the URL where the central list of logins is stored (include the http://):<br />
			<input type="text" name="ayb_aspsharedlogins_url" size="60" value="' . $ayb_aspsharedlogins_url . '"></p>
			<p class="submit">
				<input type="submit" name="submit" value="Update Options" />
			</p>
			</form>



			<h2>Import</h2>
			Use this option to manually import a fresh list of accounts from your central copy. Note: each time a post 
			is published, a new copy is downloaded anyway.
			<form method="post">
			<input type="hidden" name="type" value="import">
			<p class="submit">
				<input type="submit" name="submit" value="Import" />
			</p>
			</form>


			<h2>Export</h2>
			Use this option to display your account details. Then copy-and-paste that output to the file which can 
			be found at ' . $ayb_aspsharedlogins_url . '
			<form method="post">
			<input type="hidden" name="type" value="export">
			<p class="submit">
				<input type="submit" name="submit" value="Export" />
			</p>
			</form>
		';

	
	}
	
	echo '
	
		<h2>Help</h2>
		<p>The Auto Social Poster plugin is an extension to the <a href="http://www.automateyourbusiness.com/recommends/autosocialposter/">Auto Social Poster</a> plugin by Anthony Ellis. As such, you need to have 
		purchased, installed, and activated that plugin first.</p>
		<p>Once you have done that, you can find out more about the Auto Social Poster Shared Logins plugin <a href="http://www.automateyourbusiness.com/updates/2007/06/11/auto-social-poster-shared-logins-plugin/" target="_blank">here</a>.</p>
		<p>&nbsp;</p>
		<h2>Donate</h2>
		<p>Although I offer this plugin for free, if you found this plugin useful, feel free to send me 
		a <a href="http://www.automateyourbusiness.com" target="_blank">small donation to say thanks</a> (see the "Buy Me A Beer" link on the right-hand side). Or send me something from <a href="http://www.amazon.co.uk/gp/registry/2DE9CJSYTQT24" target="_blank">my Amazon wishlist</a>, if you like.</p>
	
	</div>';
}


// Plugin integration ----------------------------------------------------------------------------------



// Initiation ----------------------------------------------------------------------------------

function ayb_aspsharedlogins_install() {
	// If text file exists, read the URL from the text file
	if (file_exists(ABSPATH . "wp-content/plugins/wp-ayb-aspsharedlogins-url.txt")) {
		$ayb_aspsharedlogins_url = trim(file_get_contents(ABSPATH . "wp-content/plugins/wp-ayb-aspsharedlogins-url.txt"));
		update_option("ayb_aspsharedlogins_url", $ayb_aspsharedlogins_url);	
	} else {
		update_option("ayb_aspsharedlogins_url", "");	
	}
}


// Activation / De-activation
// Add a one-off load of the URL from a text file
$installed = get_option('ayb_aspsharedlogins_installed');
if ($installed != 1) {
	ayb_aspsharedlogins_install();
	update_option("ayb_aspsharedlogins_installed", 1);
}


// Hooks ----------------------------------------
// Add the custom options page
add_action('admin_menu', 'ayb_aspsharedlogins_add_option_page');
add_action('publish_post', 'ayb_aspsharedlogins_import', 9); // Make sure  this occurs before ASP posting

// Initilisation --------------------------------
// Get ASP options file
ayb_aspsharedlogins_get_conf_file();




?>