Esempio n. 1
0
 /**
  * Save CSS
  * @param string $filePath
  * @param string $selector
  * @return string 
  */
 protected function saveCSSAction($changes)
 {
     $changes = json_decode($changes, TRUE);
     if (!empty($changes)) {
         foreach ($changes as $file => $selectors) {
             /* If CSS file doesn't exists in profile/ dir, we create a copy from modules/ */
             if (!is_file(PROFILE_PATH . $file) && is_file('modules/' . $file)) {
                 \tools::file_put_contents(PROFILE_PATH . $file, file_get_contents('modules/' . $file));
             }
             $filePath = PROFILE_PATH . $file;
             $cssFile = new \css($filePath);
             if (!empty($selectors)) {
                 foreach ($selectors as $rule) {
                     $code = trim($rule['value']);
                     if (!empty($code)) {
                         if (!$cssFile->selectorExists($rule['selector'], $rule['media'])) {
                             $cssFile->addSelector($rule['selector'], $rule['media']);
                         }
                     }
                     $cssFile->replaceSelector($rule['selector'], $code, $rule['media']);
                 }
                 $cssFile->save();
             }
         }
     }
     $return = array('notification' => t('The style sheet has been saved'), 'notificationType' => 'positive');
     return $this->returnResult($return);
 }