Location: PHPKode > projects > chillyCMS > chillyCMS/installation/testdata.php
<?php
defined('DOIT') or die('Restricted access');

//Modules//////////////////////////////////////////////////////////////////////////////////////////

//Load all modules
$modules = array();
$handle = opendir(PATH."/modules");
if ($handle) {
	while (false !== ($file = readdir($handle))) {
		if ($file != "." && $file != ".." && $file != 'content' && $file != 'menu'
		&& $file != 'ckeditor' && $file != 'login') {
			$modules[$file] = false;
		}	
	}
	closedir($handle);
}

//enter directories and get config values
$id = 4;
$insertmodules = array();
$modtablequeries = array();
foreach ($modules as $m=>$mod) {
	if (file_exists(PATH."/modules/$m/config.php")) {
		$name=$author=$version=$type=false;
		include (PATH."/modules/".$m.'/config.php');
		$mod = array('id'=>$id,'name'=>$name,'author'=>$author,'version'=>$version,'type'=>$type);
		$insertmodules[] = $mod;
		$id++;
	}
	if (file_exists(PATH."/modules/$m/drop.sql")) {
		$modtablequeries[] = PATH."/modules/$m/drop.sql";
	}
	if (file_exists(PATH."/modules/$m/create.sql")) {
		$modtablequeries[] = PATH."/modules/$m/create.sql";
	}
}

//make insert query
$sql="insert into system_modules (`modid`,`name`,`author`,`version`,`type`) values ";
foreach ($insertmodules as $m) {
	$sql .= "(".$m['id'].",'".$m['name']."','".$m['author']."','".$m['version']."',".$m['type']."),";	
}
$sql = substr($sql,0,-1);

$page->query($sql);

