TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,989
  • Total Topics: 21,322
  • Online today: 1,078
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 724
  • Total: 724

Coppermine SSI Function

Started by carver, September 26, 2005, 04:01:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

carver

Being that I am moderately php handicapped .. is there a way to get this to run in a block on the portal?

<? include_once("/home/yourdomain/public_html/coppermine/ssi.php"); ?>
<? print cpg_random(); ?>

I have tried about every combination of things that I can think of. head and body tags, removing the <? ?> tags.
I can get it to work out of the portal fine, but not in a block..

It is for the coppermine gallery...

bloc

You have set the block to be "phpbox" type?

If so, I would assume just doing below should be right...

include_once("/home/yourdomain/public_html/coppermine/ssi.php");
print cpg_random();

carver

I did try that too, and I get

Coppermine critical error:
Unable to connect to database !
MySQL said: No Database Selected

but I can run the same code stand alone and it works.

I have a meeting but will play with it more later..

bloc

mm, I think maybe I need to look at the file/code you include.

When in a block, the connection to the SMF database is there..but if any script assumes open connection to ANOTHER ( like coppermine) databse, it will need a call for that. So maybe thats the reason. I assume this is in the regualr Coppermine files?


carver

it is a mod, abit old but a mod they offered to pull random pictures... I will include it here.

Not like your not busy enough but I know there have been quite a few people looking to add random photo's from coppermine to their TP sites so I remembered this and hoped for quick and easy, which it appears is not going to be the case..

<?
// ------------------------------------------------------------------------- //
//  include script for CPG (c) 2003 GauGau (mail@gaugau.de) V1.4             //
//  http://gaugau.de/                                                        //
// ------------------------------------------------------------------------- //
//  Coppermine Photo Gallery v1.1                                     //
// ------------------------------------------------------------------------- //
//  Copyright (C) 2002,2003  Gr&eacute;gory DEMAR <gdemar@wanadoo.fr>               //
//  http://www.chezgreg.net/coppermine/                                      //
// ------------------------------------------------------------------------- //
//  Based on PHPhotoalbum by Henning StÃÆ'Ã,¸verud <henning@stoverud.com>         //
//  http://www.stoverud.com/PHPhotoalbum/                                    //
// ------------------------------------------------------------------------- //
//  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.                                      //
// ------------------------------------------------------------------------- //

/////////////////// edit the following lines //////////////////////////////
$url_of_cpg_dir=' http://tmorrowonline.com/copper/';    // full path to your coppermine gallery (with trailing slash)
$absolute_path_to_coppermine='/home/tmorcom/public_html/copper/'; // absolute path on your server to coppermine gallery (with trailing slash)
// to find more about absolute paths, check http://www.php.net/manual/en/function.phpinfo.php and look for 'DOCUMENT_ROOT' in your phpinfo.php
$cpg_decimal_point="."; //what character is used to separate decimals in your country, e.g. in Germany ",", in GB "."
$cpg_thousands_separator=","; //what character is used to separate thousands in your country, e.g. in Germany ".", in GB & US ",", in France " "
$cpg_lang_pics = "Pictures"; //translate this
$cpg_lang_views = "view"; //translate this
$cpg_lang_random = "Random pic of this album"; //translate this
$cpg_lang_keywords = "Keywords"; //translate this
/////// don't edit below this line unless you know what your're doing /////////

include_once( $absolute_path_to_coppermine.'/include/config.inc.php');

print <<<EOT
<script language="javascript" type="text/javascript">
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
</script>
EOT;


// definition taken from init.inc.php
$CONFIG['TABLE_PICTURES']        = $CONFIG['TABLE_PREFIX']."pictures";
$CONFIG['TABLE_ALBUMS']                = $CONFIG['TABLE_PREFIX']."albums";
$CONFIG['TABLE_COMMENTS']        = $CONFIG['TABLE_PREFIX']."comments";
$CONFIG['TABLE_CATEGORIES']        = $CONFIG['TABLE_PREFIX']."categories";
$CONFIG['TABLE_CONFIG']                = $CONFIG['TABLE_PREFIX']."config";
$CONFIG['TABLE_USERGROUPS']        = $CONFIG['TABLE_PREFIX']."usergroups";
$CONFIG['TABLE_VOTES']                = $CONFIG['TABLE_PREFIX']."votes";
$CONFIG['TABLE_USERS']                = $CONFIG['TABLE_PREFIX']."users";
// Connect to database
db_connect() || die("<b>Coppermine critical error</b>:<br />Unable to connect to database !<br /><br />MySQL said: <b>".mysql_error()."</b>");

