record display

1 view
Skip to first unread message

Shannon

unread,
Apr 3, 2009, 10:50:00 AM4/3/09
to Scriblio
I've been working on the CID module. Now that the data model is fairly
complete, I'm trying to get the records to display, but I seem to be
missing something. I'm going to post my parse_content function in
hopes that someone can point out what I'm doing wrong. I used the
marcish_parse_content function in Scriblio as a model, but I must not
understand some part of it. I would really appreciate any insight.
Thanks!
Shannon

add_filter( 'the_content', array(&$this, 'cid_the_content'));

public function cid_the_content( $content ) {
global $id;
if ( $id && ( $r = get_post_meta( $id, 'scrib_meditor_content',
true )) && is_array( $r[$cid] ))
return( $this->cid_parse_content( $r['cid'] ));
}

function cid_parse_content() {
global $id;

$result = '<ul class="fullrecord">';

if( isset( $r['location'][0]['street_a'])){
$result .='<li class="location">' . $r['location'][0]['street_a'] .
'</li>';
}

if( isset( $r['location'][0]['city'])){
foreach( $r['city'] as $temp)
$result .='<li>' . $temp['city'] . '</li>';
}

$result .= '</ul>';

return($result);

Casey Bisson

unread,
Apr 3, 2009, 3:41:09 PM4/3/09
to scri...@googlegroups.com

Good thinking to look to the main Scriblio plugin for clues. I think
you've got it mostly right except that the code is written to be part
of a PHP class, but the CID plugin isn't written that way (unless
you've rewritten it that much).

As an aside, please commit your changes to the plugin so far. The CID
plugin is the only one I've not yet renamed, mostly because I don't
want to mess up your work by renaming it without coordinating with
you. Also, however, I'd get a chance to see the context for this
question.

Once renamed, it will be here:
http://svn.wp-plugins.org/scriblio-schema-cid/

Anyway, back to your question...

This add_filter call probably looks funny because it's calling the
method of an object:

> add_filter( 'the_content', array(&$this, 'cid_the_content'));

For the CID plugin, it could probably look like this:

add_filter( 'the_content', 'cid_the_content' );


And this function definition is also written to be part of an object:

> public function cid_the_content( $content ) {

For the CID plugin, you can probably drop "public".


And this function call could be rewritten without the "$this->"

> return( $this->cid_parse_content( $r['cid'] ));


I might be able to offer a better example, however. Take a look at
this site, then read on:

http://connect2.plymouth.edu/

The schema here is "phonebook". I'd started out thinking it would be a
generic people directory, but time and other complications focused it
more specifically on the needs of that one marketing website. Still,
it's tracking a few details and uses WordPress' built-in content field
for the person's description. Even better, it's not written as a class
and has none of the OOP syntax. Here's how the various bits of data
get assembled:

add_filter( 'the_content', 'phonebook_the_content', 1);

function phonebook_the_content( $content ) {
global $id;
if( $id && ( $r = get_post_meta( $id, 'scrib_meditor_content',
true )) && is_array( $r['phonebook'] )){
global $bsuite;

$place = array();
$facebookid = '';

$phonebook = '<p class="academics">';
if ( is_array( $r['phonebook']['hometown'] )){
foreach( $r['phonebook']['academic'] as $temp )
if( !empty( $temp['class'] ))
$phonebook .= '<span class="graduating">Class of '.
$temp['class'] .'</span>';
if( !empty( $temp['major'] ))
$phonebook .= '<br /><span class="major">'. $temp['major'] .'</
span>';

}
$phonebook .= '</p>';

if ( is_array( $r['phonebook']['hometown'] )){
foreach( $r['phonebook']['hometown'] as $temp ){
if( !empty( $temp['highschool'] ))
$phonebook .= '<p class="highschool">'. $temp['highschool'];
if( !empty( $temp['city'] ))
$place[] = $temp['city'];
if( !empty( $temp['state'] ))
$place[] = $temp['state'];
}
}

if ( is_array( $r['phonebook']['contact'] )){
foreach( $r['phonebook']['contact'] as $temp ){
if( !empty( $temp['facebookid'] ))
$facebookid .= '<div class="facebook"><a href="'.
$temp['facebookid'] .'" title="Find me on Facebook!">Find me on
Facebook</a></div>';
}
}

if ( is_array( $place ))
$phonebook .= '<br />'. implode( ', ', $place ) .'</p>';
else
$phonebook .= '</p>';

return( '<div class="sub">'. $phonebook .'</div>'. $content .
$facebookid );
}

return( $content );
}

Shannon Astolfi

unread,
Apr 6, 2009, 9:08:55 AM4/6/09
to scri...@googlegroups.com
Casey, thanks for the quick reply - that makes things clearer.  I'll let you know when I have committed my changes.

Shannon

Shannon

unread,
Apr 8, 2009, 6:43:47 PM4/8/09
to Scriblio
Hi Casey,

Changes to scriblio-meditor-cid have been committed. I'll update my
svn to scriblio-schema-cid, if you are ready to rename the plugin.

The cid_the_content function is very stripped down now, in hopes of
not confusing myself.

Your last message made me take a closer look at the structure of the
CID plugin, and I have some questions.

- Your phonebook example seems to include bits of cid_save_record (I'm
referring to the if statements that deal with $temp). In the plugin,
cid_save_record is separate, so how should cid_the_content interact
with cid_save_record?

- I'm confused about the add_action that refers to cid_save record:
why doesn't it use the Wordpress action save_post?

I also have a bit more information from the tests I've been doing. I'm
just trying to enter data into the CID form and publish the post. A
post is created, and I can see its title in my database as well as in
the browser, but the post doesn't have content. If I create a new
archive record, that will save and display with no problem. I can see
the HTML in my database in post_content. When I create a CID post, the
post_content field is blank. This seems like a problem in
cid_save_record, maybe? I can't quite identify how these functions
interact, so any insight you can give me would be great.

Thanks so much,
Shannon

Casey Bisson

unread,
Apr 12, 2009, 10:03:49 PM4/12/09
to scri...@googlegroups.com

On Apr 8, 2009, at 6:43 PM, Shannon wrote:

> Changes to scriblio-meditor-cid have been committed. I'll update my
> svn to scriblio-schema-cid, if you are ready to rename the plugin.

Sweet. I've moved and renamed the plugin:

http://svn.wp-plugins.org/scriblio-schema-cid/
http://wordpress.org/extend/plugins/scriblio-schema-cid/

I also did a little work on it. the_content now works a bit (see
below). I've also remove a bit of extraneous code that I should have
cleared out previously.


> The cid_the_content function is very stripped down now, in hopes of
> not confusing myself.

I've gone and made it a bit more complex. It can now generate some
basic HTML for the locations and facilities. It's not much, but it's a
start.


> - I'm confused about the add_action that refers to cid_save record:
> why doesn't it use the Wordpress action save_post?

Scriblio uses the save_post action and preprocesses the Meditor
inputs, then Scriblio calls a x_save_record action for each of the
Meditor forms it finds, that's where cid_save_record comes in.


> I also have a bit more information from the tests I've been doing. I'm
> just trying to enter data into the CID form and publish the post. A
> post is created, and I can see its title in my database as well as in
> the browser, but the post doesn't have content.

It was looking for $r[$cid], but should have been looking for
$r['cid']. Things seem to be working with that change.

Shannon

unread,
Apr 13, 2009, 5:41:20 PM4/13/09
to Scriblio
Hi Casey, thanks for all the additions to this module. I've got the
latest version now.

> I've gone and made it a bit more complex. It can now generate some  
> basic HTML for the locations and facilities. It's not much, but it's a start.

Thanks, I think I understand how to extend this now.


> It was looking for $r[$cid], but should have been looking for  
> $r['cid']. Things seem to be working with that change.

I'm still not able to get values I enter into the form to display in a
post. Can you describe what you did to get things working?

I've been trying to solve the problem by comparing the CID module to
Scriblio...I can't tell why my input is not being processed (or is
it?), but I do have a question. Why doesn't CID need a cid_parse
function like marcish_parse_parts? Is it just another example of
object-orientedness in Scriblio, or is Scriblio actually handling the
input differently?

Thanks for your patience with all these questions.

Shannon

Shannon

unread,
May 1, 2009, 3:15:43 PM5/1/09
to Scriblio
Well, I'm stumped. I've read the Wordpress documentation and looked
over the old posts on this list, but I cannot figure out why the
post_content field of my wp_posts table is empty after entering data
in the CID meditor. Here's what I know:

The action hook is created in Scriblio
do_action( 'scrib_meditor_save_record', $post_id, $record );

The action is defined in CID
add_action('scrib_meditor_save_record', 'cid_save_record', 1, 2);

The cid_save_record function does create ouput
Array ( [cid] => Array ( [location] => Array ( [0] => Array
( [street_a] => Street [street_b] => Street [street_c] => Street
[city] => City [directions] => Directions ) ) [contact] => Array ( [0]
=> Array ( [contact_name] => Name [email] => Email ) ) [geog] => Array
( [0] => Array ( [a] => Areas ) ) [category] => Array ( [0] => Array
( [a] => 522 ) ) [keywords] => Array ( [0] => Array ( [a] =>
Keyword ) ) [services] => Array ( [0] => Array ( [serv_name] =>
Service ) ) [facilities] => Array ( [0] => Array ( [desc] => Facility
[room_cap] => 11 [room_fee] => $4 [kitchen] => Kitchen ) ) ) ) 1

The values are stored in wp_postmeta.meta_value
a:1:{s:3:"cid";a:7:{s:8:"location";a:1:{i:0;a:5:{s:8:"street_a";s:
6:"Street";s:8:"street_b";s:6:"Street";s:8:"street_c";s:6:"Street";s:
4:"city";s:4:"City";s:10:"directions";s:10:"Directions";}}s:
7:"contact";a:1:{i:0;a:2:{s:12:"contact_name";s:4:"Name";s:5:"email";s:
5:"Email";}}s:4:"geog";a:1:{i:0;a:1:{s:1:"a";s:5:"Areas";}}s:
8:"category";a:1:{i:0;a:1:{s:1:"a";s:3:"522";}}s:8:"keywords";a:1:{i:
0;a:1:{s:1:"a";s:7:"Keyword";}}s:8:"services";a:1:{i:0;a:1:{s:
9:"serv_name";s:7:"Service";}}s:10:"facilities";a:1:{i:0;a:4:{s:
4:"desc";s:8:"Facility";s:8:"room_cap";s:2:"11";s:8:"room_fee";s:
2:"$4";s:7:"kitchen";s:7:"Kitchen";}}}}

Meta_value is retrieved by cid_the_content
if ( $id && ( $r = get_post_meta( $id, 'scrib_meditor_content',
true )) && is_array( $r['cid'] ))

And I think that cid_the_content should be extracting the values from
the key:value pairs in meta_value and putting them between HTML tags.
But the HTML that should be stored in wp_posts.post_content is either
never generated or never saved. This is where I get confused. I don't
know if there is a problem in cid_the_content or if it's somewhere
else. Here's the function:

function cid_the_content( $content ) {
global $id, $bsuite;

if ( $id && ( $r = get_post_meta( $id, 'scrib_meditor_content',
true )) && is_array( $r['cid'] )){
$r = $r['cid'];

$record = '<ul class="cid-fullrecord">';
$record .= $bsuite->icon_get_h( $id, 's' );

// go through each of the locations and build an html list for each
foreach( $r['location'] as $temp ){
$location = '';
if( !empty( $temp['street_a'] ))
$location .= '<li class="street_a">' . $temp['street_a'] . '</
li>';

if( !empty( $temp['street_b'] ))
$location .= '<li class="street_b">' . $temp['street_b'] . '</
li>';

if( !empty( $temp['street_c'] ))
$location .= '<li class="street_c">' . $temp['street_c'] . '</
li>';

if( !empty( $temp['city'] ))
$location .= '<li class="city">' . $temp['city'] . '</li>';

if( !empty( $temp['state'] ))
$location .= '<li class="state">' . $temp['state'] . '</li>';

if( !empty( $temp['zip'] ))
$location .= '<li class="zip">' . $temp['zip'] . '</li>';

if( !empty( $temp['directions'] ))
$location .= '<li class="directions">' . $temp['directions'] . '</
li>';

// if $location is not empty, then add it to the record
if( !empty( $location ))
$record .= '<li class="location"><ul>' . $location . '</ul></li>';
}

// go through each of the facilities and build an html list for
each
foreach( $r['facilities'] as $temp ){
$facility = '';
if( !empty( $temp['room_cap'] ))
$facility .= '<li class="room_cap">' . $temp['room_cap'] . '</
li>';

if( !empty( $temp['room_fee'] ))
$facility .= '<li class="room_fee">' . $temp['room_fee'] . '</
li>';

if( !empty( $temp['room_restrict'] ))
$facility .= '<li class="room_restrict">' . $temp
['room_restrict'] . '</li>';

if( !empty( $temp['kitchen'] ))
$facility .= '<li class="kitchen">' . $temp['kitchen'] . '</li>';

if( !empty( $temp['equip'] ))
$facility .= '<li class="equip">' . $temp['equip'] . '</li>';

if( !empty( $temp['equip_restrict'] ))
$facility .= '<li class="equip_restrict">' . $temp
['equip_restrict'] . '</li>';

if( !empty( $temp['disabled'] ))
$facility .= '<li class="disabled">' . $temp['disabled'] . '</
li>';

// if $facility is not empty, then add it to the record
if( !empty( $facility ))
$record .= '<li class="desc">'. ( isset( $temp['desc'] ) ? $temp
['desc'] : '' ) .'<ul>' . $facility . '</ul></li>';
}

$record .= '</ul>';
}

return( $record . $content );

}


Any insights? What am I missing?

Thanks so much,
Shannon

Casey Bisson

unread,
May 3, 2009, 8:44:06 AM5/3/09
to scri...@googlegroups.com

There really isn't much that should be saved to the post_content field
of wp_posts. If you don't enter a long description, then there won't
be anything.

The cid_the_content() function that assembles the data from
wp_postmeta is run as the post is actually being displayed, not as
it's being saved.

So there's no need to worry about having nothing in the post_content
field, but is the real issue that nothing is getting displayed when
you view the record in your browser?

Shannon Astolfi

unread,
May 3, 2009, 10:23:09 PM5/3/09
to scri...@googlegroups.com
Aha! Thanks! I didn't realize where the HTML I was seeing in post_content came from.  So, yes, the real issue is that nothing is getting displayed.  I was just trying to theorize about why that was happening.

Thanks,
Shannon

Casey Bisson

unread,
May 4, 2009, 5:58:22 PM5/4/09
to scri...@googlegroups.com

In the the_content function you'll see a call to get_post_meta. You should try print_r'ng that to see what's there. 

Sent from my iPhone

Shannon Astolfi

unread,
May 13, 2009, 3:23:10 PM5/13/09
to scri...@googlegroups.com
Thanks for the testing advice.

print_r ($r) returns nothing. I'm out of my depth and can't tell where the error is, in the CID plugin itself or in the way I'm conducting the test.

Shannon

Casey Bisson

unread,
May 13, 2009, 10:47:12 PM5/13/09
to scri...@googlegroups.com

My earlier message was vague at best, so I've added some debugging
helpers to the plugin. Take a look at lines 466-469 and 474-477.

The first block of code will help identify if the cid_the_content()
function is running at all, if it's getting the post ID, and if
there's a post_meta record associated with it.

The second block will only execute if the scrib_meditor_content
post_meta record contains a CID record. Both blocks with print_r()
whatever records are found at that stage.

The scrib_meditor_content data is stored in the wp_postmeta table as a
PHP serialized array. The get_post_meta() and set_post_meta()
functions automatically serialize and unserialize the data and return
the array.

--Casey

Shannon Astolfi

unread,
May 21, 2009, 2:07:38 PM5/21/09
to scri...@googlegroups.com
Casey, thanks for the debugging advice.

cid_the_content and scrib_meditor_content seem to work; all test posts display an ID and an array containing my test inputs. When I comment out the debugging functions, no content displays, just post title.  It seems like this behavior would suggest a problem with the filter, maybe? If so, I have no idea what it is. Do you have the time to take a close look at this problem?

Thanks,
Shannon

Shannon Astolfi

unread,
Jun 4, 2009, 4:18:00 PM6/4/09
to scri...@googlegroups.com
Casey,
Huge thanks for helping me figure this problem out; screenshots of successful displays are attached.

I will be committing new CID code this evening which fills out the data model.

My next two priorities are mapping to the III importer and getting search/browse to work (currently browse and search return 404 errors).  Just so I know where to direct my energies, could you tell me whether I should expect Browse to work at this point? In other words, should the Scrib browse functions be working for my CID plugin, or do I need some additional code in CID to make that happen?

Thanks again,
Shannon

scrib2.JPG
scrib1.JPG

Casey Bisson

unread,
Jun 5, 2009, 8:04:55 AM6/5/09
to scri...@googlegroups.com

On Jun 4, 2009, at 4:18 PM, Shannon Astolfi wrote:

> Casey,
> Huge thanks for helping me figure this problem out; screenshots of
> successful displays are attached.
>
> I will be committing new CID code this evening which fills out the
> data model.

I'm glad it's working!


> My next two priorities are mapping to the III importer and getting
> search/browse to work (currently browse and search return 404
> errors). Just so I know where to direct my energies, could you tell
> me whether I should expect Browse to work at this point? In other
> words, should the Scrib browse functions be working for my CID
> plugin, or do I need some additional code in CID to make that happen?

The problem with the browse page may be that the permalinks aren't
configured or haven't updated properly after the Scriblio install. If
you already configured permalinks, simply visiting the permalink
options page again should be enough to update the settings, but making
(and reverting) a small change would help. If you don't have
permalinks setup, make sure you're using anything other than the ?
p=123 style.

Shannon

unread,
Jun 8, 2009, 5:25:17 PM6/8/09
to Scriblio

> The problem with the browse page may be that the permalinks aren't  
> configured or haven't updated properly after the Scriblio install. If  
> you already configured permalinks, simply visiting the permalink  
> options page again should be enough to update the settings, but making  
> (and reverting) a small change would help. If you don't have  
> permalinks setup, make sure you're using anything other than the ?
> p=123 style.

An extra note, in case it's helpful - attempting to search also
returns a 404 page. Does that point to permalink problems?

When I choose any option *besides* Default for the permalinks, the
page that I have chose as the Browse base in Settings -> Scriblio
returns a 404 error, even though the URL is correct (ie. matches the
permalink shown in Edit Page). I've tested it by creating a couple of
pages and selecting each one in turn as the Browse base. Could you
explain what selecting a Browse base does, or point me to the code I
should read?

Casey Bisson

unread,
Jun 8, 2009, 10:21:00 PM6/8/09
to scri...@googlegroups.com

All these signs point towards a missing .htaccess file or broken
Apache configuration.

I've posted a bit about .htaccess here:
http://about.scriblio.net/wiki/htaccess/

There's a chance that your Apache config is set to ignore .htaccess
files. You'll need to look at your directory or virtual host settings
in the Apache conf file. "AllowOverride None" will block .htaccess
access files, so you'll need to change those to something less
restrictive (I boldly set them to "All") and restart Apache.

--Casey

Shannon

unread,
Jun 18, 2009, 5:18:13 PM6/18/09
to Scriblio
Some new information...

Careful testing of our virtual host settings showed that they are
correct, so I decided to reinstall Wordpress.

A fresh install of Wordpress 2.7, Scrib 2.7r2, etc etc: selected
pretty permalinks, created some test records, and the Browse page
works - hooray!

But then I selected Use cid_category, cid_lang, cid_geog in Scriblio
options. Now my Browse page returns a 404 error, and deselecting the
facets and updating options does not fix the issue. I'm not sure what
this means, other than demonstrating that a functional Browse page is
possible with our server configuration. Does this suggest anything to
you?

Thanks,
Shannon

Casey Bisson

unread,
Jun 18, 2009, 11:41:10 PM6/18/09
to scri...@googlegroups.com

Hrm.... I will investigate.

Casey Bisson

unread,
Jun 19, 2009, 9:21:43 AM6/19/09
to scri...@googlegroups.com

A hah!

There are at least two ways to get a 404:
A. because Apache doesn't find a file to serve the request (gives a
rather bland 404 page)
B. because WordPress finds no posts for the the request (gives a 404
page using the WP theme)

