Skip to content

Commit 05a292d

Browse files
committed
Refine inline cloudinary image behaviour
1 parent 291b870 commit 05a292d

File tree

2 files changed

+104
-84
lines changed

2 files changed

+104
-84
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 4
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[{*.yml}]
14+
indent_size = 2
15+
indent_style = space
+89-84
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,114 @@
11
<?php
22

33
class MarkdownCloudinaryUpload extends Extension {
4-
54
/**
65
* update the field holder adding new javascript
76
*/
87
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+
}
1412
}
1513

1614
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+
);
2219

2320
/**
2421
* @return Form
2522
*/
2623
public function ImageForm(){
2724

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');
6966
$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+
}
7572

7673
/**
7774
* get markdown image url
7875
*
7976
* @return string
8077
*/
8178
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+
}
109114
}

0 commit comments

Comments
 (0)