pancakes

MicrostockGroup Sponsors


Author Topic: Symbiostock Genetics Lab - A Rapid Code Implementer For Special Requests  (Read 4218 times)

0 Members and 1 Guest are viewing this topic.

Leo Blanchette

« on: July 03, 2013, 03:15 »
0
Instead of generating a special plugin for every possible scenario and request, I've created a special plugin which allows Symbiostock to quickly assimilate (or infuse) code snippets for fast upgrades and improvements. In some cases it can even be used for temporary patching and bug fixes!

[SEE PLUGIN HERE]

Example: I've recently received a request to allow search results to show more images per page.

In just a short amount of time  I was able to create the code snippet to make this possible:
http://www.symbiostock.com/change-posts-per-page-symbiostock-genetics-lab-snippet/

I'm using this snippet, and search results on my site display 96 per page:
 http://www.clipartillustration.com/?s=cute&submit=Search&post_type=image


Using the Symbiostock Genetics Lab (endearingly named because I just love biology references :D ) we can plug this snippet in real quick and get the desired effect.

Now arguably I could put this into a theme upgrade, and perhaps in time I will, but its much much easier for me to just hand out the codez :D . Then when I get to it I can implement it to the theme. Not every request or upgrade should be sold as a plugin either...that will just get messy.

But in many cases people will have unique needs, so I can quickly develop fast solutions for them (paid or not) and they can take the code and implement it. I can post these snippets online for others who wish to benefit.



I hope to build a little "infusions" library which are implemented this way - fetched online and easily plugged in.

This will be very helpful in speeding Symbiostock progress as the other developers may enjoy using this interface for testing as well.

You may wonder if this will cause more issues.

If you have command line access (quite likely you do) this plugin validates code before its written. If its broken, it will refuse to write it. The only other chances for crashes is if the code is badly written - so implement wisely. The snippets I provide will generally be well tested and safe. Same with AJT and no doubt PLRANG who use PHP.

Generally the more elaborate features will come as plugins, which are pretty and multi-featured. But small modifications will most always be handed out through the Genetics Lab plugin.

This was quite fun to make!




CHANGE POSTS PER PAGE IN SEARCH RESULTS

http://www.symbiostock.com/change-posts-per-page-symbiostock-genetics-lab-snippet/

Code: [Select]
<?php
function gl_setposts_infusion(){
function gl_mod_search$query ) {
global $network_search;
//$network_search = get_query_var('symbiostock_network_search');
if($network_search != true && !is_admin()){
$per_page get_option('gl_posts_per_page'24);
$query->set('posts_per_page'$per_page);
return;
}
}
add_action'pre_get_posts''gl_mod_search'10);
}
add_action'after_setup_theme''gl_setposts_infusion' );

function 
gl_set_post_results(){
wp_verify_nonce('gl_setposts_action');
if(isset($_POST['gl_set_post_results'])){
if(is_numeric($_POST['gl_set_post_results']))
update_option('gl_posts_per_page'trim($_POST['gl_set_post_results']));
}
?>

<form method="post" action="">
    <?php wp_nonce_field('gl_setposts_action'); ?>
        <label for="gl_set_post_results">Set number of search results per page:
            <input id="gl_set_post_results" name="gl_set_post_results" type="text" value="<?php echo get_option('gl_posts_per_page'24); ?>" />
        </label>
        <input name="set_results" class="button" type="submit" value="SET" />
</form>
<?php
}
add_action'gl_custom_actions_after''gl_set_post_results' );
?>



SPLIT COMPOUND KEYWORDS FOR PRESENT SEARCH SYSTEM

http://www.symbiostock.com/split-compound-keywords-into-individual-ones-temporary-search-aid/

(Saves backup keywords so you can revert when new database is implemented)
The "Split" command shows up right under the Genetics Lab panel.
Code: [Select]
<?php
//this script splits compound keywords into individual ones, 
//allowing our present (limited) search engine to find keyword combinations better.
//it also saves a backup in post meta, so you can revert when you upgrade later.
function gl_run_split_keywords( )
{
    
$args       = array(
         
'post_type' => 'image',
        
'post_status' => 'publish',
        
'posts_per_page' => -1,
        
'caller_get_posts' => 1,
        
'fields' => 'ids' 
    
);
    
$image_list null;
    
$image_list = new WP_Query$args );
    if ( 
$image_list->have_posts() ) {
        
$image_meta = array( );
        while ( 
$image_list->have_posts() ):
            
$image_list->the_post();
            
$id    get_the_ID();
            
$terms get_the_terms$id'image-tags' );
            
