window.location = window.location.href;');
}
}
}
}
public static function init_hooks()
{
self::$initiated = true;
add_filter( 'plugin_action_links', [__CLASS__, 'options_link'], 2, 2);
add_action( 'admin_menu', [__CLASS__, 'admin_menu'], 5 );
add_action( 'admin_enqueue_scripts', [__CLASS__, 'load_resources'] );
add_action( 'wp_ajax_display_synchronize_log', [__CLASS__, 'display_synchronize_log'] );
add_action( 'add_meta_boxes', [__CLASS__, 'switch_boxes'] );
add_post_type_support( 'page', 'excerpt' );
}
public static function admin_menu()
{
add_options_page(
'Настройки плагина API ChiefRed.com',
'API ChiefRed.com',
'manage_options',
'chiefred',
array( __CLASS__, 'display_options_page' )
);
}
public static function options_link($actions, $file)
{
if (false !== strpos($file, 'chiefred')) {
$add['options'] = 'Настройки';
$actions = $add + $actions;
}
return $actions;
}
public static function load_resources()
{
wp_register_style( 'chiefred_options.css', CHIEFRED_PLUGIN_URL . 'res/chiefred_options.css', array(), CHIEFRED_VERSION );
wp_enqueue_style( 'chiefred_options.css' );
wp_register_script( 'chiefred_options.js', CHIEFRED_PLUGIN_URL . 'res/chiefred_options.js', array('jquery'), CHIEFRED_VERSION );
wp_enqueue_script( 'chiefred_options.js' );
wp_register_script( 'jquery.mask.min.js', CHIEFRED_PLUGIN_URL . 'res/jquery.mask.min.js', array('jquery'), CHIEFRED_VERSION );
wp_enqueue_script( 'jquery.mask.min.js' );
}
public static function display_options_page()
{
$options['site_id'] = get_option('chiefred_site_id');
$options['api_ip'] = get_option('chiefred_api_ip');
$options['api_port'] = get_option('chiefred_api_port');
$options['api_secret'] = get_option('chiefred_api_secret');
$options['article_parent_link'] = get_option('chiefred_article_parent_link');
$options['article_creators'] = get_option('chiefred_article_creators');
$options['article_childrens'] = get_option('chiefred_article_childrens');
$options['article_was_useful'] = get_option('chiefred_article_was_useful');
$options['illustration_size'] = get_option('chiefred_illustration_size');
$options['illustration_class'] = get_option('chiefred_illustration_class');
$options['illustration_link'] = get_option('chiefred_illustration_link');
$options['illustration_link_class'] = get_option('chiefred_illustration_link_class');
$options['illustration_link_rel'] = get_option('chiefred_illustration_link_rel');
$options['illustration_link_target'] = get_option('chiefred_illustration_link_target');
foreach (ChiefRed::get_image_sizes() as $size_name => $size) {
switch ($size_name) {
case 'thumbnail':
$options['image_sizes']['thumbnail'] = ['nname'=>'Малый', 'width'=>$size['width']];
break;
case 'medium':
$options['image_sizes']['medium'] = ['nname'=>'Средний', 'width'=>$size['width']];
break;
case 'medium_large':
$options['image_sizes']['medium_large'] = ['nname'=>'Крупный', 'width'=>$size['width']];
break;
}
}
$options['image_sizes']['full'] = ['nname'=>'Полный', 'width'=>800];
ChiefRed::view( 'options', $options );
}
public static function display_synchronize_log()
{
header('Content-Type: text/plain; charset=utf-8');
echo htmlspecialchars(file_get_contents( CHIEFRED_PLUGIN_DIR . '/logs/chiefred.log' ));
wp_die();
}
public static function switch_boxes()
{
if ( ! post_type_supports( $GLOBALS['post']->post_type, 'excerpt' ) )
{
return;
}
remove_meta_box(
'postexcerpt',
'',
'normal'
);
add_meta_box(
'postexcerpt2',
__('Excerpt'),
array(__CLASS__, 'show'),
null,
'normal',
'core'
);
}
public static function show( $post )
{
?>
post_excerpt),
'excerpt',
array(
'editor_height' => 500,
'media_buttons' => FALSE,
'teeny' => TRUE,
'tinymce' => TRUE
)
);
}
public static function unescape( $str )
{
return str_replace(
array ( '<', '>', '"', '&', ' ', ' ' ),
array ( '<', '>', '"', '&', ' ', ' ' ),
$str
);
}
}