Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2008-05-20 03:55:12

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: must have hack?

“#textpattern”:irc://irc.freenode.net/xpat (you need an IRC client).

That code is correct – have you tried commenting out parts of your plugin? Also, your array could just be:

$types = array('article', 'comment', 'file', 'link', 'misc',);

Then use ucfirst to capitalize the value.

Last edited by jm (2008-05-20 03:55:36)

Offline

#38 2008-05-20 04:04:57

Ruhh
Member
From: dakota dunes
Registered: 2008-01-20
Posts: 305

Re: must have hack?

Oh ok, well the capitalization won’t be neccesary. Uh, how about this line:

foreach ($types as $type_table => $type_name) {
	$query = "SELECT * FROM 'txp_form' WHERE 'type' = '$type_table'";
	$result = mysql_query($query, $link);
	if (mysql_num_rows($result) > 0) {
?>

<txp:Ruhh />

Offline

#39 2008-05-20 04:22:52

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: must have hack?

<?php
    // see lib/txplib_db.php
    // This is sloppy, since we don't need a WHERE clause, but it's simple.
    $forms = safe_rows("name, type", "txp_form", "name != ''", 1);
    if ($forms)
    {
        foreach ($forms as $form)
        {
            dmp($form);
            // Do stuff
        }
    }
?>

Offline

#40 2008-05-20 19:08:33

Ruhh
Member
From: dakota dunes
Registered: 2008-01-20
Posts: 305

Re: must have hack?

Yeah.

I get the same error. I can’t create this at all. So anyone wanna create this?


<txp:Ruhh />

Offline

#41 2008-05-20 19:44:57

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: must have hack?

Post all of your code! The snippet I posted is error-free, so the error must be before it.

Offline

#42 2008-05-20 22:24:37

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: must have hack?

I’m fighting with output buffers right now, but here’s the gist of the plugin:

<?php
$plugin = array(
    'version' => '0.1',
    'author' => 'Jon-Michael Deldin',
    'author_uri' => 'http://jmdeldin.com',
    'description' => 'Toggleable forms.',
    'type' => 1,
);
if (!defined('txpinterface')) include 'zem_tpl.php';

if (0) {
?>

# --- BEGIN PLUGIN HELP ---

# --- END PLUGIN HELP ---

<?php
}

# --- BEGIN PLUGIN CODE ---

if (txpinterface == 'admin')
{
    register_callback('jmd_form_toggle_init', 'form', '', 1);
}

function jmd_form_toggle_init($event, $step)
{
    ob_start('jmd_form_toggle');
}

function jmd_form_toggle($buffer)
{
    $rs = safe_rows("name, type", "txp_form", "name != '' ORDER BY type");
    $forms = array();
    foreach ($rs as $form)
    {
        if (!array_key_exists($form['type'], $forms))
        {
            $forms[$form['type']] = array($form['name']);
        }
        else
        {
            array_push($forms[$form['type']], $form['name']);
        }
    }

    $out .= tr(tda(sLink('form', 'form_create', gTxt('create_new_form')), 
          ' colspan="2"'));

    $types = array_keys($forms);
    foreach ($types as $type)
    {
        $out .= '<tr>
            <th colspan="2" onclick="toggleDisplay(\'' . $type . '\')">
            ' . $type . '</th></tr><tbody id="' . $type . '">';
        for ($i = 0; $i < count($forms[$type]); $i++)
        {
            $form = $forms[$type][$i];
            $out .= '<tr><td>';
            if (gps('name') == $form)
            {
                $out .= $form;
            }
            else
            {
                $out .= href($form, '?event=form&amp;name=' . $form);
            }
            $out .= '<td><input type="checkbox" name="selected_forms[]" 
                value="' . $form . '"/>
                </td></tr>';
        }
        $out .= '</tbody>';
    }
    $out .= '</table>';
    $pattern = '<tr><td colspan="3" style="height:30px">(.*)<input type="hidden" name="event" value="form" />';

    return ereg_replace($pattern, $out, $buffer);
}

# --- END PLUGIN CODE ---

?>

Last edited by jm (2008-05-21 02:47:07)

Offline

#43 2008-05-20 23:25:06

Ruhh
Member
From: dakota dunes
Registered: 2008-01-20
Posts: 305

Re: must have hack?

Yeah.

My code is poorly written, lol. And of course, I highly doubt it will work.

<?php
$link = mysql_connect("HOST", "USER", "PASS") or die("Can't connect.");
mysql_select_db("txp_form", $link) or die("Can't select database.");
$types = array("article" => "Article", "comment" => "Comment", "file" => "File", "link" => "Link", "misc" => "Miscellaneous");
foreach($types as $type_table => $type_name) {
	$query = "SELECT * FROM `txp_form` WHERE `type` = '$type_table'";
	$result = mysql_query($query, $link);
	if (mysql_num_rows($result) > 0) {
?>
<h1 class="show-jquery-extra"><?php echo $type_name; ?></h1>
<table class="jquery-extra">
	<tr>
		<th>Form</th>
	</tr>
<?php while($row = mysql_fetch_assoc($result)) { ?>
	<tr>
		<td><?php echo $row['name']; ?></td>
	</tr>
<?php } ?>
</table>
<?php
	}
}
?>

Feel free to laugh…

Last edited by Ruhh (2008-05-20 23:27:41)


<txp:Ruhh />

Offline

#44 2008-05-21 03:03:50

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: must have hack?

Ruhh – see textpattern > lib > txplib_db.php ;).

The plugin is mostly done. Calling all buffering pros – why does the code in foreach() not seem to be executed? When I print $out (w/o buffer), it works.

Offline

#45 2008-05-21 03:31:03

Ruhh
Member
From: dakota dunes
Registered: 2008-01-20
Posts: 305

Re: must have hack?

Sighs, I will read over those things again and make sure I get myself clarified.

So, for now I will use your code but may I have the txt file, the plugin itself?


<txp:Ruhh />

Offline

#46 2008-05-21 03:42:00

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: must have hack?

It doesn’t actually work yet – I need some help with buffering. Once it works, you should be able to paste the code into ied_plugin_composer or just download zem_tpl.php into the same directory as the plugin.

Offline

Board footer

Powered by FluxBB