示例#1
0
 protected function _manageButtonInAllConfigs($buttonData, $mode)
 {
     $datasToKeep = array_flip(BBM_Helper_Bbm::getColumnsToKeepInRegistry());
     $buttonData = array_intersect_key($buttonData, $datasToKeep);
     $button_tag = $buttonData['tag'];
     $configs = $this->getAllConfigs();
     foreach ($configs as $config_id => $config) {
         //Only continue if the config was set & wasn't empty (for ie: user delete a default button before to have set a config)
         if (empty($config['config_buttons_full']) || empty($config['config_buttons_order'])) {
             continue;
         }
         $config_type = $config['config_type'];
         $config_ed = $config['config_ed'];
         //Prepare two main elements
         $order = explode(',', $config['config_buttons_order']);
         $full = unserialize($config['config_buttons_full']);
         /***
         				Find the key inside the full configuration of the targeted button 
         				Info: the key is the position of the button and not its tag!
         			**/
         foreach ($full as $buttonIndex => $selectedbutton) {
             if (!isset($selectedbutton['tag'])) {
                 continue;
             }
             if ($selectedbutton['tag'] == $button_tag) {
                 $buttonPositionInFull = $buttonIndex;
                 break;
             }
         }
         if (!isset($buttonPositionInFull)) {
             continue;
         }
         //Modify the button according to the chosen mode
         if ($mode == 'update') {
             if ($buttonData['active']) {
                 $buttonData['class'] = 'activeButton';
             } else {
                 $buttonData['class'] = 'unactiveButton';
             }
             //Update button values in the config
             $full[$buttonPositionInFull] = $buttonData;
         } elseif ($mode == 'delete') {
             $buttonPositionInOrder = array_search($button_tag, $order);
             unset($full[$buttonPositionInFull]);
             unset($order[$buttonPositionInOrder]);
         } elseif ($mode == 'toggleStatus') {
             if ($buttonData['active']) {
                 $full[$buttonPositionInFull]['active'] = 0;
                 $full[$buttonPositionInFull]['class'] = 'unactiveButton';
             } else {
                 $full[$buttonPositionInFull]['active'] = 1;
                 $full[$buttonPositionInFull]['class'] = 'activeButton';
             }
         }
         //Let's prepare the two main elements to be saved in the database
         $full = serialize($full);
         $order = implode(',', $order);
         //Save
         $dw = XenForo_DataWriter::create('BBM_DataWriter_Buttons');
         if ($this->getConfigById($config_id)) {
             $dw->setExistingData($config_id);
         }
         $dw->set('config_type', $config_type);
         $dw->set('config_buttons_order', $order);
         $dw->set('config_buttons_full', $full);
         $dw->save();
         //Update the Registry
         $this->InsertConfigInRegistry();
     }
 }
示例#2
0
 /**
  * 	Get bbcodes with a button option
  */
 public function getBbCodesWithButton($allFields = false)
 {
     $fields = $allFields ? '*' : implode(", ", BBM_Helper_Bbm::getColumnsToKeepInRegistry());
     return $this->fetchAllKeyed("\n\t\t\tSELECT {$fields}\n\t\t\tFROM bbm\n\t\t\tWHERE hasButton = '1'\n\t\t\tORDER BY tag ASC\t\n\t\t", 'tag');
 }