Plugin Directory

Changeset 728901


Ignore:
Timestamp:
06/20/2013 02:23:53 PM (13 years ago)
Author:
smoo1337
Message:

Version 2.0.0

Location:
wp-vgwort/trunk
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-vgwort/trunk/readme.txt

    r714650 r728901  
    4242== Changelog ==
    4343
     44= 2.0.0 =
     45* new features
     46
     47= 1.9 =
     48* Bugfix
     49
     50= 1.8 =
     51* Bugfix
     52
    4453= 1.7 =
    4554* Bugfix - Zaehlpixel wird nur in Beitraegen und Seiten angezeigt
  • wp-vgwort/trunk/wp-vgwort.php

    r714650 r728901  
    11<?php
    22
    3 /*
    4 Plugin Name: WP VG WORT
    5 Plugin URI: http://www.mywebcheck.de/vg-wort-plugin-wordpress/
    6 Description: Verwaltung der VG Wort Zählpixel
    7 Version: 1.9
    8 Author: Marcus Franke
    9 Author URI: http://mywebcheck.de
    10 */
     3/**
     4 *
     5 * @package   PluginName
     6 * @author    Marcus Franke <[email protected]>
     7 * @license   GPL-2.0+
     8 * @link      http://mywebcheck.de
     9 * @copyright 2013 MyWebcheck
     10 *
     11 * @wordpress-plugin
     12 * Plugin Name: WP VG WORT
     13 * Plugin URI:  http://www.mywebcheck.de/vg-wort-plugin-wordpress/
     14 * Description: Verwaltung der VG Wort Zählpixel
     15 * Version:     2.0.0
     16 * Author:      Marcus Franke
     17 * Author URI:  http://mywebcheck.de
     18 * Text Domain: wp-vgwort-locale
     19 * License:     GPL-2.0+
     20 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
     21 * Domain Path: /lang
     22 */
    1123
    12 define(PLUGINNAME,'wp-vgwort');
    13 define(REQUIREDCHARS,1800);
    14 define(VGWORTMETA, get_option('wp_vgwortmetaname', 'wp_vgwortmarke'));
     24// If this file is called directly, abort.
     25if ( ! defined( 'WPINC' ) ) {
     26    die;
     27}
    1528
    16 new WP_VGWORT();
     29// TODO: replace `class-plugin-name.php` with the name of the actual plugin's class file
     30require_once( plugin_dir_path( __FILE__ ) . 'class-wp-vgwort.php' );
    1731
    18 class WP_VGWORT {
    19          
    20     public function __construct(){
    21    
    22     // Init Methods
    23 
    24         add_action( 'edit_user_profile' , array( &$this , 'wpVGWortaddProfileData' ));
    25         add_action( 'show_user_profile' , array( &$this , 'wpVGWortaddProfileData' ));
    26         add_action( 'personal_options_update', array( &$this,'wpVGWortSaveExtraUserProfileFields' ));
    27         add_action( 'edit_user_profile_update', array( &$this,'wpVGWortSaveExtraUserProfileFields' ));
    28        
    29        
    30         add_action( 'add_meta_boxes' , array( &$this , 'wpVGWortAddCustomMeta' ));
    31         add_action( 'save_post' , array( &$this , 'wpVGWortSavePost' ));
    32         add_action( 'the_content' , array( &$this , 'wpVGWortFrontendDisplay' ));
    33         add_action( 'manage_posts_custom_column' , array( &$this , 'wpVGWortCustomColumn' ));
    34         add_action( 'manage_pages_custom_column' , array( &$this , 'wpVGWortCustomColumn' ));
    35         add_action( 'admin_footer' ,  array( &$this , 'wpVGWortAdminFooter' ));
    36         add_filter( 'manage_posts_columns' , array( &$this , 'wpVGWortColumn' ));
    37         add_filter( 'manage_pages_columns' , array( &$this , 'wpVGWortColumn' ));
    38         add_action( 'admin_menu' , array( &$this , 'wpVGWortRegisterSettingsPage' ));
    39        
    40     }
    41 
    42     /**
    43     *
    44     * register settingspage in wordpress
    45     * @param: none
    46     *
    47     */
    48    
    49     function wpVGWortRegisterSettingsPage() {
    50         add_submenu_page( 'options-general.php' , 'VG WORT', 'VG WORT' , 'add_users', 'wpVGWortSettings',  array( &$this , 'wpVGWortSettingsPage' ));   
    51     }
    52    
    53     /**
    54     *
    55     * Add Html for the settingspage
    56     * @param: none
    57     *
    58     */
    59    
    60     function wpVGWortSettingsPage (){
    61        
    62         // REQUEST
    63        
    64         if(isset($_POST[ 'save' ])){
    65             $ctypes = array('post','page');
    66             foreach($_POST['cpt'] as $key => $value){
    67                 $ctypes[] = sanitize_title( $key );
    68             }
    69            
    70             update_option('wp_cpt' , $ctypes,array());
    71             update_option('wp_vgwortmetaname' , esc_html($_POST['wpvgwortmetaname']));
    72            
    73         }
    74        
    75         $vgWortMetaOption = get_option( 'wp_vgwortmetaname' , 'wp_vgwortmarke' );
    76        
    77         ?>
    78         <div class="wrap">
    79         <?php screen_icon( 'plugins' ); ?>
    80         <form method="POST" action="">
    81             <h2>Einstellungen VG-Wort Plugin</h2>
    82            
    83         <table class="form-table">
    84         <tr valign="top">
    85         <th scope="row"> <h3>Konfiguration:</h3> </th>
    86         <td>
    87        
    88             <?php
    89 
    90             $types = get_post_types( array('public' => true,'show_ui' => true,'_builtin' => false) );
    91             $myTypes = get_option( 'wp_cpt');
    92            
    93             echo '<h4>Custom Post Types</h4>';
    94             echo'<p>Markierte Custom Post Types werden mit der VG Wort Funktion versehen</p>';
    95             echo '<ul>';
    96             foreach($types as $type){
    97                 if(in_array($type,$myTypes)){
    98                     echo '<li><input checked="checked" type="checkbox" name="cpt['.$type.']"> '.$type.' </li>';
    99                 } else {
    100                     echo '<li><input type="checkbox" name="cpt['.$type.']"> '.$type.' </li>';
    101                 }
    102             }
    103            
    104             echo '</ul>';
    105            
    106             ?>
    107             <span class="description">In Beiträge und Seiten sind immer vorhanden!</span>
    108             <br />
    109             <br />
    110         </td>
    111         </tr>
    112         <tr valign="top">
    113         <th scope="row"> <h3>MetaName:</h3> </th>
    114         <td>
    115             <input size="25" name="wpvgwortmetaname" value="<?php echo VGWORTMETA; ?>" /><br /><br />
    116             <span class="description">Dieses Feld kann genutzt werden um ein kompatible Lösung für andere Plugins zu erhalten</span>
    117             <ul>
    118                 <li>Default: "wp_vgworkmarke"</li>
    119                 <li><a href="http://maheo.eu/355-vg-wort-plugin-fuer-wordpress.php" title="VG Wort Plugin - Heiner Otterstedt" target="_blank">VG-Wort Krimskram</a>  -> "vgwpixel"</li>
    120             </ul>
    121            
    122         </td>
    123         </tr>
    124         <tr valign="top">
    125         <th scope="row"> <h3>Speichern:</h3> </th>
    126         <td>
    127             <input type="submit" name="save" value="Einstellung speichern" class="button-primary" / >
    128         </td>
    129         </tr>
    130         </form>
    131         <tr valign="top">
    132         <th scope="row"> <h3>Fehler und Bugs:</h3> </th>
    133         <td>
    134             Wenn Fehler Ihr Fehler in unserem Plugin gefunden habt, dann wäre es sehr nett wenn Ihr uns diese mitteilt.<br />
    135             Dazu könnt Ihr auf unserer Plugin Seite kommentieren oder eine E-Mail an uns senden.
    136            
    137             <ul>
    138                 <li>Kontakt</li>
    139                 <li><a href="http://www.mywebcheck.de/vg-wort-plugin-wordpress/" title="MyWebcheck - Plugin Seite" target="_blank">Plugin Seite</a></li>
    140                 <li><a href="[email protected]">[email protected]</li>
    141             </ul>
    142            
    143         </td>
    144         </tr>
    145         <tr valign="top">
    146         <th scope="row"> <h3>Cooles Plugin?:</h3> </th>
    147         <td>
    148             <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    149             <input type="hidden" name="cmd" value="_s-xclick">
    150             <input type="hidden" name="hosted_button_id" value="2PJGA2XSNG8EQ">
    151             <input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
    152             <img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
    153             </form>
    154         </td>
    155         </tr>
    156         </table>
    157        
    158         </div>
    159         <?php
    160     }
    161    
    162     /**
    163     *
    164     * Add the value of counted Chars in the Footer of RTE
    165     * @param: none
    166     *
    167     */
    168    
    169     function wpVGWortAdminFooter() {
    170         global $post;
    171 
    172       if(!empty( $post->post_content )) {
    173         printf('<script language="javascript" type="text/javascript"> var div = document.getElementById("wp-word-count"); if (div != undefined) { div.innerHTML = div.innerHTML + \'%s\'; } </script>', str_replace("'", "\'", sprintf('<span class="inside"> / Zeichen:'.' %d'.'</span> ', $this->getCharCount( $post->post_title.$post->post_content ) )));
    174       }
    175     }
    176    
    177     /**
    178     *
    179     * Add heading in overview of posts/pages
    180     * @param: none
    181     *
    182     */
    183    
    184     function wpVGWortColumn( $defaults )    {
    185 
    186         $currentPostType = get_post_type();
    187         $allowedTypes = get_option( 'wp_cpt',array('post','page'));
    188         if(in_array($currentPostType,$allowedTypes)){
    189             $defaults['vgwort'] = 'VG Wort';
    190         }
    191         return $defaults;
    192     }
    193    
    194     /**
    195     *
    196     * Add a custom row for displaying the WGWort status
    197     * @param: none
    198     *
    199     */
    200    
    201     function wpVGWortCustomColumn( $column ) {
    202         global $post;
    203 
    204         if($column == 'vgwort') {
    205      
    206             // VG vorhanden?
    207      
    208             $vgwort = get_post_meta( $post->ID , VGWORTMETA , true );
    209          
    210             if($vgwort) {
    211                 echo '<br/><span style="color:green">vorhanden</span>';
    212             }
    213             else {
    214               echo '<br/><span style="color:red">nicht vorhanden</span><br />';
    215             }
    216         }
    217        
    218     }
    219    
    220     /**
    221     *
    222     * show the available posts/pages that could be used for WGWort
    223     * @param: object $user;
    224     *
    225     */
    226    
    227     public function wpVGWortaddProfileData( $user ) {
    228        
    229         global $wpdb;
    230 
    231         if( user_can( $user->ID , 'edit_posts' ) ) {
    232 
    233             ?>
    234             <h3 id="vgwortanchor">VG Wort</h3>
    235             <table class="form-table">
    236             <tr>
    237             <th><label for="vgwort">bisher eingebunden Wortmarken: <?php echo $wpdb->get_var($wpdb->prepare("SELECT count(P.ID) as count FROM wp_postmeta PM INNER JOIN wp_posts P ON P.ID = PM.post_id WHERE PM.meta_key = 'wp_vgwortmarke' AND PM.meta_value != '' AND P.post_author = '%d'",$user->ID)); ?></label></th>
    238             <td>
    239                
    240             <?php
    241            
    242             $currentFilter = get_user_meta( $user->ID, 'wp-wort-filter', true);
    243            
    244             if(empty($currentFilter) OR $currentFilter == 'all'){
    245                 $currentFilter = "all";
    246                 $results = $wpdb->get_results($wpdb->prepare("SELECT * , CHAR_LENGTH(`post_content`) as charlength , post_type FROM ".$wpdb->posts." WHERE post_status = 'publish' AND post_type NOT IN ('attachment','nav_menu_item','revison') AND post_author = '%d' HAVING charlength > '%d'",$user->ID,REQUIREDCHARS));
    247             }else{
    248                 $results = $wpdb->get_results($wpdb->prepare("SELECT * , CHAR_LENGTH(`post_content`) as charlength , post_type FROM ".$wpdb->posts." WHERE post_status = 'publish' AND post_type = %s AND post_author = '%d' HAVING charlength > '%d'",$currentFilter,$user->ID,REQUIREDCHARS));
    249             }
    250 
    251             $postTypes = $wpdb->get_results("SELECT post_type  FROM ".$wpdb->posts." WHERE post_type NOT IN ('attachment','nav_menu_item','revison') group by post_type  ORDER BY FIELD(post_type,'post','page') DESC ");
    252        
    253             echo 'Filtern nach Posttype:<select name="wpvgwortcurrentposttype" size="1"><option value="all">Alle</option>';
    254        
    255             foreach($postTypes as $postType) {
    256            
    257                 if($postType->post_type != $currentFilter){
    258                     echo '<option value="'.$postType->post_type.'">'.$postType->post_type.'</option>';
    259                 }else{
    260                     echo '<option selected="selected" value="'.$postType->post_type.'">'.$postType->post_type.'</option>';
    261                 }
    262            
    263                
    264             }
    265             echo '</select><input type="submit" name="Sender" value="filtern" />';
    266                
    267             if(!empty($results)) {
    268                 ?>
    269                     <ul>
    270                         <li><h4>Mögliche Beiträge</h4></li>
    271                 <?php
    272            
    273                 $clearContentCount = 0;
    274                
    275                 foreach($results as $result){
    276 
    277                     $vgwort = get_post_meta( $result->ID , VGWORTMETA , true );
    278                     if(empty($vgwort)){
    279                
    280                         // Just Text nothing more :)
    281                         $clearContentCount = $this->getCharCount( $result->post_title.$result->post_content );
    282                         if($clearContentCount > REQUIREDCHARS){         
    283                             echo '<li><a href="'.get_admin_url().'post.php?post='.$result->ID.'&action=edit" title="jetzt VG Wort einfügen">'.$result->post_title.' ('.$clearContentCount.' Zeichen) ('.$result->post_type.')</a></li>';
    284                         }
    285                     }
    286                 }
    287             }
    288         }
    289         ?>
    290             </ul>
    291         <span class="description">Diesen Beiträge sollten VG Wortmarken hinzugefügt werden</span>
    292         </td>
    293         </tr>
    294         </table>
    295        
    296 <?php }
    297 
    298     /**
    299     *
    300     * Save the current FilterOption
    301     * @param: int $user_id
    302     * @return int
    303     *
    304     */
    305 
    306     public function wpVGWortSaveExtraUserProfileFields( $user_id ) {
    307  
    308         if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    309          
    310         update_user_meta( $user_id, 'wp-wort-filter', $_POST['wpvgwortcurrentposttype'] );
    311        
    312     }
    313 
    314 
    315 
    316     /**
    317     *
    318     * Calculate the Chars of the delivered content
    319     * @param: string $content
    320     * @return int
    321     *
    322     */
    323 
    324     private function getCharCount( $content ) {
    325         return mb_strlen(preg_replace("/\\015\\012|\\015|\\012| {2,}|\[[a-zA-Z0-9\_=\"\'\. \/]*\]/", "", strip_tags(html_entity_decode($content ))));
    326     }
    327 
    328     /**
    329     *
    330     * append the Value of VGWORTMETA on the end of content
    331     * just insert VGWORTMETA on page.php and single.php
    332     * @param: string $content
    333     * @return string $content
    334     *
    335     */
    336    
    337     public function wpVGWortFrontendDisplay( $content ) {
    338 
    339         global $post;
    340    
    341         $vgwort = get_post_meta( $post->ID , VGWORTMETA , true );
    342        
    343         if(is_single() OR is_page()){
    344             if(!empty( $vgwort )){
    345                 $content .= $vgwort;
    346             }
    347         }
    348    
    349         return $content;
    350     }
    351 
    352     /**
    353     *
    354     * Adds a box to the main column on the Post and Page edit screens
    355     * @param: none
    356     *
    357     */
    358    
    359     public function wpVGWortAddCustomMeta() {
    360         $currentPostType = get_post_type();
    361         $allowedTypes = get_option( 'wp_cpt',array('post','page'));
    362         if(in_array($currentPostType,$allowedTypes)){
    363             add_meta_box( 'VGWortCustomMeta', __( 'VG Wort', 'VG Wort' ), array( &$this , 'createVGWortCustomMeta' ), $currentPostType , 'advanced','high' );
    364         }
    365     }
    366    
    367     /**
    368     *
    369     * displays the metabox in Posts and pages
    370     * @param: object $post
    371     *
    372     */
    373     public function createVGWortCustomMeta( $post ) {
    374 
    375         // Use nonce for verification
    376         wp_nonce_field( plugin_basename(__FILE__) , PLUGINNAME );
    377 
    378         // The actual fields for data entry
    379         $marke = get_post_meta( $post->ID , VGWORTMETA , true );
    380         if(!empty($marke))
    381         {
    382             echo '<strong>Vorhandene Zählmarke</strong>: '.htmlspecialchars($marke);
    383             echo '<input type="hidden" name="markein" value="1" />';
    384         }
    385        
    386         echo '<input type="input" size="150" name="wp_vgwortmarke" value="" />';
    387         echo '<input type="submit" name="Sender" value="speichern" /><br />';
    388         echo '<a href="http://www.vgwort.de/" target="_blank">VG WORT Marke erstellen</a>';
    389 
    390     }
    391 
    392     /**
    393     *
    394     * save the values of VGWort Meta
    395     * @param: int $post_id
    396     *
    397     */
    398    
    399     function wpVGWortSavePost( $post_id ) {
    400 
    401        
    402         // Erweiterung bei Einstellungen
    403         $allowedTypes = get_option( 'wp_cpt',array('post','page'));
    404    
    405         // AutoSave Methode
    406         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
    407             return;
    408         }
    409        
    410         // verify this came from the our screen and with proper authorization,
    411         // because save_post can be triggered at other times
    412 
    413         if ( !wp_verify_nonce( $_POST[PLUGINNAME], plugin_basename( __FILE__ ) ) )
    414         return;
    415 
    416         // Check permissions
    417 
    418         if ( in_array($_POST['post_type'],$allowedTypes)) {
    419             if ( !current_user_can( 'edit_page', $post_id ) )
    420                 return;
    421         }
    422         else{
    423             return;
    424         }
    425 
    426         // vars übergeben
    427        
    428         if(!isset($_POST['markein'])){
    429             if(!empty($_POST['wp_vgwortmarke'])){
    430                 update_post_meta($post_id , VGWORTMETA , stripslashes($_POST['wp_vgwortmarke']) );
    431             }else{
    432                 delete_post_meta($post_id , VGWORTMETA , stripslashes($_POST['wp_vgwortmarke']));
    433             }
    434         } else {
    435             if(!empty($_POST['wp_vgwortmarke'])){
    436                 update_post_meta($post_id , VGWORTMETA , stripslashes($_POST['wp_vgwortmarke']) );
    437             }
    438         }
    439     }
    440 }   
    441 
    442 ?>
     32// TODO: replace PluginName with the name of the plugin defined in `class-plugin-name.php`
     33WP_VGWORT::get_instance();
Note: See TracChangeset for help on using the changeset viewer.