26 error_reporting(E_ALL);
27 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
29 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
30 if (empty($SYSTEM_ROOT)) {
31 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
35 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
36 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
40 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
41 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
42 $ROOT_PATH = SQ_FUDGE_PATH.
'/wysiwyg/';
43 require_once SQ_FUDGE_PATH.
'/wysiwyg/plugins/html_tidy/html_tidy.inc';
45 $ROOT_ASSETID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'1';
46 if ($ROOT_ASSETID == 1) {
47 echo
"\nWARNING: You are running this checker on the whole system.\nThis is fine but:\n\tit may take a long time; and\n\tit will acquire locks on many of your assets (meaning you wont be able to edit content for a while)\n\n";
51 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
54 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
55 echo
"ERROR: Failed loggin in as root user\n";
60 $tmp->_running_vars[
'cache_dirs'] = Array();
61 $dh = opendir(SQ_CACHE_PATH);
62 while (
false !== ($file = readdir($dh))) {
63 if ($file ==
'.' || $file ==
'..')
continue;
64 if (!is_dir(SQ_CACHE_PATH.
'/'.$file))
continue;
67 if (!preg_match(
'|\d{4}|', $file))
continue;
71 $tmp->_running_vars[
'cache_dirs'][] = $file;
76 $wysiwygids = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($ROOT_ASSETID,
'content_type_wysiwyg',
false);
77 foreach ($wysiwygids as $wysiwygid => $type_code_data) {
78 $type_code = $type_code_data[0][
'type_code'];
79 $wysiwyg = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($wysiwygid, $type_code);
80 printAssetName(
'WYSIWYG #'.$wysiwyg->id);
83 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($wysiwyg->id,
'attributes')) {
84 printUpdateStatus(
'LOCKED');
85 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
89 $old_html = $wysiwyg->attr(
'html');
94 $tidy->process($html);
96 if ($tidy->htmltidy_status !=
'pass' || !$wysiwyg->setAttrValue(
'html', $html) || !$wysiwyg->setAttrValue(
'htmltidy_status', $tidy->htmltidy_status) || !$wysiwyg->setAttrValue(
'htmltidy_errors', $tidy->htmltidy_errors) || !$wysiwyg->saveAttributes()) {
97 printUpdateStatus(
'TIDY FAIL');
98 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
106 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($wysiwyg->id,
'attributes')) {
107 printUpdateStatus(
'UNLOCK FAIL');
108 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
112 printUpdateStatus(
'TIDY PASS');
115 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($wysiwyg->id);
116 foreach ($parents as $parent) {
117 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent);
118 if (!$parent_asset->saveSystemVersion()) {
119 printAssetName($parent_asset->name.
' (#'.$parent_asset->id.
')');
120 printUpdateStatus(
'CONTENT FAIL');
123 printAssetName($parent_asset->name.
' (#'.$parent_asset->id.
')');
124 printUpdateStatus(
'CONTENT PASS');
127 $cm = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
133 $assetid_code = md5($parent_asset->id);
134 $group = $cm->getAssetHash($assetid_code);
136 foreach ($tmp->_running_vars[
'cache_dirs'] as $dir) {
137 if (substr($dir, 0, strlen($group)) == $group) {
141 $dh = opendir(SQ_CACHE_PATH.
'/'.$dir);
143 while (
false !== ($file = readdir($dh))) {
144 $abs_path = SQ_CACHE_PATH.
'/'.$dir.
'/'.$file;
145 if (is_dir($abs_path))
continue;
148 if (substr($file, 0, strlen($assetid_code)) == $assetid_code) unlink($abs_path);
149 printAssetName($parent_asset->name.
' (#'.$parent_asset->id.
')');
150 printUpdateStatus(
'CACHE CLEAR');
159 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
174 function printAssetName($name)
176 printf (
'%s%'.(30 - strlen($name)).
's', $name,
'');
189 function printUpdateStatus($status)
191 echo
" [ $status ] \n";