Connections-Business-Directory / Connections

Directory Plugin for WordPress
https://connections-pro.com
GNU General Public License v2.0
27 stars 18 forks source link

pull r #317

Closed quantumJLBass closed 10 years ago

quantumJLBass commented 10 years ago

the term query is set up to match the get_terms but increases it's capabilities to allow for multiple ORDER BY's as MySQL allows for. Meaning now orderby and order not only take strings but also take arrays. All possible combinations of the two properties are accounted for. In cases where illogical combinations were provided, it reacts in a way that doesn't fail out.

Tested combinations used in the EXPsearch plugin for $connections->retrieve->categories($args) _Note: it's only a sample of the test combinations _


    $args = array( 'orderby'=>array('parent','name'),
        'order'=>array('ASC','DESC')
    );

//=> 'SELECT t.*, tt.* from wp_connections_terms AS t INNER JOIN wp_connections_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  ORDER BY    parent ASC ,  name DESC' 

    $args = array( 'orderby'=>array('parent'),
        'order'=>array('ASC','DESC')
    );

//=> 'SELECT t.*, tt.* from wp_connections_terms AS t INNER JOIN wp_connections_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  ORDER BY    parent ASC' 

    $args = array( 'orderby'=>array('parent','name'),
        'order'=>array('ASC')
    );

//=> 'SELECT t.*, tt.* from wp_connections_terms AS t INNER JOIN wp_connections_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  ORDER BY    parent ASC ,  name ASC'

    $args = array( 'orderby'=>array('parent','name'),
        'order'=>'DESC'
    );

//=> 'SELECT t.*, tt.* from wp_connections_terms AS t INNER JOIN wp_connections_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  ORDER BY    parent DESC ,  name DESC' 

    $args = array( 'orderby'=>'parent',
        'order'=>array('ASC','DESC')
    );

//=> 'SELECT t.*, tt.* from wp_connections_terms AS t INNER JOIN wp_connections_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  ORDER BY    parent ASC' 
quantumJLBass commented 10 years ago

I'm still be hind so I'm working back to this project now that I'm a little less flu ridden. There is an example of cherry-picking commits to pull in here I believe this is the best way to get around conflicts, but maybe not

shazahm1 commented 10 years ago

I've thought about this a bit more...

How about instead of registering many different shortcode, only register a single shortcode named cn_template.

One would use it like so: [cn_template part=header att=one att=two and='so,on']Other content such as other shortcodes can be here.[/cn_template] [cn_template part=body att=one att=two and='so,on']As with the header, other content and shortcodes...[/cn_template] [cn_template]same, same...[cn_template part=footer att=one att=two and='so,on']

The callback for the cn_template shortcode would just be a switch which calls the correct function based on part. something like:

switch ($part) {
case 'header':
// something
break;
case 'body':
// something
break;
default:
// so random custom parts can be added and ran.
do_action('cn_template_part-' . $part);
break;
}

Looking at what you've done so far, it should be easy to switch.

This is the method I think I'm going to use for my entry shortcodes class.

Thoughts?

quantumJLBass commented 10 years ago

I thought about this, and aimed to avoid locking user out of being able to warp or alter the html of sections. I have come from MVC worlds and was trying to break it out that way. My mind is parted at the moment but I think I got were you are driving, and would imagine that would seem like an okay way.

One of the biggest troubles I had was that the display of things needed to be in a jQuery UI accordion but due to the hard coded html I had to alter core stuff, but when I tried to it consolidated shorcodes I found I was locked down but it seems maybe your way will not?

I figure the goal in one sense was to be able to have a text list (was thinking emails) so that you could end up with an output of

Name: Mr, Foo Bar
Company: Acme
Phone: etc.. down the list

So that it was empty of all html. The issue I then thought of is that there would need to be some way to condition... Well that is all of the thoughts behind the proof of concept, but to be honest, I'm still digging out of the work that backed up from being sick last week. I am hoping to jump back in both on this project and the site using it mid next week. I'll keep and eye out on things and get back though.

shazahm1 commented 10 years ago

