/* Plugin Name: Lexikon Plugin URI: http://www.k-evolution.de Description: Plug-In internes Lexikon Author: M.Klindworth Version: 1.0 Author URI: http://www.k-evolution.de */ # by IT-Connect 03.02.2016 mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); @mysql_select_db(DB_NAME) or die( "Unable to select database"); mysql_query("SET NAMES 'utf8'"); function liste() { if($_GET['lex']) { include "includes/".$_GET['action'].".php"; } else include "includes/liste.php"; } function add() { include "includes/add.php"; } function liste_category() { include "includes/liste_category.php"; } function add_category() { include "includes/add_category.php"; } function profileAddMenu() { add_menu_page('Wellness-Lexikon', 'Wellness-Lexikon', 10, basename(__FILE__), 'liste'); add_submenu_page(basename(__FILE__), 'Alle Eintr├Ąge', 'Alle Eintr├Ąge', 10, basename(__FILE__), 'liste'); add_submenu_page(basename(__FILE__), 'Erstellen', 'Erstellen', 10, 'add.php', 'add'); add_submenu_page(basename(__FILE__), 'Kategorien', 'Kategorien', 10, 'liste_category.php', 'liste_category'); add_submenu_page(basename(__FILE__), 'Erstellen', 'Erstellen', 10, 'add_category.php', 'add_category'); } function lexikonFilter($content) { if(is_single()) { $query = mysql_query("SELECT slug,title FROM wp_lexikon"); while($daten = mysql_fetch_array($query)) $replaces[$daten['title']] = ''.$daten['title'].''; preg_match_all('|?[^>]*>|',$content,$matches); foreach($matches[0] AS $k => $v) $content = str_replace($v,"[[".$k."]]",$content); foreach($replaces AS $k => $v) $content = str_replace($k,$v,$content); foreach($matches[0] AS $k => $v) $content = str_replace("[[".$k."]]",$v,$content); } if(strpos($content,"[lexikon")!==false) { global $_GET; preg_match_all('/\[lexikon ([a-zA-Z0-9_-]{1,})\]/',$content,$matches); if(!empty($matches[1][0])) { $query = mysql_query("SELECT id FROM wp_category WHERE slug='".$matches[1][0]."'"); $d = mysql_fetch_assoc($query); } $abc = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','','',''); $query = mysql_query("SELECT SUBSTR(title,1,1) AS abc FROM wp_lexikon ".(!empty($d) ? " l JOIN wp_lexikon_category lc ON(lc.lexikon_id=l.id) WHERE lc.category_id='".$d['id']."'" : "")." GROUP BY abc ORDER BY title"); while($daten = mysql_fetch_assoc($query)) $ls[] = strtoupper($daten['abc']); // Standards if(!isset($_GET['lexikon'])) $_GET['lexikon'] = $ls[0]; if(!isset($_GET['title'])) $_GET['title'] = ''; // Top-Nav $text[] = '

'; // Artikel $i = 0; $query = mysql_query("SELECT * FROM wp_lexikon ".(!empty($d) ? " l JOIN wp_lexikon_category lc ON(lc.lexikon_id=l.id) WHERE lc.category_id='".$d['id']."' AND" : "WHERE")." slug LIKE '".$_GET['lexikon']."%' ORDER BY title"); $text[] = '
'.utf8_decode($inh).'

'; $content = str_replace("[lexikon".(!empty($matches[1][0]) ? " ".$matches[1][0] : "")."]",implode("",$text),$content); } return $content; } add_action('admin_menu', 'profileAddMenu'); add_filter('the_content', 'lexikonFilter'); // JS if(!is_admin()) { wp_register_script( 'lexikon-js', plugins_url( 'js/lexikon.js' , __FILE__ )); wp_enqueue_script( 'lexikon-js' ); } // CSS wp_register_style( 'lexikon-css', plugins_url( 'css/lexikon.css' , __FILE__ )); wp_enqueue_style( 'lexikon-css' ); ?>