Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.118.144.12
Web Server : Apache/2.4.61 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/cwd/var/www/wordpress/wp-content/plugins/fictional-maps-handler/php/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/cwd/var/www/wordpress/wp-content/plugins/fictional-maps-handler/php/classes/SIDEBAR.php
<?php

/**
* @author Michael Herrmann
* @copyright 2020
*/

define('HTML_LIB', dirname(__FILE__) . '/../../html/lib');
define('HTML_PANELS', dirname(__FILE__) . '/../../html/panels');
define('HTML_POPUPS', dirname(__FILE__) . '/../../html/popups');
define('HTML_FORMS', dirname(__FILE__) . '/../../html/forms');
define('CSS_FM', dirname(__FILE__) . '/../../css/fm');
define('JS_SCRIPTS', dirname(__FILE__) . '/../../js/site');
define('IMG_POPUPS', dirname(__FILE__) . '/../../img/popups');

include_once('MAP_DB_CONNECTOR.php');

class SIDEBAR{
    private $map_db_connector;
    
    /**
     */
    public function __construct(){
        $this->map_db_connector = new MAP_DB_CONNECTOR();                           //create this connector object to get the db connection $conn
    }

    /**
     * SIDEBAR::draw()
     * creates the sidebar for the audience map
     */
    public function draw() {
        $userid = get_current_user_id();                                            //as always, get the user id first
        $current_map = $this->map_db_connector->get_newest_map($userid);            //now get the map
        $this->options_and_settings($userid, $current_map);                         //see below for actual settings
    }
    
    
    
    /**
     * SIDEBAR::edit()
     * creates the left sidebar for the edit map page, containing Settings
     */
    public function edit_left() {
        $userid = get_current_user_id();                                            //as always, get the user id first
        $creatorid = intval($_GET['creator']);                                      //get the creator's userid and the map name from the URL parameters
        $current_map = $this->map_db_connector->get_map($creatorid, $_GET['map']);  //get the map
        //check if the current user is the creator of the map
        if ($creatorid == $userid){
            //yes, user = creator, continue
            include HTML_PANELS.'/sidebar_edit_left.html';
        }
        else {
            //nope, current user is not the creator of this map. Access Denied!
            echo "Error: Access Denied! Only the creator of the map may edit it.";
        }
    }
    
    /**
     * SIDEBAR::edit_right()
     * creates the right sidebar for the edit map page, containing Warnings
     */
    public function edit_right() {
        include HTML_PANELS . '/sidebar_edit_right.html';                             //everything that happens here is Javascript and CSS (and a html shell) so we just show the contents of this file
    }
    
    /**
     * SIDEBAR::audience()
     * creates the sidebar for the audience map
     */
    public function audience_right() {
        $creatorid = intval($_GET['creator']);                                      //get the userid of the map creator and map name from the URL
        $map_name = $_GET['map'];
        $current_map = $this->map_db_connector->get_map($creatorid, $map_name);     //use it to get the map object
        $user_ip =$_SERVER['REMOTE_ADDR'];                                          //get the current visitors IP address
        //insert the sidebar but hide the Rating form for now
        include HTML_PANELS.'/sidebar_audience.html';
        if(isset($_POST['submit_rating'])) {
            $prep_insert_rating = $this->map_db_connector->conn->prepare("INSERT INTO fm_map_ratings (rater_ip, map_id, rating) VALUES (:rater_ip, :map_id, :rating)");  //prepare the sql statement to insert the rating into the ratings table
            $sql_values = [                                                         //set the array of values to hand over to the prepared sql statement for adding a map
                'rater_ip' => $user_ip,
                'map_id' => $current_map->get_id(),
                'rating' => $_POST['starrating'],
            ];
            $prep_insert_rating->execute($sql_values);                              //execute the prepared statement
            //display user's star rating
            $this->map_db_connector->show_map_rating($_POST['starrating']);         //use the get_rating_ip() inherited from MAP_OPERATIONS
            echo '<script>votedJustNow()</script>';
        }
        elseif ($current_map->was_rated_by($user_ip)){
            //if the ip of the user is in the array of ips that voted for this map already, show the form with that vote and hide the submit button
            $this->map_db_connector->show_map_rating($current_map->get_rating_from_ip($user_ip));    //use the get_rating_ip() inherited from MAP_OPERATIONS
            echo '<script>votedInPast()</script>';
        }
        else {
            //nothing, just let the form be shown
        }
        $this->origin_note($current_map);
    }
    
