Skip to content

Commit

Permalink
Merge pull request #2722 from QuizandSurveyMaster/CU-86cx5gncd-Linked…
Browse files Browse the repository at this point in the history
…in-sharing

Add Feature for sharing result on Linkedin
  • Loading branch information
zubairraeen authored Nov 27, 2024
2 parents 9245e19 + 3bf7b39 commit 6db32fb
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
Binary file added assets/linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,9 @@ function qmnSocialShare(network, mlw_qmn_social_text, mlw_qmn_title, facebook_id
"&" + "link=" + pageUrlEncoded + "&" + "name=" + encodeURIComponent(mlw_qmn_social_text) +
"&" + "description=";
}
if (network === 'linkedin') {
url = "https://www.linkedin.com/sharing/share-offsite?url=" + encodeURIComponent(mlw_qmn_social_text);
}
if (network == 'twitter') {
url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text);
}
Expand Down Expand Up @@ -1756,6 +1759,9 @@ jQuery(function () {
if (network == 'twitter') {
url = "https://twitter.com/intent/tweet?text=" + social_text;
}
if (network == 'linkedin') {
url = "https://www.linkedin.com/feed/?text=" + social_text;
}
var sTop = window.screen.height / 2 - (218);
var sLeft = window.screen.width / 2 - (313);
var sqShareOptions = "height=400,width=580,toolbar=0,status=0,location=0,menubar=0,directories=0,scrollbars=0,top=" + sTop + ",left=" + sLeft;
Expand Down
1 change: 1 addition & 0 deletions php/classes/class-qmn-plugin-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ public static function get_default_texts() {
'scheduled_timeframe_text' => '',
'twitter_sharing_text' => __('I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next'),
'facebook_sharing_text' => __('I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next'),
'linkedin_sharing_text' => __('I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next'),
'submit_button_text' => __('Submit', 'quiz-master-next'),
'retake_quiz_button_text' => __('Retake Quiz', 'quiz-master-next'),
'previous_button_text' => __('Previous', 'quiz-master-next'),
Expand Down
4 changes: 3 additions & 1 deletion php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2650,11 +2650,13 @@ public function display_social( $qmn_quiz_options, $qmn_array_for_variables ) {
$qmn_social_media_text = array(
'twitter' => $qmn_quiz_options->social_media_text,
'facebook' => $qmn_quiz_options->social_media_text,
'linkedin' => $qmn_quiz_options->social_media_text,
);
}
$qmn_social_media_text['twitter'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['twitter'], $qmn_array_for_variables );
$qmn_social_media_text['facebook'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['facebook'], $qmn_array_for_variables );
$social_display .= "<br /><a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('facebook', '" . esc_js( $qmn_social_media_text['facebook'] ) . "', '" . esc_js( $qmn_quiz_options->quiz_name ) . "', '" . esc_js( $facebook_app_id ) . "');\">Facebook</a><a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('twitter', '" . esc_js( $qmn_social_media_text['twitter'] ) . "', '" . esc_js( $qmn_quiz_options->quiz_name ) . "');\">Twitter</a><br />";
$qmn_social_media_text['linkedin'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['linkedin'], $qmn_array_for_variables );
$social_display .= "<br /><a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('facebook', '" . esc_js( $qmn_social_media_text['facebook'] ) . "', '" . esc_js( $qmn_quiz_options->quiz_name ) . "', '" . esc_js( $facebook_app_id ) . "');\">Facebook</a><a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('twitter', '" . esc_js( $qmn_social_media_text['twitter'] ) . "', '" . esc_js( $qmn_quiz_options->quiz_name ) . "');\">Twitter</a><a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('linkedin', '" . esc_js( $qmn_social_media_text['linkedin'] ) . "', '" . esc_js( $qmn_quiz_options->quiz_name ) . "');\">Linkedin</a><br />";
}
return apply_filters( 'qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables );
}
Expand Down
23 changes: 22 additions & 1 deletion php/classes/class-qsm-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public function register_default_settings() {
),
'default' => 0,
/* translators: %FACEBOOK_SHARE%: Facebook share link, %TWITTER_SHARE%: Twitter share link */
'tooltip' => __( 'Please use the new template variables instead.%FACEBOOK_SHARE% %TWITTER_SHARE%', 'quiz-master-next' ),
'tooltip' => __( 'Please use the new template variables instead.%FACEBOOK_SHARE% %TWITTER_SHARE% %LINKEDIN_SHARE%', 'quiz-master-next' ),
'option_tab' => 'legacy',
);
$mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' );
Expand Down Expand Up @@ -1073,6 +1073,27 @@ public function register_default_settings() {
);
$mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_text' );

// Registers linkedin_sharing_text setting
$field_array = array(
'id' => 'linkedin_sharing_text',
'label' => __( 'Linkedin Sharing Text', 'quiz-master-next' ),
'type' => 'editor',
'default' => 0,
'variables' => array(
'%POINT_SCORE%',
'%AVERAGE_POINT%',
'%AMOUNT_CORRECT%',
'%TOTAL_QUESTIONS%',
'%CORRECT_SCORE%',
'%QUIZ_NAME%',
'%QUIZ_LINK%',
'%RESULT_LINK%',
'%TIMER%',
'%CURRENT_DATE%',
),
);
$mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_text' );

// Registers facebook_sharing_text setting
$field_array = array(
'id' => 'facebook_sharing_text',
Expand Down
2 changes: 2 additions & 0 deletions php/classes/class-qsm-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ private function load_settings() {
$social_media_text = array(
'twitter' => $quiz_options->social_media_text,
'facebook' => $quiz_options->social_media_text,
'linkedin' => $quiz_options->social_media_text,
);
}

Expand Down Expand Up @@ -394,6 +395,7 @@ private function load_settings() {
'total_user_tries_text' => $quiz_options->total_user_tries_text,
'twitter_sharing_text' => $social_media_text['twitter'],
'facebook_sharing_text' => $social_media_text['facebook'],
'linkedin_sharing_text' => $social_media_text['linkedin'],
'previous_button_text' => $pagination_text[0],
'next_button_text' => $pagination_text[1],
'require_log_in_text' => $quiz_options->require_log_in_text,
Expand Down
8 changes: 8 additions & 0 deletions php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ function mlw_qmn_variable_social_share( $content, $mlw_quiz_array ) {
$social_display = "<a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('twitter', '" . esc_js( $sharing ) . "', '" . esc_js( $mlw_quiz_array['quiz_name'] ) . "');\"><img src='" . $tw_image . "' alt='" . __( 'Twitter Share', 'quiz-master-next' ) . "' /></a>";
$content = str_replace( '%TWITTER_SHARE%', $social_display, $content );
}
if ( false !== strpos( $content, '%LINKEDIN_SHARE%' ) ) {
$ln_image = plugins_url( '', dirname( __FILE__ ) ) . '/assets/linkedin.png';
$sharing = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_text', 'linkedin_sharing_text', '%QUIZ_NAME%' );
$sharing = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $sharing, "quiz_linkedin_sharing_text-{$mlw_quiz_array['quiz_id']}" );
$sharing = apply_filters( 'mlw_qmn_template_variable_results_page', $sharing, $mlw_quiz_array );
$social_display = "<a class=\"mlw_qmn_quiz_link\" onclick=\"qmnSocialShare('linkedin', '" . esc_js( $sharing ) . "', '" . esc_js( $mlw_quiz_array['quiz_name'] ) . "', '$page_link');\"><img src='" . $ln_image . "' alt='" . __( 'Linkedin Share', 'quiz-master-next' ) . "' /></a>";
$content = str_replace( '%LINKEDIN_SHARE%', $social_display, $content );
}
return $content;
}

Expand Down

0 comments on commit 6db32fb

Please sign in to comment.