Changeset 172102
- Timestamp:
- 11/10/2009 07:11:55 PM (16 years ago)
- Location:
- article-templates/trunk
- Files:
-
- 5 edited
-
manage.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
template_form.php (modified) (3 diffs)
-
templates.php (modified) (5 diffs)
-
wpframe.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
article-templates/trunk/manage.php
r135264 r172102 1 1 <?php 2 2 include('wpframe.php'); 3 stopDirectCall(__FILE__);3 wpframe_stop_direct_call(__FILE__); 4 4 5 5 if(isset($_POST['action'])) { -
article-templates/trunk/readme.txt
r135264 r172102 5 5 Requires at least: 2.5 6 6 Tested up to: 2.8 7 Stable tag: 1.0 4.17 Stable tag: 1.05.0 8 8 9 9 Article Templates plugin lets you create templates that can be used when writing a new post or page. … … 45 45 * This version also fixes the new line insertion bug that happens in code(non-visual) editor mode. 46 46 47 = 1.0 4.1=47 = 1.05.0 = 48 48 * WP 2.8 Compatibility 49 49 * Made admin forms prettier 50 50 * Now uses wpframe 51 52 = 1.05.0 = 53 * Changed by Philipp Bartels ([email protected]) 54 * Added feature to make a template available to all users (users at or above editor role may do this) 55 * Added feature to set a default template for all users, without overwriting a user selected default template (administrators may do this) 56 * Fixed the editor bug that happens in WP 2.8.5 -
article-templates/trunk/template_form.php
r135264 r172102 1 1 <?php 2 2 include('wpframe.php'); 3 stopDirectCall(__FILE__);3 wpframe_stop_direct_call(__FILE__); 4 4 ?> 5 5 <div class="wrap"> … … 20 20 $name = $template_data[0]->post_name; 21 21 $content= $template_data[0]->post_content; 22 $default_template= $template_data[0]->menu_order; 22 $default_template = $template_data[0]->menu_order; 23 $available_for_all = get_post_meta($template_id, 'available_for_all', true); 24 $default_for_all = get_post_meta($template_id, 'default_for_all', true); 23 25 } 24 26 25 wp_admin_css('thickbox'); 26 wp_print_scripts('jquery-ui-core'); 27 wp_print_scripts('jquery-ui-tabs'); 28 wp_print_scripts('post'); 29 wp_print_scripts('editor'); 30 if (function_exists('add_thickbox')) add_thickbox(); 31 wp_print_scripts('media-upload'); 32 if (function_exists('wp_tiny_mce')) wp_tiny_mce(); 27 wpframe_add_editor_js(); 33 28 34 29 ?> … … 56 51 <h3 class="hndle"><span><?php e('Template Status') ?></span></h3> 57 52 <div class="inside"> 58 <label for="menu_order"><?php e('Default Template'); ?></label> 59 <input type="checkbox" name="menu_order" value="1" <?=($default_template)?"checked='checked'":''?> /> 53 <div> 54 <label for="menu_order"><?php e('Default Template'); ?></label> 55 <input type="checkbox" id="menu_order" name="menu_order" value="1" <?=($default_template)?"checked='checked'":''?> /> 56 </div> 57 <?php // allow just users editors to add templates available to all users ?> 58 <?php if( 5 <= $user_level ) { ?> 59 <div> 60 <label for="available_for_all"><?php e('Available to all users'); ?></label> 61 <input type="checkbox" id="available_for_all" name="available_for_all" value="1" <?=($available_for_all)?"checked='checked'":''?> /> 62 </div> 63 <?php } 64 // allow just administrators to set as default template for all users 65 if( 8 <= $user_level ) { ?> 66 <div> 67 <label for="default_for_all"><?php e('Default for all users'); ?></label> 68 <input type="checkbox" id="default_for_all" name="default_for_all" value="1" <?=($default_for_all)?"checked='checked'":''?> /> 69 </div> 70 <?php } ?> 60 71 </div></div> 61 72 -
article-templates/trunk/templates.php
r135264 r172102 4 4 Plugin URI: http://www.bin-co.com/tools/wordpress/plugins/article_templates/ 5 5 Description: Enables template support for posts and pages. You can see all existing templates in the <a href="edit.php?page=article-templates/manage.php">Manage Templates</a> page. 6 Version: 1.0 4.16 Version: 1.05.0 7 7 Author: Binny V A 8 8 Author URI: http://binnyva.com/ 9 9 */ 10 require_once('wpframe.php');11 10 12 11 /** … … 20 19 if($wp_version >= '2.7') $page = 'tools.php'; 21 20 22 add_submenu_page($page, t('Manage Templates'), t('Manage Templates'), $view_level, 'article-templates/manage.php' ); 23 wpf_register_page('article-templates/template_form.php'); 21 add_submenu_page($page, __('Manage Templates', 'article-templates'), __('Manage Templates', 'article-templates'), $view_level, 'article-templates/manage.php' ); 22 $hookname = get_plugin_page_hookname('article-templates/template_form.php', '' ); 23 $GLOBALS['_registered_pages'][$hookname] = true; 24 24 } 25 25 … … 35 35 ?> 36 36 <div id="article-template" class="postbox"> 37 <h3> Article Template</h3>37 <h3><?php _e("Article Template", 'article-templates') ?></h3> 38 38 <div class="inside"> 39 <p> Article template allows you to create templates that can be used when writing a new post or page. Templates are very useful if you create several posts with the same structure. You can create a new template under the <a title="Manage Templates" href="edit.php?page=article-templates/manage.php">Manage Templates</a> section.</p>40 41 <label for="template" style="font-size: 11px; font-weight: bold;"> Template:</label>39 <p><?php _e('Article template allows you to create templates that can be used when writing a new post or page. Templates are very useful if you create several posts with the same structure. You can create a new template under the <a title="Manage Templates" href="edit.php?page=article-templates/manage.php">Manage Templates</a> section.', 'article-templates') ?></p> 40 41 <label for="template" style="font-size: 11px; font-weight: bold;"><?php _e("Template: ", 'article-templates') ?></label> 42 42 <br /><br /> 43 43 <select name="template" id="template"> 44 <option value="none"> None</option>44 <option value="none"><?php _e("None", 'article-templates') ?></option> 45 45 <?php foreach($templates as $template) { ?> 46 46 <option value="<?=$template->post_name?>"><?=$template->post_title?></option> … … 117 117 */ 118 118 function templates_get_users_templates($user_id) { 119 global $wpdb; 120 return $wpdb->get_results("SELECT ID,post_title,post_name,post_date,post_type,post_content,post_author " 121 . " FROM {$wpdb->posts} WHERE post_type='template' AND post_author='$user_id' ORDER BY post_date DESC"); 119 global $wpdb; 120 121 $query = <<<SQL 122 SELECT DISTINCT ID, post_title, post_name, post_date, post_type, post_content, post_author 123 FROM {$wpdb->posts} 124 JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id 125 WHERE post_type='template' AND (post_author='$user_id' OR meta_key='available_for_all') 126 ORDER BY post_date DESC 127 SQL; 128 129 return $wpdb->get_results($query); 122 130 } 123 131 … … 126 134 */ 127 135 function templates_get_default_template_for_user($user_id) { 128 global $wpdb; 129 return $wpdb->get_var("SELECT post_name FROM {$wpdb->posts} " 130 . " WHERE post_type='template' AND post_author='$user_id' AND menu_order='1' LIMIT 1"); 136 global $wpdb; 137 138 $user_selected = 139 $wpdb->get_var("SELECT post_name FROM {$wpdb->posts} " . 140 " WHERE post_type='template' AND post_author='$user_id' AND menu_order='1' LIMIT 1"); 141 142 if( ! $user_selected ) 143 { 144 $query = <<<SQL 145 SELECT DISTINCT post_name 146 FROM {$wpdb->posts} 147 JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id 148 WHERE post_type='template' AND meta_key='default_for_all' AND meta_value = 1 149 ORDER BY post_date DESC 150 SQL; 151 152 return $wpdb->get_var($query); 153 } 154 155 return $user_selected; 156 } 157 158 /// Register server side request handling function 159 add_action('save_post', 'article_templates_handle_update', 10, 2); 160 function article_templates_handle_update( $post_id, $post ) 161 { 162 if( ! empty($_REQUEST['available_for_all']) ) 163 { 164 add_post_meta($post_id, 'available_for_all', intval($_REQUEST['available_for_all']), true) 165 or update_post_meta($post_id, 'available_for_all', intval($_REQUEST['available_for_all'])); 166 } 167 else 168 { 169 delete_post_meta($post_id, 'available_for_all'); 170 } 171 172 if( ! empty($_REQUEST['default_for_all']) ) 173 { 174 // avoid multiple default_for_all templates 175 global $wpdb; 176 $wpdb->get_results("DELETE FROM {$wpdb->postmeta} WHERE meta_key = \"default_for_all\""); 177 178 add_post_meta($post_id, 'default_for_all', intval($_REQUEST['default_for_all']), true) 179 or update_post_meta($post_id, 'default_for_all', intval($_REQUEST['default_for_all'])); 180 181 // default_for_all implies available_for_all 182 add_post_meta($post_id, 'available_for_all', 1, true) 183 or update_post_meta($post_id, 'available_for_all', 1, true); 184 } 185 else 186 { 187 delete_post_meta($post_id, 'default_for_all'); 188 } 131 189 } 132 190 -
article-templates/trunk/wpframe.php
r135264 r172102 11 11 $GLOBALS['wpframe_plugin_folder'] = $GLOBALS['wpframe_siteurl'] . '/wp-content/plugins/' . $GLOBALS['wpframe_plugin_name']; 12 12 //$GLOBALS['wpframe_plugin_data'] = get_plugin_data($GLOBALS['wpframe_plugin_name'] . '.php'); 13 / /* :DEBUG: */ $GLOBALS['wpdb']->show_errors();13 /* :DEBUG: */ $GLOBALS['wpdb']->show_errors(); 14 14 15 if(!function_exists(' stopDirectCall')) { //Make sure multiple plugins can be created using WPFrame15 if(!function_exists('wpframe_add_editor_js')) { //Make sure multiple plugins can be created using WPFrame 16 16 17 /// Need to register a page to use it in a plugin in WP2.8.1+. THIS IS A HACK. 18 function wpf_register_pages($pages, $folder) { 19 foreach($pages as $p) wpf_register_page($folder . DIRECTORY_SEPARATOR . $p); 20 } 21 function wpf_register_page($file) { 22 global $_registered_pages; 23 $hookname = get_plugin_page_hookname($file, '' ); 24 $_registered_pages[$hookname] = true; 17 /// Adds the JS code needed for the editor. Changes often. So made it centralized 18 function wpframe_add_editor_js() { 19 wp_enqueue_script( 'common' ); 20 wp_enqueue_script( 'jquery-color' ); 21 wp_print_scripts('editor'); 22 if (function_exists('add_thickbox')) add_thickbox(); 23 wp_print_scripts('media-upload'); 24 if (function_exists('wp_tiny_mce')) wp_tiny_mce(); 25 wp_admin_css(); 26 wp_enqueue_script('utils'); 27 do_action("admin_print_styles-post-php"); 28 do_action('admin_print_styles'); 25 29 } 26 30 27 31 /// Make sure that the user don't call this file directly - forces the use of the WP interface 28 function stopDirectCall($file) {32 function wpframe_stop_direct_call($file) { 29 33 if(preg_match('#' . basename($file) . '#', $_SERVER['PHP_SELF'])) die('Don\'t call this page directly.'); // Stop direct call 30 34 } 31 35 32 36 /// Shows a message in the admin interface of Wordpress 33 function showMessage($message, $type='updated') {37 function wpframe_message($message, $type='updated') { 34 38 if($type == 'updated') $class = 'updated fade'; 35 39 elseif($type == 'error') $class = 'updated error';
Note: See TracChangeset
for help on using the changeset viewer.