function cf_print_media_templates()
{
    $replaces = array('/<option value="center"/' => '<option value="left pull-left">' . esc_attr('Bootstrap Left') . '</option>$0', '/<option value="none"/' => '<option value="right pull-right">' . esc_attr('Bootstrap Right') . '</option>$0', '/<button class="button" value="center">/' => '<button class="button" value="left pull-left">' . esc_attr('Bootstrap Left') . '</button>$0', '/<button class="button active" value="none">/' => '<button class="button" value="right pull-right">' . esc_attr('Bootstrap Right') . '</button>$0');
    ob_start();
    wp_print_media_templates();
    echo preg_replace(array_keys($replaces), array_values($replaces), ob_get_clean());
}
 public function upload_scripts()
 {
     wp_enqueue_media();
     wp_print_media_templates();
     wp_enqueue_script('upload_media_widget', CHERRY_PLUGIN_URL . 'admin/js/upload-media-files.js');
 }
 /**
  * Modifies the media templates for Backbone to include attachment taxonomy term dropdowns.
  *
  * This approach is kind of hacky, but there is no other way to adjust this output.
  *
  * @since 1.0.0
  * @access public
  */
 public function print_media_templates()
 {
     ob_start();
     wp_print_media_templates();
     $output = ob_get_clean();
     $taxonomy_output = $this->get_taxonomy_media_template_output();
     $output = preg_replace('#<script type="text/html" id="tmpl-attachment-details">(.+)</script>#Us', '<script type="text/html" id="tmpl-attachment-details">$1' . $taxonomy_output . '</script>', $output);
     $output = str_replace('<div class="attachment-compat"></div>', $taxonomy_output . "\n" . '<div class="attachment-compat"></div>', $output);
     echo $output;
 }
 /**
  * Tweaks WordPress media templates so that we can
  * display HTML we need for plugin features
  *
  * @return void
  */
 public function __modifyWordpressMediaTemplates()
 {
     ob_start();
     wp_print_media_templates();
     $original_html = ob_get_clean();
     $search = '<div class="settings">';
     ob_start();
     include Config::getInstance()->get('plugin_base_path') . 'templates/attachment-editor/module.php';
     $module_html = ob_get_clean();
     echo str_replace($search, $module_html . $search, $original_html);
 }
    /**
     * Hook up the "Edit Image" links/buttons in the admin ui
     */
    private function hookupUI()
    {
        add_filter('media_row_actions', function ($actions, $post) {
            $newaction['ilab_edit_image'] = '<a class="ilab-thickbox" href="' . $this->editPageURL($post->ID) . '" title="Edit Image">' . __('Edit Image') . '</a>';
            return array_merge($actions, $newaction);
        }, 10, 2);
        add_action('wp_enqueue_media', function () {
            remove_action('admin_footer', 'wp_print_media_templates');
            add_action('admin_footer', function () {
                ob_start();
                wp_print_media_templates();
                $result = ob_get_clean();
                echo $result;
                ?>
                <script>
                    jQuery(document).ready(function() {

                        jQuery('input[type="button"]')
                            .filter(function() {
                                return this.id.match(/imgedit-open-btn-[0-9]+/);
                            })
                            .each(function(){
                                var image_id=this.id.match(/imgedit-open-btn-([0-9]+)/)[1];
                                var button=jQuery(this);
                                button.off('click');
                                button.attr('onclick',null);
                                button.on('click',function(e){
                                    e.preventDefault();

                                    ILabModal.loadURL("<?php 
                echo relative_admin_url('admin-ajax.php');
                ?>
?action=ilab_imgix_edit_page&image_id="+image_id,false,null);

                                    return false;
                                });
                        });

                        jQuery(document).on('click','.ilab-edit-attachment', function(e){
                            var button=jQuery(this);
                            var image_id=button.data('id');
                            e.preventDefault();

                            ILabModal.loadURL("<?php 
                echo relative_admin_url('admin-ajax.php');
                ?>
?action=ilab_imgix_edit_page&image_id="+image_id,false,null);

                            return false;
                        });

                        attachTemplate = jQuery('#tmpl-attachment-details-two-column');
                        if (attachTemplate) {
                            attachTemplate.text(attachTemplate.text().replace('<button type="button" class="button edit-attachment"><?php 
                _e('Edit Image');
                ?>
</button>','<button type="button" data-id="{{data.id}}" class="button ilab-edit-attachment"><?php 
                _e('Edit Image');
                ?>
</button>'));
                        }

                        attachTemplate=jQuery('#tmpl-attachment-details-two-column');
                        if (attachTemplate)
                        {
                            attachTemplate.text(attachTemplate.text().replace(/(<a class="(?:.*)edit-attachment(?:.*)"[^>]+[^<]+<\/a>)/,'<a href="<?php 
                echo $this->editPageURL('{{data.id}}');
                ?>
" class="ilab-thickbox button edit-imgix"><?php 
                echo __('Edit Image');
                ?>
</a>'));
                        }

                        attachTemplate=jQuery('#tmpl-attachment-details');
                        if (attachTemplate)
                            attachTemplate.text(attachTemplate.text().replace(/(<a class="(?:.*)edit-attachment(?:.*)"[^>]+[^<]+<\/a>)/,'<a class="ilab-thickbox edit-imgix" href="<?php 
                echo $this->editPageURL('{{data.id}}');
                ?>
"><?php 
                echo __('Edit Image');
                ?>
</a>'));
                    });
                </script>
                <?php 
            });
        });
    }
 public function upload_scripts($hook)
 {
     if ('widgets.php' !== $hook) {
         return;
     }
     wp_enqueue_media();
     wp_print_media_templates();
     wp_enqueue_script('upload_media_widget', CHERRY_PLUGIN_URL . 'admin/js/upload-media-files.js');
 }
    /**
     * Hook up the "Crop Image" links/buttons in the admin ui
     */
    private function hookupUI()
    {
        // TODO: Still need to hook up the edit attachment page
        add_filter('media_row_actions', function ($actions, $post) {
            $newaction['ilab_crop_image'] = '<a class="ilab-thickbox" href="' . $this->cropPageURL($post->ID) . '" title="Crop Image">' . __('Crop Image') . '</a>';
            return array_merge($actions, $newaction);
        }, 10, 2);
        add_filter('admin_post_thumbnail_html', function ($content, $id) {
            if (!has_post_thumbnail($id)) {
                return $content;
            }
            $image_id = get_post_thumbnail_id($id);
            if (!current_user_can('edit_post', $image_id)) {
                return $content;
            }
            $content .= '<a class="ilab-thickbox" href="' . $this->cropPageURL($image_id) . '">' . __('Crop Image') . '</a>';
            return $content;
        }, 10, 2);
        add_action('wp_enqueue_media', function () {
            remove_action('admin_footer', 'wp_print_media_templates');
            add_action('admin_footer', function () {
                ob_start();
                wp_print_media_templates();
                $result = ob_get_clean();
                echo $result;
                $sizes = ilab_get_image_sizes();
                $sizeKeys = array_keys($sizes);
                ?>
                <script>
                    jQuery(document).ready(function() {
                        jQuery('input[type="button"]')
                            .filter(function() {
                                return this.id.match(/imgedit-open-btn-[0-9]+/);
                            })
                            .each(function(){
                                var image_id=this.id.match(/imgedit-open-btn-([0-9]+)/)[1];
                                var button=jQuery('<input type="button" class="button" style="margin-left:5px;" value="Crop Image">');
                                jQuery(this).after(button);

                                button.on('click',function(e){
                                    e.preventDefault();

                                    ILabModal.loadURL("<?php 
                echo relative_admin_url('admin-ajax.php');
                ?>
?action=ilab_crop_image_page&size=<?php 
                echo $sizeKeys[0];
                ?>
&post="+image_id,false,null);

                                    return false;
                                });
                            });

                        attachTemplate=jQuery('#tmpl-image-details');
                        if (attachTemplate)
                            attachTemplate.text(attachTemplate.text().replace(/(<input type="button" class="replace-attachment button")/,'<a href="<?php 
                echo $this->cropPageURL('{{data.attachment.id}}');
                ?>
" class="ilab-thickbox button"><?php 
                echo __('Crop Image');
                ?>
</a>&nbsp;$1'));

                        attachTemplate=jQuery('#tmpl-attachment-details-two-column');
                        if (attachTemplate)
                        {
                            attachTemplate.text(attachTemplate.text().replace(/(<button(?:.*)class="(?:.*)edit-attachment(?:.*)"[^>]*[^<]+<\/button>)/,'$1&nbsp;<a href="<?php 
                echo $this->cropPageURL('{{data.id}}');
                ?>
" class="ilab-thickbox button"><?php 
                echo __('Crop Image');
                ?>
</a>'));
                            attachTemplate.text(attachTemplate.text().replace(/(<a(?:.*)class="(?:.*)edit-imgix(?:.*)"[^>]*[^<]+<\/a>)/,'$1&nbsp;<a href="<?php 
                echo $this->cropPageURL('{{data.id}}');
                ?>
" class="ilab-thickbox button"><?php 
                echo __('Crop Image');
                ?>
</a>'));
                            attachTemplate.text(attachTemplate.text().replace(/(<a class="(?:.*)edit-attachment(?:.*)"[^>]+[^<]+<\/a>)/,'$1&nbsp;<a href="<?php 
                echo $this->cropPageURL('{{data.id}}');
                ?>
" class="ilab-thickbox button"><?php 
                echo __('Crop Image');
                ?>
</a>'));
                            attachTemplate.text(attachTemplate.text().replace(/(<a class="(?:.*)view-attachment(?:.*)"[^>]+[^<]+<\/a>)/,'$1 | <a class="ilab-thickbox" href="<?php 
                echo $this->cropPageURL('{{data.id}}');
                ?>
"><?php 
                echo __('Crop Image');
                ?>
</a>'));
                        }

                        attachTemplate=jQuery('#tmpl-attachment-details');
                        if (attachTemplate)
                        {
                            attachTemplate.text(attachTemplate.text().replace(/(<a(?:.*)class="(?:.*)edit-imgix(?:.*)"[^>]*[^<]+<\/a>)/, '$1<br><a class="ilab-thickbox" href="<?php 
                echo $this->cropPageURL('{{data.id}}');
                ?>
"><?php 
                echo __('Crop Image');
                ?>
</a>'));
                            attachTemplate.text(attachTemplate.text().replace(/(<a class="(?:.*)edit-attachment(?:.*)"[^>]+[^<]+<\/a>)/, '$1\n<a class="ilab-thickbox" href="<?php 
                echo $this->cropPageURL('{{data.id}}');
                ?>
"><?php 
                echo __('Crop Image');
                ?>
</a>'));
                        }
                    });
                </script>
                <?php 
            }, 1000);
        });
    }