<?php
/**
* /logic/sitedesigner/sitedesigner.class.php
*
* Provides drag and drop site creation
* @package AgaresCore4
* @author Agares Media <hide@address.com>
* @copyright Copyright (c) 2009 Agares Media. All rights reserved.
*/
loadclass('view'); // To extend the view, we first need to load it
/**
* sitedesigner() Class
*
* Provides drag and drop site creation
* @package AgaresCore4
*/
class sitedesigner extends view {
/**
* load() Method
*
* Loads the Site Designer data for the page specified in $application and the view specified in $view
*
* @access public
* @param string $application Loads the Site Designer data for the page specified in $application
* @param string $view The view from the application to load
* @return mixed Returns an array with the proper data for the Site Designer. Returns false on failure
*/
public function load($application, $view) {
global $database; // We'll use the global $database connection
if(!$result = $database->query('SELECT * FROM `windows` WHERE `application`="'.$application.'" AND `view`="'.$view.'";')) {
return false;
} else {
return $result;
}
}
/**
* loadwindows() Method
*
* Loads the Site Designer data for the page specified in $application, and then feeds the window code for each window to $body_output
*
* @access public
* @param string $application Loads the Site Designer data for the page specified in $application in combination with the specified $view
* @param string $view The view from the application to load
* @return mixed Returns void on succes, returns false on failure
*/
public function loadwindows($application, $view) {
global $homedir, $database, $body_output, $designermode;
// This foreach loop loads the DIV's for the page
$divs = $database->query('SELECT * FROM `div` WHERE `application`="'.$application.'" AND `view`="'.$view.'";');
if(is_resource($divs)) {
foreach($divs as $div) {
$styleoverride = NULL;
$class = NULL;
if(trim($div['styleoverride'])!='') {
$styleoverride = ' style="'.$div['styleoverride'].'"';
}
if(trim($div['class'])!='') {
$class = ' class="'.$div['class'].'"';
}
$body_output .= '<div id="'.$div['id'].'"'.$class.$styleoverride.'>'.$div['content'].'</div>';
$styleoverride = NULL;
$class = NULL;
}
}
if(!$result = $this->load($application, $view)) {
return false;
} else {
// This foreach loop loads the Window/Widgets for the page
foreach($result as $cycle) {
if($cycle['windowtype']=='widget') { // If it's a widget then we need to load the appropriate DIV from the database.
} else {
$cycle['contentfile'] = $homedir . $cycle['contentfile'];
}
$body_output .= $this->window($cycle['title'], $cycle['contentfile'], $cycle['windowid'], $cycle['winwidth'], $cycle['winheight'], $cycle['decoration'], $cycle['zindex'], $cycle['destoryonclose'], $cycle['recenterauto'], $cycle['toppos'], $cycle['leftpos'], 'true', $cycle['windowtype'], $cycle['isresizable'], $cycle['iscloseable'], $cycle['isminimizable'], $cycle['ismaximizable'], $cycle['isdraggable']);
}
}
}
/**
* createproject() Method
*
* @access public
* @param string $projectname The name you would like to assign to the project. Must only contain characters suitable for both your file system and MySQL insertion
* @return boolean Returns true on success, false on failure.
*/
public function createproject($projectname) {
global $localpath;
loadclass('filesystem');
$filesystem = new filesystem();
$failed = false;
if(!$filesystem->createdir($localpath . '\\applications\\' . $projectname)) { // Try and create the directory here
$this->debug('Step 1 - FAILED - Could not create the folder: '. $localpath . '\\applications\\' . $projectname);
$failed = true;
} else {
$this->debug('Step 1 - SUCCESS - Created folder: '. $localpath . '\\applications\\' . $projectname);
if(!$filesystem->createdir($localpath . '\\applications\\' . $projectname . '\\logic')) { // Try and create the directory here
$this->debug('Step 2 - FAILED - Could not create the folder: '. $localpath . '\\applications\\' . $projectname. '\\logic');
$failed = true;
} else {
$this->debug('Step 2 - SUCCESS - Created folder: '. $localpath . '\\applications\\' . $projectname. '\\logic');
if(!$filesystem->createdir($localpath . '\\applications\\' . $projectname . '\\views')) { // Try and create the directory here
$this->debug('Step 3 - FAILED - Could not create the folder: '. $localpath . '\\applications\\' . $projectname. '\\views');
$failed = true;
} else {
$this->debug('Step 3 - SUCCESS - Created folder: '. $localpath . '\\applications\\' . $projectname. '\\views');
if(!$filesystem->createdir($localpath . '\\applications\\' . $projectname . '\\data')) { // Try and create the directory here
$this->debug('Step 4 - FAILED - Could not create the folder: '. $localpath . '\\applications\\' . $projectname. '\\data');
$failed = true;
} else {
$this->debug('Step 4 - SUCCESS - Created folder: '. $localpath . '\\applications\\' . $projectname. '\\data');
if(!$filesystem->writefile($localpath . '\\applications\\' . $projectname . '\\config.php', "<?PHP ?>")) { // Try and create the directory here
$this->debug('Step 5 - FAILED - Could not create the file: '. $localpath . '\\applications\\' . $projectname. '\\config.php');
$failed = true;
} else {
$this->debug('Step 5 - SUCCESS - Created file: '. $localpath . '\\applications\\' . $projectname. '\\config.php');
if(!$filesystem->writefile($localpath . '\\applications\\' . $projectname . '\\logic\\index.php', "<?PHP ?>")) { // Try and create the directory here
$this->debug('Step 6 - FAILED - Could not create the file: '. $localpath . '\\applications\\' . $projectname. '\\logic\\index.php');
$failed = true;
} else {
$this->debug('Step 6 - SUCCESS - Created file: '. $localpath . '\\applications\\' . $projectname. '\\logic\\index.php');
if(!$filesystem->writefile($localpath . '\\applications\\' . $projectname . '\\views\\index.php',
"<?php
loadclass('sitedesigner');
\$sitedesigner = new sitedesigner();
\$sitedesigner->loadwindows('{$projectname}', 'index');
echo \$sitedesigner->sdoutput('{$projectname}', 'index');
?>")) { // Try and create the directory here
$this->debug('Step 7 - FAILED - Could not create the file: '. $localpath . '\\applications\\' . $projectname. '\\views\\index.php');
$failed = true;
} else {
$this->debug('Step 7 - SUCCESS - Created file: '. $localpath . '\\applications\\' . $projectname. '\\views\\index.php');
}
}
}
}
}
}
}
if($failed==true) { // @todo Isn't it just great coding convention to use $failed==true? Absolutely not (notice the lack of play on words.) How about nested if statements eight levels deep?
return false;
} else {
return true;
}
}
/**
* sdoutput() Method
*
* The sdoutput() method loads the data from the sitedesigner table for the application specified in $application, and the view specified in $view
* and returns a string with HTML markup
*
* @access public
* @param string $application loads the data from the sitedesigner table for the application specified in $application
* @param string $view loads the data from the sitedesigner table for the application specified in $application and the view specified in $view
* @return mixed
*/
public function sdoutput($application, $view) {
global $homedir, $database, $headtop_output, $headbottom_output, $body_output, $designermode; // We'll use the global $database connection
$resset = false;
if(!$result = $database->query('SELECT * FROM `sitedesigner` WHERE `application`="'.$application.'" AND `view`="'.$view.'";')) {
$resset = true;
return false;
}
if($resset == false) {
if($designermode==true) {
$headtop_output .= '
<style type="text/css">
#control_contextmenu {
font-family:arial,verdana;
border:1px solid #666;
background-color:#eee;
min-width:150px;
}
#control_contextmenu ul {
list-style:none;
padding:0;
margin:0;
cursor:pointer;
}
#control_contextmenu ul li {
text-align:left;
padding:2px 10px 2px 5px;
margin:0;
cursor:pointer;
text-decoration:none;
color:#000000;
font-size:14px;
border:0px;
border-left:1px solid #fff;
border-right:1px solid #999;
}
#control_contextmenu ul li.selected, #control_contextmenu ul li:hover {
color:#fff;
background-color:#3875d7;
cursor:pointer;
}
#control_contextmenu ul li.selected:hover {
color:#333;
background-color:#eee;
cursor:pointer;
}
#control_contextmenu ul li.disabled,
#control_contextmenu ul li:hover.disabled {
background-color: #eee;
color:#999;
cursor:pointer;
}
</style>';
$headbottom_output .= $this->dependancy('./libraries/3rdparty/prototype/prototype.js');
$headbottom_output .= $this->dependancy('./libraries/3rdparty/script.aculo.us/src/effects.js', ' defer="defer"');
$headbottom_output .= $this->dependancy('./libraries/3rdparty/script.aculo.us/src/dragdrop.js', ' defer="defer"');
$headbottom_output .= $this->dependancy('./libraries/3rdparty/livepipe/src/livepipe.js', ' defer="defer"');
$headbottom_output .= $this->dependancy('./libraries/3rdparty/livepipe/src/contextmenu.js', ' defer="defer"');
$windowOptions = array (
'title' => 'Tool Pallete',
'content' => $homedir . '/sitedesigner/toolbar/',
'windowid' => '@toolbar',
'winwidth' => '200',
'winheight' => '260',
'decoration' => 'groundos',
'zindex' => '500',
'destroyonclose' => 'true',
'recenterauto' => 'false',
'toppos' => '28',
'leftpos' => '1',
'usetags' => 'true',
'windowtype' => 'window',
'isresizable' => 'true',
'iscloseable' => 'false',
'isminimizable' => 'true',
'ismaximizable' => 'true',
'isdraggable' => 'true',
);
$body_output = $body_output . $this->awindow($windowOptions);
}
return $this->output(
$result[0]['title'], // Set the meta tag title of the page
$result[0]['keyword'], // Set the meta tag for keywords
$result[0]['description'], // Set the meta tag for description
$result[0]['doctype'], // Set the XHTML to UTF-8, Set this to NULL if not using XHTML
$result[0]['realdoctype'], // Use XHTML 1.0 Transitional
$result[0]['realencode'], // Set to UTF-8,
$headtop_output, // Load any CSS or other top most content intended for the head tag
$headbottom_output, // Load any Javascript or othercontent intended for the bottom of head tag
$result[0]['bodymarkup'], // When this is NULL the body tag reads <body>. To insert custom style of javascript, insert a string into the parameter. For example, a string of this: ' style="border:1px;"' would make the body tag output as <body style="border:1px;">
$body_output // Output the body of the document
);
}
}
}
?>