Unless I'm just confused ... my suggestion is no different from using a bunch of shortcodes except your checking a single shortcode for an attribute before passing it on to the correct output method, whether that be some default HTML output or custom HTML or no HTML at all. A prototype I did while back using just a simple string replace instead of real shortcodes [which are far more flexible], I was creating "template"/completely change the output using the themes tabbing shortcode and its accordion shortcode and even its google map shortcode. I even combine all three in one test where each entry was an accordion item, within that was a tabbed section for notes and bio and the map.

Any way, maybe I am confused with what your done. My weekend plan is to pull this branch and play with it, same with your other plugin that you've added this to. I also plan on pumping the entry shortcode equivalent so within the card you could do something like this:

[cn_template part=card att=one att=two and='so,on']
Name: [cn_entry part=name]
Company: [cn_entry part=organization]
Work Phone: [cn_entry part=phone type=workphone]
[/cn_template]
quantumJLBass commented 10 years ago

I see what your saying. One note is that the thought on real shortcodes was that it'd process faster? I was going to do a test but I thought I remembered reading an article on this subject and there was a big diff in render time. I'll see if I can find that post again. But there was another thought that may be wise for larger sites (as an option) would be to let there be a cached rendered card that on edit for the card would delete it's output and could even rebuild it? Just a side thought I was having while I was doing the work.

It looks like I'm still on track for mid next week on when I pick back up. Hope your weekend is well.

shazahm1 commented 10 years ago

Oh, no, did I misstate ... I want to use real shortcode ... my prototype was just using string replacement for testing, that all.

I've thought about adding pre-processing and caching it, my first thought is page caching plugins, maybe best left to them. However, there are plenty of items I'd love to cache since I'm using custom tables and cant really take advantage of WP builtin db caching. Pods actually has a really great caching class I think I want to lift and adapt.

shazahm1 commented 10 years ago

Well ...

I started work on my entry shortcodes for #198 ... actually taking a path more similar to this than what I documented in the issue. Any way...

I definitely came across a "gotcha" with using a single shortcode. Take this example:

Name: [cn_entry part=name format='%last%, %first% %middle%']

Addresses:
[cn_entry part=addresses]
[cn_address]
Line One: %line_1%
Line Two: %line_2%
Line Three: %line_3%
City: %locality%
State: %region%
Zip: %postal-code%
Latitude: %latitude%
Longitude: %longitude%
[/cn_address]
[/cn_entry]

When I run this thru the filter, the address section is gone. The shortcode API is greedy in the sense that it'll look for the first closing, [/cn_entry], shortcode tag ignoring that fact there's another opening tag before the closing tag.

So, if I do the following instead, it works:

Name: [cn_entry part=name format='%last%, %first% %middle%'][/cn_entry]

Addresses:
[cn_entry part=addresses]
[cn_address]
Line One: %line_1%
Line Two: %line_2%
Line Three: %line_3%
City: %locality%
State: %region%
Zip: %postal-code%
Latitude: %latitude%
Longitude: %longitude%
[/cn_address]
[/cn_entry]

Also, if you have a shortcode within a shortcode of the same name with an end tag, the inner shortcode will not be run even if it properly closed.

Looks like separate shortcodes (prefixed) are going to be required...

Currently with my entry shortcodes I'm registering them just in time and the removing them ... so they can not be run out of context, meaning cn_addresses should exist or be processed if not within cn_entry.

Any way, mostly writing it here for my benefit as I think it thru ... maybe you'll find it useful, or not.

quantumJLBass commented 10 years ago

For sure I'm reading these. I still expect mid week is when I'll be getting back this way so I'll hold off on this section of things till you have what you believe is the "it" way here. I did read on the nested shortcodes about what you are talking about and I do believe there was a self closing option. I can't check back on that just yet but iirc you should be able to go [foo agr="bar" /] and [foo agr="bar" ] baz [/foo] .. it was in the codex somewhere I think but I'll have to check later.

shazahm1 commented 10 years ago

Yes, this does work:

Name: [cn_entry part=name format='%last%, %first% %middle%'/]

