function getButtons()
 {
     // should maybe but a 'light init' of buttons?
     $selection = $this->data["selection"];
     $buttonsArray = array();
     if (count($selection) == 0) {
         return $buttonsArray;
     }
     $table = maxUtils::get_buttons_table_name();
     $query_selection = $selection;
     $selectstring = implode($query_selection, ",");
     $sql = "SELECT DISTINCT * FROM {$table} WHERE id in (" . $selectstring . ")";
     global $wpdb;
     $results = $wpdb->get_results($sql, ARRAY_A);
     $data_array = array();
     foreach ($results as $result) {
         $data_array[$result['id']] = $result;
     }
     foreach ($selection as $button_id) {
         $button = MB()->getClass("button");
         // performance: bypass the set ( = query ) for every button
         //$button->set($button_id);
         $data = isset($data_array[$button_id]) ? $data_array[$button_id] : array();
         if (count($data) > 0) {
             maxButtons::buttonLoad(array("button_id" => $button_id));
             // central registration - from button
             $button->setupData($data);
         }
         maxButtons::forceNextID();
         $buttonsArray[] = $button;
     }
     return $buttonsArray;
 }
Exemplo n.º 2
0
 function set($id = 0, $name = '', $status = 'publish')
 {
     maxUtils::addTime("Button set {$id}");
     $id = intval($id);
     $name = sanitize_text_field($name);
     $status = sanitize_text_field($status);
     global $wpdb;
     $this->clear();
     // clear the internals of any previous work
     // check to see if the value passed is NOT numeric. If it is, use title, else assume numeric
     if ($id == 0 && $name != '') {
         $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . maxUtils::get_buttons_table_name() . " WHERE name = '%s' and status ='%s'", trim($name), $status), ARRAY_A);
     } else {
         $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . maxUtils::get_buttons_table_name() . " WHERE id = %d and status ='%s'", $id, $status), ARRAY_A);
     }
     if (count($row) == 0) {
         return false;
     }
     /* Take the id from the query, otherwise ( when button shortcode called by name ) id might not be present properly' */
     $button_id = $row["id"];
     maxButtons::buttonLoad(array("button_id" => $button_id));
     // central registration
     return $this->setupData($row);
 }
    function do_social_option($button_id, $data, $button_array = array())
    {
        global $supported_networks, $share_url_settings;
        extract($data);
        $index = $data["index"];
        $button = MB()->getClass("button");
        if ($button_id > 0 && (!isset($button_array["meta"]) || !$button_array["meta"]["is_virtual"])) {
            $button->set($button_id);
        } elseif (count($button_array) > 0) {
            $button_array["name"] = $button_array["basic"]["name"];
            $button_array["status"] = $button_array["basic"]["status"];
            $button->clear();
            maxButtons::buttonLoad(array("button_id" => $button_id));
            // central registration - from button
            $button->setupData($button_array);
        }
        $document_id = $button->getDocumentID();
        ?>
	<div class="social-option" data-id="<?php 
        echo $button_id;
        ?>
" data-document_id="<?php 
        echo $document_id;
        ?>
"> 
		<input type="hidden" name="social-option[]" value="<?php 
        echo $button_id;
        ?>
" /> 
		<div class="option"> 
			<div class="shortcode-container">
			<?php 
        $button->display(array("mode" => "preview"));
        ?>

			</div>
					<span class="button_name"><?php 
        echo $button->getName();
        ?>
</span>
		</div>
		
		
		<div class="option  "> 
			<label><?php 
        _e("Sharing network", "maxbuttons");
        ?>
</label>
			<?php 
        echo maxUtils::selectify("network-{$button_id}-{$index}", $supported_networks, $network, 'network');
        ?>
 
			
		</div>
		
		<div class="option conditional-option"  data-show="<?php 
        echo $this->do_supports('display_count', $button_id, $index);
        ?>
"> 
			<label><?php 
        _e("Show Share Counts", "maxbuttons");
        ?>
</label>
			<input type="checkbox" name="display_count-<?php 
        echo $button_id;
        ?>
-<?php 
        echo $index;
        ?>
" value="1" <?php 
        checked($display_count, 1);
        ?>
  /> 
		</div>
		
		<div class="option conditional-option"  data-show="<?php 
        echo $this->do_supports('count_threshold', $button_id, $index);
        ?>
"> 
			<label><?php 
        _e("Minimum share count", "maxbuttons");
        ?>
</label>
			<input type="number" name="count_threshold-<?php 
        echo $button_id;
        ?>
-<?php 
        echo $index;
        ?>
" min="0" 
			value="<?php 
        echo intval($count_threshold);
        ?>
" />  
		</div>	

		<div class="option conditional-option"  data-show="<?php 
        echo $this->do_supports('share_url_setting', $button_id, $index);
        ?>
"> 
			<label><?php 
        _e("Share URL settings", "maxbuttons");
        ?>
</label>
			<?php 
        echo maxUtils::selectify("share_url_setting-{$button_id}-{$index}", $share_url_settings, $share_url_setting);
        ?>
			 

			<div class="help fa fa-question-circle "> 
			<span><?php 
        _e("Which URL (link) is to be shared. Auto will share the current page on pages, and the full site URL on the homepage", "maxbuttons");
        ?>
 
				</span>
			</div>
				
		</div>	
		
		<!-- bloglovin --> 
		<div class="option conditional-option"  data-show="<?php 
        echo $this->do_supports('blog_url', $button_id, $index);
        ?>
"> 
			<label><?php 
        _e("Bloglovin' Blog URL", "maxbuttons");
        ?>
</label>
			<input type="text" name="blog_url-<?php 
        echo $button_id;
        ?>
-<?php 
        echo $index;
        ?>
"
				 value="<?php 
        echo esc_attr($blog_url);
        ?>
"> 
		</div>
		
	<?php 
        $condition = array("target" => "share_url_setting-{$button_id}-{$index}", "values" => array("custom-url"));
        $custom_conditional = htmlentities(json_encode($condition));
        ?>
	
			
  		
		<div class="option conditional-option" data-show="<?php 
        echo $custom_conditional;
        ?>
">	
			<label><?php 
        _e("Custom URL", "maxbuttons");
        ?>
</label> 
			<input type="text" name="share_url_custom-<?php 
        echo $button_id;
        ?>
-<?php 
        echo $index;
        ?>
"
			 value="<?php 
        echo esc_attr($share_url_custom);
        ?>
"> 
  
		</div>
	</div> <!-- social option --> 
		<?php 
    }