0

I am using an api from a third party developer that I can get to work outside of EE with a simple PHP include, but I can't seem to get it to work within a template.

You will see that this page (outside of EE) works and lists the events: http://discoverycolorado.dreamhosters.com/public_calendar_listing/

Here is the page where it is not working: http://discoverycolorado.dreamhosters.com/events

I don't think this is an API, I think it may be an EE issue or something I am not doing correctly with the PHP include. I was wondering if someone might have an idea why this might not be working?

Here is the include on the page I am trying to get this events list to show:

<?php 
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/public_calendar_listing/event_search_list.php";
                           include_once($path);
                        ?>

Here is the file I am including on the above page:

<?php $count = 0; ?>

   <table>
        <tbody>

<?php foreach ( $events as $event ) {

    // If there was a search, and nothing matched, return nothing
    if ($q && $event['search'] == '0') {
        } else {

    // Bring the recurring event dates back in to merge
    if (is_array($dup_events)) {    
        foreach ($dup_events as $dup_event) {
            if ($event['id'] == $dup_event['id']) {
                if ($event['date'] !== $dup_event['date']) {
                    $event['end_date'] = $dup_event['date'];
                    }
                }
            }
        }

    ########################################
    #### Format the time and datestamps ####
    ########################################
    $start_stamp = strtotime($event['start_time']);
    $end_stamp = strtotime($event['end_time']);
    $date_stamp = strtotime($event['date']);
    if ($event['end_date']) $end_date_stamp = strtotime($event['end_date']);

    if (date('i', $start_stamp) !== '00' ) {
        $event['start_time'] = date($config['timeformat'], $start_stamp);
        } else {
            $event['start_time'] = date($config['timeformat_simplified'], $start_stamp);
            }      

    if (date('i', $end_stamp) !== '00' ) {
        $event['end_time'] = date($config['timeformat'], $end_stamp);
        } else {
            $event['end_time'] = date($config['timeformat_simplified'], $end_stamp);
            }   

    if ($event['end_date']) {
        if (date('F', $end_date_stamp) == date('F', $date_stamp)) {
            $event['end_date'] = date($config['dateformat_simplified'], $end_date_stamp);
        } else $event['end_date'] = date($config['dateformat'], $end_date_stamp);
        $event['date'] = date($config['dateformat'], $date_stamp);
    } else $event['date'] = date($config['dateformat_single'], $date_stamp);
    $event['occur'] = date('Ymd', $date_stamp);

    ?>  

           <tr><td>
           <?php if ($config['display_ccblink']) { ?>
                <a href="https://<?php echo $config['url'] . '/event_detail.php?event_id=' . $event['id'] . '&occur=' . $event['occur']; ?>" target="_blank">
                <strong><?php echo $event['name']; ?></strong></a>
            <?php } else { ?>
                <strong><?php echo $event['name']; ?></strong>
            <?php } ?>  
           </td></tr>

           <tr><td>Date: <?php echo $event['date'];
                    if ($event['end_date']) {
                        echo ' - ' . $event['end_date']; 
                    } ?></td></tr>
            <?php if ( $event['start_time'] !== '12' ) { ?>
                    <tr><td>Time: <?php echo $event['start_time'] . ' - ' . $event['end_time']; ?>
                <?php if ( $event['location'] ) { ?>
                        <?php echo ' (' . $event['location'] . ')'; ?></td></tr>
                <?php } ?>      
            <?php } else { ?>   
                    <tr><td>Time: <?php echo $event['start_time']; ?>
                <?php if ( $event['location'] ) { ?>    
                        <?php echo ' (' . $event['location'] . ')'; ?></td></tr>    
                <?php } ?>  

            <?php } ?>

            <?php if ( $event['description'] ) { ?>
            <tr><td style="white-space:pre-wrap;">Description: <?php echo $event['description']; ?></td></tr>
            <?php } ?>

            <?php if ($config['display_contact']) { ?>
            <tr><td>Contact: <a onclick="javascript:window.open('https://<?php echo $config['url']; ?>/app/easy_email.php?ax=create_new&individual_id=<?php echo $event['leader_id']; ?>&event_id=<?php echo $event['id']; ?>&individual_full_name=<?php echo $event['leader']; ?>','Email','scrollbars=1,width=520,height=710');return false;" href="javascript:void();" ><?php echo $event['leader']; ?></a> <?php echo $event['leader_phone']; ?></td></tr>
            <?php } ?>


        <?php // 2014/02/14 mjf include group name ?>
        <?php if ($event['group_name']) { ?>
                    <tr><td><i><?php echo $event['group_name'] ?></i></td></tr>
        <?php } ?>

            <tr><td>&nbsp;</td></tr>    

    <?php $count++;
        }
    } // end foreach $event ?>

    </tbody>
