Starting rewrite

parent 520e3bb5
...@@ -11,7 +11,7 @@ remember to do, mostly little refinery. ...@@ -11,7 +11,7 @@ remember to do, mostly little refinery.
------------------------------------- -------------------------------------
SOON OR LATER this plugin will be re-written to make some order and re-group SOON this plugin will be re-written to make some order and re-group
action, filters and so on with a better organizations of classes, hooks etc, action, filters and so on with a better organizations of classes, hooks etc,
and then the initialization will be re-done from scratch removing the "sub plugin selection" and then the initialization will be re-done from scratch removing the "sub plugin selection"
while we will remove dependencies from woocommerce, pms and the rest. while we will remove dependencies from woocommerce, pms and the rest.
......
<?php
namespace wp_SexHackMe;
if(!class_exists('TemplateClass')) {
class TemplateClass
{
public function __construct()
{
sexhack_log('TemplateClass() Instanced');
}
}
}
$SEXHACK_SECTION = array(
'class' => 'TemplateClass',
'description' => 'Describe me',
'name' => 'sexhackme_template_name'
);
?>
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
@media screen and (min-width: 768px) { @media screen and (min-width: 768px) {
.col-full {
max-width: 85em;
}
.storefront-breadcrumb { .storefront-breadcrumb {
padding: 0.5em 0em; padding: 0.5em 0em;
margin: 0 0 0.7em; margin: 0 0 0.7em;
......
...@@ -128,9 +128,11 @@ if(!class_exists('SexHackVideoGallery')) { ...@@ -128,9 +128,11 @@ if(!class_exists('SexHackVideoGallery')) {
add_action('wp_enqueue_scripts', array( $this, 'add_css' ), 200); add_action('wp_enqueue_scripts', array( $this, 'add_css' ), 200);
add_shortcode("sexgallery", array($this, "sexgallery_shortcode")); add_shortcode("sexgallery", array($this, "sexgallery_shortcode"));
add_action('init', array($this, "register_sexhack_video_post_type")); add_action('init', array($this, "register_sexhack_video_post_type"));
//add_action('add_meta_boxes', array($this, "sexhack_video_metaboxes"));
add_action('admin_init', array($this, "register_settings")); add_action('admin_init', array($this, "register_settings"));
//add_filter('page_template', array($this, 'sexhack_video_template')); //add_filter('page_template', array($this, 'sexhack_video_template'));
add_filter('archive_template', array($this, 'sexhack_video_template')); add_filter('archive_template', array($this, 'sexhack_video_template'));
add_action('save_post', array($this, 'save_sexhack_video_meta_box_data' ));
add_action('pre_get_posts', array($this, 'fix_video_query'), 1, 1); add_action('pre_get_posts', array($this, 'fix_video_query'), 1, 1);
sexhack_log('SexHackVideoGallery() Instanced'); sexhack_log('SexHackVideoGallery() Instanced');
...@@ -231,19 +233,32 @@ if(!class_exists('SexHackVideoGallery')) { ...@@ -231,19 +233,32 @@ if(!class_exists('SexHackVideoGallery')) {
sexhack_log("REGISTER SEXHACK_VIDEO "); sexhack_log("REGISTER SEXHACK_VIDEO ");
register_post_type('sexhack_video', array( register_post_type('sexhack_video', array(
'label' => 'Sexhack.me Video','description' => '', 'labels' => array(
'name' => 'Videos',
'singular_name' => 'Video',
'add_new' => 'Add New',
'add_new_item' => 'Add New Video',
'edit_item' => 'Edit Video',
'not_found' => 'There are no videos yet',
'not_found_in_trash' => 'Nothing found in Trash',
'search_items' => 'Search videos',
),
'description' => 'Videos for SexHack.me gallery',
'public' => true, 'public' => true,
'register_meta_box_cb' => array($this, 'sexhack_video_metaboxes'),
'show_ui' => true, 'show_ui' => true,
'show_in_menu' => false, // Visibility in admin menu. 'show_in_menu' => true,
'capability_type' => 'post', 'show_in_rest' => true,
'hierarchical' => false, 'menu_position' => 32,
'capability_type' => 'post', // XXX We should create our own cap type?
// 'capabilities' => array(), // Or just select specific capabilities here
'hierarchical' => true,
'publicly_queryable' => true, 'publicly_queryable' => true,
'rewrite' => false, 'rewrite' => false,
'query_var' => true, 'query_var' => true,
'has_archive' => true, 'has_archive' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes'), 'supports' => array('title'), // 'thumbnail', 'editor','excerpt','trackbacks','custom-fields','comments','revisions','author','page-attributes'),
'taxonomies' => array('category','post_tag'), 'taxonomies' => array('category','post_tag'), // XXX Shouldn't we have a "video_type" taxonomy for VR or flat?
// there are a lot more available arguments, but the above is plenty for now
)); ));
$projects_structure = '/'.$DEFAULTSLUG.'/%wooprod%/'; $projects_structure = '/'.$DEFAULTSLUG.'/%wooprod%/';
...@@ -256,18 +271,80 @@ if(!class_exists('SexHackVideoGallery')) { ...@@ -256,18 +271,80 @@ if(!class_exists('SexHackVideoGallery')) {
$wp_rewrite->add_rewrite_tag("%videoaccess%", '([^/]+)', "videoaccess="); $wp_rewrite->add_rewrite_tag("%videoaccess%", '([^/]+)', "videoaccess=");
$wp_rewrite->add_permastruct($DEFAULTSLUG, $projects_structure, false); $wp_rewrite->add_permastruct($DEFAULTSLUG, $projects_structure, false);
$wp_rewrite->add_permastruct($DEFAULTSLUG, $projects_structure."%videoaccess%/", false); $wp_rewrite->add_permastruct($DEFAULTSLUG, $projects_structure."%videoaccess%/", false);
//$wp_rewrite->add_permastruct($DEFAULTSLUG.'public', $projects_structure.'public/', false);
//$wp_rewrite->add_permastruct($DEFAULTSLUG.'members', $projects_structure.'members/', false);
//$wp_rewrite->add_permastruct($DEFAULTSLUG.'subscribers', $projects_structure.'subscribers/', false);
//$wp_rewrite->add_permastruct($DEFAULTSLUG.'vrpub', $projects_structure.'vrpub/', false);
//$wp_rewrite->add_permastruct($DEFAULTSLUG.'vrmem', $projects_structure.'vrmem/', false);
//$wp_rewrite->add_permastruct($DEFAULTSLUG.'vrsub', $projects_structure.'vrsub/', false);
update_option('need_rewrite_flush', 1); update_option('need_rewrite_flush', 1);
} }
} }
public function sexhack_video_metaboxes($post=false)
{
add_meta_box( 'sh-mbox-videodescription', 'Video Description', array($this, 'load_metabox_videodescription'), 'sexhack_video', 'normal','default');
add_meta_box( 'sh-mbox-video', 'Video locations', array( $this, 'load_metabox_videolocations' ), 'sexhack_video', 'normal', 'default' );
//remove_meta_box( 'postimagediv', 'sexhack_video', 'side' );
add_meta_box('postimagediv', 'Video Thumbnail', 'post_thumbnail_meta_box', 'sexhack_video', 'side', 'default');
}
public function load_metabox_videodescription($post)
{
wp_nonce_field('video_description_nonce','sh_video_description_nonce');
$value = get_post_meta( $post->ID, 'video_description', true );
echo '<textarea style="width:100%" id="video_description" name="video_description">' . esc_attr( $value ) . '</textarea>';
}
public function save_sexhack_video_meta_box_data( $post_id ) {
// Verify that the nonce is set and valid.
if (!isset( $_POST['sh_video_description_nonce'])
|| !wp_verify_nonce( $_POST['sh_video_description_nonce'], 'video_description_nonce' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
// Make sure that it is set.
if ( ! isset( $_POST['video_description'] ) ) {
return;
}
// Sanitize user input.
$my_data = sanitize_text_field( $_POST['video_description'] );
// Update the meta field in the database.
update_post_meta( $post_id, 'video_description', $my_data );
}
public function load_metabox_videolocations($post) //($object, $box)
{
wp_nonce_field( 'global_notice_nonce', 'global_notice_nonce' );
$value = get_post_meta( $post->ID, '_global_notice', true );
echo '<textarea style="width:100%" id="global_notice" name="global_notice">' . esc_attr( $value ) . '</textarea>';
}
public function getProducts($vcat=false) { public function getProducts($vcat=false) {
if(!$this->productlist) if(!$this->productlist)
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
function debug_rewrite_rules($matchonly=false)
{
$matchonly=true;
global $wp_rewrite, $wp, $template;
$i=1;
if (!empty($wp_rewrite->rules)) {
foreach($wp_rewrite->rules as $name => $value) {
if($name==$wp->matched_rule) {
sexhack_log("MATCHED REWRITE RULE $i!!! NAME: ".$name." , VALUE: ".$value." , REQUEST: ".$wp->request." , MATCHED: ".$wp->matched_query." , TEMPLATE:".$template);
} else {
if(!$matchonly)
sexhack_log("REWRITE $i: $name -> $value ");
}
$i++;
}
}
}
function starts_with ($startString, $string)
{
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
function dump_rewrite( &$wp ) {
global $wp_rewrite;
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<h2>rewrite rules</h2>';
echo var_export( $wp_rewrite->wp_rewrite_rules(), true );
echo '<h2>permalink structure</h2>';
echo var_export( $wp_rewrite->permalink_structure, true );
echo '<h2>page permastruct</h2>';
echo var_export( $wp_rewrite->get_page_permastruct(), true );
echo '<h2>matched rule and query</h2>';
echo var_export( $wp->matched_rule, true );
echo '<h2>matched query</h2>';
echo var_export( $wp->matched_query, true );
echo '<h2>request</h2>';
echo var_export( $wp->request, true );
global $wp_the_query;
echo '<h2>the query</h2>';
echo var_export( $wp_the_query, true );
}
function do_dump_rewrite() {
add_action( 'parse_request', 'wp_SexHackMe\sarca' );
}
function get_proto(){
if(is_ssl()) {
return 'https://';
} else {
return 'http://';
}
}
function user_has_premium_access($uid='')
{
global $sexhack_pms;
return $sexhack_pms->is_premium($uid) AND is_user_logged_in();
}
function user_has_member_access($uid='')
{
global $sexhack_pms;
if($uid) return $sexhack_pms->is_member($uid) OR $sexhack_pms->is_premium($uid);
return is_user_logged_in();
}
?>
...@@ -21,56 +21,11 @@ ...@@ -21,56 +21,11 @@
namespace wp_SexHackMe; namespace wp_SexHackMe;
function sexhack_getURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}
function trim_text_preview($text, $len=340, $fill=false) function is_valid_eth_address($addr)
{ {
$min="10"; return preg_match('/^0x[a-fA-F0-9]{40}$/', $addr);
if($len < $min) $len=$min;
if (strlen($text) > $len)
{
$offset = ($len - 3) - strlen($text);
$text = substr($text, 0, strrpos($text, ' ', $offset)) . '...';
}
if($fill)
{
$start=strlen($text);
while($start < $len+1) {
$start++;
$text .= "&nbsp";
}
}
return $text;
} }
function html2text($html)
{
// remove comments and any content found in the the comment area (strip_tags only removes the actual tags).
$plaintext = preg_replace('#<!--.*?-->#s', '', $html);
// put a space between list items (strip_tags just removes the tags).
$plaintext = preg_replace('#</li>#', ' </li>', $plaintext);
// remove all script and style tags
$plaintext = preg_replace('#<(script|style)\b[^>]*>(.*?)</(script|style)>#is', "", $plaintext);
// remove br tags (missed by strip_tags)
$plaintext = preg_replace('#<br[^>]*?>#', " ", $plaintext);
// remove all remaining html
$plaintext = strip_tags($plaintext);
return $plaintext;
}
?> ?>
...@@ -21,6 +21,105 @@ ...@@ -21,6 +21,105 @@
namespace wp_SexHackMe; namespace wp_SexHackMe;
if(!function_exists('sexhack_log')){
function sexhack_log( $message, $dumps=false) {
if( WP_DEBUG === true ){
if( is_array( $message ) || is_object( $message ) ){
error_log( "SexHackMe: ".print_r( $message, true ) );
} else {
if($dumps) error_log( "SexHackMe: ".$message." ".str_replace("\n", "", print_r($dumps, TRUE)) );
else error_log( "SexHackMe: ".$message );
}
}
}
}
function debug_rewrite_rules($matchonly=false)
{
$matchonly=true;
global $wp_rewrite, $wp, $template;
$i=1;
if (!empty($wp_rewrite->rules)) {
foreach($wp_rewrite->rules as $name => $value) {
if($name==$wp->matched_rule) {
sexhack_log("MATCHED REWRITE RULE $i!!! NAME: ".$name." , VALUE: ".$value." , REQUEST: ".$wp->request." , MATCHED: ".$wp->matched_query." , TEMPLATE:".$template);
} else {
if(!$matchonly)
sexhack_log("REWRITE $i: $name -> $value ");
}
$i++;
}
}
}
function starts_with ($startString, $string)
{
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
function dump_rewrite( &$wp ) {
global $wp_rewrite;
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<h2>rewrite rules</h2>';
echo var_export( $wp_rewrite->wp_rewrite_rules(), true );
echo '<h2>permalink structure</h2>';
echo var_export( $wp_rewrite->permalink_structure, true );
echo '<h2>page permastruct</h2>';
echo var_export( $wp_rewrite->get_page_permastruct(), true );
echo '<h2>matched rule and query</h2>';
echo var_export( $wp->matched_rule, true );
echo '<h2>matched query</h2>';
echo var_export( $wp->matched_query, true );
echo '<h2>request</h2>';
echo var_export( $wp->request, true );
global $wp_the_query;
echo '<h2>the query</h2>';
echo var_export( $wp_the_query, true );
}
function do_dump_rewrite() {
add_action( 'parse_request', 'wp_SexHackMe\sarca' );
}
function get_proto(){
if(is_ssl()) {
return 'https://';
} else {
return 'http://';
}
}
function user_has_premium_access($uid='')
{
global $sexhack_pms;
return $sexhack_pms->is_premium($uid) AND is_user_logged_in();
}
function user_has_member_access($uid='')
{
global $sexhack_pms;
if($uid) return $sexhack_pms->is_member($uid) OR $sexhack_pms->is_premium($uid);
return is_user_logged_in();
}
function send_changepwd_mail($user_login, $baseurl=false){ function send_changepwd_mail($user_login, $baseurl=false){
global $wpdb, $wp_hasher; global $wpdb, $wp_hasher;
...@@ -110,4 +209,56 @@ function send_changepwd_mail($user_login, $baseurl=false){ ...@@ -110,4 +209,56 @@ function send_changepwd_mail($user_login, $baseurl=false){
} }
function sexhack_getURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}
function trim_text_preview($text, $len=340, $fill=false)
{
$min="10";
if($len < $min) $len=$min;
if (strlen($text) > $len)
{
$offset = ($len - 3) - strlen($text);
$text = substr($text, 0, strrpos($text, ' ', $offset)) . '...';
}
if($fill)
{
$start=strlen($text);
while($start < $len+1) {
$start++;
$text .= "&nbsp";
}
}
return $text;
}
function html2text($html)
{
// remove comments and any content found in the the comment area (strip_tags only removes the actual tags).
$plaintext = preg_replace('#<!--.*?-->#s', '', $html);
// put a space between list items (strip_tags just removes the tags).
$plaintext = preg_replace('#</li>#', ' </li>', $plaintext);
// remove all script and style tags
$plaintext = preg_replace('#<(script|style)\b[^>]*>(.*?)</(script|style)>#is', "", $plaintext);
// remove br tags (missed by strip_tags)
$plaintext = preg_replace('#<br[^>]*?>#', " ", $plaintext);
// remove all remaining html
$plaintext = strip_tags($plaintext);
return $plaintext;
}
?> ?>
...@@ -5,15 +5,9 @@ ...@@ -5,15 +5,9 @@
* Description: Cumulative plugin for https://www.sexhack.me modifications to wordpress, woocommerce and storefront theme * Description: Cumulative plugin for https://www.sexhack.me modifications to wordpress, woocommerce and storefront theme
* Version: 0.1 * Version: 0.1
* Author: Franco Lanza * Author: Franco Lanza
*/ *
* ----------------------
/** *
* include all files from folder sites
* Array for every classfile, format: array('description' => "<text>", 'name' => "<text>", "class" => "<classname>");
* it MUST be present on every subclass!!!
*/
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it> * Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0 * License: GNU/GPL version 3.0
* *
...@@ -39,40 +33,267 @@ namespace wp_SexHackMe; ...@@ -39,40 +33,267 @@ namespace wp_SexHackMe;
// look at https://woocommerce.com/document/create-a-plugin/#section-1 // look at https://woocommerce.com/document/create-a-plugin/#section-1
$SEXHACK_SECTIONS = array(); // Exit if accessed directly
$SEXHACK_ERRORS = array(); if ( ! defined( 'ABSPATH' ) ) exit;
$GLOBAL_NOSLUGS=array(
'wp-cron.php',
'wp-content',
'xmlrpc.php'
);
if(!function_exists('sexhack_log')){ if(!class_exists('SexHackMe_Plugin')) {
function sexhack_log( $message ) {
if( WP_DEBUG === true ){ class SexHackMe_Plugin
if( is_array( $message ) || is_object( $message ) ){ {
error_log( "SexHackMe: ".print_r( $message, true ) );
public $prefix;
public function __construct()
{
define( 'SH_VERSION', '0.0.1' );
define( 'SH_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'SH_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'SH_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
// The prefix of the plugin
$this->prefix = 'sh_';
// Install needed components on plugin activation
register_activation_hook( __FILE__, array( $this, 'install' ) );
register_deactivation_hook(__FILE__, array($this, 'uninstall') );
//add_action( 'plugins_loaded', array( $this, 'register_custom_meta_tables' ) );
// Check if this is a newer version
add_action( 'plugins_loaded', array( $this, 'update_check' ) );
// Include dependencies
$this->include_dependencies();
// Initialize the components
$this->init();
}
/*
* Method that gets executed on plugin activation
*
*/
public function install( $network_activate = false ) {
// Handle multi-site installation
if( function_exists( 'is_multisite' ) && is_multisite() && $network_activate ) {
global $wpdb;
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
// Create needed tables
//$this->create_tables();
// Add default settings
//$this->add_default_settings();
restore_current_blog();
}
// Handle single site installation
} else { } else {
error_log( "SexHackMe: ".$message );
// Create needed tables
//$this->create_tables();
// Add default settings
//$this->add_default_settings();
}
// Add a cron job to be executed daily
//$this->cron_job();
}
/*
* Method that gets executed on plugin deactivation
*
*/
public function uninstall() {
// Clear cron job
//$this->clear_cron_job();
}
/*
* Method that checks if the current version differs from the one saved in the db
*
*/
public function update_check() {
$db_version = get_option( 'sh_version', '' );
if( SH_VERSION != $db_version ) {
//$this->create_tables();
do_action('sh_update_check');
update_option( 'sh_version', SH_VERSION );
} }
} }
/*
* Function that schedules a hook to be executed daily (cron job)
*
*/
public function cron_job() {
// Process payments for custom member subscriptions
//if( !wp_next_scheduled( 'sh_cron_process_member_subscriptions_payments' ) )
// wp_schedule_event( time(), 'daily', 'sh_cron_process_member_subscriptions_payments' );
} }
}
$FIRST_SLUG = "/";
$slug = explode("/", $_SERVER['REQUEST_URI']);
if(count($slug) > 1) {
$FIRST_SLUG=explode("?", $slug[1])[0];
$FIRST_SLUG=explode("#", $FIRST_SLUG)[0];
}
require_once dirname( __FILE__ ) . '/inc/class-tgm-plugin-activation.php'; /*
* Function that cleans the scheduler on plugin deactivation:
*
*/
public function clear_cron_job() {
//wp_clear_scheduled_hook( 'pms_cron_process_member_subscriptions_payments' );
}
/*
* Add the default settings if they do not exist
*
*/
public function add_default_settings() {
$already_installed = get_option( 'sh_already_installed' );
if ( !$already_installed )
update_option( 'sh_already_installed', 'yes', false );
}
/*
* Function to include the files needed
*
*/
public function include_dependencies() {
/*
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/' ) )
include_once( SH_PLUGIN_DIR_PATH . 'includes/' );
*/
/* Manage Plugin Dependencies */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-tgm-plugin-activation.php' ) )
include_once( SH_PLUGIN_DIR_PATH . 'includes/class-tgm-plugin-activation.php' );
/* Utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-utils.php' ) )
include_once( SH_PLUGIN_DIR_PATH . 'includes/functions-utils.php' );
/* Cryptocurrencies utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-crypto.php' ) )
include_once( SH_PLUGIN_DIR_PATH . 'includes/functions-crypto.php' );
/* Paid Member Subscription utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-paid-member-subscriptions-integration.php' ) )
include_once( SH_PLUGIN_DIR_PATH . 'includes/functions-paid-member-subscriptions-integration.php' );
/* Testing code */
foreach( glob(dirname(__FILE__) . '/testing/*.php') as $class_path ) {
try {
include_once($class_path);
} catch(\Throwable $e) {
sexhack_log($e);
}
}
}
/**
* Registers custom meta tables with WP's $wpdb object
*
*/
public function register_custom_meta_tables() {
global $wpdb;
$wpdb->member_subscriptionmeta = $wpdb->prefix . $this->prefix . 'member_subscriptionmeta';
}
/*
* Initialize the plugin
*
*/
public function init() {
// Check plugin dependencies
add_action( 'tgmpa_register', array($this, 'plugin_dependencies' ));
// Set the main menu page
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_init', array($this, 'initialize_plugin'));
add_action('init', array($this, 'register_flush'), 10);
add_action('init', array($this, 'flush_rewrite'), 900);
// Enqueue scripts on the front end side
//add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_front_end_scripts' ) );
// Enqueue scripts on the admin side
//if( is_admin() )
// add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
// Initialize shortcodes
//add_action( 'init', array( 'PMS_Shortcodes', 'init' ) );
//add_action( 'init', array( $this, 'init_dependencies' ), 1 );
//Show row meta on the plugin screen (used to add links like Documentation, Support etc.).
//add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
// Hook to be executed on a specific interval, by the cron job (wp_schedule_event); used to check if a subscription has expired
//add_action('pms_check_subscription_status','pms_member_check_expired_subscriptions');
// Hook to be executed on a daily interval, by the cron job (wp_schedule_event); used to remove the user activation key from the db (make it expire) every 24 hours
//add_action('pms_remove_activation_key','pms_remove_expired_activation_key');
// Add new actions besides the activate/deactivate ones from the Plugins page
//add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_plugin_action_links' ) );
add_action( 'tgmpa_register', 'wp_SexHackMe\sexhackme_register_required_plugins' );
sexhack_log("SexHackMe PLUGIN Loaded!");
function sexhackme_register_required_plugins() { // Initialize the deprecated plugin parts
// XXX To be removed soon!
$this->deprecated();
}
public function plugin_dependencies() {
$plugins = array( $plugins = array(
array( array(
'name' => 'WooCommerce', 'name' => 'WooCommerce',
...@@ -93,65 +314,49 @@ function sexhackme_register_required_plugins() { ...@@ -93,65 +314,49 @@ function sexhackme_register_required_plugins() {
'is_automatic' => false, // Automatically activate plugins after installation or not. 'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table. 'message' => '', // Message to output right before the plugins table.
); );
} }
sexhack_log("FIRST_SLUG:".$FIRST_SLUG." REQUEST:".$_SERVER['REQUEST_URI']." QUERY:".$_SERVER['QUERY_STRING'] );
foreach( glob(dirname(__FILE__) . '/helpers/*.php') as $helper_path ) { public function register_flush() {
sexhack_log('Loading '.$helper_path); register_setting('sexhackme-settings', 'need_rewrite_flush');
require_once($helper_path); }
}
public function flush_rewrite()
{
if( get_option('need_rewrite_flush'))
{
sexhack_log("FLUSHING REWRITE RULES");
flush_rewrite_rules(false);
update_option('need_rewrite_flush', 0);
}
}
if(!class_exists('SexHackMe')) {
foreach( glob(dirname(__FILE__) . '/classes/*.php') as $class_path ) { /* FROM HERE IS THE DEPRECATED PART */
public function deprecated()
{
$SECTIONS = array();
foreach( glob(dirname(__FILE__) . '/deprecated/*.php') as $class_path ) {
sexhack_log($class_path);
$SEXHACK_SECTION = false; $SEXHACK_SECTION = false;
try { try {
include_once($class_path); include_once($class_path);
} catch(\Throwable $e) { } catch(\Throwable $e) {
sexhack_log($e); sexhack_log($e);
} }
//sexhack_log("Class_path:" . $class_path); if(is_array($SEXHACK_SECTION)) $SECTIONS[] = $SEXHACK_SECTION;
//sexhack_log("Section:" . $SEXHACK_SECTION["name"]);
if(is_array($SEXHACK_SECTION)) { $SEXHACK_SECTIONS[] = $SEXHACK_SECTION; }
else { $SEXHACK_ERRORS[] = basename("/classes/".$class_path); }
} }
class SexHackMe
{
public function __construct($SECTIONS)
{
global $FIRST_SLUG;
//$FIRST_SLUG = \wp_SexHackMe\$FIRST_SLUG;
sexhack_log("SexHackMe Instanciated");
$this->SECTIONS = $SECTIONS; $this->SECTIONS = $SECTIONS;
$this->instances = array(); $this->instances = array();
add_action('admin_menu', array($this, 'admin_menu')); foreach($SECTIONS as $section) {
add_action('admin_init', array($this, 'initialize_plugin')); sexhack_log("Loading ".$section['name']);
add_action('init', array($this, 'register_flush'), 10);
add_action('init', array($this, 'flush_rewrite'), 900);
foreach($this->SECTIONS as $section) {
if(get_option( $section['name'])=="1")
{
if (array_key_exists('noslugs', $section) && in_array($FIRST_SLUG, $section['noslugs'])) {
sexhack_log("NOSLUGS for ".$section['name']);
continue;
}
else {
if (array_key_exists('slugs', $section)) {
if(in_array($FIRST_SLUG, $section['slugs'])) {
sexhack_log("SLUGS for ".$section['name']);
$this->instance_subclass($section);
}
}
else {
$this->instance_subclass($section); $this->instance_subclass($section);
} }
}
}
}
} }
...@@ -166,40 +371,16 @@ if(!class_exists('SexHackMe')) { ...@@ -166,40 +371,16 @@ if(!class_exists('SexHackMe')) {
echo "<h3>Enable following functionalities:</h3>"; echo "<h3>Enable following functionalities:</h3>";
} }
/*
public function settings_field($name)
{
echo $name;
}
*/
public function checkbox($res) public function checkbox($res)
{ {
if($res=="1") return "checked"; if($res=="1") return "checked";
} }
public function register_flush() {
register_setting('sexhackme-settings', 'need_rewrite_flush');
}
public function flush_rewrite()
{
if( get_option('need_rewrite_flush'))
{
sexhack_log("FLUSHING REWRITE RULES");
flush_rewrite_rules(false);
update_option('need_rewrite_flush', 0);
}
}
public function initialize_plugin() public function initialize_plugin()
{ {
add_settings_section('sexhackme-settings', ' ', array($this, 'settings_section'), 'sexhackme-settings'); add_settings_section('sexhackme-settings', ' ', array($this, 'settings_section'), 'sexhackme-settings');
//register_setting('sexhackme-settings', 'need_rewrite_flush');
foreach($this->SECTIONS as $section) { foreach($this->SECTIONS as $section) {
//add_settings_field($section['name'], $section['name'], $section['name'],
// array($this, 'settings_field'), 'sexhackme-settings', 'sexhackme-settings', $section['name'] );
register_setting('sexhackme-settings', $section['name']); register_setting('sexhackme-settings', $section['name']);
if(array_key_exists('require-page', $section) && ($section['require-page'])) if(array_key_exists('require-page', $section) && ($section['require-page']))
{ {
...@@ -219,7 +400,7 @@ if(!class_exists('SexHackMe')) { ...@@ -219,7 +400,7 @@ if(!class_exists('SexHackMe')) {
public function admin_menu() public function admin_menu()
{ {
add_menu_page('SexHackMe Settings', 'SexHackMe', 'manage_options', 'sexhackme-settings', add_menu_page('SexHackMe Settings', 'SexHackMe', 'manage_options', 'sexhackme-settings',
array($this, 'admin_page'), plugin_dir_url(__FILE__) .'/img/admin_icon.png', 150); array($this, 'admin_page'), plugin_dir_url(__FILE__) .'/img/admin_icon.png', 31);
add_submenu_page( 'sexhackme-settings', 'SexHackMe Settings', 'Modules', add_submenu_page( 'sexhackme-settings', 'SexHackMe Settings', 'Modules',
'manage_options', 'sexhackme-settings'); 'manage_options', 'sexhackme-settings');
...@@ -245,12 +426,9 @@ if(!class_exists('SexHackMe')) { ...@@ -245,12 +426,9 @@ if(!class_exists('SexHackMe')) {
public function admin_page() public function admin_page()
{ {
global $SEXHACK_ERRORS;
?> ?>
<div class="wrap"> <div class="wrap">
<h2>SexHackMe Plugin Settings</h2> <h2>SexHackMe Plugin Settings</h2>
<?php if(!empty($SEXHACK_ERRORS)) {
foreach($SEXHACK_ERRORS as $serr) { ?><h3 style="color: red;">Error loading <?php echo $serr ?>!</h3><?php }} ?>
<form method="post" action="/wp-admin/options.php"> <form method="post" action="/wp-admin/options.php">
<?php settings_fields( 'sexhackme-settings' ); ?> <?php settings_fields( 'sexhackme-settings' ); ?>
<?php do_settings_sections( 'sexhackme-settings' ); ?> <?php do_settings_sections( 'sexhackme-settings' ); ?>
...@@ -314,14 +492,8 @@ if(!class_exists('SexHackMe')) { ...@@ -314,14 +492,8 @@ if(!class_exists('SexHackMe')) {
} }
} }
function sexhackme_plugin_run($SECTIONS, $SLUG) // Let's run the plugin!
{ new SexHackMe_Plugin;
sexhack_log("Running SexHackMe Plugins (".$SLUG.")");
$SexHackMe = new SexHackMe($SECTIONS);
}
if(!in_array($FIRST_SLUG, $GLOBAL_NOSLUGS)) sexhackme_plugin_run($SEXHACK_SECTIONS, $FIRST_SLUG);
else sexhack_log("NOSLUGS DETECTED: NOT RUNNING( ".$FIRST_SLUG." - ".$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'].")");
} }
...@@ -329,7 +501,7 @@ if(!class_exists('SexHackMe')) { ...@@ -329,7 +501,7 @@ if(!class_exists('SexHackMe')) {
// DEBUG REWRITE RULES // DEBUG REWRITE RULES
if( WP_DEBUG === true ){ if( WP_DEBUG === true ){
// only matched? // only matched?
add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules'); //add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
} }
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
//the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' ); // XXX Check it? what it does?
?>
</header><!-- .page-header -->
<?php
do_action( 'storefront_loop_before' );
//print_r($sexhack_pms->plans);
while ( have_posts() ) :
the_post();
echo do_shortcode("[sexadv adv=".get_option('sexadv_video_top')."]");
$htmltags = '<span><b>TAGS: </b></span>';
$tags = get_the_terms( get_the_ID(), 'product_tag' );
if ( ! empty( $tags ) && ! is_wp_error( $tags ) )
{
foreach($tags as $tag) {
$htmltags.="<span>#".$tag->name . '</span> ';
}
}
$videoslug = get_option('sexhack_gallery_slug', 'v');
$vurl = str_replace("/product/", "/".$videoslug."/", esc_url( get_the_permalink() ));
$prod = wc_get_product(get_the_ID());
$hls = $prod->get_attribute("hls_public");
$hls_members = $prod->get_attribute("hls_members");
$hls_premium = $prod->get_attribute("hls_premium");
$video_preview = $prod->get_attribute("video_preview");
$gif_preview = $prod->get_attribute("gif_preview");
$vr_premium = $prod->get_attribute("vr_premium");
$vr_members = $prod->get_attribute("vr_members");
$vr_public = $prod->get_attribute("vr_public");
$vr_preview = $prod->get_attribute("vr_preview");
$categories = explode(", ", wp_SexHackMe\html2text( wc_get_product_category_list($id)));
if(($hls) AND wp_SexHackMe\starts_with('/', $hls)) $hls = site_url().$hls;
if(($hls_members) AND wp_SexHackMe\starts_with('/', $hls_members)) $hls_members = site_url().$hls_members;
if(($hls_premium) AND wp_SexHackMe\starts_with('/', $hls_premium)) $hls_premium = site_url().$hls_premium;
if(($video_preview) AND wp_SexHackMe\starts_with('/', $video_preview)) $video_preview = site_url().$video_preview;
if(($vr_public) AND wp_SexHackMe\starts_with('/', $vr_public)) $vr_public = site_url().$vr_public;
if(($vr_members) AND wp_SexHackMe\starts_with('/', $vr_members)) $vr_members = site_url().$vr_members;
if(($vr_premium) AND wp_SexHackMe\starts_with('/', $vr_premium)) $vr_premium = site_url().$vr_premium;
if(($vr_preview) AND wp_SexHackMe\starts_with('/', $vr_preview)) $vr_preview = site_url().$vr_preview;
$thumb = wp_get_attachment_url($prod->get_image_id());
$avail = array();
$tabtext = array('subscribers' => 'Subscribers',
'vrsub' => 'Subscribers',
'members' => 'Members',
'vrmem' => 'Members',
'vrpub' => 'Public',
'public' => 'Public');
if($hls || $video_preview ) $avail[] = 'public';
if($vr_public || $vr_preview) $avail[] = 'vrpub';
if($hls_members) $avail[] = 'members';
if($vr_members) $avail[] = 'vrmem';
if($hls_premium) $avail[] = 'subscribers';
if($vr_premium) $avail[] = 'vrsub';
$videoaccess = get_query_var('videoaccess', false);
if($videoaccess && in_array($videoaccess, $avail))
{
$tab = $videoaccess;
}
else
{
if(user_has_premium_access()) {
if($hls_premium) $tab = 'subscribers';
elseif($vr_premium) $tab = 'vrsub';
elseif($hls_members) $tab = 'members';
elseif($vr_members) $tab = 'vrmem';
elseif($vr_public || $vr_preview) $tab = 'vrpub';
else $tab = 'public';
}
elseif(user_has_member_access()) // free membership
{
if($hls_members) $tab = 'members';
elseif($vr_members) $tab = 'vrmem';
elseif($vr_public) $tab = 'vrpub';
else $tab = 'public';
}
else // public
{
if($vr_public) $tab = 'vrpub';
else $tab = 'public';
}
}
?>
<article id="post-<?php echo get_the_ID();?>" class="post-<?php echo get_the_ID();?> product type-product">
<header class="entry-header">
<h2 class="alpha entry-title sexhack_video_title">
<?php the_title(); echo " (".$tabtext[$tab]." version)"; ?>
</h2>
</header><!-- .entry-header -->
<div class="sexhack-video-container">
<?php
if(in_array($tab, $avail))
{
switch($tab)
{
case "members":
case "vrmem":
if(user_has_member_access())
{
if($hls_members) echo do_shortcode( "[sexhls url=\"".$hls_members."\" posters=\"".$thumb."\"]" );
else if($vr_members) echo do_shortcode( "[sexvideo url=\"".$vr_members."\" posters=\"".$thumb."\"]" );
else echo "<h3 class='sexhack-videonotify'>SOMETHING WENT BADLY WRONG. I CAN'T FIND THE VIDEO</h3>";
}
else
{
if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>';
else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>';
echo "<h3 class='sexhack-videonotify'><a href='/login'>YOU NEED TO LOGIN TO ACCESS THIS VIDEO</a></h3>";
echo "<div style='width: 80%; margin-left: 10%;' >".do_shortcode('[pms-login redirect_url="/account" ]')."</div>";
}
break;
case "subscribers":
case "vrsub":
if(user_has_premium_access())
{
if($hls_premium) echo do_shortcode( "[sexhls url=\"".$hls_premium."\" posters=\"".$thumb."\"]" );
else if($vr_premium) echo do_shortcode( "[sexvideo url=\"".$vr_premium."\" posters=\"".$thumb."\"]" );
else echo "<h3 class='sexhack-videonotify'>SOMETHING WENT BADLY WRONG. I CAN'T FIND THE VIDEO</h3>";
}
else
{
if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>';
else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>';
echo "<h3 class='sexhack-videonotify'><a href='/product-category/subscriptions/'>YOU NEED A SUBSCRIPTION TO ACCESS THIS VIDEO</a></h3>";
}
break;
case "vrpub":
default: // public too!
if($hls) echo do_shortcode( "[sexhls url=\"".$hls."\" posters=\"".$thumb."\"]" );
else if($vr_public) echo do_shortcode( "[sexvideo url=\"".$vr_public."\" posters=\"".$thumb."\"]" );
else if($video_preview) echo '<video src='."'$video_preview'".' controls autoplay muted playsinline loop poster="'.$thumb.'"></video>';
else if($vr_preview) echo do_shortcode( "[sexvideo url=\"".$vr_preview."\" posters=\"".$thumb."\"]" );
else if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>';
else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>';
}
}
else // if(in_array($tab, $avail))
{
if($video_preview) echo '<video src='."'$video_preview'".' controls autoplay muted playsinline loop poster="'.$thumb.'"></video>';
else if($vr_preview) echo do_shortcode( "[sexvideo url=\"".$vr_preview."\" posters=\"".$thumb."\"]" );
else if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>';
else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>';
?>
<h2 class='sexhack-videonotify'><b>PUBLIC VIDEO NOT AVAILABLE</b></h2>
<?php
}
?>
</div> <!-- video container -->
<div class="sexhack-tabs">
<?php
foreach($avail as $vaval)
{
if(!(in_array('vrpub', $avail) && ($vaval == 'public'))) {
$hrefurl = $vurl.'/'.$vaval.'/';
$bclass = '';
if(isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) $hrefurl .= '?'.$_SERVER['QUERY_STRING'];
if($vaval == $tab) $bclass='sexhack_toggled_button';
?>
<a class="sexhack_tab_a" href="<?php echo $hrefurl; ?>">
<button name="<?php echo $vaval; ?>" class="sexhack_tab_button <?php echo $bclass; ?>">
<?php echo $tabtext[$vaval]; ?>
</button>
</a>
<?php
}
}
?>
</div>
<br><hr>
<?php
echo $htmltags;
?>
<h3><a href="<?php echo get_the_permalink(); ?>">Download the full lenght hi-res version of this video</a><h3>
<hr>
<?php
echo do_shortcode("[sexadv adv=".get_option('sexadv_video_bot')."]");
endwhile;
/**
* Functions hooked in to storefront_paging_nav action
*
* @hooked storefront_paging_nav - 10
*/
do_action( 'storefront_loop_after' );
else :
get_template_part( 'content', 'none' );
endif;
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
do_action( 'storefront_sidebar' );
get_footer();
<?php
/* add new tab called "mytab" */
namespace wp_SexHackMe;
//add_filter('um_account_page_default_tabs_hook', 'wp_SexHackMe\my_custom_tab_in_um', 100 );
function my_custom_tab_in_um( $tabs ) {
$tabs[800]['mytab']['icon'] = 'um-faicon-pencil';
$tabs[800]['mytab']['title'] = 'My Custom Tab';
$tabs[800]['mytab']['custom'] = true;
return $tabs;
}
/* make our new tab hookable */
add_action('um_account_tab__mytab', 'wp_SexHackMe\um_account_tab__mytab');
function um_account_tab__mytab( $info ) {
global $ultimatemember;
extract( $info );
$output = $ultimatemember->account->get_tab_output('mytab');
if ( $output ) { echo $output; }
}
/* Finally we add some content in the tab */
add_filter('um_account_content_hook_mytab', 'wp_SexHackMe\um_account_content_hook_mytab');
function um_account_content_hook_mytab( $output ){
ob_start();
?>
<div class="um-field">
<!-- Here goes your custom content -->
</div>
<?php
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
// You could set the default privacy for custom tab and disable to change the tab privacy settings in admin menu.
/*
* There are values for 'default_privacy' atribute
* 0 - Anyone,
* 1 - Guests only,
* 2 - Members only,
* 3 - Only the owner
*/
// Filter
function um_mycustomtab_add_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My Custom Antani',
'icon' => 'um-faicon-pencil',
//'default_privacy' => 0,
);
return $tabs;
}
//add_filter( 'um_profile_tabs', 'wp_SexHackMe\um_mycustomtab_add_tab', 10000 );
/**
* Check an ability to view tab
*
* @param $tabs
*
* @return mixed
*/
function um_mycustomtab_add_tab_visibility( $tabs ) {
if ( empty( $tabs['mycustomtab'] ) ) {
return $tabs;
}
$user_id = um_profile_id();
//if ( ! user_can( $user_id, '{here some capability which you need to check}' ) ) {
// unset( $tabs['mycustomtab'] );
//}
return $tabs;
}
add_filter( 'um_user_profile_tabs', 'wp_SexHackMe\um_mycustomtab_add_tab_visibility', 2000, 1 );
// Action
function um_profile_content_mycustomtab_default( $args ) {
echo 'Hello world!';
}
add_action( 'um_profile_content_mycustomtab_default', 'wp_SexHackMe\um_profile_content_mycustomtab_default' );
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment