Support » Plugin: JaJaDi Kerktijden » Added feature jajadi-kerktijden

  • ResolvedPlugin Author henrivanwerkhoven

    (@henrivanwerkhoven)


    Nice plugin, thanks for sharing!

    I’ve made some modifications in the shortcode function to allow display of a limited number of services in a narrow list. In our case we use this on the home page with a link to the full list of services (see http://zeist.cgk.nl). By default, if no arguments are given, the function returns the same as the original one.

    You may want to add this to the next release, so I thought I’d post the new function here. Please let me know if you have any questions or concerns.

    ## jajadi-kerktijden-functions.php line 12
    function jajadi_kerktijden_shortcode($atts){
    	// default attributes
    	$atts = shortcode_atts( array(
    		'limit' => NULL, /* number of items to show, NULL to show all */
    		'narrow' => FALSE, /* set to TRUE to display in narrow style (i.e. pastor on second line) */
     		'future_only' => FALSE, /* set to TRUE to show only future sermons */
    		'url' => NULL, /* url to page containing all sermons, NULL to omit url */
    		'url_name' => 'more sermons' /* name for urlto page containing all sermons */
    	), $atts);
    	// original code
    	$return				= '';
    	$kerktijdensite		= 'http://www.kerktijden.nl/?zoek=toonkerktijden&kerkid=' . get_option( 'jajadikerkid' );
    	$ch					= curl_init ($kerktijdensite);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	$page				= curl_exec($ch);
    
    	preg_match('#<table id="zoekresultaten"[^>]*>(.+?)</table>#is', $page, $matches);
    	foreach ($matches as &$match) {
    		$match = $match;
    	}
    	if(!is_null($atts['limit']) || $atts['future_only']){
    		/* added functionality:
    		 *   optionally limit number of sermons displayed
    		 *   optionally only show future sermons
    		 *   optionally display in narrow layout (pastor on second line) [requires limit or future_only to be set]
    		 *   optionally add a link to all sermons [requires limit or future_only to be set]
    		 */
    		$table = '';
    		$lines = preg_split('#</tr>#is', $matches[1]);
    		$c = 0;
    		for($i=1; $i<count($lines); $i++){
    			if($atts['future_only'] && preg_match('#style="color: gray;"#is',$lines[$i])) continue;
    			if($atts['narrow']){
    				preg_match_all('#<td[^>]*>(.*?)</td>#is',$lines[$i], $cellmatches);
    				$cells = $cellmatches[1];
    				$table .= '<tr class="list_tr"><td class="td_left">'. str_replace(" uur","",$cells[0]) . (empty($cells[2]) ? '' : ' ('.$cells[2].')') . '<br/><em>' . $cells[1] . '</em></td></tr>';
    			}
    			else{
    				$table .= $lines[$i] . '</tr>';
    			}
    			$c ++;
    			if(!is_null($atts['limit']) && $c == $atts['limit']) break;
    		}
    		$table .= '<tr><td' . ($atts['narrow'] ? '' : ' colspan="3"') . '>';
    		if(!is_null($atts['url'])){
    			$table .= '<a href="' . htmlspecialchars($atts['url']) . '" style="float:right;">' . htmlspecialchars($atts['url_name']) . '</a>';
    		}
    		$table .= '<small>' . __('Source:', 'jajadi-kerktijden') . ' <a href="http://www.kerktijden.nl/">kerktijden.nl</a></small></td></tr>';
    		return '<table style="border:none;">' . $table . '</table>';
    	}
    	$return	.= '<table class="jajadikerktijden">';
    	$return	.= $matches[1];
    	$return	.= '</table><br /><small>' . __('Source:', 'jajadi-kerktijden') . ' <a href="http://www.kerktijden.nl/">kerktijden.nl</a></small>';
    	return $return;
    }

    https://wordpress.org/plugins/jajadi-kerktijden/

Viewing 1 replies (of 1 total)
  • Plugin Author DoubelJ

    (@doubelj)

    Thanks for your modifications. I’ve updated the plugin with it. I’ve also made you a contributor, so you can update the plugin by yourself if you like.

Viewing 1 replies (of 1 total)
  • The topic ‘Added feature jajadi-kerktijden’ is closed to new replies.