I think you're suffering from cause B, and I probably should have
thought of this earlier.

Scriblio records are expected to be in a certain category set in the
Scrib options page. That's used to keep them off the front page[1] and
select them for browsing[2]. But the CID schema isn't setting the
category when it saves the record, leaving WordPress to issue the 404
on the browse page because it can't find any records in the required
category.

All we need to do to fix this is make sure the CID records are in that
category. The Marcish schema does that during the
scrib_meditor_save_record hook[3] like this:

wp_set_object_terms( $post_id, (int) $this-
>options['catalog_category_id'], 'category', FALSE );

I've committed a change[4] to CID to fix that, as well as a change[5]
to fix a bug (I had made long ago) in how it was displaying repeated
fields.

I should have made both changes a while ago, or at least identified
the cause of the 404s more quickly,

--Casey

[1]: http://plugins.trac.wordpress.org/browser/scriblio/trunk/scriblio.php#L448
[2]: http://plugins.trac.wordpress.org/browser/scriblio/trunk/scriblio.php#L393
[3]: http://plugins.trac.wordpress.org/browser/scriblio/trunk/scriblio.php#L2827
[4]: http://plugins.trac.wordpress.org/changeset/127354/scriblio-schema-cid/trunk
[5]: http://plugins.trac.wordpress.org/changeset/127364/scriblio-schema-cid/trunk

