Skip to content

Commit

Permalink
export to html feature done
Browse files Browse the repository at this point in the history
  • Loading branch information
yllumi committed Dec 2, 2014
1 parent 671f1db commit c8b8d00
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 21 deletions.
55 changes: 51 additions & 4 deletions system/modules/panel/controllers/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ function index()
$this->template->view('export');
}

function check_writable()
{
$folder = $this->input->post('location');

// if(!file_exists($this->export_location))
// mkdir($this->export_location, 0777);

if(is_writable($folder))
echo '{"status":"success", "message":"Folder writable."}';
else
echo '{"status":"error", "message":"Folder destination is not writable. Make it writable first."}';
}

function copy_theme()
{
$this->export_location = ($this->input->post('location'))
? $this->input->post('location')
: $this->export_location;

$theme = $this->config->item('theme');
$theme_locations = $this->template->theme_locations();
$theme_location = false;
Expand All @@ -31,16 +48,34 @@ function copy_theme()
}
}

if(!file_exists($theme_location))
if(!file_exists($this->export_location.'/'.$theme_location.'/'.$theme.'/assets'))
mkdir($this->export_location.'/'.$theme_location.'/'.$theme.'/assets', 0777, true);

recurse_copy($theme_location.$theme.'/assets', $this->export_location.'/'.$theme_location.$theme.'/assets');

echo '{"status":"success", "message":"Theme copied."}';
}

function copy_files()
{
$this->export_location = ($this->input->post('location'))
? $this->input->post('location')
: $this->export_location;

if(!file_exists($this->export_location.'/sites/'.SITE_SLUG.'/content/'))
mkdir($this->export_location.'/sites/'.SITE_SLUG.'/content/', 0777, true);

recurse_copy('sites/'.SITE_SLUG.'/content/files', $this->export_location.'/sites/'.SITE_SLUG.'/content/files');

echo '{"status":"success", "message":"Files content copied."}';
}

function export_pages($data = false, $parent = '', $depth = 1)
{
$this->export_location = ($this->input->post('location'))
? $this->input->post('location')
: $this->export_location;

$page = ($data)? $data : $this->pusaka->get_pages_tree();

$uplink = '';
Expand All @@ -67,7 +102,7 @@ function export_pages($data = false, $parent = '', $depth = 1)
write_file($this->export_location.'/index.html', $file);
}

