Plugin Directory

Changeset 198266


Ignore:
Timestamp:
01/26/2010 11:10:32 AM (16 years ago)
Author:
hanok
Message:

Version 0.3

Location:
googl-generator/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • googl-generator/trunk/googl-generator.php

    r194644 r198266  
    44Plugin URI: http://www.dolcebita.com/wordpress/googl-generator/
    55Description: Returns short URL based on Goo.gl using Matthew Flaschen web service.
    6 Version: 0.2
     6Version: 0.3
    77Author: Marcos Esperon
    88Author URI: http://www.dolcebita.com/
     
    2525*/
    2626
    27 function googl_generator($long_url) {
     27function gg_generate($long_url) {
    2828   
    29   $output = '';
     29  $output = '<div class="google_generator">';
    3030 
    3131  if (extension_loaded("curl")) {
     
    3737      $json_response = json_decode($response_text);
    3838    }
    39     $output = $json_response->short_url;
     39    $shorturl = $json_response->short_url;
    4040 
    4141  } else {
     
    4343    $url = htmlentities($long_url, ENT_QUOTES);
    4444      $obj = json_decode(file_get_contents('http://ggl-shortener.appspot.com/?url=' . urlencode($url)));
    45       $output = $obj->{'short_url'};
     45      $shorturl = $obj->{'short_url'};
    4646
    4747  }
    4848 
    49   echo $output;
    50  
    51 }
    52 
     49  if(get_option('gg_version') == 'link') {
     50    $output .= '<a href="'.$shorturl.'" title="Short URL">'.$shorturl.'</a>';
     51  } else if (get_option('gg_version') == 'input') {
     52    $output .= '<input type="text" value="'.$shorturl.'" readonly />';
     53  } else {
     54    $output .= $shorturl;
     55  }
     56 
     57  $output .= '</div>';
     58  return $output;
     59 
     60}
     61
     62function googl_generator($long_url) {
     63  echo gg_generate($long_url);
     64}
     65
     66function googl_generator_box($content) {
     67
     68    global $post;
     69   
     70
     71    if (get_option('gg_display_post') == null && is_single()) {
     72        return $content;
     73    }
     74   
     75    if (get_option('gg_display_page') == null && is_page()) {
     76        return $content;
     77    }
     78
     79    if (get_option('gg_display_front') == null && is_home()) {
     80        return $content;
     81    }
     82       
     83    $url = '';
     84    if (get_post_status($post->ID) == 'publish') {
     85        $url = get_permalink();
     86    }
     87    $box = gg_generate($url);
     88   
     89    // Before and After code added by http://www.jimyaghi.com
     90    if (get_option('gg_where') == 'beforeandafter') {
     91      return $box . $content . $box;
     92    } else if (get_option('gg_where') == 'before') {
     93      return $box . $content;
     94    } else {
     95      return $content . $box;
     96    }
     97       
     98}
     99
     100function gg_remove_filter($content) {
     101    if (!is_feed()) {
     102        remove_action('the_content', 'googl_generator_box');
     103    }
     104    return $content;
     105}
     106
     107function gg_options_page() {
    53108?>
     109    <div class="wrap">
     110    <div class="icon32" id="icon-options-general"><br/></div><h2>Settings for Goo.gl Generator</h2>
     111    <form method="post" action="options.php">
     112    <?php
     113        // New way of setting the fields, for WP 2.7 and newer
     114        if(function_exists('settings_fields')){
     115            settings_fields('gg-options');
     116        } else {
     117            wp_nonce_field('update-options');
     118            ?>
     119            <input type="hidden" name="action" value="update" />
     120            <input type="hidden" name="page_options" value="gg_where,gg_display_page,gg_display_post,gg_display_front,gg_version" />
     121            <?php
     122        }
     123    ?>
     124        <table class="form-table">
     125            <tr>
     126                <tr>
     127                    <th scope="row">
     128                        Display
     129                    </th>
     130                    <td>
     131                        <p>
     132                            <input type="checkbox" value="1" <?php if (get_option('gg_display_post') == '1') echo 'checked="checked"'; ?> name="gg_display_post" id="gg_display_post" group="gg_display"/>
     133                            <label for="gg_display_post">Display the URL on posts</label>
     134                        </p>
     135                      <p>
     136                            <input type="checkbox" value="1" <?php if (get_option('gg_display_page') == '1') echo 'checked="checked"'; ?> name="gg_display_page" id="gg_display_page" group="gg_display"/>
     137                            <label for="gg_display_page">Display the URL on pages</label>
     138                        </p>
     139                        <p>
     140                            <input type="checkbox" value="1" <?php if (get_option('gg_display_front') == '1') echo 'checked="checked"'; ?> name="gg_display_front" id="gg_display_front" group="gg_display"/>
     141                            <label for="gg_display_front">Display the URL on the front page (home)</label>
     142                        </p>
     143                    </td>
     144                </tr>
     145                <th scope="row">
     146                    Position
     147                </th>
     148                <td>
     149                    <p>
     150                        <select name="gg_where">
     151                            <option <?php if (get_option('gg_where') == 'before') echo 'selected="selected"'; ?> value="before">Before</option>
     152                            <option <?php if (get_option('gg_where') == 'after') echo 'selected="selected"'; ?> value="after">After</option>
     153                            <option <?php if (get_option('gg_where') == 'beforeandafter') echo 'selected="selected"'; ?> value="beforeandafter">Before and After</option>
     154                        </select>
     155                    </p>
     156                </td>
     157            </tr>           
     158            <tr>
     159                <th scope="row">
     160                    Type
     161                </th>
     162                <td>
     163                    <p>
     164                        <input type="radio" value="plain" <?php if (get_option('gg_version') == 'plain') echo 'checked="checked"'; ?> name="gg_version" id="gg_version_plain" group="gg_version"/>
     165                        <label for="gg_version_plain">Text plain</label>
     166                    </p>
     167                    <p>
     168                        <input type="radio" value="link" <?php if (get_option('gg_version') == 'link') echo 'checked="checked"'; ?> name="gg_version" id="gg_version_link" group="gg_version"/>
     169                        <label for="gg_version_link">Link</label>
     170                    </p>
     171                    <p>
     172                        <input type="radio" value="input" <?php if (get_option('gg_version') == 'input') echo 'checked="checked"'; ?> name="gg_version" id="gg_version_input" group="gg_version" />
     173                        <label for="gg_version_input">Input</label>
     174                    </p>
     175                </td>
     176            </tr>
     177        </table>
     178        <p class="submit">
     179            <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
     180        </p>
     181    </form>
     182    </div>
     183<?php
     184}
     185
     186function gg_init(){
     187    if(function_exists('register_setting')){
     188        register_setting('gg-options', 'gg_display_page');
     189        register_setting('gg-options', 'gg_display_post');
     190        register_setting('gg-options', 'gg_display_front');
     191        register_setting('gg-options', 'gg_version');
     192        register_setting('gg-options', 'gg_where');       
     193    }
     194}
     195
     196if(is_admin()){
     197    add_action('admin_init', 'gg_init');
     198    add_action('admin_menu', 'gg_option_page');
     199}
     200
     201// Set the default options when the plugin is activated
     202function gg_activate(){
     203    add_option('gg_where', 'after');   
     204    add_option('gg_version', 'plain');   
     205    add_option('gg_display_page', '0');
     206    add_option('gg_display_post', '1');
     207    add_option('gg_display_front', '0');
     208}
     209
     210function gg_option_page() {
     211    add_options_page(__('Goo.gl Generator', 'googl-generator'), 'Goo.gl Generator', 8, basename(__FILE__), 'gg_options_page');
     212}
     213
     214add_filter('the_content', 'googl_generator_box');
     215add_filter('get_the_excerpt', 'gg_remove_filter', 9);
     216
     217register_activation_hook( __FILE__, 'gg_activate');
     218
     219?>
  • googl-generator/trunk/readme.txt

    r194802 r198266  
    44Requires at least: 2.0.0
    55Tested up to: 2.8
    6 Stable tag: 0.1
     6Stable tag: 0.3
    77 
    88Returns short URL based on Goo.gl using Matthew Flaschen web service.
     
    1212Returns short URL based on Goo.gl using Matthew Flaschen web service.
    1313
    14 Just activate the plugin and use this call in your theme:
     14Just activate the plugin and visit settings panel to configure the output.
     15
     16Yoy can use this call too in your theme:
    1517
    1618`<?php googl_generator('URL'); ?>`
     
    32341. URL example
    3335
     362. Settings panel
     37
    3438== Changelog == 
     39
     40= 0.3 = 
     41* Settings panel.
     42* Include URL automatically in post content. You can select position: before, after or both.
     43* Three output modes: text plain, link or input.
     44* Include URL in pages and front view (home).
    3545
    3646= 0.2 = 
Note: See TracChangeset for help on using the changeset viewer.