This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.php
68 lines (61 loc) · 2.14 KB
/
script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$template = KService::get('repos://site/templates.menu', array(
'resources' => 'templates_menu',
'identity_property' => 'menuid'
))->getQuery()->clientId(0)->fetchValue('template');
$path = WWW_ROOT.'/templates/'.$template.'/html/com_html/content';
$dialog = $console->getHelperSet()->get('dialog');
if ( !$dialog->askConfirmation($output, '<info>Export articles into '.$template.' template ? (y\n) </info>') ) {
do {
$path = $dialog->ask($output, '<info>Enter the path to where you want to export articles to ? ');
} while( empty($path) );
}
if ( !file_exists($path) )
{
if ( !mkdir($path, 0755) ) {
throw new \RuntimeException("Unable to create the directory $path");
}
}
$cats = \KService::get('repos:contents.category', array(
'resources' => 'categories'
));
$sections = \KService::get('repos:contents.section', array(
'resources' => 'sections'
));
$artilces = \KService::get('repos:contents.article', array(
'resources' => 'content',
'relationships' => array(
'section' => array('child_column'=>'sectionid'),
'category' => array('child_column'=>'catid')
)
));
foreach($artilces->fetchSet() as $article)
{
$base = $path;
if ( isset($article->category) )
{
$base = $base.'/'.str_replace('-','_',$article->category->alias);
if ( !file_exists($base) &&
!mkdir($base, 0755) ) {
throw new \RuntimeException("Unable to create the directory $base");
}
}
if ( isset($article->section) )
{
$base = $base.'/'.str_replace('-','_',$article->section->alias);
if ( !file_exists($base) &&
!mkdir($base, 0755) ) {
throw new \RuntimeException("Unable to create the directory $base");
}
}
$output->writeLn('Exporting '.$article->title.'...');
$title = $article->title;
$filename = str_replace('-','_',$article->alias).'.php';
$text = $article->introtext;
$content = <<<EOF
<?php @title('$title') ?>
$text
EOF;
file_put_contents($base.'/'.$filename, $content);
}
?>