articlesss.com.', 'article-directory');
return $string;
}
add_filter('pre_kses', 'artdir_plugin_description');
function article_directory() {
// получаем все опции
$options = get_option('article_directory');
// проверяем каждую опцию
// если опция есть, то присваиваем её переменной, если нет (:), то дефолт
$exclude_cats = isset($options['exclude_cats']) ? $options['exclude_cats'] : 0;
$show_parent_count = isset($options['show_parent_count']) ? (int) $options['show_parent_count'] : 1;
$show_child_count = isset($options['show_child_count']) ? (int) $options['show_child_count'] : 1;
$hide_empty = isset($options['hide_empty']) ? (int) $options['hide_empty'] : 0;
$desc_for_parent_title = isset($options['desc_for_parent_title']) ? (int) $options['desc_for_parent_title'] : 1;
$desc_for_child_title = isset($options['desc_for_child_title']) ? (int) $options['desc_for_child_title'] : 1;
$child_hierarchical = isset($options['child_hierarchical']) ? (int) $options['child_hierarchical'] : 1;
$column_count = isset($options['column_count']) ? $options['column_count'] : 3;
$sort_by = isset($options['sort_by']) ? (int) $options['sort_by'] : 0;
$sort_direction = isset($options['sort_direction']) ? (int) $options['sort_direction'] : 0;
$no_child_alert = isset($options['no_child_alert']) ? (int) $options['no_child_alert'] : 1;
$show_child = isset($options['show_child']) ? (int) $options['show_child'] : 1;
$maximum_child = isset($options['maximum_child']) ? $options['maximum_child'] : 0;
$forgot_the_cat = isset($options['forgot_the_cat']) ? (int) $options['forgot_the_cat'] : 1;
$sel_only_one_cat = isset($options['sel_only_one_cat']) ? (int) $options['sel_only_one_cat'] : 1;
$kinderloss = isset($options['kinderloss']) ? (int) $options['kinderloss'] : 1;
$hide_blocks = isset($options['hide_blocks']) ? (int) $options['hide_blocks'] : 1;
$using_wp_version = isset($options['using_wp_version']) ? (int) $options['using_wp_version'] : 1;
$cat_block_height = isset($options['cat_block_height']) ? $options['cat_block_height'] : 200;
$hide_tags_field = isset($options['hide_tags_field']) ? (int) $options['hide_tags_field'] : 0;
$publish_terms = isset($options['publish_terms']) ? (int) $options['publish_terms'] : 0;
$publish_terms_text = isset($options['publish_terms_text']) ? $options['publish_terms_text'] : '';
$show_article_code = isset($options['show_article_code']) ? (int) $options['show_article_code'] : 0;
$exclude_cat = array($exclude_cats);
global $wpdb;
$cal_tree = array();
if (!$column_count) $column_count = 1;
if (!function_exists('artdir_wp_version')) {
function artdir_wp_version() {
$wp_version = file_get_contents(ABSPATH."wp-includes/version.php");
preg_match("/'(.*)'/is", $wp_version, $out);
$out = $out[1];
preg_match("/\d\.\d/i", $out, $match);
return $match[0];
}
}
global $rssfeeds;
$feed = '';
if ($rssfeeds) {
$feed = 'RSS';
$show_parent_count = 0;
$show_child_count = 0;
}
if ($sort_by == 0) $order_by = $orderby = 'name';
elseif ($sort_by == 1) { $order_by = 'term_order'; $orderby = 'order'; }
$parent_cats = $wpdb->get_results("SELECT *
FROM " . $wpdb->term_taxonomy . " term_taxonomy
LEFT JOIN " . $wpdb->terms . " terms
ON terms.term_id = term_taxonomy.term_id
WHERE term_taxonomy.taxonomy = 'category' AND term_taxonomy.parent = 0 " .
( count($exclude_cat) ? ' AND terms.term_id NOT IN (' . implode(',', $exclude_cat) . ') ' : '' )
. " ORDER BY terms." . $order_by);
foreach ($parent_cats as $parent) {
$summ = "SELECT SUM(count) FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $parent->term_id;
$child_summ = mysql_result(mysql_query($summ),0); //считаем кол-во статей в подрубрике 1-го уровня
$catid = $wpdb->get_var("SELECT term_ID FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $parent->term_id); //определяем ID подрубрики 1-го уровня
$sub_child_summ = (int)$catid ? $wpdb->get_var("SELECT SUM(count) FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $catid) : 0; //считаем кол-во статей в подрубрике 2-го уровня
$cat_name = get_the_category_by_ID($parent->term_id);
$descr = sprintf(__("View all posts filed under %s"), $cat_name);
if ($desc_for_parent_title == 1) {
if (empty($parent->description)) {
$descr = $descr;
} else {
$descr = $parent->description;
}
}
$child_summ += $parent->count; //прибавляем к сумме родительской рубрики сумму в подрубрике 1-го уровня
$child_summ += $sub_child_summ; //прибавляем к сумме родительской рубрики сумму в подрубрике 2-го уровня
if ($show_parent_count == 1) {
$parent_count = ' (' . $child_summ . ')';
} else {
$parent_count = '';
}
$cal_tree[] = array(
'cat' => array(
'href' => get_category_link($parent->term_id),
'title' => $descr,
'name' => $cat_name,
'count' => $parent_count
),
'cats'=> wp_list_categories( ( count($exclude_cat) ? 'exclude=' . implode(',', $exclude_cat) : '' ) . '&orderby=' . $orderby . '&show_count=' . $show_child_count . '&hide_empty=' . $hide_empty . '&use_desc_for_title=' . $desc_for_child_title . '&child_of=' . $parent->term_id . '&title_li=&hierarchical=' . $child_hierarchical . '&echo=0&feed=' . $feed)
);
}
$_tree = array();
$count = count($cal_tree);
if ($sort_direction) {
$line_count = ceil( $count / $column_count );
$limit = $count - $line_count * $column_count % $count;
for ($i = 0; $i < $count; $i++) {
$index = floor($i / $line_count) + ($limit && $i > $limit ? 1 : 0);
if (!isset($_tree[$index])) { $_tree[$index] = array(); }
$_tree[$index][] = &$cal_tree[$i];
}
}
else {
for ($i = 0; $i < $count; $i++) {
$index = $i % $column_count;
if (!isset($_tree[$index])) { $_tree[$index] = array(); }
$_tree[$index][] = &$cal_tree[$i];
}
}
if (count($_tree)) {
echo '
';
for ($j = 0, $count = count($_tree); $j < $count; $j++) {
// вывод столбца
$write = '
';
// вывод рубрик для столбца
for ($i = 0, $icount = count($_tree[$j]); $i < $icount; $i++) {
$catcount = $i + 11;
if ($j == 1) $catcount = $i + 21;
if ($j == 2) $catcount = $i + 31;
if ($j == 3) $catcount = $i + 41;
if ($j == 4) $catcount = $i + 51;
if ($rssfeeds) {
$write .= '
- ';
} else {
$write .= '
- ';
}
// see wp-includes/category-template.php::276
// $output .= '
- ' . __("No categories") . '
';
$nocats = '- ' . __("No categories") . '
';
if ($no_child_alert == 1) $nocats = '';
if ($_tree[$j][$i]['cats'] != $nocats && $show_child == 1) {
$write .= '
';
if ($maximum_child) {
for ($s = 0, $strlen = strlen($_tree[$j][$i]['cats']), $counter = $maximum_child+1, $slevel = 0; $s < $strlen; $s++) {
if (!$slevel && substr($_tree[$j][$i]['cats'], $s, 3) == '- ') $slevel--;
else if (!$slevel) $write .= substr($_tree[$j][$i]['cats'], $s, 1);
}
$licount = substr_count($_tree[$j][$i]['cats'], '
- $maximum_child) && ($_tree[$j][$i]['cats'] != '
- ' . __("No categories") . '
') ) {
$write .= '- ...
';
}
}
else $write .= $_tree[$j][$i]['cats'];
$write .= '
';
}
$write .= '
';
}
// печать одного столбца
echo $write . '
';
}
echo '
';
}
}
function artdir_options_page() {
if (function_exists('add_options_page')) {
add_options_page('Article Directory', 'Article Directory', 8, __FILE__, 'artdir_options');
}
}
function artdir_options() {
$options = $newoptions = get_option('article_directory');
//if update
if (isset($_POST['artdir_update'])) {
$newoptions['exclude_cats'] = stripslashes($_POST['exclude_cats']);
$newoptions['show_parent_count'] = (int) stripslashes($_POST['show_parent_count']);
$newoptions['show_child_count'] = (int) stripslashes($_POST['show_child_count']);
$newoptions['hide_empty'] = (int) stripslashes($_POST['hide_empty']);
$newoptions['desc_for_parent_title'] = (int) stripslashes($_POST['desc_for_parent_title']);
$newoptions['desc_for_child_title'] = (int) stripslashes($_POST['desc_for_child_title']);
$newoptions['child_hierarchical'] = (int) stripslashes($_POST['child_hierarchical']);
$newoptions['column_count'] = stripslashes($_POST['column_count']);
$newoptions['sort_by'] = (int) stripslashes($_POST['sort_by']);
$newoptions['sort_direction'] = (int) stripslashes($_POST['sort_direction']);
$newoptions['no_child_alert'] = (int) stripslashes($_POST['no_child_alert']);
$newoptions['show_child'] = (int) stripslashes($_POST['show_child']);
$newoptions['maximum_child'] = stripslashes($_POST['maximum_child']);
$newoptions['forgot_the_cat'] = (int) stripslashes($_POST['forgot_the_cat']);
$newoptions['sel_only_one_cat'] = (int) stripslashes($_POST['sel_only_one_cat']);
$newoptions['kinderloss'] = (int) stripslashes($_POST['kinderloss']);
$newoptions['hide_blocks'] = (int) stripslashes($_POST['hide_blocks']);
$newoptions['using_wp_version'] = (int) stripslashes($_POST['using_wp_version']);
$newoptions['cat_block_height'] = stripslashes($_POST['cat_block_height']);
$newoptions['hide_tags_field'] = (int) stripslashes($_POST['hide_tags_field']);
$newoptions['publish_terms'] = (int) stripslashes($_POST['publish_terms']);
$newoptions['publish_terms_text'] = stripslashes($_POST['publish_terms_text']);
$newoptions['show_article_code'] = (int) stripslashes($_POST['show_article_code']);
$error=false;
//check errors
if(!preg_match("/^(\d+,)*\d+$/", $newoptions['exclude_cats'])){
$error .='' . __('IDs of categories is incorrect.', 'article-directory') . '';
$error1 = ' style="border: 1px solid #F00; background: #FFF5F4;"';
}
if (!is_numeric($newoptions['column_count'])) {
$error .='' . __('You can only specify a digit in the "The number of columns for categories list".', 'article-directory') . '';
$error2 = ' style="border: 1px solid #F00; background: #FFF5F4;"';
}
elseif ($newoptions['column_count'] == 0) {
$error .='' . __('The number of columns should not be zero.', 'article-directory') . '';
$error2 = ' style="border: 1px solid #F00; background: #FFF5F4;"';
}
if (!is_numeric($newoptions['maximum_child'])) {
$error .='' . __('You can only specify a digit in the "The number of child categories to show".', 'article-directory') . '';
$error3 = ' style="border: 1px solid #F00; background: #FFF5F4;"';
}
if (!is_numeric($newoptions['cat_block_height'])) {
$error .='' . __('You can only specify a digit in the "The height of the categories block".', 'article-directory') . '';
$error4 = ' style="border: 1px solid #F00; background: #FFF5F4;"';
}
elseif ($newoptions['cat_block_height'] < 100) {
$error .='' . __('The height of the categories block can\'t be less than 100 pixels.', 'article-directory') . '';
$error4 = ' style="border: 1px solid #F00; background: #FFF5F4;"';
}
//if something went wrong we write an error message
if ($error) {
?>
0,
'show_parent_count' => 1,
'show_child_count' => 1,
'hide_empty' => 0,
'desc_for_parent_title' => 1,
'desc_for_child_title' => 1,
'child_hierarchical' => 1,
'column_count' => 3,
'sort_by' => 0,
'sort_direction' => 0,
'no_child_alert' => 1,
'show_child' => 1,
'maximum_child' => 0,
'forgot_the_cat' => 1,
'sel_only_one_cat' => 1,
'kinderloss' => 1,
'hide_blocks' => 1,
'using_wp_version' => 1,
'cat_block_height' => 200,
'hide_tags_field' => 0,
'publish_terms' => 0,
'publish_terms_text' => '',
'show_article_code' => 0,
);
update_option('article_directory', $options);
?>
#categorychecklist {height: '.$options['cat_block_height'].'px !important}
';
} else {
$hide = '
';
}
echo $hide;
}
add_action('admin_head', 'hide_blocks');
} else {
// wp 2.5+
function hide_blocks() {
global $options;
$hide = '';
if ( current_user_can('level_7') ) {
$hide = '
';
} else {
$hide = '
';
}
echo $hide;
}
add_action('admin_head', 'hide_blocks');
}
} else {
if ($options['using_wp_version'] == 1) {
// <= wp 2.3.3
function hide_blocks() {
global $options;
$hide = '
';
echo $hide;
}
add_action('admin_head', 'hide_blocks');
} else {
// wp 2.5+
function hide_blocks() {
global $options;
$hide = '
';
echo $hide;
}
add_action('admin_head', 'hide_blocks');
}
}
function clear_fields() {
global $options;
if ($options['hide_blocks'] == 1) {
if ( !current_user_can('level_7') ) {
if (isset($_POST['excerpt'])) $_POST['excerpt'] = '';
if (isset($_POST['trackback_url'])) $_POST['trackback_url'] = '';
if (isset($_POST['post_password'])) $_POST['post_password'] = '';
if (isset($_POST['post_name'])) $_POST['post_name'] = '';
if (isset($_POST['save']) || isset($_POST['publish'])) $_POST['post_status'] = 'pending';
if ($options['hide_tags_field'] == 0) {
if (isset($_POST['tags_input'])) $_POST['tags_input'] = '';
if (isset($_POST['old_tags_input'])) $_POST['old_tags_input'] = '';
}
}
}
}
add_action('init', 'clear_fields');
if ($options['forgot_the_cat'] == 1) {
//thanks to "Forgot the Category" plugin - http://dancoulter.com/forgot-the-category/
class DC_ForgotTheCategory {
function AddToEditPage() {
?>
query_vars['cat'] . '\') AND post_type = \'post\' AND post_status = \'publish\'', $where);
}
return $where;
}
add_filter('posts_where', 'kinderloss_where');
}
//thanks to "Manage Your Posts Only" plugin - http://code.mincus.com/41/manage-your-posts-only-in-wordpress/
function mypo_parse_query_useronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
if ( !current_user_can( 'level_7' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'mypo_parse_query_useronly' );
if ($options['publish_terms'] == 1) {
global $pagenow;
$wp_pages = array('post.php', 'post-new.php', );
if ( in_array($pagenow, $wp_pages) ) {
function PublishTerms() {
$options = get_option('article_directory');
$publishTerms = "" . __('Terms of article publication', 'article-directory'). "
";
$publishTerms .= $options['publish_terms_text'];
$publishTerms .="";
if (!current_user_can('level_7')) {
echo $publishTerms;
}
}
add_action('admin_notices', 'PublishTerms');
}
}
function restrict_dashboard_screens() {
if ( ((strpos($_SERVER['SCRIPT_NAME'], 'wp-admin/edit-comments.php')) or (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin/comment.php')))) {
if (!current_user_can('level_7')) {
echo "";
die();
}
}
}
add_action('init', 'restrict_dashboard_screens');
if ($options['show_article_code'] == 1) {
function get_article_code($text) {
$get_article_code = '
'.__('Article Source', 'article-directory').'
'.__('HTML Version', 'article-directory').':
'.__('Text Version', 'article-directory').':
'.__('Article Url', 'article-directory').':
';
return ''.$text.'
'.$get_article_code;
}
add_filter('the_content', 'get_article_code');
//Подключаем jQuery
function artdir_jquery() {
if ( is_single() || is_page() ) { wp_enqueue_script('jquery'); }
}
add_action('wp_head', 'artdir_jquery', 1);
}
?>