[svn-inject] Installing original source of nanobloggerplugins upstream/0.1.3
authorgregor herrmann <gregoa@debian.org>
Sat, 25 Feb 2006 18:12:14 +0000 (18:12 -0000)
committergregor herrmann <gregoa@debian.org>
Sat, 25 Feb 2006 18:12:14 +0000 (18:12 -0000)
README [new file with mode: 0644]
calendar_prev.sh [new file with mode: 0644]
weblog_visits.sh [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..eaffa78
--- /dev/null
+++ b/README
@@ -0,0 +1,38 @@
+nanoblogger_plugins - additional plugins for nanoblogger
+========================================================
+
+Author: Gregor Herrmann <gregor+debian@comodo.priv.at>
+Licence: GPL
+
+1) weblog_visits.sh
+-------------------
+Function:
+Counts hits on blog from apache access logs.
+
+Configuration:
+Set ACCESS_LOG in your configuration, e.g.
+       ACCESS_LOG="/var/log/apache-ssl/vhosts/comodo-access.log*"
+Attention: The user running nb most have reading permissions on the file(s),
+e.g. be member of the adm group
+
+Usage:
+Put $TOTAL_VISITS into your templates, e.g.
+       <div class="calendar">
+       Total visits (last year): $TOTAL_VISITS
+       </div>
+
+
+2) calendar_prev.sh
+-------------------
+Function:
+Creates a nice calendar table but for last month.
+
+Configuration:
+Set CAL_ARGS_PREV in your config, e.g.
+       CAL_ARGS_PREV="-m `date --date "$(date +%Y-%m-15) 1 months ago" +'%B %Y'`"   
+
+Usage:
+Put $NB_Calendar_prev into your templates, e.g.
+       <div class="side">
+       $NB_Calendar_prev
+       </div>
diff --git a/calendar_prev.sh b/calendar_prev.sh
new file mode 100644 (file)
index 0000000..0f32225
--- /dev/null
@@ -0,0 +1,70 @@
+# NanoBlogger Calendar Plugin, requires the cal command.
+# converts the output of cal to an HTML Table and creates links of entries
+# used for last month's calendar table!
+#
+# sample code for template - based off default stylesheet
+#
+# <div class="calendar">
+# $NB_Calendar_prev
+# </div>
+
+PLUGIN_OUTFILE="$BLOG_DIR/$PARTS_DIR/cal_prev.$NB_FILETYPE"
+: ${CAL_CMD:=cal}
+
+if $CAL_CMD > "$PLUGIN_OUTFILE" 2>&1 ; then
+nb_msg "generating calendar (last month) ..."
+[ -z "$DATE_LOCALE" ] || CALENDAR=`LC_ALL="$DATE_LOCALE" $CAL_CMD $CAL_ARGS_PREV`
+[ ! -z "$CALENDAR" ] || CALENDAR=`$CAL_CMD $CAL_ARGS_PREV`
+CAL_HEAD=`echo "$CALENDAR" |sed -e '/^[ ]*/ s///g; 1q'`
+WEEK_DAYS=`echo "$CALENDAR" |sed -n 2p`
+DAYS=`echo "$CALENDAR" |sed 1,2d`
+NUM_DAY_LINES=`echo "$DAYS" |grep -n "[0-9]" |cut -c1`
+
+curr_month=`date +%Y.%m --date "$(date +%Y-%m-15) 1 months ago"`
+query_db all
+set_baseurl "./"
+MONTH_LIST=`echo "$DB_RESULTS" |sort $SORT_ARGS |grep ''$curr_month''`
+
+echo '<table border="0" cellspacing="4" cellpadding="0" summary="Calendar with links to days with entries">' > "$PLUGIN_OUTFILE"
+echo '<caption class="calendarhead">'$CAL_HEAD'</caption>' >> "$PLUGIN_OUTFILE"
+echo '<tr>' >> "$PLUGIN_OUTFILE"
+for wd in $WEEK_DAYS ; do
+       echo '<th style="text-align: center;"><span class="calendarday">'$wd'</span></th>' >> "$PLUGIN_OUTFILE"
+done
+echo '</tr>' >> "$PLUGIN_OUTFILE"
+for line in $NUM_DAY_LINES ; do
+       DN_LINES=`echo "$DAYS" |sed -n "$line"p`
+       [ -n "$DN_LINES" ] || continue
+       echo '<tr>' >> "$PLUGIN_OUTFILE"
+       echo "$DN_LINES" | sed -e '/  $/ Q; /  [ \t]/ s//<td style="text-align: center;"><\/td>\ /g; /[0-9]/ s///g' >> "$PLUGIN_OUTFILE"
+       for dn in $DN_LINES ; do
+               set_link=0
+               MONTH_LINE=`echo "$MONTH_LIST" |grep $dn`
+               for entry in $MONTH_LINE ; do
+                       entry_year=`echo $entry |cut -c1-4`
+                       entry_month=`echo $entry |cut -c6-7`
+                       entry_day=`echo $entry |cut -c9-10 |sed -e '/^0/ s///g'`
+                       curr_month=`date +%m --date "$(date +%Y-%m-15) 1 months ago"`
+                       curr_year=`date +%Y --date "$(date +%Y-%m-15) 1 months ago"`
+               if [ "$curr_year$curr_month$dn" = "$entry_year$entry_month$entry_day" ] ; then
+                       set_link=1
+                       NB_EntryID=`set_entryid $entry`
+                       set_entrylink "$entry" altlink
+                       dn='<a href="'${ARCHIVES_PATH}$NB_EntryPermalink'">'$dn'</a>'
+                       echo '<td style="text-align: center;"><span class="calendar">'$dn'</span></td>' >> "$PLUGIN_OUTFILE"
+               fi
+               done
+               if [ "$set_link" != 1 ] ; then
+                       echo '<td style="text-align: center;"><span class="calendar">'$dn'</span></td>' >> "$PLUGIN_OUTFILE"
+               fi
+       done
+       echo "$DN_LINES" | sed -e '/^  / Q; /  [ \t]/ s//<td style="text-align: center;"><\/td>\ /g; /[0-9]/ s///g' >> "$PLUGIN_OUTFILE"
+       echo '</tr>' >> "$PLUGIN_OUTFILE"
+done
+echo '</table>' >> "$PLUGIN_OUTFILE"
+
+# The calendar's place-holder for the templates
+NB_Calendar_prev=$(< "$PLUGIN_OUTFILE")
+CALENDAR=
+fi
+
diff --git a/weblog_visits.sh b/weblog_visits.sh
new file mode 100644 (file)
index 0000000..24b2e63
--- /dev/null
@@ -0,0 +1,17 @@
+# NanoBlogger Total Vists Plugin
+# gets hits on /blog from apache access logs
+#
+# sample code for templates - based on default stylesheet
+#
+# <div class="side">
+# Total visits (last year): $TOTAL_VISITS
+# </div>
+
+nb_msg "generating last visits ..."
+
+TOTAL_VISITS=0
+
+for log in $ACCESS_LOG; do 
+       TOTAL_VISITS=$(($TOTAL_VISITS + $(zgrep -c -h "GET /blog/ " $log)))
+done
+