2022-02-13 17:58:25 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# file: gsl__post_checkers
|
|
|
|
# Folder: /var/lib/gsl/scripts
|
|
|
|
# By echolib
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# From: gsl__loop_posts | Check Post from modules
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_all_checkers() {
|
|
|
|
clear
|
|
|
|
unset gsl_check_done
|
|
|
|
|
2022-02-14 02:57:58 +01:00
|
|
|
echo -n ": Searching for needed Headers..."
|
|
|
|
gsl__post_check_needed_headers
|
2022-02-13 17:58:25 +01:00
|
|
|
echo -ne "\r\033[2K: Searching for #1..."
|
|
|
|
gsl__post_check_h1
|
2022-02-14 18:54:07 +01:00
|
|
|
echo -ne "\r\033[2K: Searching for Paragraphs"
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__post_check_paragraphs
|
|
|
|
echo -ne "\r\033[2K: Searching for Content MARKERS..."
|
|
|
|
gsl__post_check_markers
|
2022-02-14 18:54:07 +01:00
|
|
|
echo -ne "\r\033[2K: Searching for BLOCKQUOTEs..."
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__post_check_blockquote
|
2022-02-14 18:54:07 +01:00
|
|
|
echo -ne "\r\033[2K: Searching for ABBRs..."
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__post_check_abbr
|
2022-02-14 18:54:07 +01:00
|
|
|
echo -ne "\r\033[2K: Searching for LINKs.."
|
|
|
|
gsl__post_check_links
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
echo
|
2022-02-14 02:57:58 +01:00
|
|
|
#echo -ne "\r\033[2K"
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
# End of checkers : show logs for war and err
|
|
|
|
[[ "$gsl_checker_war" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl log -s -w
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
[[ "$gsl_checker_err" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl log -s -e
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
2022-02-14 02:57:58 +01:00
|
|
|
# Check Post for MISSING & VALID Content HEADERS
|
2022-02-13 17:58:25 +01:00
|
|
|
#=======================================================================
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__post_check_needed_headers() {
|
|
|
|
#-----------------------------------------------------------------------
|
2022-02-13 17:58:25 +01:00
|
|
|
# Check if Missing NEEDED HEADERS
|
2022-02-14 02:57:58 +01:00
|
|
|
#-----------------------------------------------------------------------
|
2022-02-13 17:58:25 +01:00
|
|
|
# Title
|
|
|
|
gsl_header_title=`gsl__get_header "$gsl_marker_title" "$gsl_post"`
|
|
|
|
! [[ "$gsl_header_title" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Title" \
|
|
|
|
"Post" \
|
|
|
|
"Missing" \
|
|
|
|
"${PWD}/$gsl_post" \
|
|
|
|
&& gsl_checker_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
# Slug
|
|
|
|
gsl_header_slug=`gsl__get_header "$gsl_marker_slug" "$gsl_post"`
|
|
|
|
! [[ "$gsl_header_slug" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Slug" \
|
|
|
|
"Post" \
|
|
|
|
"Missing" \
|
|
|
|
"${PWD}/$gsl_post" \
|
|
|
|
&& gsl_checker_err=true \
|
|
|
|
&& gsl_slug_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
# Author
|
|
|
|
gsl_header_author=`gsl__get_header "$gsl_marker_author" "$gsl_post"`
|
|
|
|
! [[ "$gsl_header_author" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Author" \
|
|
|
|
"Post" \
|
|
|
|
"Missing" \
|
|
|
|
"${PWD}/$gsl_post" \
|
|
|
|
&& gsl_checker_err=true \
|
|
|
|
&& gsl_author_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
# Date
|
|
|
|
gsl_header_date=`gsl__get_header "$gsl_marker_date" "$gsl_post"`
|
|
|
|
! [[ "$gsl_header_date" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Date" \
|
|
|
|
"Post" \
|
|
|
|
"Missing" \
|
|
|
|
"${PWD}/$gsl_post" \
|
|
|
|
&& gsl_checker_err=true \
|
|
|
|
&& gsl_date_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
# Description
|
|
|
|
gsl_header_info=`gsl__get_header "$gsl_marker_info" "$gsl_post"`
|
|
|
|
! [[ "$gsl_header_info" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Infos" \
|
|
|
|
"Post" \
|
|
|
|
"Missing" \
|
|
|
|
"${PWD}/$gsl_post" \
|
|
|
|
&& gsl_checker_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
|
2022-02-14 02:57:58 +01:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Check for VALID Content HEADERS
|
|
|
|
#-----------------------------------------------------------------------
|
2022-02-13 17:58:25 +01:00
|
|
|
# Author registred
|
2022-02-14 02:57:58 +01:00
|
|
|
if ! [[ "$gsl_author_err" ]] && \
|
|
|
|
! [[ `grep "$gsl_header_author" "$gsl_file_auth_ndd"` ]];then
|
|
|
|
|
|
|
|
gsl__logs_print \
|
2022-02-13 17:58:25 +01:00
|
|
|
"$gsl_log_e" \
|
|
|
|
"Author" \
|
|
|
|
"Post" \
|
|
|
|
"$gsl_header_author not registred for domain $gsl_find_domain" \
|
|
|
|
"${PWD}/$gsl_post"
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl_checker_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Date Format YYYY-MM-DD
|
2022-02-14 02:57:58 +01:00
|
|
|
if ! [[ "$gsl_date_err" ]] && \
|
|
|
|
! [[ "$gsl_header_date" =~ $gsl_test_date ]];then
|
|
|
|
|
|
|
|
gsl__logs_print \
|
2022-02-13 17:58:25 +01:00
|
|
|
"$gsl_log_e" \
|
|
|
|
"Date" \
|
|
|
|
"Post" \
|
|
|
|
"$gsl_header_date not YYYY-MM-DD" \
|
|
|
|
"${PWD}/$gsl_post"
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl_checker_err=true
|
2022-02-13 17:58:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Slug format title-post
|
2022-02-14 02:57:58 +01:00
|
|
|
if ! [[ "$gsl_slug_err" ]];then
|
|
|
|
gsl_header_slug_test=${gsl_header_slug// /-}
|
|
|
|
|
|
|
|
if ! [[ "$gsl_header_slug" == "$gsl_header_slug_test" ]];then
|
|
|
|
gsl_new_header_slug="$gsl_marker_slug$gsl_header_slug_test"
|
|
|
|
sed -i \
|
|
|
|
"s|$gsl_marker_slug$gsl_header_slug|$gsl_new_header_slug" \
|
|
|
|
"$gsl_post" && \
|
|
|
|
gsl__logs_print \
|
2022-02-13 17:58:25 +01:00
|
|
|
"$gsl_log_w" \
|
|
|
|
"Slug" \
|
|
|
|
"Post" \
|
|
|
|
"Changed: $gsl_header_slug_test" \
|
|
|
|
"${PWD}/$gsl_post"
|
2022-02-14 02:57:58 +01:00
|
|
|
|
|
|
|
gsl_header_slug=$gsl_header_slug_test
|
|
|
|
gsl_checker_war=true
|
|
|
|
fi
|
2022-02-13 17:58:25 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check Post for begining content
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_check_h1() {
|
|
|
|
gsl_post_begin=`
|
2022-02-14 02:57:58 +01:00
|
|
|
grep -n "#1" $gsl_post \
|
|
|
|
| head -1 \
|
|
|
|
| awk -F: '{print $1}'`
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
if ! [[ "$gsl_post_begin" ]];then
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Begin" \
|
|
|
|
"Post" \
|
|
|
|
"Missing content: #1 TITLE" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check for paragraphs ( and )
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_check_paragraphs() {
|
|
|
|
gsl_post_p_open_nbr=`
|
|
|
|
awk -v line="$gsl_post_begin" \
|
|
|
|
-v op="$gsl_mo_p" \
|
|
|
|
'NR > line && $1 == op' \
|
|
|
|
"$gsl_post" \
|
|
|
|
| wc -l`
|
|
|
|
|
|
|
|
gsl_post_p_close_nbr=`
|
|
|
|
awk -v line="$gsl_post_begin" \
|
|
|
|
-v cp="$gsl_mc_p" \
|
|
|
|
'NR > line && $1 == cp' \
|
|
|
|
"$gsl_post" \
|
|
|
|
| wc -l`
|
|
|
|
|
|
|
|
if (( "$gsl_post_p_open_nbr" == 0 ));then
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Paragraph" \
|
|
|
|
"Post" \
|
|
|
|
"Missing content: ( and ) at begining lines" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
gsl_checker_err=true
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( "$gsl_post_p_open_nbr" == "$gsl_post_p_close_nbr" ));then
|
|
|
|
gsl_post_stat_p="$gsl_post_p_open_nbr"
|
|
|
|
else
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Paragraph" \
|
|
|
|
"Post" \
|
|
|
|
"Mismatch: (=$gsl_post_p_open_nbr ; )=$gsl_post_p_close_nbr" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check and count MARKERS content (Strong, links...)
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_check_markers() {
|
|
|
|
gsl_markers_nbr=$(( ${#gsl_o_markers[@]} - 1 ))
|
|
|
|
gsl_post_stat_m=(0 0 0 0 0 0)
|
|
|
|
|
|
|
|
while read -r "gsl_post_line"
|
|
|
|
do
|
|
|
|
gsl_line_nbr=`awk -F":" '{print $1}' <<< $gsl_post_line`
|
|
|
|
|
|
|
|
for gsl_i in `seq 0 $gsl_markers_nbr`
|
|
|
|
do
|
|
|
|
if [[ "$gsl_post_line" =~ ${gsl_o_markers[gsl_i]} ]];then
|
|
|
|
# Open Marker by Type
|
|
|
|
gsl_o=`
|
|
|
|
grep -o "${gsl_o_markers[gsl_i]}" \
|
|
|
|
<<< $gsl_post_line \
|
|
|
|
| wc -l`
|
|
|
|
# Close Marker by Type
|
|
|
|
gsl_c=`
|
|
|
|
grep -o "${gsl_c_markers[gsl_i]}" \
|
|
|
|
<<< $gsl_post_line \
|
|
|
|
| wc -l`
|
|
|
|
|
|
|
|
# Strong Vs Bold | 2= **_ / 3= *_ in array
|
|
|
|
if (( $gsl_i == 2 ));then
|
|
|
|
gsl_oS=$gsl_o # Open Strong marker nbr
|
|
|
|
gsl_cS=$gsl_c # Close Strong marker nbr
|
|
|
|
|
|
|
|
elif (( $gsl_i == 3 ));then
|
|
|
|
# Count difference from Strong
|
|
|
|
if (( $gsl_oS ));then
|
|
|
|
gsl_o=$(( $gsl_o - $gsl_oS ))
|
|
|
|
unset gsl_oS
|
|
|
|
fi
|
|
|
|
if (( $gsl_cS ));then
|
|
|
|
gsl_c=$(( $gsl_c - $gsl_cS ))
|
|
|
|
unset gsl_cS
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Compare
|
|
|
|
if ! (( $gsl_o == $gsl_c ));then
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Post" \
|
|
|
|
"${gsl_i_markers[gsl_i]}" \
|
|
|
|
"Line $gsl_line_nbr: Mismatch ${gsl_u_markers[gsl_i]}" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
else
|
|
|
|
gsl_post_stat_m[gsl_i]=$(( gsl_post_stat_m[gsl_i] + gsl_o ))
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done < <(awk -v line="$gsl_post_begin" \
|
|
|
|
'NR >= line {print NR":",$0}' \
|
|
|
|
"$gsl_post")
|
|
|
|
|
|
|
|
# Show Counts in logs
|
|
|
|
for gsl_i in `seq 0 $gsl_markers_nbr`
|
|
|
|
do
|
|
|
|
if (( ${gsl_post_stat_m[gsl_i]} >= 1 ));then
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Post" \
|
|
|
|
"${gsl_i_markers[gsl_i]}" \
|
|
|
|
"NBR=${gsl_post_stat_m[gsl_i]} > ${gsl_u_markers[gsl_i]}" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check for blockquotes: ---
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_check_blockquote() {
|
|
|
|
gsl_post_blockquotes_nbr=`
|
|
|
|
awk -v line="$gsl_post_begin" \
|
|
|
|
-v bq="$gsl_mark_blockquote" \
|
|
|
|
'NR > line && $1 == bq' \
|
|
|
|
"$gsl_post" \
|
|
|
|
| wc -l`
|
|
|
|
|
|
|
|
gsl_post_blockquotes_nbr_r=$(( $gsl_post_blockquotes_nbr % 2 ))
|
|
|
|
|
|
|
|
if [[ "$gsl_post_blockquotes_nbr_r" -eq 0 ]];then
|
|
|
|
gsl_post_stat_bq=$(( $gsl_post_blockquotes_nbr / 2 ))
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Post" \
|
|
|
|
"Blockquotes" \
|
|
|
|
"NBR=$gsl_post_stat_bq > $gsl_mark_blockquote (2x)" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check Post for ABBR HEADER + Content
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_check_abbr() {
|
2022-02-14 18:54:07 +01:00
|
|
|
gsl_post_stat_abbr=0
|
2022-02-14 02:57:58 +01:00
|
|
|
while read -r "gsl_header_abbr"
|
|
|
|
do
|
|
|
|
gsl_post_abbr_s=`gsl__get_header_field 1 "$gsl_header_abbr"`
|
|
|
|
gsl_post_abbr_l=`gsl__get_header_field 2 "$gsl_header_abbr"`
|
|
|
|
gsl_post_line_nbr=`gsl__get_line "$gsl_header_abbr" "$gsl_post"`
|
|
|
|
|
|
|
|
if ! [[ "$gsl_post_abbr_s" ]] || \
|
|
|
|
! [[ "$gsl_post_abbr_l" ]];then
|
|
|
|
|
|
|
|
gsl__logs_print \
|
2022-02-13 17:58:25 +01:00
|
|
|
"$gsl_log_e" \
|
|
|
|
"Post" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"ABBR" \
|
2022-02-14 18:54:07 +01:00
|
|
|
"Line:$gsl_post_line_nbr > Content: $gsl_log_act_abbr" \
|
2022-02-13 17:58:25 +01:00
|
|
|
"${PWD}/$gsl_post"
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl_checker_err=true
|
|
|
|
continue
|
|
|
|
fi
|
2022-02-14 18:54:07 +01:00
|
|
|
|
|
|
|
if ! [[ `gsl__get_content_line "$gsl_post_abbr_s" "$gsl_post"` ]];then
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Post" \
|
|
|
|
"ABBR" \
|
2022-02-14 18:54:07 +01:00
|
|
|
"Missing Content: $gsl_post_abbr_s" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
else
|
2022-02-14 18:54:07 +01:00
|
|
|
(( gsl_post_stat_abbr ++ ))
|
|
|
|
fi
|
|
|
|
done < <(gsl__get_header "$gsl_marker_abbr" "$gsl_post")
|
|
|
|
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Post" \
|
|
|
|
"ABBR" \
|
|
|
|
"NBR=$gsl_post_stat_abbr" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check Post for LINKs HEADER + Content
|
|
|
|
#=======================================================================
|
|
|
|
gsl__post_check_links() {
|
|
|
|
while read -r "gsl_header_link"
|
|
|
|
do
|
|
|
|
# Get in HEADERS
|
|
|
|
gsl_post_link_ref=`gsl__get_header_field 1 "$gsl_header_link"`
|
|
|
|
gsl_post_link_url=`gsl__get_header_field 2 "$gsl_header_link"`
|
|
|
|
gsl_post_link_alt=`gsl__get_header_field 3 "$gsl_header_link"`
|
|
|
|
gsl_post_line_nbr=`gsl__get_line "$gsl_marker_link$gsl_post_link_ref" "$gsl_post"`
|
|
|
|
|
|
|
|
if ! [[ "$gsl_post_link_ref" ]] || \
|
|
|
|
! [[ "$gsl_post_link_url" ]];then
|
|
|
|
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__logs_print \
|
2022-02-14 18:54:07 +01:00
|
|
|
"$gsl_log_e" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"Post" \
|
2022-02-14 18:54:07 +01:00
|
|
|
"Link" \
|
|
|
|
"Line:$gsl_post_line_nbr > Content: $gsl_log_act_link" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Not ALT TEXT ?
|
|
|
|
if ! [[ "$gsl_post_link_alt" ]];then
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"Post" \
|
|
|
|
"Link" \
|
|
|
|
"Line:$gsl_post_line_nbr > No ALT TEXT ?" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"${PWD}/$gsl_post"
|
2022-02-14 18:54:07 +01:00
|
|
|
gsl_checker_war=true
|
2022-02-14 02:57:58 +01:00
|
|
|
fi
|
2022-02-14 18:54:07 +01:00
|
|
|
|
|
|
|
# Find if ref is in CONTENT
|
|
|
|
gsl_content_link=`
|
|
|
|
gsl__get_content_finder \
|
|
|
|
-o "$gsl_mo_link" \
|
|
|
|
-b "$gsl_post_link_ref" \
|
|
|
|
-c "$gsl_mc_link" \
|
|
|
|
-f "$gsl_post" \
|
|
|
|
| tail -1`
|
|
|
|
|
|
|
|
if ! [[ $gsl_content_link ]];then
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Post" \
|
|
|
|
"Link" \
|
|
|
|
"Missing Content: [_${gsl_post_link_ref}_]" \
|
|
|
|
"${PWD}/$gsl_post"
|
|
|
|
gsl_checker_err=true
|
|
|
|
fi
|
|
|
|
done < <(gsl__get_header "$gsl_marker_link" "$gsl_post")
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|