Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 03:24:25 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155541 Posts in 21713 Topics by 7737 Members
Latest Member: simpleguy3
* Home Help Search Login Register
Pages: [1] 2   Go Down
Print
Author Topic: WYSIWYG and WB_URL fix  (Read 2067 times)
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« on: February 18, 2011, 02:08:48 PM »

Hi,

Meybe this already exist, but I couldnt find it on search, so here it is:

You all noticed that when you create a link or image in WYSIWYG editor, it displays full (current) url. (for example: http://www.mysite.xy/pages/page1.php) so you have more job when migrating sites..

I came up to idea to replace "http://www.mysite.xy" with a droplet, in order to be easier and less job when migrating sites to different domain (example: moving from test server to live server)

Here is how to:

Step 1:
First, create droplet [[WB-URL]]
Code:
return WB_URL;

Step 2:
then, in root/modules/wysiwyg/modfy.php
Code:
After line:
$content = (htmlspecialchars($pokazi['content']));
ADD THIS:
$content = str_replace( "[[WB-URL]]", WB_URL, $content);

Step 3:
and in, in root/modules/wysiwyg/save.php
Code:
After line:
$content = $admin->add_slashes($_POST['content'.$section_id]);
ADD THIS:
$content = str_replace( WB_URL, "[[WB-URL]]", $content);


Thats it..

Step 3 replaces the "http://www.mysite.xy" (current url [or http://localhost/wb/ ] ) with a droplet [[WB-URL]] in database

Step 2 does oposite: replaces the [[WB-URL]] with current url "http://www.mysite.xy" so you can see the link or image in wysiwyg editor..

If it doesnt exist, I belive it would be a good addition for a core files..

Let me know what you think..

Cheers,
Ivan

Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #1 on: February 18, 2011, 02:27:45 PM »

it's already implemented in WB 2.9.x_dev_R24 since more then a month.  wink
(without the use of Droplets)
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #2 on: February 18, 2011, 04:05:57 PM »

Cool,

Then let this be a tutorial for older versions Smiley

and how about to implement it to 2.8.2 too ?

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
sky writer

Offline Offline

Posts: 285



« Reply #3 on: February 18, 2011, 04:20:04 PM »

Thanks Ivan!  This is extremely useful.

Cheers!
Logged
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #4 on: February 18, 2011, 06:35:11 PM »

Here is a private patch solution for all versions before 2.9
This patch is full upgrade compatible to 2.9 and up.

Code: (/modules/wysiwyg/modify.php)
<?php
$MEDIA_URL 
WB_URL.MEDIA_DIRECTORY;
$content $get_content->fetchRow();
$content str_replace('{SYSVAR:MEDIA_REL}',$MEDIA_URL$content['content'] );
$content htmlspecialchars($content);
?>

Code: (/modules/wysiwyg/save.php)
<?php
// Update the mod_wysiwygs table with the contents
$MEDIA_URL WB_URL.MEDIA_DIRECTORY;
if(isset(
$_POST['content'.$section_id])) {
     
$content $_POST['content'.$section_id];
     
$searchfor '#(<.*= *\")('.quotemeta($MEDIA_URL).')(.*\".*>)#iU';
     
$content preg_replace($searchfor'$1{SYSVAR:MEDIA_REL}$3'$content);
     
$content $admin->add_slashes($content);

?>

Code: (/modules/wysiwyg/view.php)
<?php
$MEDIA_REL 
WB_URL.MEDIA_DIRECTORY;
// Get content
$content '';
$sql 'SELECT `content` FROM `'.TABLE_PREFIX.'mod_wysiwyg` WHERE `section_id`='.$section_id;
if( (
$content $database->get_one($sql)) ) {
        
$content str_replace('{SYSVAR:MEDIA_REL}',$MEDIA_REL$content );
}
echo 
$content;
?>

It's not a good idea to use Droplets here. If module droplets  or the specific droplet itself isn't installed, so module wysiwyg will not work.
« Last Edit: September 17, 2011, 08:53:08 PM by DarkViper » Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #5 on: February 18, 2011, 06:40:25 PM »

Hi,

I am curious what is SYSVAR:MEDIA_REL and is it defined in lower versions than 2.9 ?

I know that a droplet is not the best solution, but I couldnt figure out better and simplier solution Smiley

cheers
Ivan

Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
snark
Guest
« Reply #6 on: February 18, 2011, 07:08:40 PM »

Why not open THE sql in à texteditor

Find and replace

Find www.olddomain.com

Replace wwwnewdomain.org


Save

Upload to THE new phpmyadmin


All workzxxxxx fine

2 minutes max


Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #7 on: February 18, 2011, 08:37:01 PM »

Hi,

yes but for example I have special chars, like č, ć ž etc.. so when I open dumped DB with text editor, and then save it, I get special chars messed up Sad

I believe that other languages have similar issues with non standard chars..

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
snark
Guest
« Reply #8 on: February 20, 2011, 02:41:08 AM »

Do all texteditors mess up those characters?

I am using smultron à lot, i Will ry to find it out
Logged
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #9 on: February 20, 2011, 09:29:56 AM »

I am curious what is SYSVAR:MEDIA_REL and is it defined in lower versions than 2.9 ?

right now this is a simply placeholder inside the database only but with the syntax of future versions/releases.
From 2.9 MEDIA_REL itself is (like WB_REL, ADMIN_REL and others) a new system variable which contains the relative path based on DocumentRoot.
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
mjm4842

Offline Offline

Posts: 227


« Reply #10 on: February 20, 2011, 12:11:04 PM »

Here is another solution. It has the advantage of also affecting all links in WYSIWYG content including those in media URL's. It also makes your config.php system independent in most cases.

The following instructions should work with both the standard WYSIWYG version of the module which comes include with WebsiteBaker and the WYSIWYG History replacement version.

Code in BLACK is the existing code that need not be changed.

Comment out or delete the existing lines in RED.

Insert the lines in GREEN.

STEP 1: CHANGE /config.php

Replace:

define('WB_URL', ...);
define('ADMIN_PATH', ...);
define('ADMIN_URL', ...');


...with...

define('ADMIN_PATH', WB_PATH.'/admin');
$WB_SERVROOT = 'http'.(@empty($_SERVER['HTTPS'])?'':'s').'://';
$WB_SERVROOT .= $_SERVER['SERVER_NAME'];
if($_SERVER['SERVER_PORT']!=='80' && $_SERVER['SERVER_PORT']!=='443') {
  $WB_SERVROOT .= ':'.$_SERVER['SERVER_PORT'];
}
define('WB_SERVROOT', $WB_SERVROOT);
define('WB_URL', $WB_SERVROOT.'');  // only modify content of last quotes if not installed in root. Ex: '/mysite'
define('ADMIN_URL', WB_URL.'/admin');


This will make your config.php system independent except as noted above. Please note that this may not be compatible with future WebsiteBaker upgrade scripts so you might want to just comment out the original lines for now.

STEP 2: CHANGE /modules/wysiwyg/modify.php

The following change will fix the URL's when you go to edit existing WYSIWYG content.

WYSIWYG Standard Version

$content = str_replace(WB_SERVROOT,'', content['content']);
$content = htmlspecialchars($content);

$content = (htmlspecialchars($content['content']));


WYSIWYG History Version

$content = str_replace(WB_SERVROOT,'', row['content']);
$content = htmlspecialchars($content);

$content = htmlspecialchars($row['content']);


WYSIWYG Some Older Versions

$content = str_replace(WB_SERVROOT,'', $content);
$content = htmlspecialchars($content);


STEP 3: CHANGE /modules/wysiwyg/save.php

The following change will fix the URL's when you go to save WYSIWYG content:

$content = str_replace(WB_SERVROOT,'', $_POST['content'.$section_id]);
$content = $admin->add_slashes($content);

$content = $admin->add_slashes($_POST['content'.$section_id]);


STEP 4: CHANGE /modules/wysiwyg/view.php

The following change will fix the URL's in existing content:

$content = str_replace(WB_SERVROOT,'', $content);
echo $content;


With best regards,

Michael Milette
TNG Consulting Inc.
« Last Edit: February 20, 2011, 12:16:02 PM by mjm4842 » Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
Argos
Moderator
**
Offline Offline

Posts: 2161


WWW
« Reply #11 on: February 20, 2011, 11:33:45 PM »

You all noticed that when you create a link or image in WYSIWYG editor, it displays full (current) url. (for example: http://www.mysite.xy/pages/page1.php) so you have more job when migrating sites..

It creates links like [wblink2], doesn't it? Or do you mean something else?
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #12 on: February 21, 2011, 03:30:33 AM »

It creates links like [wblink2], doesn't it? Or do you mean something else?

... more something else. Wink

each full qualified link, pointing into media-dir [ http: //websitebaker.org/media/images/pic.gif ]
will be stored in database in shortened manner [ {SYSVAR:MEDIA_REL}/images/pic.gif ]

for modify or view {SYSVAR:MEDIA_REL} will be replaced by the link of the current installation.

this method gives the possibility to change the webspace, install dir, domain and so on, without any changes in the database.
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
Argos
Moderator
**
Offline Offline

Posts: 2161


WWW
« Reply #13 on: February 21, 2011, 09:45:13 AM »

So what's the best solution: yours or mjm4842's one?
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #14 on: February 21, 2011, 11:39:19 AM »

from my point of view i'll use the solution, which is 100% compatible to the already existing solution in WB2.9 wink

So there is no need to change any database entry during upgrade.

Also the 'official' solution does not replace any URL. (sometimes you have to write an URL as text maybe)
A URL which is a property  of a HTML tag ( <a> <img> <object> s.o. ) will be replaced only.

A purpose in WB 2.9 is to substitute fully qualified, internal links with shortened links basing on DocumentRoot and installation settings.
Code:
instead of

http://example.com/wb/media/images/pic.gif

the only output shall be

/wb/media/images/pic.gif
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
Argos
Moderator
**
Offline Offline

Posts: 2161


WWW
« Reply #15 on: February 21, 2011, 01:42:52 PM »

Allright, thanks for the explanation!
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #16 on: February 21, 2011, 03:20:09 PM »

Hi all,

well, it appears now when I presented my suggestion for fix that there are multiple ways of doing this, but nobody presented the solution so far..  angry angry

At my point of view {SYSVAR:MEDIA_REL} is good solution but if I understood good it doesnt work on 2.8.1 and lower versions, but other presented fixes (mine and Michael's) may be a solution while stable 2.9 appears..

AND, next time when you figure out something usefull, please share the code Smiley that os a point of open source Smiley

cheers,
Ivan
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Argos
Moderator
**
Offline Offline

Posts: 2161


WWW
« Reply #17 on: February 21, 2011, 03:23:42 PM »

At my point of view {SYSVAR:MEDIA_REL} is good solution but if I understood good it doesnt work on 2.8.1 and lower versions, but other presented fixes (mine and Michael's) may be a solution while stable 2.9 appears..

If I understand well, it does work on al current versions:
Quote
Here is a private patch solution for all versions before 2.9
This patch is full upgrade compatible to 2.9 and up.
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
dbs
WebsiteBaker Org e.V.

Offline Offline

Posts: 3719


WWW
« Reply #18 on: September 17, 2011, 04:25:22 PM »

has anybody darkvipers patch tested with WB 2.8.2?
backend wysiwyg-section notice:
Quote
Use of undefined constant MEDIA_URL - assumed 'MEDIA_URL' in .../modules/wysiwyg/modify.php on line 25

line 25:
Code:
$content = str_replace('{SYSVAR:MEDIA_REL}',MEDIA_URL, $content['content'] );

dbs
Logged

dbs
WebsiteBaker Org e.V.

Offline Offline

Posts: 3719


WWW
« Reply #19 on: September 17, 2011, 07:47:02 PM »

@ivan: i like your solution.
is this only for upcoming pathes in wysiwyg?
have tested. 1 pic was old (in a link), 1 pic i have added after made changes.
on the new location the old pic has the old path and the new pic has the new path.

dbs
« Last Edit: September 17, 2011, 07:49:33 PM by dbs » Logged

DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #20 on: September 17, 2011, 09:04:01 PM »


there was a little issue in my previous Patch. Just i fixed it.

Quote from: dbs
have tested. 1 pic was old (in a link), 1 pic i have added after made changes.
on the new location the old pic has the old path and the new pic has the new path.

of sure. The database will not change by itself. wink
To change, you must open all of the WYSIWYG sections only and save it again.

Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
dbs
WebsiteBaker Org e.V.

Offline Offline

Posts: 3719


WWW
« Reply #21 on: September 17, 2011, 10:07:57 PM »

Quote
To change, you must open all of the WYSIWYG sections only and save it again.
ah, ok, i understand.
this is not the yellow of the egg  grin
Logged

DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #22 on: September 17, 2011, 10:19:08 PM »

i know. that's why it is a patch only, not a final solution.
otherhands, it must be done once only for existing sections...
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
dbs
WebsiteBaker Org e.V.

Offline Offline

Posts: 3719


WWW
« Reply #23 on: September 18, 2011, 07:19:59 AM »

Quote
otherhands, it must be done once
that's right and ok.

have now tested (with easyPHP) your version and it seems the save.php has a malefunction.
content will be saved with success-message, but after this message there is the old content again without changes.

dbs
Logged

crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #24 on: September 18, 2011, 08:15:06 AM »

@ivan: i like your solution.
is this only for upcoming pathes in wysiwyg?
have tested. 1 pic was old (in a link), 1 pic i have added after made changes.
on the new location the old pic has the old path and the new pic has the new path.

dbs

You would have to open and save each wysiwyg editor to make it work with existing project site. I apply this patch when I create new site.

For existing site, you can try to dump the database, then search and replace www.mysite.xy with [[WB-URL]] and import DB back to site..

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Pages: [1] 2   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!