WordPress.org

Plugin Directory

Changeset 128300


Ignore:
Timestamp:
06/22/09 03:29:19 (5 years ago)
Author:
ryelle
Message:

updated to 1.6.20: proper image support, better documentation, specific categories, auto-detect directory, cosmetics.

Location:
post-from-site/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • post-from-site/trunk/post_from_site.php

    r123267 r128300  
    22/* 
    33 * Plugin Name: Post From Site 
    4  * Plugin URI: http://www.redradar.net/wp/?p= 
    5  * Description: Add a new post directly from your website - no need to go to the admin side.<br /> 
     4 * Plugin URI: http://www.redradar.net/wp/?p=95 
     5 * Description: Add a new post directly from your website - no need to go to the admin side. 
    66 * Author: Kelly Dwan 
    7  * Version: 1.6.3 
    8  * Date: 6.3.09 
     7 * Version: 1.6.20 
     8 * Date: 6.20.09 
    99 * Author URI: http://www.redradar.net/wp 
    10 */ 
    11  
     10 */ 
     11/* * * 
     12 * TODO: 
     13 *      Tag support 
     14 *      additional media? 
     15 * SUGGESTIONS: 
     16 *      BuddyPress 
     17 *      non-registered users -> captcha and/or automatic pending status 
     18 *      horizontal category layout rather than vertical 
     19 * SEPERATE PLUGINS: 
     20 *      simple pulldown login box 
     21 *      forked pfs that just does images 
     22 */ 
    1223add_action('wp_head','pfs_includes'); 
    13 function pfs_includes(){  
    14     /*ensure jquery exists, perhaps a checkbox in the options? */ 
    15     if (True == get_option('pfs_addjquery')) echo "<script type='text/javascript' src='".dirname(__FILE__)."'></script>"; ?> 
    16     <script language='javascript' src='<?php bloginfo('url'); ?>/wp-content/plugins/pfs/pfs_display.js'></script>  
    17     <link rel="stylesheet" type="text/css" media="screen" href='<?php bloginfo('url'); ?>/wp-content/plugins/pfs/pfs_style.php' /> 
     24function pfs_includes(){ 
     25$path = split('wp',__FILE__,2); ?> 
     26<!-- CSS/js added by post-from-site plugin --> 
     27<script language='javascript' src='<?php echo get_bloginfo('url').dirname($path[1]); ?>/pfs_display.js'></script>  
     28<link rel="stylesheet" type="text/css" media="screen" href='<?php echo get_bloginfo('url').dirname($path[1]); ?>/pfs_style.php' /> 
    1829<?php } ?> 
    19 <?php function post_from_site(){ 
     30<?php  
     31/* * * 
     32 * Creates link and postbox (initially hidden with display:none), calls pfs_submit on form-submission. 
     33 * @param string $cat Category ID for posting specifically to one category. Default is '', which allows user to choose from allowed categories. 
     34 * @param string $linktext Link text for post link. Default is set in admin settings, any text here will override that.  
     35 */ 
     36function post_from_site($cat = '', $linktext = ''){ 
     37    if (''==$linktext) $linktext = get_option('pfs_linktext'); 
    2038    // Javascript displays the box when the link is clicked  
    21     echo "<a id='postlink' onclick='pfsopen()'>".get_option('pfs_linktext')."</a><span id='pfs_proc'></span>"; ?> 
     39    echo "<a id='postlink' onclick='pfsopen()'>$linktext</a><span id='pfs_proc'></span>"; ?> 
    2240    <div id="pfs_postbox" style="display:none"> 
    2341        <div id="closex"><a onclick="javascript:pfsclose()">x</a></div> 
    24         <form class="pfs" id="pfs_form" method="post" action="<?php echo ''; ?>" enctype="multipart/form-data"> 
     42        <form class="pfs" id="pfs_form" method="post" action="<?php echo ''; ?>" enctype='multipart/form-data'> 
    2543        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_option('pfs_maxfilesize');?>" /> 
    2644        <center><h4>Title:</h4> <input name="title" id="pfs_title" value="" size="50" /></center> 
     
    2846        <?php if (True == get_option('pfs_allowimg')) echo "Image: <input type='file' name='image' id='pfs_image' size='50'>"; ?> 
    2947        <div id="pfs_catchecks"> 
    30         <h4>Categories:</h4><br /> 
    31         <?php $cat = get_option('pfs_excats'); 
    32         $categories = wp_dropdown_categories("exclude=$cat&echo=0&hide_empty=0"); 
    33         preg_match_all('/\s*<option class="(\S*)" value="(\S*)">(.*)<\/option>\s*/', $categories, $matches, PREG_SET_ORDER); 
    34         foreach ($matches as $match) 
    35             echo '<input type="checkbox" name="cats[]" value="'.$match[2].'" class="'.$match[1].'" id="'.$match[1].$match[2].'" /><label for="'.$match[1].$match[2].'">'.$match[3].'</label><br />'; 
     48        <?php  
     49        if (''==$cat){ 
     50            echo "<h4>Categories:</h4><br />"; 
     51            $excats = get_option('pfs_excats'); 
     52            $categories = wp_dropdown_categories("exclude=$excats&echo=0&hide_empty=0"); 
     53            preg_match_all('/\s*<option class="(\S*)" value="(\S*)">(.*)<\/option>\s*/', $categories, $matches, PREG_SET_ORDER); 
     54            foreach ($matches as $match) 
     55                echo '<input type="checkbox" name="cats[]" value="'.$match[2].'" class="'.$match[1].'" id="'.$match[1].$match[2].'" /><label for="'.$match[1].$match[2].'">'.$match[3].'</label><br />'; 
     56        } else { 
     57            echo "<h4>Posting to ".get_cat_name($cat)."</h4><br />"; 
     58            echo "<input type='hidden' name='cats[]' value='$cat' />"; 
     59        } 
    3660        ?> 
    3761        </div> 
     
    4872} 
    4973?> 
    50 <?php function pfs_submit($pfs_data){ 
     74<?php  
     75/* * * 
     76 * Processed form data into a proper post array, uses wp_insert_post() to add post. Also uses variables defined in the admin settings. 
     77 * @param array $pfs_data POSTed array of data from the form 
     78 */ 
     79function pfs_submit($pfs_data){ 
    5180    foreach($pfs_data as $key=>$value) ${$key} = $value; 
    5281    echo "<script language=javascript>document.getElementById('pfs_proc').innerHTML='processing...'</script>"; 
    53     $msg = ''; 
    5482    if (is_user_logged_in()) {  
    5583        /* play with the image */ 
    56         (preg_match("/(\.gif$|\.png$|\.jpg$|\.jpeg$)/",$_FILES['image']['name'])) ? $imgAllowed = 1 : $imgAllowed = ($_FILES['image']['name']==''); 
    57         if (!(empty($_FILES['image']['name'])) && $imgAllowed) { 
    58             $image = $_FILES['image']; 
    59             if (move_uploaded_file($image['tmp_name'], $image['name'])){ 
    60                 $msg .= ""; 
     84        if(''!=$_FILES['image']['tmp_name']){ 
     85            (getimagesize($_FILES['image']['tmp_name'])) ? $imgAllowed = 1 : $imgAllowed = (''==$_FILES['image']['name']); 
     86        } 
     87        if ($imgAllowed && (''!=$_FILES['image']['tmp_name'])){ 
     88            $upload = wp_upload_bits($_FILES["image"]["name"], null, file_get_contents($_FILES["image"]["tmp_name"])); 
     89            if (False === $upload['error']){ 
     90                $success = True; 
    6191            } else { 
    62                 $msg .= "<div id=\"alert\">There was an error uploading the image: "; 
    63                 switch($image['error']){ 
    64                     case 1: 
    65                     case 2: 
    66                         $msg .= "Filesize too large. "; 
    67                         break; 
    68                     case 3: 
    69                         $msg .= "Upload was interrupted. "; 
    70                         break; 
    71                     case 4: 
    72                         $msg .= "No file was uploaded. "; 
    73                         break; 
    74                 } 
    75                 $msg .= "</div><br />"; 
    76                 echo $msg; 
     92                echo "<div id=\"alert\">There was an error uploading the image: {$upload['error']}</div><br />"; 
    7793                return; 
    7894            } 
     
    85101                $title = $pfs_data['title']; 
    86102                $content = $pfs_data['postcontent']; 
    87                 ($image['name']!='')?$content .= "<br /><img src='{$image['name']}' class='postimg' />":''; 
     103                ($success)?$content .= "<br /><img src='{$upload['url']}' class='postimg' />":''; 
    88104                $categories = $pfs_data['cats']; 
    89105                $postarr = array(); 
     
    105121        echo "<div id=\"alert\">You need to be logged in to post. <a href='http://www.redradar.net/wp/wp-login.php?redirect_to=$page'>Log in</a></div><br />"; 
    106122    } 
    107     echo "<script language=javascript>document.getElementById('pfs_proc').innerHTML=''</script>"; 
     123    echo "<script language=javascript>document.getElementById('pfs_proc').innerHTML='';</script>"; 
    108124    return; 
    109125}  
     
    126142    add_option('pfs_customcss', ''); 
    127143}?> 
    128 <?php function pfs_settings() { ?> 
     144<?php 
     145/* * * 
     146 * What to display in the admin menu 
     147 */ 
     148function pfs_settings() { ?> 
    129149<script language="Javascript"> 
    130150function filesize_bytes() { 
     
    148168    } 
    149169} 
     170function genCode(){ 
     171    if (document.getElementById("cat").value == ''){cat = "''";} else {cat=document.getElementById("cat").value;} 
     172    document.getElementById('gendCode').innerHTML = "&lt;?php if (function_exists('post_from_site')) {post_from_site("+cat+",'"+document.getElementById('pfs_indlinktxt').value+"');} ?&gt;"; 
     173} 
    150174</script> 
    151175<style type='text/css'> 
    152 .pfs th{ 
     176.pfs th { 
    153177    font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif; 
    154178    font-size:12pt; 
     
    156180    font-weight:bold; 
    157181} 
    158 .pfs td{ 
     182.pfs td { 
    159183    font-size:10pt; 
    160184} 
     
    170194                <tr><th colspan='2'>User Permissions</th></tr> 
    171195                <tr><td>What categories can't quickpost users post to (ie, which to exclude)? <small>comma seperated values, please.</small></td><td><input type='text' name='pfs_excats' value='<?php echo get_option('pfs_excats');?>' /></td><td>Default: none</td></tr> 
    172                 <tr><td>Allow users to upload an image (will be attached to end of post)?</td><td><select name='pfs_allowimg'><option value='1' <?php echo (get_option('pfs_allowimg'))?'selected':'';?>>Yes</option><option value='0' <?php echo (get_option('pfs_allowimg'))?'':'selected';?>>No</option></select></td><td>Default: No [note: still not perfected as of v0.6.2]</td></tr> 
    173                 <tr><td>Where to upload the images?</td><td><input type='text' name='pfs_imagedir' value='<?php echo get_option('pfs_imagedir');?>' /></td></tr> 
     196                <tr><td>Allow users to upload an image (will be attached to end of post)?</td><td><select name='pfs_allowimg'><option value='1' <?php echo (get_option('pfs_allowimg'))?'selected':'';?>>Yes</option><option value='0' <?php echo (get_option('pfs_allowimg'))?'':'selected';?>>No</option></select></td><td>Note: Images automatically uploaded to 'uploads' directory of wp-content -- just like uploading through the write-post/write-page pages.</td></tr> 
    174197                <tr><td>Maximum file size for uploaded images?</td><td><input type='text' id='pfs_mfs' onblur='javascript:filesize_bytes()' value='<?php echo display_filesize(get_option('pfs_maxfilesize'));?>' /></td><td>Default: 30MB</td></tr> 
    175198                <input type="hidden" id='pfs_mfsHidden' name='pfs_maxfilesize' value='' /> 
     
    203226        <p>Add the following code wherever you want the link to appear in your theme.</p> 
    204227        <p><code>&lt;?php if (function_exists('post_from_site')) {post_from_site();} ?&gt;</code></p> 
    205  
     228        <p>To generate individual links to specific category posts: <small>(like, 'click here to post in the general category')</small></p>  
     229        <p>Category: <select id="cat" class="postform"><?php  
     230            $categories = wp_dropdown_categories("echo=0&hide_empty=0"); 
     231            preg_match_all('/\s*<option class="(\S*)" value="(\S*)">(.*)<\/option>\s*/', $categories, $matches, PREG_SET_ORDER); 
     232            echo "<option class='{$matches[0][1]}' value=''></option>"; 
     233            foreach ($matches as $match) echo $match[0];  
     234        ?></select> &nbsp; Link Text: <input type="text" id="pfs_indlinktxt" /> &nbsp; <input type="submit" value="generate code" onclick="javascript:genCode();"/></p> 
     235        <p><code id="gendCode"></code></p> 
    206236    </div> 
    207237<?php } ?> 
    208238<?php 
    209 /* 
     239/* * * 
    210240 * A few useful housekeeping-type functions 
    211241 */ 
  • post-from-site/trunk/readme.txt

    r123699 r128300  
    22Contributors: ryelle 
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YB5AWJMBLCCVC&lc=US&item_name=redradar%2enet&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted 
    4 Tags: quick post, frontend, insert post, post 
     4Tags: quick post, frontend, insert post, post, Post 
    55Requires at least: 2.7 
    6 Tested up to: 2.7 
    7 Stable tag: trunk 
     6Tested up to: 2.8 
     7Stable tag: 1.6.20 
    88 
    99This plugin allows you to post straight from your front-end (i.e. website) - perfect for a quick update! Also useful if you have multiple users and don’t need them to see the admin side of things.  
     
    1515On the admin side, there is a settings page where you can edit the plugin to your preferences. You can customize the link text, post-box background color, title/text color, and even add your own CSS to tailor pfs to your site. 
    1616 
    17 As for permissions, you can limit the categories pfs can post to and allow/disallow uploading of images (currently under work, will be fixed in next version). If you’d rather have pfs’s posts approved before they are visible, you can set the post status to ‘pending’ or ‘draft’. Same with the comment status, it can default to ‘open’ (allowing comments) or ‘closed’ (not allowing comments). 
     17As for permissions, you can limit the categories pfs can post to and allow/disallow uploading of images. If you’d rather have pfs’s posts approved before they are visible, you can set the post status to ‘pending’ or ‘draft’. Same with the comment status, it can default to ‘open’ (allowing comments) or ‘closed’ (not allowing comments). 
    1818 
    1919== Installation == 
    2020 
    21211. Unzip `pfs.zip` 
    22 1. Upload all files to the `/wp-content/plugins/pfs` directory 
     221. Upload all files to the `/wp-content/plugins/post-from-site` directory 
    23231. Activate the plugin through the 'Plugins' menu in WordPress 
    24241. Place `<?php if (function_exists('post_from_site')) {post_from_site();} ?>` in your templates where you want to see the link. 
     
    2626== Frequently Asked Questions == 
    2727 
    28 No questions yet - [ask one](http://www.redradar.net/wp/?p=95)? 
     281. The pop-up won't pop-up! (aka there is a link, but clicking it does nothing.) 
     29 
     30Check that you have the javascript and css files in the plugin's folder (`post-from-site`). A problem with the first version of this plugin was that the plugin was looking for the files in the wrong directory. This *should* be fixed with the newest version, so definitely let me know if this is still happening. 
     31 
     32[ask a question?](http://www.redradar.net/wp/?p=95)? 
    2933 
    3034== Screenshots == 
Note: See TracChangeset for help on using the changeset viewer.