alertify.error(\"Incorrect Password, try again\")" : ""); $matthew_ppu = yourls__( "Password Protected URL", "matthew_pwp" ); // Translate Password Title $matthew_ph = yourls__( "Password" , "matthew_pwp" ); // Translate the word Password $matthew_sm = yourls__( "Please enter the password below to continue.", "matthew_pwp" ); // Translate the main message $matthew_submit = yourls__( "Send!" , "matthew_pwp" ); // Translate the Submit button // Displays main "Insert Password" area echo << Redirection Notice

$error PWP; die(); } } } // Register plugin page in admin page yourls_add_action( 'plugins_loaded', 'matthew_pwprotection_display_panel' ); function matthew_pwprotection_display_panel() { yourls_register_plugin_page( 'matthew_pwp', 'Password Protection', 'matthew_pwprotection_display_page' ); } // Function which will draw the admin page function matthew_pwprotection_display_page() { if( isset( $_POST[ 'checked' ] ) && isset( $_POST[ 'password' ] ) || isset( $_POST[ 'unchecked' ] ) ) { matthew_pwprotection_process_new(); matthew_pwprotection_process_display(); } else { if(yourls_get_option('matthew_pwprotection') !== false){ yourls_add_option( 'matthew_pwprotection', 'null' ); } matthew_pwprotection_process_display(); } } // Set/Delete password from DB function matthew_pwprotection_process_new() { // Verify nonce token. yourls_verify_nonce( "matthew_pwprotection_update" ); $matthew_pwprotection_array = json_decode(yourls_get_option('matthew_pwprotection'), true); foreach( $_POST[ 'password' ] as $url => $url_password) { if($url_password != "DONOTCHANGE_8fggwrFrRXvqndzw") { $_POST[ 'password' ][ $url ] = password_hash($url_password, PASSWORD_BCRYPT); } else { $_POST[ 'password' ][ $url ] = $matthew_pwprotection_array[ $url ]; } } // Update database yourls_update_option( 'matthew_pwprotection', json_encode( $_POST[ 'password' ] ) ); echo "

Success!

"; } // Display Form function matthew_pwprotection_process_display() { $ydb = yourls_get_db(); $table = YOURLS_DB_TABLE_URL; $sql = "SELECT * FROM `$table` WHERE 1=1"; $query = $ydb->fetchAll( $sql ); $matthew_su = yourls__( "Short URL" , "matthew_pwp" ); // Translate "Short URL" $matthew_ou = yourls__( "Original URL", "matthew_pwp" ); // Translate "Original URL" $matthew_pw = yourls__( "Password" , "matthew_pwp" ); // Translate "Password" // Protect action with nonce $matthew_pwprotection_noncefield = yourls_nonce_field( "matthew_pwprotection_update" ); echo << table { border-collapse: collapse; width: 100%; } th, td { text-align: left; padding: 8px; } tr:nth-child(even){background-color: #313131} tr:nth-child(odd){background-color: #232323}
TB; foreach( $query as $link ) { // Displays all shorturls in the YOURLS DB $short = $link["keyword"]; $url = $link["url"]; $matthew_pwprotection_array = json_decode(yourls_get_option('matthew_pwprotection'), true); // Get array of currently active Password Protected URLs if( strlen( $url ) > 51 ) { // If URL is too long, shorten it with '...' $sURL = substr( $url, 0, 30 ). "..."; } else { $sURL = $url; } if( array_key_exists( $short, (array)$matthew_pwprotection_array ) ){ // Check if URL is currently password protected or not $text = yourls__( "Enable?" ); $password = "DONOTCHANGE_8fggwrFrRXvqndzw"; $checked = " checked"; $unchecked = ''; $style = ''; $disabled = ''; } else { $text = yourls__( "Enable?" ); $password = ''; $checked = ''; $unchecked = ' disabled'; $style = 'display: none'; $disabled = ' disabled'; } echo <<
$matthew_su $matthew_ou $matthew_pw
TABLE; } echo << $matthew_pwprotection_noncefield END; } ?>
$short $sURL $text