// get config data
$result = mysql_query("SELECT * from {$CONFIG['TABLE_CONFIG']} WHERE name='fullpath'");
$row = mysql_fetch_row($result);
$cpg_album_path=$row[1];
$result = mysql_query("SELECT * from {$CONFIG['TABLE_CONFIG']} WHERE name='thumb_pfx'");
$row = mysql_fetch_row($result);
$cpg_thumb_pfx=$row['1'];
$result = mysql_query("SELECT * from {$CONFIG['TABLE_CONFIG']} WHERE name='thumbcols'");
$row = mysql_fetch_row($result);
$cpg_thumbcols=$row['1'];


if ($function == 'cpg_thumb' || $function == 'recentTopics' || $function == 'whosOnline' || $function == 'welcome' || $function == 'menubar' || $function == 'logout' || $function == 'login' || $function == 'topBoards' || $function == 'topTopicsViews' || $function == 'topTopicsReplies' || $function == 'latestMember' || $function == 'boardStats')
{
        $function(); // Execute Function
        exit;
}

function cpg_thumb()
{
GLOBAL $CONFIG,$url_of_cpg_dir,$cpg_album_path,$cpg_thumb_pfx,$cpg_thumbcols,$cpg_lang_random,$cpg_lang_views,$cpg_lang_keywords;
$numargs = func_num_args();
$arg_list = func_get_args();
if ($numargs > 0) {$cpg_include_link=$arg_list[0];}
if ($numargs > 1) {$cpg_link_singlepic=$arg_list[1];}
if ($numargs > 2) {$cpg_how_many=$arg_list[2];}
if ($numargs > 3) {$cgp_limit_album=$arg_list[3];}
if ($numargs > 4) {$cpg_random=$arg_list[4];}
if ($numargs > 5) {$cpg_link_target=$arg_list[5];}
if ($cpg_link_target==""){$cpg_link_target="_top";}


//get pic info
$query = "SELECT * from {$CONFIG['TABLE_PICTURES']} WHERE approved='YES' ";
if($cgp_limit_album!=""){$query.="AND aid='".$cgp_limit_album."'";}
$query.=" AND user2!='1' ORDER BY ";
if($cpg_random=="1"){$query.="RAND()";}else{$query.="ctime";}
$query.=" DESC LIMIT 0,".$cpg_how_many;
$result = mysql_query($query);
if ($cpg_how_many!=1)
{
$return_value="<table align=\"center\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\" class=\"maintable\" border=\"0\">";
$td_start="<td valign=\"middle\" class=\"thumbnails\" align=\"center\">\n";
$td_end="</td>";
$cpg_table_end="</table>";
$tr_start="<tr>\n";
$tr_end="</tr>\n";
}
else
{
$return_value="";
$td_start="";
$td_end="";
$cpg_table_end="";
$tr_start="";
$tr_end="";
}
$counter=0;
if ($cpg_thumbcols > $cpg_how_many) {$cpg_thumbcols=$cpg_how_many;}

while ($row = mysql_fetch_array($result)) {
//------
if ($counter==0){$return_value.=$tr_start;}
$return_value.=$td_start;
if ($cpg_include_link==1)
  {
  $return_value.= "<a href=\"";
    if ($cpg_link_singlepic==1)
      {
       if ($cpg_link_target=="popup")
          {
          $return_value.="javascript:;\" onClick=\"MM_openBrWindow('".$url_of_cpg_dir."displayimage.php?pid=".$row['pid']."&fullsize=1','".uniqid(rand())."','toolbar=yes,status=yes,resizable=yes,width=".($row['pwidth']+16).",height=".($row['pheight']+16)."')\"";
          }
          else
          {
          $return_value.=$url_of_cpg_dir."displayimage.php?&pos=-".$row['pid'];
          }
      }
    else
      {
      $return_value.=$url_of_cpg_dir."thumbnails.php?album=".$row['aid'];
      }
  $return_value.="\" ";

  if($cpg_link_target=="popup"){$return_value.="";}else{$return_value.="target=\"".$cpg_link_target."\"";}
  $return_value.=">";
  }
$return_value.= "<img src=\"".$url_of_cpg_dir.$cpg_album_path.$row['filepath'].$cpg_thumb_pfx.$row['filename']."\" border=\"0\" alt=\"\" title=\"";
if ($row['title']!="") {$return_value.= $row['title']."&#10;";}
if ($row['caption']!="") {$return_value.= $row['caption']."&#10;";}
if ($row['keywords']!="") {$return_value.= $cpg_lang_keywords . ": " . $row['keywords']."&#10;";}
if ($row['hits']!="") {$return_value.= $row['hits']." ".$cpg_lang_views."&#10;";}
if($cpg_random=="1")  {$return_value.= $cpg_lang_random;}
$return_value.= "\" align=\"left\" class=\"padright\">";
if ($cpg_include_link==1){$return_value.="</a>";}
$return_value.=$td_end."\n";
$counter++;
if ($counter==$cpg_thumbcols){$counter=0;$return_value.=$tr_end;}
}

$return_value.=$cpg_table_end;
return $return_value;
}

