2014-02-10 15:18:28 -06:00
|
|
|
<?php if(!defined('APPLICATION')) exit();
|
2014-02-06 14:44:21 -06:00
|
|
|
/* Copyright 2013 Zachary Doll */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage the yaga application including configuration and import/export
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
* @package Yaga
|
|
|
|
*/
|
|
|
|
class YagaController extends DashboardController {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array These objects will be created on instantiation and available via
|
|
|
|
* $this->ObjectName
|
|
|
|
*/
|
|
|
|
public $Uses = array('Form');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make this look like a dashboard page and add the resources
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function Initialize() {
|
|
|
|
parent::Initialize();
|
|
|
|
$this->Application = 'Yaga';
|
|
|
|
Gdn_Theme::Section('Dashboard');
|
|
|
|
if($this->Menu) {
|
|
|
|
$this->Menu->HighlightRoute('/yaga');
|
|
|
|
}
|
2014-02-06 15:08:29 -06:00
|
|
|
$this->AddSideMenu('yaga/settings');
|
2014-02-07 14:05:13 -06:00
|
|
|
|
2014-02-06 14:44:21 -06:00
|
|
|
$this->AddCssFile('yaga.css');
|
|
|
|
}
|
2014-02-07 14:05:13 -06:00
|
|
|
|
2014-02-06 14:44:21 -06:00
|
|
|
/**
|
|
|
|
* Redirect to settings by default
|
|
|
|
*/
|
|
|
|
public function Index() {
|
|
|
|
$this->Settings();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This handles all the core settings for the gamification application.
|
|
|
|
*/
|
|
|
|
public function Settings() {
|
|
|
|
$this->Permission('Garden.Settings.Manage');
|
|
|
|
$this->Title(T('Yaga.Settings'));
|
|
|
|
|
|
|
|
// Get list of actions from the model and pass to the view
|
|
|
|
$ConfigModule = new ConfigurationModule($this);
|
|
|
|
|
|
|
|
$ConfigModule->Initialize(array(
|
2014-02-07 14:05:13 -06:00
|
|
|
'Yaga.Reactions.Enabled' => array(
|
2014-08-27 13:34:47 -05:00
|
|
|
'LabelCode' => 'Yaga.Reactions.Use',
|
2014-02-07 14:05:13 -06:00
|
|
|
'Control' => 'Checkbox'
|
|
|
|
),
|
|
|
|
'Yaga.Badges.Enabled' => array(
|
2014-08-26 17:25:44 -05:00
|
|
|
'LabelCode' => 'Yaga.Badges.Use',
|
2014-02-07 14:05:13 -06:00
|
|
|
'Control' => 'Checkbox'
|
|
|
|
),
|
|
|
|
'Yaga.Ranks.Enabled' => array(
|
2014-08-26 17:25:44 -05:00
|
|
|
'LabelCode' => 'Yaga.Ranks.Use',
|
2014-02-07 14:05:13 -06:00
|
|
|
'Control' => 'Checkbox'
|
|
|
|
),
|
|
|
|
'Yaga.LeaderBoard.Enabled' => array(
|
2014-08-26 17:25:44 -05:00
|
|
|
'LabelCode' => 'Yaga.LeaderBoard.Use',
|
2014-02-07 14:05:13 -06:00
|
|
|
'Control' => 'Checkbox'
|
|
|
|
),
|
|
|
|
'Yaga.LeaderBoard.Limit' => array(
|
2014-08-26 17:25:44 -05:00
|
|
|
'LabelCode' => 'Yaga.LeaderBoard.Max',
|
2014-02-07 14:05:13 -06:00
|
|
|
'Control' => 'Textbox',
|
|
|
|
'Options' => array(
|
|
|
|
'Size' => 45,
|
|
|
|
'class' => 'SmallInput'
|
|
|
|
)
|
2014-02-06 14:44:21 -06:00
|
|
|
)
|
|
|
|
));
|
|
|
|
$this->ConfigurationModule = $ConfigModule;
|
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
$this->Render();
|
2014-02-06 14:44:21 -06:00
|
|
|
}
|
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
/**
|
|
|
|
* Import a Yaga transport file
|
|
|
|
*/
|
2014-02-06 14:44:21 -06:00
|
|
|
public function Import() {
|
2014-02-06 15:08:29 -06:00
|
|
|
$this->Title(T('Yaga.Import'));
|
2014-02-08 16:12:59 -06:00
|
|
|
$this->SetData('TransportType', 'Import');
|
2014-02-10 16:28:50 -06:00
|
|
|
|
|
|
|
if(!class_exists('ZipArchive')) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.TransportRequirements'));
|
2014-02-10 16:28:50 -06:00
|
|
|
}
|
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
if($this->Form->IsPostBack() == TRUE) {
|
2014-02-10 14:55:18 -06:00
|
|
|
// Handle the file upload
|
|
|
|
$Upload = new Gdn_Upload();
|
|
|
|
$TmpZip = $Upload->ValidateUpload('FileUpload', FALSE);
|
|
|
|
|
|
|
|
$ZipFile = FALSE;
|
|
|
|
if($TmpZip) {
|
|
|
|
// Generate the target name
|
|
|
|
$TargetFile = $Upload->GenerateTargetName(PATH_UPLOADS, 'zip');
|
|
|
|
$BaseName = pathinfo($TargetFile, PATHINFO_BASENAME);
|
|
|
|
|
|
|
|
// Save the uploaded zip
|
|
|
|
$Parts = $Upload->SaveAs($TmpZip, $BaseName);
|
|
|
|
$ZipFile = PATH_UPLOADS . DS . $Parts['SaveName'];
|
2014-02-10 16:28:50 -06:00
|
|
|
$this->SetData('TransportPath', $ZipFile);
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
|
|
|
|
2014-02-10 16:28:50 -06:00
|
|
|
$Include = $this->_FindIncludes();
|
2014-02-10 14:55:18 -06:00
|
|
|
if(count($Include)) {
|
2014-02-10 16:28:50 -06:00
|
|
|
$Info = $this->_ExtractZip($ZipFile);
|
|
|
|
$this->_ImportData($Info, $Include);
|
|
|
|
Gdn_FileSystem::RemoveFolder(PATH_UPLOADS . DS . 'import' . DS . 'yaga');
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
|
|
|
else {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.Includes'));
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
|
|
|
|
if($this->Form->ErrorCount() == 0 && $this->Form->IsPostBack()) {
|
|
|
|
$this->Render('transport-success');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->Render();
|
|
|
|
}
|
2014-02-06 14:44:21 -06:00
|
|
|
}
|
2014-02-07 14:05:13 -06:00
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
/**
|
|
|
|
* Create a Yaga transport file
|
|
|
|
*/
|
2014-02-06 14:44:21 -06:00
|
|
|
public function Export() {
|
2014-02-06 15:08:29 -06:00
|
|
|
$this->Title(T('Yaga.Export'));
|
2014-02-08 16:12:59 -06:00
|
|
|
$this->SetData('TransportType', 'Export');
|
2014-02-07 14:05:13 -06:00
|
|
|
|
2014-02-10 16:28:50 -06:00
|
|
|
if(!class_exists('ZipArchive')) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.TransportRequirements'));
|
2014-02-10 16:28:50 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-10 16:28:50 -06:00
|
|
|
if($this->Form->IsPostBack()) {
|
|
|
|
$Include = $this->_FindIncludes();
|
2014-02-08 16:12:59 -06:00
|
|
|
if(count($Include)) {
|
2014-02-10 16:28:50 -06:00
|
|
|
$Filename = $this->_ExportData($Include);
|
|
|
|
$this->SetData('TransportPath', $Filename);
|
2014-02-08 16:12:59 -06:00
|
|
|
}
|
|
|
|
else {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.Includes'));
|
2014-02-08 16:12:59 -06:00
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-10 16:28:50 -06:00
|
|
|
if($this->Form->ErrorCount() == 0 && $this->Form->IsPostBack()) {
|
|
|
|
$this->Render('transport-success');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->Render();
|
2014-02-08 16:12:59 -06:00
|
|
|
}
|
2014-02-07 16:03:50 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-08-25 15:53:10 -05:00
|
|
|
/**
|
|
|
|
* This searches through the submitted checkboxes and constructs an array of
|
|
|
|
* Yaga sections to be included in the transport file.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-02-10 16:28:50 -06:00
|
|
|
protected function _FindIncludes() {
|
|
|
|
$FormValues = $this->Form->FormValues();
|
|
|
|
$Sections = $FormValues['Checkboxes'];
|
|
|
|
|
|
|
|
// Figure out which boxes were checked
|
|
|
|
$Include = array();
|
|
|
|
foreach($Sections as $Section) {
|
|
|
|
$Include[$Section] = $FormValues[$Section];
|
|
|
|
}
|
|
|
|
return $Include;
|
|
|
|
}
|
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
/**
|
|
|
|
* Creates a transport file for easily transferring Yaga configurations across
|
|
|
|
* installs
|
2014-02-10 16:28:50 -06:00
|
|
|
*
|
2014-02-10 15:18:28 -06:00
|
|
|
* @param array An array containing the config areas to transfer
|
|
|
|
* @param string Where to save the transport file
|
|
|
|
* @return mixed False on failure, the path to the transport file on success
|
|
|
|
*/
|
2014-02-10 16:28:50 -06:00
|
|
|
protected function _ExportData($Include = array(), $Path = NULL) {
|
2014-02-07 16:03:50 -06:00
|
|
|
$StartTime = microtime(TRUE);
|
2014-02-07 16:35:31 -06:00
|
|
|
$Info = new stdClass();
|
|
|
|
$Info->Version = C('Yaga.Version', '?.?');
|
|
|
|
$Info->StartDate = date('Y-m-d H:i:s');
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 16:03:50 -06:00
|
|
|
if(is_null($Path)) {
|
2014-02-10 15:18:28 -06:00
|
|
|
$Path = PATH_UPLOADS . DS . 'export' . date('Y-m-d-His') . '.yaga.zip';
|
2014-02-07 16:03:50 -06:00
|
|
|
}
|
|
|
|
$FH = new ZipArchive();
|
2014-02-07 16:35:31 -06:00
|
|
|
$Images = array();
|
|
|
|
$Hashes = array();
|
2014-02-10 14:55:18 -06:00
|
|
|
|
|
|
|
if($FH->open($Path, ZipArchive::CREATE) !== TRUE) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(sprintf(T('Yaga.Error.ArchiveCreate'), $FH->getStatusString()));
|
2014-02-07 16:03:50 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-12 15:59:41 -06:00
|
|
|
// Add configuration items
|
|
|
|
$Info->Config = 'configs.yaga';
|
|
|
|
$Configs = Gdn::Config('Yaga', array());
|
|
|
|
unset($Configs['Version']);
|
|
|
|
$ConfigData = serialize($Configs);
|
|
|
|
$FH->addFromString('configs.yaga', $ConfigData);
|
|
|
|
$Hashes[] = md5($ConfigData);
|
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
// Add actions
|
2014-02-10 16:28:50 -06:00
|
|
|
if($Include['Action']) {
|
2014-02-10 15:18:28 -06:00
|
|
|
$Info->Action = 'actions.yaga';
|
2014-02-07 16:35:31 -06:00
|
|
|
$Actions = Yaga::ActionModel()->Get('Sort', 'asc');
|
2014-02-10 16:28:50 -06:00
|
|
|
$this->SetData('ActionCount', count($Actions));
|
2014-02-07 16:35:31 -06:00
|
|
|
$ActionData = serialize($Actions);
|
|
|
|
$FH->addFromString('actions.yaga', $ActionData);
|
2014-02-10 14:55:18 -06:00
|
|
|
$Hashes[] = md5($ActionData);
|
2014-02-07 16:35:31 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
// Add ranks and associated image
|
2014-02-10 16:28:50 -06:00
|
|
|
if($Include['Rank']) {
|
2014-02-10 15:18:28 -06:00
|
|
|
$Info->Rank = 'ranks.yaga';
|
2014-02-07 16:35:31 -06:00
|
|
|
$Ranks = Yaga::RankModel()->Get('Level', 'asc');
|
2014-02-10 16:28:50 -06:00
|
|
|
$this->SetData('RankCount', count($Ranks));
|
2014-02-07 16:35:31 -06:00
|
|
|
$RankData = serialize($Ranks);
|
|
|
|
$FH->addFromString('ranks.yaga', $RankData);
|
|
|
|
array_push($Images, C('Yaga.Ranks.Photo'), NULL);
|
2014-02-10 14:55:18 -06:00
|
|
|
$Hashes[] = md5($RankData);
|
2014-02-07 16:35:31 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
// Add badges and associated images
|
2014-02-10 16:28:50 -06:00
|
|
|
if($Include['Badge']) {
|
2014-02-10 15:18:28 -06:00
|
|
|
$Info->Badge = 'badges.yaga';
|
2014-02-07 16:35:31 -06:00
|
|
|
$Badges = Yaga::BadgeModel()->Get();
|
2014-02-10 16:28:50 -06:00
|
|
|
$this->SetData('BadgeCount', count($Badges));
|
2014-02-07 16:35:31 -06:00
|
|
|
$BadgeData = serialize($Badges);
|
|
|
|
$FH->addFromString('badges.yaga', $BadgeData);
|
2014-02-10 14:55:18 -06:00
|
|
|
$Hashes[] = md5($BadgeData);
|
2014-02-07 16:35:31 -06:00
|
|
|
foreach($Badges as $Badge) {
|
|
|
|
array_push($Images, $Badge->Photo);
|
|
|
|
}
|
2014-02-07 16:03:50 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
// Add in any images
|
2014-02-08 16:12:59 -06:00
|
|
|
$FilteredImages = array_filter($Images);
|
2014-02-10 16:28:50 -06:00
|
|
|
$ImageCount = count($FilteredImages);
|
|
|
|
$this->SetData('ImageCount', $ImageCount);
|
|
|
|
if($ImageCount > 0) {
|
2014-02-08 16:12:59 -06:00
|
|
|
$FH->addEmptyDir('images');
|
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-08 16:12:59 -06:00
|
|
|
foreach($FilteredImages as $Image) {
|
2014-08-27 13:56:09 -05:00
|
|
|
if($FH->addFile('.' . $Image, 'images/' . $Image) === FALSE) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(sprintf(T('Yaga.Error.AddFile'), $FH->getStatusString()));
|
2014-08-27 13:56:09 -05:00
|
|
|
//return FALSE;
|
2014-02-07 16:03:50 -06:00
|
|
|
}
|
2014-08-27 13:56:09 -05:00
|
|
|
$Hashes[] = md5_file('.' . $Image);
|
2014-02-07 16:03:50 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
// Save all the hashes
|
|
|
|
sort($Hashes);
|
|
|
|
$Info->MD5 = md5(implode(',', $Hashes));
|
|
|
|
$Info->EndDate = date('Y-m-d H:i:s');
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 14:05:13 -06:00
|
|
|
$EndTime = microtime(TRUE);
|
|
|
|
$TotalTime = $EndTime - $StartTime;
|
|
|
|
$m = floor($TotalTime / 60);
|
|
|
|
$s = $TotalTime - ($m * 60);
|
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
$Info->ElapsedTime = sprintf('%02d:%02.2f', $m, $s);
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-07 16:35:31 -06:00
|
|
|
$FH->setArchiveComment(serialize($Info));
|
2014-02-07 16:03:50 -06:00
|
|
|
if($FH->close()) {
|
2014-02-08 16:12:59 -06:00
|
|
|
return $Path;
|
2014-02-07 14:05:13 -06:00
|
|
|
}
|
|
|
|
else {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(sprintf(T('Yaga.Error.ArchiveSave'), $FH->getStatusString()));
|
2014-02-07 16:03:50 -06:00
|
|
|
return FALSE;
|
2014-02-07 14:05:13 -06:00
|
|
|
}
|
2014-02-06 14:44:21 -06:00
|
|
|
}
|
2014-02-10 14:55:18 -06:00
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
/**
|
|
|
|
* Extract the transport file and validate
|
2014-02-10 16:28:50 -06:00
|
|
|
*
|
2014-02-10 15:18:28 -06:00
|
|
|
* @param string The transport file path
|
|
|
|
* @return boolean Whether or not the transport file was extracted successfully
|
|
|
|
*/
|
2014-02-10 14:55:18 -06:00
|
|
|
protected function _ExtractZip($Filename) {
|
|
|
|
if(!file_exists($Filename)) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.FileDNE'));
|
2014-02-10 14:55:18 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ZipFile = new ZipArchive();
|
|
|
|
$Result = $ZipFile->open($Filename);
|
|
|
|
if($Result !== TRUE) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.ArchiveOpen'));
|
2014-02-10 14:55:18 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the metadata from the comment
|
|
|
|
$Comment = $ZipFile->comment;
|
|
|
|
$MetaData = unserialize($Comment);
|
2014-02-10 16:28:50 -06:00
|
|
|
|
2014-02-10 14:55:18 -06:00
|
|
|
$Result = $ZipFile->extractTo(PATH_UPLOADS . DS . 'import' . DS . 'yaga');
|
|
|
|
if($Result !== TRUE) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.ArchiveExtract'));
|
2014-02-10 14:55:18 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ZipFile->close();
|
|
|
|
|
|
|
|
// Validate checksum
|
|
|
|
if($this->_ValidateChecksum($MetaData) === TRUE) {
|
|
|
|
return $MetaData;
|
|
|
|
}
|
|
|
|
else {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.ArchiveChecksum'));
|
2014-02-10 14:55:18 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 16:28:50 -06:00
|
|
|
/**
|
2014-02-12 15:59:41 -06:00
|
|
|
* Overwrites Yaga configurations, dumps Yaga db tables, inserts data via the
|
|
|
|
* model, and copies uploaded files to the server
|
|
|
|
*
|
2014-02-10 16:28:50 -06:00
|
|
|
* @param stdClass The info object read in from the archive
|
|
|
|
* @param array Which tables should be overwritten
|
2014-08-25 15:53:10 -05:00
|
|
|
* @return bool Pass/Fail on the import being executed. Errors can exist on the
|
|
|
|
* form with a passing return value.
|
2014-02-10 16:28:50 -06:00
|
|
|
*/
|
|
|
|
protected function _ImportData($Info, $Include) {
|
2014-02-12 15:59:41 -06:00
|
|
|
if(!$Info) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import Configs
|
|
|
|
$Configs = unserialize(file_get_contents(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . $Info->Config));
|
|
|
|
$Configurations = $this->_NestedToDotNotation($Configs, 'Yaga');
|
|
|
|
foreach($Configurations as $Name => $Value) {
|
|
|
|
SaveToConfig($Name, $Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import model data
|
2014-02-10 16:28:50 -06:00
|
|
|
foreach($Include as $Key => $Value) {
|
|
|
|
if($Value) {
|
|
|
|
$Data = unserialize(file_get_contents(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . $Info->$Key));
|
|
|
|
Gdn::SQL()->EmptyTable($Key);
|
|
|
|
$ModelName = $Key . 'Model';
|
|
|
|
$Model = Yaga::$ModelName();
|
|
|
|
foreach($Data as $Datum) {
|
|
|
|
$Model->Insert((array)$Datum);
|
|
|
|
}
|
|
|
|
$this->SetData($Key . 'Count', $Model->GetCount());
|
|
|
|
}
|
|
|
|
}
|
2014-02-12 15:59:41 -06:00
|
|
|
|
|
|
|
// Import uploaded files
|
2014-08-27 13:56:09 -05:00
|
|
|
if(Gdn_FileSystem::Copy(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . 'images' . DS . 'uploads' . DS, PATH_UPLOADS . DS) === FALSE) {
|
2014-02-12 16:35:22 -06:00
|
|
|
$this->Form->AddError(T('Yaga.Error.TransportCopy'));
|
2014-02-10 16:28:50 -06:00
|
|
|
}
|
2014-08-25 15:53:10 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2014-02-10 16:28:50 -06:00
|
|
|
}
|
2014-02-12 15:59:41 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converted a nest config array into an array where indexes are the configuration
|
|
|
|
* strings and the value is the value
|
|
|
|
*
|
|
|
|
* @param array The nested array
|
|
|
|
* @param string What should the configuration strings be prefixed with
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function _NestedToDotNotation($Configs, $Prefix = '') {
|
|
|
|
$ConfigStrings = array();
|
|
|
|
|
|
|
|
foreach($Configs as $Name => $Value) {
|
|
|
|
if(is_array($Value)) {
|
|
|
|
$ConfigStrings = array_merge($ConfigStrings, $this->_NestedToDotNotation($Value, "$Prefix.$Name"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ConfigStrings["$Prefix.$Name"] = $Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ConfigStrings;
|
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
|
2014-02-10 15:18:28 -06:00
|
|
|
/**
|
|
|
|
* Inspects the Yaga transport files and calculates a checksum
|
2014-02-10 16:28:50 -06:00
|
|
|
*
|
2014-02-10 15:18:28 -06:00
|
|
|
* @param stdClass The metadata object read in from the transport file
|
|
|
|
* @return boolean Whether or not the checksum is valid
|
|
|
|
*/
|
2014-02-10 14:55:18 -06:00
|
|
|
protected function _ValidateChecksum($MetaData) {
|
|
|
|
$Hashes = array();
|
2014-02-12 15:59:41 -06:00
|
|
|
|
|
|
|
// Hash the config file
|
|
|
|
$Hashes[] = md5_file(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . $MetaData->Config);
|
|
|
|
|
2014-02-10 14:55:18 -06:00
|
|
|
// Hash the data files
|
2014-02-12 15:59:41 -06:00
|
|
|
if(property_exists($MetaData, 'Action')) {
|
|
|
|
$Hashes[] = md5_file(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . $MetaData->Action);
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
|
2014-02-12 15:59:41 -06:00
|
|
|
if(property_exists($MetaData, 'Badge')) {
|
|
|
|
$Hashes[] = md5_file(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . $MetaData->Badge);
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
|
2014-02-12 15:59:41 -06:00
|
|
|
if(property_exists($MetaData, 'Rank')) {
|
|
|
|
$Hashes[] = md5_file(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . $MetaData->Rank);
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
|
2014-02-10 14:55:18 -06:00
|
|
|
// Hash the image files
|
2014-02-10 15:18:28 -06:00
|
|
|
$Files = $this->_GetFiles(PATH_UPLOADS . DS . 'import' . DS . 'yaga' . DS . 'images');
|
2014-02-10 16:28:50 -06:00
|
|
|
$this->SetData('ImageCount', count($Files));
|
2014-02-10 14:55:18 -06:00
|
|
|
foreach($Files as $File) {
|
|
|
|
$Hashes[] = md5_file($File);
|
|
|
|
}
|
2014-02-10 16:28:50 -06:00
|
|
|
|
2014-02-10 14:55:18 -06:00
|
|
|
sort($Hashes);
|
|
|
|
$CalculatedChecksum = md5(implode(',', $Hashes));
|
2014-02-12 15:59:41 -06:00
|
|
|
|
|
|
|
if($CalculatedChecksum != $MetaData->MD5) {
|
2014-02-10 14:55:18 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-10 15:18:28 -06:00
|
|
|
* Returns a list of all files in a directory, recursively (Thanks @businessdad)
|
2014-02-10 14:55:18 -06:00
|
|
|
*
|
2014-02-10 15:18:28 -06:00
|
|
|
* @param string Directory The directory to scan for files
|
2014-08-25 15:53:10 -05:00
|
|
|
* @return array A list of Files and, optionally, Directories.
|
2014-02-10 14:55:18 -06:00
|
|
|
*/
|
2014-02-10 15:18:28 -06:00
|
|
|
protected function _GetFiles($Directory) {
|
2014-02-10 14:55:18 -06:00
|
|
|
$Files = array_diff(scandir($Directory), array('.', '..'));
|
|
|
|
$Result = array();
|
|
|
|
foreach($Files as $File) {
|
|
|
|
$FileName = $Directory . '/' . $File;
|
|
|
|
if(is_dir($FileName)) {
|
2014-02-10 15:18:28 -06:00
|
|
|
$Result = array_merge($Result, $this->_GetFiles($FileName));
|
2014-02-10 16:28:50 -06:00
|
|
|
continue;
|
2014-02-10 14:55:18 -06:00
|
|
|
}
|
|
|
|
$Result[] = $FileName;
|
|
|
|
}
|
|
|
|
return $Result;
|
|
|
|
}
|
|
|
|
|
2014-02-06 14:44:21 -06:00
|
|
|
}
|