On Jun 18, 2009, at 5:18 PM, Shannon wrote:

Shannon Astolfi

unread,
Jun 19, 2009, 9:29:52 AM6/19/09
to scri...@googlegroups.com
Excellent - thanks, Casey!
 
Shannon

Casey Bisson

unread,
Jun 19, 2009, 11:26:10 AM6/19/09
to scri...@googlegroups.com

Is this online anywhere that we can explore?

Shannon Astolfi

unread,
Jun 22, 2009, 10:51:08 AM6/22/09
to scri...@googlegroups.com
Hi Casey,
Your solution for the Browse error makes sense, but I'm still getting a WP-themed 404 with the new schema-cid, even though now I only have Category selected as a facet.  I'm not sure why but, with the new schema-cid, cid_category, cid_geog, and cid_lang no longer appear as facet options. I thought I understood how to set facets, but there may be a mistake in my code there [1].

I wonder if there is some conflict between 'category' as it is used in Scrib [2]  and 'category' in CID, which is an array of subject terms [3]? Not sure if that makes sense, just trying to find some reason for my continued issues.

Our test server is not online. Would particular screenshots/code/settings details be helpful?

Thanks,
Shannon

[1] http://plugins.trac.wordpress.org/browser/scriblio-schema-cid/trunk/schema-cid.php?rev=127354#L416
[2] http://plugins.trac.wordpress.org/browser/scriblio/trunk/scriblio.php#L128
[3] http://plugins.trac.wordpress.org/browser/scriblio-schema-cid/trunk/schema-cid.php?rev=127354#L159


