1: <?php
 2: 
 3:  4:  5: 
 6: abstract class Quform_Admin_Page_Entries extends Quform_Admin_Page
 7: {
 8:      9: 10: 
11:     protected function enqueueScripts()
12:     {
13:         parent::enqueueScripts();
14: 
15:         wp_enqueue_script('quform-entries', Quform::adminUrl('js/entries.min.js'), array('jquery'), QUFORM_VERSION, true);
16: 
17:         wp_localize_script('quform-entries', 'quformEntriesL10n', array(
18:             'setEntryLabelsNonce' => wp_create_nonce('quform_set_entry_labels'),
19:             'errorSettingEntryLabel' => __('An error occurred setting the entry label', 'quform')
20:         ));
21:     }
22: 
23:     24: 25: 26: 27: 28: 
29:     public function getEntryLabelsHtml(array $labels)
30:     {
31:         $output = '<div class="qfb-entry-label-indicators qfb-cf">';
32:         $hasVisibleLabel = false;
33: 
34:         foreach ($labels as $label) {
35:             if (is_array($label)) {
36:                 $classes = array('qfb-entry-label-indicator');
37: 
38:                 if ($this->isColorTransparent($label['color'])) {
39:                     $classes[] = 'qfb-entry-label-indicator-transparent';
40:                 } else {
41:                     $hasVisibleLabel = true;
42:                 }
43: 
44:                 $output .= sprintf(
45:                     '<span class="%s" data-id="%d" style="background-color: %s;"%s></span>',
46:                     Quform::escape(join(' ', $classes)),
47:                     Quform::escape($label['id']),
48:                     Quform::escape($label['color']),
49:                     Quform::isNonEmptyString($label['name']) ? sprintf(' title="%s"', Quform::escape($label['name'])) : ''
50:                 );
51:             }
52:         }
53: 
54:         $output .= sprintf('<i class="qfb-entry-no-labels qfb-icon qfb-icon-tags%s"></i>', $hasVisibleLabel ? ' qfb-hidden' : '');
55: 
56:         $output .= '</div>';
57: 
58:         return $output;
59:     }
60: 
61:     62: 63: 64: 65: 66: 
67:     public function isColorTransparent($color)
68:     {
69:         if ($color == 'transparent') {
70:             return true;
71:         }
72: 
73:         if (preg_match('/rgba\((.+)\)/', $color, $matches)) {
74:             $parts = explode(',', $matches[1]);
75: 
76:             if (count($parts) == 4 && is_numeric($parts[3]) && floatval($parts[3]) === 0.0) {
77:                 return true;
78:             }
79:         }
80: 
81:         return false;
82:     }
83: }
84: