articlesss.com. // Страница плагина на русском языке находится здесь.
Version: 0.9
Author: Dimox
Author URI: http://dimox.name/
*/
function artdir_get_version(){
return '0.9';
}
add_action('init', 'artdir_textdomain');
function artdir_textdomain() {
load_plugin_textdomain('article-directory', 'wp-content/plugins/article-directory');
}
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_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'] : '';
$exclude_cat = array($exclude_cats);
global $wpdb;
$cal_tree = array();
if (!$column_count) $column_count = 1;
function get_wpvers() {
global $wp_version;
preg_match("/\d\.\d/i", $wp_version, $match);
// wpmu - increment version by 1.0 to match wp
if (strpos($wp_version, 'wordpress-mu') !== false) {
$match[0] = $match[0] + 1.0;
}
return $match[0];
}
if (get_wpvers() == '2.1' || get_wpvers() == '2.2') {
error_reporting(0);
$wpdb->show_errors = false;
}
global $rssfeeds;
$feed = '';
if ($rssfeeds) {
$feed = 'RSS';
$show_parent_count = 0;
$show_child_count = 0;
}
if (get_wpvers() < '2.3') {
// for WP < 2.3
$parent_cats = $wpdb->get_results("SELECT *
FROM " . $wpdb->categories . "
WHERE category_parent = 0 " .
( count($exclude_cat) ? ' AND cat_ID NOT IN (' . implode(',', $exclude_cat) . ') ' : '' )
. " ORDER BY cat_name");
foreach ($parent_cats as $parent) {
$summ = "SELECT SUM(category_count) FROM " . $wpdb->categories . " WHERE category_parent = " . $parent->cat_ID;
$child_summ = mysql_result(mysql_query($summ),0);
$catid = $wpdb->get_var("SELECT cat_ID FROM " . $wpdb->categories . " WHERE category_parent = " . $parent->cat_ID); //определяем ID подрубрики 1-го уровня
$sub_child_summ = $wpdb->get_var("SELECT SUM(category_count) FROM " . $wpdb->categories . " WHERE category_parent = " . $catid); //считаем кол-во статей в подрубрике 2-го уровня
$cat_name = get_the_category_by_ID($parent->cat_ID);
$descr = sprintf(__("View all posts filed under %s"), $cat_name);
if ($desc_for_parent_title == 1) {
if (empty($parent->category_description)) {
$descr = sprintf(__("View all posts filed under %s"), $cat_name);
} else {
$descr = $parent->category_description;
}
}
$child_summ += $parent->category_count; //прибавляем к сумме родительской рубрики сумму в подрубрике 1-го уровня
$child_summ += $sub_child_summ; //прибавляем к сумме родительской рубрики сумму в подрубрике 2-го уровня
if ($show_parent_count == 1) {
$parent_count = ' (' . $child_summ . ')';
} else {
$parent_count = '';
}
// перехват вывода
ob_start();
wp_list_cats( ( count($exclude_cat) ? 'exclude=' . implode(',', $exclude_cat) : '' ) . '&optioncount=' . $show_child_count . '&hide_empty=' . $hide_empty . '&use_desc_for_title=' . $desc_for_child_title . '&child_of=' . $parent->cat_ID . '&hierarchical=1&feed=' . $feed);
$echo = ob_get_contents();
ob_end_clean();
$cal_tree[] = array(
'cat' => array(
'href' => get_category_link($parent->cat_ID),
'title' => $descr,
'name' => $cat_name,
'count' => $parent_count
),
'cats'=> $echo
);
}
} // end for WP < 2.3
else {
// for WP >= 2.3
$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.name");
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 = $wpdb->get_var("SELECT SUM(count) FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = 'category' AND parent = " . $catid); //считаем кол-во статей в подрубрике 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 = sprintf(__("View all posts filed under %s"), $cat_name);
} 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) : '' ) . '&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)
);
}
} // end for WP >= 2.3
$_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_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']);
$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_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' => '',
);
update_option('article_directory', $options);
?>
Article Directory v by Dimox.
Installation and customization:
- Make sure you have copied the categories.css file in your theme directory.
- Add the following code in the style.css:
@import \'categories.css\';
- Put the following code where you want to display categories list:
<?php if (function_exists(\'article_directory\')) article_directory(); ?>
- If necessary, configure the options listed above.
* * *
More detailed informations on this plugin can be found at Article Directory homepage.
If you find this plugin useful, please tell your blog readers about it.
', 'article-directory') ?>
#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
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');
}
}
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\'', $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' );
//thanks to http://guff.szub.net/
/*
function szub_erase_commenter_details($text) {
if( !current_user_can('publish_posts') ) {
$patterns = array('/ \ .*<\/a>/', '/ \| ' . __('IP') . ': /', '/ \| /', '/(' . __('E-mail') . '|' . __('IP') . ')<\/th>/', '/ | ()?<\/td>/');
$text = preg_replace($patterns, '', $text);
}
return $text;
}
if( strpos($_SERVER['REQUEST_URI'], 'wp-admin/edit-comments.php') ) {
ob_start('szub_erase_commenter_details');
}|
*/
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');
function logout_redirect() {
$logout_redirect = '
';
echo $logout_redirect;
}
add_action('admin_head', 'logout_redirect');
?> |