..we are going to create a new app for the hacksuite. We're not going to do anything fancy here, we will make a simple app to get familiar how to write compatible scripts for the..
Creates a blueprint/map of a server folder
<?php
/* Manager for search widgets
Author: Remco Kouw
Site: http://www.hacksuite.com
Last Edit: 08-03-2015
*/
if(!defined('IN_SCRIPT')){
exit;
}
$_CONTEXT['subtitle'] = "Widgets";
// target files we need, so make sure they are present
$aFiles = array($_PATHS['functions_root']."/fwrite.php",$_PATHS['data_root']."/widgets.php",$_PATHS['functions_root']."/get_file_data.php");
for($x=0;$x<count($aFiles);$x++){
(!IsThere($aFiles[$x]) ? include_once($_PATHS['end']) : include_once($aFiles[$x]));
}
if(!isset($_CONTEXT['widgets'])){
$_CONTEXT['errors'][] = "No widgets present";
include_once($_PATHS['end']);
}
// simple verification of content and extractor of useful stuff in the big widget array
$_CONTEXT['widget'] = array();
$_CONTEXT['widget']['keys'] = array();
$_CONTEXT['widget']['active'] = array();
foreach($_CONTEXT['widgets'] as $sKey=>$aValues){
$_CONTEXT['widget']['keys'][] = $sKey;
$_CONTEXT['widget']['active'][] = $aValues['active'];
}
if(false==($iItems = count($_CONTEXT['widget']['keys']))){
// no widgets or maybe a corrupt file or array
$_CONTEXT['errors'][] = "No widgets present or are you sure the file contains the proper data?";
// no need to end just log a warning if necessary
}
if(isset($_POST['submit'])){
switch($_POST['submit']){
// activate or deactivate
case"Change State":
if(false==($sData = GetFileData($_PATHS['data_root']."/widgets.php"))){
include_once($_PATHS['end']);
}
$sBeforeH = md5($sData);
// verify submitted form field
for($x=0;$x<count($_CONTEXT['widget']['keys']);$x++){
$sVar = strtolower($_CONTEXT['widget']['keys'][$x]);
if(!isset($_POST[$sVar])){
$_CONTEXT['errors'][] = "Expecting variable <b>".$sVar."</b> to be present for widget <b>".$_CONTEXT['widget']['keys'][$x]."</b>";
include_once($_PATHS['end']);
}
$iNew = $_POST[$sVar]!=1 ? 0 : 1;
$iCurrent = $_CONTEXT['widget']['active'][$x]!=1 ? 0 : 1;
$sData = str_replace("\$_CONTEXT['widgets']['".$sVar."']['active'] = ".$iCurrent.";","\$_CONTEXT['widgets']['".$sVar."']['active'] = ".$iNew.";",$sData);
}
$sAfterH = md5($sData);
if($sAfterH==$sBeforeH){
$sCode .= "<div class=\"spacingmsg\">".$_CONTEXT['result_headers']['result']."No changes have been made.. click <a href=\"javascript:history.go(-1)\">here</a> to return</div>\n";
}
else{
if(!WriteF($_PATHS['data_root']."/widgets.php",$sData,"w")){
include_once($_PATHS['end']);
}
else{
$sCode .= "<div class=\"spacingmsg\">".$_CONTEXT['result_headers']['result']."Update succeeded, click <a href=\"javascript:history.go(-1)\">here</a> to return</div>\n";
}
}
break;
// default
default:
$_CONTEXT['errors'][] = "Invalid submission button value";
include_once($_PATHS['end']);
}
}
else{
// output form
$sCode .= " <form method=\"post\">\n";
$sCode .= " <div class=\"emboss borderr5 border1pxtrans pad5 edgeglow overflw\">\n";
$sCode .= " <div class=\"embosshdrnocenter border1pxtrans pad10\">Enable or disable widgets</div>\n";
for($x=0;$x<count($_CONTEXT['widget']['keys']);$x++){
$iCurrent = $_CONTEXT['widget']['active'][$x]!=1 ? 0 : 1;
$sVar = strtolower($_CONTEXT['widget']['keys'][$x]);
$sCode .= " <div class=\"cc_record\">\n";
$sCode .= " <div class=\"flt pad3 w150\"><b>".$_CONTEXT['widget']['keys'][$x]."</b></div><div class=\"flt pad3\"><b>active</b> <input type=\"radio\" name=\"".$sVar."\" value=\"1\" ".($iCurrent==1 ? "checked" : "")." /> <b>disabled</b> <input type=\"radio\" name=\"".$sVar."\" value=\"0\" ".($iCurrent==0 ? "checked" : "")." /></div>\n";
$sCode .= " </div>\n";
$sCode .= " <div class=\"clear\"></div>\n";
}
$sCode .= " <div class=\"cc_record\">\n";
$sCode .= " <div class=\"flt pad3\"><input type=\"submit\" name=\"submit\" value=\"Change State\" /><input type=\"hidden\" name=\"iCFG\" value=\"".$_POST['iCFG']."\" /></div>\n";
$sCode .= " </div>\n";
$sCode .= " </div>\n";
$sCode .= " </form>\n";
}
?>