0 ) $loglevel += $loglevel_offset; } } file_put_contents( $logfile , '' ); } else { /** * dummy function for logger() when debug mode is deactivated * * @param string $dummy1 void * @param int $dummy2 void * @return boolean false */ function logger( $dummy1 = '', $dummy2 = 0 ) { return false; } } logger("plugin start", +1); logger("\$ch_options = " . var_export( $ch_options , true )); function ch_menu () { global $ch_options; add_options_page ( 'CH', 'Comment Highlighter', 9, __FILE__, 'ch_manage_options' ) ; } function CommentHighlight ( $link = 'class', $additional_options = array() ) { global $comment, $wpdb, $ch_options ; logger("CommentHighlight ( \$link = '{$link}', \$additional_options ) {", +1); logger("\$additional_options = " . var_export($additional_options, true)); logger("\$comment = " . var_export($comment, true)); $ret = array ( ) ; if ($link == 'link') { if (current_user_can ( 'manage_options' )) { logger("current_user_can manage_options"); $_url = get_bloginfo ( 'wpurl' ) . "/wp-admin/options-general.php?page={$ch_options['install_path']}&c={$comment->comment_ID}" ; logger("\$_url = {$_url}"); echo " (comment highlight)" ; } } elseif ($link == 'class') { $evenodd = '$evenodd' . $comment->comment_post_ID ; global $$evenodd ; $$evenodd ++ ; $_sql = "SELECT * FROM {$wpdb->postmeta} WHERE (meta_key = '_jpo_comment_highlighter' AND post_id = {$comment->comment_post_ID}) OR meta_key = '_jpo_comment_highlighter_global';"; logger("\$_sql = {$_sql}"); $_meta = $wpdb->get_results ( $_sql, ARRAY_A ) ; logger("\$_meta = " . var_export($_meta, true)); if (count ( $_meta )) { foreach ( $_meta as $row ) { $val = unserialize ( $row [ 'meta_value' ] ) ; foreach ( $val as $critkey => $critval ) { switch ( $critkey) { case 'email' : if ($comment->comment_author_email == $critval) { $ret [] = $val [ 'class' ] ; } break ; case 'name' : if ($comment->comment_author == $critval) { $ret [] = $val [ 'class' ] ; } break ; case 'url' : if ($comment->comment_author_url == $critval) { $ret [] = $val [ 'class' ] ; } break ; case 'uid' : if ($comment->comment_author_name == $critval) { $ret [] = $val [ 'class' ] ; } break ; case 'cid' : if ($comment->comment_ID == $critval) { $ret [] = $val [ 'class' ] ; } break ; case 'even' : $ret [] = ($$evenodd % 2 ? '' : $val [ 'class' ]) ; break ; case 'odd' : $ret [] = ($$evenodd % 2 ? $val [ 'class' ] : '') ; break ; case 'pingback' : if ($comment->comment_type == 'pingback') { $ret [] = $val [ 'class' ] ; } break ; default : } } } } foreach ($ret AS $key => $val) { if (isset($additional_options['prefix'])) { $ret[$key] = $additional_options['prefix'].$val; } if (isset($additional_options['postfix'])) { $ret[$key] = $val.$additional_options['postfix']; } } echo implode ( ' ', $ret ) ; } logger("\$ret = " . var_export($ret, true)); logger("}", -1); } function ch_manage_options () { global $wpdb, $VERSION, $ch_options ; logger("ch_manage_options () {", +1); if ($_POST) { if ($_POST [ 'submit' ]) { $_meta_key = '_jpo_comment_highlighter' . ($_POST [ 'global' ] ? '_global' : '') ; $_meta_id = $_POST['meta_id']; $_post_id = ($_POST [ 'txt_pid' ] ? $_POST [ 'txt_pid' ] : 0) ; $_arr = array ( ) ; foreach ( $_POST as $key => $val ) { list ( $_pre, $_post ) = explode ( '_', $key ) ; if ($_pre == 'ch' && $val) { $_arr [ $_post ] = addslashes ( $_POST [ "txt_{$_post}" ] ) ; } } if ($_meta_id) { $wpdb->query ( "UPDATE {$wpdb->postmeta} SET post_id = {$_post_id}, meta_key = '{$_meta_key}', meta_value = '" . serialize ( $_arr ) . "' WHERE meta_key LIKE '_jpo_comment_highlighter%' AND meta_id = {$_meta_id};" ) ; } else { $wpdb->query ( "INSERT {$wpdb->postmeta} SET post_id = {$_post_id}, meta_key = '{$_meta_key}', meta_value = '" . serialize ( $_arr ) . "' ;" ); // $wpdb->query ( "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) VALUES ({$_post_id}, '{$_meta_key}', '" . serialize ( $_arr ) . "');" ) ; } } elseif ($_POST['update_values']) { $ch_options['debug_key'] = $_POST['debug_key']; update_option( 'jpo_comment_highlighter_options' , $ch_options ); } echo "" ; exit; } if ($_GET [ 'delete' ]) { $wpdb->query ( "DELETE FROM {$wpdb->postmeta} WHERE meta_id = {$_GET['delete']};" ) ; echo "" ; exit; } $tofff = array( 'email' => 'email.png', 'pingback' => 'arrow_refresh.png', 'global' => 'asterisk_yellow.png', 'class' => 'tag.png', 'name' => 'vcard.png', 'even' => 'shape_move_backwards.png', 'odd' => 'shape_move_forwards.png', 'pid' => 'tag_red.png', 'cid' => 'tag_blue.png', 'uid' => 'tag_green.png', 'url' => 'world.png', 'delete' => 'delete.png', 'edit' => 'pencil.png', ); echo "
" ; echo "

Comment Highlighter Options

" ; echo "
" ; if (isset($_GET['c']) || isset($_GET['edit'])) { if ($_GET [ 'c' ] == 'new') { $_pid = $_cid = '0' ; $_uid = $_email = $_name = $_url = '' ; } elseif ($_GET['edit']) { $_sql = "SELECT * FROM {$wpdb->postmeta} WHERE LEFT(meta_key, 24) = '_jpo_comment_highlighter' AND meta_id = {$_GET['edit']};"; logger("\$_sql = {$_sql}"); $_meta = $wpdb->get_results ( $_sql , ARRAY_A ) ; $_global = (substr($_meta[0]['meta_key'], -6) == 'global' ? true : false); foreach(unserialize($_meta[0]['meta_value']) AS $var => $val) { $_tmp = "_{$var}"; $$_tmp = $val; } echo ""; } else { $_meta = $wpdb->get_row ( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = {$_GET['c']};" ) ; $_pid = $_meta->comment_post_ID ; $_cid = $_GET [ 'c' ] ; $_email = $_meta->comment_author_email ; $_email = $_meta->comment_author_name ; $_name = $_meta->comment_author ; $_url = $_meta->comment_author_url ; } echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo ""; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "
Create a new comment highlight based on (only selected criterias will be saved and you can select multiple criterias):
 
 
the user ID of a person (usually the WP login name)
the email of the person
the name of the person
the URL the person has entered
if a comment isn't really a comment but a pingback/trackback
every even numbered comment
every odd numbered comment
 this means that the post and comment ID will not be part of the criteria
".fff($tofff['class'])." Class(es):separate multiple classes with spaces
" ; echo "
" ; echo "
" ; echo "
" ; } else { $_sql = "SELECT * FROM {$wpdb->postmeta} WHERE LEFT(meta_key, 24) = '_jpo_comment_highlighter';"; logger("\$_sql = {$_sql}"); $_meta = $wpdb->get_results ( $_sql , ARRAY_A ) ; logger("\$_meta = " . var_export($_meta, true)); $debug_key = ($ch_options['debug_key'] ? $ch_options['debug_key'] : substr(md5(uniqid()),0, 8)); echo "
" ; echo "" ; echo ""; echo ""; echo ""; echo ""; if (count ( $_meta )) { echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; foreach ( $_meta as $row ) { $pid = (substr ( $row [ 'meta_key' ], - 6 ) == 'global' ? fff($tofff['global']) .' Global' : fff($tofff['pid']).' '.$row [ 'post_id' ]) ; $val = unserialize ( $row [ 'meta_value' ] ) ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; } echo "
"; echo "Secret debug key (?)
"; echo "Used to enable debug mode by adding ?debug=xxx or &debug=xxx to the URL where xxx is the secret debug key"; echo "
"; echo ""; echo "" ; echo "
Post IDCriteria(s)Class(es) to use 
{$pid}" ; foreach ( $val as $critkey => $critval ) { if ($critkey != 'class') { echo fff($tofff[$critkey])." ".ucfirst($critkey)." = {$critval}
"; } } echo "
".fff($tofff['class'])."{$val['class']}"; echo fff($tofff['delete'])." Delete"; echo str_repeat(' ', 5); echo fff($tofff['edit'])." Edit" ; echo "
" ; echo "
"; } else { echo "" ; echo "

You haven't got any comment highlights yet...

" ; } $_url = get_bloginfo ( 'wpurl' ) . "/wp-admin/options-general.php?page={$_GET['page']}&c=new" ; echo "" ; $ch_options['install_path'] = $_GET['page']; update_option( 'jpo_comment_highlighter_options' , $ch_options ); } echo "
" ; logger("}", -1); } function comment_highlighter () { global $wpdb, $comment_highlighter_cache ; logger("comment_highlighter () {", +1); if (! isset ( $comment_highlighter_cache )) { $comment_highlight = $wpdb->get_results ( "SELECT post_id, meta_value FROM {$wpdb->postmeta} AS pm INNER JOIN {$wpdb->posts} AS p ON (pm.post_id = p.ID) WHERE meta_key = '_jpo_comment_highlighter' AND (post_status = 'static' OR post_status = 'publish');" ) ; } else { // return $comment_highlighter_cache ; $ret = $comment_highlighter_cache; } if (! $comment_highlight) { // $comment_highlighter_cache = false ; // return false ; $ret = false; } else { foreach ( $comment_highlight as $link ) { $comment_highlighter_cache [ $link->post_id ] = $link->meta_value ; } $ret = $comment_highlighter_cache; } logger("\$comment_highlighter_cache = " . var_export($comment_highlighter_cache, true)); logger("}", -1); return $ret; } if (! function_exists('fff')) { function fff($name) { $name = basename($name,'.png'); return "{$name}"; } } function toChecked($in) { return ($in ? "checked='checked'" : ''); } logger("plugin end", -1); ?>