How to use verbose method of script class

Best Atoum code snippet using script.verbose

jqueryeasy.php

Source:jqueryeasy.php Github

copy

Full Screen

...26 $this->_supplement_scripts = array();27 $this->_supplement_stylesheets = array();28 29 $this->_showreport = false;30 $this->_verbose_array = array();31 32 $this->_usejQuery = false;33 $this->_usejQueryUI = false;34 35 $this->_enabled = true;36 37 $this->_timeafterroute = 0;38 $this->_timebeforerender = 0;39 $this->_timeafterrender = 0;40 41 $this->_back_compat_path = true;42 }43 44 function onAfterRoute() {45 46 if (JFactory::getDocument()->getType() !== 'html') { 47 // put here so JFactory::getDocument() does not break feeds (will break if used in any function before onAfterRoute)48 // https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-general/S0GYKhLm92A49 $this->_enabled = false;50 return;51 }52 53 $app = JFactory::getApplication(); 54 $doc = JFactory::getDocument();55 56 $this->_showreport = $this->params->get('showreport', false);57 $this->_back_compat_path = $this->params->get('back_compat_paths', true);58 59 $time_start = microtime(true);60 61 $suffix = $app->isAdmin() ? 'backend' : 'frontend';62 63 // disable plugin in selected templates64 if ($app->isSite()) {65 66 $templates_array = $this->params->get('templateid', array('none'));67 68 if (!is_array($templates_array)) { // before the plugin is saved, the value is the string 'none'69 $templates_array = explode(' ', $templates_array);70 }71 72 $array_of_template_values = array_count_values($templates_array);73 if (isset($array_of_template_values['none']) && $array_of_template_values['none'] > 0) { // 'none' was selected74 // keep the plugin enabled75 } else { 76 if (!empty($app->getTemplate(true)->id)) { 77 $current_template_id = $app->getTemplate(true)->id; 78 foreach ($array_of_template_values as $key => $value) {79 if ($current_template_id == $key) {80 $this->_enabled = false;81 return;82 }83 } 84 } 85 } 86 } 87 88 // enable plugin only on the allowed pages89 $includedPaths = trim( (string) $this->params->get('enableonlyin'.$suffix, ''));90 if ($includedPaths) {91 $paths = array_map('trim', (array) explode("\n", $includedPaths));92 $current_uri_string = JURI::getInstance()->toString();93 94 //if ($this->_showreport) {95 // $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_ENABLEPLUGININPAGES');96 // $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_CURRENTURI', $current_uri_string);97 //} 98 99 $found = false;100 foreach ($paths as $path) { 101 $paths_compare = self::path_compare($current_uri_string, $path, $this->_back_compat_path);102 if ($paths_compare) {103 $found = true;104 }105 } 106 if (!$found) {107 $this->_enabled = false;108 return;109 }110 } else { 111 // disable plugin in the listed pages112 $excludedPaths = trim( (string) $this->params->get('disablein'.$suffix, ''));113 if ($excludedPaths) {114 $paths = array_map('trim', (array) explode("\n", $excludedPaths));115 $current_uri_string = JURI::getInstance()->toString();116 117 //if ($this->_showreport) {118 // $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_DISABLEPLUGININPAGES');119 // $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_CURRENTURI', $current_uri_string);120 //} 121 122 foreach ($paths as $path) { 123 $paths_compare = self::path_compare($current_uri_string, $path, $this->_back_compat_path);124 if ($paths_compare) {125 $this->_enabled = false;126 return;127 }128 }129 }130 }131 132 // prepare spaces to fill with script, stylesheets, scripts and stylesheets declarations133 134 $javascript = trim( (string) $this->params->get('addjavascript'.$suffix, ''));135 if (!empty($javascript)) {136 $this->_supplement_scripts = array_map('trim', (array) explode("\n", $javascript));137 $i = 0;138 foreach($this->_supplement_scripts as $path) {139 $doc->addScript("ADD_SCRIPT_HERE".$i);140 $i++;141 }142 }143 144 $javascript_declaration = trim( (string) $this->params->get('addjavascriptdeclaration'.$suffix, ''));145 if (!empty($javascript_declaration)) {146 $doc->addScriptDeclaration("ADD_SCRIPT_DECLARATION_HERE");147 }148 149 $css = trim( (string) $this->params->get('addcss'.$suffix, ''));150 if (!empty($css)) {151 $this->_supplement_stylesheets = array_map('trim', (array) explode("\n", $css));152 $i = 0;153 foreach($this->_supplement_stylesheets as $path) {154 $doc->addStyleSheet("ADD_STYLESHEET_HERE".$i);155 $i++;156 }157 }158 159 $css_declaration = trim( (string) $this->params->get('addcssdeclaration'.$suffix, ''));160 if (!empty($css_declaration)) {161 $doc->addStyleDeclaration("ADD_STYLESHEET_DECLARATION_HERE");162 } 163 164 $useWhat = $this->params->get('jqueryin'.$suffix, 0);165 switch ($useWhat) {166 case 1: $this->_usejQuery = true; break;167 case 2: $this->_usejQuery = true; $this->_usejQueryUI = true; break;168 default: break;169 } 170 171 $time_end = microtime(true);172 $this->_timeafterroute = $time_end - $time_start;173 174 if (!$this->_usejQuery) {175 return;176 }177 178 $jQueryVersion = $this->params->get('jqueryversion'.$suffix, '1.8'); 179 $jQuerySubversion = $this->params->get('jquerysubversion'.$suffix, '');180 if ($jQuerySubversion != '') {181 $jQuerySubversion = '.'.$jQuerySubversion;182 }183 184 $jQueryHTTP = $this->params->get('whichhttp'.$suffix,'https');185 $jQueryHTTP = ($jQueryHTTP == 'none') ? '' : $jQueryHTTP.':';186 187 $jQueryCompressed = '';188 if ($this->params->get('compression'.$suffix,'compressed') == 'compressed') {189 $jQueryCompressed = '.min';190 }191 192 // jQuery path193 194 if ($jQueryVersion == 'local') {195 $localVersionPath = trim($this->params->get('localversion'.$suffix, ''));196 if ($localVersionPath) { 197 if (JFile::exists(JPATH_ROOT.$localVersionPath)) {198 //if (JFile::exists($_SERVER['DOCUMENT_ROOT'].JURI::root(true).$localVersionPath)) {199 $this->_jqpath = JURI::root(true).$localVersionPath;200 } else {201 if ($this->_showreport) {202 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_COULDNOTFINDFILE', JPATH_ROOT.$localVersionPath);203 }204 }205 } else {206 if ($this->_showreport) {207 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_EMPTYLOCALFILE', 'jQuery');208 }209 }210 } else {211 $this->_jqpath = $jQueryHTTP."//ajax.googleapis.com/ajax/libs/jquery/".$jQueryVersion.$jQuerySubversion."/jquery".$jQueryCompressed.".js";212 }213 214 if (!empty($this->_jqpath)) {215 $doc->addScript("JQEASY_JQLIB"); 216 } 217 218 // jQuery Migrate219 220 $localPathMigrate = trim($this->params->get('localpathmigrate'.$suffix, '')); 221 if ($localPathMigrate) {222 if (JFile::exists(JPATH_ROOT.$localPathMigrate)) {223 $this->_jqmigratepath = JURI::root(true).$localPathMigrate;224 } else {225 if ($this->_showreport) {226 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_COULDNOTFINDFILE', JPATH_ROOT.$localPathMigrate);227 }228 }229 } 230 231 if (!empty($this->_jqmigratepath)) {232 $doc->addScript("JQEASY_JQMIGRATELIB"); 233 } 234 235 // no conflict path236 237 $addjQueryNoConflict = $this->params->get('addnoconflict'.$suffix, 1);238 if ($addjQueryNoConflict == 1) {239 $doc->addScriptDeclaration("JQEASY_JQNOCONFLICT");240 } else if ($addjQueryNoConflict == 2) {241 $doc->addScript("JQEASY_JQNOCONFLICT");242 $this->_jqnoconflictpath = JURI::root(true)."/plugins/system/jqueryeasy/jquerynoconflict.js";243 }244 245 $time_end = microtime(true);246 $this->_timeafterroute = $time_end - $time_start;247 248 $app->set('jQuery', true);249 250 if (!$this->_usejQueryUI) {251 return;252 }253 254 $jQueryUIVersion = $this->params->get('jqueryuiversion'.$suffix, '1.9'); 255 $jQueryUISubversion = $this->params->get('jqueryuisubversion'.$suffix, '');256 if ($jQueryUISubversion != '') {257 $jQueryUISubversion = '.'.$jQueryUISubversion;258 }259 $jQueryUITheme = $this->params->get('jqueryuitheme'.$suffix,'base'); 260 261 // jQuery UI path262 263 if ($jQueryUIVersion == 'local') {264 $localVersionPath = trim($this->params->get('localuiversion'.$suffix, ''));265 if ($localVersionPath) {266 if (JFile::exists(JPATH_ROOT.$localVersionPath)) {267 $this->_jquipath = JURI::root(true).$localVersionPath;268 } else {269 if ($this->_showreport) {270 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_COULDNOTFINDFILE', JPATH_ROOT.$localVersionPath);271 }272 }273 } else {274 if ($this->_showreport) {275 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_EMPTYLOCALFILE', 'jQuery UI');276 }277 }278 } else {279 $this->_jquipath = $jQueryHTTP."//ajax.googleapis.com/ajax/libs/jqueryui/".$jQueryUIVersion.$jQueryUISubversion."/jquery-ui".$jQueryCompressed.".js";280 }281 282 if (!empty($this->_jquipath)) {283 $doc->addScript("JQEASY_JQUILIB");284 }285 286 // jQuery UI CSS path287 288 if ($jQueryUITheme != 'none') { 289 if ($jQueryUITheme == 'custom') {290 $localVersionPath = trim($this->params->get('jqueryuithemecustom'.$suffix, ''));291 if ($localVersionPath) {292 if (JFile::exists(JPATH_ROOT.$localVersionPath)) {293 $this->_jquicsspath = JURI::root(true).$localVersionPath;294 } else {295 if ($this->_showreport) {296 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_COULDNOTFINDFILE', JPATH_ROOT.$localVersionPath);297 }298 }299 } else {300 if ($this->_showreport) {301 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_EMPTYLOCALCSSFILE');302 }303 }304 } else {305 $this->_jquicsspath = $jQueryHTTP."//ajax.googleapis.com/ajax/libs/jqueryui/".$jQueryUIVersion.$jQueryUISubversion."/themes/".$jQueryUITheme."/jquery-ui.css";306 }307 308 if (!empty($this->_jquicsspath)) {309 $doc->addStyleSheet("JQEASY_JQUICSS");310 }311 }312 $time_end = microtime(true);313 $this->_timeafterroute = $time_end - $time_start;314 }315 316 function onBeforeRender() {317 if (!$this->_enabled) {318 return;319 }320 321 $app = JFactory::getApplication();322 $doc = JFactory::getDocument(); 323 324 if ($app->isAdmin() && !$this->_usejQuery) { // no need to reorder libraries if jQuery not used in backend325 return;326 }327 328 $time_start = microtime(true);329 // at this point, jQuery and MooTools libraries are loaded in the wrong order, if jQuery is enabled330 // we have jQuery, MooTools and other libraries loaded in that order331 // take all 'media/system/js' libraries and put them in front of all others 332 333 $headerdata = $doc->getHeadData();334 $scripts = $headerdata['scripts'];335 $headerdata['scripts'] = array();336 337 $ignore_caption = $this->params->get('disablecaptions', 0);338 $library_needing_mootools_present = false;339 340 $js_needing_mootools = array("mooRainbow.js", "mootree.js");341 $js_to_ignore = array("mootools-core.js", "mootools-more.js"); // uncompressed versions are not taken into account because used for debug342 343 $quoted_path = preg_quote('media/system/js/', '/'); 344 345 // put MooTools in front346 foreach ($scripts as $url => $type) {347 if (preg_match('#'.$quoted_path.'#s', $url)) { 348 349 if ($app->isSite()) {350 foreach ($js_needing_mootools as $library) {351 if (preg_match('#'.$quoted_path.$library.'#s', $url)) {352 $library_needing_mootools_present = true;353 }354 }355 }356 357 if ($ignore_caption && $app->isSite() && preg_match('#'.$quoted_path.'caption#s', $url)) {358 //unset($headerdata['scripts'][$url]);359 } else {360 $headerdata['scripts'][$url] = $type;361 }362 363 unset($scripts[$url]);364 }365 }366 // make sure we follow with all jQuery scripts367 foreach ($scripts as $url => $type) {368 if (preg_match('#JQEASY_#s', $url)) {369 $headerdata['scripts'][$url] = $type;370 unset($scripts[$url]);371 }372 }373 374 // remaining scripts375 foreach ($scripts as $url => $type) {376 $headerdata['scripts'][$url] = $type;377 }378 379 if ($this->_showreport) {380 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_REORDEREDLIBRARIES');381 }382 383 // get rid of MooTools only if :384 // + on its own, with no other library using MooTools loaded from media/system/js385 // + in frontend386 // + view != form (submit weblink, edit or create article)387 // + tmpl != component (component.php used to get images from editor for instance)388 // + not in specified pages389 390 if ($this->params->get('disablemootools', 0) && $app->isSite() && !$library_needing_mootools_present) {391 // $_GET['view'] available if SEF URLs set to yes or not 392 if (isset($_GET['view']) && $_GET['view'] == 'form') { 393 // do nothing394 } else if (isset($_GET['tmpl']) && $_GET['tmpl'] == 'component') {395 // do nothing396 } else {397 foreach ($headerdata['scripts'] as $url => $type) {398 $ignore = false;399 foreach ($js_to_ignore as $library) {400 if (preg_match('#'.$quoted_path.$library.'#s', $url)) {401 // found library to ignore402 $ignore = true;403 }404 }405 406 // DO NOT REMOVE if a page has been specifically listed as not to disable MooTools407 $exceptPaths = trim( (string) $this->params->get('keepmootoolsin', ''));408 if ($exceptPaths) {409 $this->_exceptpaths = array_map('trim', (array) explode("\n", $exceptPaths));410 $current_uri_string = JURI::getInstance()->toString();411 412 //if ($this->_showreport) {413 // $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_DISABLEMOOTOOLSINPAGES');414 // $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_CURRENTURI', $current_uri_string);415 //} 416 417 foreach ($this->_exceptpaths as $path) { 418 $paths_compare = self::path_compare($current_uri_string, $path, $this->_back_compat_path);419 if ($paths_compare) {420 $ignore = false;421 }422 }423 }424 425 if ($ignore) {426 unset($headerdata['scripts'][$url]);427 if ($this->_showreport) {428 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDMOOTOOLSLIBRARY', $url);429 }430 }431 }432 } 433 }434 435 // also we have script declarations loaded alongside MooTools libraries436 // if getting rid of libraries, also need to get rid of script declarations associated to them437 438 if ($ignore_caption && $app->isSite()) {439 $headerdata['script'] = preg_replace('#([a-zA-Z0-9();,\'_:\.-\s]*)JCaption([a-zA-Z0-9();,\'_:\.-\s]*)#', '', $headerdata['script']);440 //$headerdata['script'] = preg_replace('#([a-zA-Z0-9();,\'_:\.-\s]*)function(){}#', '', $headerdata['script']);441 if ($this->_showreport) { 442 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVECAPTION');443 }444 } 445 446 $doc->setHeadData($headerdata); 447 $time_end = microtime(true);448 $this->_timebeforerender = $time_end - $time_start;449 }450 451 function onAfterRender() {452 453 if (!$this->_enabled) {454 return;455 }456 457 $app = JFactory::getApplication();458 459 $time_start = microtime(true);460 461 $suffix = $app->isAdmin() ? 'backend' : 'frontend'; 462 463 $body = JResponse::getBody();464 465 if ($this->_usejQuery) {466 467 $remainingScripts = trim( (string) $this->params->get('stripremainingscripts'.$suffix, ''));468 if ($remainingScripts) {469 $remainingScripts = array_map('trim', (array) explode("\n", $remainingScripts));470 foreach ($remainingScripts as $script) {471 $count = 0;472 $body = preg_replace('#<script[^>]*'.$script.'[^>]*></script>#', '', $body, -1, $count);473 if ($count > 0 && $this->_showreport) {474 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_STRIPPEDREMAININGSCRIPT', $script, $count);475 }476 }477 }478 479 $remainingStylesheets = trim( (string) $this->params->get('stripremainingcss'.$suffix, ''));480 if ($remainingStylesheets) {481 $remainingStylesheets = array_map('trim', (array) explode("\n", $remainingStylesheets));482 foreach ($remainingStylesheets as $stylesheet) {483 $count = 0;484 $body = preg_replace('#<link[^>]*'.$stylesheet.'[^>]*/>#', '', $body, -1, $count);485 if ($count > 0 && $this->_showreport) {486 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_STRIPPEDREMAININGCSS', $stylesheet, $count);487 }488 }489 } 490 491 // remove all '...jQuery.noConflict(...);' or '... $.noConflict(...);'492 $removejQueryNoConflict = $this->params->get('removenoconflict'.$suffix, 1);493 if ($removejQueryNoConflict) {494 $matches = array();495 if (preg_match_all('#[^}^;^\n^>]*(jQuery|\$)\.noConflict\((true|false|)\);#', $body, $matches, PREG_SET_ORDER) > 0) { 496 $quoted_javascript = preg_quote('<script type="text/javascript">', '/');497 498 foreach ($matches as $match) { 499 $quoted_match = preg_quote($match[0], '#'); // prepares for regexp500 501 if (preg_match('#('.$quoted_javascript.'[\S\s]*?'.$quoted_match.')#', $body)) { // makes sure we are in a javascript tag with anything in between the script tag and the noConflict code502 $body = preg_replace('#'.$quoted_match.'#', '', $body, 1);503 if ($this->_showreport) {504 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDNOCONFLICTSCRIPTDECLARATIONS', $match[0]);505 }506 }507 }508 509 $count = 0;510 $body = preg_replace('#<script type="text/javascript">[\s]*?</script>#', '', $body, -1, $count); // remove newly empty scripts, if any511 if ($count > 0 && $this->_showreport) {512 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDEMPTYSCRIPTTAGS', $count);513 }514 }515 516 // remove potential jquery-noconflict.js (different combinations)517 $count = 0;518 $body = preg_replace('#src="([\\\/a-zA-Z0-9_:\.-]*)jquery[.-]no[.-]*[cC]onflict\.js"#', 'GARBAGE', $body, -1, $count);519 if ($count > 0 && $this->_showreport) {520 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDNOCONFLICTSCRIPTS', $count);521 } 522 } 523 524 $do_not_add_libraries = false;525 $move_unique_library = false;526 $move_unique_libraryui = false;527 $move_unique_cssui = false; 528 529 $replace_when_unique = $this->params->get('replacewhenunique'.$suffix, 1);530 $add_when_missing = $this->params->get('addwhenmissing'.$suffix, 1); 531 532 // remove all other references to jQuery library except some533 $ignoreScripts = trim( (string) $this->params->get('ignorescripts'.$suffix, ''));534 if ($ignoreScripts) {535 $ignoreScripts = array_map('trim', (array) explode("\n", $ignoreScripts));536 }537 538 if (empty($ignoreScripts) && $add_when_missing && $replace_when_unique) { // faster this way539 $count = 0;540 $body = preg_replace('#src="([\\\/a-zA-Z0-9_:\.-]*)jquery([0-9\.-]|core|min|pack)*?.js"#', 'GARBAGE', $body, -1, $count); // find jQuery versions541 if ($count > 0 && $this->_showreport) {542 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDJQUERY', $count);543 }544 } else { 545 $matches = array();546 if (preg_match_all('#src="([\\\/a-zA-Z0-9_:\.-]*)jquery([0-9\.-]|core|min|pack)*?.js"#', $body, $matches, PREG_SET_ORDER) >= 0) {547 548 $nbr_of_matches = sizeof($matches);549 if ($nbr_of_matches == 0 && !$add_when_missing) {550 $do_not_add_libraries = true;551 if ($this->_showreport) {552 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_NOJQUERYLIBRARIESADDED');553 }554 } elseif ($nbr_of_matches == 1 && !$replace_when_unique) {555 foreach ($matches as $match) {556 $this->_jqpath = rtrim(substr($match[0], 5), '"');557 $move_unique_library = true;558 if ($this->_showreport) {559 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_KEEPINGUNIQUELIBRARY', $this->_jqpath);560 }561 }562 } 563 564 foreach ($matches as $match) {565 $quoted_match = preg_quote($match[0], '/'); // prepares for regexp566 $ignore = false;567 if ($ignoreScripts) {568 foreach ($ignoreScripts as $script) {569 if (stripos($match[0], $script) !== false) { // library needs to be ignored for removal570 $ignore = true;571 if ($this->_showreport) {572 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_IGNORESCRIPT', $script);573 }574 }575 }576 }577 if (!$ignore) { // remove the library578 $body = preg_replace('#'.$quoted_match.'#', 'GARBAGE', $body, 1);579 if ($this->_showreport) {580 if ($nbr_of_matches == 1 && !$replace_when_unique) {581 // do not show any message582 } else {583 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDJQUERYLIBRARY', rtrim(substr($match[0], 5), '"'));584 }585 }586 }587 }588 }589 }590 591 // use jQuery version set in the plugin 592 if (!empty($this->_jqpath)) {593 if ($do_not_add_libraries) {594 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQLIB#', 'GARBAGE', $body, 1);595 } else {596 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQLIB#', $this->_jqpath, $body, 1);597 if ($this->_showreport) {598 if ($move_unique_library) {599 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_MOVEDJQUERY', $this->_jqpath);600 } else {601 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDJQUERY', $this->_jqpath);602 }603 }604 }605 } else {606 if ($this->_showreport) {607 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_ERRORADDINGJQUERY');608 }609 }610 611 // use jQuery Migrate612 if (!empty($this->_jqmigratepath)) {613 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQMIGRATELIB#', $this->_jqmigratepath, $body, 1);614 if ($this->_showreport) {615 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDJQUERYMIGRATE', $this->_jqmigratepath);616 }617 }618 619 // replace deleted occurences 620 $addjQueryNoConflict = $this->params->get('addnoconflict'.$suffix, 1);621 if ($addjQueryNoConflict == 1) {622 if ($do_not_add_libraries) {623 $body = preg_replace('#JQEASY_JQNOCONFLICT#', '', $body, 1);624 } else {625 $body = preg_replace('#JQEASY_JQNOCONFLICT#', 'jQuery.noConflict();', $body, 1); // add unique jQuery.noConflict();626 if ($this->_showreport) {627 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDNOCONFLICTDECLARATION');628 }629 }630 } elseif ($addjQueryNoConflict == 2) {631 if ($do_not_add_libraries) {632 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQNOCONFLICT#', 'GARBAGE', $body, 1); 633 } else {634 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQNOCONFLICT#', $this->_jqnoconflictpath, $body, 1); // add jquerynoconflict.js 635 if ($this->_showreport) {636 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDNOCONFLICTSCRIPT', $this->_jqnoconflictpath);637 }638 }639 } 640 641 // replace '$(document).ready(function()' with 'jQuery(document).ready(function($)'642 if ($this->params->get('replacedocumentready'.$suffix, 1)) { 643 $count = 0;644 $body = preg_replace('#\$\(document\).ready\(function\(\)#s', 'jQuery(document).ready(function($)', $body, -1, $count);645 if ($count > 0 && $this->_showreport) {646 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REPLACEDDOCUMENTREADY', $count);647 }648 } 649 650 if ($this->_usejQueryUI) {651 652 // remove all other references to jQuery UI library653 if (!$replace_when_unique) {654 $matches = array();655 if (preg_match_all('#src="([\\\/a-zA-Z0-9_:\.-]*)jquery[.-]ui([0-9\.-]|core|custom|min|pack)*?.js"#', $body, $matches, PREG_SET_ORDER) > 0) {656 657 $nbr_of_matches = sizeof($matches);658 if ($nbr_of_matches == 1) {659 foreach ($matches as $match) {660 $this->_jquipath = rtrim(substr($match[0], 5), '"');661 $quoted_match = preg_quote($match[0], '/'); // prepares for regexp662 $body = preg_replace('#'.$quoted_match.'#', 'GARBAGE', $body, 1);663 if ($this->_showreport) {664 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_KEEPINGUNIQUELIBRARYUI', $this->_jquipath);665 }666 }667 } else { 668 foreach ($matches as $match) {669 $quoted_match = preg_quote($match[0], '/'); // prepares for regexp670 $body = preg_replace('#'.$quoted_match.'#', 'GARBAGE', $body, 1);671 if ($this->_showreport) {672 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDJQUERYUILIBRARY', rtrim(substr($match[0], 5), '"'));673 }674 }675 }676 }677 } else { // faster this way678 $count = 0;679 $body = preg_replace('#src="([\\\/a-zA-Z0-9_:\.-]*)jquery[.-]ui([0-9\.-]|core|custom|min|pack)*?.js"#', 'GARBAGE', $body, -1, $count); // find jQuery UI versions680 if ($count > 0 && $this->_showreport) {681 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDJQUERYUI', $count);682 }683 }684 685 // use jQuery UI version set in the plugin686 if (!empty($this->_jquipath)) {687 if ($do_not_add_libraries) {688 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQUILIB#', 'GARBAGE', $body, 1);689 } else {690 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQUILIB#', $this->_jquipath, $body, 1);691 if ($this->_showreport) {692 if ($move_unique_libraryui) {693 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_MOVEDJQUERYUI', $this->_jquipath);694 } else {695 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDJQUERYUI', $this->_jquipath);696 }697 }698 }699 } else {700 if ($this->_showreport) {701 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_ERRORADDINGJQUERYUI');702 }703 } 704 705 // remove all other references to jQuery UI stylesheets706 if (!$replace_when_unique) {707 $matches = array();708 if (preg_match_all('#href="([\\\/a-zA-Z0-9_:\.-]*)jquery[.-]ui([0-9\.-]|core|custom|min|pack)*?.css"#', $body, $matches, PREG_SET_ORDER) > 0) {709 710 $nbr_of_matches = sizeof($matches);711 if ($nbr_of_matches == 1) {712 foreach ($matches as $match) {713 $this->_jquicsspath = rtrim(substr($match[0], 5), '"');714 $quoted_match = preg_quote($match[0], '/'); // prepares for regexp715 $body = preg_replace('#'.$quoted_match.'#', 'GARBAGE', $body, 1);716 if ($this->_showreport) {717 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_KEEPINGUNIQUECSSUI', $this->_jquicsspath);718 }719 }720 } else {721 foreach ($matches as $match) {722 $quoted_match = preg_quote($match[0], '/'); // prepares for regexp723 $body = preg_replace('#'.$quoted_match.'#', 'GARBAGE', $body, 1);724 if ($this->_showreport) {725 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDJQUERYUICSSLINK', rtrim(substr($match[0], 5), '"'));726 }727 }728 }729 }730 } else { // faster this way731 $count = 0;732 $body = preg_replace('#href="([\\\/a-zA-Z0-9_:\.-]*)jquery[.-]ui([0-9\.-]|core|custom|min|pack)*?.css"#', 'GARBAGE', $body, -1, $count); // find jQuery UI CSS versions733 if ($count > 0 && $this->_showreport) {734 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDJQUERYUICSS', $count);735 }736 }737 738 // use jQuery UI CSS set in the plugin739 if (!empty($this->_jquicsspath)) {740 if ($do_not_add_libraries) {741 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQUICSS#', 'GARBAGE', $body, 1);742 } else {743 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)JQEASY_JQUICSS#', $this->_jquicsspath, $body, 1);744 if ($this->_showreport) {745 if ($move_unique_cssui) {746 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_MOVEDJQUERYUICSS', $this->_jquicsspath);747 } else {748 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDJQUERYUICSS', $this->_jquicsspath);749 }750 }751 }752 } else {753 if ($this->_showreport) {754 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_ERRORADDINGJQUERYUICSS');755 }756 }757 758 // remove all obsolete link tags759 $count = 0;760 $body = preg_replace('#<link[^>]*GARBAGE[^>]*/>#', '', $body, -1, $count); // remove newly empty stylesheets761 if ($count > 0 && $this->_showreport) {762 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDEMPTYLINKTAGS', $count);763 }764 }765 766 // remove all obsolete script tags767 $count = 0;768 $body = preg_replace('#<script[^>]*GARBAGE[^>]*></script>#', '', $body, -1, $count); // remove newly empty scripts769 if ($count > 0 && $this->_showreport) {770 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDEMPTYSCRIPTTAGS', $count);771 }772 }773 774 // remove window.addEvent('load', function() {}); left after removal of 'new JCaption('img.caption');'775 $ignore_caption = $this->params->get('disablecaptions', 0);776 if ($ignore_caption && $app->isSite()) {777 $count = 0;778 $body = preg_replace('#window.addEvent\(\'load\', function\(\) {[\s]*?}\);#', '', $body, -1, $count); // remove newly empty scripts779 if ($count > 0 && $this->_showreport) {780 $this->_verbose_array[] = JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEDEMPTYSCRIPTWINDOWADDEVENT');781 }782 }783 784 if (!empty($this->_supplement_scripts)) {785 foreach($this->_supplement_scripts as $path) {786 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)ADD_SCRIPT_HERE([0-9]*)#', $path, $body, 1);787 if ($this->_showreport) {788 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDSCRIPT', $path);789 }790 }791 }792 793 $javascript_declaration = trim( (string) $this->params->get('addjavascriptdeclaration'.$suffix, ''));794 if (!empty($javascript_declaration)) {795 $body = preg_replace('#ADD_SCRIPT_DECLARATION_HERE#', $javascript_declaration, $body, 1);796 if ($this->_showreport) { 797 $lines = array_map('trim', (array) explode("\n", $javascript_declaration)); 798 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDSCRIPTDECLARATION', $lines[0]);799 }800 }801 802 if (!empty($this->_supplement_stylesheets)) {803 foreach($this->_supplement_stylesheets as $path) {804 $body = preg_replace('#([\\\/a-zA-Z0-9_:\.-]*)ADD_STYLESHEET_HERE([0-9]*)#', $path, $body, 1);805 if ($this->_showreport) {806 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDSTYLESHEET', $path);807 }808 }809 }810 811 $css_declaration = trim( (string) $this->params->get('addcssdeclaration'.$suffix, ''));812 if (!empty($css_declaration)) {813 $body = preg_replace('#ADD_STYLESHEET_DECLARATION_HERE#', $css_declaration, $body, 1);814 if ($this->_showreport) {815 $lines = array_map('trim', (array) explode("\n", $css_declaration));816 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_ADDEDSTYLESHEETDECLARATION', $lines[0]);817 }818 } 819 820 if ($this->params->get('removeblanklines'.$suffix, 0)) {821 $count = 0;822 $body = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $body, -1, $count); // gets all of the empty lines in the source and replaces them with a simple carriage return to preserve the content structure.823 if ($count > 0 && $this->_showreport) {824 $this->_verbose_array[] = JText::sprintf('PLG_SYSTEM_JQUERYEASY_VERBOSE_REMOVEBLANKLINES', $count);825 }826 }827 $time_end = microtime(true);828 $this->_timeafterrender = $time_end - $time_start;829 830 // output the results (verbose or not)831 832 $output = $body;833 834 if ($this->_showreport) {835 836 $pattern = '#</body>#';837 $replacement = '<div style="display: block; float: left; width: 100%; background-color: #D9EDF7; color: #48484C;">';838 $replacement .= '<dl style="padding: 15px; margin: 20px; border: 1px solid #BCE8F1; border-radius: 4px; background-color: #FFFFFF;">';839 $replacement .= '<dt style="padding: 5px; border: 1px solid #DDDDDD; border-radius: 4px; background-color: #F5F5F5; margin-bottom: 10px">'.JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_JQUERYEASY').'</dt>';840 841 if (!empty($this->_verbose_array)) {842 foreach ($this->_verbose_array as $verbose) {843 844 $color = '#48484C';845 switch (substr($verbose, 0, 3)) {846 case 'INF': $color = '#3A87AD'; break;847 case 'DEL': $color = '#C09853'; break;848 case 'ERR': $color = '#B94A48'; break;849 case 'ADD': $color = '#468847'; break;850 default: $color = '#48484C'; break;851 }852 853 $replacement .= '<dd style="color: '.$color.';">'.substr($verbose, 4).'</dd>';854 }855 } else {856 $replacement .= '<dd>'.JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_NOCHANGESMADE').'</dd>';857 }858 859 $replacement .= '<dd style="padding-top: 10px">'.JText::_('PLG_SYSTEM_JQUERYEASY_VERBOSE_EXECUTIONTIME').': '.($this->_timeafterroute + $this->_timebeforerender + $this->_timeafterrender).'</dd>';860 861 $output = preg_replace($pattern, $replacement.'</dl></div></body>', $output, 1);862 }863 864 JResponse::setBody($output);865 866 return true;867 } ...

Full Screen

Full Screen

ezs3rename.php

Source:ezs3rename.php Github

copy

Full Screen

...24 'use-modules' => true,25 'use-extensions' => true,26 'user' => true ) );27$script->startup();28$options = $script->getOptions( "[force;][script-verbose;][script-verbose-level;][parent-node:][hours;][min;]",29 "[node]",30 array( 'parent-node' => 'Content Tree Node ID. Example: --parent-node=2',31 'force' => 'Force disables delayed startup. Example: ' . "'--force'" . ' is an optional parameter which defaults to false',32 'hours' => 'Number of hours to search in reverse. Example: --hours=5',33 'min' => 'Number of min instead of hours to search in reverse. Example: --min=15',34 'script-verbose' => 'Use this parameter to display verbose script output without disabling script iteration counting of images created or removed. Example: ' . "'--script-verbose'" . ' is an optional parameter which defaults to false',35 'script-verbose-level' => 'Use only with ' . "'--script-verbose'" . ' parameter to see more of execution internals. Example: ' . "'--script-verbose-level=3'" . ' is an optional parameter which defaults to 1 and works till 5'),36 false,37 array( 'user' => true ) );38$script->initialize();39/** Script default values **/40$limit = 100;41$offset = 0;42$adminUserID = 14;43$s3FileClassIdentifier = eZINI::instance( 's3.ini' )->variable( 'S3Settings', 'ClassIdentifier' );44$s3FileAttributeIdentifier = eZINI::instance( 's3.ini' )->variable( 'S3Settings', 'AttributeIdentifier' );45$s3FileRenameAttributeIdentifier = eZINI::instance( 's3.ini' )->variable( 'S3Settings', 'RenameAttributeIdentifier' );46$awsS3Bucket = eZINI::instance( 's3.ini' )->variable( 'S3Settings', 'Bucket' );47/** Login script to run as admin user This is required to see past content tree permissions, sections and other limitations **/48$currentuser = eZUser::currentUser();49$currentuser->logoutCurrent();50$user = eZUser::fetch( $adminUserID );51$user->loginCurrent();52/** Test for required script arguments **/53if ( isset( $options['parent-node'] ) )54{55 $parentNodeID = $options['parent-node'];56}57else58{59 $cli->error( '--parent-node parameter is required. Specify a content treee node id' );60 $script->shutdown( 1 );61}62if ( !is_numeric( $parentNodeID ) )63{64 $cli->error( 'Please specify a numeric node ID' );65 $script->shutdown( 2 );66}67if ( isset( $options['hours'] ) && $options['hours'] )68{69 $hoursAgo = $options['hours'];70}71else72{73 $hoursAgo = 1;74}75if ( !is_numeric( $hoursAgo ) )76{77 $cli->error( 'Please specify a numeric hour number' );78 $script->shutdown( 2 );79}80if ( isset( $options['min'] ) && $options['min'] )81{82 $minsAgo = $options['min'];83}84else85{86 $minsAgo = 2.5;87}88if ( !is_numeric( $minsAgo ) )89{90 $cli->error( 'Please specify a numeric minute number' );91 $script->shutdown( 2 );92}93$force = isset( $options['force'] ) ? true : false;94$verbose = isset( $options['script-verbose'] ) ? true : false;95$scriptVerboseLevel = isset( $options['script-verbose-level'] ) ? $options['script-verbose-level'] : 1;96$troubleshoot = ( isset( $options['script-verbose-level'] ) && $options['script-verbose-level'] > 0 ) ? true : false;97/** Modified time stamp to search with **/98if( isset( $options['min'] ) && !isset( $options['hours'] ) )99{100 $whileAgo = $minsAgo;101 $whileSpan = 'Minutes';102 /** Optional debug output **/103 if( $troubleshoot && $scriptVerboseLevel >= 5 )104 {105 $cli->output( "Searching: Using minutes to search: " . $minsAgo . "\n");106 }107 $searchTimeStampInSeconds = time() - ( $minsAgo * 60 );108}109elseif( isset( $options['min'] ) && isset( $options['hours'] ) )110{111 $whileAgo = $hoursAgo . "' Hours and '" . $minsAgo;112 $whileSpan = 'Minutes';113 /** Optional debug output **/114 if( $troubleshoot && $scriptVerboseLevel >= 5 )115 {116 $cli->output( "Searching: Using hours and minutes to search: " . $hoursAgo . ' Hours and ' . $minsAgo . " Minutes\n");117 }118 $searchTimeStampInSeconds = time() - ( ( $hoursAgo * 3600 ) + ( $minsAgo * 60 ) );119}120else121{122 $whileAgo = $hoursAgo;123 $whileSpan = 'Hours';124 /** Optional debug output **/125 if( $troubleshoot && $scriptVerboseLevel >= 5 )126 {127 $cli->output( "Searching: Using hours to search: " . $hoursAgo . "\n");128 }129 $searchTimeStampInSeconds = time() - ( $hoursAgo * 3600 );130}131/** Fetch total files count from content tree **/132$totalFileCountParams = array( 'ClassFilterType' => 'include',133 'ClassFilterArray' => array( $s3FileClassIdentifier ),134 'AttributeFilter' => array( 'and', array( 'modified','>=', $searchTimeStampInSeconds ),135 array( "large_file/$s3FileRenameAttributeIdentifier",'!=', true ) ),136 'Depth', 5,137 'MainNodeOnly', true,138 'IgnoreVisibility', true );139/** Optional debug output **/140if( $troubleshoot && $scriptVerboseLevel >= 5 )141{142 $cli->output( "S3 File object search params: \n");143 $cli->output( print_r( $totalFileCountParams ) );144}145/** Fetch total count for recently modified AWS S3 File content objects **/146$totalFileCount = eZContentObjectTreeNode::subTreeCountByNodeID( $totalFileCountParams, $parentNodeID );147/** Debug verbose output **/148if ( !$totalFileCount )149{150 $cli->error( "No S3 File objects found needing rename" );151 /** Call for display of execution time **/152 executionTimeDisplay( $srcStartTime, $cli );153 $script->shutdown( 3 );154}155elseif( $verbose && $totalFileCount > 0 )156{157 $cli->warning( "Found! Modified S3 File objects to be checked: " . $totalFileCount . "\n" );158}159/** Alert user of script process starting **/160if( $verbose )161{162 $cli->output( "Querying content tree for S3 large file objects\nwith parent node of '$parentNodeID' modified in the last\n'$whileAgo' $whileSpan ...\n" );163}164if( $verbose && !$force )165{166 $cli->warning( "You can run this script with --force parameter to skip this script startup delay and execute immediately.\n" );167 $cli->warning( "You have 10 seconds to stop the script execution before it starts (press Ctrl-C)." );168 sleep( 10 );169 $cli->output();170}171/** Setup script iteration details **/172$script->setIterationData( '.', '.' );173$script->resetIteration( $totalFileCount );174/** Iterate over nodes **/175while ( $offset < $totalFileCount )176{177 /** Fetch nodes under starting node in content tree **/178 $subTreeParams = array( 'ClassFilterType' => 'include',179 'ClassFilterArray' => array( $s3FileClassIdentifier ),180 'AttributeFilter' => array( 'and', array( 'modified','>=', $searchTimeStampInSeconds ),181 array( "large_file/$s3FileRenameAttributeIdentifier",'!=', true ) ),182 'Limit', $limit,183 'Offset', $offset,184 'SortBy', array( 'modified', false ),185 'Depth', 5,186 'MainNodeOnly', true,187 'IgnoreVisibility', true );188 /** Optional debug output **/189 if( $troubleshoot && $scriptVerboseLevel >= 5 )190 {191 $cli->output( "S3 File object fetch params: \n");192 $cli->output( print_r( $subTreeParams ) );193 }194 /** Fetch nodes with limit and offset **/195 $subTree = eZContentObjectTreeNode::subTreeByNodeID( $subTreeParams, $parentNodeID );196 $subTreeCount = count( $subTree );197 /** Optional debug output **/198 if( $troubleshoot && $scriptVerboseLevel >= 4 )199 {200 $cli->output( "S3 File objects fetched: ". $subTreeCount ."\n" );201 if( $troubleshoot && $scriptVerboseLevel >= 6 )202 {203 $cli->output( print_r( $subTree ) );204 }205 }206 /** Iterate over nodes **/207 while ( list( $key, $childNode ) = each( $subTree ) )208 {209 $status = true;210 /** Fetch object details **/211 $object = $childNode->attribute( 'object' );212 $objectID = $object->attribute( 'id' );213 $objectCurrentVersion = $object->attribute( 'current_version' );214 $objectLastVersion = $objectCurrentVersion - 1;215 $objectDataMap = $object->dataMap();216 $objectPathName = $objectDataMap[ $s3FileAttributeIdentifier ]->content();217 $nodeID = $childNode->attribute('node_id');218 $nodeUrl = $childNode->attribute('url');219 /** Only iterate over versions of nodes greater than zero **/220 if( $objectLastVersion > 0 )221 {222 $objectPastDataMap = $object->fetchDataMap( $objectLastVersion );223 $objectPastPathName = $objectPastDataMap[ $s3FileAttributeIdentifier ]->content();224 /** Debug verbose output **/225 if( $troubleshoot && $scriptVerboseLevel >= 3 )226 {227 $cli->warning( "Found! S3 File object pending rename: " . $nodeUrl . ", NodeID " . $nodeID . "\n" );228 if( $troubleshoot && $scriptVerboseLevel >= 5 )229 {230 $cli->output( "Past Version Path: " . $objectPastPathName . "" );231 $cli->output( "New Path: " . $objectPathName . "\n" );232 }233 else234 {235 $cli->output( "Attempting S3 File object copy. From: " . $objectPastPathName . " To: " . $objectPathName ."\n" );236 }237 }238 /** Only iterate over versions of nodes path attributes which do not match **/239 if ( $objectPathName != $objectPastPathName )240 {241 /** Connect to aws s3 service **/242 $awsS3 = new AmazonS3();243 /** Copy object path from old version to new version **/244 $response = $awsS3->copy_object(245 array(// Source246 'bucket' => $awsS3Bucket,247 'filename' => $objectPastPathName ),248 array(// Destination249 'bucket' => $awsS3Bucket,250 'filename' => $objectPathName ) );251 /** Only delete old s3 file object if copy is a success **/252 if( $response->isOK() )253 {254 /** Debug verbose output **/255 if( $verbose )256 {257 $cli->output( "Success: Copy of AWS S3 File object path. New path: '$objectPathName'\n");258 }259 $delete = $awsS3->delete_object( $awsS3Bucket, $objectPastPathName );260 /** Optional debug output **/261 if( $troubleshoot && $scriptVerboseLevel >= 3 )262 {263 $cli->output( "Delete Object Responce: \n". print_r( $delete ) . "\n");264 }265 if( $delete->isOK() )266 {267 /** Debug verbose output **/268 if( $verbose )269 {270 $cli->output( "Success: Deletion of AWS S3 File object. Deleted Path: '$objectPastPathName'\n");271 }272 /** Only modify object if s3 file has been renamed Publish new object with renamed attribute checked **/273 $updateParams = array();274 $updateAttributeList = array( "$s3FileRenameAttributeIdentifier" => 1 );275 $updateParams['attributes'] = $updateAttributeList;276 $updateResult = eZContentFunctions::updateAndPublishObject( $object, $updateParams );277 /** Debug verbose output **/278 if( $verbose )279 {280 $cli->output( "Publishing new S3 File object version with $s3FileRenameAttributeIdentifier attribute checked\n");281 }282 /** Iterate cli script progress tracker **/283 $script->iterate( $cli, $status );284 }285 }286 else287 {288 /** Debug verbose output **/289 if( $verbose )290 {291 $errorMsgAlert = "Failure! S3 File object failed to be renamed: " . $nodeUrl . ", NodeID " . $nodeID . "\n";292 $cli->error( $errorMsgAlert );293 eZDebug::writeError( $errorMsgAlert );294 $errorMsg = "S3 File object copy from: " . $objectPastPathName . " to " . $objectPathName . " failed\n";295 $cli->error( $errorMsg );296 eZDebug::writeError( $errorMsg );297 /** Catch error, 404 file not found **/298 if( $response->status == 404 )299 {300 $warningMsg = "Reason: S3 File object copy failed because file path " . $objectPastPathName . " no longer exists\n";301 $cli->warning( $warningMsg );302 eZDebug::writeError( $warningMsg );303 }...

Full Screen

Full Screen

ezs3renamefile.php

Source:ezs3renamefile.php Github

copy

Full Screen

...24 'use-modules' => true,25 'use-extensions' => true,26 'user' => true ) );27$script->startup();28$options = $script->getOptions( "[script-verbose;][script-verbose-level;][old-path:][new-path:]",29 "[node]",30 array( 'old-path' => 'Path on AWS S3. Example: --old-path=Media/Test/File.jpg',31 'new-path' => 'Path on AWS S3. Example: --new-path=Media/Test/File.2013.jpg',32 'script-verbose' => 'Use this parameter to display verbose script output without disabling script iteration counting of images created or removed. Example: ' . "'--script-verbose'" . ' is an optional parameter which defaults to false',33 'script-verbose-level' => 'Use only with ' . "'--script-verbose'" . ' parameter to see more of execution internals. Example: ' . "'--script-verbose-level=3'" . ' is an optional parameter which defaults to 1 and works till 5'),34 false,35 array( 'user' => true ) );36$script->initialize();37/** Script default values **/38$limit = 100;39$offset = 0;40$awsS3Bucket = eZINI::instance( 's3.ini' )->variable( 'S3Settings', 'Bucket' );41/** Test for required script arguments **/42if ( isset( $options['old-path'] ) )43{44 $oldPath = $options['old-path'];45}46else47{48 $cli->error( 'Old path is required. Specify a content treee node path to file the command' );49 $script->shutdown( 1 );50}51if ( isset( $options['new-path'] ) )52{53 $newPath = $options['new-path'];54}55else56{57 $cli->error( 'New path is required. Specify a content treee node path to file the command' );58 $script->shutdown( 1 );59}60$verbose = isset( $options['script-verbose'] ) ? true : false;61$scriptVerboseLevel = isset( $options['script-verbose-level'] ) ? $options['script-verbose-level'] : 1;62$troubleshoot = ( isset( $options['script-verbose-level'] ) && $options['script-verbose-level'] > 0 ) ? true : false;63/** Debug verbose output **/64if( $troubleshoot && $scriptVerboseLevel >= 3 )65{66 $cli->output( "Old path: " . $oldPath . "\n" );67 $cli->output( "New path: " . $oldPath . "\n" );68}69/** Connect to aws s3 service **/70$awsS3 = new AmazonS3();71/** Copy object path from old version to new version **/72$response = $awsS3->copy_object(73 array(// Source74 'bucket' => $awsS3Bucket,75 'filename' => $oldPath ),76 array(// Destination77 'bucket' => $awsS3Bucket,78 'filename' => $newPath ) );79/** Only delete old s3 file object if copy is a success **/80if( $response->isOK() )81{82 /** Debug verbose output **/83 if( $verbose )84 {85 $cli->output( "Copy file path name on AWS S3 successfull! New path: '$nodePathName'\n");86 }87 $delete = $awsS3->delete_object( $awsS3Bucket, $oldPath );88 /** Optional debug output **/89 if( $troubleshoot && $scriptVerboseLevel >= 3 )90 {91 $cli->output( "Delete Object Responce: \n". print_r( $delete ) . "\n");92 }93 if( $delete->isOK() )94 {95 /** Debug verbose output **/96 if( $verbose )97 {98 $cli->output( "Success: Deletion of AWS S3 File object. Path: '$oldPath'\n");99 }100 }101}102else103{104 /** Debug verbose output **/105 if( $verbose )106 {107 /** Catch error, 404 file not found **/108 if( $response->status == 404 )109 {110 $cli->output( "Reason: S3 File object copy failed because " . $oldPath . " no longer exists\n" );111 }112 }113 /** Optional debug output **/114 if( $troubleshoot && $scriptVerboseLevel >= 3 )115 {116 $cli->output( "Copy S3 File object response: \n" . print_r( $response ) );117 }118}119/** Add a stoping timing point tracking and calculating total script execution time **/...

Full Screen

Full Screen

verbose

Using AI Code Generation

copy

Full Screen

1$script->setVerbose(true);2$script->setVerbose(true);3$script->setVerbose(true);4$script->setVerbose(true);5$script->setVerbose(true);6$script->setVerbose(true);7$script->setVerbose(true);8$script->setVerbose(true);9$script->setVerbose(true);10$script->setVerbose(true);11$script->setVerbose(true);12$script->setVerbose(true);13$script->setVerbose(true);14$script->setVerbose(true);15$script->setVerbose(true);16$script->setVerbose(true);17$script->setVerbose(true);18$script->setVerbose(true);19$script->setVerbose(true);20$script->setVerbose(true);21$script->setVerbose(true);

Full Screen

Full Screen

verbose

Using AI Code Generation

copy

Full Screen

1$script = new script();2$script->verbose = true;3$script->run();4$script = new script();5$script->verbose = false;6$script->run();7$script = new script();8$script->verbose = true;9$script->run();10$script = new script();11$script->verbose = false;12$script->run();13$script = new script();14$script->verbose = true;15$script->run();16$script = new script();17$script->verbose = false;18$script->run();19$script = new script();20$script->verbose = true;21$script->run();22$script = new script();23$script->verbose = false;24$script->run();25$script = new script();26$script->verbose = true;27$script->run();28$script = new script();29$script->verbose = false;30$script->run();31$script = new script();32$script->verbose = true;33$script->run();34$script = new script();35$script->verbose = false;36$script->run();37$script = new script();38$script->verbose = true;39$script->run();40$script = new script();41$script->verbose = false;42$script->run();43$script = new script();

Full Screen

Full Screen

verbose

Using AI Code Generation

copy

Full Screen

1$script = new Script();2$script->verbose("This is a verbose message");3$script->verbose("This is another verbose message");4$script->verbose("This is the last verbose message");5$script = new Script();6$script->verbose("This is a verbose message");7$script->verbose("This is another verbose message");8$script->verbose("This is the last verbose message");9$script = new Script();10$script->verbose("This is a verbose message");11$script->verbose("This is another verbose message");12$script->verbose("This is the last verbose message");13$script = new Script();14$script->verbose("This is a verbose message");15$script->verbose("This is another verbose message");16$script->verbose("This is the last verbose message");17$script = new Script();18$script->verbose("This is a verbose message");19$script->verbose("This is another verbose message");20$script->verbose("This is the last verbose message");21$script = new Script();22$script->verbose("This is a verbose message");23$script->verbose("This is another verbose message");24$script->verbose("This is the last verbose message");25$script = new Script();26$script->verbose("This is a verbose message");27$script->verbose("This is another verbose message");28$script->verbose("This is the last verbose message");29$script = new Script();30$script->verbose("This is a verbose message");31$script->verbose("This is another verbose message");32$script->verbose("This is the last verbose message");33$script = new Script();34$script->verbose("This is a verbose message");35$script->verbose("This is another verbose message");36$script->verbose("This is the last verbose message");

Full Screen

Full Screen

verbose

Using AI Code Generation

copy

Full Screen

1$script = new script();2$script->verbose(true);3$script->verbose(false);4$script = new script();5$script->verbose();6$script = new script();7$script->verbose(false);8$script = new script();9$script->verbose(true);10$script = new script();11$script->verbose();12$script = new script();13$script->verbose();14$script = new script();15$script->verbose();16$script = new script();17$script->verbose(true);18$script = new script();19$script->verbose(true);20$script = new script();21$script->verbose(false);22$script = new script();23$script->verbose();24$script = new script();25$script->verbose(true);26$script = new script();27$script->verbose(false);28$script = new script();29$script->verbose(true);30$script = new script();31$script->verbose();32$script = new script();33$script->verbose(true);34$script = new script();35$script->verbose();36$script = new script();

Full Screen

Full Screen

verbose

Using AI Code Generation

copy

Full Screen

1$script->verbose(true);2$script->verbose(true);3$script->verbose(true);4$script->verbose(true);5$script->verbose(true);6$script->verbose(true);7$script->verbose(true);8$script->verbose(true);9$script->verbose(true);10$script->verbose(true);11$script->verbose(true);12$script->verbose(true);13$script->verbose(true);14$script->verbose(true);15$script->verbose(true);16$script->verbose(true);17$script->verbose(true);18$script->verbose(true);

Full Screen

Full Screen

verbose

Using AI Code Generation

copy

Full Screen

1require_once('script.php');2$script = new script('silent');3$script->set_time_limit(0);4$script->set_memory_limit('1024M');5$script->set_error_reporting(E_ALL);6$script->set_reporting_level('verbose');7$script->set_logging_level('verbose');8$script->set_log_file('log.txt');9$script->log('Start of script', 'verbose');10$script->log('Start of script', 'silent');11$script->log('Start of script', 'verbose');12$script->log('Start of script', 'silent');13$script->log('End of script', 'verbose');14$script->log('End of script', 'silent');15$script->log('End of script', 'verbose');16$script->log('End of script', 'silent');17$script->log('End of script', 'verbose');18$script->log('End of script', 'silent');19$script->log('End of script', 'verbose');20$script->log('End of script', 'silent');21$script->log('End of script', 'verbose');22$script->log('End of script', 'silent');23$script->log('End of script',

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger verbose code on LambdaTest Cloud Grid

Execute automation tests with verbose on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful