Skip to content

Instantly share code, notes, and snippets.

@kanetei
Last active November 22, 2017 02:14
Show Gist options
  • Save kanetei/4f5086cba654520618ed0d64eedc0480 to your computer and use it in GitHub Desktop.
Save kanetei/4f5086cba654520618ed0d64eedc0480 to your computer and use it in GitHub Desktop.
Advanced HTML Block:強制ダウンロードするリンクを挿入出来るようにする
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<p>
<button id="ccm-block-advanced-html-page-selector" type="button" class="btn btn-primary btn-xs"><?php echo t('Insert Page Link'); ?></button>
<button id="ccm-block-advanced-html-inline-file-selector" type="button" class="btn btn-primary btn-xs"><?php echo t('Insert File Inline Link'); ?></button>
<button id="ccm-block-advanced-html-download-file-selector" type="button" class="btn btn-primary btn-xs"><?php echo t('Insert File Download Link'); ?></button>
<button id="ccm-block-advanced-html-base-url" type="button" class="btn btn-primary btn-xs"><?php echo t('Insert Base URL'); ?></button>
<button id="ccm-block-advanced-html-force-download-file-selector" type="button" class="btn btn-primary btn-xs"><?php echo t('Insert Force File Download Link'); ?></button>
</p>
<div id="ccm-block-advanced-html-value"><?php echo htmlspecialchars($content,ENT_QUOTES,APP_CHARSET)?></div>
<textarea style="display: none" id="ccm-block-advanced-html-value-textarea" name="content"></textarea>
<style type="text/css">
#ccm-block-advanced-html-value {
width: 100%;
border: 1px solid #eee;
height: 490px;
}
</style>
<?php
$c = Page::getCurrentPage();
$cID = ($c instanceof Page) ? $c->getCollectionID() : 0;
?>
<script type="text/javascript">
$(function() {
var editor = ace.edit("ccm-block-advanced-html-value");
editor.setTheme("ace/theme/eclipse");
editor.getSession().setMode("ace/mode/html");
refreshTextarea(editor.getValue());
editor.getSession().on('change', function() {
refreshTextarea(editor.getValue());
});
$('#ccm-block-advanced-html-page-selector').on('click', function() {
ConcretePageAjaxSearch.launchDialog(function(data) {
editor.insert('{CCM:CID_' + data.cID + '}');
});
});
$('#ccm-block-advanced-html-inline-file-selector').on('click', function() {
ConcreteFileManager.launchDialog(function(data) {
editor.insert('{CCM:FID_' + data.fID + '}');
});
});
$('#ccm-block-advanced-html-download-file-selector').on('click', function() {
ConcreteFileManager.launchDialog(function(data) {
editor.insert('{CCM:FID_DL_' + data.fID + '}');
});
});
$('#ccm-block-advanced-html-base-url').on('click', function() {
editor.insert('{CCM:BASE_URL}');
});
$('#ccm-block-advanced-html-force-download-file-selector').on('click', function() {
ConcreteFileManager.launchDialog(function(data) {
editor.insert('{CCM:BASE_URL}' + '/download_file/force/' + data.fID + '/<?= $cID ?>');
});
});
});
function refreshTextarea(contents) {
$('#ccm-block-advanced-html-value-textarea').val(contents);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment