<?php
 
/*
 
      BloggerIntegration v1.3 - BloggerIntegration.php4 v1.2 2007/03/24
 
 
    This class enables you to insert a blog created with Blogger.com (FTP publishing) into your web site. 
 
    More precisely, it wraps your website's look (or template) around your blog.
 
 
      Copyright (c) 2007 DAKEDO
 
 
    This program is free software; you can redistribute it and/or modify
 
    it under the terms of the GNU General Public License as published by
 
    the Free Software Foundation; either version 2 of the License, or
 
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License along
 
    with this program; if not, write to the Free Software Foundation, Inc.,
 
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 
      designer:    DAKEDO, Online Shopping Mall  
 
      url:        http://www.dakedo.com
 
      download:     http://www.dakedo.com/blogs/27/2007/02/blogger-integration.html
 
    email:        [email protected]
 
*/                                                
 
 
define('OSCOMMERCE','false');//set to 'true' if you use osCommerce
 
 
include("includes/classes/DynamicTemplate.php");
 
 
function replace_directive($match) 
 
    {
 
    $product_id = $match[2];
 
    $product_url = $match[1] . $match[2];
 
    $product_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
 
    $product_result = tep_db_fetch_array($product_query);
 
 
    eval("\$return_string = '<a href=\"" . $product_url . "\" >'" . " . tep_image('" . DIR_WS_IMAGES . $product_result['products_image'] . "','','','','style=\"margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;\"') . '</a>';");
 
 
    return $return_string;
 
    }
 
 
