Integrate

Jason Pell edited this page Jun 21, 2013 · 1 revision

This section of the documentation will list and describe methods of including OpenDB into other Applications.

TikiWiki

My first example will be a short plugin I used to display OpenDB new items in TikiWiki. The current plugin requires that a DSN be made to connect to the OpenDB database. The DSN should use a user with no write privileges to the DB to limit exposure. This plugin was writen for TW 1.9. To run, copy and paste code section into a new file and revise $imglink = "<img src='http://www.efamilynj.org/opendb/"; section and replace the url with the one that leads to your OpenDB site.

You must put this file (named: wikiplugin_odbnew.php) into the lib/wiki-plugins directory of your TikiWiki installation. You should also set the owner to the same user as the web-server.

Once you have the file in the directory all that remains is to add the plugin into a page and it will render the last five recently added movies in a table. I suggest using this in the main column and perhaps with some DIV wrappers to control the size. This is a very rudimentary method of linking OpenDB content to TikiWiki.

The next version will make actual calls to the OpenDB code and use the OpenDB code to process the request.

ODBNEW TikiWiki Plugin

   function wikiplugin_odbnew($data, $params) {
    global $tikilib;
   
    extract ($params,EXTR_SKIP);
   
    if (!isset($db)) {
      return tra('Missing db param');
    }
   
    $perm_name = 'tiki_p_dsn_' . $db;
    global $$perm_name;
   
    if ($$perm_name != 'y') {
      return ('');
    }
   
    $ret = '';
    $sql_oke = true;
      $dbmsg = '';
      $data="SELECT 
         iattr.attribute_val as 'Cover',
         title as 'Title', 
         DATE_FORMAT(item_instance.update_on, '%m/%d/%Y') as 'Entered'
   from item
   
       left JOIN item_instance on item.id = item_instance.item_id
       LEFT JOIN item_attribute iattr ON iattr.item_id = item.id
           
   where s_item_type='DVD'
        AND iattr.s_attribute_type = 'IMAGEURL'
   
   ORDER by id DESC limit 5";
      
    if ($db == 'local') {
      $result = $tikilib->query($data,array());
    } else {
   
      $dsnsqlplugin = $tikilib->get_dsn_by_name($db);
   
      $parsedsn=$dsnsqlplugin;
      $dbdriver=strtok($parsedsn, ":");
      $parsedsn=substr($parsedsn,strlen($dbdriver)+3);
      $dbuserid=strtok($parsedsn, ":");
      $parsedsn=substr($parsedsn,strlen($dbuserid)+1);
      $dbpassword=strtok($parsedsn, "@");
      $parsedsn=substr($parsedsn,strlen($dbpassword)+1);
      $dbhost=strtok($parsedsn, "/");
      $parsedsn=substr($parsedsn,strlen($dbhost)+1);
      $database = $parsedsn;
   
      $dbsqlplugin = &ADONewConnection($dbdriver);
      if (!$dbsqlplugin) {
        $dberror = $dbsqlplugin->ErrorMsg();
        $dbmsg = "<div>$dberror</div>";
        $sql_oke = false;
      } else {
              if (!$dbsqlplugin->NConnect($dbhost, $dbuserid, $dbpassword, $database)) {
            $dberror = $dbsqlplugin->ErrorMsg();
            $dbmsg = "<div>$dberror</div>";
            $sql_oke = false;
          } else {
                    $result=$dbsqlplugin->Execute($data); 
            if (!$result) {
              $dberror = $dbsqlplugin->ErrorMsg();
              $dbmsg = "<div>$dberror</div>";
              $sql_oke = false;
            }
          }
      }
   
    }
   
    $first = true;
    $class = 'even';
    $last_item = array(array());
    $last_items = array();
    $imglink = "<img src='http://www.efamilynj.org/opendb/";
    $date_added = array();
    
    while ($sql_oke && $res = $result->fetchRow()) {
        
          foreach ($res as $name => $val) {
            $last_item[$name] = $val;
          }
        
        $last_items[] = $last_item;
        
          
        } //end while Main Loop
   
   
       // Now loop through result array and build display table.
   
           $ret = "<table class='normal'><colgroup align='center'>";
           $ret .= "<col width='120' align='center'><col width='120' align='center'>";
           $ret .= "<col width='120' align='center'><col width='120' align='center'>";
           $ret .= "<col width='120' align='center'>";
           $imgrow = "<tr>";
           $titlerow = "<tr>";
           $daterow = "<tr>";
   
   
       foreach ($last_items as $item){
                   
           foreach ($item as $name => $val){
               
               if($name=="Cover"){
                   If($val != Array()){$imgrow .= "<td align='center'>" . $imglink . $val . 
                     "'></td>";}
                   }
                   
               if($name=="Title" && $val != "Array"){
                   If($val != Array()){$titlerow .= "<td align='center' class='cbox-data'>
                     <div class='cbox-data'>" . $val . "</div></td>";}
                   }
               
               if($name=="Entered" && $val != "Array"){
                   If($val != Array()){$daterow .= "<td align='center'><div class='cbox-data'>"
                     . $val . "</div></td>";}
                   }
               }
           } // end Item loop   
   
        if ($dbmsg) {
          $ret .= $dbmsg;
        }
       
        if ($db != 'local') {
          $dbsqlplugin->Close();
        }
   
           $ret .= $imgrow . "</tr>";
           $ret .= $titlerow . "</tr>";
           $ret .= $daterow . "</tr>";    
           $ret .= "</table>";
   
    return $ret;          
   
   } // end function 
   
   ?>
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.