function cpg_single()
{
$numargs = func_num_args();
$arg_list = func_get_args();
if ($numargs > 0){return cpg_thumb(1,1,1,"",0,$arg_list[0]);}
else{return cpg_thumb(1,1,1,"",0);}
}

function cpg_total_pics($cgp_limit_album)
{
GLOBAL $CONFIG,$cpg_decimal_point,$cpg_thousands_separator;
  $query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES'";
  if($cgp_limit_album!=""){$query.=" AND aid='".$cgp_limit_album."'";}
  $result = mysql_query($query);
  $nbEnr = mysql_fetch_array($result);
  $pic_count = $nbEnr[0];
  mysql_free_result($result);
  return number_format($pic_count,0,$cpg_decimal_point,$cpg_thousands_separator);
}

function cpg_total_views($cgp_limit_album)
{
GLOBAL $CONFIG,$cpg_decimal_point,$cpg_thousands_separator;
  $query = "SELECT sum(hits) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1";
  if($cgp_limit_album!=""){$query.=" AND aid='".$cgp_limit_album."'";}
  $result = mysql_query($query);
  $nbEnr = mysql_fetch_array($result);
  $view_count = $nbEnr[0];
  mysql_free_result($result);
  return number_format($view_count,0,$cpg_decimal_point,$cpg_thousands_separator);
}

