24 error_reporting(E_ALL);
25 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
27 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
28 if (empty($SYSTEM_ROOT)) {
29 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
33 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
34 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
38 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
40 $ROOT_ASSETID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'1';
41 if ($ROOT_ASSETID == 1) {
42 echo
"\nWARNING: You are running this integrity 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";
45 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
48 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
49 echo
"Failed loggin in as root user\n";
54 $wysiwygids = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($ROOT_ASSETID,
'content_type_wysiwyg',
false);
55 foreach ($wysiwygids as $wysiwygid => $type_code_data) {
56 $type_code = $type_code_data[0][
'type_code'];
57 $wysiwyg = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($wysiwygid, $type_code);
58 printWYSIWYGName(
'WYSIWYG #'.$wysiwyg->id);
61 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($wysiwyg->id,
'attributes')) {
62 printUpdateStatus(
'LOCK');
63 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
67 $old_html = $wysiwyg->attr(
'html');
68 $new_html = preg_replace(
'|http[s]?://[^\s]+(\?a=[0-9]+)|',
'./\\1', $old_html);
69 if (!$wysiwyg->setAttrValue(
'html', $new_html) || !$wysiwyg->saveAttributes()) {
70 printUpdateStatus(
'FAILED');
71 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($container);
76 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($wysiwyg->id,
'attributes')) {
77 printUpdateStatus(
'!!');
78 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
82 printUpdateStatus(
'OK');
83 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg);
98 function printWYSIWYGName($name)
100 printf (
'%s%'.(30 - strlen($name)).
's', $name,
'');
113 function printUpdateStatus($status)
115 echo
"[ $status ]\n";