Ejemplo n.º 1
0
function layotter_make_search_dump($data, $raw_post)
{
    $post_id = $raw_post['ID'];
    // don't change anything if not editing a Layotter-enabled post
    if (!Layotter::is_enabled_for_post($post_id) or !isset($raw_post['layotter_json'])) {
        return $data;
    }
    // copy JSON from POST and strip slashes that were added by Wordpress
    $json = $raw_post['layotter_json'];
    $unslashed_json = stripslashes_deep($json);
    // turn JSON into post content HTML
    $layotter_post = new Layotter_Post($unslashed_json);
    $content = $layotter_post->get_frontend_view();
    // save JSON to a custom field (oddly enough, Wordpress breaks JSON if it's stripslashed)
    update_post_meta($post_id, 'layotter_json', $json);
    // insert spaces to prevent <p>foo</p><p>bar</p> becoming "foobar" instead of "foo bar"
    // then strip all tags except <img>
    // then remove excess whitespace
    $spaced_content = str_replace('<', ' <', $content);
    $clean_content = strip_tags($spaced_content, '<img>');
    $normalized_content = trim($clean_content);
    if (function_exists('mb_ereg_replace')) {
        $normalized_content = mb_ereg_replace('/\\s+/', ' ', $normalized_content);
    }
    // wrap search dump with a [layotter] shortcode and return modified post data to be saved to the database
    // add the post ID because otherwise the shortcode handler would have no reliable way to get the post ID through
    // which the JSON data will be fetched
    $shortcoded_content = '[layotter post="' . $post_id . '"]' . $normalized_content . '[/layotter]';
    $data['post_content'] = $shortcoded_content;
    return $data;
}
Ejemplo n.º 2
0
/**
 * Process post content
 *
 * @param array $atts Shortcode attributes
 * @param string $input Data wrapped by the [layotter] shortcode
 * @return string HTML for frontend view of the current post
 */
