| Conditions | 4 |
| Paths | 3 |
| Total Lines | 56 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 31 | function dolWebsiteOutput($content) |
||
| 32 | { |
||
| 33 | global $db, $langs, $conf, $user; |
||
| 34 | global $dolibarr_main_url_root, $dolibarr_main_data_root; |
||
| 35 | |||
| 36 | dol_syslog("dolWebsiteOutput start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')'); |
||
| 37 | |||
| 38 | // Define $urlwithroot |
||
| 39 | $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
||
| 40 | $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
||
| 41 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
||
| 42 | |||
| 43 | // Note: This seems never called when page is output inside the website editor (search 'REPLACEMENT OF LINKS When page called by website editor') |
||
| 44 | |||
| 45 | if (! defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from virtual host |
||
| 46 | { |
||
| 47 | $symlinktomediaexists=1; |
||
| 48 | |||
| 49 | // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server |
||
| 50 | // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
||
| 51 | // become |
||
| 52 | // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
||
| 53 | $nbrep=0; |
||
| 54 | if (! $symlinktomediaexists) |
||
| 55 | { |
||
| 56 | $content=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
||
| 57 | $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
||
| 58 | } |
||
| 59 | else |
||
| 60 | { |
||
| 61 | $content=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1medias/\4\5', $content, -1, $nbrep); |
||
| 62 | $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | else // REPLACEMENT OF LINKS When page called from dolibarr server |
||
| 66 | { |
||
| 67 | global $website; |
||
| 68 | |||
| 69 | // Replace relative link / with dolibarr URL: ...href="/"... |
||
| 70 | $content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); |
||
| 71 | // Replace relative link /xxx.php with dolibarr URL: ...href="....php" |
||
| 72 | $content=preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
||
| 73 | |||
| 74 | // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart=" |
||
| 75 | $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3"', $content, -1, $nbrep); |
||
| 76 | // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart=" |
||
| 77 | $content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3"', $content, -1, $nbrep); |
||
| 78 | |||
| 79 | // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
||
| 80 | $content=preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
||
| 81 | } |
||
| 82 | |||
| 83 | dol_syslog("dolWebsiteOutput end"); |
||
| 84 | |||
| 85 | print $content; |
||
| 86 | } |
||
| 87 | |||
| 123 |