We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

site_info plugin development wrong tag_data being sent to plugin

Development and Programming

Tokyo Development Learning Center's avatar
Tokyo Development Learning Center
1 posts
17 years ago
Tokyo Development Learning Center's avatar Tokyo Development Learning Center

Hi,

I’m sure this is a stupid question, but I’m trying to develop a plugin to accept a site_id and parse a block of text replacing the relevant variable markers with the proper values for site information.

Sample usage:

<ul>{exp:weblog:entries site="not nonexistant"}
  <li>{title} - {exp:site_info id="{entry_site_id}"}{site_name} - {site_description}{/exp:site_info}</li>
{/exp:weblog:entries}

here is the relevant plugin code:

function Site_info() {
    global $TMPL, $SESS;
    if (!isset($SESS->cache['site_info'])) {
      global $DB;
      $query=$DB->query("SELECT site_label, site_name, site_description, site_id FROM exp_sites");
      foreach($query->result as $value) {
        $SESS->cache['site_info'][$value['site_id']]=$value;
      }
      //print_r($SESS->cache['site_info']);
      //do the db query and stick site info into array here
    }
    $input_text = $TMPL->tagdata;
    $site_id = (! $TMPL->fetch_param('id')) ? 1 : $TMPL->fetch_param('id');
    print_r($input_text);
    $search = array('{site_id}','{site_label}','{site_description}','{site_name}');
    $replace = array($SESS->cache['site_info'][$site_id]['site_id'],$SESS->cache['site_info'][$site_id]['site_label'],$SESS->cache['site_info'][$site_id]['site_description'],$SESS->cache['site_info'][$site_id]['site_name']);
    $this->return_data = str_replace($search,$replace,$input_text);
    //Now do the actual conversion using the provited site_id parameter
  }

That includes a print_r debugging statement, used to show me what is included in $TMPL->tagdata, and I get a large part of the template before the bit inside the {exp:site_info} tags as part of the tag_data as well. What am I doing wrong?

Briefly (hopefully) the error ridden page can be viewed at http://test.gdlnap.org

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Hey Tokyo,

Can I get a peak at the whole plugin? I’ll see if anything jumps out at me.

Jamie

       
UltraBob's avatar
UltraBob
186 posts
17 years ago
UltraBob's avatar UltraBob

Sure, I was accidentally logged in with the client account last time, but I’m the same guy.

<?php

$plugin_info = array(
  'pi_name' => 'Site Info',
  'pi_version' => '0.8',
  'pi_author' => 'Bob McDonald - Akatombo Media',
  'pi_author_url' => 'http://www.akatombo.com',
  'pi_description' => "This plugin is intended to be used with the {entry_site_id} variable of the {exp:weblog:entries} tag in the weblog module when used in conjunction with the Multiple Site Manager.  Given a site_id it will return variables for site_label, site_name, and site_description.",
  'pi_usage' => Site_info::usage()
  );

/**
* The main class of the Site_info plugin
*/
class Site_info {
  var $return_date = "";
  function Site_info() {
    global $TMPL, $SESS;
    if (!isset($SESS->cache['site_info'])) {
      global $DB;
      $query=$DB->query("SELECT site_label, site_name, site_description, site_id FROM exp_sites");
      foreach($query->result as $value) {
        $SESS->cache['site_info'][$value['site_id']]=$value;
      }
      //print_r($SESS->cache['site_info']);
      //do the db query and stick site info into array here
    }
    $input_text = $TMPL->tagdata;
    $site_id = (! $TMPL->fetch_param('id')) ? 1 : $TMPL->fetch_param('id');
    print_r($input_text);
    $search = array('{site_id}','{site_label}','{site_description}','{site_name}');
    $replace = array($SESS->cache['site_info'][$site_id]['site_id'],$SESS->cache['site_info'][$site_id]['site_label'],$SESS->cache['site_info'][$site_id]['site_description'],$SESS->cache['site_info'][$site_id]['site_name']);
    $this->return_data = str_replace($search,$replace,$input_text);
    //Now do the actual conversion using the provited site_id parameter
  }
  function usage() {
    ob_start();
    ?>
    This is a test
    <?php
    $buffer = ob_get_contents();
    ob_end_clean();
    return $buffer;
  }
}

?>

I think you’ll find there isn’t much more there than what I already included. For good measure, here is the template:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>{site_label}</title>
    <link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection">
        <link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print">    
        <!--[if IE]><link rel="stylesheet" href="css/blueprint/lib/ie.css" type="text/css" media="screen, projection"><![endif]-->
</head>

<body>
<div class="container">
<div id="header">
  <h1>{site_label}</h1><div id="login">{exp:member:login_form return=""}

<label>Username</label>

<input type="text" name="username" value="" maxlength="32" class="input" size="25" />

<label>Password</label>

<input type="password" name="password" value="" maxlength="32" class="input" size="25" />

{if auto_login}
<input class='checkbox' type='checkbox' name='auto_login' value='1' /> Auto-login on future visits
{/if}

<input class='checkbox' type='checkbox' name='anon' value='1' checked='checked' /> Show my name in the online users list

<input type="submit" name="submit" value="Submit" />

<a href="http://{path=member/forgot_password}">Forgot your password</a>

{/exp:member:login_form}</div>
</div>
<div id="navigation"></div>
<div id="content">
  <div id="network" class="column span-12">
    <h2>Our DLC (Distance Learning Center) Network</h2>
<h3>header 3</h3>
<h4>header 4</h4>
<h5>header 5</h5>
<h6>header 6</h6>
{exp:site_info}
            <dl>{exp:weblog:category_archive weblog="dlc_report" site="not nonexistant" style="linear"}

            {categories}
            <dt>{category_name}</dt>
            {/categories}

            {entry_titles}
            <dd><a href="http://{path=" title="GDLN AP: {title}">{title}</a></dd>
            {/entry_titles}

            {/exp:weblog:category_archive}</dl>
  </div>
  <div id="gdlnap_news" class="column span-12 last">
    <ul>{exp:weblog:entries weblog="gdln_ap_news" disable="categories|member_data|pagination|trackbacks" site="not nonexistant"}
      <li>{title} - {entry_site_id} - 
        {exp:site_info}food{/exp:site_info}</li>
    {/exp:weblog:entries}</ul>
  </div>
</div>
<div id="footer"></div>
</div>
</body>
</html>
       
UltraBob's avatar
UltraBob
186 posts
17 years ago
UltraBob's avatar UltraBob

I am apparently incapable of operating the find function in my text editor. The problem is in the template, and I expect that after I fix the idiot mistake everything will work fine.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

I was just about to take a look at this

Please let me know you do indeed have the issue figured out. 😊

Jamie

       
UltraBob's avatar
UltraBob
186 posts
17 years ago
UltraBob's avatar UltraBob

Yes, it was a bonehead mistake. I hope to make this plugin available to anyone else who might use it sometime very soon. Thanks for the responsiveness!

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Glad to hear it. 😊

Jamie

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.