Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:03:07+00:00 2026-05-25T10:03:07+00:00

I am using tinymce editor for inserting contents to mysql. I have changed wordpress

  • 0

I am using tinymce editor for inserting contents to mysql.
I have changed wordpress gallery editor plugin according to my system.

If there is gallery code in content. I convert this code to a symbolic photo, so that user understand there is a gallery , in stead of seeing a code. Like wordpress does.

If there is only 1 gallery in content, i convert this code to image successfully, but if there is more than 1 gallery it fails.

How can i convert all {gallery} code into a symbolic image before saving to db and convert these photos back to {gallery} code again while inserting or updating into mysql.

I am so bad on regular expression.
I think do_gallery RegExp has mistake. How should i change this.

initalising editor like:

ed.onBeforeSetContent.add(function(ed, o) {
            ed.dom.loadCSS(url + "/css/gallery.css");
            o.content = t._do_gallery(o.content);
        });

        ed.onPostProcess.add(function(ed, o) {
            if (o.get)
                o.content = t._get_gallery(o.content);
        });

My “do and get gallery” codes like that:

_do_gallery : function(co) {
        return co.replace(/\{gallery([^\]]*)\}/g, function(a,b){
            var image = '<img src="gallery.gif" class="wpGallery mceItem" title="gallery'+tinymce.DOM.encode(b)+'" />';
            console.log(image);
            return image;

        });
    },

    _get_gallery : function(co) {

        function getAttr(s, n) {
            n = new RegExp(n + '="([^"]+)"', 'g').exec(s);
            return n ? tinymce.DOM.decode(n[1]) : '';
        };

        return co.replace(/(?:<p{^>}*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) {
            var cls = getAttr(im, 'class');

            if ( cls.indexOf('wpGallery') != -1 )
                return '<p>{'+tinymce.trim(getAttr(im, 'title'))+'}</p>';

            return a;
        });
    }

If Content is:

<p>Blah</p>
<p>{gallery Name="gallery1" id="82" galeryID="15"  sizeId="6" galery_type="list"}</p>
<p>test</p>

this is ok

<img src="gallery.gif" class="wpGallery mceItem" title="gallery Name=&quot;tekne1&quot; id=&quot;82&quot; galeryID=&quot;15&quot; sizeId=&quot;6&quot; galery_type=&quot;liste&quot;" />

But, if content is:

<p>Blah</p>
<p>{gallery Name="gallery1" id="82" galeryID="15"  sizeId="6" galery_type="list"}</p>
<p>test</p>
<p>{gallery Name="gallery2" id="88" galeryID="11"  sizeId="1" galery_type="slide"}</p>
<p>test2</p>

it logs

<img src="gallery.gif" class="wpGallery mceItem" title="gallery Name=&quot;gallery1&quot; id=&quot;82&quot; galeryID=&quot;15&quot; sizeId=&quot;6&quot; galery_type=&quot;list&quot;}&lt;/p&gt; &lt;p&gt;test&lt;/p&gt; &lt;p&gt;{gallery Name=&quot;gallery2&quot; id=&quot;88&quot; galeryID=&quot;11&quot; sizeId=&quot;1&quot; galery_type=&quot;slide&quot;" />

I hope i could explain my problem
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:03:07+00:00Added an answer on May 25, 2026 at 10:03 am

    I suspect that your original regex is a typo, looks like a missing Shift when you hit the ]. Try this:

    /\{gallery([^\}]*)\}/g
    

    Then the ([^\}]*) part will (greedily) eat up any sequence of characters that aren’t }; your original one would consume any sequence of character that didn’t include a ] and the result is that you’d grab everything between the first { and the last } rather than just grabbing the text between pairs of braces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using tinymce editor for my form. i have three instance of tiny
I am using asp.net, i have added tinyMCE editor to my page. I want
I have a problem as follows: We're using a rich text editor (TinyMCE, but
I have data stored using tinymce with placeholders before each table Editor view when
I am using the TinyMCE editor. I have a div element. When an edit
I have been using tinyMCE over dojo dijit.editor because tinyMCE wins out on functionality.
I have been using tinyMce_hammer plugin to use tinymce in my rails app... but
I am using tinymce editor to have html page and then insert it in
My drupal site (internal) will not display the TinyMCE editor when using Google Chrome
I've started using Joomla 1.5 recently and am using the TinyMCE online WYSIWYG editor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.