function cpg_hit_ratio($cgp_limit_album)
{
GLOBAL $CONFIG;
//get stats
$result=mysql_query("SELECT sum(hits) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$hit_count = (int)$nbEnr[0];
$result=mysql_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$picture_count = $nbEnr[0];
$cpg_ratio_string=str_replace(".", ",",(floor(((str_replace(".", "", cpg_total_views($cgp_limit_album))/str_replace(".", "", cpg_total_pics($cgp_limit_album)))*10)/($hit_count/$picture_count)))/10);
//$cpg_ratio_string=cpg_total_views($cgp_limit_album).'|'.cpg_total_pics($cgp_limit_album).'|'.$hit_count.'|'.$picture_count;
return $cpg_ratio_string;


}

function cpg_stat_string($cgp_limit_album)
{
GLOBAL $url_of_cpg_dir,$cpg_lang_pics,$cpg_lang_views;
$cpg_stat_string='[<a href="'.$url_of_cpg_dir.'thumbnails.php?album='.$cgp_limit_album.'"><b>';
$cpg_stat_string.=cpg_total_pics($cgp_limit_album);
$cpg_stat_string.='</b> ' . $cpg_lang_pics . '</a>, <a href="'.$url_of_cpg_dir.'thumbnails.php?album=topn&cat=-'.$cgp_limit_album.'"><b>';
$cpg_stat_string.=cpg_total_views($cgp_limit_album);
$cpg_stat_string.='</b> ' . $cpg_lang_views . '</a>';
$cpg_stat_string.=', <span class="tool" title="SF=Spanner-Faktor:&#10;Wie oft sind die Bilder dieses Albums durchschnittlich angeklickt worden, im Vergleich zur gesamten Galerie?">SF: '.cpg_hit_ratio($cgp_limit_album).'</span>';
$cpg_stat_string.=']';
return $cpg_stat_string;
}

function cpg_total_albums()
{
GLOBAL $CONFIG,$cpg_decimal_point,$cpg_thousands_separator;
  $query = "SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1";
  $result = mysql_query($query);
  $nbEnr = mysql_fetch_array($result);
  $album_count = $nbEnr[0];
  mysql_free_result($result);
  return number_format($album_count,0,$cpg_decimal_point,$cpg_thousands_separator);
}

function cpg_total_comments()
{
GLOBAL $CONFIG,$cpg_decimal_point,$cpg_thousands_separator;
  $query = "SELECT count(*) FROM {$CONFIG['TABLE_COMMENTS']} WHERE 1";
  $result = mysql_query($query);
  $nbEnr = mysql_fetch_array($result);
  $comments_count = $nbEnr[0];
  mysql_free_result($result);
  return number_format($comments_count,0,$cpg_decimal_point,$cpg_thousands_separator);
}

function cpg_total_cats()
{
GLOBAL $CONFIG,$cpg_decimal_point,$cpg_thousands_separator;
  $query = "SELECT count(*) FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1";
  $result = mysql_query($query);
  $nbEnr = mysql_fetch_array($result);
  $cats_count = $nbEnr[0];
  mysql_free_result($result);
  return number_format($cats_count,0,$cpg_decimal_point,$cpg_thousands_separator);
}


function cpg_random()
{
return cpg_thumb(1,1,1,"",1);
}

function cpg_search($cpg_size,$cpg_question,$cpg_submit_text)
{
GLOBAL $url_of_cpg_dir;
$cpg_search_string = "<form method=\"get\" action=\"" . $url_of_cpg_dir . "thumbnails.php\" name=\"search_cpg\">
<input type=\"hidden\" name=\"album\" value=\"search\" />
<input type=\"hidden\" name=\"type\" value=\"full\" />
<input type=\"input\" name=\"search\" maxlength=\"255\" size=\"" . $cpg_size . "\" value=\"" . $cpg_question . "\" class=\"textfield\" onfocus=\"this.value=''\" />";
if ($cpg_submit_text!="" and $cpg_submit_text!="0")
  {
  $cpg_search_string.= " <input type=\"submit\" value=\"" . $cpg_submit_text . "\" class=\"submit\" />";
  }
$cpg_search_string.= "</form>";
return $cpg_search_string;
}

function cpg_stats()
{
GLOBAL $CONFIG;
$result=mysql_query("SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$album_count = $nbEnr[0];
mysql_free_result($result);

$result=mysql_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$picture_count = $nbEnr[0];
mysql_free_result($result);

$result=mysql_query("SELECT count(*) FROM {$CONFIG['TABLE_COMMENTS']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$comment_count = $nbEnr[0];
mysql_free_result($result);

$result=mysql_query("SELECT count(*) FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$cat_count = $nbEnr[0] - $HIDE_USER_CAT;
mysql_free_result($result);

$result=mysql_query("SELECT sum(hits) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$hit_count = (int)$nbEnr[0];
mysql_free_result($result);


print $picture_count.", ".$album_count.", ".$cat_count.", ".$comment_count.", ".$hit_count;
}


//function taken from functions.inc.php
function db_connect()
{
        global $CONFIG;
        $result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
        if (!$result)
                return false;
        if (!mysql_select_db($CONFIG['dbname']))
                return false;
        return $result;
}



?>



envon

Just use cpm_fetch at this site I have used it in TP from the start. It's a very flexible little object. http://www.fistfullofcode.com/projects/copperminefetch/index.php

bloc

It would take a while to test the above code and get it going, so if copperminefetch works alright, maybe post what needs to be done , envon?

envon

Sorry.  Goto the link above download the file.  It has a very detailed instruction set as to the different ways to use CPM-Fetch.  As there are several different ways to call the object and alot of different functions to it.  There is even a test to make sure you entered all the right data and test the database connection etc.  I use it blocks to pull random pics from the gallery.  Long nite with no sleep, sorry if this doesnt make sence right now.  Just download and follow instructions.

This website is proudly hosted on Crocweb Cloud Website Hosting.