# buttonizer-multifunctional-button/1.0.4/trunk/classes/admin/Buttons.php

Buttonizer – Floating Menus, Sticky Buttons, &amp; Popup Builder, version 1.0.4. 424 lines.

- Page: https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.4/code/trunk/classes/admin/Buttons.php
- Raw: https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.4/raw/trunk/classes/admin/Buttons.php
- Modified: 2017-09-29T15:33:28+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.4/code/trunk/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 = array() ;
    private  $aPageCategories = array() ;
    private  $aFontAwesome = array() ;
    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'] : array(
            0 => -1,
        ) );
        if ( $aButtons[0] != '-1' ) {
            $aButtons[-1] = '-1';
        }
        echo  '<ul id="button-rows">' ;
        $iButtonCount = 0;
        foreach ( $aButtons as $sButtonKey => $iButtonId ) {
            $this->loadIndividialButtonRow( $sButtonKey, $iButtonId, ( isset( $bDisabled ) ? true : false ) );
            $iButtonCount++;
        }
        echo  '</ul>' ;
        echo  '<img src="' . plugins_url( '/assets/no-buttons.jpg', BUTTONIZER_PLUGIN_DIR ) . '" style="' . (( 0 == $iButtonCount - 1 ? 'display: block;' : 'display: none;' )) . '" class="buttonizer-no-buttons" />' ;
    }
    
    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'] : '' );
        ?>
        <li>
    		<div class="button-row" id="btn_row_<?php 
        echo  $iButtonId ;
        ?>
" button-id="<?php 
        echo  $iButtonId ;
        ?>
"<?php 
        if ( $iButtonId == -1 ) {
            echo  ' style="display: none"' ;
        }
        ?>
>
    			<input type="checkbox" name="buttonizer_buttons[buttonorder][]" value="<?php 
        echo  $iButtonId ;
        ?>
" checked="checked" style="display: none;" />

    			<div class="row-info drag-handle">
                    <div class="mover"></div>
    				<span><i class="fa <?php 
        echo  $this->buttonOutputIcon( $iButtonId ) ;
        ?>
 button-icon"></i> <span class="row-title"><?php 
        echo  ( $iButtonId == -1 ? 'New button' : $sButtonTitle ) ;
        ?>
</span> <i class="fa fa-pencil pencil-edit"></i></span>

    				<a href="javascript:buttonizer.removeRow(<?php 
        echo  $iButtonId ;
        ?>
)" class="delete-button">Delete <i class="fa fa-trash-o"></i></a>

    				<a href="javascript:buttonizer.toggleMobile(<?php 
        echo  $iButtonId ;
        ?>
)" class="mobiledesktop mobile-button <?php 
        echo  ( $onMobile == '' ? 'selected' : '' ) ;
        ?>
"><i class="fa fa-mobile"></i></a>
    				<a href="javascript:buttonizer.toggleDesktop(<?php 
        echo  $iButtonId ;
        ?>
)" class="mobiledesktop desktop-button <?php 
        echo  ( $onDesktop == '' ? 'selected' : '' ) ;
        ?>
"><i class="fa fa-desktop"></i></a>

                    <a href="javascript:void(0)" class="is-live-button" style="<?php 
        echo  ( $onMobile != '' || $onDesktop != '' ? '' : 'display: none;' ) ;
        ?>
"><i class="fa fa-circle"></i> Live</a>

                    <button type="submit" class="must-save-button savebutton " style="display: none;"><i class="fa fa-floppy-o"></i> Save changes</button>
                </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_<?php 
        echo  $iButtonId ;
        ?>
_title]" value="<?php 
        echo  $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>
    							<?php 
        echo  $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>
    							<?php 
        echo  $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>
    							<?php 
        echo  $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"><?php 
        echo  $this->buttonGetUrl( $iButtonId ) ;
        ?>
</td>
    					</tr>

    					<tr class="settings-row">
    						<td>
    							<i class="fa fa-phone setting-icon"></i> Is phone number
    						</td>
    						<td><?php 
        echo  $this->buttonGetIsPhoneNumber( $iButtonId ) ;
        ?>
<label for="button_<?php 
        echo  $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><?php 
        echo  $this->buttonGetNewTab( $iButtonId ) ;
        ?>
<label for="button_<?php 
        echo  $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><?php 
        echo  $this->buttonGetShowPhone( $iButtonId ) ;
        ?>
<label for="button_<?php 
        echo  $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><?php 
        echo  $this->buttonGetShowDesktop( $iButtonId ) ;
        ?>
<label for="button_<?php 
        echo  $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><?php 
        echo  $this->buttonGetHideLabel( $iButtonId ) ;
        ?>
<label for="button_<?php 
        echo  $iButtonId ;
        ?>
_hide_label"> Yes</label></td>
    						<td></td>
    					</tr>

    					<tr>
    						<td>&nbsp;</td>
    						<td></td>
    						<td></td>
    					</tr>

                        <?php 
        ?>
                        <tr class="settings-row">
                            <td>
                                <i class="fa fa-clock-o setting-icon"></i> Show <b>only</b> on opening hours
                            </td>
                            <td><input type="checkbox" class="buttonizer-click-to-pro" readonly=""> <label> Yes</label> <span class="buttonizer-pro-feature">PRO</span></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><input type="checkbox" class="buttonizer-click-to-pro" readonly=""> <label> Yes</label> <span class="buttonizer-pro-feature">PRO</span></td>
                            <td></td>
                        </tr>
                        <?php 
        ?>
    				</table>
    			</div>
    		</div>
        </li>
		<?php 
    }
    
    /*
     * Form functions
     */
    // Get the text of the button
    public 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
    public 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
    public function buttonOutputIcon( $iButtonId = 0 )
    {
        $fieldName = 'button_' . $iButtonId . '_icon';
        return ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : 'fa-info' );
    }
    
    // Only show this button on phone?
    public 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
    public 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'] : array() );
        /*
         * 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?
    public 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?
    public 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?
    public 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"' : '' )) . ' />';
    }
    
    public 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?
    public 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"' : '' )) . ' />';
    }
    
    public 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?
    public 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"' : '' )) . ' />';
    }

}
```
