Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_body.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
57  protected function _printPaintingCode()
58  {
59  $format = $this->attr('format');
60 
61  echo '
62  <','?php';
63  // NB we are leaving PHP mode here so that
64  // the following code is echoed rather than executed
65  ?>
66 
67  $body = '';
68  if (SQ_IN_LIMBO) {
69 
70  // Print the Simple Edit Interface
71  $ASSET->printLimbo();
72 
73  } else if ((array_get_index($_GET, 'SQ_ACTION') == 'diff') && ($ASSET->status & SQ_SC_STATUS_SAFE_EDITING) && $ASSET->writeAccess('')) {
74 
75  // Show the diff between system version and edited version
76 
77  // Keep track of used assets for later...
78  $num_previous_gets = count($GLOBALS['SQ_SYSTEM']->am->_get_asset_history);
79 
80  // Get the live contents of the asset being displayed
81  ob_start();
82  $ASSET->printBodyWithPaintLayout();
83  $edited_contents = ob_get_contents();
84  ob_end_clean();
85 
86  // Set the force-system-version flag
87  $GLOBALS['SQ_SYSTEM']->setGlobalDefine('force_system_version', TRUE);
88 
89  // Reload all assets that were used during the previous printbody,
90  // so they know they have to use the system version
91  $used_asset_ids = array_unique(array_slice($GLOBALS['SQ_SYSTEM']->am->_get_asset_history, $num_previous_gets));
92  foreach ($used_asset_ids as $used_asset_id) {
93  $used_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($used_asset_id);
94  if($used_asset)
95  $used_asset->reload();
96  }
97  $ASSET->reload();
98 
99  // Keep track for next time...
100  $num_previous_gets = count($GLOBALS['SQ_SYSTEM']->am->_get_asset_history);
101 
102  // Get the safe edit contents of the asset being displayed
103  ob_start();
104  $ASSET->printBodyWithPaintLayout();
105  $system_version_contents = ob_get_contents();
106  ob_end_clean();
107 
108  // Unset the force-system-version flag
109  $GLOBALS['SQ_SYSTEM']->setGlobalDefine('force_system_version', FALSE);
110 
111  // Reload all assets that were used during the printbody,
112  // so they no longer think they have to use the system version
113  $used_asset_ids = array_unique(array_slice($GLOBALS['SQ_SYSTEM']->am->_get_asset_history, $num_previous_gets));
114  foreach ($used_asset_ids as $used_asset_id) {
115  $used_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($used_asset_id);
116  if($used_asset)
117  $used_asset->reload();
118  }
119  $ASSET->reload();
120 
121  // Show the differences
122  require_once SQ_CORE_PACKAGE_PATH.'/designs/design_areas/design_area_body/matrix_diff_highlighter.inc';
123  $highlighter = new Matrix_Diff_Highlighter();
124  echo $highlighter->process($system_version_contents, $edited_contents);
125 
126  } else {
127 
128  // Print the body as normal
129  if ($ASSET->_is_cacheable) {
130  $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cache_manager');
131  $body = $cm->loadFromCache($ASSET->id, $ASSET->type());
132  }
133 
134  // If cache MISS, or not cacheable at all
135  if (!$ASSET->_is_cacheable || ($body === FALSE)) {
136  ob_start();
137  $ASSET->printBodyWithPaintLayout();
138  $body = ob_get_contents();
139  ob_end_clean();
140  }
141 
142  <?php
143  switch ($format) {
144  case 'low_bandwidth':
145  // low bandwidth design - strip images, embeds, objects, and additional whitespace
146  echo '
147  $body = preg_replace(\'|\s+|\', \' \', $body);
148  $body = str_replace(\'<br />\', \'<br/>\', $body);
149  $body = str_replace(\'<br/>\', "\n", $body);
150  $body = preg_replace(\'|\n\s+|\', "\n", $body);
151  $body = preg_replace(\'|[\n]+|\', "\n", $body);
152  $body = str_replace("\n", \'<br/>\', $body);
153  ';
154 
155  // break is missing on purpose
156 
157  case 'text':
158  // text only design - strip images, embeds and objects
159  echo '
160  $body = preg_replace(\'|<img([^>]*)>|Ui\',\'\',$body);
161  $body = preg_replace(\'|\\<embed(.*)>(.*)</embed>|i\',\'\',$body);
162  $body = preg_replace(\'|\\<object(.*)>(.*)</object>|i\',\'\',$body);
163  ';
164  break;
165  }
166  ?>
167  echo $body;
168 
169  }//end else print normally
170  <?php
171  echo '
172  ?','>';
173 
174  return TRUE;
175 
176  }//end _printPaintingCode()
177 
178 
185  public function canBeCached()
186  {
187  return FALSE;
188 
189  }//end canBeCached()
190 
191 
192 }//end class
193 ?>