0

I've created a simple shortcode plugin on Joomla. Actually I am trying to integrate Cleeng Video with Joomla. And will connect it's users in the future ( I hope ). I've stack on creating shortcode's parameter. I don't know how to parse it's parameter and value. My Shortcode is here (no parameter)

{cleengvideo}<iframe class="wistia_embed" src="http://fast.wistia.net/embed/iframe/5r8r9ib6di" name="wistia_embed" width="640" height="360" frameborder="0" scrolling="no" allowfullscreen=""></iframe>{/cleengvideo}

My code is here

public function onContentPrepare($content, $article, $params, $limit) {
     preg_match_all('/{cleengvideo}(.*?){\/cleengvideo}/is', $article->text, $matches);
      $i = 0;
      foreach ($matches[0] as $match) {
      $videoCode = $matches[1][$i];
      $article->text = str_replace($match, $videoCode, $article->text);
      }

I want to set height, width and 5r8r9ib6di this code from shortcode at least. Please can anyone help me with adding and parsing it's parameter

3 Answers 3

1

To get a parameter, you can simply use the following code:

$params->get('param_name', 'default_value');

So for example, in your XML file, if you had a field like so:

<field name="width" type="text" label="Width" default="60px" />

you would call the parameter like so:

$params->get('width', '60px');

Note that you don't have to add the default value as the second string, however I always find it good practice.

Hope this helps

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for you reply, but I need to make my shortcode with parameter. For example my current shortcode is {cleengvideo}videourl{/cleengvideo} and I would like to make it like this {cleengvideo width=150}videourl{/cleengvideo} Sorry for my bad description and bad english
Ahh I see what you mean. Try this: preg_match_all('/{cleengvideo width="' . $params->get('width') . '"}(.*?){\/cleengvideo}/is', $article->text, $matches); then call the width parameter in your <iframe> tag
Thank you again, I am sorry for made you misunderstood. I should pick an another example. Adding joomla plugin's parameter having no problem. I am trying to parse the Shortcode's parameter. I mean fetch OfferID from this code {cleengvideo offerid="R575665444_MN"} . But when I comes to " preg_match_all " and foreach loop, I got lost. Preg_match_all is on my first post. Thank you : )
0

I think I could found it's solution. It's here https://github.com/Cleeng/cleeng-wp-plugin/blob/master/php/classes/Frontend.php Code is

$expr = '/\[cleeng_content(.*?[^\\\])\](.*?[^\\\])\[\/cleeng_content\]/is';
        preg_match_all( $expr, $post->post_content, $m );
        foreach ( $m[0] as $key => $content ) {
            $paramLine = $m[1][$key];
            $expr = '/(\w+)\s*=\s*(?:\"|&quot;)(.*?)(?<!\\\)(?:\"|&quot;)/si';
            preg_match_all( $expr, $paramLine, $mm );

            if ( ! isset( $mm[0] ) || ! count( $mm[0] ) ) {
                continue;
            }

            $params = array( );
            foreach ( $mm[1] as $key => $paramName ) {
                $params[$paramName] = $mm[2][$key];
            }
            if ( ! isset( $params['id'] ) ) {
                continue;
            }

            $content = array(
                'contentId' => $params['id'],
                'shortDescription' => @$params['description'],
                'price' => @$params['price'],
                'itemType' => 'article',
                'purchased' => false,
                'shortUrl' => '',
                'referred' => false,
                'referralProgramEnabled' => false,
                'referralRate' => 0,
                'rated' => false,
                'publisherId' => '000000000',
                'publisherName' => '',
                'averageRating' => 4,
                'canVote' => false,
                'currencySymbol' => '',
                'sync' => false
            );

            if ( isset( $params['referral'] ) ) {
                $content['referralProgramEnabled'] = true;
                $content['referralRate'] = $params['referral'];
            }

            if ( isset( $params['ls'] ) && isset( $params['le'] ) ) {
                $content['hasLayerDates'] = true;
                $content['layerStartDate'] = $params['ls'];
                $content['layerEndDate'] = $params['le'];
            }

            $this->cleeng_content[$params['id']] = $content;
        }

Comments

0

Hope this helps someone searching for shortcode parameters, for parameters in short code we can use preg_match_all like that

preg_match_all('/{cleengvideo(.*?)}(.*?){\/cleengvideo}/is', $article->text, $matches);

This will give a array with 3 array elements, the second array have the parameters which you can maupulate with codes.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.