Addresses:
[cn_entry part=addresses]
[cn_address]
Line One: %line_1%
Line Two: %line_2%
Line Three: %line_3%
City: %locality%
State: %region%
Zip: %postal-code%
Latitude: %latitude%
Longitude: %longitude%
[/cn_address]
[/cn_entry]

Now, I ponder, is it too much to expect proper closing of the tags ... oh, decisions!

So, you see I opted for "tokens" for the address details rather than shortcodes. I almost think using real shortcodes for that would be overkill. I thought about just using brackets instead of the percent, to maintain style, but it feels safer because I "know" I'm going to run into some conflict with some other plugin that just happens to be using one of my tokens as their actual shortcode.

quantumJLBass commented 10 years ago

so just fyi, the project has had a hold for a week put on it, so I'll have to wait till next week to get back on things. Sorry for the delay here

shazahm1 commented 10 years ago

Thanks for the fyi ... I hadn't had much progress with the entry shortcodes. I had some site maintenance to do which led to having a to write a plugin to solve a problem.

shazahm1 commented 10 years ago

Found this... http://wordpress.org/plugins/wp-conditional-shortcodes/

Could be very interesting to have similar functionality with the template shortcode.

quantumJLBass commented 10 years ago

for sure, I think that kinda logic should be integrated give the scope, nice find

shazahm1 commented 10 years ago

I just push the first pass at the entry shortcode ... running the following thru a filter seems to work quite well.

Name: [cn_entry part=name format='%last%, %first% %middle%'/]
Title: [cn_entry part=title/]
Department: [cn_entry part=department/]
Organization: [cn_entry part=organization/]
Contact: [cn_entry part=contact/]

[cn_entry part=addresses]
[cn_address]
  %type% Address:
    Line One: %line_1%
    Line Two: %line_2%
    Line Three: %line_3%
    City: %locality%
    State: %region%
    Zip: %postal-code%
    Latitude: %latitude%
    Longitude: %longitude%
[/cn_address]
[/cn_entry]

[cn_entry part=phone_numbers]
[cn_phone]
  %type% Phone:
    Number: %number%
[/cn_phone]
[/cn_entry]

[cn_entry part=im]
[cn_im]
  %type%:
    User ID: %id%
[/cn_im]
[/cn_entry]

[cn_entry part=social_networks]
[cn_social_network]
  %type%: %url%
[/cn_social_network]
[/cn_entry]

[cn_entry part=links]
[cn_link]
  <a href="%url%" title="%title%">%title%</>
[/cn_link]
[/cn_entry]

[cn_entry part=dates]
[cn_date]
  %type%: %date%
[/cn_date]
[/cn_entry]

[cn_entry part=bio/]

[cn_entry part=notes/]
quantumJLBass commented 10 years ago

that will surely provide very nice templates for email.. I was thinking that you could expand the templates for sale to be for emails now as well.. just a thought

shazahm1 commented 10 years ago

Yep, absolutely. Matter of fact, that is exactly what I had in mind and how I'm testing this. I have an add-on that can send email based on several definable events. There's already an email template api which email templates can be registered.

Using it is really simply and to apply the template you just set the template to be used before you send the email. This adds a filter to the message body which applies the template. Pretty nifty, I think.

shazahm1 commented 10 years ago

fyi, I actually started to work on this b/c it fits in with #218. I just started to lay the (initial ground work)[440718e1ef1f23951eff54800a4124c483c35669], grabbing what I can from this pull request.

I am approaching it from a different angle though. I decided to have a generic shortcode class to contain common shortcode functions. And each core shortcode will have its own static class. Also, I decided to implement the new code structure as a new shortcode tag so can easily test using the old shortcode tag as a control. That way, when I'm finish I can simply remove the old code and change the tag on the new code to the old tag and be done.

I think this in combination with #218 with strategically placed actions and filters will provide enough flexibility to shape the output any way one could want.

quantumJLBass commented 10 years ago

I got you, well I'm barely starting back up on this project so I'll keep an eye out.

quantumJLBass commented 10 years ago

well 20 days later, lol, I'm starting back up on the held project. I'll start moving through all of this and get back

shazahm1 commented 10 years ago

only two months later and I this is moving forward. Thanks for your time on this!