Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
css_file.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/files/file/file.inc';
18 
27 class CSS_File extends File
28 {
29 
30 
36  public $allowed_extensions = Array('css');
37 
38 
45  function __construct($assetid=0)
46  {
47  parent::__construct($assetid);
48 
49  }//end constructor
50 
51 
62  public function create(Array &$link, $info=Array())
63  {
64  $this->_tmp['file_create_data'] =& $info;
65 
66  if (empty($info)) {
67  // Try getting the uploaded file details
68  $info = get_file_upload_info($this->getPrefix());
69  }
70 
71  if ($info === FALSE || empty($info)) {
72  // See if they've chosen a pre-uploaded file
73  $edit = $this->getEditFns();
74  $info = $edit->getChosenFileInfo($this->getPrefix());
75  }
76 
77  $file_name = '';
78  if ($GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
79 
80  // When no file is supplied via uploaded, create a new file
81  if ($info === FALSE || empty($info)) {
82 
83  $file_title = trim($this->attr('title'));
84  $file_title = preg_replace('/\s/', '_', $file_title);
85  $file_title = preg_replace('/[^A-Za-z0-9_\-]/', '', $file_title);
86 
87  // Take first name from the allowed extension names array for this file
88  $extension = $this->allowed_extensions[0];
89 
90  $file_name = $file_title . '.' . $extension;
91 
92  $create_location = SQ_SYSTEM_ROOT.'/'.'data/temp';
93  // Create an temporary empty file
94  if (!fopen($create_location.'/'.$file_name, 'w+')) {
95  trigger_localised_error('SYS0025', E_USER_WARNING, $file_name. " from given title ".$file_title);
96  return FALSE;
97  }
98 
99  // Create info array for the file just created
100 
101  $info = Array();
102 
103  $info['name'] = $file_name;
104  $info['tmp_name'] = $create_location;
105  $info['created_file'] = TRUE;
106  }
107  }
108 
109  // Make the info array look like a result from getExistingFile()
110  if (!isset($info['path'])) {
111  $info['path'] = array_get_index($info, 'tmp_name', '');
112  }
113  if (!isset($info['filename'])) {
114  $info['filename'] = array_get_index($info, 'name', '');
115  }
116 
117  if ($GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
118  if (!$this->validFile($info)) return FALSE;
119  }
120 
121  if ($GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
122  // Check that we are not going to have web path conflicts
123  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
124  $valid_names = make_valid_web_paths(Array($info['name']));
125  $name = array_shift($valid_names);
126 
127  // Make grep sure the new web path is not already is use
128  $bad_paths = $GLOBALS['SQ_SYSTEM']->am->webPathsInUse($link['asset'], Array($name));
129  if (!empty($bad_paths)) {
130  trigger_localised_error('CORE0086', E_USER_WARNING, $name);
131  return FALSE;
132  }
133 
134  $this->setAttrValue('name', $name);
135  }//end if
136 
137  return parent::create($link, $info);
138 
139  }//end create()
140 
141 }//end class
142 ?>