foreach ($pages as $slug => $page) {
foreach ($page as $slug => $page) {
$file = str_replace($search, $replace, $this->_render_page(site_url($page['url'])));
write_file($this->export_location.'/'.$parent.$slug.'.html', $file);

Expand All @@ -85,8 +120,9 @@ function export_pages($data = false, $parent = '', $depth = 1)

function export_blog()
{
if(!file_exists($this->export_location))
mkdir($this->export_location, 0777);
$this->export_location = ($this->input->post('location'))
? $this->input->post('location')
: $this->export_location;

// sync post first
$this->pusaka->sync_post();
Expand Down Expand Up @@ -169,10 +205,15 @@ function export_blog()
write_file($this->export_location.'/'.$date_folder.'/'.$postslug.'.html', $file);
}

echo '{"status":"success", "message":"Blog exported."}';
}

function add_missing_index_folder($data = false, $parent = '', $depth = 1)
{
$this->export_location = ($this->input->post('location'))
? $this->input->post('location')
: $this->export_location;

$uplink = '../';
if($depth > 1)
for ($i=1; $i < $depth; $i++)
Expand Down Expand Up @@ -210,6 +251,12 @@ function add_missing_index_folder($data = false, $parent = '', $depth = 1)
echo '{"status":"success", "message":"Missing index files created."}';
}

function success()
{
$this->session->set_flashdata('success','Export content to HTML success. Go check the folder');
redirect('panel/export');
}

function _render_page($url)
{
return file_get_contents($url);
Expand Down
6 changes: 6 additions & 0 deletions system/modules/panel/views/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<div class="btn-label">Settings</div>
</a>
</div>
<div class="col-sm-2 col-xs-6">
<a href="{{ func.site_url }}panel/export" class="btn btn-block btn-dashboard">
<div class="btn-icon"><span class="fa fa-html5"></span></div>
<div class="btn-label">Export to HTML</div>
</a>
</div>
</div>
</div>

Expand Down
88 changes: 81 additions & 7 deletions system/modules/panel/views/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,90 @@
<div class="col-md-6">
<h1>EXPORT TO HTML</h1>
</div>
<?php if($this->config->item('url_suffix') == '.html'): ?>
<div class="col-md-6 align-right">
<div><button class="btn btn-transparent" data-toggle="modal" data-target="#areaModal"><span class="fa fa-html5"></span> Export to Static HTML</button></div>
</div>
<?php endif; ?>
</div>
<br>

<div class="panel panel-default">
<div class="panel-body align-center">
<p class="option">There is no export history yet.</p>
<div class="row">
<div class="col-md-9">
<input type="text" class="form-control" name="location" id="location" placeholder="Fill export location, i.e. D:/xampp/htdocs/html or /var/www/html">
</div>
<div class="col-md-3">
<?php if($this->config->item('url_suffix') == '.html'): ?>
<button class="btn btn-success form-control" id="btn-export">Export to HTML</button>
<?php endif; ?>
</div>
</div>
<br>
<div class="progress-panel" style="display:none">
<div class="progress">
<div id="progress-bar" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width:0%"></div>
</div>
<div id="progress-msg" class="align-left">
<p>Processing..</p>
</div>
</div>
</div>
</div>
</div>

<script>
var url = [
{"url":"<?php echo site_url('panel/export/check_writable');?>"},
{"url":"<?php echo site_url('panel/export/copy_theme');?>"},
{"url":"<?php echo site_url('panel/export/copy_files');?>"},
{"url":"<?php echo site_url('panel/export/export_pages');?>"},
{"url":"<?php echo site_url('panel/export/export_blog');?>"},
{"url":"<?php echo site_url('panel/export/add_missing_index_folder');?>"}
];
var step = 0;
var progress = 0;
var satuan = Math.floor(100 / url.length);

$('#btn-export').click(function(){
var dest = $('#location').val();
if(jQuery.trim(dest) == ''){
$('.alert-danger').fadeOut('fast').fadeIn()
.children('span').html('Specify the export destination first.');
$(this).focus();
return;
}

$('.progress-panel').fadeIn();
get_ajax(dest, url, step);
});


function get_ajax(dest, url, step)
{
progress = satuan * step;
$('#progress-bar').css('width', progress+'%');

$.ajax({
url: url[step].url,
type: 'POST',
data: {location:dest}
})
.done(function(data){
var msg = jQuery.parseJSON(data);
if(msg.status == 'error'){
$('.alert-danger').fadeOut('fast').fadeIn()
.children('span').html(msg.message);
$('.progress-panel').fadeOut();
return;
}

$('#progress-msg').append('<p><span class="fa fa-check"></span> '+msg.message+'</p>');

step = step + 1;
if(step < url.length)
get_ajax(dest, url, step);
else {
$('#progress-bar').css('width', '100%');
setTimeout(function(){
window.location.href = "<?php echo site_url('panel/export/success'); ?>";
}, 1000);
}
})
}
</script>
18 changes: 9 additions & 9 deletions system/themes/jakarta/views/partials/post_sidebar.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<div class="widget">
<h3>Labels</h3>
<?php $labels = $this->pusaka->get_labels();
asort($labels);
foreach ($labels as $url => $label): ?>
<label class="label label-info"><?php echo anchor($url, $label); ?></label>
<?php endforeach; ?>
</div>

<div class="widget">
<h3>Like Our Page</h3>
<iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fnyankod&amp;width=208&amp;height=290&amp;colorscheme=light&amp;show_faces=true&amp;header=false&amp;stream=false&amp;show_border=false&amp;appId=414317858711157" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:208px; height:290px;" allowTransparency="true"></iframe>
Expand All @@ -8,12 +17,3 @@
<a class="twitter-timeline" href="https://twitter.com/nyankodTWEET" data-widget-id="267929124176269312">Tweets by @nyankodTWEET</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>

<div class="widget">
<h3>Labels</h3>
<?php $labels = $this->pusaka->get_labels();
asort($labels);
foreach ($labels as $url => $label): ?>
<label class="label label-info"><?php echo anchor($url, $label); ?></label>
<?php endforeach; ?>
</div>
8 changes: 8 additions & 0 deletions system/themes/pusakapanel/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -971,4 +971,12 @@ small, .small {
}
span.code {
font-family: 'Courier New', sans-serif;
}

#progress-msg {
text-align: left;
margin-left: 20px;
}
#progress-msg p {
margin: 0;
}
2 changes: 1 addition & 1 deletion system/themes/pusakapanel/views/partials/head_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'structure' => array(
'#' => '<span class="fa fa-newspaper-o"></span><span class="nav-tooltip">Structure</span>',
'navigation' => '<span class="fa fa-list"></span> Navigation',
//'export' => '<span class="fa fa-html5"></span> Export to HTML'
'export' => '<span class="fa fa-html5"></span> Export to HTML'
),
'settings' => array(
'#' => '<span class="fa fa-gears"></span><span class="nav-tooltip">Settings</span>',
Expand Down

0 comments on commit c8b8d00

Please sign in to comment.