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;
}
?> ?>
This diff is collapsed.
This diff is collapsed.
<?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