class BloggerIntegration extends DynamicTemplate {
 
 
function BloggerIntegration($templateFile, $globals = array()) {
 
$this->loadTemplate($templateFile, $globals);
 
}
 
 
//Copyright announcement (html comment, not visible on the web page of course)
 
function copyright() {
 
//This announcement complies with section 2c of the GNU General Public License (GPL) and thus can not be removed.
 
return "BloggerIntegration V1.0\rCopyright (c) 2007 DAKEDO\rReleased under the GNU General Public License\rurl:           http://www.dakedo.com\rfree download: http://www.dakedo.com/blogs/27/2007/02/blogger-integration.html\r";
 
}
 
 
 
function processBody($page_body) {
 
if (OSCOMMERCE == 'true') {
 
//replace (http://www.yoursite.com/catalog/product_info.php?products_id=24) by the image with the link
 
//image insertion
 
$this->page = preg_replace_callback ("(\((" . HTTP_SERVER . DIR_WS_HTTP_CATALOG . FILENAME_PRODUCT_INFO ."\?products_id=)([0-9]+)\))", 'replace_directive', $this->page);
 
}
 
 
//add the full path to the permalinks
 
//so that I can keep the original base directory coming from the template
 
$this->page = eregi_replace('((<a[^<^>]*[ ]+href=\")(#c[0-9]+\"[^<^>]*>[^<^>]+<\/a>))', '\\2' . BLOG_SERVER . DIR_WS_BLOG . $PHP_SELF . '?\\3', $this->page);
 
 
//Little image link near the button "Powered by blogger"
 
//Please keep this little image if you can, that will allow people reading your blog to download easily this distribution (like you probably did :-) ) if they like it...
 
$this->page = eregi_replace('(<a href="http://www.blogger.com"><img)','<a target="_blank" href="http://www.dakedo.com/blogs/27/2007/02/blogger-integration.html"><img border="0" src="http://www.dakedo.com/mall/images/dakedo-logo1.gif" alt="Integrated by DAKEDO" title="Integrated by DAKEDO"></a>\\1 border="0"', $this->page);
 
 
//"Add to Google" and "Add to Yahoo" buttons
 
$matches = array();
 
preg_match("(http://[1-9a-zA-Z./]+.xml)", $this->page, $matches);
 
$rss_feed_url = $matches[0];
 
 
$add_to_google = '<a href="http://fusion.google.com/add?feedurl=' . $rss_feed_url . '"><img src="http://buttons.googlesyndication.com/fusion/add.gif" width="104" height="17" border="0" alt="Add to Google"></a>';
 
 
$add_to_yahoo = '<a href="http://add.my.yahoo.com/content?.intl=us&url=' . $rss_feed_url . '"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif" width="91" height="17" border="0" align=middle alt="Add to My Yahoo!"></a>';
 
 
$rss_feed_url_pos = strpos($this->page,'id="blogfeeds"');
 
 
$rss_feed_end_pos = strpos($this->page,"</p>",$rss_feed_url_pos);
 
 
$this->page =    substr($this->page,0,$rss_feed_end_pos+4) .
 
                "\n  <p>" . $add_to_google . "</p>" . 
 
                "\n  <p>" . $add_to_yahoo . "</p>" . 
 
                substr($this->page,$rss_feed_end_pos+4);
 
 
}
 
 
 
function processHead($page_head) {
 
//remove the navbar style definition,to get the navbar with the body of the blog
 
$this->page = eregi_replace('(<style[ ]+type=[^<]+>[^<^>]+navbar[^<^>]+</style>)','',$this->page);
 
 
//remove parts that interfere with my stylesheet, if needed
 
//$this->page = eregi_replace('(a:(link|visited)[ ]+\{[^{^}]+})','',$this->page);
 
}
 
 
 
function get_File_To_Include($path, $file) {
 
$error = false;
 
 
//case of a directory or a wrong file name
 
if ( ($file == '') || (!file_exists($path . $file)) )
 
    {
 
    if (file_exists($path . 'index.html')) $included_file = $path . 'index.html';
 
    elseif (file_exists($path . 'index.htm')) $included_file = $path . 'index.htm';
 
    elseif (file_exists($path . 'index.php')) $included_file = $path . 'index.php';
 
    else $included_file = false;
 
    }
 
else $included_file = $path . $file;
 
 
if ($included_file === false)
 
    {
 
    if (isset($_GET['language']))//=> the language-specific blog wasn't found
 
        {
 
        //if there is one at the root I take it
 
        if (file_exists('index.html')) $included_file = 'index.html';
 
        elseif (file_exists('index.htm')) $included_file = 'index.htm';
 
        elseif (file_exists('index.php')) $included_file = 'index.php';
 
        else $included_file = false;
 
        } 
 
 
    if ($included_file === false) //=>no file in the root directory
 
        {
 
        $languages_array = array();
 
        if ($handle = opendir(DIR_FS_BLOG)) 
 
            {
 
               while (false !== ($file = readdir($handle))) 
 
                {
 
                   if     (    $file != "." && $file != ".." && 
 
                        filetype(DIR_FS_BLOG . $file)=='dir' && 
 
                        strlen($file)<3 && !is_numeric($file) ) $languages_array[] = $file;
 
                   }
 
               closedir($handle);
 
            }
 
        else die("can not open the blog directory '" . DIR_FS_BLOG . "'");
 
 
        // I take the first blog I find in the language-specific subdirectories
 
        $found = false;
 
        $i = 0;
 
        $nb_languages = count($languages_array);
 
        while( $i < $nb_languages  && !$found)
 
            {
 
            $language_code = $languages_array[$i];
 
            $found = true;
 
 
            if (file_exists(DIR_FS_BLOG . $language_code . '/index.html')) 
 
                $included_file = DIR_FS_BLOG . $language_code . '/index.html';
 
            elseif (file_exists(DIR_FS_BLOG . $language_code . '/index.htm'))
 
                $included_file = DIR_FS_BLOG . $language_code . '/index.htm';
 
            elseif (file_exists(DIR_FS_BLOG . $language_code . '/index.php'))
 
                $included_file = DIR_FS_BLOG . $language_code . '/index.php';
 
            else 
 
                {
 
                $included_file = false;
 
                $found = false;        
 
                }
 
 
            $i++;
 
            }
 
 
        }
 
    }
 
 
return $included_file;
 
}
 
 
}
 
?>
 
 
 |