Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul for 2.0 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
271 changes: 80 additions & 191 deletions protect-selected-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,200 +27,89 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

require 'psource/psource-plugin-update/plugin-update-checker.php';
$MyUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://n3rds.work//wp-update-server/?action=get_metadata&slug=protect-selected-content',
__FILE__,
'protect-selected-content'
);


class PartialPostPassword {

function __construct() {

//shortcodes
add_shortcode( 'protect', array(&$this, 'shortcode') );

//localize the plugin
add_action( 'plugins_loaded', array(&$this, 'localization') );

//handle cookie
add_action( 'wp_ajax_nopriv_psc-set', array(&$this, 'set_password') );
add_action( 'wp_ajax_psc-set', array(&$this, 'set_password') );

// TinyMCE options
add_action( 'wp_ajax_protectTinymceOptions', array(&$this, 'tinymce_options') );
add_action( 'admin_init', array(&$this, 'load_tinymce') );

//load dashboard notice
//include_once( 'dash-notice/wpmudev-dash-notification.php' );
}

function localization() {
// Load up the localization file if we're using WordPress in a different language
// Place it in this plugin's "languages" folder and name it "psc-[value in wp-config].mo"
load_plugin_textdomain('psc', false, dirname(plugin_basename(__FILE__)) . '/languages');
}

function shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'password' => false
), $atts ) );

//skip check for no content
if ( is_null( $content ) )
return;

//if no pass set don't protect
if ( !$password )
return do_shortcode( $content );

//check cookie for password
if ( isset( $_COOKIE['psc-postpass_' . COOKIEHASH] ) && $_COOKIE['psc-postpass_' . COOKIEHASH] == sha1( $password ) ) {
return do_shortcode( $content );
} else {
$label = 'pwbox-' . rand();
return '<form action="' . admin_url('admin-ajax.php') . '" method="post"><input type="hidden" name="action" value="psc-set" />
<p>' . __("Dieser Inhalt ist passwortgeschützt. Um es anzuzeigen, gib bitte unten Dein Passwort ein:", 'psc') . '</p>
<p><label for="' . $label . '">' . __("Passwort:", 'psc') . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Entsperren", 'psc') . '" /></p>
</form>
';
}
}

function set_password() {

if ( get_magic_quotes_gpc() )
$_POST['post_password'] = stripslashes( $_POST['post_password'] );

//set cookie for 10 days
setcookie( 'psc-postpass_' . COOKIEHASH, sha1( $_POST['post_password'] ), time() + 864000, COOKIEPATH );

//jump back to post
wp_safe_redirect( wp_get_referer() );
exit;
function __construct() {

// Shortcodes
add_shortcode( 'protect', array(&$this, 'shortcode') );

// Localize the plugin
add_action( 'plugins_loaded', array(&$this, 'localization') );

// Handle cookie
add_action( 'wp_ajax_nopriv_psc-set', array(&$this, 'set_password') );
add_action( 'wp_ajax_psc-set', array(&$this, 'set_password') );

// Add Shortcode Button
if ( current_user_can('edit_posts') && current_user_can('edit_pages') ) {
add_filter('mce_external_plugins', array(&$this, 'add_shortcode_button_plugin'));
add_filter('mce_buttons', array(&$this, 'register_shortcode_button'));
}
}

function load_tinymce() {
if ( (current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing') == 'true') {
add_filter( 'mce_external_plugins', array(&$this, 'tinymce_add_plugin') );
add_filter( 'mce_buttons', array(&$this,'tinymce_register_button') );
add_filter( 'mce_external_languages', array(&$this,'tinymce_load_langs') );
}
}

/**
* TinyMCE dialog content
*/
function tinymce_options() {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
/**
* TODO: We are including our own copy of tiny_mce_popup.js until this issue is resolved in the core file: https://core.trac.wordpress.org/ticket/41124
*/
?>
<script type="text/javascript"
src="<?php echo plugins_url(dirname(plugin_basename(__FILE__)) . '/tinymce/tiny_mce_popup.js'); ?>">
</script>
<script type="text/javascript" src="../wp-includes/js/tinymce/utils/form_utils.js?ver=327-1235"></script>
<script type="text/javascript" src="../"></script>

<script type="text/javascript" src="../wp-includes/js/jquery/jquery.js"></script>

<script type="text/javascript">

tinyMCEPopup.storeSelection();

var insertProtect = function (ed) {
var password = jQuery.trim(jQuery('#psc-password').val());
if (!password) {
jQuery('#psc-error').show();
jQuery('#psc-password').focus();
return false;
}
tinyMCEPopup.restoreSelection();
output = '[protect password="'+password+'"]'+tinyMCEPopup.editor.selection.getContent()+'[/protect]';

tinyMCEPopup.execCommand('mceInsertContent', 0, output);
tinyMCEPopup.editor.execCommand('mceRepaint');
tinyMCEPopup.editor.focus();
// Return
tinyMCEPopup.close();
};
</script>
<style type="text/css">
td.info {
vertical-align: top;
color: #777;
}
</style>

<title><?php _e("Inhalt mit Passwort schützen", 'psc'); ?></title>
</head>
<body style="display: none">
<form onsubmit="insertProtect();return false;" action="#">

<div id="general_panel" class="panel current">
<div id="psc-error" style="display: none; color:#C00;padding: 2px 0;"><?php _e("Bitte Passwort eingeben!", 'psc'); ?></div>
<fieldset>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td><label for="chat_width"><?php _e("Passwort", 'psc'); ?></label></td>
<td>
<input type="text" id="psc-password" name="psc-password" value="" class="size" size="15" />
</td>
<td class="info"><?php _e("Gib ein Passwort ein, das auf den ausgewählten Inhalt angewendet werden soll.", 'psc'); ?></td>
</tr>
</table>
</fieldset>
</div>

<div class="mceActionPanel">
<div style="float: left">
<input type="button" id="cancel" name="cancel" value="<?php _e("Abbrechen", 'psc'); ?>" onclick="tinyMCEPopup.close();" />
</div>

<div style="float: right">
<input type="submit" id="insert" name="insert" value="<?php _e("Einfügen", 'psc'); ?>" />
</div>
</div>
</form>
</body>
</html>
<?php
exit(0);
}

/**
* @see http://codex.wordpress.org/TinyMCE_Custom_Buttons
*/
function tinymce_register_button($buttons) {
array_push($buttons, "separator", "protect");
return $buttons;
}

/**
* @see http://codex.wordpress.org/TinyMCE_Custom_Buttons
*/
function tinymce_load_langs($langs) {
$langs["protect"] = plugins_url(dirname(plugin_basename(__FILE__)) . '/tinymce/langs/langs.php');
return $langs;

function localization() {
// Load up the localization file if we're using WordPress in a different language
// Place it in this plugin's "languages" folder and name it "psc-[value in wp-config].mo"
load_plugin_textdomain('psc', false, dirname(plugin_basename(__FILE__)) . '/languages');
}

function shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'password' => false
), $atts ) );

