Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrickatwsrn/7ea74b8c0550097f186e81ed1c91fe14 to your computer and use it in GitHub Desktop.
Save patrickatwsrn/7ea74b8c0550097f186e81ed1c91fe14 to your computer and use it in GitHub Desktop.
MODX Revolution Plugin that saves all your Chunks and Snippets to the external files (in category folders) right in the Root directory. Save the plugin, go to "System Events", check "On Manager Cache Update", Refresh cache from Dashboard, Disable Plugin.
<?php
$chunks = $modx->getCollection('modChunk');
$snippets = $modx->getCollection('modSnippet');
foreach ($chunks as $chunk) {
$content = $chunk->getContent();
$category = "SELECT category FROM `modx_categories` WHERE id = " . $chunk->get('category') . "";
$query = $modx->query($category);
$aCategory = $query->fetch(PDO::FETCH_ASSOC);
mkdir('../chunks/'.$aCategory['category'], 0755, true);
$file = '../chunks/'.$aCategory['category'].'/'.$chunk->get('name').'.tpl';
$handle = fopen($file, 'w') or die('Cannot open file: '.$file);
fwrite($handle, $content);
}
foreach ($snippets as $snippet) {
$content = $snippet->getContent();
$category = "SELECT category FROM `modx_categories` WHERE id = " . $snippet->get('category') . "";
$query = $modx->query($category);
$aCategory = $query->fetch(PDO::FETCH_ASSOC);
mkdir('../snippets/'.$aCategory['category'], 0755, true);
$file = '../snippets/'.$aCategory['category'].'/'.$snippet->get('name').'.php';
$handle = fopen($file, 'w') or die ('Cannot open file: '.$file);
fwrite($handle, $content);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment