|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | class MarkdownCloudinaryUpload extends Extension {
|
4 |
| - |
5 | 4 | /**
|
6 | 5 | * update the field holder adding new javascript
|
7 | 6 | */
|
8 | 7 | public function updateFieldHolder(){
|
9 |
| - if(Config::inst()->get('MarkdownCloudinaryUpload', 'enable') == true){ |
10 |
| - Requirements::javascript('markdown/javascript/MarkdownCloudinaryUpload.js'); |
11 |
| - } |
12 |
| - } |
13 |
| - |
| 8 | + if(Config::inst()->get('MarkdownCloudinaryUpload', 'enable') == true){ |
| 9 | + Requirements::javascript('markdown/javascript/MarkdownCloudinaryUpload.js'); |
| 10 | + } |
| 11 | + } |
14 | 12 | }
|
15 | 13 |
|
16 | 14 | class MarkdownCloudinaryUpload_Controller extends Controller {
|
17 |
| - |
18 |
| - private static $allowed_actions = array( |
19 |
| - 'ImageForm', |
20 |
| - 'getImageTag' |
21 |
| - ); |
| 15 | + private static $allowed_actions = array( |
| 16 | + 'ImageForm', |
| 17 | + 'getImageTag' |
| 18 | + ); |
22 | 19 |
|
23 | 20 | /**
|
24 | 21 | * @return Form
|
25 | 22 | */
|
26 | 23 | public function ImageForm(){
|
27 | 24 |
|
28 |
| - Requirements::css(FRAMEWORK_DIR .'/admin/thirdparty/jquery-notice/jquery.notice.css'); |
29 |
| - Requirements::css(FRAMEWORK_DIR .'/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css'); |
30 |
| - Requirements::css(FRAMEWORK_DIR .'/thirdparty/jstree/themes/apple/style.css'); |
31 |
| - Requirements::css(FRAMEWORK_DIR .'/css/GridField.css'); |
32 |
| - Requirements::css(FRAMEWORK_DIR .'/admin/css/screen.css'); |
33 |
| - Requirements::css(CMS_DIR . '/css/screen.css'); |
34 |
| - |
35 |
| - |
36 |
| - Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js'); |
37 |
| - Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); |
38 |
| - |
39 |
| - $numericLabelTmpl = '<span class="step-label"><span class="flyout">%d</span><span class="arrow"></span>' |
40 |
| - . '<strong class="title">%s</strong></span>'; |
41 |
| - $form = new Form( |
42 |
| - $this, |
43 |
| - "ImageForm", |
44 |
| - new FieldList( |
45 |
| - $contentComposite = new CompositeField( |
46 |
| - new LiteralField('Step1', |
47 |
| - '<div class="step1">' |
48 |
| - . sprintf($numericLabelTmpl, '1', _t('HtmlEditorField.SELECTIMAGE', 'Select Image')) . '</div>' |
49 |
| - ), |
50 |
| - CloudinaryFileField::create('Image')->addExtraClass('markdown-popup'), |
51 |
| - new LiteralField('Step2', |
52 |
| - '<div class="step2">' |
53 |
| - . sprintf($numericLabelTmpl, '2', _t('HtmlEditorField.DETAILS', 'Details')) . '</div>' |
54 |
| - ), |
55 |
| - NumericField::create('Width'), |
56 |
| - NumericField::create('Height'), |
57 |
| - TextField::create('AltText')->setTitle('Alter Text') |
58 |
| - ) |
59 |
| - ), |
60 |
| - new FieldList( |
61 |
| - FormAction::create('insert', _t('HtmlEditorField.BUTTONINSERTIMAGE', 'Insert Image')) |
62 |
| - ->addExtraClass('ss-ui-action-constructive') |
63 |
| - ->setAttribute('data-icon', 'accept') |
64 |
| - ->setUseButtonTag(true) |
65 |
| - ) |
66 |
| - ); |
67 |
| - |
68 |
| - $contentComposite->addExtraClass('ss-insert-image content ss-insert-media'); |
| 25 | + Requirements::css(FRAMEWORK_DIR .'/admin/thirdparty/jquery-notice/jquery.notice.css'); |
| 26 | + Requirements::css(FRAMEWORK_DIR .'/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css'); |
| 27 | + Requirements::css(FRAMEWORK_DIR .'/thirdparty/jstree/themes/apple/style.css'); |
| 28 | + Requirements::css(FRAMEWORK_DIR .'/css/GridField.css'); |
| 29 | + Requirements::css(FRAMEWORK_DIR .'/admin/css/screen.css'); |
| 30 | + Requirements::css(CMS_DIR . '/css/screen.css'); |
| 31 | + |
| 32 | + Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js'); |
| 33 | + Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); |
| 34 | + |
| 35 | + $numericLabelTmpl = '<span class="step-label"><span class="flyout">%d</span><span class="arrow"></span>' |
| 36 | + . '<strong class="title">%s</strong></span>'; |
| 37 | + |
| 38 | + $form = new Form( |
| 39 | + $this, |
| 40 | + "ImageForm", |
| 41 | + new FieldList( |
| 42 | + $contentComposite = new CompositeField( |
| 43 | + new LiteralField('Step1', |
| 44 | + '<div class="step1">' |
| 45 | + . sprintf($numericLabelTmpl, '1', _t('HtmlEditorField.SELECTIMAGE', 'Select Image')) . '</div>' |
| 46 | + ), |
| 47 | + CloudinaryFileField::create('Image')->addExtraClass('markdown-popup'), |
| 48 | + new LiteralField('Step2', |
| 49 | + '<div class="step2">' |
| 50 | + . sprintf($numericLabelTmpl, '2', _t('HtmlEditorField.DETAILS', 'Details')) . '</div>' |
| 51 | + ), |
| 52 | + NumericField::create('Width'), |
| 53 | + NumericField::create('Height'), |
| 54 | + TextField::create('AltText')->setTitle('Alternate Text') |
| 55 | + ) |
| 56 | + ), |
| 57 | + new FieldList( |
| 58 | + FormAction::create('insert', _t('HtmlEditorField.BUTTONINSERTIMAGE', 'Insert Image')) |
| 59 | + ->addExtraClass('ss-ui-action-constructive') |
| 60 | + ->setAttribute('data-icon', 'accept') |
| 61 | + ->setUseButtonTag(true) |
| 62 | + ) |
| 63 | + ); |
| 64 | + |
| 65 | + $contentComposite->addExtraClass('ss-insert-image content ss-insert-media'); |
69 | 66 | $form->setFormAction('cloudinary-upload/ImageForm');
|
70 |
| - $form->unsetValidator(); |
71 |
| - $form->loadDataFrom($this); |
72 |
| - $form->addExtraClass('markdownfield-form markdowneditorfield-imageform '); |
73 |
| - return $form; |
74 |
| - } |
| 67 | + $form->unsetValidator(); |
| 68 | + $form->loadDataFrom($this); |
| 69 | + $form->addExtraClass('markdownfield-form markdowneditorfield-imageform '); |
| 70 | + return $form; |
| 71 | + } |
75 | 72 |
|
76 | 73 | /**
|
77 | 74 | * get markdown image url
|
78 | 75 | *
|
79 | 76 | * @return string
|
80 | 77 | */
|
81 | 78 | public function getImageTag(){
|
82 |
| - $strRet = ''; |
83 |
| - $arrPieces = array('cloudinary_image'); |
84 |
| - if(isset($_POST['Image']) && ($image = $_POST['Image'])){ |
85 |
| - $arrPieces[] = "id='".CloudinaryUtils::public_id($image['URL'])."'"; |
86 |
| - if(!empty($_POST['Width']) && !empty($_POST['Height'])) { |
87 |
| - $arrPieces[] = "width=" . $_POST['Width']; |
88 |
| - $arrPieces[] = "height=" . $_POST['Height']; |
89 |
| - } |
90 |
| - if(!empty($image['Credit'])) { |
91 |
| - $arrPieces[] = "credit='" . $image['Credit']."'"; |
92 |
| - } |
93 |
| - if(!empty($image['Caption'])) { |
94 |
| - $arrPieces[] = "caption='" . $image['Caption']."'"; |
95 |
| - } |
96 |
| - |
97 |
| - $arrPieces[] = "gravity='" . $image['Gravity']."'"; |
98 |
| - |
99 |
| - if(!empty($_POST['AltText'])) { |
100 |
| - $arrPieces[] = "alt='".$_POST['AltText']."'"; |
101 |
| - } |
102 |
| - |
103 |
| - $strRet = '['. implode(', ', $arrPieces) . ']'; |
104 |
| - } |
105 |
| - return Convert::array2json(array( |
106 |
| - 'Markdown' => $strRet |
107 |
| - )); |
108 |
| - } |
| 79 | + $strRet = ''; |
| 80 | + $arrPieces = array('cloudinary_image'); |
| 81 | + |
| 82 | + if(isset($_POST['Image']) && ($image = $_POST['Image'])) { |
| 83 | + $arrPieces[] = "id='".CloudinaryUtils::public_id($image['URL'])."'"; |
| 84 | + |
| 85 | + if(!empty($_POST['Width'])) { |
| 86 | + $arrPieces[] = "width=" . $_POST['Width']; |
| 87 | + } |
| 88 | + |
| 89 | + if(!empty($_POST['Height'])) { |
| 90 | + $arrPieces[] = "height=" . $_POST['Height']; |
| 91 | + } |
| 92 | + |
| 93 | + if(!empty($image['Credit'])) { |
| 94 | + $arrPieces[] = "credit='" . $image['Credit']."'"; |
| 95 | + } |
| 96 | + |
| 97 | + if(!empty($image['Caption'])) { |
| 98 | + $arrPieces[] = "caption='" . $image['Caption']."'"; |
| 99 | + } |
| 100 | + |
| 101 | + $arrPieces[] = "gravity='" . $image['Gravity']."'"; |
| 102 | + |
| 103 | + if(!empty($_POST['AltText'])) { |
| 104 | + $arrPieces[] = "alt='".$_POST['AltText']."'"; |
| 105 | + } |
| 106 | + |
| 107 | + $strRet = '['. implode(', ', $arrPieces) . ']'; |
| 108 | + } |
| 109 | + |
| 110 | + return Convert::array2json(array( |
| 111 | + 'Markdown' => $strRet |
| 112 | + )); |
| 113 | + } |
109 | 114 | }
|
0 commit comments