</table>

<?php if ($count == 0) { ?>
        <p> No results found. </p>     
<?php }     
?>

Here is config file for the api:

  ##################################################
  #### CCB PUBLIC CALENDAR IN LIST FORMAT       ####
  #### Configuration Options                    ####
  ####                                          ####
  #### This CCB API example provided by:        ####
  #### Philip Cain <[email protected]> ####
  ##################################################

  $config = array (



  #### CCB API CONFIG ####

  // Your church's CCB address (no "http://" or trailing "/")
  'url' => 'xxxxxxxx',

  // API username and password. You can create one by following the instructions here:
  // https://churchcommunity.fogbugz.com/default.asp?W490
  //
  // Make sure you enable the "public_calendar_listing" service
 'username' => 'xxxxxxxx',
 'password' => 'xxxxxxx',

  #### OPTIONS ####

  // Create a link to the event in CCB
  'display_ccblink' => true,

  // Display event contact information
  'display_contact' => true,

  // Display recurring or multi-day events as a single event?
  'combine_recurring' => true,

  // Set the range for how far into the future you'd like to look
  'range' => '+3 months',

  // 2014/02/14 mjf specify groups to include in calendar
  // group names must match ccb group names exactly
  // to provide no filtering, use:
  //    'groups' => array(),
  // to filter for Congregational Life Events and AWANA events, use:
  //    'groups' => array('Congregational Life Events', 'AWANA'),
  'groups' => array(),

  #### DATE/TIME FORMATS ####

  // Main time format (default looks like "6:30am")
  'timeformat' => 'g:ia',

  // Simplified time format, used when the time is at the top of the hour (default looks like "6am")
  'timeformat_simplified' => 'ga',

  // Main date format (default looks like "May 18")
  'dateformat' => 'F j',

  // Date format for one day events (default looks like "Wednesday, May 18")
  'dateformat_single' => 'l, F j',

  // Simplified date format, used for the end date of a multi-day event       (default looks like "18")
  'dateformat_simplified' => 'j',

      );

?>
2
  • Seeing the code on from EE template could possibly help us figure out your problem. Mar 12, 2014 at 18:30
  • sorry about that. I have included everything I am using in the description above. Mar 12, 2014 at 18:55

2 Answers 2

0

To answer with an aside which may indirectly help you...

Putting PHP code in templates isn't ideal. It muddies the water and can be prone to problems.

I can't help but think that you'd be better served integrating your PHP into a simple add-on.

You could quite easily take your code and wrap it in ExpressionEngine's API. http://ellislab.com/expressionengine/user-guide/development/plugins.html

A simple plugin might look like

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Event_Search {
public $return_data = "";
public function __construct()
{
  $path = $_SERVER['DOCUMENT_ROOT'];
  $path .= "/public_calendar_listing/event_search_list.php";
  $this->return_data = include_once($path);
  }
}

You would put that into /system/expressionengine/third_party/event_search/pi.event_search.php and call it with {exp:event_search}.

But if that works maybe look into developing it into a nicer add-on in which you return the data back into ExpressionEngine variables so you can build the template directly into EE.

4
  • I think I may give that a try. I have always wanted to learn how to make add-ons. I will let you know how it goes. Mar 13, 2014 at 3:09
  • So I did what you suggested, but I don't see the plugin show up in the plugins section. Any idea why? Mar 13, 2014 at 3:31
  • I tried calling it anyway, but see what errors I get on the page: discoverycolorado.dreamhosters.com/events Mar 13, 2014 at 3:36
  • somehow this changed overnight. Now I am not getting the errors, but it still isn't generating any results Mar 13, 2014 at 13:25
0

Well, I finally threw in the towel and went with the wimpy solution. I went to my main events page and used an iframe to pull in the working page. Not elegant, but it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.