# buttonizer-multifunctional-button/1.0.3/classes/admin/Buttons.php

Buttonizer – Floating Menus, Sticky Buttons, &amp; Popup Builder, version 1.0.3. 345 lines.

- Page: https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.3/code/classes/admin/Buttons.php
- Raw: https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.3/raw/classes/admin/Buttons.php
- Modified: 2017-08-31T08:15:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.3/code/classes/admin/Buttons.php#L10-L20`.

```php
<?php
/*
This program 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 2
of the License, or (at your option) any later version.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Copyright 2017 Buttonizer
*/

namespace Buttonizer\Admin;

# No script kiddies
defined( 'ABSPATH' ) or die('No script kiddies please!');

class Buttons {
    private $aSavedData = [];
    private $aPageCategories = [];
    private $aFontAwesome = [];

    public function __construct($aFontAwesome) {
        $this->aFontAwesome = $aFontAwesome;
        $this->loadData();
        $this->loadButtons();
    }

    private function loadData() {
        $this->aSavedData      = (array) get_option('buttonizer_buttons');
        $this->aPageCategories = (array) get_option('buttonizer_page_categories');
    }

    private function loadButtons() {
        // Get buttons
        $aButtons = (isset($this->aSavedData['buttonorder']) && is_array($this->aSavedData['buttonorder']) ? $this->aSavedData['buttonorder'] : [0 => -1]);

        if($aButtons[0] != '-1') {
            $aButtons[-1] = '-1';
        }

        echo '<div id="button-rows">';
        $iButtonCount = 0;
		foreach($aButtons as $sButtonKey => $iButtonId) {
            $this->loadIndividialButtonRow($sButtonKey, $iButtonId, (isset($bDisabled) ? true : false));
            $iButtonCount++;
        }

        echo '<img src="'. plugins_url('/assets/no-buttons.jpg', BUTTONIZER_PLUGIN_DIR) .'" style="'. (0 == ($iButtonCount - 1) ? 'display: block;' : 'display: none;') .'" class="buttonizer-no-buttons" />';

        echo '</div>';
    }

    private function loadIndividialButtonRow($sButtonKey, $iButtonId, $bDisabled) {
		$sButtonTitle = (isset($this->aSavedData['button_' . $iButtonId . '_title']) ? ( $this->aSavedData['button_' . $iButtonId . '_title'] ):'Button ' . ($iButtonId + 1));

		$onMobile = (isset($this->aSavedData['button_' . $iButtonId . '_show_on_phone'])?( $this->aSavedData['button_' . $iButtonId . '_show_on_phone'] ):'');
		$onDesktop = (isset($this->aSavedData['button_' . $iButtonId . '_show_on_desktop'])?( $this->aSavedData['button_' . $iButtonId . '_show_on_desktop'] ):'');

		?>
		<div class="button-row" id="btn_row_<?=$iButtonId?>" button-id="<?=$iButtonId?>"<?php if($iButtonId == -1) { echo ' style="display: none"'; } ?>>
			<input type="checkbox" name="buttonizer_buttons[buttonorder][]" value="<?=$iButtonId?>" checked="checked" style="display: none;" />

			<div class="row-info">
				<span><i class="fa <?=$this->buttonOutputIcon($iButtonId);?> button-icon"></i> <span class="row-title"><?=($iButtonId == -1 ? 'New button' : $sButtonTitle)?></span> <i class="fa fa-pencil pencil-edit"></i></span>

				<a href="javascript:buttonizer.removeRow(<?=$iButtonId?>)" class="delete-button">Delete <i class="fa fa-trash-o"></i></a>

				<a href="javascript:buttonizer.toggleMobile(<?=$iButtonId?>)" class="mobiledesktop mobile-button <?=($onMobile == "" ? 'selected' : '');?>"><i class="fa fa-mobile"></i></a>
				<a href="javascript:buttonizer.toggleDesktop(<?=$iButtonId?>)" class="mobiledesktop desktop-button <?=($onDesktop == "" ? 'selected' : '');?>"><i class="fa fa-desktop"></i></a>
            </div>

			<div class="button-data">
				<table>
					<tr style="display: none;">
						<td width="20%"></td>
						<td width="20%"></td>
						<td></td>
					</tr>
					<tr>
						<td>
							<label for="button_text" class="label-top">
								<span class="info-class"><i class="fa fa-info-circle"></i> <span>This is for internal use only.<br /><br />When using Google Analytics, this will be the title of the event when clicking this button.</span></span>
								Button name:
							</label>
							<input type="text" name="buttonizer_buttons[button_<?=$iButtonId?>_title]" value="<?=$sButtonTitle?>" class="button_title" />
						</td>
						<td class="button-pdr" colspan="2">
							<label for="button_icon" class="label-top">
								<span class="info-class"><i class="fa fa-info-circle"></i> <span>This will be the icon of the button. You can choose from the build-in Font Awesome icons.<br /><br />When you want to use your own icon or image, you can click the 'or upload an image' link to use your own icon.</span></span>
								Button icon:
							</label>
							<?=$this->buttonGetIcon($iButtonId); ?>
						</td>
					</tr>

					<tr>
						<td>&nbsp;</td>
						<td></td>
						<td></td>
					</tr>

					<tr>
						<td>
							<label for="button_text" class="label-top">
								<span class="info-class"><i class="fa fa-info-circle"></i> <span>This is the label what the guest on your website will see. Something like 'Contact me!', or 'Like us on Facebook'</span></span>
								Button label:
							</label>
							<?=$this->buttonGetText($iButtonId); ?>
						</td>
						<td colspan="2">
							<label for="button_category" class="label-top">
								<span class="info-class"><i class="fa fa-info-circle"></i> <span>Select a page category. You can add more page rules at the 'Page categories' tab.</span></span>
								Button page category:
							</label>
							<?=$this->buttonGetShowOnPages($iButtonId); ?>
						</td>
					</tr>

					<tr>
						<td>&nbsp;</td>
						<td></td>
						<td></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-globe setting-icon"></i> URL or phone-number
                            <span class="info-class"><i class="fa fa-info-circle"></i> <span>This is the click-action of your button. You can input a full url (http://myawesomewebsite.com), a URI (/contact), an anchor-link (#anchor) or a phone number. Note that if you input a phone number that you select the option ‘Is phone number’. This will be a direct click-to-call action. Please don’t add a full url without the http:// (like: www.myawesomewebsite.com). </span></span>
						</td>
						<td colspan="2"><?=$this->buttonGetUrl($iButtonId)?></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-phone setting-icon"></i> Is phone number
						</td>
						<td><?=$this->buttonGetIsPhoneNumber($iButtonId)?><label for="button_<?=$iButtonId?>_is_phonenumber"> Yes</label></td>
						<td></td>
					</tr>

					<tr class="settings-row setting-new-tab">
						<td>
							<i class="fa fa-external-link setting-icon"></i> Open in new tab
						</td>
						<td><?=$this->buttonGetNewTab($iButtonId)?><label for="button_<?=$iButtonId?>_url_newtab"> Yes</label></td>
						<td></td>
					</tr>

					<tr>
						<td>&nbsp;</td>
						<td></td>
						<td></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-mobile setting-icon"></i> Show on mobile
						</td>
						<td><?=$this->buttonGetShowPhone($iButtonId)?><label for="button_<?=$iButtonId?>_show_on_phone"> Yes</label></td>
						<td></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-desktop setting-icon"></i> Show on desktop
						</td>
						<td><?=$this->buttonGetShowDesktop($iButtonId)?><label for="button_<?=$iButtonId?>_show_on_desktop"> Yes</label></td>
						<td></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-tag setting-icon"></i> Hide label

                            <span class="info-class">
                                <i class="fa fa-info-circle"></i>
                                <span>
                                    This is the label what the guest on your website will see. Something like 'Contact me!', or 'Like us on Facebook'
                                </span>
                            </span>
						</td>
						<td><?=$this->buttonGetHideLabel($iButtonId)?><label for="button_<?=$iButtonId?>_hide_label"> Yes</label></td>
						<td></td>
					</tr>

					<tr>
						<td>&nbsp;</td>
						<td></td>
						<td></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-clock-o setting-icon"></i> Show <b>only</b> on opening hours
						</td>
						<td><?=$this->buttonGetShowWenOpen($iButtonId)?><label for="button_<?=$iButtonId?>_show_when_opened"> Yes</label></td>
						<td></td>
					</tr>

					<tr class="settings-row">
						<td>
							<i class="fa fa-times-circle-o setting-icon"></i> Show <b>only outside</b> opening hours
						</td>
						<td><?=$this->buttonGetShowNotWenOpen($iButtonId)?><label for="button_<?=$iButtonId?>_show_not_when_opened"> Yes</label></td>
						<td></td>
					</tr>
				</table>
			</div>
		</div>
		<?php
    }

    /*
     * Form functions
     */
     // Get the text of the button
 	function buttonGetText($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_text';

 		$fieldValue = (isset($this->aSavedData[$fieldName]) ? ($this->aSavedData[$fieldName]) : 'New button');

 		return '<input type="text" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="'. $fieldValue .'" class="button_textfield" placeholder="Button text" />';
 	}

 	// Get button icon
 	function buttonGetIcon($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_icon';

 		$fab_icon_image = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		$p = '<select name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" style="font-family: \'FontAwesome\', \'Helvetica\';" class="button_iconfield fa-chooser">';

 		foreach($this->aFontAwesome as $key=>$row) {
 			$p .= '<option value="'. $key . '" '. ($fab_icon_image == $key ? 'selected="selected"' : '') . '>'. $row ." ".$key .'</option>';
 		}

 		return $p;
 	}

 	// Get button icon
 	function buttonOutputIcon($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_icon';

 		return (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'fa-info');
 	}

 	// Only show this button on phone?
 	function buttonGetShowPhone($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_show_on_phone';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_showonphone" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}

 	// buttonGetShowOnPages
 	function buttonGetShowOnPages($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_show_on_pages';

 		$is_selected = (isset($this->aSavedData[$fieldName]) ? ($this->aSavedData[$fieldName]) : '');

 		$pageOrders = (isset($this->aPageCategories['categorieOrder']) ? $this->aPageCategories['categorieOrder'] : []);

 		/*
 		 * Generate <select>
 		 */
 		$html = '<select name="buttonizer_buttons['. $fieldName .']" id="button_category"><option value="-5">Show on every page</option><option value="-4">Hide everywhere</option>';
 		foreach($pageOrders as $arrayKey => $pageKey) {
 			if($pageKey == -1) { continue; }

 			$html .= '<option value="'. $pageKey .'"'. ($pageKey == $is_selected ? 'selected="selected"' : '') .'>'. $this->aPageCategories['category_' . $pageKey . '_title'] .'</option>';
 		}
 		return $html . '</select>';
 	}

 	// Only show this button on desktop?
 	function buttonGetShowDesktop($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_show_on_desktop';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_showondesktop" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}

 	// Only show when company is open?
 	function buttonGetShowWenOpen($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_show_when_opened';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_showwhenopened" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}

 	// Only show when company is open?
 	function buttonGetShowNotWenOpen($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_show_not_when_opened';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_showwhenopened" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}

 	function buttonGetHideLabel($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_hide_label';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_hidelabel" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}

 	// Is this a phone number?
 	function buttonGetIsPhoneNumber($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_is_phonenumber';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_isphonenumber" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}

 	function buttonGetUrl($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_url';

 		$fieldValue = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="text" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="'. $fieldValue .'" class="button_isurl" placeholder="URL/Phone number" />';
 	}

 	// Only show this button on phone?
 	function buttonGetNewTab($iButtonId = 0) {
 		$fieldName = 'button_' . $iButtonId . '_url_newtab';

 		$is_selected = (isset($this->aSavedData[$fieldName])?( $this->aSavedData[$fieldName] ):'');

 		return '<input type="checkbox" name="buttonizer_buttons['. $fieldName .']" id="'. $fieldName .'" value="1" class="button_isnewtab" '. ($is_selected == '1' ? 'checked="checked"' : '') .' />';
 	}
}

```