function layotter_frontend_shortcode($atts, $input = '')
{
    // since 1.5.0, shortcode attributes carry a post ID, and JSON is stored in a custom field
    // before 1.5.0, JSON was stored directly in the post content
    // get_the_ID() wouldn't be reliable here because this shortcode handler might be triggered in a context where the
    // $post variable hasn't been correctly initialized, like do_shortcode() or apply_filters('the_content')
    if (isset($atts['post']) and Layotter::is_enabled_for_post($atts['post'])) {
        $post_id = intval($atts['post']);
        $layotter = new Layotter_Post($post_id);
    } else {
        $layotter = new Layotter_Post($input);
    }
    $html = $layotter->get_frontend_view();
    // apply wptexturize manually after post HTML has been parsed because automatic wptexturizing is disabled for
    // Layotter content (see layotter_disable_wptexturize() below)
    return wptexturize($html);
}
Ejemplo n.º 3
0
function layotter_assets_admin_enqueue_scripts()
{
    // load assets only if necessary
    if (!Layotter::is_enabled()) {
        return;
    }
    // styles
    wp_enqueue_style('layotter', plugins_url('assets/css/editor.css', __DIR__));
    wp_enqueue_style('layotter-font-awesome', plugins_url('assets/css/font-awesome.min.css', __DIR__));
    // jQuery plugin used to serialize form data
    wp_enqueue_script('layotter-serialize', plugins_url('assets/js/vendor/jquery.serialize-object.compiled.js', __DIR__), array('jquery'));
    // Angular scripts
    $scripts = array('angular' => 'assets/js/vendor/angular.js', 'angular-animate' => 'assets/js/vendor/angular-animate.js', 'angular-sanitize' => 'assets/js/vendor/angular-sanitize.js', 'angular-ui-sortable' => 'assets/js/vendor/angular-ui-sortable.js', 'layotter' => 'assets/js/app/app.js', 'layotter-controller-editor' => 'assets/js/app/controllers/editor.js', 'layotter-controller-templates' => 'assets/js/app/controllers/templates.js', 'layotter-controller-form' => 'assets/js/app/controllers/form.js', 'layotter-service-state' => 'assets/js/app/services/state.js', 'layotter-service-data' => 'assets/js/app/services/data.js', 'layotter-service-content' => 'assets/js/app/services/content.js', 'layotter-service-templates' => 'assets/js/app/services/templates.js', 'layotter-service-layouts' => 'assets/js/app/services/layouts.js', 'layotter-service-view' => 'assets/js/app/services/view.js', 'layotter-service-forms' => 'assets/js/app/services/forms.js', 'layotter-service-modals' => 'assets/js/app/services/modals.js', 'layotter-service-history' => 'assets/js/app/services/history.js');
    foreach ($scripts as $name => $path) {
        wp_enqueue_script($name, plugins_url($path, __DIR__));
    }
    // fetch allowed row layouts and default layout
    $allowed_row_layouts = Layotter_Settings::get_allowed_row_layouts();
    $default_row_layout = Layotter_Settings::get_default_row_layout();
    // fetch default values for post, row and element options
    $default_post_options = new Layotter_Options('post');
    $default_row_options = new Layotter_Options('row');
    $default_col_options = new Layotter_Options('col');
    $default_element_options = new Layotter_Options('element');
    // fetch content structure for the current post
    $post_id = get_the_ID();
    $content_structure = new Layotter_Post($post_id);
    // fetch post layouts and element templates
    $saved_layouts = Layotter_Layouts::get_all();
    $saved_templates = Layotter_Templates::get_all_for_post($post_id);
    // fetch available element types
    $element_objects = Layotter::get_filtered_element_types($post_id);
    $element_types = array();
    foreach ($element_objects as $element_object) {
        $element_types[] = array('type' => $element_object->get('type'), 'title' => $element_object->get('title'), 'description' => $element_object->get('description'), 'icon' => $element_object->get('icon'));
    }
    // fetch general settings
    $enable_post_layouts = Layotter_Settings::post_layouts_enabled();
    $enable_element_templates = Layotter_Settings::element_templates_enabled();
    // inject data for use with Javascript
    wp_localize_script('layotter', 'layotterData', array('postID' => $post_id, 'isACFPro' => Layotter_ACF::is_pro_installed(), 'contentStructure' => $content_structure->to_array(), 'allowedRowLayouts' => $allowed_row_layouts, 'defaultRowLayout' => $default_row_layout, 'savedLayouts' => $saved_layouts, 'savedTemplates' => $saved_templates, 'enablePostLayouts' => $enable_post_layouts, 'enableElementTemplates' => $enable_element_templates, 'elementTypes' => $element_types, 'options' => array('post' => array('enabled' => $default_post_options->is_enabled(), 'defaults' => $default_post_options->get_clean_values()), 'row' => array('enabled' => $default_row_options->is_enabled(), 'defaults' => $default_row_options->get_clean_values()), 'col' => array('enabled' => $default_col_options->is_enabled(), 'defaults' => $default_col_options->get_clean_values()), 'element' => array('enabled' => $default_element_options->is_enabled(), 'defaults' => $default_element_options->get_clean_values())), 'i18n' => array('delete_row' => __('Delete row', 'layotter'), 'delete_element' => __('Delete element', 'layotter'), 'delete_template' => __('Delete template', 'layotter'), 'edit_template' => __('Edit template', 'layotter'), 'cancel' => __('Cancel', 'layotter'), 'discard_changes' => __('Discard changes', 'layotter'), 'discard_changes_confirmation' => __('Do you want to cancel and discard all changes?', 'layotter'), 'delete_row_confirmation' => __('Do you want to delete this row and all its elements?', 'layotter'), 'delete_element_confirmation' => __('Do you want to delete this element?', 'layotter'), 'delete_template_confirmation' => __('Do you want to delete this template? You can not undo this action.', 'layotter'), 'edit_template_confirmation' => __('When editing a template, your changes will be reflected on all pages that are using it. Do you want to edit this template?', 'layotter'), 'save_new_layout_confirmation' => __('Please enter a name for your layout:', 'layotter'), 'save_layout' => __('Save layout', 'layotter'), 'rename_layout_confirmation' => __('Please enter the new name for this layout:', 'layotter'), 'rename_layout' => __('Rename layout', 'layotter'), 'delete_layout_confirmation' => __('Do want to delete this layout? You can not undo this action.', 'layotter'), 'delete_layout' => __('Delete layout', 'layotter'), 'load_layout_confirmation' => __('Do want to load this layout and overwrite the existing content?', 'layotter'), 'load_layout' => __('Load layout', 'layotter'), 'history' => array('undo' => __('Undo:', 'layotter'), 'redo' => __('Redo:', 'layotter'), 'add_element' => __('Add element', 'layotter'), 'edit_element' => __('Edit element', 'layotter'), 'duplicate_element' => __('Duplicate element', 'layotter'), 'delete_element' => __('Delete element', 'layotter'), 'move_element' => __('Move element', 'layotter'), 'save_element_as_template' => __('Save element as template', 'layotter'), 'create_element_from_template' => __('Create element from template', 'layotter'), 'add_row' => __('Add row', 'layotter'), 'change_row_layout' => __('Change row layout', 'layotter'), 'duplicate_row' => __('Duplicate row', 'layotter'), 'delete_row' => __('Delete row', 'layotter'), 'move_row' => __('Move row', 'layotter'), 'edit_post_options' => __('Edit post options', 'layotter'), 'edit_row_options' => __('Edit row options', 'layotter'), 'edit_column_options' => __('Edit column options', 'layotter'), 'edit_element_options' => __('Edit element options', 'layotter'), 'load_post_layout' => __('Load layout', 'layotter')))));
}