$linkedin_enabled, "msg"=>wp_kses_post($_POST['linkedin_msg']),
'title' => $linkedin_title, "facebook_button" => esc_url_raw($_POST['facebook_button']), );
update_option('watuproshare_linkedin', $linkedin_options, false);
$twitter_options = array("use_twitter" => $use_twitter, "show_count" => $show_count,
"via" => $_POST['via'], "hashtag" => $hashtag, 'large_button' => '',
"tweet" => wp_kses_post($_POST['tweet']), "twitter_button" => esc_url_raw($_POST['twitter_button']));
update_option('watuproshare_twitter', $twitter_options, false);
}
$appid = get_option('watuproshare_facebook_appid');
$linkedin_options = get_option('watuproshare_linkedin');
$twitter_options = get_option('watuproshare_twitter');
if(@file_exists(get_stylesheet_directory().'/watu/sharing-options.html.php')) include get_stylesheet_directory().'/watu/sharing-options.html.php';
else include(WATU_PATH . '/views/sharing-options.html.php');
}
// display the social sharing buttons
static function display() {
global $wpdb;
$taking_id = intval($GLOBALS['watu_taking_id']);
ob_start();
// https://developers.facebook.com/docs/sharing/reference/feed-dialog
$appid = get_option('watuproshare_facebook_appid');
// get the grade title and description
$grade_id = $wpdb->get_var($wpdb->prepare("SELECT grade_id FROM ".WATU_TAKINGS." WHERE ID=%d", $taking_id));
if(empty($grade_id)) $grade = (object)array("gtitle"=>'None', 'gdescription'=>'None');
else $grade = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".WATU_GRADES." WHERE ID=%d", $grade_id));
// select quiz name
$quiz_name = $wpdb->get_var($wpdb->prepare("SELECT tE.name FROM ".WATU_EXAMS." tE
JOIN ".WATU_TAKINGS." tT ON tE.ID = tT.exam_id
WHERE tT.ID = %d", $taking_id));
// keep linkedin vars always because they are also used in Facebook
$linkedin = get_option('watuproshare_linkedin');
$linkedin_msg = stripslashes($linkedin['msg']);
$linkedin_title = stripslashes($linkedin['title']);
// title and description set up?
if(!empty($linkedin_title)) {
$linkedin_title = str_replace('{{{grade-title}}}', stripslashes($grade->gtitle), $linkedin_title);
$linkedin_title = str_replace('{{{quiz-name}}}', stripslashes($quiz_name), $linkedin_title);
}
if(!empty($linkedin_msg)) {
$linkedin_msg = str_replace('{{{grade-title}}}', stripslashes($grade->gtitle), $linkedin_msg);
$linkedin_msg = str_replace('{{{grade-description}}}', stripslashes($grade->gdescription), $linkedin_msg);
$linkedin_msg = str_replace('{{{quiz-name}}}', stripslashes($quiz_name), $linkedin_msg);
$linkedin_msg = str_replace('{{{url}}}', get_permalink($_POST['post_id']), $linkedin_msg);
}
// if not, default to grade title and desc
if(empty($linkedin_title)) $linkedin_title = $grade->gtitle;
if(empty($linkedin_msg)) $linkedin_msg = $grade->gdescription;
$linkedin_title = stripslashes($linkedin_title);
$linkedin_title = str_replace('"', '"', $linkedin_title);
$linkedin_title = str_replace("'", '’', $linkedin_title);
$linkedin_msg = stripslashes($linkedin_msg);
$linkedin_msg = str_replace('"', '"', $linkedin_msg);
$linkedin_msg = str_replace("'", '’', $linkedin_msg);
// any picture?
$picture_str = '';
if(strstr($grade->gdescription, 'gdescription);
$dom = new DOMDocument;
$dom->loadHTML($html);
$images = array();
foreach ($dom->getElementsByTagName('img') as $image) {
$src = $image->getAttribute('src');
$class = $image->getAttribute('class');
$images[] = array('src'=>$src, 'class'=>$class);
} // end foreach DOM element
if(sizeof($images)) {
$target_image = $images[0]['src'];
// but check if we have any that are marked with the class
foreach($images as $image) {
if(strstr($image['class'], 'watu-share')) {
$target_image = $image['src'];
break;
}
}
$picture_str = "&picture=".urlencode($target_image);
}
} // end searching for image
$twitter_options = get_option('watuproshare_twitter');
// prepare tweet text
if(!empty($twitter_options['use_twitter'])) {
$tweet = stripslashes($twitter_options['tweet']);
if(empty($tweet)) {
$tweet = stripslashes($grade->gdescription);
if(empty($tweet)) $tweet = stripslashes($grade->gtitle);
}
else {
$tweet = str_replace('{{{grade-title}}}', stripslashes($grade->gtitle), $tweet);
$tweet = str_replace('{{{grade-description}}}', stripslashes($grade->gdescription), $tweet);
$tweet = str_replace('{{{quiz-name}}}', stripslashes($quiz_name), $tweet);
}
$tweet = substr($tweet, 0, 140);
}
// buttons
$facebook_button = empty($linkedin['facebook_button']) ? WATU_URL.'/img/share/facebook.png' : $linkedin['facebook_button'];
$twitter_button = empty($twitter_options['twitter_button']) ? 'Tweet' : '
';
$facebook_button = apply_filters('watu_facebook_button', $facebook_button);
$twitter_button = apply_filters('watu_twitter_button', $twitter_button);
?>