<?php

	class PHPWS_hackmaster {

		function set_up_hacks() {

			if(empty($GLOBALS['mod_hackmaster']))
				$GLOBALS['mod_hackmaster']=array();
			if(empty($GLOBALS['mod_hackmaster']['hacks']))
				$GLOBALS['mod_hackmaster']['hacks']=
					array(	'anonymous_themes' => array(
							'author' => 'rck',
							'author_web' => 'http://www.kiesler.at/',
							'hack_web' => 'http://www.kiesler.at/article125.html'
						),
						'download_counter' => array(
							'author' => 'langer',
							'author_web' => 'http://www.modhole.com/',
							'hack_web' => 'http://www.modhole.com/index.php?module=documents&amp;JAS_DocumentManager_op=viewDocument&amp;JAS_Document_id=9'
						),
						'folders' => array(
							'author' => 'rck',
							'author_web' => 'http://www.kiesler.at/',
							'hack_web' => 'http://www.kiesler.at/article140.html'
						),
						'member_since' => array(
							'author' => 'rck',
							'author_web' => 'http://www.kiesler.at/',
							'hack_web' => 'http://www.phpwsforums.com/showthread.php?t=274'
						),
						'menuman_permissions' => array(
							'author' => 'jreid',
							'author_web' => 'http://www.essenceinteractive.com/',
							'hack_web' => 'http://www.phpwebsitemanual.com/index.php?module=phpwsbb&amp;PHPWSBB_MAN_OP=view&amp;PHPWS_MAN_ITEMS[]=272'
						),
						'mod_rewrite' => array(
							'author' => 'aDarkling',
							'author_web' => 'http://www.bygeorgeware.com/',
							'hack_web' => 'http://www.bygeorgeware.com/index.php?module=phatfile&amp;FILE_MAN_OP=Main'
						),
						'pagemaster_security' => array(
							'author' => 'tonynl',
							'author_web' => 'http://www.oosterhoff.nu/',
							'hack_web' => 'http://www.oosterhoff.nu/pws/index.php?module=documents&amp;JAS_DocumentManager_op=viewDocument&amp;JAS_Document_id=14'
						),
						'relative_time' => array(
							'author' => 'rck',
							'author_web' => 'http://www.kiesler.at/',
							'hack_web' => 'http://www.kiesler.at/article224.html'
						),
						'swallow' => array(
							'author' => 'rck',
							'author_web' => 'http://www.kiesler.at/',
							'hack_web' => 'http://www.kiesler.at/article90.html'
						),
						'thread_visits' => array(
							'author' => 'rck',
							'author_web' => 'http://www.kiesler.at/',
							'hack_web' => 'http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1153715&amp;group_id=81260&amp;atid=562404'
						)
					);


		}

		function PHPWS_hackmaster() {

			$this->set_up_hacks();

		}


		function anonymous_themes() {

			@include_once (PHPWS_SOURCE_DIR . 'mod/layout/class/Layout.php');

			return( is_callable(array('PHPWS_Layout', 'overrideLayout')) );
		}


		function download_counter() {

			if(!$GLOBALS['core']->sqlTableExists('mod_documents_files', TRUE))
				return(false);

			return( $GLOBALS['core']->sqlColumnExists('mod_documents_files', 'downloads') );

		}


		function folders() {

			$prefix=$GLOBALS['core']->tbl_prefix;

			if(!$GLOBALS['core']->sqlTableExists('mod_phpwsbb_folders', TRUE))
				return(false);

			return( $GLOBALS['core']->sqlColumnExists('mod_phpwsbb_folders', 'name') );
		}



		function member_since() {

			if(!$GLOBALS['core']->sqlTableExists('mod_users', TRUE))
				return(false);

			return( $GLOBALS['core']->sqlColumnExists('mod_users', 'member_since'));

		}


		function menuman_permissions() {

			if(!$GLOBALS['core']->sqlTableExists('mod_menuman_menus', TRUE))
				return(false);

			return( $GLOBALS['core']->sqlColumnExists('mod_menuman_menus', 'groups') );

		}


		function mod_rewrite() {

			@include_once (PHPWS_SOURCE_DIR . 'core/Core.php');

			return( defined( 'MOD_REWRITE_ENABLED' ) );
			
		}


		function pagemaster_security() {

			if(!$GLOBALS['core']->sqlTableExists('mod_pagemaster_pages', TRUE))
				return(false);

			return( $GLOBALS['core']->sqlColumnExists('mod_pagemaster_pages', 'egroups') );
		}


		function relative_time() {

			@include_once (PHPWS_SOURCE_DIR . 'core/DateTime.php');

			return( is_callable(array('PHPWS_DateTime', 'relativeTime')) );

		}

		function swallow() {

			@include_once (PHPWS_SOURCE_DIR . 'mod/article/class/Section.php');

			return( is_callable(array('PHPWS_Article_section', 'swallow')) );
		}


		function thread_visits() {

			if(!$GLOBALS['core']->sqlTableExists('mod_phpwsbb_threads'))
				return(false);

			return( $GLOBALS['core']->sqlColumnExists('mod_phpwsbb_threads', 'visits'));

		}



		function render() {

			$content ='';
			$backlink='<a href="./index.php?module=controlpanel">back to controlpanel</a>';

			if(!$_SESSION['OBJ_user'])
				return('Please log in as a deity to do that.');
			else
			if(!$_SESSION['OBJ_user']->isDeity())
				return('Please log in as a deity to do that.<br />'.$backlink);

			$this->set_up_hacks();

			$hacks=$GLOBALS['mod_hackmaster']['hacks'];
			if(empty($hacks))
				return('no hacks set up in Hack Master.<br />'.$backlink);


			$content.="<br /><p>$backlink</p>\n";
			$content.='<table width="100%"><tr>';
			$content.='<th width="40%">hack</th><th width="40%">author</th><th width="20%">installed?</th>';
			$content.="</tr>\n";

			$odd=1;

			foreach($hacks as $hack => $data) {

				$author=$data['author'];
				$author_site=$data['author_web'];

				if(isset($author_site))
					$author="<a href='$author_site'>$author</a>";

				if($odd) {
					$content.="<tr class='bg_light'>";
					$odd=0;
				} else {
					$content.="<tr class='bg_medium'>";
					$odd=1;
				}

				$hack_caption=$hack;
				$hack_site=$data['hack_web'];

				if(isset($hack_site))
					$hack_caption="<a href='$hack_site'>$hack</a>";

				$content.="<td>$hack_caption</td>";
				$content.="<td>$author</td>";

				$content.='<td>';

				if($this->$hack())
					$content.="<strong>yes</strong>";
				else
					$content.="no";

				$content.='</td>';

				$content.="</tr>\n";

			}


			$content.="</table><br />\n";
			$content.="$backlink\n";

			return($content);
		}

	}

?>

