ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

ContentSectionsListControl.php (3880B)


      1 <?php
      2 
      3 namespace Materialis\Customizer\Controls;
      4 
      5 class ContentSectionsListControl extends RowsListControl
      6 {
      7     public function init()
      8     {
      9         $this->cpData['type']      = 'mod_changer';
     10         $this->type                = $this->cpData['type'];
     11         $this->cpData['selection'] = apply_filters('cloudpress\customizer\control\content_sections\multiple', 'check');
     12         parent::init();
     13     }
     14 
     15     public function alterSourceData($data)
     16     {
     17         $categorized = array();
     18 
     19 
     20         foreach ($data as $id => $item) {
     21             if ( ! isset($item['category'])) {
     22                 $item['category'] = 'general';
     23             }
     24 
     25             $category = strtolower($item['category']);
     26 
     27             if ( ! isset($categorized[$category])) {
     28                 $categorized[$category] = array();
     29             }
     30 
     31             $categorized[$category][$item['id']] = $item;
     32         }
     33 
     34         $categorized = apply_filters('cloudpress\customizer\control\content_sections\data', $categorized);
     35 
     36         return $categorized;
     37     }
     38 
     39     public function renderModChanger()
     40     {
     41         $items = $this->getSourceData();
     42         ?>
     43 
     44         <ul <?php $this->dataAttrs(); ?> class="list rows-list">
     45             <?php foreach ($items as $category => $data): ?>
     46 
     47                 <?php
     48                 $data  = apply_filters('cloudpress\customizer\control\content_sections\category_data', $data, $category);
     49                 $label = apply_filters('cloudpress\customizer\control\content_sections\category_label', $category, $category);
     50                 ?>
     51 
     52                 <li data-category="<?php echo $category ?>" class="category-title">
     53                     <span><?php echo $label; ?></span>
     54                 </li>
     55 
     56                 <?php foreach ($data as $item): ?>
     57                     <?php $used = ($item['id'] === $this->value()) ? "already-in-page" : ""; ?>
     58                     <?php $proOnly = isset($item['pro-only']) ? "pro-only" : ""; ?>
     59 
     60                     <li title="<?php echo $item['id']; ?>" class="item available-item <?php echo $used; ?> <?php echo $proOnly; ?>" data-id="<?php echo $item['id']; ?>">
     61                         <div class="image-holder" style="background-position:center center;">
     62                             <img data-src="<?php echo $item['thumb']; ?>" src=""/>
     63                         </div>
     64 
     65                         <?php if ($proOnly) : ?>
     66                             <span data-id="<?php echo $item['id']; ?>" data-pro-only="true" class="available-item-hover-button" <?php $this->getSettingAttr(); ?> >
     67                                 <?php _e('Available in PRO', 'cloudpress-companion') ?>
     68                             </span>
     69                         <?php else: ?>
     70                             <span data-id="<?php echo $item['id']; ?>" class="available-item-hover-button" <?php $this->getSettingAttr(); ?> >
     71                                 <?php echo $this->cpData['insertText']; ?>
     72                             </span>
     73                         <?php endif; ?>
     74 
     75                         <div title="Section is already in page" class="checked-icon"></div>
     76                         <div title="Pro Only" class="pro-icon"></div>
     77                         <span class="item-preview" data-preview="<?php echo $item['preview']; ?>">
     78                             <i class="icon"></i>
     79                         </span>
     80                         <?php if (isset($item['description'])): ?>
     81                             <span class="description"> <?php echo $item['description']; ?> </span>
     82                         <?php endif; ?>
     83                     </li>
     84                 <?php endforeach; ?>
     85             <?php endforeach; ?>
     86         </ul>
     87 
     88         <input type="hidden" value="<?php echo esc_attr(json_encode($this->value())); ?>" <?php $this->link(); ?> />
     89 
     90         <?php ;
     91     }
     92 }