View source
<?php
define('MINISITE_UPLOADPATH', 'minisite/upload');
define('MINISITE_ASSETPATH', 'minisite/static');
define('MINISITE_EXTENSIONS_WHITELIST', 'html htm js css png jpg gif svg pdf doc docx ppt pptx xls xlsx tif xml txt woff woff2 ttf eot');
define('MINISITE_EXTENSIONS_BLACKLIST', 'exe scr bmp');
define('MINISITE_EXTENSIONS_NOREWRITE', 'pdf doc docx ppt pptx xls xlsx tif xml txt');
define('MINISITE_MAXFILESIZE', format_size(file_upload_max_size()));
require_once dirname(__FILE__) . '/includes/minisite.field.inc';
require_once dirname(__FILE__) . '/includes/minisite.theme.inc';
function minisite_help($path, $arg) {
switch ($path) {
case 'admin/help#minisite':
$output = '<p>' . t("Provides the ability to upload arbitrary 'minisites' to a Drupal website.") . '</p>';
return $output;
}
}
function minisite_site_lookup() {
$minisite_info =& drupal_static(__FUNCTION__);
if (!isset($minisite_info)) {
module_load_include('inc', 'minisite', 'includes/minisite.site');
return minisite_site_lookup_path();
}
}
function minisite_site_load($redirect = TRUE) {
$minisite_info = minisite_site_lookup();
if (empty($minisite_info) || empty($minisite_info['mid']) || empty($minisite_info['source'])) {
return FALSE;
}
if (!empty($minisite_info['alias_status']) && $minisite_info['alias_status'] == 1) {
return $minisite_info;
}
if ($redirect) {
$minisite_site_url = _minisite_site_file_public_path_base_url() . $minisite_info['source'] . '/index.html';
drupal_goto($minisite_site_url);
}
else {
return $minisite_info;
}
}
function minisite_site_save($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as &$item) {
if (isset($item['fid'])) {
$file = file_load($item['fid']);
if (!empty($file)) {
module_load_include('inc', 'minisite', 'includes/minisite.site');
list($minisite_extract_path, $minisite_base_path, $minisite_listing) = minisite_site_asset_info($item['fid'], FALSE);
minisite_site_extract($file, $minisite_extract_path);
$item['site_path'] = $minisite_extract_path . '/' . $minisite_base_path;
$minisite_field_data = array(
'minisite_alias_status' => isset($item['alias_status']) ? $item['alias_status'] : 0,
'minisite_extract_path' => $minisite_extract_path,
'minisite_base_path' => $minisite_base_path,
);
$item['data'] = serialize($minisite_field_data);
$minisite_info = array(
'minisite_extract_path' => $minisite_extract_path,
'minisite_base_path' => $minisite_base_path,
'minisite_listing' => $minisite_listing,
);
drupal_register_shutdown_function('minisite_site_save_asset', $entity_type, $entity, $field['field_name'], $langcode, $item, $minisite_info);
}
}
}
}
function minisite_site_save_asset($entity_type, $entity, $field_name, $langcode, $item, $minisite_info) {
$entity_uri = entity_uri($entity_type, $entity);
$entity_path = $entity_uri['path'];
$entity_path_alias = drupal_get_path_alias($entity_path, $langcode);
list($entity_id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
$keys = array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'entity_id' => $entity_id,
'revision_id' => $vid,
'minisite_field_name' => $field_name,
'minisite_fid' => $item['fid'],
'language' => $langcode,
'source' => $minisite_info['minisite_extract_path'] . '/' . $minisite_info['minisite_base_path'],
);
$fields = array(
'alias' => $entity_path_alias,
'alias_status' => isset($item['alias_status']) ? $item['alias_status'] : 0,
);
db_merge('minisite_asset')
->key($keys)
->fields($fields)
->execute();
if (isset($item['alias_status']) && $item['alias_status'] == 1) {
foreach ($minisite_info['minisite_listing'] as $minisite_file) {
if (strpos(strtolower($minisite_file), '.html') !== FALSE || strpos(strtolower($minisite_file), '.htm') !== FALSE) {
$keys['source'] = $minisite_info['minisite_extract_path'] . '/' . $minisite_file;
$search = $minisite_info['minisite_base_path'];
$replace = $entity_path_alias;
$fields['alias'] = str_replace($search, $replace, $minisite_file);
db_merge('minisite_asset')
->key($keys)
->fields($fields)
->execute();
}
}
}
}
function minisite_site_delete($item, $field, $entity_type, $id) {
$file = (object) $item;
$file_usage = file_usage_list($file);
if ($file->status == 0 || !empty($file_usage['minisite'])) {
if (!empty($file)) {
db_delete('minisite_asset')
->condition('minisite_fid', $file->fid)
->execute();
module_load_include('inc', 'minisite', 'includes/minisite.site');
$path = 'public://' . MINISITE_ASSETPATH . '/' . minisite_site_hash($file);
file_unmanaged_delete_recursive($path);
}
}
}
function minisite_site_build($minisite_info) {
$minisite_html =& drupal_static(__FUNCTION__);
if (!isset($minisite_html)) {
$minisite_html = array();
}
if (!isset($minisite_html[$minisite_info['mid']])) {
module_load_include('inc', 'minisite', 'includes/minisite.site');
$html = minisite_site_parse($minisite_info);
if (empty($html)) {
$minisite_html[$minisite_info['mid']] = '';
_minisite_fast_404();
}
else {
$minisite_html[$minisite_info['mid']] = $html;
}
}
return $minisite_html[$minisite_info['mid']];
}