<?php

#########################################################################################################
# Project:				PHPLinkDirectory: Link exchange directory @ http://www.phplinkdirectory.com/	#
# Mod:					[Article Importer] @ http://www.monster-submit.com/phpld/						#
# Version:				1.00200906251																	#
# Notice:				Maintain this section															#
# Author:				Virtual Solutions																#
# Idea by and																							#
# contributed to by:	Matt @ http://www.thecanad1an.com												#
# License:				Copyright (c) 2008 - 2009 Virtual Solutions										#
#																										#
# Any redistribution of phpLD_Vault mods without the expressed written consent of Virtual Solutions is	#
# strictly prohibited. Copying any of the code contained within any phpLD_Vault mod and claiming it as	#
# your own is also prohibited. You may not remove any header notices from any mods. By using these		#
# phpLD_Vault mods, you agree to indemnify Virtual Solutions from any liability that might arise from	#
# their use.																							#
#																										#
# PHPLD_VAULT MODS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING	#
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND			#
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES	#
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN	#
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.							#
#########################################################################################################

##########################################################################
#  Do NOT change or alter the code below!
##########################################################################

require_once 'init.php';

$version = CURRENT_VERSION;
$version = preg_replace('/\.(\d+) RC(.*)$/', '', $version);
$tpl->assign('version', $version);
if ($version < "3.3.0") { define('ADMIN_TEMPLATE', 'admin'); }

function error($error) {
	echo $error;
	exit;
}

if ($_POST['submit']) {
	$provider		= $_POST['provider'];
	if (! $provider) { error("No required [Article Provider] selected"); }
	$url			= $_POST['url'];
	if (! $url) { error("No required [Article URL] entered"); }
    if (! preg_match('!^http(s)?://[\w-]+\.[\w-]+(\S+)?$!i', $url)) { error("Invalid URL"); }
	$ret			= get_url($url);
	if (! $ret['status']) { error("Cannot connect :: " . $ret['response']); }
	$format			= $_POST['format'];
	if (! $format) { error("No required [Article Format] selected"); }
	if (REQUIRE_REGISTERED_USER_ARTICLE == 1) {
		$owner_id		= $_POST['OWNER_ID'];
		if (! $owner_id) { error("No required [Owner] selected"); }
	}
	$category_id	= $_POST['CATEGORY_ID'];
	if (! $category_id) { error("No required [Category] selected"); }
	$article_type	= $_POST['ARTICLE_TYPE'];
	if ($article_type = "") { error("No required [Article Type] selected"); }
	$status		= $_POST['STATUS'];
	if ($status == "") { error("No required [Status] selected"); }
	$link_attribute	= $_POST['link_attribute'];
	$maxlinks	= $_POST['maxlinks'];
	if ($maxlinks == "") { error("No required [Max Links] selected"); }
	if (! file_exists("artimporter/" . $provider)) { error("Cannot locate importer file [artimporter/$provider]"); }
	include "artimporter/" . $provider;
	echo "<br/>Import job done!<br/>\n";
	exit;
}

if ($dir = @opendir("./artimporter/")) {
	while (($file = readdir($dir)) !== false) {
		if (preg_match("/\.php$/", $file)) {
			$contents		= file_get_contents("./artimporter/$file");
			preg_match('/\$ap = "(.*)"/', $contents, $matches);
			$plugins[$file]	= $matches[1];
			preg_match('/\$ex = "(.*)"/', $contents, $matches);
			$examples[]		= $matches[1];
			unset($contents, $matches);
		}
	}
}
closedir($dir);
$tpl->assign('plugins', $plugins);
$tpl->assign('examples', $examples);
if (AJAX_CAT_SELECTION_METHOD != 1) {
	$categs				= get_categs_tree();
	$tpl->assign('categs', $categs);
}
$ActiveUsersList	= $db->GetAssoc("SELECT `ID`, CONCAT(`LOGIN`, '  (', `NAME`, ' / ', `EMAIL`, ')') AS `USER` FROM `{$tables['user']['name']}` WHERE `ACTIVE` = '1'");
$ActiveUsersList[0]	= _L('Select username');
ksort($ActiveUsersList);
$tpl->assign('ActiveUsersList', $ActiveUsersList);
$tpl->assign('stats', array (0 => _L('Inactive'), 1 => _L('Pending'), 2 => _L('Active'),));
$tpl->assign('types', array (0 => _L('None'), 1 => _L('Free'), 2 => _L('Normal'), 3 => _L('Reciprocal'), 4 => _L('Featured'),));
$res				= $tpl->fetch(ADMIN_TEMPLATE . '/artimporter.tpl');
$tpl->assign('content', $res);
$tpl->load_filter('output', 'trimwhitespace');
if (COMPRESS_OUTPUT == 1) { $tpl->load_filter('output', 'CompressOutput'); }
echo $tpl->fetch(ADMIN_TEMPLATE . '/main.tpl');

?>
