| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Flynt\Features\TinyMce; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Flynt\Utils\Feature; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Flynt\Utils\Asset; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // Clean Up TinyMCE Buttons | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | // First Bar | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | add_filter('mce_buttons', function ($buttons) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     $toolbarsFromFile = getToolbarsFromJson(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     return $toolbarsFromFile['Default'][0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | // Second Bar | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | add_filter('mce_buttons_2', function ($buttons) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | add_filter('tiny_mce_before_init', function ($init) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     $options = Feature::getOptions('flynt-tiny-mce'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     $init['block_formats'] = getBlockFormats($options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     $init['style_formats'] = getStyleFormats($options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     return $init; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | add_filter('acf/fields/wysiwyg/toolbars', function ($toolbars) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     // Load Toolbars and parse them into TinyMCE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     $toolbarsFromFile = getToolbarsFromJson(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     if ($toolbarsFromFile) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $toolbars = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         foreach ($toolbars as $name => $toolbar) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             array_unshift($toolbar, []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             $toolbars[$name] = $toolbar; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     return $toolbars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 44 |  | View Code Duplication | function getToolbarsFromJson() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     $options = Feature::getOptions('flynt-tiny-mce'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     if (isset($options[0]) && isset($options[0]['toolbarsConfigPath'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $configPath = $options[0]['paths']['toolbarsConfigPath']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $configPath = 'config/toolbars.json'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     $filePath = Asset::requirePath('/Features/TinyMce/' . $configPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     if (file_exists($filePath)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return json_decode(file_get_contents($filePath), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | function getBlockFormats($options) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     if (isset($options[0]) && isset($options[0]['blockformatsConfigPath'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $configPath = $options[0]['paths']['blockformatsConfigPath']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $configPath = 'config/blockformats.json'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     $filePath = Asset::requirePath('/Features/TinyMce/' . $configPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     if (file_exists($filePath)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $blockstyles = json_decode(file_get_contents($filePath), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $blockstylesQueries = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         foreach ($blockstyles as $label => $tag) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $blockstylesQueries[] = $label . '=' . $tag; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return implode(';', $blockstylesQueries); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return 'Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 82 |  | View Code Duplication | function getStyleFormats($options) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 83 |  |  | { | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |     if (isset($options[0]) && isset($options[0]['styleformatsConfigPath'])) { | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |         $configPath = $options[0]['paths']['styleformatsConfigPath']; | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |     } else { | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |         $configPath = 'config/styleformats.json'; | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |     $filePath = Asset::requirePath('/Features/TinyMce/' . $configPath); | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |     if (file_exists($filePath)) { | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |         // Get contents as JSON string first and convert it to array for sending it to style_formats as true js array | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |         $loadedStyle = json_decode(file_get_contents($filePath), true); | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |         return json_encode($loadedStyle); | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |     } else { | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |         return false; | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 98 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.