Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION Using (%%)
#1
I've noticed that several plugins use the placeholder (%%) when placing content into a page. never actually used this before and was wondering if there's any relevant documentation to show me the process of using it. 

Thanks
Reply
#2
It's plugin specific, so you can read it in the plugin documentation. Usually it's something like (% plugin name %) or (% plugin name + parameter %)

For example I18N Gallery:

(% gallery name=my-gallery-name %)

So this is (% gallery %) + the name of your gallery, for example a gallery called flowers:

(% gallery name=flowers %)
Reply
#3
(2019-02-27, 23:10:42)datiswous Wrote: It's plugin specific, so you can read it in the plugin documentation. Usually it's something like (% plugin name %) or (% plugin name + parameter %)

For example I18N Gallery:

(% gallery name=my-gallery-name %)

So this is (% gallery %) + the name of your gallery, for example a gallery called flowers:

(% gallery name=flowers %)

Thanks for the reply, I must keep missing it as I don't see any ref to ShortCode in the docs .
much appreciated.
Reply
#4
(2019-03-01, 22:49:39)craiga Wrote:
(2019-02-27, 23:10:42)datiswous Wrote: It's plugin specific, so you can read it in the plugin documentation. Usually it's something like (% plugin name %) or (% plugin name + parameter %)

For example I18N Gallery:

(% gallery name=my-gallery-name %)

So this is (% gallery %) + the name of your gallery, for example a gallery called flowers:

(% gallery name=flowers %)

Thanks for the reply, I must keep missing it as I don't see any ref to  ShortCode in the docs .
much appreciated. . . . .


Still no joy . . . is anyone able to provide some help please. I've searched high and low and can't find any docs on creating the placeholders. I need to display some content from the back end in the front when the plugin is installed and wanted to use % whatevername %

Thanks
Reply
#5
What plugin? Or is it your own plugin you make?
Reply
#6
(2019-04-23, 06:56:30)datiswous Wrote: What plugin? Or is it your own plugin you make?

It's an idea for a plug-in I'd like to make. I'd really like to know exactly how the process works. For example if I had a contact form or any content (even just a simple div with some text in it ) that I wanted to display in one of the pages.   I would like the user to be able to use the process of adding (%whatever%) on any created page to display the form (or any content that I specify.)

Hope I've explained that clearly enough for you. I actually thought at first it was through adding a filter but I'm not sure on it. I've looked at several plugins to see if I could gain any information on how the process works (i18n gallery, po1 contact form).

Thanks
Reply
#7
(2019-04-23, 08:05:04)craiga Wrote:
(2019-04-23, 06:56:30)datiswous Wrote: What plugin? Or is it your own plugin you make?

It's an idea for a plug-in I'd like to make. I'd really like to know exactly how the process works. For example if I had a contact form or any content (even just a simple div with some text in it ) that I wanted to display in one of the pages.   I would like the user to be able to use the process of adding (%whatever%) on any created page to display the form (or any content that I specify.)

Hope I've explained that clearly enough for you. I actually thought at first it was through adding a filter but I'm not sure on it. I've looked at several plugins to see if I could gain any information on how the process works (i18n gallery, po1 contact form).

Thanks


Maybe this can help you.
PHP Code:
add_filter('content','some_names'); 