Casey Bisson

unread,
Jun 22, 2009, 12:12:25 PM6/22/09
to scri...@googlegroups.com

Are you sure the CID records have been saved in the WordPress category that Scrib is looking for on the browse page?

I had changed the CID schema to make it set the right category when saving records, but existing records won't get the the correct category until they get re-saved.

Shannon Astolfi

unread,
Jun 22, 2009, 12:21:02 PM6/22/09
to scri...@googlegroups.com
Oops, I didn't know about re-saving. All posts are now assigned to the Catalog category, and the browse page is back!

Thanks again,
Shannon

Casey Bisson

unread,
Jun 22, 2009, 12:42:47 PM6/22/09
to scri...@googlegroups.com

Yay!

Sorry I wasn't specific in my previous messages.

Shannon

unread,
Jun 24, 2009, 3:41:04 PM6/24/09
to Scriblio
Does the search page also require records to be saved in a particular
way?

Shannon


On Jun 22, 12:21 pm, Shannon Astolfi <shannon.asto...@gmail.com>
wrote:
> >http://plugins.trac.wordpress.org/browser/scriblio-schema-cid/trunk/s...
> > [2]
> >http://plugins.trac.wordpress.org/browser/scriblio/trunk/scriblio.php...
> > [3]
> >http://plugins.trac.wordpress.org/browser/scriblio-schema-cid/trunk/s...

Casey Bisson

unread,
Jun 26, 2009, 9:24:40 AM6/26/09
to scri...@googlegroups.com

The schema also needs to save some content for the full text index as
the record is being saved. I'll grab an example when I'm at my
computer next.

Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages