WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Schema Data Support (34 posts)

  1. James W. Lane
    Member
    Posted 5 months ago #

    I guess this is really a two part question.
    Does TablePress have some way to support Schema data?
    Or where would I hook / filter the Markups output to adjust and add the correct itemtype and itemprop to the correct tags. Love the plugin :)

    James

    Below is a example of what I am looking for.

    <table class="zebra-striped">
      <tbody>
        <tr>
            <th class="rank">
                Rank
            </th>
            <th class="school">
                School
            </th>
            <th class="faculty">
                Full-time to Part-time Faculty
            </th>
            <th class="financial-aid">
                Financial Aid Rate
            </th>
            <th class="acceptance">
                Acceptance Rate
            </th>
            <th class="retention">
                Retention Rate
            </th>
            <th class="graduation">
                Graduation Rate
            </th>
            <th class="accredited">
                Years Accredited
            </th>
            <th class="default">
                Default Rate
            </th>
            <th class="jobs">
                Job Placement Rate
            </th>
        </tr>
        <tr itemscope itemtype="http://schema.org/CollegeOrUniversity">
            <td class="rank" itemprop="aggregateRating">
                1
            </td>
            <td class="school" itemprop="name">
                <a rel="nofollow" itemprop="url" href="http://www.tamu.edu">Texas A & M University</a>
            </td>
            <td class="faculty">
                22.71 to 1
            </td>
            <td class="financial-aid">
                52%
            </td>
            <td class="acceptance">
                63%
            </td>
            <td class="retention">
                92%
            </td>
            <td class="graduation">
                81%
            </td>
            <td class="accredited">
                88
            </td>
            <td class="default">
                5%
            </td>
            <td class="jobs">
                NA
            </td>
        </tr>
       </tbody>
    </table>

    https://wordpress.org/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    thanks for your question, and sorry for the trouble.

    No, sorry, TablePress does not yet have support for Schema data (mainly, because there's no way to really enter it, at this time).

    Your best chance would probably be to add this via the filters in the class-render.php file, like tablepress_cell_css_class and similar.

    Regards,
    Tobias

  3. James W. Lane
    Member
    Posted 5 months ago #

    Thanks Tobias,
    I have some idea's on how to handle this if I come up with a working plugin I will let you know.

    James

  4. James W. Lane
    Member
    Posted 5 months ago #

    Is there a easy way to hook into the edit table page and add my own meta box? Also if there is a extension that would be good to look at for a reference that would be awesome.

    Thanks a ton
    James

  5. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    you could take a look at the Table Auto Update Extension from http://tablepress.org/extensions/table-auto-import/
    That adds a meta box to the "Import" screen, by inheriting/extending from the original import view.

    Regards,
    Tobias

  6. James W. Lane
    Member
    Posted 5 months ago #

    Awesome, I will look at that. I was thinking accomplishing this by two ways visually.

    By adding a tab to the options menu called "Schema Data" or adding a meta box to the actual edit screen for the table called "Schema Data".

    I am thinking to the actual edit screen would be more useful.

    Then I would figure out how many columns there are and create a text field for each column plus one "for the tr".

    The first field will handle the itemtype url:

    <tr itemscope itemtype="http://schema.org/CollegeOrUniversity">

    Then for each cell the text field would handle the itemprop:

    <td class="school" itemprop="name">

    I am thinking this would be the easiest visually to handle the front end information.

    The I will just have to add a filter and add the information in those fields into the TR tag and TD tags of table.

  7. James W. Lane
    Member
    Posted 5 months ago #

    Tobias
    I have started on this project TablePress Extension: Schema Data. I am hoping to have it finished by the end of the week. I would take any advise you have to give on anything regarding the project. After spending a few hours looking through TablePress and your extensions they are built rock solid and with a very high quality of coding standards. I am hoping that I can produce a extension that meets the same high standard of coding.

    James

  8. James W. Lane
    Member
    Posted 5 months ago #

    Tobias,
    I am getting stuck on how to hook into the save function ( handle_post_action_edit ) and save the Schema Data preferably as a array to the tables options array. I could use your advice on this if you have a second.

    Thanks for everything
    James

  9. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi James,

    great to see that you are making quick progress!

    Now, saving the data is indeed tricky, and I should probably have thought about this earlier...
    The problem is that the JavaScript/AJAX saving mechanism that TablePress uses, does not "collect" the data from the input fields that you added, and unfortunately, it can't really be extended to do that. (You'd need to make changes to the edit.js file, but that's not update-proof then, at all.) Then, you'd also need changes in the the default table scheme and in the data validation/sanitization functions...

    It might therefore actually be the best to "abuse" some table data.
    For example, you could designate the first row of input fields as the Schema data. With that, you'd only have to make changes to the rendering functions (i.e. extract that data and add it to the table HTML as the new HTML markup, instead of having it printed as regular table cells).
    With that approach, you'd get the input fields and the saving automatically, with the drawback that you would not have correct "labels" or naming on the Edit screen for this data.

    Another idea might be to add the data via the Shortcode. You could for example define a new Shortcode parameter which has the Schema data as |-separated string, like

    [table id=123 schema_data="school|name|id" /]

    Regards,
    Tobias

  10. James W. Lane
    Member
    Posted 5 months ago #

    Tobias,
    I have most the code written "in a rough state"
    I now have my fields $_POST ( https://www.dropbox.com/s/ihprw7gwn7jtrb1/Screenshot%202014-03-13%2016.52.51.png )
    But I am truly not a expert with form data I tend to avoid forms. So I need to grab the data and save it. Once I have that completed. And I can pull the data from the database I just have to finish my filter by digging more into tablepress_cell_css_class and how it builds items. I been pushing all my changes to GitHub, even tho I am becoming pretty filmiure that last two days of TablePress. If you see a better way of doing something I will take your advice on it.

    I would like to make the plugin available on TablePress so editing the JS is out. I also don't feel comfortable messing with the table data incase something goes wrong I don't want to risk people losing their tables. Since I am getting the Data to post now I just need to grab it and save it "Somewhere". Once I have that figured out, I just need to finish the filter and this should be ready to test "crosses finger"

    James

  11. James W. Lane
    Member
    Posted 5 months ago #

    Tobias,
    I have the plugin now saving and recalling the needed data properly, Now I just need to get a better handle on how to filter the tablepress_cell_css_class function to get the result we want. I could use any insight on this cause is seems to be a very complicated mesh of code. I am hoping to have a rough working version by the end of Friday so I can clean it up and test all weekend. Thanks again for all your help.

    James

  12. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi James,

    I haven't yet had chance to take a more detailed look at your code, but I'm very interested in seeing how you now save the data, and actually how you submit the form without making changes to the JS. Back in my head, I have feeling that this might not be possible without risking to lose modifications to the table data that were not yet saved (i.e. the case where a user edits the table and the Schema data at the same time, but then uses the submit method that you added), but we'll see.

    I saw that you submitted a pull request for new filters for the HTML output. After taking a look at that, I can see that those will indeed be necessary. The existing tablepress_cell_css_class filters (and related) are indeed not sufficient here.
    I'll be waiting for you to complete that PR then and then gladly add those filters!

    Best wishes,
    Tobias

  13. James W. Lane
    Member
    Posted 5 months ago #

    Well I have the rough code completed and working.

    https://www.dropbox.com/s/6ld62sde0zwj26n/Screenshot%202014-03-14%2015.30.47.png

    I am just hung up on one item, I am moving the code to its own render class to extend class-render.php and TablePress_Render with my own render class. I just can't seem to find the best way to Initialized my class with yours. Without hooking into three separate functions where they are calling it. Any suggestions what would be the best way to extend TablePress_Render?

    James

  14. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi James,

    I guess the simplest approach would be to hook into tablepress_render_data which gets the entire table array as a parameter. From that, you can extract the $table['id'] and use that to load the Schema data (from wherever you have stored it), and then append that to the $table array, e.g. as $table['schema-data'].
    As the filters for the actual rendering (those that we still have to add) will also get the entire $table array, they would again have access to the Schema data and can generate the HTML.
    With that, you wouldn't have to create a child class of the render class, but use plain filter hooks.

    Regards,
    Tobias

  15. James W. Lane
    Member
    Posted 5 months ago #

    I like simple :) I will try that out.

  16. James W. Lane
    Member
    Posted 5 months ago #

    Where is tablepress_render_data defined or located. I can't seem to find it defined in the TablePress plugin?

  17. James W. Lane
    Member
    Posted 5 months ago #

    Are you talking about tablepress_table_render_data?

  18. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    ah, yes, my bad. tablepress_table_render_data is what I meant.

    Regards,
    Tobias

  19. James W. Lane
    Member
    Posted 5 months ago #

    I have it pulling all the data properly, I just need to go in and clean up my code. Maybe make it a little more DRY.

  20. James W. Lane
    Member
    Posted 5 months ago #

  21. James W. Lane
    Member
    Posted 5 months ago #

    Well I ran into a issue, Its working properly on the backend when you hit the preview. But it doesn't seem to be working on the front end. Any idea on what may cause that?

  22. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    great! I'll probably have time to take a look tonight.

    For the issue on the frontend: It might be possible that you are running into caching issues. Please try extending the Shortcode on the page to

    [table id=123 cache_table_output=false /]

    Regards,
    Tobias

  23. James W. Lane
    Member
    Posted 5 months ago #

    Tried that and it's still not showing up on the front end, but it is working on the editors preview menu.

  24. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    did you make this change in the "Text" editor or in the "Visual" editor?
    The table output caching is the only thing that I can really think of here...
    Or are you maybe using some other caching?

    Regards,
    Tobias

  25. James W. Lane
    Member
    Posted 5 months ago #

    Text editor and its local so it shouldn't be running any caching "varnish" but to be safe I flushed it.

  26. James W. Lane
    Member
    Posted 5 months ago #

    Do you use Skype, ScreenHero or Email? Maybe easier to debug, also have a few other questions that would be out of context of this thread.

  27. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    ok, I just had a very brief look at the code in your pull request. The apply_filters calls are not passing any arguments, thus your filter handlers don't get any data.
    At the moment, you shouldn't even see Schema data when using the Preview mode, I'm pretty sure.

    And yes, the email address that you found is correct :-) If it's about TablePress (and can be discussed publicly), I'd like to keep it here in the forums, if you don't mind. Otherwise, feel free to email me, of course.

    Regards,
    Tobias

  28. James W. Lane
    Member
    Posted 5 months ago #

    You may want to double check because they have the following

    $other_attr = apply_filters('tag_custom_attr', '', $this->table, $this->table['id'], $cell_content, $row_idx + 1, $col_idx + 1, $this->colspan[ $row_idx ], $this->rowspan[ $col_idx ] );

    and

    $tr_attr = apply_filters( 'tr_custom_attr', '', $this->table, $this->table['id'], $row_idx + 1, $this->table['data'][ $row_idx ] );

  29. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    ah, my bad. I hadn't noticed the second commit in the pull request that passes the data. Sorry.

    Now, I think I found another possible reason:
    You are basically only running the Extension in the admin area: https://github.com/jameswlane/TablePress-Extension-Schema-Data/blob/master/tablepress-schema-data.php#L93
    That's why your filters are not registered on the frontend.

    Regards,
    Tobias

  30. James W. Lane
    Member
    Posted 5 months ago #

    Doh /facepalm Let me fix that

Reply »

You must log in to post.

About this Plugin

About this Topic