In this example I use a table
PHP Code:
function some_names($content) {
    
    
$xml getXML(dpeventGSCONTENT);
    
    
$settings getXML(dpeventGSSETTINGS);
    
    
$dateformat $settings->dateformat

$out ='<table class="event-content">
            <thead>
                <tr>
                    <th>Event</th>
                    <th colspan="3" style="text-align:center;">Date</th>
                    <th>Content</th>
                    <th>Color</th>
                </tr>
            </thead>'
;
    
    foreach (
$xml->event as $event)

        {
            
$ids  $event['id'];
            
$name $event->name;
            
$startdate $event->startdate;
            
$enddate $event->enddate;
            
$color $event->color;
            
$url $event->url;
            
$content $event->content;
        
// start content
            
$out .='<tr>';
                    if((string)
$url ==='') {
            
$out .='<td>'.$name.'</td>';
                    } else {
            
$out .='<td><a href="'.$url.'">'.$name.'</a></td>';    
                    } 
// end else
            
$out .='<td>'.date($dateformat,strtotime($startdate)).'</td>';
                    
                    if((string)
$enddate ==='') {
            
$out .= '<td>No date</td>';        
                        } else {
            
$out .= '<td>'.date($dateformat,strtotime($enddate)).'</td>';
                    } 
// end else
                        
                    
if((string)$content ==='') {
            
$out .= '<td>NO Content</td>';
                    } else {
            
$out .= '<td style="max-width:400px;background:red;">'.$content.'</td>';
                    } 
// end else 
            
$out .= '<td style="max-width:400px;background:red;">'.$url.'</td>
                        <td><div style="width:17px;height:17px;border-radius:3em;background-color:'
.$color.'"></div></td>
                    </tr>'
;
        } 
// foreach
                    
            
$out .= '</table>';
        
// end content
        
        
        
$regex '(%whatever%)'// this is what you need
        
$content str_replace($regex$out$content);

    return 
$content;

Reply
#8
That's brilliant.

Thank you very much.
I'll try that today


Ahhhh, I get it now:


Really appreciate your help
Reply
#9
In the hope this helps others:

PHP Code:
add_filter('content','content_test');



function 
content_test($content){
   
$regex '(%whatever%)'// add this (%whatever%) to your page to include content
   
$out "whatever content- it works!!!";
   
$content str_replace($regex$out$content);
   return 
$content;





Using the add_filter() function
==================================
From the docs section: http://get-simple.info/wiki/plugins:hooks_filters
'content' Will allow you to alter or filter the $content variable.
The function that you pass $content to should then return your results back to the system.

 In other words 
 My interpretation is as follows:

 When you use a filter and specify (content,function call) then
 the content variable is passed to that function so make sure you include a param variable in your function description.
 Once the function searches for the placeholder and replaces the placeholder with your content 
 then we return the new value back to the filter using the return method.

Big thanks to smdp-1971 for the example. It really helped. 
(I've tweaked the original example so it just outputs something simple.)
Reply
#10
(2019-04-23, 17:18:40)craiga Wrote: That's brilliant.

Thank you very much.
I'll try that today


Ahhhh,  I get it now:


Really appreciate your help

I'm glad I can help.

Enjoy!
Reply
#11
This is what I wrote to do this

PHP Code:
function getExpansion($trigger,$contents,$noargs false){
  
// todo: get lookaheads and lookbehind implemented so you can put non executing code in pages for examples.
  
  // $lookb = "<code>";
  // $looka = "</code>";
  
  // $pattern = "/(?<!".$lookb.")\(%\s*(".$trigger.")(\s+(?:%[^%\)]|[^%])+)?\s*%\)(?!".$looka.")/";
  // $pattern = "/(?<=".$look.")\(%\s*(".$trigger.")(\s+(?:%[^%\)]|[^%])+)?\s*%\)(?=".$look.")/";
  
$pattern "/\(%\s*(".$trigger.")(\s+(?:%[^%\)]|[^%])+)?\s*%\)/";
  
  if(
preg_match($pattern,$contents,$matches)){
    
# echo "<h2>Trigger was Found</h2>"; print_r($matches);
    
if(!empty($matches[2]) && !$noargs){
      
// get arguments
      # echo "<h2>Trigger has arguments</h2>";      
      
return array(true,'args'=>get_args(trim($matches[2])) );
    }
    else
    {
      return array(
true);
    }
  }
  
}

function 
get_args($str){
  
/*
    Gets key value pairs from a string
    pairs are deimited by space
    values can be defined as either
      key=value_no_spaces
      key='value spaces'
      key = "value spaces"
      key
     * spaces in the pair assigment do not matter
  */
  
  // TODO: make delimiters variable
  
$regex = <<<EOD
  /(?J)(?:(?P<key>\w+)\s*\=\s*["'](?P<value>[^"']*(?:["']{2}[^"']*)*)["']) | (?:(?P<key>\w+)\s*\=\s*(?<value>[^"'\s]*)) | (?:(?P<key>\w+)\s*)/ix
EOD;
  
  
$args = Array();
  
  
preg_match_all($regex,$str,$argsraw,PREG_SET_ORDER);
  
  if(
$argsraw){
    
$cnt count($argsraw);
    for(
$i=0;$i<$cnt;$i++){
      
# echo $argsraw[$i]['key'] . " = " . $argsraw[$i]['value'] . "<br>";
      
$args[strtolower($argsraw[$i]['key'])] = $argsraw[$i]['value'];
    }
  }  
  
  return 
$args;

NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#12
(2019-04-26, 02:46:42)shawn_a Wrote: This is what I wrote to do this

PHP Code:
function getExpansion($trigger,$contents,$noargs false){
 
 // todo: get lookaheads and lookbehind implemented so you can put non executing code in pages for examples.
 
 
  
// $lookb = "<code>";
 
 // $looka = "</code>";
 
 
  
// $pattern = "/(?<!".$lookb.")\(%\s*(".$trigger.")(\s+(?:%[^%\)]|[^%])+)?\s*%\)(?!".$looka.")/";
 
 // $pattern = "/(?<=".$look.")\(%\s*(".$trigger.")(\s+(?:%[^%\)]|[^%])+)?\s*%\)(?=".$look.")/";
 
 $pattern "/\(%\s*(".$trigger.")(\s+(?:%[^%\)]|[^%])+)?\s*%\)/";
 
 
  if
(preg_match($pattern,$contents,$matches)){
 
   # echo "<h2>Trigger was Found</h2>"; print_r($matches);
 
   if(!empty($matches[2]) && !$noargs){
 
     // get arguments
 
     # echo "<h2>Trigger has arguments</h2>";      
 
     return array(true,'args'=>get_args(trim($matches[2])) );
 
   }
 
   else
    
{
 
     return array(true);
 
   }
 
 }
 
 
}

function 
get_args($str){
 
 /*
    Gets key value pairs from a string
    pairs are deimited by space
    values can be defined as either
      key=value_no_spaces
      key='value spaces'
      key = "value spaces"
      key
     * spaces in the pair assigment do not matter
  */
 
 
  
// TODO: make delimiters variable
 
 $regex = <<<EOD
  /(?J)(?:(?P<key>\w+)\s*\=\s*["'](?P<value>[^"']*(?:["']{2}[^"']*)*)["']) | (?:(?P<key>\w+)\s*\=\s*(?<value>[^"'\s]*)) | (?:(?P<key>\w+)\s*)/ix
EOD;
 
 
  $args 
= Array();
 
 
  preg_match_all
($regex,$str,$argsraw,PREG_SET_ORDER);
 
 
  if
($argsraw){
 
   $cnt count($argsraw);
 
   for($i=0;$i<$cnt;$i++){
 
     # echo $argsraw[$i]['key'] . " = " . $argsraw[$i]['value'] . "<br>";
 
     $args[strtolower($argsraw[$i]['key'])] = $argsraw[$i]['value'];
 
   }
 
  
  
  return $args
;
  

Nice one. I have to admit that even after several years coding, I still don't utilise REGEX half as much as I should.
Reply
#13
I avoid it at all costs, it is pretty expensive and should not be used when string operations will do
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)