Plugin Directory

Changeset 172102


Ignore:
Timestamp:
11/10/2009 07:11:55 PM (16 years ago)
Author:
binnyva
Message:

New version - 1.05.0

Location:
article-templates/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • article-templates/trunk/manage.php

    r135264 r172102  
    11<?php
    22include('wpframe.php');
    3 stopDirectCall(__FILE__);
     3wpframe_stop_direct_call(__FILE__);
    44
    55if(isset($_POST['action'])) {
  • article-templates/trunk/readme.txt

    r135264 r172102  
    55Requires at least: 2.5
    66Tested up to: 2.8
    7 Stable tag: 1.04.1
     7Stable tag: 1.05.0
    88
    99Article Templates plugin lets you create templates that can be used when writing a new post or page.
     
    4545* This version also fixes the new line insertion bug that happens in code(non-visual) editor mode.
    4646
    47 = 1.04.1 =
     47= 1.05.0 =
    4848* WP 2.8 Compatibility
    4949* Made admin forms prettier
    5050* 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  
    11<?php
    22include('wpframe.php');
    3 stopDirectCall(__FILE__);
     3wpframe_stop_direct_call(__FILE__);
    44?>
    55<div class="wrap">
     
    2020    $name   = $template_data[0]->post_name;
    2121    $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);
    2325}
    2426
    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();
     27wpframe_add_editor_js();
    3328
    3429?>
     
    5651<h3 class="hndle"><span><?php e('Template Status') ?></span></h3>
    5752<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
     65if( 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 } ?>
    6071</div></div>
    6172
  • article-templates/trunk/templates.php

    r135264 r172102  
    44Plugin URI: http://www.bin-co.com/tools/wordpress/plugins/article_templates/
    55Description: 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.04.1
     6Version: 1.05.0
    77Author: Binny V A
    88Author URI: http://binnyva.com/
    99*/
    10 require_once('wpframe.php');
    1110
    1211/**
     
    2019    if($wp_version >= '2.7') $page = 'tools.php';
    2120   
    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;
    2424}
    2525
     
    3535?>
    3636<div id="article-template" class="postbox">
    37 <h3>Article Template</h3>
     37<h3><?php _e("Article Template", 'article-templates') ?></h3>
    3838<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>
    4242<br /><br />
    4343<select name="template" id="template">
    44     <option value="none">None</option>
     44    <option value="none"><?php _e("None", 'article-templates') ?></option>
    4545    <?php foreach($templates as $template) { ?>
    4646    <option value="<?=$template->post_name?>"><?=$template->post_title?></option>
     
    117117 */
    118118function 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
     127SQL;
     128
     129    return $wpdb->get_results($query);
    122130}
    123131
     
    126134 */
    127135function 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
     150SQL;
     151
     152        return $wpdb->get_var($query);
     153    }
     154
     155    return $user_selected;
     156}
     157
     158/// Register server side request handling function
     159add_action('save_post', 'article_templates_handle_update', 10, 2);
     160function 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    }
    131189}
    132190
  • article-templates/trunk/wpframe.php

    r135264 r172102  
    1111$GLOBALS['wpframe_plugin_folder'] = $GLOBALS['wpframe_siteurl'] . '/wp-content/plugins/' . $GLOBALS['wpframe_plugin_name'];
    1212//$GLOBALS['wpframe_plugin_data'] = get_plugin_data($GLOBALS['wpframe_plugin_name'] . '.php');
    13 //* :DEBUG: */ $GLOBALS['wpdb']->show_errors();
     13/* :DEBUG: */ $GLOBALS['wpdb']->show_errors();
    1414
    15 if(!function_exists('stopDirectCall')) { //Make sure multiple plugins can be created using WPFrame
     15if(!function_exists('wpframe_add_editor_js')) { //Make sure multiple plugins can be created using WPFrame
    1616
    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
     18function 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');
    2529}
    2630
    2731/// Make sure that the user don't call this file directly - forces the use of the WP interface
    28 function stopDirectCall($file) {
     32function wpframe_stop_direct_call($file) {
    2933    if(preg_match('#' . basename($file) . '#', $_SERVER['PHP_SELF'])) die('Don\'t call this page directly.'); // Stop direct call
    3034}
    3135
    3236/// Shows a message in the admin interface of Wordpress
    33 function showMessage($message, $type='updated') {
     37function wpframe_message($message, $type='updated') {
    3438    if($type == 'updated') $class = 'updated fade';
    3539    elseif($type == 'error') $class = 'updated error';
Note: See TracChangeset for help on using the changeset viewer.