diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 120000 index 0000000..0d79d56 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +readme.txt \ No newline at end of file diff --git a/css/error-recovery.css b/css/error-recovery.css new file mode 100644 index 0000000..a0e0508 --- /dev/null +++ b/css/error-recovery.css @@ -0,0 +1,112 @@ +#sm-fatal-error-notice.loading { + position: relative; } + #sm-fatal-error-notice.loading #sm-curtain { + width: 100%; + height: 100%; + background: #ffffff; + opacity: .7; } + #sm-fatal-error-notice.loading #sm-spinner { + opacity: 1; } + +#sm-curtain { + position: absolute; + top: 0; + left: 0; + opacity: 0; + background: transparent; + transition: opacity .5s; } + #sm-curtain.dialog { + transition: none; + position: fixed; + z-index: 99999; + background: #fff; + opacity: .8; + width: 100%; + height: 100%; } + +#sm-spinner { + z-index: 10; + position: absolute; + top: 50%; + transform: translate(-50%, -50%); + left: 50%; + opacity: 0; + transition: opacity 1s; } + +#sm-disable-recovery-notice { + color: #e29300; } + #sm-disable-recovery-notice > a { + color: #a26300; } + +#sm-error { + background-color: #01354e; + color: #ffffff; + padding: .5rem; } + +.ui-dialog { + box-shadow: 0 -2px 25px 0 rgba(0, 0, 0, 0.15), 0 13px 25px 0 rgba(0, 0, 0, 0.3); + background-color: #FFFFFF; + margin: 0 auto; + width: auto; + height: auto; + border-radius: 2px 2px 0 0; + padding: 21px 24px 12px; + z-index: 100000; } + +.ui-dialog-titlebar { + font-family: 'Roboto', sans-serif; + font-weight: 500; + font-size: 20px; + color: rgba(0, 0, 0, 0.8); + line-height: 24px; + text-align: left; + letter-spacing: 0.03px; } + +.ui-dialog-content { + font-size: 13px; + color: rgba(0, 0, 0, 0.5); + line-height: 24px; + text-align: left; + letter-spacing: 0.03px; + padding: 14px 0 0; } + .ui-dialog-content textarea, .ui-dialog-content input[type="email"] { + width: 100%; } + +.ui-dialog-titlebar-close { + display: none; } + +.ui-dialog-buttonpane { + width: auto; + height: 48px; + background-color: #FFFFFF; + text-align: right; + border-radius: 0 0 2px 2px; + padding: 8px 0 0 16px; } + +.ui-dialog-buttonset > button { + display: inline-block; + height: 36px; + background-color: rgba(9, 9, 9, 0); + font-weight: 500; + font-size: 16px; + color: rgba(33, 150, 243, 0.9); + line-height: 36px; + text-align: center; + letter-spacing: 0.4px; + padding: 0 8px; + margin: 6px 4px; + text-transform: uppercase; + outline: none; + border: none; + cursor: pointer; + transition: all 0.2s ease; } + .ui-dialog-buttonset > button:last-child { + margin-right: 0; } + +.ui-dialog-buttonset > button:hover { + background-color: rgba(99, 99, 99, 0.2); } + +.ui-dialog-buttonset > button:active { + background-color: rgba(99, 99, 99, 0.4); } + +/*# sourceMappingURL=error-recovery.css.map */ diff --git a/css/error-recovery.css.map b/css/error-recovery.css.map new file mode 100644 index 0000000..d2b0bb1 --- /dev/null +++ b/css/error-recovery.css.map @@ -0,0 +1,7 @@ +{ +"version": 3, +"mappings": "AAAA,8BAA+B;EAC7B,QAAQ,EAAE,QAAQ;EAElB,0CAAY;IACV,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,OAAO;IACnB,OAAO,EAAE,EAAE;EAGb,0CAAY;IACV,OAAO,EAAE,CAAC;;AAId,WAAY;EACV,QAAQ,EAAE,QAAQ;EAClB,GAAG,EAAE,CAAC;EACN,IAAI,EAAE,CAAC;EACP,OAAO,EAAE,CAAC;EACV,UAAU,EAAE,WAAW;EACvB,UAAU,EAAE,WAAW;EAEvB,kBAAS;IACP,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,EAAE;IACX,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;;AAIhB,WAAY;EACV,OAAO,EAAE,EAAE;EACX,QAAQ,EAAE,QAAQ;EAClB,GAAG,EAAE,GAAG;EACR,SAAS,EAAE,qBAAqB;EAChC,IAAI,EAAE,GAAG;EACT,OAAO,EAAE,CAAC;EACV,UAAU,EAAE,UAAU;;AAGxB,2BAA4B;EAC1B,KAAK,EAAE,OAAO;EAEd,+BAAI;IACF,KAAK,EAAE,OAAO;;AAIlB,SAAU;EACR,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,OAAO;EACd,OAAO,EAAE,KAAK;;AAGhB,UAAW;EACT,UAAU,EAAE,mEAAmE;EAC/E,gBAAgB,EAAE,OAAO;EACzB,MAAM,EAAE,MAAM;EACd,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;EACZ,aAAa,EAAE,WAAW;EAC1B,OAAO,EAAE,cAAc;EACvB,OAAO,EAAE,MAAM;;AAGjB,mBAAoB;EAClB,WAAW,EAAE,oBAAoB;EACjC,WAAW,EAAE,GAAG;EAChB,SAAS,EAAE,IAAI;EACf,KAAK,EAAE,kBAAiB;EACxB,WAAW,EAAE,IAAI;EACjB,UAAU,EAAE,IAAI;EAChB,cAAc,EAAE,MAAM;;AAGxB,kBAAmB;EACjB,SAAS,EAAE,IAAI;EACf,KAAK,EAAE,kBAAiB;EACxB,WAAW,EAAE,IAAI;EACjB,UAAU,EAAE,IAAI;EAChB,cAAc,EAAE,MAAM;EACtB,OAAO,EAAE,QAAQ;EAEjB,mEAA8B;IAC5B,KAAK,EAAE,IAAI;;AAIf,yBAA0B;EACxB,OAAO,EAAE,IAAI;;AAGf,qBAAsB;EACpB,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;EACZ,gBAAgB,EAAE,OAAO;EACzB,UAAU,EAAE,KAAK;EACjB,aAAa,EAAE,WAAW;EAC1B,OAAO,EAAE,YAAY;;AAGvB,6BAA8B;EAC5B,OAAO,EAAE,YAAY;EACrB,MAAM,EAAE,IAAI;EACZ,gBAAgB,EAAE,gBAAgB;EAClC,WAAW,EAAE,GAAG;EAChB,SAAS,EAAE,IAAI;EACf,KAAK,EAAE,uBAAuB;EAC9B,WAAW,EAAE,IAAI;EACjB,UAAU,EAAE,MAAM;EAClB,cAAc,EAAE,KAAK;EACrB,OAAO,EAAE,KAAK;EACd,MAAM,EAAE,OAAO;EACf,cAAc,EAAE,SAAS;EACzB,OAAO,EAAE,IAAI;EACb,MAAM,EAAE,IAAI;EACZ,MAAM,EAAE,OAAO;EACf,UAAU,EAAE,aAAa;EAEzB,wCAAa;IACX,YAAY,EAAE,CAAC;;AAInB,mCAAoC;EAClC,gBAAgB,EAAE,qBAAqB;;AAGzC,oCAAqC;EACnC,gBAAgB,EAAE,qBAAqB", +"sources": ["error-recovery.scss"], +"names": [], +"file": "error-recovery.css" +} \ No newline at end of file diff --git a/css/error-recovery.scss b/css/error-recovery.scss new file mode 100644 index 0000000..30ddda4 --- /dev/null +++ b/css/error-recovery.scss @@ -0,0 +1,135 @@ +#sm-fatal-error-notice.loading { + position: relative; + + #sm-curtain { + width: 100%; + height: 100%; + background: #ffffff; + opacity: .7; + } + + #sm-spinner { + opacity: 1; + } +} + +#sm-curtain { + position: absolute; + top: 0; + left: 0; + opacity: 0; + background: transparent; + transition: opacity .5s; + + &.dialog { + transition: none; + position: fixed; + z-index: 99999; + background: #fff; + opacity: .8; + width: 100%; + height: 100%; + } +} + +#sm-spinner { + z-index: 10; + position: absolute; + top: 50%; + transform: translate(-50%, -50%); + left: 50%; + opacity: 0; + transition: opacity 1s; +} + +#sm-disable-recovery-notice { + color: #e29300; + + > a { + color: #a26300 + } +} + +#sm-error { + background-color: #01354e; + color: #ffffff; + padding: .5rem; +} + +.ui-dialog { + box-shadow: 0 -2px 25px 0 rgba(0, 0, 0, 0.15), 0 13px 25px 0 rgba(0, 0, 0, 0.3); + background-color: #FFFFFF; + margin: 0 auto; + width: auto; + height: auto; + border-radius: 2px 2px 0 0; + padding: 21px 24px 12px; + z-index: 100000; +} + +.ui-dialog-titlebar { + font-family: 'Roboto', sans-serif; + font-weight: 500; + font-size: 20px; + color: rgba(0, 0, 0, .8); + line-height: 24px; + text-align: left; + letter-spacing: 0.03px; +} + +.ui-dialog-content { + font-size: 13px; + color: rgba(0, 0, 0, .5); + line-height: 24px; + text-align: left; + letter-spacing: 0.03px; + padding: 14px 0 0; + + textarea, input[type="email"] { + width: 100%; + } +} + +.ui-dialog-titlebar-close { + display: none; +} + +.ui-dialog-buttonpane { + width: auto; + height: 48px; + background-color: #FFFFFF; + text-align: right; + border-radius: 0 0 2px 2px; + padding: 8px 0 0 16px; +} + +.ui-dialog-buttonset > button { + display: inline-block; + height: 36px; + background-color: rgba(9, 9, 9, 0); + font-weight: 500; + font-size: 16px; + color: rgba(33, 150, 243, 0.9); + line-height: 36px; + text-align: center; + letter-spacing: 0.4px; + padding: 0 8px; + margin: 6px 4px; + text-transform: uppercase; + outline: none; + border: none; + cursor: pointer; + transition: all 0.2s ease; + + &:last-child { + margin-right: 0; + } +} + +.ui-dialog-buttonset > button:hover { + background-color: rgba(99, 99, 99, 0.2); +} + +.ui-dialog-buttonset > button:active { + background-color: rgba(99, 99, 99, 0.4); +} diff --git a/css/sermon.css b/css/sermon.css index 99ebae7..630222a 100755 --- a/css/sermon.css +++ b/css/sermon.css @@ -139,6 +139,10 @@ display: block; } +.widget_recent_sermons .meta > span { + display: inline; +} + #sermon-navigation { padding-bottom: 15px; } diff --git a/includes/CMB2/includes/types/CMB2_Type_Text_Date.php b/includes/CMB2/includes/types/CMB2_Type_Text_Date.php index 327cfd0..cfd95f7 100755 --- a/includes/CMB2/includes/types/CMB2_Type_Text_Date.php +++ b/includes/CMB2/includes/types/CMB2_Type_Text_Date.php @@ -17,9 +17,10 @@ class CMB2_Type_Text_Date extends CMB2_Type_Picker_Base { public function render() { $args = $this->parse_args( 'text_date', array( 'class' => 'cmb2-text-small cmb2-datepicker', - 'value' => $this->field->get_timestamp_format(), + 'value' => isset( $_GET['post'] ) ? ( get_post_meta( $_GET['post'], 'sermon_date_auto', true ) ? '' : $this->field->get_timestamp_format() ) : '', 'desc' => $this->_desc(), 'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ), + 'placeholder' => isset( $_GET['post'] ) ? ( get_post_meta( $_GET['post'], 'sermon_date_auto', true ) ? $this->field->get_timestamp_format() : '' ) : $this->field->get_timestamp_format( 'date_format', time() ), ) ); if ( false === strpos( $args['class'], 'timepicker' ) ) { diff --git a/includes/admin-functions.php b/includes/admin-functions.php index a7f993a..b385dcb 100755 --- a/includes/admin-functions.php +++ b/includes/admin-functions.php @@ -121,19 +121,19 @@ function wpfc_sermon_updated_messages( $messages ) { $messages['wpfc_sermon'] = array( 0 => '', // Unused. Messages start at index 1. - 1 => sprintf( __( 'Sermon updated. View sermon', 'sermon-manager' ), esc_url( get_permalink( $post_ID ) ) ), - 2 => __( 'Custom field updated.', 'sermon-manager' ), - 3 => __( 'Custom field deleted.', 'sermon-manager' ), - 4 => __( 'Sermon updated.', 'sermon-manager' ), + 1 => sprintf( __( 'Sermon updated. View sermon', 'sermon-manager-for-wordpress' ), esc_url( get_permalink( $post_ID ) ) ), + 2 => __( 'Custom field updated.', 'sermon-manager-for-wordpress' ), + 3 => __( 'Custom field deleted.', 'sermon-manager-for-wordpress' ), + 4 => __( 'Sermon updated.', 'sermon-manager-for-wordpress' ), /* translators: %s: date and time of the revision */ - 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Sermon restored to revision from %s', 'sermon-manager' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, - 6 => sprintf( __( 'Sermon published. View sermon', 'sermon-manager' ), esc_url( get_permalink( $post_ID ) ) ), - 7 => __( 'Sermon saved.', 'sermon-manager' ), - 8 => sprintf( __( 'Sermon submitted. Preview sermon', 'sermon-manager' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), - 9 => sprintf( __( 'Sermon scheduled for: %1$s. Preview sermon', 'sermon-manager' ), + 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Sermon restored to revision from %s', 'sermon-manager-for-wordpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, + 6 => sprintf( __( 'Sermon published. View sermon', 'sermon-manager-for-wordpress' ), esc_url( get_permalink( $post_ID ) ) ), + 7 => __( 'Sermon saved.', 'sermon-manager-for-wordpress' ), + 8 => sprintf( __( 'Sermon submitted. Preview sermon', 'sermon-manager-for-wordpress' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), + 9 => sprintf( __( 'Sermon scheduled for: %1$s. Preview sermon', 'sermon-manager-for-wordpress' ), // translators: Publish box date format, see http://php.net/date - date_i18n( __( 'M j, Y @ G:i', 'sermon-manager' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), - 10 => sprintf( __( 'Sermon draft updated. Preview sermon', 'sermon-manager' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), + date_i18n( __( 'M j, Y @ G:i', 'sermon-manager-for-wordpress' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), + 10 => sprintf( __( 'Sermon draft updated. Preview sermon', 'sermon-manager-for-wordpress' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), ); return $messages; @@ -186,13 +186,14 @@ function wpfc_sermon_order( $vars ) { function wpfc_sermon_edit_columns() { $columns = array( "cb" => "", - "title" => __( 'Sermon Title', 'sermon-manager' ), - "preacher" => __( \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher', 'sermon-manager' ), - "series" => __( 'Sermon Series', 'sermon-manager' ), - "topics" => __( 'Topics', 'sermon-manager' ), - "views" => __( 'Views', 'sermon-manager' ), - "preached" => __( 'Date Preached', 'sermon-manager' ), - "passage" => __( 'Bible Passage', 'sermon-manager' ), + "title" => __( 'Sermon Title', 'sermon-manager-for-wordpress' ), + /* Translators: %s: Preacher label (sentence case; singular) */ + "preacher" => sprintf( __( '%s', 'sermon-manager-for-wordpress' ), ucwords(\SermonManager::getOption( 'preacher_label' ) ) ?: 'Preacher' ), + "series" => __( 'Sermon Series', 'sermon-manager-for-wordpress' ), + "topics" => __( 'Topics', 'sermon-manager-for-wordpress' ), + "views" => __( 'Views', 'sermon-manager-for-wordpress' ), + "preached" => __( 'Date Preached', 'sermon-manager-for-wordpress' ), + "passage" => __( 'Bible Passage', 'sermon-manager-for-wordpress' ), ); return $columns; diff --git a/includes/class-sm-api.php b/includes/class-sm-api.php new file mode 100644 index 0000000..5ec785c --- /dev/null +++ b/includes/class-sm-api.php @@ -0,0 +1,147 @@ +data; + + $post_meta = wp_parse_args( get_post_meta( $data['id'] ), array( + 'sermon_audio' => array( '' ), + '_wpfc_sermon_duration' => array( '' ), + 'Views' => array( '' ), + 'bible_passage' => array( '' ), + 'sermon_description' => array( '' ), + 'sermon_video' => array( '' ), + 'sermon_video_link' => array( '' ), + 'sermon_bulletin' => array( '' ), + '_thumbnail_id' => array( '' ), + 'sermon_date_auto' => array( '' ), + ) ); + + $data['sermon_audio'] = $post_meta['sermon_audio'][0]; + $data['sermon_audio_duration'] = $post_meta['_wpfc_sermon_duration'][0]; + $data['_views'] = $post_meta['Views'][0]; + $data['bible_passage'] = $post_meta['bible_passage'][0]; + $data['sermon_description'] = $post_meta['sermon_description'][0]; + $data['sermon_video_embed'] = $post_meta['sermon_video'][0]; + $data['sermon_video_url'] = $post_meta['sermon_video_link'][0]; + $data['sermon_bulletin'] = $post_meta['sermon_bulletin'][0]; + $data['_featured_url'] = wp_get_attachment_url( $post_meta['_thumbnail_id'][0] ); + + if ( $date = SM_Dates::get( 'U', $data['id'] ) ) { + $data['sermon_date'] = intval( $date ); + $data['_sermon_date_auto'] = $post_meta['sermon_date_auto'][0] == 1 ? true : false; + } + + return $response; + } +} + +new SM_API(); \ No newline at end of file diff --git a/includes/class-sm-dates-wp.php b/includes/class-sm-dates-wp.php index 572050d..94e207b 100644 --- a/includes/class-sm-dates-wp.php +++ b/includes/class-sm-dates-wp.php @@ -1,4 +1,6 @@ post_date; + $GLOBALS['sm_original_sermon_date'] = get_post_meta( $post_ID, 'sermon_date', true ); + } + } + + /** + * Sets/updates date for posts if they are not user-defined + * + * @param int $post_ID Post ID. + * @param WP_Post $post Post object. + * @param bool $update Whether this is an existing post being updated or not. + * + * @since 2.7 + */ + public static function maybe_update_date( $post_ID, $post, $update ) { + $update_date = $auto = false; + + if ( $update ) { + // compare sermon date and if user changed it update sermon date and disable auto update + if ( ! empty( $GLOBALS['sm_original_sermon_date'] ) && ! empty( $_POST['sermon_date'] ) ) { + $dt = DateTime::createFromFormat( SermonManager::getOption( 'date_format' ) ?: 'm/d/Y', $_POST['sermon_date'] ); + if ( $dt instanceof DateTime && $dt->format( 'U' ) != $GLOBALS['sm_original_sermon_date'] ) { + update_post_meta( $post_ID, 'sermon_date_auto', 0 ); + } + } + + // compare published date and if user changed it update sermon date if auto update is set + if ( ! empty( $GLOBALS['sm_original_published_date'] ) ) { + if ( $post->post_date !== $GLOBALS['sm_original_published_date'] && + get_post_meta( $post_ID, 'sermon_date_auto', true ) == 1 ) { + $update_date = true; + } + } + } + + // if sermon date is blank (not set on sermon create or removed later on update), mark + // this post for auto updating and update date now + if ( isset( $_POST['sermon_date'] ) && $_POST['sermon_date'] == '' ) { + $update_date = true; + $auto = true; + } + + // if marked for date updating + if ( $update_date ) { + update_post_meta( $post_ID, 'sermon_date', mysql2date( 'U', $post->post_date ) ); + add_filter( 'cmb2_override_sermon_date_meta_save', '__return_true' ); + add_filter( 'cmb2_override_sermon_date_meta_remove', '__return_true' ); + } + + // if we should set it for auto date updating + if ( $auto ) { + update_post_meta( $post_ID, 'sermon_date_auto', '1' ); + } } } \ No newline at end of file diff --git a/includes/class-sm-dates.php b/includes/class-sm-dates.php index 646ad36..95b8864 100644 --- a/includes/class-sm-dates.php +++ b/includes/class-sm-dates.php @@ -1,4 +1,5 @@ post_date_gmt ) ); + $dt = DateTime::createFromFormat( 'U', mysql2date( 'U', $post->post_date ) ); $time = array( $dt->format( 'H' ), - $dt->format( 'm' ), + $dt->format( 'i' ), $dt->format( 's' ) ); diff --git a/includes/class-sm-error-recovery.php b/includes/class-sm-error-recovery.php new file mode 100644 index 0000000..b9a2b76 --- /dev/null +++ b/includes/class-sm-error-recovery.php @@ -0,0 +1,309 @@ +query( $sql ); + if ( $result->num_rows === 0 ) { + $sql = "INSERT INTO {$table_prefix}options (option_name, option_value, autoload) VALUES ('_sm_recovery_do_not_catch', '0', 'yes')"; + } else { + $sql = "UPDATE {$table_prefix}options SET option_value = '0' WHERE option_name = '_sm_recovery_do_not_catch'"; + } + $mysqli->query( $sql ); + } + + $sql = "SELECT option_value FROM {$table_prefix}options WHERE option_name = '_sm_recovery_do_not_catch'"; + $result = $mysqli->query( $sql ); + if ( $result->num_rows === 0 ) { + $does_not_exist = true; + $sm_do_not_catch = false; + } else { + $result = $result->fetch_assoc(); + $sm_do_not_catch = $result['option_value'] == 1; + } + + if ( $sm_do_not_catch ) { + return; + } + + self::$_error = error_get_last(); + + if ( self::_is_fatal() ) { + // check if it's caused by SM + self::_update_db(); + + if ( ! empty( $does_not_exist ) ) { + $sql = "INSERT INTO {$table_prefix}options (option_name, option_value, autoload) VALUES ('_sm_recovery_do_not_catch', '1', 'yes')"; + } else { + $sql = "UPDATE {$table_prefix}options SET option_value = '1' WHERE option_name = '_sm_recovery_do_not_catch'"; + } + $mysqli->query( $sql ); + + $headers = get_headers( get_site_url() ); + if ( substr( $headers[0], 9, 3 ) == 500 ) { + self::reset_db(); + } + + $mysqli->query( "UPDATE {$table_prefix}options SET option_value = '0' WHERE option_name = '_sm_recovery_do_not_catch'" ); + } + } + + /** + * Checks if PHP error is fatal + * + * @access private + * + * @return bool True if it is, false otherwise + */ + private static function _is_fatal() { + return in_array( self::$_error['type'], self::$_catch_errors ); + } + + /** + * Prevents Sermon Manager from running and saves error message for displaying + * + * @access private + */ + private static function _update_db() { + global $table_prefix; + $mysqli = new mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME ); + + // check if set + $sql = "SELECT option_id FROM {$table_prefix}options WHERE option_name = '_sm_recovery_disable'"; + $result = $mysqli->query( $sql ); + if ( $result->num_rows === 0 ) { + $sql = "INSERT INTO {$table_prefix}options (option_name, option_value, autoload) VALUES ('_sm_recovery_disable', '1', 'yes')"; + } else { + $sql = "UPDATE {$table_prefix}options SET option_value = '1' WHERE option_name = '_sm_recovery_disable'"; + } + $mysqli->query( $sql ); + + // check if set + $sql = "SELECT option_id FROM {$table_prefix}options WHERE option_name = '_sm_recovery_last_fatal_error'"; + $result = $mysqli->query( $sql ); + if ( $result->num_rows === 0 ) { + $sql = "INSERT INTO {$table_prefix}options (option_name, option_value, autoload) VALUES ('_sm_recovery_last_fatal_error', '" . $mysqli->real_escape_string( self::_get_message() ) . "', 'yes')"; + } else { + $sql = "UPDATE {$table_prefix}options SET option_value = '" . $mysqli->real_escape_string( self::_get_message() ) . "' WHERE option_name = '_sm_recovery_last_fatal_error'"; + } + $mysqli->query( $sql ); + } + + /** + * Gets PHP error message + * + * @access private + * + * @return string + */ + private static function _get_message() { + return self::$_error['message']; + } + + /** + * Allows Sermon Manager to run again, called on plugin update or by user + */ + public static function reset_db() { + global $table_prefix; + $mysqli = new mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME ); + + // check if set + $sql = "SELECT option_id FROM {$table_prefix}options WHERE option_name = '_sm_recovery_disable'"; + $result = $mysqli->query( $sql ); + if ( $result->num_rows === 0 ) { + $sql = "INSERT INTO {$table_prefix}options (option_name, option_value, autoload) VALUES ('_sm_recovery_disable', '0', 'yes')"; + } else { + $sql = "UPDATE {$table_prefix}options SET option_value = '0' WHERE option_name = '_sm_recovery_disable'"; + } + + $mysqli->query( $sql ); + } + + /** + * Displays WordPress admin error message + */ + public static function render_admin_message() { + $plugin_name = get_plugin_data( constant( self::$_plugin_main_file ) )['Name']; + $old_error = get_option( '_sm_recovery_last_fatal_error_hash' ) === md5( get_option( '_sm_recovery_last_fatal_error' ) ); + + ?> +
+ + = sprintf( __( '%s encountered a fatal error and recovered successfully.', 'sermon-manager-for-wordpress' ), $plugin_name ) ?> + + + = __( 'The issue has already been submitted.', 'sermon-manager-for-wordpress' ) ?> +
++ + + = _x( 'Send an anonymous report', 'Button', 'sermon-manager-for-wordpress' ) ?> + + + + = _x( 'Show error message', 'Button', 'sermon-manager-for-wordpress' ) ?> + + + = _x( 'Reactivate Plugin', 'Button', 'sermon-manager-for-wordpress' ) ?> + +
+ + + + + +