update_post_meta$id'symbiostock_terms_backup'$terms );
            if ( 
$terms && !is_wp_error$terms ) ):
                
$keywords = array( );
            
//first populate the original kewywords
                
foreach ( $terms as $term ) {
                    
array_push$keywords$term->name );
                }
                
//then split them and add the split versions
                
foreach ( $terms as $term ) {
                    
$split preg_split'/[+\s_-]/'$term->name );
                    if ( 
is_array$split ) ) {
                        foreach ( 
$split as $word ) {
                            
array_push$keywords$word );
                        }
                    }
                }
                
$corrected_keywords            array_unique$keywords );
                
$keyword_update'tax_input' ] = array(
                     
'image-tags' => $corrected_keywords 
                
);
                
wp_update_post$keyword_update );
            endif;
        endwhile;
    } 
//$image_list->have_posts()
}
function 
gl_split_keywords( )
{
    if ( isset( 
$_POST'gl_split_keywords' ] ) ) {
        
gl_run_split_keywords();
    }
?>

    <p>The keyword splitter takes compound keywords and splits them into separate ones. Symbiostock uses Wordpress's database, which is not always flexibile. This is a temporary fix until the premium plugin is available, which will use its own specialized database for searches.</p>
<form method="post" action="">
        <label for="gl_split_keywords">Split keywords? 
        <input id="gl_split_keywords" name="gl_split_keywords" class="button" type="submit" value="SPLIT" />
        </label>
</form>
    <hr />
<?php
}
add_action'gl_custom_actions_after''gl_split_keywords' );
?>

« Last Edit: July 05, 2013, 04:36 by Leo »


Leo Blanchette

« Reply #1 on: July 03, 2013, 03:43 »
0
...
« Last Edit: July 05, 2013, 04:36 by Leo »

« Reply #2 on: July 03, 2013, 03:54 »
0

I'm using this snippet, and search results on my site display 96 per page:
 http://www.clipartillustration.com/?s=cute&submit=Search&post_type=image



Nice, but now network results still have 24/page, so Google will claim many non existing pages, when searching for links taken from pagination. Maybe add to pagination links actual number per page or other value, to inform site that this links are from network results and should be somehow reworked to show something valid.

Leo Blanchette

« Reply #3 on: July 03, 2013, 04:05 »
0

I'm using this snippet, and search results on my site display 96 per page:
 http://www.clipartillustration.com/?s=cute&submit=Search&post_type=image



Nice, but now network results still have 24/page, so Google will claim many non existing pages, when searching for links taken from pagination. Maybe add to pagination links actual number per page or other value, to inform site that this links are from network results and should be somehow reworked to show something valid.

Are you sure about that? It should only modify your locally displayed results, not the outgoing ones.

This part here makes sure of that

Code: [Select]
$network_search = get_query_var('symbiostock_network_search');
if($network_search != true && !is_admin()){
$per_page = get_option('gl_posts_per_page', 24);
$query->set('posts_per_page', $per_page);
return;
}

Ron

« Reply #4 on: July 03, 2013, 04:12 »
0
Thanks Leo, I will check that out tonight.

« Reply #5 on: July 03, 2013, 04:15 »
0
Are you sure about that? It should only modify your locally displayed results, not the outgoing ones.


Yes, that's because it modifies only local results.
Here is link taken from pagination, after searching in my site for "orange people":
www.clipartillustration.com/?s=orange+people&submit=Search&post_type=image&cr=79.191.39.179&page=5

There is no "page not found" message now (so there will be no Google errors I hope), but your site shows "No results found on this site.", because it now hasn't page 5.

These pagination links are followed only by bots, so maybe let it stay as is? Does it affect SEO somehow?
« Last Edit: July 03, 2013, 04:22 by ajt »

Leo Blanchette

« Reply #6 on: July 03, 2013, 04:39 »
0
Thats odd. Yes, small problem but still significant. I'll see what I can do to improve that.

Ron

« Reply #7 on: July 04, 2013, 15:32 »
0
Is this code ready for use? If so, I will purchase the plugin. Thanks.

« Reply #8 on: July 04, 2013, 15:53 »
0
Is this code ready for use? If so, I will purchase the plugin. Thanks.

Yes, it works fine: obtain and install the plugin, paste the code and define# of images to display upon search - bingo. In my case I set it to 96 now.

Leo Blanchette

« Reply #9 on: July 04, 2013, 16:04 »
0
Is this code ready for use? If so, I will purchase the plugin. Thanks.
Yep! I'm working out one minor bug in that posted code that does not relate very much to the customer experience, but it works great.

Half the point of the "genetics lab" is to test code before implementing it. I'll be submitting an updated version soon.