    /**
     * SIDEBAR::audience_left()
     * creates the left sidebar for the audience map where the map description is shown
     */
    public function audience_left() {
    	if(!isset($_GET['creator']) || !isset($_GET['map']))return false;
        $creatorid = intval($_GET['creator']);                                      //get the userid of the map creator and map name from the URL
    	$map_name = $_GET['map'];
    	$current_map = $this->map_db_connector->get_map($creatorid, $map_name);     //use it to get the map object
    	//echo out the divs with the map name and description text - wrapping it in divs allows to later change the contents via jQuery. E.g. to display content from map popups.
    	echo '<div id="audience_content_panel" style="display:flex;flex-direction: column;height: 100%;">
							<div id="audience_content_heading" style="margin-top:20px;"><h1>'.$this->check_map_name_for_default($map_name).'</h1><br></div>
							<div id="audience_content" style="align-self: flex-start">'.$current_map->get_description().'</div>
							<hr>
							<div id="origin_note" style="display:inline-block;">'.$this->origin_note($current_map).'</div>
					  </div>';
    	//include some js functionality to pop out the description - helpful for long description texts
    	echo '<link rel="stylesheet" href="../wp-content/plugins/fictional-maps-handler/css/lib/jBox.min.css" />
    				<script src="../wp-content/plugins/fictional-maps-handler/js/lib/jBox.min.js" ></script>
    				<script>'. file_get_contents(JS_SCRIPTS.'/popups_audience_map_description.js') .'</script>';
        return true;
    }
    
    /*
     * ========================================================================= *
     * HELPER FUNCTIONS                                                          *
     * ========================================================================= *
     */
    
