From 7cf445975dd3a591c94089273e2848a1e6d4ec95 Mon Sep 17 00:00:00 2001 From: manandeep singh Date: Wed, 27 Nov 2024 10:47:58 +0530 Subject: [PATCH 1/2] Add Feature for sharing result on Linkedin --- assets/linkedin.png | Bin 0 -> 754 bytes js/qsm-quiz.js | 8 ++++++++ php/classes/class-qmn-plugin-helper.php | 1 + php/classes/class-qmn-quiz-manager.php | 4 +++- php/classes/class-qsm-install.php | 23 ++++++++++++++++++++++- php/classes/class-qsm-settings.php | 2 ++ php/template-variables.php | 8 ++++++++ 7 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 assets/linkedin.png diff --git a/assets/linkedin.png b/assets/linkedin.png new file mode 100644 index 0000000000000000000000000000000000000000..6e2f555ed4ee2e3520535761660e1d187de13e98 GIT binary patch literal 754 zcmV*^{jyP2sViBegp1zk$WKoO)% zvDzgujLyY0Rm@(0s4nXmQp68wS`(b$IeIEh9nTKv9=Ro*?V(gS;0>M4dFVImxCw`iX=Rk$6#>phZ7_k}! zDbACp`TR%U;53LBxzEBtr-Il6e)m`F#u33&0V_6&0|%}w>R*<^&ria_IxNy zfX>4^Y1vbROIIoP=5YIXHPwZA=>uroo^OgZMbJ>bIeh^BU?eFwwP2(Vpsjy|P&B?0 zzZjpT`?Wvi0D`tYX;mz7JE<%4GP4-t!P_Zfam%F}mS$COZc?c&^`HuYH(O_aiJNC* z-%u67$?8I!nhL;|kiq@oDGG8O9Nk?&xhI>rgwg2`Jwul;2L0D*9nL)Tv7ZGX(E?m?pQgsEOz z>aiD~weKBI#{vYxQSJ=-=^6TDs&8{U?FHx``D%&>{6SNk^PB!iDZpIB{HrY(aZ{Y7 z*$l9jgs`qD`1}%}vZE&lb!2 z<8_=4DL`V)RrV>N0I45y{$3vypf_XoQuZns(RPr-={M&M!f{dI>XBJ+900B$nE>o; kN(qc3WhX+fp`(882kAq-3KRmzN&o-=07*qoM6N<$g4TFYn*aa+ literal 0 HcmV?d00001 diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index eea3325f..2c13acc0 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1394,6 +1394,11 @@ 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=" + pageUrlEncoded; + window.open(url, "Share", sqShareOptions); + return false; + } if (network == 'twitter') { url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text); } @@ -1756,6 +1761,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; diff --git a/php/classes/class-qmn-plugin-helper.php b/php/classes/class-qmn-plugin-helper.php index 41da8402..cca0bd78 100644 --- a/php/classes/class-qmn-plugin-helper.php +++ b/php/classes/class-qmn-plugin-helper.php @@ -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'), diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 3ad6a341..11cd5c3f 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -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 .= "
quiz_name ) . "', '" . esc_js( $facebook_app_id ) . "');\">Facebookquiz_name ) . "');\">Twitter
"; + $qmn_social_media_text['linkedin'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['linkedin'], $qmn_array_for_variables ); + $social_display .= "
quiz_name ) . "', '" . esc_js( $facebook_app_id ) . "');\">Facebookquiz_name ) . "');\">Twitterquiz_name ) . "');\">Linkedin
"; } return apply_filters( 'qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables ); } diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index 6c1fa9d4..869207ef 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -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' ); @@ -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', diff --git a/php/classes/class-qsm-settings.php b/php/classes/class-qsm-settings.php index 07683343..2b112915 100644 --- a/php/classes/class-qsm-settings.php +++ b/php/classes/class-qsm-settings.php @@ -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, ); } @@ -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, diff --git a/php/template-variables.php b/php/template-variables.php index e03e0d3f..87caf677 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -312,6 +312,14 @@ function mlw_qmn_variable_social_share( $content, $mlw_quiz_array ) { $social_display = "" . __( "; $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 = "" . __( "; + $content = str_replace( '%LINKEDIN_SHARE%', $social_display, $content ); + } return $content; } From 3bf7b39bc985c02888db034b5b41d5746cb98dee Mon Sep 17 00:00:00 2001 From: manandeep singh Date: Wed, 27 Nov 2024 11:05:24 +0530 Subject: [PATCH 2/2] Linkedin share option --- js/qsm-quiz.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 2c13acc0..dfd9ac13 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1395,9 +1395,7 @@ function qmnSocialShare(network, mlw_qmn_social_text, mlw_qmn_title, facebook_id "&" + "description="; } if (network === 'linkedin') { - url = "https://www.linkedin.com/sharing/share-offsite?url=" + pageUrlEncoded; - window.open(url, "Share", sqShareOptions); - return false; + 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);