//Demo Content/////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['sitedemo']) && $_POST['sitedemo']=='sitedemo') {
	//Groups
	$sql="insert into system_groups (`gid`,`name`,`backend`,`write`) values
	(3,'Readgroup',1,0),
	(4,'Writegroup',1,1)";
	$page->query($sql);

	//Users
	$sql="insert into system_users (`uid`,`user`,`name`,`pw`,`email`,`gids`,`active`) values
	(2,'klaus','Klaus Klausen','26c669cd0814ac40e5328752b21c4aa6450d16295e4eec30356a06a911c23983aaebe12d5da38eeebfc1b213be650498df8419194d5a26c7e0a50af156853c79','hide@address.com','2,3',1),
	(3,'peter','Peter Petersen','26c669cd0814ac40e5328752b21c4aa6450d16295e4eec30356a06a911c23983aaebe12d5da38eeebfc1b213be650498df8419194d5a26c7e0a50af156853c79','hide@address.com','2,4',1),
	(4,'jens','Jens Jensen','26c669cd0814ac40e5328752b21c4aa6450d16295e4eec30356a06a911c23983aaebe12d5da38eeebfc1b213be650498df8419194d5a26c7e0a50af156853c79','hide@address.com','2,3,4',1)";
	$page->query($sql);

	//Active Modules
	$sql = "insert into site_modules (`name`,`modid`,`position`,`order`,`active`,`access`,`settings`) values ".
	"('Special Menu',2,'left',2,1,1,'10,1,1,0'),".
	"('Login',3,'right',1,1,0,'1,1,1,1,1'),";
	foreach ($insertmodules as $m) {
		if ($m['name']=='newarticles') {
			$sql .= "('New',".$m['id'].",'right',2,1,0,'5'),";
		}
		if ($m['name']=='populararticles') {
			$sql .= "('Popular',".$m['id'].",'right',2,1,0,'5'),";
		}
		if ($m['name']=='visitorcounter') {
			$sql .= "('Visitors',".$m['id'].",'user0',1,1,0,'0,5,oldschool.jpg'),";
		}	
	}
	$sql = substr($sql,0,-1);
	$page->query($sql);

	//Content
	$allowedTags="<a><b><i><u><p><hr><sub><sup><strong><em><strike><table><td><tr><th><cite>".
	"<code><h1><h2><h3><h4><h5><h6><img><li><ol><ul><span><div><br><ins><del><blockquote><small>";

	$sonnet1="<p>II.</p><br />
	<p>When forty winters shall besiege thy brow,<br />And dig deep trenches in thy beauty's field,</p>
	<hr class=\"readon\" />
	<p>Thy youth's proud livery, so gazed on now,<br />Will be a tatter'd weed, of small worth held:</p>
	<p>Then being ask'd where all thy beauty lies,<br />Where all the treasure of thy lusty days,</p>
	<p>To say, within thine own deep-sunken eyes,<br />Were an all-eating shame and thriftless praise.</p><br />
	<p>How much more praise deserved thy beauty's use,<br />If thou couldst answer: 'This fair child of mine</p>
	<p>Shall sum my count and make my old excuse,'<br />Proving his beauty by succession thine!</p><br />
	<p>This were to be new made when thou art old,<br />And see thy blood warm when thou feel'st it cold.</p>";
	$sonnet1=escape(strip_tags(stripslashes($sonnet1),$allowedTags));

	$sonnet2="<p>CXXX.</p><br />
	<p>My mistress' eyes are nothing like the sun;<br />Coral is far more red than her lips' red;</p>
	<hr class=\"readon\" />
	<p>If snow be white, why then her breasts are dun;<br />If hairs be wires, black wires grow on her head.</p>
	<p>I have seen roses damask'd, red and white,<br />But no such roses see I in her cheeks;</p>
	<p>And in some perfumes is there more delight<br />Than in the breath that from my mistress reeks.</p><br />
	<p>I love to hear her speak, yet well I know<br />That music hath a far more pleasing sound;</p>
	<p>I grant I never saw a goddess go;<br />My mistress, when she walks, treads on the ground:</p><br />
	<p>And yet, by heaven, I think my love as rare<br />As any she belied with false compare.</p>";
	$sonnet2=escape(strip_tags(stripslashes($sonnet2),$allowedTags));

	$sonnet3="<p>XXXI.</p><br />
	<p>Thy bosom is endeared with all hearts,<br />Which I by lacking have supposed dead,</p>
	<hr class=\"readon\" />
	<p>And there reigns love and all love's loving parts,<br />And all those friends which I thought buried.</p>
	<p>How many a holy and obsequious tear<br />Hath dear religious love stol'n from mine eye,</p>
	<p>As interest of the dead, which now appear,<br />But things removed that hidden in thee lie.</p><br />
	<p>Thou art the grave where buried love doth live,<br />Hung with the trophies of my lovers gone,</p>
	<p>Who all their parts of me to thee did give,<br />That due of many, now is thine alone.</p><br />
	<p>Their images I loved, I view in thee,<br />And thou (all they) hast all the all of me.</p>";
	$sonnet3=escape(strip_tags(stripslashes($sonnet3),$allowedTags));

	$sonnet4="<p>CXLV.</p><br />
	<p>Those lips that Love's own hand did make,<br />Breathed forth the sound that said 'I hate',</p>
	<hr class=\"readon\" />
	<p>To me that languished for her sake:<br />But when she saw my woeful state,</p>
	<p>Straight in her heart did mercy come,<br />Chiding that tongue that ever sweet,</p>
	<p>Was used in giving gentle doom:<br />And taught it thus anew to greet:</p><br />
	<p>'I hate' she altered with an end,<br />That followed it as gentle day,</p>
	<p>Doth follow night who like a fiend<br />From heaven to hell is flown away.</p><br />
	<p>'I hate', from hate away she threw,<br />And saved my life saying 'not you'.</p>";
	$sonnet4=escape(strip_tags(stripslashes($sonnet4),$allowedTags));

	$sonnet5="<p>XVIII.</p><br />
	<p>Shall I compare thee to a summer's day?<br />Thou art more lovely and more temperate:</p>
	<hr class=\"readon\" />
	<p>Rough winds do shake the darling buds of May,<br />And summer's lease hath all too short a date:</p>
	<p>Sometime too hot the eye of heaven shines,<br />And often is his gold complexion dimmed,</p>
	<p>And every fair from fair sometime declines,<br />By chance, or nature's changing course untrimmed:</p><br />
	<p>But thy eternal summer shall not fade,<br />Nor lose possession of that fair thou ow'st,<//p>
	<p>Nor shall death brag thou wand'rest in his shade,<br />When in eternal lines to time thou grow'st,</p><br />
	<p>So long as men can breathe or eyes can see,<br />So long lives this, and this gives life to thee.</p>";
	$sonnet5=escape(strip_tags(stripslashes($sonnet5),$allowedTags));

	$sql = "insert into site_content (`id`, `name`, `treeid`, `depth`, `parentid`, `order`, `active`, `startpage`, `modid`,".
	"`settings`, `access`, `specialaccess`, `date_new`, `date_edit`, `content`) values ".
		"(3,'Shakespeares Sonnets',1,1,1,2,1,0,1,'0,1',0,'',now(),now(),'Here are the best sonnets ever written!'),".
			"(4,'Sonnet 2',1,2,3,1,1,0,1,null,0,'',now(),now(),'$sonnet1'),".
			"(5,'Sonnet 130',1,2,3,2,1,0,1,null,0,'',now(),now(),'$sonnet2'),".
		"(6,'More Sonnets',1,1,1,3,1,0,1,null,1,'',now(),now(),'These sonnets are also very good! They can only be seen if you are logged in.'),".
			"(7,'Sonnet 31',1,2,6,1,1,0,1,null,1,'',now(),now(),'$sonnet3'),".
			"(8,'Sonnet 145',1,2,6,2,1,0,1,null,1,'',now(),now(),'$sonnet4'),".
			"(9,'Sonnet 18',1,2,6,3,1,0,1,null,1,'',now(),now(),'$sonnet5'),".
	"(10,'Usermenu',10,0,0,0,1,0,1,null,2,'3,4',now(),now(),null),";

	$contentids = array();
	$id = 11;
	$modsql = '';
	foreach ($insertmodules as $m) {
		if ($m['name']=='contact') {
			$modsql .= "($id,'Contact',10,1,10,1,1,0,".$m['id'].",'1,Subject,1',2,'3,4',now(),now(),''),";
			$contentids['contact'] = $id;
			$id++;
		}
		if ($m['name']=='cssgallery') {
			$modsql .= "($id,'Gallery',10,1,10,2,1,0,".$m['id'].",'../media,_small',2,'3,4',now(),now(),''),";
			$contentids['cssgallery'] = $id;
			$id++;
		}
		if ($m['name']=='download') {
			$modsql .= "($id,'Downloads',10,1,10,3,1,0,".$m['id'].",'on,on',2,'3,4',now(),now(),''),";
			$contentids['download'] = $id;
			$id++;
		}
		if ($m['name']=='bugtrap') {
			$modsql .= "($id,'MyProject',10,1,10,4,1,0,".$m['id'].",'1,".date('d.m.Y',strtotime('now + 2 months')).
			"',2,'3,4',now(),now(),'Example Project'),";
			$contentids['bugtrap'] = $id;
			$id++;
		}
		if ($m['name']=='guestbook') {
			$modsql .= "($id,'Guestbook',10,1,10,5,1,0,".$m['id'].",'1,hide@address.com,1,0,1,1,1,,',0,'',now(),now(),''),";
			$contentids['guestbook'] = $id;
			$id++;
		}
	}
	$sql = substr($sql.$modsql,0,-1);
	$page->query($sql);

	//Special Module Tables
	foreach ($modtablequeries as $q) { exec_sql($q); }

	//Special Module Table Content
	//--guestbook
	$sql="insert into mod_guestbook (`mainmodid`,`name`,`msg_date`,`message`,`email`,`active`,`reply_user`,`reply_date`,`reply`) values ".
	"(".$contentids['guestbook'].",'Some User','2010-03-29 16:38:33','Nice website! chillyCMS is great!','hide@address.com',1,1,'2010-03-29 16:42:39','Thank you very much!')";
	$page->query($sql);
	//--download
	$sql="insert into mod_download (`modid`,`filename`,`location`) values (".$contentids['download'].",'chilly.png','media')";
	$page->query($sql);

	//home content
	$sql="update site_content set `content`='Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod temApor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. <br /><br />Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. <br /><br />Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.' where id=2";
	$page->query($sql);
}
?>
Return current item: chillyCMS