    private function options_and_settings($userid, $current_map) {
        $user = $this->map_db_connector->get_user($userid);                                                 //get the user to be able to check if certain options are available to this user according to his subscription plan
        echo "<input id=initial_protected type=hidden value=" . $current_map->get_protected() . " >";       //this is just so that the helper script knows to not show the save button when the protection checkbox is unchecked

        echo '<h2 id="map_options_title">Map Options</h2>';
        echo '<div id="map_options" class="sidenav_section">';
        //RENAME MAP SECTION
        if(!empty($_POST['renameSubmit'])){
            $new_map_name = $_POST['renameSubmit'];
            //rename the map
            $sanitized_map_name = $this->map_db_connector->rename_map($userid, $current_map->map_name, $_POST['new_map_name']);  //returns different map name if problematic character had to be removed
            //and then reload the edit map page with the new name
            $new_map_link = "https://fictionalmaps.com/edit-map/?creator=" . $userid . "&map=" . $sanitized_map_name . "&rand=" . uniqid();
            echo '<script type="text/javascript"> window.location = "' . $new_map_link . '"</script>';      //reloading needs a bit of a javascript workaround
        }
        else {
            //show the rename map form
            echo '<div id="rename_btn" class="sidenav_button">Rename Map</div>
             <div id="rename_popup_content" class="sidenav_hidden_content">
             <form action="" method="post">
             <input type="text" id="new_map_name" name="new_map_name" value="' . $current_map->map_name . '" /></br>
             <input type=submit name=renameSubmit class="sidenav_button" value="Rename"/>
             </div>';                        //the form submit button
        }
        //MODAL POPUP "Replace Background Map"
        echo '<div id="replace_map_btn" class="sidenav_button">Replace Background Map</div>
							<div id="replace_map" class="sidenav_hidden_content">
								Choose a new map image<br>
								<input type="file" name="map_file" id="map_file" /></br><br>
								Note: It is advised to choose an image of same or at least similar resolution.<br>Otherwise undesired effects may occur.<br><br> 
								<button id="save_replace_map_btn">Save</button><button id="cancel_replace_map_btn">Cancel</button>
							</div>';
        //PASSWORD PROTECTION SECTION
        if ($user->subscription_plan->pw_protection) {                                                      //show the option to password protect the map only if allowed by the user's subscription plan
          echo '<div id="pw_protection_btn" class="sidenav_button">Password Protection</div>';
          echo "<input id=initial_protected type=hidden value=" . $current_map->get_protected() . " >";       //this is just so that the helper script knows to not show the save button when the protection checkbox is unchecked
          $this->pw_protection_form($current_map);                                                    // show the password protection form
        }
        //MODAL POPUP "Edit Map Description"
        echo '<div id="set_description_btn" class="sidenav_button">Edit Map Description</div>													
							<div style="display: none" id="set_description">
								<textarea name="description" id="description" rows="12" cols="100" >'.$current_map->get_description().'</textarea><br>
                <button id="save_description_btn" class="fm_button">Save</button><button id="cancel_description_btn" class="fm_button">Cancel</button>
							</div>';
        //MODAL POPUP "Edit Map Tags"
        echo '<div id="set_tags_btn" class="sidenav_button">Edit Map Tags</div>
							<div style="display: none" id="set_tags">
								<input type="text" name="tags" id="tags" style="width:100%;" /></br>								
								<button id="save_tags_btn">Save</button><button id="cancel_tags_btn">Cancel</button>
							</div>';
        echo "</div>"; //end map options section
        echo '<hr><h2>Map Settings</h2>';
        if(!empty($_POST['submit_settings'])){
            $search_box_value = (isset($_POST['search']) ? $_POST['search'] : 0);               //shorthand ternary operator instead of if clauses
            $fullscreen_box_value = (isset($_POST['fullscreen']) ? $_POST['fullscreen'] : 0);
            $popout_box_value = (isset($_POST['popout']) ? $_POST['popout'] : 0);
            $scalebar_toggle_value = (isset($_POST['scalebar']) ? $_POST['scalebar'] : 0);
            $measuring_value = (isset($_POST['measuring']) ? $_POST['measuring'] : 0);
            $map_units = (isset($_POST['map_units']) ? $_POST['map_units'] : 'miles');          //if the map unit field is disabled, we need to set the value to the default of 'miles'. Otherwise it will be null and PDO throws an exception
            $stmt = $this->map_db_connector->conn->prepare("UPDATE fm_maps 
                                                            SET min_zoom = :new_min_zoom, max_zoom = :new_max_zoom, search = :new_search, fullscreen = :new_fullscreen, popout = :new_popout, scalebar_toggle =:new_scalebar_toggle,
                                                                labels = :new_labels, popup_background = :new_popup_background, map_units = :new_map_units,  width_in_units = :new_width_in_units, measuring = :new_measuring
                                                            WHERE userid = :userid AND map_name = :map_name");
            $sql_values = [                                       //set the array of values to hand over to the prepared sql statement
                'new_min_zoom' => $_POST['min_zoom'],
                'new_max_zoom' => $_POST['max_zoom'],
                'new_search' => (int)$search_box_value,                         //the value of the checkbox needs to be cast to int from string
                'new_fullscreen' => (int)$fullscreen_box_value,
            		'new_popout' => (int)$popout_box_value,
                'new_scalebar_toggle' => (int)$scalebar_toggle_value,
                'new_labels' => $_POST['labels'],
                'new_popup_background' => $_POST['popup-background'],
                'new_map_units' => $map_units,
                'new_width_in_units' => $_POST['width_in_units'],
                'new_measuring' => (int)$measuring_value,
                'userid' => $userid,
                'map_name' => $current_map->map_name,
            ];
            $stmt->execute($sql_values);
            $current_map = $this->map_db_connector->get_map($userid, $current_map->map_name);  //reload the map object to reflect changes in the preloaded values of the form
        }
        //show form
        //using the shorthand ternary operator instead of if clauses for the checkboxes because those results can be used in concatenation
        echo '<form action="" method="post" >
                Min. Zoom
                <input type="text" maxlength="2" size="2" name="min_zoom" id="minZoom" value="' . $current_map->get_min_zoom() . '"
                    title="Min. Zoom determines how far you can zoom out. Default value of 2 fits the whole map within the map window. Not recommended to change this unless you are displaying the map in a different context."/>
                Max. Zoom
                <input type="text" maxlength="2" size="2" name="max_zoom" id="maxZoom" value="' . $current_map->get_max_zoom() . '"
                    title="Max. Zoom determines how far you can zoom in. A value of 5-8 is usually sufficient for most maps."/>
                <input type="checkbox" name="search" id="search" value="1" ' . ($current_map->get_search() ? 'checked': '') . '
                    title="The search box is disabled by default for a cleaner standard user interface in the audience map. It is usually a good idea to enable it, should your map contain more than a handful of markers."/>
                    &nbsp;&nbsp;Enable Search</br>
                <input type="checkbox" name="fullscreen" id="fullscreen" value="1" ' . ($current_map->get_fullscreen() ? 'checked': '') . '
                    title="The option to enter fullscreen mode is enabled by default."/>
                    &nbsp;&nbsp;Enable Fullscreen Mode</br>
                <input type="checkbox" name="popout" id="popout" value="1" ' . ($current_map->get_popout() ? 'checked': '') . '
                    title="Adds a button to the audience map that let\'s the user open only the map itself in a new window. <br> One use case where this can be especially handy is, if the map embedded in an application like a virtual tabletop and users only need the map occasionally."/>
                    &nbsp;&nbsp;Enable Popout Button</br>
                    Show Labels<br>
                <select name="labels" id="labels" title="Decide how or if you want the names of locations displayed beneath the symbol. Available option are always, never and hover, meaning that the label will only displayed if the user moves the mouse over the symbol.">
                    <option selected="selected">' . $current_map->get_labels() . ' 
                    <option value="always">Always&nbsp&nbsp&nbsp</option>
                    <option value="hover">Hover</option>
                    <option value="never">Never</option>
                </select><br>
                Popup Background<br>
                <select name="popup-background" id="popup-background" >'
                . $this->popup_background_form($userid, $current_map) .' 
                </select>
                <span id="popup-background-preview"></span>
                <input type="checkbox" name="scalebar" id="scalebar" value="1" ' . ($current_map->get_scalebar_toggle() ? 'checked': '') . ' onclick="toggleUnits()" 
                    title="Show a scalebar on the bottom left of your map. Requires additional information about map units and map size."/>
                    &nbsp;&nbsp;Show Scale Bar</br>
                <input type="checkbox" name="measuring" id="measuring" value="1" ' . ($current_map->get_measuring() ? 'checked': '') . ' onclick="toggleUnits()" 
                    title="Enable the measuring of distances in your map."/>
                    &nbsp;&nbsp;Enable Measuring</br>
                    Map Units
                <span id="units"><input type="text" maxlength="32" size="10" name="map_units" id="map_units" value="' . $current_map->get_map_units() . '"
                    title="What are the units called you want your map to be measured in?"/>
                Width in Units
                <input type="text" maxlength="10" size="10" name="width_in_units" id="width_in_units" value="' . ($current_map->get_width_in_units() ? $current_map->get_width_in_units() : '') . '"
                    title="How many map units is your map wide? E.g. 4000 miles from left to right or 60 feet or 287 furlongs."/>
                    </span>
                </br> <input type="submit" value="Save Settings" name="submit_settings" />
            </form>';
      #echo '<link rel="stylesheet" href="../wp-content/plugins/fictional-maps-handler/css/lib/tagify.css" />';
      #echo '<script src="../wp-content/plugins/fictional-maps-handler/js/lib/tagify.min.js" ></script>';
	  #echo '<script>'. file_get_contents(JS_SCRIPTS.'/sidebar_edit_left.js') .'</script>';    //include some js functionality to make section collapsable and and popup background previews
			
    }
    
    /*==============================================================================================
     * HELPER FUNCTIONS
     *
     * - get_popup_backgrounds()
     * - popup_background_form()
     * - pw_protection_form($current_map);
     * ==============================================================================================
     */
    
    /**
     * SIDEBAR::get_popup_backgrounds()
     * creates an array of the popup background names from the default popup background folder and any assets the user
     * uploaded
     * @returns array $backgrounds - array of png file names
     */
    private function get_popup_backgrounds_default(){
        $backgrounds = [];
        $all_files=scandir(IMG_POPUPS);                                       //returns all files from the directory
        $default_backgrounds=array_diff($all_files, array('.','..','undefined.png')); //removes the . and .. before returning the list as well as the undefined option
        foreach ($default_backgrounds as $file_name){
            $backgrounds[]=[
                'link'=>"wp-content/plugins/fictional-maps-handler/img/popups/",
                'popup_name'=>pathinfo($file_name, PATHINFO_FILENAME)              //removes the file extension and adds it to the array
            ];
        }
       return $backgrounds;
    }

    /**
     * SIDEBAR::get_popup_backgrounds()
     * creates an array of the popup background names from the default popup background folder and any assets the user
     * uploaded
     * @returns array $backgrounds - array of png file names
     */
    private function get_popup_backgrounds_user($userid){
        $backgrounds = [];
        $ASSET_MANAGER=new ASSET_MANAGER($userid);
        $user_backgrounds=$ASSET_MANAGER->get_assets("backgrounds");
        if($user_backgrounds) {
            foreach ($user_backgrounds as $file_name) {
                $backgrounds[] = [
                    'link' => "wp-content/plugins/fictional-maps-handler/usermaps/$userid/_assets/backgrounds/",
                    'popup_name' => pathinfo($file_name, PATHINFO_FILENAME)              //removes the file extension and adds it to the array
                ];
            }
        }
        return $backgrounds;
    }


    /**
     * SIDEBAR::popup_background_form()
     * creates the strings to dynamically add the option fields for the popup background select form in edit() -> map settings
     * @param $userid
     * @param map $current_map
     * @return string
     */
    private function popup_background_form($userid, $current_map) {
//        echo '<script src="../wp-content/plugins/fictional-maps-handler/js/lib/jBox.min.js" ></script>';
        if ($current_map->get_popup_background() != null){              //some background has been set
            if ($current_map->get_popup_background() == 'undefined'){   //it's the default one
                $str = '<option selected="selected" value="undefined" data-link="wp-content/plugins/fictional-maps-handler/img/popups/">Default';
            }else {
                if(!empty(glob("wp-content/plugins/fictional-maps-handler/img/popups/".$current_map->get_popup_background().".*"))){ //check if it's in the default img folder
                    $str = '<option selected="selected" data-link="wp-content/plugins/fictional-maps-handler/img/popups/">' . $current_map->get_popup_background();
                }else { //if not it must be a user uploaded asset
                    $str = '<option selected="selected" data-link="wp-content/plugins/fictional-maps-handler/usermaps/'.$current_map->userid.'/_assets/backgrounds/">' . $current_map->get_popup_background();
                }
                $str .= '<option value="undefined" data-link="wp-content/plugins/fictional-maps-handler/img/popups/">Default</option>'; //also add the default option
            }
        } else {   //no background has been set yet
            $str = '<option selected="selected" value="undefined" data-link="wp-content/plugins/fictional-maps-handler/img/popups/">Default';
        }
        $i = 0;
        $background_array_default=$this->get_popup_backgrounds_default();               //array of default background
        $user_has_backgrounds=false;                                                 //flag to determine if user has uploaded assets
        $background_array_user=$this->get_popup_backgrounds_user($userid);      //array of user background - empty if none have been uploaded
        if(count($background_array_user)>0)$user_has_backgrounds=true;
        if($user_has_backgrounds)$str.='<optgroup label="Default Backgrounds">';
        foreach ($background_array_default as $background){
            if($background==$current_map->get_popup_background())continue;      //skip the one already selected
            $str .='<option id="background_option_'.$i.'" value="'.$background['popup_name'].'" data-link="'.$background['link'].'">'.$background['popup_name'].'</option>';
            $i++;
        }
        if($user_has_backgrounds){
            $str.='</optgroup>';
            $str.='<optgroup label="Your Backgrounds">';
            foreach ($background_array_user as $background){
                if($background==$current_map->get_popup_background())continue;      //skip the one already selected
                $str .='<option id="background_option_'.$i.'" value="'.$background['popup_name'].'" data-link="'.$background['link'].'">'.$background['popup_name'].'</option>';
                $i++;
            }
            $str.='</optgroup>';
        }
        return $str;
    }
    
    /**
     * SIDEBAR::pw_protection_form()
     * creates to simple password setting form for edit() -> map settings
     * @param map $current_map
     */
    private function pw_protection_form($current_map) {
      echo '<div id="protection" class="sidenav_hidden_content"><form action="" method="post">';
      echo 'Restrict access to your map by setting a password. Only those who know the correct password will be able to view your map.<br>';
      echo '<input type="checkbox" name="protected" id="protected" value="1" ' . ($current_map->get_protected() ? 'checked': '') . '/>&nbsp;&nbsp;Password Protection</br>';
      echo '<span id="password-input"><input type="text" id="pw" name="pw" /></br></span>';
      //echo '<input type=submit id="passwordSubmit" class="fm_button" name="passwordSubmit" value="Set New Password"/>';                     //the form submit button
      echo '<div class="fm_button_container" >';
        echo '<button id="save_password_btn" class="fm_button">Set New Password</button>';
      echo '</div>';
      echo '</div>';
    }
    
    /**
     * SIDEBAR::origin_note()
     * show a link back to the partner page the map was created with - if applicable
     * @param object $map - MAP object
     */
    private function origin_note($map) {
    	$origin = $map->get_origin();           //returns an associated array with id, origin, origin_url
    	$origin_note = "";
    	if ($origin['origin'] != 'user'){
    		$origin_note =  'This map was created with <br><a href="'.$origin['origin_url'].'" target="blank">'.$origin['origin'].'</a>';
    	}
    	return $origin_note;
    }
     /**
     * SIDEBAR::check_map_name_for_default()
     * checks if the map name equals the default name of a partner site plus random string and returns it without the random string
     * @param string $map_name
     */
    //TODO: this is duplicated in MAP_GALLERY - remove the need for duplicates through inheritage
    private function check_map_name_for_default($map_name){
        if (substr($map_name, 0, 16) === 'DungeonMapDoodle'){
            return 'DungeonMapDoodle';
        } else {
            return $map_name;
        }
    }
    
}

Anon7 - 2022
AnonSec Team