// Skip check for no content
if ( is_null( $content ) )
return;

// If no password set, don't protect
if ( !$password )
return do_shortcode( $content );

// Check cookie for password
if ( isset( $_COOKIE['psc-postpass_' . COOKIEHASH] ) && $_COOKIE['psc-postpass_' . COOKIEHASH] == sha1( $password ) ) {
return do_shortcode( $content );
} else {
$label = 'pwbox-' . rand();
return '<form action="' . admin_url('admin-ajax.php') . '" method="post"><input type="hidden" name="action" value="psc-set" />
<p>' . __("Dieser Inhalt ist passwortgeschützt. Um ihn anzuzeigen, gib bitte unten dein Passwort ein:", 'psc') . '</p>
<p><label for="' . $label . '">' . __("Passwort:", 'psc') . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Entsperren", 'psc') . '" /></p>
</form>
';
}
}

function register_shortcode_button($buttons) {
array_push($buttons, "separator", "protect");
return $buttons;
}

function add_shortcode_button_plugin($plugin_array) {
$plugin_array['protect'] = plugins_url('shortcode-button.js', __FILE__);
return $plugin_array;
}

function set_password() {

if ( function_exists( 'stripslashes_deep' ) ) {
$_POST = stripslashes_deep( $_POST );
}

// Set cookie for 10 days
setcookie( 'psc-postpass_' . COOKIEHASH, sha1( $_POST['post_password'] ), time() + 864000, COOKIEPATH );

// Jump back to post
wp_safe_redirect( wp_get_referer() );
exit;
}

} //end class

function initialize_partial_post_password() {
$psc = new PartialPostPassword();
}

add_action('init', 'initialize_partial_post_password');

/**
* @see http://codex.wordpress.org/TinyMCE_Custom_Buttons
*/
function tinymce_add_plugin($plugin_array) {
$plugin_array['protect'] = plugins_url(dirname(plugin_basename(__FILE__)) . '/tinymce/editor_plugin.js');
return $plugin_array;
}

} //end class

//load class
$psc = new PartialPostPassword();
23 changes: 23 additions & 0 deletions shortcode-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {
tinymce.PluginManager.add('protect', function(editor, url) {
editor.addButton('protect', {
text: 'Protect Content',
icon: false, // You can set an icon here if needed
onclick: function() {
editor.windowManager.open({
title: 'Insert Protect Shortcode',
body: [
{
type: 'textbox',
name: 'password',
label: 'Password'
}
],
onsubmit: function(e) {
editor.insertContent('[protect password="' + e.data.password + '"]' + editor.selection.getContent() + '[/protect]');
}
});
}
});
});
})();
73 changes: 0 additions & 73 deletions tinymce/editor_plugin.js

This file was deleted.

3 changes: 0 additions & 3 deletions tinymce/langs/de_dlg.js

This file was deleted.

12 changes: 0 additions & 12 deletions tinymce/langs/langs.php

This file was deleted.

Loading
Loading