Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_add_web_path.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
19 
32 {
33 
34 
55  public static function execute($settings, &$state)
56  {
57  // check required settings
58  if (empty($settings['path'])) return FALSE;
59 
60  if (empty($state['asset'])) {
61  // grab the asset if assetid is given, but not the asset.
62  if (empty($state['assetid'])) {
63  return FALSE;
64  } else {
65  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
66  }
67  }
68 
69  if (is_null($state['asset'])) return FALSE;
70 
71  // replace keywords
72  $web_path = self::replaceKeywordsInWebPath($settings['path'], $state['asset']);
73  $valid_paths = make_valid_web_paths(Array($web_path));
74  $web_path = array_shift($valid_paths);
75 
76  // lowercase the new web path, if needed
77  if (!empty($settings['make_lowercase'])) {
78  $web_path = strtolower($web_path);
79  }
80 
81  // add the new web path
82  $web_paths_new = $web_paths_old = $state['asset']->getWebPaths();
83  if (!in_array($web_path, $web_paths_new)) {
84  $web_paths_new[] = $web_path;
85  }
86 
87  // remove all other paths, if needed
88  if (!empty($settings['remove_all'])) {
89  $web_paths_new = Array($web_path);
90  }
91 
92  // don't add remaps, if set so
93  $add_auto_remaps = !isset($settings['dont_add_remap']) || !$settings['dont_add_remap'];
94 
95  // only save the new paths if they have changed
96  // (note that lookups are updated by the saveWebPaths fn)
97  if ($web_paths_new !== $web_paths_old) {
98  if (!$state['asset']->saveWebPaths($web_paths_new, $add_auto_remaps)) {
99  return FALSE;
100  }
101 
102  // note that we dont update the lookups of all our children so we have
103  // the greatest level of control over what occurs during things like imports
104 
105  // probably need another trigger action to update lookups (run the HIPO job)
106  }
107 
108  //update lookups for children
109  if(!empty($settings['update_children'])){
110  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
111  $vars = Array('assetids' => Array($state['asset']->id));
112  $lookup_errors = $hh->freestyleHipo('hipo_job_update_lookups', $vars);
113  if (!empty($lookup_errors)) {
114  return FALSE;
115  }
116  }
117 
118  return Array(
119  'assetid' => $state['asset']->id,
120  'path' => $web_path,
121  );
122 
123  }//end execute()
124 
125 
138  public static function replaceKeywordsInWebPath($web_path, Asset $event_asset)
139  {
140  // replace global keywords
141  replace_global_keywords($web_path);
142 
143  // replace event asset keywords
144  $keywords = retrieve_keywords_replacements($web_path);
145  $replacements = Array();
146  foreach ($keywords as $keyword) {
147  $replacements[$keyword] = $event_asset->getKeywordReplacement($keyword);
148  }
149  replace_keywords($web_path, $replacements);
150 
151  return $web_path;
152 
153  }//end replaceKeywordsInWebPath()
154 
155 
166  public static function getInterface($settings, $prefix, $write_access=FALSE)
167  {
168  ob_start();
169 
170  $web_path = array_get_index($settings, 'path', '');
171  echo translate('add_web_path').' ';
172  if ($write_access) {
173  text_box($prefix.'[path]', $web_path, 40);
174  } else {
175  echo '<b>'.$web_path.'</b>';
176  }
177  echo '<br />';
178  echo '<div class="sq-backend-section-note">'.translate('trigger_add_web_path_note').'</div>';
179  check_box($prefix.'[remove_all]', '1', array_get_index($settings, 'remove_all', '0'), '', ($write_access ? '' : 'disabled="disabled"'));
180  echo '<label for='.$prefix.'[remove_all]'.'>'.translate('trigger_add_web_path_remove_all').'.</label>';
181  echo '<br />';
182  check_box($prefix.'[make_lowercase]', '1', array_get_index($settings, 'make_lowercase', '0'), '', ($write_access ? '' : 'disabled="disabled"'));
183  echo '<label for='.$prefix.'[make_lowercase]'.'>'.translate('trigger_add_web_path_make_lowercase').'.</label>';
184  echo '<br />';
185  check_box($prefix.'[update_children]', '1', array_get_index($settings, 'update_children', '0'), '', ($write_access ? '' : 'disabled="disabled"'));
186  echo '<label for='.$prefix.'[update_children]'.'>'.translate('trigger_add_web_path_update_children').'.</label>';
187  echo '<br />';
188  check_box($prefix.'[dont_add_remap]', '1', array_get_index($settings, 'dont_add_remap', '0'), '', ($write_access ? '' : 'disabled="disabled"'));
189  echo '<label for='.$prefix.'[dont_add_remap]'.'>'.translate('trigger_add_web_path_dont_add_remap').'.</label>';
190  return ob_get_clean();
191 
192  }//end getInterface()
193 
194 
206  public static function processInterface(&$settings, $request_data)
207  {
208  $web_path = array_get_index($request_data, 'path', '');
209  $web_path = trim($web_path);
210  if ($web_path == '') {
211  return translate('web_path_not_specified');
212  }
213  $settings['path'] = $web_path;
214  $settings['remove_all'] = array_get_index($request_data, 'remove_all', '');
215  $settings['make_lowercase'] = array_get_index($request_data, 'make_lowercase', '');
216  $settings['update_children'] = array_get_index($request_data, 'update_children', '');
217  $settings['dont_add_remap'] = array_get_index($request_data, 'dont_add_remap', '');
218  return FALSE;
219 
220  }//end processInterface()
221 
222 
232  public static function getLocks($settings, &$state)
233  {
234  return Array($state['assetid'] => Array('lookups'));
235 
236  }//end getLocks()
237 
238 
239 }//end class
240 
241 ?>