/** * Security checks for image upload form * @since 0.1 */ function wppb_image_upload_form_check() { // Check nonce - security protection to prevent creation and deletion of files by untrusted users if (!empty($_POST) and check_admin_referer('wppb_upload_image', 'image')) { // Upload file $data = $_FILES['upload_file']; if ('' != $data['name']) { $ext = substr(strrchr($data['name'], '.'), 1); // Grab extension $ext = strtolower($ext); // Convert extension to lower case // Spit an error out when not an image - would be better to send admin notice instead if ($ext != 'jpeg' and $ext != 'jpg' and $ext != 'gif' and $ext != 'png') { die('Only jpg, gif or png files are allowed to be uploaded!'); // Kill execution so they get to see the error } // Save file to disk add_filter('upload_dir', 'wppb_image_uploads_folder'); $overrides = array('test_form' => false); $file = wp_handle_upload($data, $overrides); remove_filter('upload_dir', 'wppb_image_uploads_folder'); } // Delete file if (isset($_POST['delete_file'])) { unlink(wppb_storage_folder('images') . '/' . $_POST['delete_file']); } } }
/** * wppb_export_zip() * @description Zips the templates into a regular WordPress theme * @since 0.8.1 */ function wppb_export_zip() { // Theme specs. $name = get_bloginfo('name'); $folder = sanitize_title(get_bloginfo('name')); // Set current userinfo (allows us to grab the current author names later on) global $current_user; get_currentuserinfo(); // Headers for theme files function pixopoint_theme_header($title, $name) { return '<?php /** * @package WordPress * @subpackage ' . $name . ' * * ' . $title . ' */ ?>'; } // Removes pointless opening and closing of PHP tags function pixopoint_remove_openclose_php($input) { return str_replace('?><?php', '', $input); } // Creating data file $options = get_option(WPPB_SETTINGS); foreach ($options as $name2 => $key) { $data .= WPPB_BLOCK_SPLITTER; $data .= WPPB_NAME_SPLIT_START . $name2 . WPPB_NAME_SPLIT_END; $data .= $key; } $options = get_option(WPPB_DESIGNER_SETTINGS); $data .= WPPB_BLOCK_SPLITTER; $data .= WPPB_NAME_SPLIT_START; $data .= 'paintbrush_designer'; $data .= WPPB_NAME_SPLIT_END; foreach ($options as $name2 => $key) { $data .= $name2; $data .= '|'; $data .= $key; $data .= '}'; } // Create CSS $css = '/* Theme Name: ' . $name . ' Theme URI: ' . home_url() . ' Description: ' . get_bloginfo('description') . ' Author: ' . $current_user->user_firstname . ' ' . $current_user->user_lastname . ' (' . $current_user->display_name . ') Version: ' . (100 + get_wppb_option('version')) / 100 . ' */ ' . get_wppb_option('css'); // Creating array of require CSS classes $css_requirements = array('.alignleft', '.aligncenter', '.alignright', '.wp-caption', '.wp-caption-text', '.gallery-caption', '.sticky', '.bypostauthor'); // Creating reminder string foreach ($css_requirements as $needle) { if (strpos($css, $needle) === false) { $css_reminder .= $needle . ', '; } } // Finalizing CSS advice for style.css file if ($css_reminder) { $css = $css . "\n\n/* You have not included some useful CSS classes. We recommend you include the " . $css_reminder . " CSS classes in your theme */"; } // Setting background image URLs to correct folder $css = str_replace(wppb_storage_folder('images', 'url') . '/', 'images/', $css); // Load template files $files = array($folder . '/data.tpl' => $data, $folder . '/functions.php' => pixopoint_remove_openclose_php(pixopoint_theme_header('Functions', $name) . '<?php ' . wppb_functions_dot_php()), $folder . '/license.txt' => file_get_contents(get_template_directory() . '/license.txt'), $folder . '/style.css' => $css); // Function for adding extra templates to the zip file function wppb_add_template_to_zip($template, $title, $name, $files, $folder) { if ('' != get_wppb_option($template)) { $files[$folder . '/' . $template . '.php'] = pixopoint_theme_header($title, $name) . pixopoint_remove_openclose_php(do_shortcode(get_wppb_option($template))); } return $files; } // Plowing through and adding each of the optional template files $files = wppb_add_template_to_zip('footer', 'Footer', $name, $files, $folder); $files = wppb_add_template_to_zip('index', 'Index', $name, $files, $folder); $files = wppb_add_template_to_zip('front_page', 'Front Page', $name, $files, $folder); $files = wppb_add_template_to_zip('home', 'Blog', $name, $files, $folder); $files = wppb_add_template_to_zip('page', 'Page', $name, $files, $folder); $files = wppb_add_template_to_zip('page_template_1', 'Page template 1', $name, $files, $folder); $files = wppb_add_template_to_zip('page_template_2', 'Page template 2', $name, $files, $folder); $files = wppb_add_template_to_zip('single', 'Single', $name, $files, $folder); $files = wppb_add_template_to_zip('archive', 'Archive', $name, $files, $folder); $files = wppb_add_template_to_zip('comments', 'Comments', $name, $files, $folder); // Add embedded fonts /* foreach ( wppb_embeddable_fonts() as $font => $details ) { if ( 'on' == get_wppb_option( 'fontembed_' . $font ) ) { $font_dir = str_replace( 'wppb_INTERNAL_FONT_', get_template_directory() . '/fonts', $details['url'] ); // if ( $details['url'] != $font_dir ) $files[$folder . '/footer.php'] = $files[$folder . '/footer.php'] . file_get_contents( get_template_directory() . '/footer.php' ); } } die; */ // Adding actual header and footers in (header does not use wppb_add_template_to_zip() since it messes up the PHPDoc comment at top of template file $files[$folder . '/header.php'] = pixopoint_theme_header('header', $name) . file_get_contents(get_template_directory() . '/header.php') . pixopoint_remove_openclose_php(do_shortcode(get_wppb_option('header'))); $files[$folder . '/header.php'] = str_replace("<?php eval( '?>' . do_shortcode( get_wppb_option( 'header' ) ) . '<?php ' ); ?>", '', $files[$folder . '/header.php']); $files[$folder . '/footer.php'] = $files[$folder . '/footer.php'] . file_get_contents(get_template_directory() . '/footer.php'); $files[$folder . '/footer.php'] = str_replace("<?php eval( '?>' . do_shortcode( get_wppb_option( 'footer' ) ) . '<?php ' ); ?>", '', $files[$folder . '/footer.php']); // Load image files $file_list = wppb_settings_list_files(wppb_storage_folder('images') . '/'); // Grab list of files in folder foreach ($file_list as $file) { $files[$folder . '/images/' . $file] = file_get_contents(wppb_storage_folder('images') . '/' . $file); } // Load scripts files $files[$folder . '/scripts/html5.js'] = file_get_contents(get_template_directory() . '/scripts/html5.js'); // Dropdown menus if ('on' == get_wppb_option('script_menu')) { $files[$folder . '/scripts/menu.js'] = file_get_contents(get_template_directory() . '/scripts/menu.js'); } // Anything slider jQuery plugin if ('on' == get_wppb_option('script_anythingslider')) { $files[$folder . '/scripts/jquery.easing.1.2.js'] = file_get_contents(get_template_directory() . '/scripts/jquery.easing.1.2.js'); $files[$folder . '/scripts/jquery.anythingslider.js'] = file_get_contents(get_template_directory() . '/scripts/jquery.anythingslider.js'); $files[$folder . '/scripts/anythingslider.init.js'] = file_get_contents(get_template_directory() . '/scripts/anythingslider.init.js'); } // Create zip file $zip = new ZipArchive(); $rand = rand(); $zip->open('temp' . $rand . '.tmp', ZIPARCHIVE::CREATE); if ($files) { foreach ($files as $localname => $source) { if (is_file($source)) { $zip->addFile($source, $localname); } else { $zip->addFromString($localname, $source); } } } $zip->close(); // Downloading zip header('Content-type: application/zip'); // File header header('Content-Disposition: attachment; filename="' . $folder . '.zip"'); // File header readfile('temp' . $rand . '.tmp'); // Read temporary file from disk unlink('temp' . $rand . '.tmp'); // Delete temporary file die; // Kill execution since all done now }
function wppb_inline_scripts() { $wppb_design_settings = get_option(WPPB_DESIGNER_SETTINGS); // Setting potentially empty variable if (empty($wppb_design_settings['design'])) { $wppb_design_settings['design'] = ''; } else { $wppb_design_settings['design'] = sanitize_title($wppb_design_settings['design']); } // Bug fix for existing poorly labelled designs ?> <script type="text/javascript"> <?php do_action('wppb_inline_scripts_hook'); ?> // Setting WP Paintbrush JS variables var storage_folder = '<?php echo wppb_storage_folder('images', 'url'); ?> '; var design_folder = '<?php echo get_template_directory_uri(); ?> /designs/<?php echo $wppb_design_settings['design']; ?> /images/'; var design_name = '<?php echo $wppb_design_settings['design']; ?> '; var nonce_link = '<?php echo wp_nonce_url(home_url(), 'wppb_editor'); ?> '; var admin_url = '<?php echo home_url(); ?> /wp-admin/'; var home_url = '<?php echo home_url(); ?> '; jQuery(function($){ // AJAX form submission function change_design(button) { $.ajax({ type: 'POST', url: home_url+'/?change_theme='+button, data: { 'wppb_nonce' : $("#wppb_nonce").val(), }, success: function(data, textStatus) { $( "#wppb-page-reload" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,}); $(location).attr('href',home_url); }, error: function(jqXHR, textStatus, errorThrown) { $( "#wppb-external-connection-failure" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,}); }, dataType: 'html' }); }<?php // Output list of available designs foreach (wppb_available_themes() as $count => $design) { echo "\$('#myform" . $design['Folder'] . "').click(function() {change_design( '" . $design['Folder'] . "' );});\n"; } ?> // AJAX form submission function option_get(button) { $("#wppb-css2").html('<div style="text-indent:0;"><img style="" src="'+admin_url+'images/wpspin_light.gif" /></div>'); $.ajax({ type: 'POST', url: home_url+'/?generator-css='+button, data: { 'wppb_nonce':$("#wppb_nonce").val(),<?php // Set all AJAX options foreach (wppb_ajax_option_get() as $option) { echo '\'' . $option . '\':$("#' . $option . '").val(),' . "\n"; } ?> }, success: function(data, textStatus) { switch(data) { case "Error: Couldn't connect to server": $( "#wppb-external-connection-failure" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,}); $('#wppb-css3').html("Error: Couldn't connect to server"); break; default: $('#wppb-css').html(data); $('#wppb-css3').html(data); break; } $('#wppb-css2').html(''); }, error: function(jqXHR, textStatus, errorThrown) { $( "#wppb-external-connection-failure" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,}); }, dataType: 'html' }); } $('#myformButton').click(function() {option_get( 'process' );}); $('.myformSaver').click(function() {option_get( 'save' );}); $('#myformPublish').click(function() {option_get( 'publish' );}); $('#myformExport').click(function() {option_get( 'export' );}); $('#ChangeHomeLayoutMagazine').click(function() {option_get( 'Magazine' );}); $('#ChangeHomeLayoutNormal').click(function() {option_get( 'Normal' );}); $("#sidebar-layout-sortable, #sidebar-blocks-sortable").sortable({ connectWith: ".sidebar-sortable-connect", update: function(){ var pos = []; $('#sidebar-layout-sortable > li').each(function(i){ pos[i] = $(this).attr('id'); }); $('#sidebar_positions').val(pos.toString()); option_get( 'process' ); } }); // Image picker var $button, $ele = $('#wppb-image-uploads').dialog({ width: 530, minWidth: 530, maxWidth: 530, title: 'Image picker', modal: false, autoOpen: false, open : function(event, ui){ $('img.uploaded-image',ui.dialog).each(function(){ var image = $(this); image.click(function(){ $button.parent().find('.image-picker').val(image.attr('alt')); $button.removeClass('ICopen').val('pick'); <?php $images = array('sidebar_background_image' => '.wrapper', 'footer_background_image' => 'footer div.footer', 'background_image' => 'body', 'maincontent_background_image' => '.wrapper #content', 'header_background_image' => 'header div.header', 'header_fullwidth_background_image' => 'header', 'header_searchbox_background_image' => 'header #search', 'header_logo_background_image' => 'header #logo', 'banner_image' => '#banner div.banner-image', 'menu1_hover_background_image' => 'nav#nav li:hover a', 'menu1_background_image' => 'nav#nav ul', 'menu1_fullwidth_background_image' => 'nav#nav', 'menu1_items_background_image' => 'nav#nav li', 'header_searchbox_text_background_image' => 'header #search input[type=text]', 'header_searchsubmit_text_background_image' => 'header #search input[type=submit]', 'footer_fullwidth_background_image' => 'footer'); foreach ($images as $theid => $selector) { echo "\n\t\t\t\t\tvar filename=\$('#" . $theid, "').val().split('/');\n\t\t\t\t\tif('stored'==filename[0]){\n\t\t\t\t\t\t\$('" . $selector . "').css({'background-image':'url('+storage_folder+'/'+filename[1]+')'});\n\t\t\t\t\t}\n\t\t\t\t\tif(design_name==filename[0]){\n\t\t\t\t\t\t\$('" . $selector . "').css({'background-image':'url('+design_folder+'/'+filename[1]+')'});\n\t\t\t\t\t}"; } ?> $ele.dialog('close'); }); }); }, beforeClose: function(event,ui){ $('img',ui.dialog).unbind(); } }); $('.imagepickerbutton').click(function(){$button = $(this);$ele.dialog('open');}); }); </script><?php }
/** * Display list of uploaded images * @since 0.1 */ function wppb_display_images() { $file_list = wppb_list_files(wppb_storage_folder('images')); if (is_array($file_list)) { foreach ($file_list as $file) { echo '<li> <a href="' . wppb_storage_folder('images', 'url') . '/' . $file . '">' . $file . '</a> <input class="delete_file" type="submit" name="delete_file" value="' . $file . '" /> <br /> <a href="' . wppb_storage_folder('images', 'url') . '/' . $file . '"> <img src="' . wppb_storage_folder('images', 'url') . '/' . $file . '" class="uploaded-image" alt="" /> </a> </li>'; } } }
function wppb_editor_content() { // Bail out now if user not supposed to see admin panel if (!current_user_can('manage_options') || 'on' != get_option('wppb_designer_pane')) { return; } // Setting defaults for "content_layout" $wppb_designer_settings = get_option(WPPB_DESIGNER_SETTINGS); ?> <div id="dialog" title="Theme Creator"> <div id="loading-text"> <img style="" src="<?php echo WPPB_URL; ?> images/load.gif" alt="<?php _e('Loading', 'wppb_lang'); ?> " /> <br /> <h3><?php _e('One moment please. The WP Paintbrush editor is loading.', 'wppb_lang'); ?> </h3> </div> <div id="tab_wrapper"> <form id="wppb-editor-form" method="post" action="" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="3000000" /> <input type="hidden" id="copyright" name="copyright" value='<?php echo $wppb_designer_settings['copyright']; ?> ' /> <input type="hidden" id="design" name="design" value='<?php echo $wppb_designer_settings['design']; ?> ' /> <?php wp_nonce_field('wppb_upload_image', 'image'); ?> <?php wp_nonce_field('wppb_nonce', 'wppb_nonce'); ?> <div id="tabs" class="maintabber"> <div id="tabs-navigation-wrapper"> <ul> <?php // Hook for adding new link do_action('wppb_add_editor_links'); ?> </ul> </div> <?php // Hook for adding new tabs do_action('wppb_add_editor_tabs'); ?> </div> <!-- Farbtastic colour picker --> <div id="farbtastic" title="Colour picker"><?php _e('Colour picker', 'wppb_lang'); ?> </div> <!-- Image picker --> <div id="wppb-image-uploads"> <div id="wppb-images"> <table> <?php wppb_list_images(wppb_storage_folder('images'), wppb_storage_folder('images', 'url'), 'display', 'stored'); echo '<tr><td><h2 style="margin:20px 0 6px 0;">' . __(' Design images', 'wppb_lang') . '</h2></td></tr>'; foreach (wppb_available_themes() as $count => $theme) { if ($theme['Folder'] == $wppb_designer_settings['design']) { if ('Internal' == $theme['Type']) { wppb_list_images(get_template_directory() . '/designs/' . $theme['Folder'] . '/images/', get_template_directory_uri() . '/designs/' . $theme['Folder'] . '/images/', '', $theme['Folder']); } } } ?> </table> </div> <h2><?php _e('Image uploads', 'wppb_lang'); ?> </h2> <!-- --><?php // If using WP 3.3 then make use of plup uploader (note use of query var to force major CSS changes in iframe) global $wp_version; if ($wp_version >= 3.3) { echo '<iframe src="' . admin_url() . '/media-new.php?wppb_frontenduploader=css" width="525" height="215"></iframe>'; } else { echo '<p>' . __('Visit the <a href="http://localhost/wp/testing/wp-admin/themes.php?page=upload_images">image uploads page</a> to upload new images.', 'wppb_lang') . '</p>'; } ?> </div> </form> <!-- Connection failure dialog --> <div id="wppb-external-connection-failure" title="<?php _e('Dangit, we got an error!', 'wppb_lang'); ?> "> <p><?php _e('Sorry, the server is having difficulties connecting to the CSS generator. Please try again.', 'wppb_lang'); ?> </p> </div> <div id="wppb-page-reload" title="Page reloading!"> <p><?php _e('We need to reload the page to show the changes you just selected. One moment please ...', 'wppb_lang'); ?> </p> </div> </div> </div> <?php }
if (!defined('WPPB_SETTINGS')) { define('WPPB_SETTINGS', 'wppb_settings'); } // Label for option used to store template code in database if (!defined('WPPB_DESIGNER_SETTINGS')) { define('WPPB_DESIGNER_SETTINGS', 'wppb_designer_settings'); } // Label for option used to store designer settings in database define('PIXOPOINT_SETTINGS_COPYRIGHT', 'Theme by <a href="http://wppaintbrush.com/">WPPaintbrush.com</a>'); // Copyright constant define('WPPB_ADMIN_URL', get_template_directory_uri() . '/admin'); // Admin directory URL define('WPPB_TEMPLATES_LABEL', 'Themes'); // Decides what label to give the templates page (for theme selection page - in development as an addon plugin) define('WPPB_STORAGE_FOLDER', 'wppb_storage'); define('WPPB_STORAGE_IMAGES_FOLDER', wppb_storage_folder('images', 'url')); define('WPPB_BLOCK_SPLITTER', "/* PixoPoint Template option */\n"); // Strings used to descriminate between differents bits in exported/imported files define('WPPB_NAME_SPLIT_START', '[----'); // Strings used to descriminate between differents bits in exported/imported files define('WPPB_NAME_SPLIT_END', "----]\n"); // Strings used to descriminate between differents bits in exported/imported files /** * Set widget suffixes * Currently uses numbers, but could easily incorporate text instead * @since 0.1 */ function wppb_settings_widgets_array() { return array(1, 2, 3, 4, 5, 6); }