Ron

« Reply #10 on: July 04, 2013, 16:07 »
0
Ok, as soon as the new code is published, I will purchase the plugin. Thanks Leo !

« Reply #11 on: July 04, 2013, 16:08 »
0
Is this the kind of thing that would allow me to access imagick on my godaddy hosting?

Leo Blanchette

« Reply #12 on: July 04, 2013, 16:11 »
0
I had you in mind as well when I made it. It can do anything really. For your case i'd end up extending the image processor class. In the end though your situation will end up as a plugin once its perfected.

« Reply #13 on: July 04, 2013, 16:21 »
0
Sound great Leo!  Can I make this work now (with code you provide) until the dedicated plugin is available?

Leo Blanchette

« Reply #14 on: July 04, 2013, 16:25 »
0
Sound great Leo!  Can I make this work now (with code you provide) until the dedicated plugin is available?
With your case (hopefully soon) I'm going to write you some code which overwrites the image processor to use command line. If it works, then I'll be producing a plugin. The code above just makes more images per page

« Reply #15 on: July 04, 2013, 16:30 »
0
You're the man!  How do you figure out all this stuff?

Leo Blanchette

« Reply #16 on: July 04, 2013, 16:34 »
+1
HUGE days of working on this project. Believe me, I want to take a break.

« Reply #17 on: July 04, 2013, 16:46 »
0
Yeah, I know you do and nobody deserves it more than you.  Speaking for myself, the reason I'm so impatient about all this is because I'm massively excited about it!  After many years as a full time stock photographer/videographer and all the cr*p that's run down the hill from above lately it feels good to be excited about something.  Thank you for that!

Leo Blanchette

« Reply #18 on: July 04, 2013, 21:22 »
0
I've just modified the above code. its PERFECT now. No side effects. I think our genetic enhancements should find its way into coming releases? :D

Code: [Select]
<?php
function gl_setposts_infusion(){
function gl_mod_search$query ) {
global $network_search;
//$network_search = get_query_var('symbiostock_network_search');
if($network_search != true && !is_admin()){
$per_page get_option('gl_posts_per_page'24);
$query->set('posts_per_page'$per_page);
return;
}
}
add_action'pre_get_posts''gl_mod_search'10);
}
add_action'after_setup_theme''gl_setposts_infusion' );

function 
gl_set_post_results(){
wp_verify_nonce('gl_setposts_action');
if(isset($_POST['gl_set_post_results'])){
if(is_numeric($_POST['gl_set_post_results']))
update_option('gl_posts_per_page'trim($_POST['gl_set_post_results']));
}
?>

<form method="post" action="">
    <?php wp_nonce_field('gl_setposts_action'); ?>
        <label for="gl_set_post_results">Set number of search results per page:
            <input id="gl_set_post_results" name="gl_set_post_results" type="text" value="<?php echo get_option('gl_posts_per_page'24); ?>" />
        </label>
        <input name="set_results" class="button" type="submit" value="SET" />
</form>
<?php
}
add_action'gl_custom_actions_after''gl_set_post_results' );
?>

Ron

« Reply #19 on: July 05, 2013, 02:44 »
0
Purchased the plugin, will let you know the results  8)

Ron

« Reply #20 on: July 05, 2013, 03:00 »
0
LOVE IT Looks so much better now !!! Thanks Leo !

Leo Blanchette

« Reply #21 on: July 05, 2013, 03:03 »
0
This little genetics lab is a fun toy. Its a great little place to test out features before implementing them.

Leo Blanchette

« Reply #22 on: July 05, 2013, 03:59 »
0
« Last Edit: July 05, 2013, 04:08 by Leo »

Ron

« Reply #23 on: July 05, 2013, 04:10 »
0
There you go! Its right under the original post.

here as well:
http://www.symbiostock.com/split-compound-keywords-into-individual-ones-temporary-search-aid/


Whuahahahahaaaaa its working  ;) Thanks a lot for that.


 

Related Topics

  Subject / Started by Replies Last post
8 Replies
4003 Views
Last post May 15, 2008, 13:46
by fotografer
3 Replies
4513 Views
Last post February 23, 2009, 21:42
by davey_rocket
1 Replies
4513 Views
Last post June 23, 2009, 23:29
by jorgeinthewater
150 Replies
20309 Views
Last post January 26, 2012, 05:29
by nicku
66 Replies
22383 Views
Last post August 14, 2013, 05:35
by tina

Sponsors

Mega Bundle of 5,900+ Professional Lightroom Presets

Microstock Poll Results

Sponsors

3100 Posing Cards Bundle