Changeset 17249

Show
Ignore:
Timestamp:
08/21/07 21:08:59 (11 months ago)
Author:
wuerzblog
Message:

Change repo-structure

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • a-year-before/trunk/ayb_posts.php

    r9826 r17249  
    22/* 
    33Plugin Name: A Year Before 
    4 Version: 0.5.3 
     4Version: 0.6beta4 
    55Plugin URI: http://wuerzblog.de/2006/12/27/wordpress-plugin-a-year-before/ 
    66Author: Ralf Thees 
     
    99*/ 
    1010 
    11 function ayb_posts( $para='') { 
    12   global $wpdb; 
    13   $dday=0; 
    14   $dmonth=0; 
    15   $dyear=0; 
    16   $before="<li>"; 
    17   $after="</li>"; 
    18   $showdate=1; 
    19   $dateformat="d.m.y"; 
    20   $notfound="Keine Beitrag an diesem Tag."; 
    21   $parameter = explode('&', $para); 
    22   $i = 0; 
    23   while ($i < count($parameter)) { 
    24    $b = split('=', $parameter[$i]); 
    25    switch ($b[0]) { 
    26       case "day": 
    27         $dday=urldecode($b[1]); 
    28         break; 
    29       case "month": 
    30         $dmonth=urldecode($b[1]); 
    31         break; 
    32       case "year": 
    33         $dyear=urldecode($b[1]); 
    34         break; 
    35       case "before": 
    36         $before=urldecode($b[1]); 
    37         break; 
    38       case "after": 
    39         $after=urldecode($b[1]); 
    40         break; 
    41       case "notfound": 
    42         $notfound=htmlspecialchars(urldecode($b[1])); 
    43         break; 
    44       case "showdate": 
    45         $showdate=urldecode($b[1]); 
    46         break; 
    47       case "dateformat": 
    48         $dateformat=urldecode($b[1]); 
    49         break; 
    50    } 
    51  
    52    $i++; 
    53 
    54    if ($dday==0 && $dmonth==0 && $dyear==0) { 
    55       $dyear=1; 
    56   } 
    57  
    58   $datum  = getdate(mktime(0, 0, 0, date("m")-$dmonth, date("d")-$dday, date("Y")-$dyear)); 
     11$ayb_posts_domain = 'ayb_posts'; 
     12$ayb_install_dir=basename(dirname(__FILE__)); 
     13load_plugin_textdomain($ayb_posts_domain, "wp-content/plugins/$ayb_install_dir"); 
    5914 
    6015 
    61    $q="SELECT ID, post_title, post_date_gmt FROM $wpdb->posts WHERE post_status='publish' AND post_password='' AND YEAR(post_date_gmt)=".$datum['year']." AND MONTH(post_date_gmt)=".$datum['mon']." AND DAYOFMONTH(post_date_gmt)=".$datum['mday']." ORDER BY post_date_gmt"; 
    62   $result = $wpdb->get_results($q, OBJECT); 
    63   if ($showdate) { 
    64       $pdate='<span class="ayb_date">'.date($dateformat,mktime(0, 0, 0, date("m")-$dmonth  , date("d")-$dday, date("Y")-$dyear))."</span> "; 
    65     } else { 
    66       $pdate=''; 
     16 
     17function ayb_posts_init() { 
     18      if ( !function_exists('register_sidebar_widget') ) 
     19      return; 
     20       
     21      function ayb_posts($para=Array()) { 
     22            if (preg_match("/sidebar/i",$para["name"])) $ayb_posts_is_widget=true; 
     23 
     24            global $wpdb, $ayb_posts_domain; 
     25             
     26             
     27            if ($ayb_posts_is_widget) extract($para); 
     28 
     29            $options = get_option("ayb_posts"); 
     30                  if ( !is_array($options) ) { 
     31                        $options = array('title'=>__('A year ago',$ayb_posts_domain)); 
     32                  } 
     33            if ($ayb_posts_is_widget) { 
     34                  $para=""; 
     35                  foreach ($options as $key => $val) { 
     36                        $para.="$key=$val&"; 
     37            } 
     38            } 
     39 
     40      $title=$options["title"]; 
     41      $dday=0; 
     42      $dmonth=0; 
     43      $dyear=0; 
     44      $before="<li>"; 
     45      $after="</li>"; 
     46      $showdate=1; 
     47      $dateformat=__('Y-m-d',$ayb_posts_domain); 
     48      $notfound=__("No articles on this date.",$ayb_posts_domain); 
     49      $parameter = explode('&', $para); 
     50      $i = 0; 
     51      while ($i < count($parameter)) { 
     52      $b = split('=', $parameter[$i]); 
     53      switch ($b[0]) { 
     54            case "day": 
     55                  $dday=urldecode($b[1]); 
     56                  break; 
     57            case "month": 
     58                  $dmonth=urldecode($b[1]); 
     59                  break; 
     60            case "year": 
     61                  $dyear=urldecode($b[1]); 
     62                  break; 
     63            case "before": 
     64                  $before=urldecode($b[1]); 
     65                  break; 
     66            case "after": 
     67                  $after=urldecode($b[1]); 
     68                  break; 
     69            case "notfound": 
     70                  $notfound=htmlspecialchars(urldecode($b[1])); 
     71                  break; 
     72            case "showdate": 
     73                  $showdate=urldecode($b[1]); 
     74                  break; 
     75            case "dateformat": 
     76                  $dateformat=urldecode($b[1]); 
     77                  break; 
     78      } 
     79 
     80      $i++; 
     81      } 
     82      if ($dday==0 && $dmonth==0 && $dyear==0) { 
     83            $dyear=1; 
     84      } 
     85 
     86      $datum  = getdate(mktime(0, 0, 0, date("m")-$dmonth, date("d")-$dday, date("Y")-$dyear)); 
     87 
     88      $q="SELECT ID, post_title, post_date_gmt FROM $wpdb->posts WHERE post_status='publish' AND post_password='' AND YEAR(post_date_gmt)=".$datum['year']." AND MONTH(post_date_gmt)=".$datum['mon']." AND DAYOFMONTH(post_date_gmt)=".$datum['mday']." ORDER BY post_date_gmt"; 
     89      $result = $wpdb->get_results($q, OBJECT); 
     90 
     91      //Ausgabe für's Widget 
     92      if ($ayb_posts_is_widget) { 
     93      echo $before_widget; 
     94    echo $before_title . $title . $after_title."<ul>"; 
    6795    } 
    68   if ($result) { 
    69     foreach ($result as $post) 
    70       { 
    71             $plink = get_permalink($post->ID); 
    72             $ptitle= $post->post_title; 
    73         echo $before.$pdate.'<a href="'.$plink.'" class="ayb_link">'.$ptitle.'</a>'.$after."\r"; 
    74       } 
    75     } else { 
    76         echo $before.$pdate.'<span class="ayb_notfound">'.$notfound.'</span>'.$after."\r"; 
    77     } 
     96 
     97      if ($showdate) { 
     98            $pdate='<span class="ayb_date">'.date($dateformat,mktime(0, 0, 0, date("m")-$dmonth  , date("d")-$dday, date("Y")-$dyear))."</span> "; 
     99            } else { 
     100            $pdate=''; 
     101            } 
     102      if ($result) { 
     103            foreach ($result as $post) 
     104                  { 
     105                        $plink = get_permalink($post->ID); 
     106                        $ptitle= $post->post_title; 
     107                  echo $before.$pdate.'<a href="'.$plink.'" class="ayb_link">'.$ptitle.'</a></span>'.$after."\r"; 
     108                  } 
     109            } else { 
     110 
     111                  echo $before.$pdate.'<span class="ayb_notfound">'.$notfound.'</span>'.$after."\r"; 
     112            } 
     113      if($ayb_posts_is_widget) { 
     114            echo "</ul>".$after_widget; 
     115      } 
     116      } 
     117 
     118      function ayb_posts_widget_control() { 
     119            global $ayb_posts_domain; 
     120            $options = get_option("ayb_posts"); 
     121            if ( !is_array($options) ) { 
     122                  $options = array('title'=>__('A year ago',$ayb_posts_domain), 'day'=>0, 'month'=>0, 'year'=>1, 'showdate'=>1, 'dateformat'=>__('Y-m-d',$ayb_posts_domain), 'notfound'=>__('No articles on this date.',$ayb_posts_domain)); 
     123 
     124            } 
     125            $title=$options['title']; 
     126            $day=$options['day']; 
     127            $month=$options['month']; 
     128            $year=$options['year']; 
     129            $showdate=$options["showdate"]; 
     130            $dateformat=$options["dateformat"]; 
     131            $notfound=$options["notfound"]; 
     132 
     133            if ( $_POST['ayb_posts_submit'] ) { 
     134 
     135                  $options['title'] = strip_tags(stripslashes($_POST['ayb_posts_title'])); 
     136                  $options["day"]=strip_tags(stripslashes($_POST['ayb_posts_day'])); 
     137                  $options["month"]=strip_tags(stripslashes($_POST['ayb_posts_month'])); 
     138                  $options["year"]=strip_tags(stripslashes($_POST['ayb_posts_year'])); 
     139                  $options["showdate"]=strip_tags(stripslashes($_POST['ayb_posts_showdate'])); 
     140                  $options["dateformat"]=strip_tags(stripslashes($_POST['ayb_posts_dateformat'])); 
     141                  $options["notfound"]=strip_tags(stripslashes($_POST['ayb_posts_notfound'])); 
     142                  update_option('ayb_posts', $options); 
     143            } 
     144 
     145            $title = htmlspecialchars($options['title'], ENT_QUOTES); 
     146 
     147            echo '<p style="text-align:right;"><label for="ayb_posts_title">' . __('Title:',$ayb_posts_domain) . ' <input style="width: 200px;" id="ayb_posts_title" name="ayb_posts_title" type="text" value="'.$title.'" /></label></p>'; 
     148            echo '<p style="text-align:right;"><label for="ayb_posts_day">' . __('Days before:',$ayb_posts_domain) . ' <input style="width: 30px;" id="ayb_posts_day" name="ayb_posts_day" type="text" value="'.$day.'" /></label></p>'; 
     149            echo '<p style="text-align:right;"><label for="ayb_posts_month">' . __('Months before:',$ayb_posts_domain) . ' <input style="width: 30px;" id="ayb_posts_month" name="ayb_posts_month" type="text" value="'.$month.'" /></label></p>'; 
     150            echo '<p style="text-align:right;"><label for="ayb_posts_year">' . __('Years before:',$ayb_posts_domain) . ' <input style="width: 30px;" id="ayb_posts_year" name="ayb_posts_year" type="text" value="'.$year.'" /></label></p>'; 
     151            echo '<p style="text-align:right;"><label for="ayb_posts_showdate">' . __('Show date:',$ayb_posts_domain) . ' <input style="width: 15px;" id="ayb_posts_showdate" name="ayb_posts_showdate" type="checkbox" value="1"'.(($showdate==0)?'':'checked').' /></label></p>'; 
     152            echo '<p style="text-align:right;"><label for="ayb_posts_dateformat">' . __('Dateformat:',$ayb_posts_domain) . ' <input style="width: 45px;" id="ayb_posts_dateformat" name="ayb_posts_dateformat" type="text" value="'.$dateformat.'" /></label></p>'; 
     153            echo '<p style="text-align:right;"><label for="ayb_posts_notfound">' . __('Text, if no article found:','ayb_posts') . ' <input style="width: 200px;" id="ayb_posts_notfound" name="ayb_posts_notfound" type="text" value="'.$notfound.'" /></label></p>'; 
     154            echo '<p style="text-align:right;"><input type="submit" id="ayb_posts_submit" name="ayb_posts_submit" value="'. __('Update',$ayb_posts_domain) . '" /></p>'; 
     155 
     156      } 
     157 
     158      register_widget_control("A Year Before","ayb_posts_widget_control",200,320); 
     159      register_sidebar_widget('A Year Before','ayb_posts'); 
    78160} 
    79  
     161// 
     162add_action('widgets_init', 'ayb_posts_init'); 
    80163?>