EditorButtonModule.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.2.3, at app/Modules/EditorButtonModule.php
| 1 | <?php namespace FluentForm\App\Modules; |
| 2 | |
| 3 | use FluentForm\App; |
| 4 | use FluentForm\Config; |
| 5 | use FluentForm\Framework\Helpers\ArrayHelper; |
| 6 | use FluentForm\Request; |
| 7 | use FluentForm\View; |
| 8 | |
| 9 | class EditorButtonModule |
| 10 | { |
| 11 | public function addButton() |
| 12 | { |
| 13 | if (! $this->pageSupportedMediaButtons()) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | $this->addMceButtonAssets(); |
| 18 | |
| 19 | $label = __('Add Form', 'fluentform'); |
| 20 | $url = App::publicUrl('img/icon_black_small.png'); |
| 21 | echo "<button id='fluent_form_insert_button' class='button'><span style='background-image: url({$url}); width: 16px;height: 16px;background-repeat: no-repeat;display: inline-block;background-size: contain;opacity: 0.4;margin-right: 5px;vertical-align: middle;'></span>{$label}</button>"; |
| 22 | } |
| 23 | |
| 24 | private function addMceButtonAssets() |
| 25 | { |
| 26 | wp_enqueue_script( |
| 27 | 'fluentform_editor_script', |
| 28 | fluentformMix('js/fluentform_editor_script.js'), |
| 29 | array('jquery'), |
| 30 | FLUENTFORM_VERSION |
| 31 | ); |
| 32 | |
| 33 | $forms = wpFluent()->table('fluentform_forms') |
| 34 | ->select(array('id', 'title')) |
| 35 | ->get(); |
| 36 | |
| 37 | $forms = array_map(function($item) { |
| 38 | return array('value' => $item->id, 'text'=> $item->title); |
| 39 | }, $forms); |
| 40 | |
| 41 | wp_localize_script('fluentform_editor_script', 'fluentform_editor_vars', array( |
| 42 | 'forms' => $forms |
| 43 | )); |
| 44 | } |
| 45 | |
| 46 | private function pageSupportedMediaButtons() |
| 47 | { |
| 48 | $currentPage = basename( $_SERVER['PHP_SELF'] ); |
| 49 | $isEligiblePage = in_array( $currentPage, array( |
| 50 | 'post.php', |
| 51 | 'page.php', |
| 52 | 'page-new.php', |
| 53 | 'post-new.php', |
| 54 | 'customize.php', |
| 55 | )); |
| 56 | |
| 57 | if ($isEligiblePage) { |
| 58 | $option = get_option('_fluentform_global_form_settings'); |
| 59 | $isEligiblePage = ArrayHelper::get($option, 'misc.classicEditorButton') == 'yes'; |
| 60 | } |
| 61 | |
| 62 | return apply_filters( 'fluentform_display_add_form_button', $isEligiblePage ); |
| 63 | } |
| 64 | |
| 65 | private function getMenuIcon() |
| 66 | { |
| 67 | return 'data:image/svg+xml;base64,'.base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><defs><style>.cls-1{fill:#fff;}</style></defs><title>dashboard_icon</title><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-1" d="M15.57,0H4.43A4.43,4.43,0,0,0,0,4.43V15.57A4.43,4.43,0,0,0,4.43,20H15.57A4.43,4.43,0,0,0,20,15.57V4.43A4.43,4.43,0,0,0,15.57,0ZM12.82,14a2.36,2.36,0,0,1-1.66.68H6.5A2.31,2.31,0,0,1,7.18,13a2.36,2.36,0,0,1,1.66-.68l4.66,0A2.34,2.34,0,0,1,12.82,14Zm3.3-3.46a2.36,2.36,0,0,1-1.66.68H3.21a2.25,2.25,0,0,1,.68-1.64,2.36,2.36,0,0,1,1.66-.68H16.79A2.25,2.25,0,0,1,16.12,10.53Zm0-3.73a2.36,2.36,0,0,1-1.66.68H3.21a2.25,2.25,0,0,1,.68-1.64,2.36,2.36,0,0,1,1.66-.68H16.79A2.25,2.25,0,0,1,16.12,6.81Z"/></g></g></svg>'); |
| 68 | } |
| 69 | } |
| 70 |