LePress = $LePress;
parent::WP_Widget(false, $name = 'LePress', array('description' => __('LePress plugin widget', lepress_textdomain)));
//If we have student role enabled
if($this->LePress->isStudentFeatures()) {
require_once('classes/student_include/student-widget.php');
$this->studentWidget = new LePressStudentWidget();
}
//If we have teacher role enabled
if($this->LePress->isTeacherFeatures()) {
require_once('classes/teacher_include/teacher-widget.php');
$this->teacherWidget = new LePressTeacherWidget();
}
//Load Basic widget class
//Ajax load widget content hooks and triggers
add_filter('query_vars', array(&$this, 'plugin_add_trigger'));
add_action('template_redirect', array(&$this,'plugin_trigger_check'));
add_action('wp_enqueue_scripts', array(&$this, 'loadWidgetJavascript'));
add_action('init', array(&$this, 'registerWidgetCSS'));
add_action('wp_head', array(&$this, 'addIECSS'));
}
/**
* Add IE styles, JS langvars
*
* This method adds Internet Explorer specific styles and
* JavaScript language vars need for widget AJAX interactions
*/
function addIECSS() {
if(isSet($_GET['if'])) { // If requesting post content via IFrame, do not append CSS/Scripts
return false;
}
echo '';
$wp_ver = get_bloginfo('version');
if($wp_ver <= '3.1.4' || get_current_theme() == "Twenty Ten") {
echo '';
}
//Add some Widget language variables too
$lang_vars = array('try_again' => __('Already subscribed ?', lepress_textdomain),
'success_simple' => __('Success', lepress_textdomain),
'blog_url_empty' => __('Blog URL not entered', lepress_textdomain),
'url_not_valid' => __('Blog URL not valid', lepress_textdomain),
'simple_profile_not_filled' => __('Subscribing failed', lepress_textdomain).'; '.__('Your profile is not filled (firstname/lastname)', lepress_textdomain),
'course_locked' => __('This course does not accept any new subscriptions', lepress_textdomain));
echo '';
}
/**
* Register Widget CSS files on init call
*/
function registerWidgetCSS() {
if(isSet($_GET['if'])) {
return false;
}
wp_register_style('lepress_widget', lepress_http_abspath.'css/lepress_widget.css');
wp_enqueue_style('lepress_widget');
}
/**
* AJAX calendar prev/next month handler
*/
function plugin_trigger_check() {
//If we have a query var lepress-calendar with value == 1
if(intval(get_query_var('lepress-calendar')) == 1) {
//WP default header is 404, have to override it
header("HTTP/1.0 200 OK");
if(isSet($_GET['c'])) {
$parts = explode('-', strip_tags(trim($_GET['c'])));
$selected_cat_ID = intval($parts[1]);
$this->storeLastCourse($_GET['c']);
}
global $widget_instance;
$widget_instance = $this->getSettingsByQuery(array('collapse_participants', 'collapse_assignments'));
get_calendar_forked(true, true, $selected_cat_ID, LePressBasicWidget::getCourseOwner(), $this->teacherWidget, $this->studentWidget, true, $instance_settings);
exit;
}
}
/**
* Add additional query var to query_variables
* @return query_vars array
*/
function plugin_add_trigger($vars) {
$vars[] = 'lepress-calendar';
return $vars;
}
/**
* Store last selected course as option in database
*/
function storeLastCourse($course_id) { //teacher-X or student-X
update_option('lepress-last-widget-course', $course_id);
}
/**
* Retrieve last selected course option from database
*
* @return string or boolean false
*/
function getLastStoredCourse() {
return get_option('lepress-last-widget-course', false);
}
/**
* Add Javascript files via wp_enqueue_scripts hook
*/
function loadWidgetJavascript() {
wp_enqueue_script( 'jquery' );
if(isSet($_GET['if'])) {
return false;
}
wp_register_script( 'lepress-wp-calendar', lepress_http_abspath.'js/lepress-calendar.js');
wp_enqueue_script( 'lepress-wp-calendar' );
}
/**
* Get settings by query
*
* @param array $array_what What setting to filter out of query
*
* @return array
*/
function getSettingsByQuery($array_what = array()) {
$out = array();
foreach($this->get_settings() as $ar) {
foreach($ar as $key => $val) {
if(in_array($key, $array_what)) {
$out[$key] = $val;
}
}
}
return $out;
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
global $LePress, $widget_instance;
extract( $args );
$title = apply_filters('widget_title', 'LePress');
$widget_instance = $this->getSettingsByQuery(array('collapse_participants', 'collapse_assignments'));
?>
isStudentFeatures() || $LePress->isTeacherFeatures()) {
echo '';
?>
teacherWidget, $this->studentWidget, false, $instance_settings);
} else {
echo ''.__('You have not configured your plugin. Please login to administrative dashboard, go to Settings -> LePress and finish LePress configuration', lepress_textdomain).'
';
}
?>
:
name="get_field_name('collapse_participants'); ?>" type="checkbox" value="1" />
isTeacherFeatures()) { ?>
name="get_field_name('collapse_assignments'); ?>" type="checkbox" value="1" />