Example #1
0
    /**
     * The widget
     */
    public function widget($args, $instance)
    {
        extract($args);
        $content = '';
        // If this is neither a Notepad or a post with an associated
        // Notepad, there's nothing to display
        if (participad_notepad_is_notepad() && ($associated_post_id = get_post_meta(get_the_ID(), 'notepad_associated_post', true))) {
            $content .= '<p>' . __('This Notepad is associated with the following post:', 'participad') . '</p>';
            $associated_post = get_post($associated_post_id);
            $content .= '<ul class="associated-post"><li><a href="' . get_permalink($associated_post_id) . '">' . esc_html($associated_post->post_title) . '</a></li></ul>';
        } else {
            if (!participad_notepad_is_notepad() && ($notepads = participad_notepad_post_has_notepad())) {
                $content .= '<p>' . __('This post is associated with the following Notepads:', 'participad') . '</p>';
                $content .= '<ul class="associated-notepads">';
                foreach ($notepads as $np) {
                    $content .= '<li><a href="' . get_permalink($np->ID) . '">' . esc_html($np->post_title) . '</a></li>';
                }
                $content .= '</ul>';
            }
        }
        if ($content) {
            $title = $instance['title'];
            $use_packaged_css = !isset($instance['use_packaged_css']) || 'no' == $instance['use_packaged_css'] ? 'no' : 'yes';
            if ('yes' == $use_packaged_css) {
                echo '<style type="text/css">
					.widget_participad_notepad_create { font-size: .8em; }
				</style>';
            }
            echo $before_widget;
            if (!empty($title)) {
                echo $before_title . $title . $after_title;
            }
            echo $content;
            echo $after_widget;
        }
    }
Example #2
0
/**
 * Detect when a success/error message should be shown
 */
function participad_notepad_display_error($content)
{
    $message = '';
    // Admins can override these hardcoded styles
    if (!apply_filters('participad_notepad_suppress_error_styles', false)) {
        $message .= '
			<style type="text/css">
				div.participad-message { padding: 10px 15px; border: 1px solid #ccc; border-radius: 2px; margin-bottom: 1em; }
				div.participad-message-success { background: #ffffe0; }
				div.participad-message-error { background: #c43; }
			</style>
		';
    }
    if (participad_notepad_is_notepad() && isset($_GET['notepad_created'])) {
        $message .= '<div class="participad-message participad-message-success">' . __('Notepad created', 'participad') . '</div>';
    }
    if (isset($_GET['notepad_noname'])) {
        $message .= '<div class="participad-message participad-message-error">' . __('Notepads must have a title', 'participad') . '</div>';
    }
    if (isset($_GET['notepad_misc'])) {
        $message .= '<div class="participad-message participad-message-error">' . __('Could not create the notepad', 'participad') . '</div>';
    }
    return $message . $content;
}