Plugin Directory

Changeset 2375582


Ignore:
Timestamp:
09/05/2020 03:03:07 AM (5 years ago)
Author:
shorthandconnect
Message:
  • Better sanitize input
File:
1 edited

Legend:

Unmodified
Added
Removed
  • shorthand-connect/trunk/shorthand_connect.php

    r2336571 r2375582  
    11<?php
     2
    23/**
    34 * @package Shorthand Connect
    4  * @version 1.3.2
     5 * @version 1.3.3
    56 */
    67/*
     
    910Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic!
    1011Author: Shorthand
    11 Version: 1.3.2
     12Version: 1.3.3
    1213Author URI: http://shorthand.com
    1314*/
     
    2728
    2829/* Create the Shorthand post type */
    29 function shand_create_post_type() {
    30   $permalink = get_option('sh_permalink');
    31   if ($permalink == '') {
    32     $permalink = 'shorthand_story';
    33   }
    34   register_post_type( 'shorthand_story',
    35     array(
    36       'labels' => array(
    37         'name' => __( 'Shorthand' ),
    38         'singular_name' => __( 'Shorthand Story' ),
    39         'add_new' => __( 'Add Shorthand Story' ),
    40         'add_new_item' => __( 'Add Shorthand Story' ),
    41         'new_item' => __( 'Add Shorthand Story' ),
    42         'edit_item' => __( 'Update Shorthand Story' ),
    43         'view_item' => __( 'View Shorthand Story' ),
    44         'not_found' => __( 'No stories found' ),
    45         'not_found_in_trash' => __( 'No stories found in trash' )
    46       ),
    47       'publicly_queryable' => true,
    48       'public' => true,
    49       'has_archive' => true,
    50       'menu_position' => 4,
    51       'supports' => array('title', 'thumbnail', 'author', 'custom-fields'),
    52       'register_meta_box_cb' => 'shand_add_shorthand_metaboxes',
    53       'menu_icon' => plugins_url( '/includes/icon.png', __FILE__ ),
    54       'rewrite' => array('slug' => $permalink, 'with_front' => true),
    55       'taxonomies' => array('category', 'post_tag'),
    56     )
    57   );
    58 
    59   register_taxonomy_for_object_type( 'category', 'shorthand_story' );
    60   register_taxonomy_for_object_type( 'post_tag', 'shorthand_story' );
    61 }
    62 add_action( 'init', 'shand_create_post_type' );
    63 
    64 
    65 function shand_wpt_shorthand_story() {
     30function shand_create_post_type()
     31{
     32    $permalink = get_option('sh_permalink');
     33    if ($permalink == '') {
     34        $permalink = 'shorthand_story';
     35    }
     36    register_post_type(
     37        'shorthand_story',
     38        array(
     39            'labels' => array(
     40                'name' => __('Shorthand'),
     41                'singular_name' => __('Shorthand Story'),
     42                'add_new' => __('Add Shorthand Story'),
     43                'add_new_item' => __('Add Shorthand Story'),
     44                'new_item' => __('Add Shorthand Story'),
     45                'edit_item' => __('Update Shorthand Story'),
     46                'view_item' => __('View Shorthand Story'),
     47                'not_found' => __('No stories found'),
     48                'not_found_in_trash' => __('No stories found in trash')
     49            ),
     50            'publicly_queryable' => true,
     51            'public' => true,
     52            'has_archive' => true,
     53            'menu_position' => 4,
     54            'supports' => array('title', 'thumbnail', 'author', 'custom-fields'),
     55            'register_meta_box_cb' => 'shand_add_shorthand_metaboxes',
     56            'menu_icon' => plugins_url('/includes/icon.png', __FILE__),
     57            'rewrite' => array('slug' => $permalink, 'with_front' => true),
     58            'taxonomies' => array('category', 'post_tag'),
     59        )
     60    );
     61
     62    register_taxonomy_for_object_type('category', 'shorthand_story');
     63    register_taxonomy_for_object_type('post_tag', 'shorthand_story');
     64}
     65add_action('init', 'shand_create_post_type');
     66
     67
     68function shand_wpt_shorthand_story()
     69{
    6670
    6771    global $post;
     
    8387    <style>
    8488        li.story {
    85             float:left;
    86             width:160px;
    87             margin:5px;
    88         }
     89            float: left;
     90            width: 160px;
     91            margin: 5px;
     92        }
     93
    8994        li.story.selected label {
    90             background:#5b9dd9;
    91             color:#eee;
    92         }
     95            background: #5b9dd9;
     96            color: #eee;
     97        }
     98
    9399        li.story input {
    94100            display: none !important;
    95101        }
     102
    96103        li.story label {
    97             display:block;
    98             background:#fafafa;
     104            display: block;
     105            background: #fafafa;
    99106            text-align: center;
    100             height:160px;
    101             padding-top:5px;
    102             border:1px solid #eeeeee;
    103         }
     107            height: 160px;
     108            padding-top: 5px;
     109            border: 1px solid #eeeeee;
     110        }
     111
    104112        li.story label:hover {
    105             border:1px solid #5b9dd9;
    106         }
     113            border: 1px solid #5b9dd9;
     114        }
     115
    107116        li.story label span {
    108117            display: block;
    109118            font-weight: bold;
    110119        }
     120
    111121        li.story label span.desc {
    112122            display: none;
    113123        }
     124
    114125        div.clear {
    115             clear:left;
    116         }
     126            clear: left;
     127        }
     128
    117129        #codearea {
    118             border:1px solid #999999;
    119             font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
    120             width:100%;
    121             height:300px;
    122         }
     130            border: 1px solid #999999;
     131            font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
     132            width: 100%;
     133            height: 300px;
     134        }
     135
    123136        #abstract {
    124             border:1px solid #999999;
    125             width:100%;
    126             height:200px;
    127         }
     137            border: 1px solid #999999;
     138            width: 100%;
     139            height: 200px;
     140        }
     141
    128142        ul.stories {
    129             max-height:400px;
    130             overflow-y:scroll;
    131         }
     143            max-height: 400px;
     144            overflow-y: scroll;
     145        }
     146
    132147        ul.stories img {
    133148            object-fit: cover;
    134             height:110px;
    135         }
     149            height: 110px;
     150        }
     151
    136152        p.warning {
    137153            color: red;
     
    139155        }
    140156    </style>
    141 <?php
     157    <?php
    142158
    143159    $selected_story = get_post_meta($post->ID, 'story_id', true);
     
    146162        if ($story_api_version == $version) {
    147163            echo '<p>Clicking UPDATE will update Wordpress with the latest version of the story from Shorthand.</p>';
    148             echo '<input name="story_id" type="hidden" value="'.$selected_story.'" />';
    149         }   else {
     164            echo '<input name="story_id" type="hidden" value="' . $selected_story . '" />';
     165        } else {
    150166            echo '<p class="warning">To update this story from Shorthand, please switch to the correct API version <a href="options-general.php?page=shorthand-options">here</a></p>';
    151167            echo '<style>#publish { visibility: hidden !important; }</style>';
    152             echo '<input name="story_id" type="hidden" value="'.$selected_story.'" />';
     168            echo '<input name="story_id" type="hidden" value="' . $selected_story . '" />';
    153169        }
    154170        return;
     
    156172    $stories = sh_get_stories();
    157173
    158     if(!is_array($stories)) {
     174    if (!is_array($stories)) {
    159175        echo 'Could not connect to Shorthand, please check your <a href="options-general.php?page=shorthand-options">Wordpress Shorthand settings</a>.';
    160     } else if(sizeOf($stories) == 0) {
     176    } else if (sizeOf($stories) == 0) {
    161177        echo 'You currently have no stories ready for publishing on Shorthand. Please check that your story is set to be ready for publishing.';
    162178    } else {
    163179        echo '<ul class="stories">';
    164         foreach($stories as $story) {
     180        foreach ($stories as $story) {
    165181            $selected = '';
    166182            $story_selected = '';
     
    177193                }
    178194            }
    179             echo '<li class="story '.$story_selected.'"><label><input name="story_id" type="radio" value="'.$story->id.'" '.$selected.' /><img width="150" src="'.$baseurl.$story->image.'" /><span class="title">'.$story->title.$archived.'</span><span class="desc">'.$story->metadata->description.'</span></a></label></li>';
     195            echo '<li class="story ' . $story_selected . '"><label><input name="story_id" type="radio" value="' . $story->id . '" ' . $selected . ' /><img width="150" src="' . $baseurl . $story->image . '" /><span class="title">' . $story->title . $archived . '</span><span class="desc">' . $story->metadata->description . '</span></a></label></li>';
    180196        }
    181197        echo '</ul><div class="clear"></div>';
     
    184200    // Noncename needed to verify where the data originated
    185201    echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
    186     wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    187 
    188 ?>
     202        wp_create_nonce(plugin_basename(__FILE__)) . '" />';
     203
     204    ?>
    189205    <script>
    190     jQuery('li.story input:radio').click(function(){
    191         jQuery('li.story').removeClass('selected');
    192         jQuery(this).parent().parent().addClass('selected');
    193         jQuery('label#title-prompt-text').text('');
    194         jQuery('input#title').val(jQuery(this).parent().find('span.title').text());
    195         if (jQuery('textarea#abstract').val() === '') {
    196             jQuery('textarea#abstract').val(jQuery(this).parent().find('span.desc').text());
    197         }
    198     });
     206        jQuery('li.story input:radio').click(function() {
     207            jQuery('li.story').removeClass('selected');
     208            jQuery(this).parent().parent().addClass('selected');
     209            jQuery('label#title-prompt-text').text('');
     210            jQuery('input#title').val(jQuery(this).parent().find('span.title').text());
     211            if (jQuery('textarea#abstract').val() === '') {
     212                jQuery('textarea#abstract').val(jQuery(this).parent().find('span.desc').text());
     213            }
     214        });
    199215    </script>
    200216<?php
    201217}
    202218
    203 function shand_wpt_shorthand_abstract() {
     219function shand_wpt_shorthand_abstract()
     220{
    204221    global $post;
    205222    $abstract = get_post_meta($post->ID, 'abstract', true);
    206223    echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
    207     wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    208     echo '<textarea id="abstract" name="abstract">'.esc_textarea($abstract).'</textarea>';
    209 }
    210 
    211 function shand_wpt_shorthand_extra_html() {
     224        wp_create_nonce(plugin_basename(__FILE__)) . '" />';
     225    echo '<textarea id="abstract" name="abstract">' . esc_textarea($abstract) . '</textarea>';
     226}
     227
     228function shand_wpt_shorthand_extra_html()
     229{
    212230    global $post;
    213231    $extra_html = get_post_meta($post->ID, 'extra_html', true);
    214232    echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
    215     wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    216     echo '<textarea id="codearea" name="extra_html">'.esc_textarea($extra_html).'</textarea>';
    217 }
    218 
    219 function shand_add_shorthand_metaboxes() {
     233        wp_create_nonce(plugin_basename(__FILE__)) . '" />';
     234    echo '<textarea id="codearea" name="extra_html">' . esc_textarea($extra_html) . '</textarea>';
     235}
     236
     237function shand_add_shorthand_metaboxes()
     238{
    220239    global $version;
    221240    global $post;
     
    223242    $selected_story = get_post_meta($post->ID, 'story_id', true);
    224243    if ($selected_story) {
    225         add_meta_box('shand_wpt_shorthand_story', 'Update Shorthand Story - '.$version.' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default');
    226     } else {
    227         add_meta_box('shand_wpt_shorthand_story', 'Select Shorthand Story - '.$version.' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default');
    228         }
    229         if (!$noabstract) {
    230             add_meta_box('shand_wpt_shorthand_abstract', 'Add story abstract', 'shand_wpt_shorthand_abstract', 'shorthand_story', 'normal', 'default');
    231         }
    232     add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default');
    233 }
    234 add_action( 'add_meta_boxes', 'shand_add_shorthand_metaboxes' );
     244        add_meta_box('shand_wpt_shorthand_story', 'Update Shorthand Story - ' . $version . ' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default');
     245    } else {
     246        add_meta_box('shand_wpt_shorthand_story', 'Select Shorthand Story - ' . $version . ' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default');
     247    }
     248    if (!$noabstract) {
     249        add_meta_box('shand_wpt_shorthand_abstract', 'Add story abstract', 'shand_wpt_shorthand_abstract', 'shorthand_story', 'normal', 'default');
     250    }
     251    add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default');
     252}
     253add_action('add_meta_boxes', 'shand_add_shorthand_metaboxes');
    235254
    236255
    237256/* Save the shorthand story */
    238 function shand_save_shorthand_story( $post_id, $post, $update ) {
     257function shand_save_shorthand_story($post_id, $post, $update)
     258{
    239259    global $noabstract;
    240260    $slug = 'shorthand_story';
    241     if ( $slug != $post->post_type ) {
    242         return;
    243     }
    244 
    245     if (!$noabstract && isset($_REQUEST['abstract'])) {
    246         update_post_meta( $post_id, 'abstract', wp_kses_post($_REQUEST['abstract']) );
    247     } else if ($noabstract && get_post_meta( $post_id, 'abstract' )) {
    248       delete_post_meta( $post_id, 'abstract' );
    249     }
    250 
    251     if (isset($_REQUEST['extra_html'])) {
    252         update_post_meta( $post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html']) );
    253         }
    254 
    255     if (isset($_REQUEST['story_id'])) {
    256             $safe_story_id = $_REQUEST['story_id'];
    257         update_post_meta( $post_id, 'story_id', sanitize_text_field( $safe_story_id ) );
    258         $err = sh_copy_story($post_id, $safe_story_id);
     261    if ($slug != $post->post_type) {
     262        return;
     263    }
     264
     265    if (!$noabstract && isset($_REQUEST['abstract'])) {
     266        update_post_meta($post_id, 'abstract', wp_kses_post($_REQUEST['abstract']));
     267    } else if ($noabstract && get_post_meta($post_id, 'abstract')) {
     268        delete_post_meta($post_id, 'abstract');
     269    }
     270
     271    if (isset($_REQUEST['extra_html'])) {
     272        update_post_meta($post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html']));
     273    }
     274
     275    if (isset($_REQUEST['story_id'])) {
     276        $safe_story_id = preg_replace("/\W|_/", '', $_REQUEST['story_id']);
     277        update_post_meta($post_id, 'story_id', sanitize_text_field($safe_story_id));
     278        $err = sh_copy_story($post_id, $safe_story_id);
     279        $story_path = sh_get_story_path($post_id, $safe_story_id);
     280
     281        //Sometimes the story needs to be gotten twice
     282        if (!isset($story_path)) {
     283            $err = sh_copy_story($post_id, $safe_story_id);
    259284            $story_path = sh_get_story_path($post_id, $safe_story_id);
    260 
    261         //Sometimes the story needs to be gotten twice
    262         if(!isset($story_path)) {
    263             $err = sh_copy_story($post_id, $safe_story_id);
    264             $story_path = sh_get_story_path($post_id, $safe_story_id);
    265         }
    266 
    267         if(isset($story_path)) {
    268                 // The story has been uploaded
    269             update_post_meta($post_id, 'story_path', $story_path);
    270 
    271             // Get path to the assets
    272                 $assets_path = sh_get_story_url($post_id, $safe_story_id);
    273 
    274             // Save the head and body
    275                 $version = get_option('sh_api_version');
    276                 update_post_meta( $post_id, 'api_version', $version);
    277                 $head_file = $story_path.'/component_head.html';
    278                 $article_file = $story_path.'/component_article.html';
    279                 if (substr($safe_story_id, 0, 2) == 'v1') {
    280                     $version = 'v1';
    281                 }
    282                 if ($version == 'v2') {
    283                     $head_file = $story_path.'/head.html';
    284                     $article_file = $story_path.'/article.html';
    285                 }
    286             $body = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version);
    287             update_post_meta($post_id, 'story_body', wp_slash($body));
    288                 $head = shand_fix_content_paths($assets_path, file_get_contents($head_file), $version);
    289                 update_post_meta($post_id, 'story_head', wp_slash($head));
    290 
    291                 // Save the abstract
    292                 if (!$noabstract) {
    293                     $abstract = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version);
    294                     remove_action( 'save_post', 'shand_save_shorthand_story', 10, 3);
    295                     $post = array(
    296                         'ID' => $post_id,
    297                         'post_content' => shand_abstract_template($post_id, wp_kses_post($_REQUEST['abstract']), $abstract)
    298                     );
    299                     wp_update_post( $post );
    300                     add_action( 'save_post', 'shand_save_shorthand_story', 10, 3);
    301                 } else  {
    302                     remove_action( 'save_post', 'shand_save_shorthand_story', 10, 3);
    303                     $post = array(
    304                         'ID' => $post_id,
    305                         'post_content' => ''
    306                     );
    307                     wp_update_post( $post );
    308                     add_action( 'save_post', 'shand_save_shorthand_story', 10, 3);
    309                 }
    310         } else {
    311             echo 'Something went wrong, please try again';
    312             print_r($err);
    313             die();
    314         }
    315     }
    316 }
    317 add_action( 'save_post', 'shand_save_shorthand_story', 10, 3);
     285        }
     286
     287        if (isset($story_path)) {
     288            // The story has been uploaded
     289            update_post_meta($post_id, 'story_path', $story_path);
     290
     291            // Get path to the assets
     292            $assets_path = sh_get_story_url($post_id, $safe_story_id);
     293
     294            // Save the head and body
     295            $version = get_option('sh_api_version');
     296            update_post_meta($post_id, 'api_version', $version);
     297            $head_file = $story_path . '/component_head.html';
     298            $article_file = $story_path . '/component_article.html';
     299            if (substr($safe_story_id, 0, 2) == 'v1') {
     300                $version = 'v1';
     301            }
     302            if ($version == 'v2') {
     303                $head_file = $story_path . '/head.html';
     304                $article_file = $story_path . '/article.html';
     305            }
     306            $body = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version);
     307            update_post_meta($post_id, 'story_body', wp_slash($body));
     308            $head = shand_fix_content_paths($assets_path, file_get_contents($head_file), $version);
     309            update_post_meta($post_id, 'story_head', wp_slash($head));
     310
     311            // Save the abstract
     312            if (!$noabstract) {
     313                $abstract = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version);
     314                remove_action('save_post', 'shand_save_shorthand_story', 10, 3);
     315                $post = array(
     316                    'ID' => $post_id,
     317                    'post_content' => shand_abstract_template($post_id, wp_kses_post($_REQUEST['abstract']), $abstract)
     318                );
     319                wp_update_post($post);
     320                add_action('save_post', 'shand_save_shorthand_story', 10, 3);
     321            } else {
     322                remove_action('save_post', 'shand_save_shorthand_story', 10, 3);
     323                $post = array(
     324                    'ID' => $post_id,
     325                    'post_content' => ''
     326                );
     327                wp_update_post($post);
     328                add_action('save_post', 'shand_save_shorthand_story', 10, 3);
     329            }
     330        } else {
     331            echo 'Something went wrong, please try again';
     332            print_r($err);
     333            die();
     334        }
     335    }
     336}
     337add_action('save_post', 'shand_save_shorthand_story', 10, 3);
    318338
    319339
    320340/* Load Shorthand Template Hook */
    321 function shand_load_single_shorthand_template($template) {
    322     global $post;
    323     if ($post->post_type == "shorthand_story"){
    324         $path = locate_template(array('single-shorthand_story.php', 'templates/single-shorthand_story.php', 'template-parts/single-shorthand_story.php'));
    325         if($path) {
    326             return $path;
    327         }
    328         $plugin_path = plugin_dir_path( __FILE__ );
    329         $template_name = 'templates/single-shorthand_story.php';
    330         if($template === get_stylesheet_directory() . '/' . $template_name
    331             || !file_exists($plugin_path . $template_name)) {
    332             return $template;
    333         }
    334         return $plugin_path . $template_name;
    335     }
    336     return $template;
     341function shand_load_single_shorthand_template($template)
     342{
     343    global $post;
     344    if ($post->post_type == "shorthand_story") {
     345        $path = locate_template(array('single-shorthand_story.php', 'templates/single-shorthand_story.php', 'template-parts/single-shorthand_story.php'));
     346        if ($path) {
     347            return $path;
     348        }
     349        $plugin_path = plugin_dir_path(__FILE__);
     350        $template_name = 'templates/single-shorthand_story.php';
     351        if (
     352            $template === get_stylesheet_directory() . '/' . $template_name
     353            || !file_exists($plugin_path . $template_name)
     354        ) {
     355            return $template;
     356        }
     357        return $plugin_path . $template_name;
     358    }
     359    return $template;
    337360}
    338361add_filter('single_template', 'shand_load_single_shorthand_template');
    339362
    340363
    341 function hook_css() {
    342     if ( is_single() && 'shorthand_story' == get_post_type() ) {
     364function hook_css()
     365{
     366    if (is_single() && 'shorthand_story' == get_post_type()) {
    343367        $meta = get_post_meta(get_post()->ID);
    344368        echo trim($meta['story_head'][0]);
     
    349373
    350374/* Get Posts Hook */
    351 function shand_shorthand_get_posts( $query ) {
    352     if ( is_home() && $query->is_main_query() )
    353         $query->set( 'post_type', array( 'post', 'shorthand_story' ) );
     375function shand_shorthand_get_posts($query)
     376{
     377    if (is_home() && $query->is_main_query())
     378        $query->set('post_type', array('post', 'shorthand_story'));
    354379
    355380    return $query;
    356381}
    357 add_filter( 'pre_get_posts', 'shand_shorthand_get_posts' );
     382add_filter('pre_get_posts', 'shand_shorthand_get_posts');
    358383
    359384
    360385/* Table Hook */
    361 function shand_add_shorthand_story_columns($columns) {
    362         $cols = array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array('api_version' => __('API Version')) + array_slice($columns, 2, count($columns)-2, true);
    363     return $cols;
    364 }
    365 add_filter('manage_shorthand_story_posts_columns' , 'shand_add_shorthand_story_columns');
     386function shand_add_shorthand_story_columns($columns)
     387{
     388    $cols = array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array('api_version' => __('API Version')) + array_slice($columns, 2, count($columns) - 2, true);
     389    return $cols;
     390}
     391add_filter('manage_shorthand_story_posts_columns', 'shand_add_shorthand_story_columns');
    366392
    367393
    368394/* Table Hook */
    369 function shand_shorthand_show_columns($name) {
    370     global $post;
    371     switch ($name) {
    372         case 'story_id':
    373             $views = get_post_meta($post->ID, 'story_id', true);
    374                         echo $views;
    375                         break;
    376                 case 'api_version':
    377                         $views = get_post_meta($post->ID, 'api_version', true);
    378                         if ($views == '') {
    379                             // Determine the version, save it if possible;
    380                             $views = 'Unknown';
    381                             $story_id = get_post_meta($post->ID, 'story_id', true);
    382                             if ($story_id) {
    383                                 $views = determine_version_id($story_id);
    384                             }
    385                         }
    386                         echo $views;
    387                         break;
    388     }
     395function shand_shorthand_show_columns($name)
     396{
     397    global $post;
     398    switch ($name) {
     399        case 'story_id':
     400            $views = get_post_meta($post->ID, 'story_id', true);
     401            echo $views;
     402            break;
     403        case 'api_version':
     404            $views = get_post_meta($post->ID, 'api_version', true);
     405            if ($views == '') {
     406                // Determine the version, save it if possible;
     407                $views = 'Unknown';
     408                $story_id = get_post_meta($post->ID, 'story_id', true);
     409                if ($story_id) {
     410                    $views = determine_version_id($story_id);
     411                }
     412            }
     413            echo $views;
     414            break;
     415    }
    389416}
    390417add_action('manage_posts_custom_column',  'shand_shorthand_show_columns');
     
    392419
    393420/* Filter to fix post type tags */
    394 function shand_post_type_tags_fix($request) {
    395     if ( isset($request['tag']) && !isset($request['post_type']) ) {
    396         $request['post_type'] = 'any';
    397     }
    398     if ( isset($request['category_name']) && !isset($request['post_type']) ) {
    399         $request['post_type'] = 'any';
    400     }
    401     return $request;
     421function shand_post_type_tags_fix($request)
     422{
     423    if (isset($request['tag']) && !isset($request['post_type'])) {
     424        $request['post_type'] = 'any';
     425    }
     426    if (isset($request['category_name']) && !isset($request['post_type'])) {
     427        $request['post_type'] = 'any';
     428    }
     429    return $request;
    402430}
    403431add_filter('request', 'shand_post_type_tags_fix');
     
    405433
    406434/* Activation Hook */
    407 function shand_shorthand_activate() {
     435function shand_shorthand_activate()
     436{
    408437    shand_create_post_type();
    409438    flush_rewrite_rules();
    410439}
    411 register_activation_hook( __FILE__, 'shand_shorthand_activate' );
     440register_activation_hook(__FILE__, 'shand_shorthand_activate');
    412441
    413442
     
    415444
    416445/* Fix content paths */
    417 function shand_fix_content_paths($assets_path, $content, $version) {
     446function shand_fix_content_paths($assets_path, $content, $version)
     447{
    418448    if ($version == 'v2') {
    419         $content = str_replace('./assets/', $assets_path.'/assets/', $content);
    420         $content = str_replace('./static/', $assets_path.'/static/', $content);
    421         $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path.'$1', $content);
     449        $content = str_replace('./assets/', $assets_path . '/assets/', $content);
     450        $content = str_replace('./static/', $assets_path . '/static/', $content);
     451        $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path . '$1', $content);
    422452    } else {
    423         $content = str_replace('./static/', $assets_path.'/static/', $content);
    424         $content = str_replace('./media/', $assets_path.'/media/', $content);
     453        $content = str_replace('./static/', $assets_path . '/static/', $content);
     454        $content = str_replace('./media/', $assets_path . '/media/', $content);
    425455    }
    426456    return $content;
    427457}
    428458
    429 function determine_version_id($story_id) {
     459function determine_version_id($story_id)
     460{
    430461    if (substr($story_id, 0, 2) == 'v1') {
    431462        return 'v1';
Note: See TracChangeset for help on using the changeset viewer.