Extension:Coppermine

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Coppermine

Release status: beta

Implementation Tag
Description This extension allows you to insert coppermine gallery pictures into a mediawiki page
Author(s) Jeremy Laurenson (JeremyLaurensontalk)
Last version 0.2(c)
License No license specified
Download No link
Parameters

Inside code listing

Check usage and version matrix

This extension allows you to display pictures from your Coppermine photo gallery inside of a MediaWiki page.

This extension assumes your Coppermine tables are in the same database as MediaWiki, since it uses MediaWiki's database functions to access the Coppermine tables.

It can display most recent, top viewed, top rated, random and last viewed pictures from the entire site or a specific album.

Pictures are displayed as thumbnails, and can be formated in a simple table or simply output inside the doc.

Contents

Usage [edit]

Example MediaWiki code:

<coppermine>view random | count 9 | cols 3 | table 1 | border 0 | colheight 105| colwidth 105 | alink yes | showcaption size,movietitle</coppermine>
Parameters
url optional Url to link to when the user clicks an image.
view Required Which type of view - this particular view was set to see the top viewed images

May be:

lastcom Show the items that were last commented on
lastup Show the latest uploaded items
topn Show the top viewed items
toprated Show the top rated items as decided by user votes
lasthits Show the most recently viewed items
random Show a random selection
count Required Number of thumbnails to display
album optional Album number to display thumbnails from
table optional Set this parameter to 1 to have the thumbnails displayed in a table
cols optional Number of columns in the table
border optional Define a border for the table - this parameter is a number, same as border= in html
colheight optional Height of each table cell
colwidth optional Width of each table cell
bgcolor optional Background color for each table cell
ilink optional Instead of linking to the single URL no matter what thumb is clicked, set this to yes to instead link to the picture page within coppermine
alink optional Instead of linking to the single URL no matter what thumb is clicked, set this to yes to instead link to the album page within coppermine
showcaption optional Displays a caption below the thumbnail - the value of this parameter determines what is displayed, and to display multiple pieces of info, separate them with commas (,) for example: size,movietitle

Caption parameter values:

size Show file size
title Show item title or filename
moviesize Show file sizes only for movies
movietitle Show titles only for movies
tooltip optional Displays a tooltip when hovering over a thumbnail - the value of this parameter determines what is displayed, and to display multiple pieces of info, separate them with commas (,) for example: size,movietitle a value of * includes all tips

Caption parameter values:

size Show file size
title Show item title or filename
moviesize Show file sizes only for movies
movietitle Show titles only for movies
dimensions Show image dimensions
votes Show number of votes
time Show image upload time/date

Code [edit]

First, you have to make file called Coppermine.php and upload it into the extensions folder.

  1. <?php
  2. #
  3. # Tag :
  4. #   <coppermine>commands</coppermine>
  5. #
  6. #  This plugin is for my site. It assumes that your coppermine data is in the same SQL database
  7. #  as your MediaWiki data. If not, bummer :-(
  8. #
  9. # Version 0.1c
  10.  
  11. $wgExtensionFunctions[] = 'wfCoppermine';
  12. $wgExtensionCredits['parserhook'][] = array(
  13.        'name' => 'Coppermine',
  14.        'description' => 'Display recent, top photos from Coppermine gallery',
  15.        'author' => 'Jeremy Laurenson',
  16.        'url' => 'http://www.mediawiki.org/wiki/Extension:Coppermine'
  17. );
  18.  
  19. function wfCoppermine() {
  20.         global $wgParser;
  21.         $wgParser->setHook('coppermine', 'rendercoppermine');
  22. }
  23.  
  24.         function connect() {
  25.             // Check if the phpBB tables are in a different database then the Wiki.
  26.             if ($GLOBALS['wgPHPBB_UseExtDatabase'] == true) {
  27.  
  28.                 // Connect to database. I supress the error here.
  29.                 $fresMySQLConnection = @mysql_connect($GLOBALS['wgPHPBB_MySQL_Host'],    //<-
  30.                                                      $GLOBALS['wgPHPBB_MySQL_Username'], //<-
  31.                                                      $GLOBALS['wgPHPBB_MySQL_Password'], true);
  32.  
  33.                 // Check if we are connected to the database.
  34.                 if (!$fresMySQLConnection) {
  35.                     $this->mySQLError('There was a problem when connecting to the phpBB database.<br />' . //<-
  36.                                       'Check your Host, Username, and Password settings.<br />');
  37.                 }
  38.  
  39.                 // Select Database
  40.                 $db_selected = mysql_select_db($GLOBALS['wgPHPBB_MySQL_Database'], $fresMySQLConnection);
  41.  
  42.                 // Check if we were able to select the database.
  43.                 if (!$db_selected) {
  44.                     $this->mySQLError('There was a problem when connecting to the phpBB database.<br />' .
  45.                                       'The database ' . $GLOBALS['wgPHPBB_MySQL_Database'] . ' was not found.<br />');
  46.                 }
  47.  
  48.             } else {
  49.  
  50.                 // Connect to database.
  51.                 $fresMySQLConnection = mysql_connect($GLOBALS['wgDBserver'], $GLOBALS['wgDBuser'], $GLOBALS['wgDBpassword'], true);
  52.  
  53.                 // Check if we are connected to the database.
  54.                 if (!$fresMySQLConnection) {
  55.                     $this->mySQLError('There was a problem when connecting to the phpBB database.<br />' . //<-
  56.                                       'Check your Host, Username, and Password settings.<br />');
  57.                 }
  58.  
  59.                 // Select Database: This assumes the wiki and phpbb are in the same database.
  60.                 $db_selected = mysql_select_db($GLOBALS['wgDBname']);
  61.  
  62.                 // Check if we were able to select the database.
  63.                 if (!$db_selected) {
  64.                     $this->mySQLError('There was a problem when connecting to the phpBB database.<br />' .
  65.                                       'The database ' . $GLOBALS['wgDBname'] . ' was not found.<br />');
  66.                 }
  67.  
  68.             }
  69.  
  70.             $GLOBALS['gstrMySQLVersion'] = substr(mysql_get_server_info(), 0, 3); // Get the mysql version.
  71.  
  72.             return $fresMySQLConnection;
  73.         }
  74.  
  75.         function mySQLError( $message ) {
  76.             echo $message . '<br />';
  77.             echo 'MySQL Error Number: ' . mysql_errno() . '<br />';
  78.             echo 'MySQL Error Message: ' . mysql_error() . '<br /><br />';
  79.             exit;
  80.         }
  81.  
  82.         function strict() {
  83.                 return true;
  84.         }
  85.  
  86.  
  87.                 function updateExternalDB( $user ) {
  88.                         return true;
  89.                 }
  90.  
  91.  
  92.  
  93.  function rendercoppermine($input) {
  94.  
  95.  
  96. #*****************************************************************************************************
  97. #*****************************************************************************************************
  98. #*****  Your information needs to be entered below... This info is from your coppermine install ******
  99. #*****************************************************************************************************
  100. #*****************************************************************************************************
  101.                $cpg_prefix =                           'cpg_';
  102.                 # Database prefix used for your coppermine tables
  103.                $cpg_root  =                                            "http://www.yoursite.com/gallery/";
  104.                 # Root of your coppermine install, so we can link to
  105. #*****************************************************************************************************
  106. #*****************************************************************************************************
  107.  
  108.  
  109.  
  110.                         $cpg_pictures=                                          $cpg_prefix .'pictures';
  111.                         $cpg_albums=                                            $cpg_prefix .'albums';
  112.                         $cpg_comments  =                                        $cpg_prefix .'comments';
  113.  
  114.  
  115.  
  116.                         $output='';
  117.                         $cpg_params=explode('|', $input);
  118.  
  119.                         $cpg_view=0;
  120.                         foreach($cpg_params as $x){
  121.                                                 $cpg_param=explode(' ', trim($x));
  122.                                                 switch(strtolower($cpg_param[0])){
  123.                                                         case 'view';
  124.                                                                 $cpg_view=strtolower($cpg_param[1]);
  125.                                                         break;
  126.                                                         case 'count';
  127.                                                                 $cpg_count=strtolower($cpg_param[1]);
  128.                                                         break;
  129.                                                         case 'url';
  130.                                                                 $cpg_url=strtolower($cpg_param[1]);
  131.                                                         break;
  132.                                                         case 'album';
  133.                                                                 $cpg_album=strtolower($cpg_param[1]);
  134.                                                         break;
  135.                                                         case 'cols';
  136.                                                                 $cpg_cols=strtolower($cpg_param[1]);
  137.                                                         break;
  138.                                                         case 'table';
  139.                                                                 $cpg_table=strtolower($cpg_param[1]);
  140.                                                         break;
  141.                                                         case 'border';
  142.                                                                 $cpg_border=strtolower($cpg_param[1]);
  143.                                                         break;
  144.                                                         case 'colheight';
  145.                                                                 $cpg_colheight=strtolower($cpg_param[1]);
  146.                                                         break;
  147.                                                         case 'colwidth';
  148.                                                                 $cpg_colwidth=strtolower($cpg_param[1]);
  149.                                                         break;
  150.                                                         case 'bgcolor';
  151.                                                                 $cpg_bgcolor=strtolower($cpg_param[1]);
  152.                                                         break;
  153.                                                         case 'ilink';
  154.                                                                 $cpg_individuallink=strtolower($cpg_param[1]);
  155.                                                         break;
  156.                                                         case 'alink';
  157.                                                                 $cpg_albumlink=strtolower($cpg_param[1]);
  158.                                                         break;
  159.                                                         case 'showcaption';
  160.                                                                 $cpg_showcaption=strtolower($cpg_param[1]);
  161.                                                         break;
  162.                                                         case 'tooltip';
  163.                                                                 $cpg_showtooltip=strtolower($cpg_param[1]);
  164.                                                         break;
  165.                                                         case 'captionsize';
  166.                                                                 $cpg_captionsize=strtolower($cpg_param[1]);
  167.                                                         break;
  168.                                                         case 'captioncolor';
  169.                                                                 $cpg_captioncolor=strtolower($cpg_param[1]);
  170.                                                         break;
  171.  
  172.  
  173.  
  174.  
  175.  
  176.                                                         }
  177.                                                 }
  178.                         if(($cpg_view!='') and ($cpg_count!='')){
  179.  
  180.  
  181.  
  182.                                         switch($cpg_view){
  183.                                         case 'lastcom': // Last comments
  184.                                                 $cpg_sort=' pid desc ';
  185.                         break;
  186.                                         case 'lastup': // Last uploaded
  187.                                                 $cpg_sort=' pid desc ';
  188.                         break;
  189.                                         case 'topn': // Top visited
  190.                                                 $cpg_sort=' hits desc ';
  191.                         break;
  192.                                         case 'toprated': // Top rated
  193.                                                 $cpg_sort=' votes desc ';
  194.                         break;
  195.                                         case 'lasthits': // Last viewed
  196.                                                 $cpg_sort=' mtime desc ';
  197.                         break;
  198.                                         case 'random': // Random
  199.                                                 $cpg_sort=' RAND() desc ';
  200.                         break;
  201.                                                 }
  202.  
  203.                                                 if ($cpg_sort=='')return ' Style may be: lastcom, lastup, topn, toprated,lasthits or random';
  204.                                            $fresMySQLConnection = connect();
  205.  
  206.  
  207.                                                 if($cpg_captionsize=='')$cpg_captionsize='2';
  208.                                                 if($cpg_captioncolor=='')$cpg_captioncolor='BLACK';
  209.  
  210.  
  211.                                                 $cpg_col=0;
  212.                                            $fstrMySQLQuery = 'SELECT * FROM `' .$cpg_pictures. '` WHERE `approved` = \'YES\' ';
  213.                                            if($cpg_album!='')$fstrMySQLQuery.=' and `aid`='.$cpg_album;
  214.                                            $fstrMySQLQuery.=' order by ';
  215.                                            $fstrMySQLQuery.=$cpg_sort;
  216.                                            $fstrMySQLQuery.=' limit '.$cpg_count;
  217.                                            $fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection) or die(mySQLError('Unable to view external table'));
  218.                                                 if(!$fresMySQLResult)$output=$output."No pictures found.";
  219.  
  220.  
  221.                                                 if($cpg_table!='')$output=$output .'<TABLE ';
  222.                                                 if(($cpg_table!='') and ($cpg_border!=''))$output=$output .'BORDER="'.$cpg_border.'" ';
  223.                                                 if($cpg_table!='')$output=$output .'><TR>';
  224.  
  225.                                                 while($faryMySQLResult = mysql_fetch_array($fresMySQLResult)){
  226.                                                         $cpg_x=$faryMySQLResult['pwidth'];
  227.                                                         $cpg_y=$faryMySQLResult['pheight'];
  228.                                                         $cpg_time=strftime('%b %e %G %I:%M%p',$faryMySQLResult['ctime']);
  229.                                                         $cpg_votes=$faryMySQLResult['votes'];
  230.                                                         $cpg_pid=$faryMySQLResult['pid'];
  231.                                                         $cpg_aid=$faryMySQLResult['aid'];
  232.                                                         $cpg_filesize=$faryMySQLResult['filesize'];
  233.                                                         $cpg_filename=$faryMySQLResult['filename'];
  234.                                                         $cpg_title=$faryMySQLResult['title'];
  235.  
  236.                                                         if($cpg_title=='')$cpg_title=$cpg_filename;
  237.                                                         $cpg_displayfilesize=$cpg_filesize;
  238.                                                         if($cpg_filesize<=(1024*1024))$cpg_displayfilesize=round($cpg_filesize/1024,1).'KB';
  239.                                                         if($cpg_filesize>(1024*1024))$cpg_displayfilesize=round($cpg_filesize/(1024*1024),1).'MB';
  240.  
  241.                                                         # Now we build the caption based on the tags we find in the caption keyword
  242.                                                        $cpg_caption='';
  243.                                                         if($cpg_showcaption!=''){
  244.                                                                                 $cpg_captioninfo=explode(',', trim($cpg_showcaption));
  245.                                                                                 foreach($cpg_captioninfo as $x){
  246.                                                                                         switch($x){
  247.                                                                                                 case "title":
  248.                                                                                                         $cpg_caption.=$cpg_title.' ';
  249.                                                                                                 break;
  250.                                                                                                 case "size":
  251.                                                                                                         $cpg_caption.=$cpg_displayfilesize.' ';
  252.                                                                                                 break;
  253.                                                                                                 case "movietitle":
  254.                                                                                                         if($cpg_x==0)$cpg_caption.=$cpg_title.' ';
  255.                                                                                                 break;
  256.                                                                                                 case "moviesize":
  257.                                                                                                         if($cpg_x==0)$cpg_caption.=$cpg_displayfilesize.' ';
  258.                                                                                                 break;
  259.                                                                                         }
  260.                                                                                 }
  261.                                                         }
  262.  
  263.                                                         if($cpg_showtooltip!=''){
  264.                                                                                 if($cpg_showtooltip=='*')$cpg_showtooltip='title,dimensions,size,votes,time';
  265.                                                                                 $cpg_tooltipinfo=explode(',', trim($cpg_showtooltip));
  266.                                                                                 $cpg_tooltip='';
  267.                                                                                 foreach($cpg_tooltipinfo as $x){
  268.                                                                                         switch($x){
  269.                                                                                                 case "title":
  270.                                                                                                         $cpg_tooltip.=$cpg_title.' ';
  271.                                                                                                 break;
  272.                                                                                                 case "size":
  273.                                                                                                         $cpg_tooltip.=$cpg_displayfilesize.' ';
  274.                                                                                                 break;
  275.                                                                                                 case "movietitle":
  276.                                                                                                         if($cpg_x==0)$cpg_tooltip.=$cpg_title.' ';
  277.                                                                                                 break;
  278.                                                                                                 case "moviesize":
  279.                                                                                                         if($cpg_x==0)$cpg_tooltip.=$cpg_displayfilesize.' ';
  280.                                                                                                 break;
  281.                                                                                                 case "dimensions":
  282.                                                                                                         $cpg_tooltip.=$cpg_x.'x'.$cpg_y.' ';
  283.                                                                                                 break;
  284.                                                                                                 case "votes":
  285.                                                                                                         $cpg_tooltip.=$cpg_votes.' ';
  286.                                                                                                 break;
  287.                                                                                                 case "time":
  288.                                                                                                         $cpg_tooltip.=$cpg_time.' ';
  289.                                                                                                 break;
  290.                                                                                                 case "moviesize":
  291.                                                                                                         if($cpg_x==0)$cpg_tooltip.=$cpg_displayfilesize.' ';
  292.                                                                                                 break;
  293.                                                                                         }
  294.                                                                                 }
  295.                                                         }
  296.  
  297.                                                         $cpg_col++;
  298.                                                         if(($cpg_table!='') and ($cpg_col>$cpg_cols)){
  299.                                                                         $cpg_col=1;
  300.                                                                         $output.='</TR><TR>';
  301.                                                                         }
  302.                                                         if($cpg_table!='')$output.='<TD VALIGN="MIDDLE" ALIGN="CENTER" ';
  303.                                                         if(($cpg_table!='') and ($cpg_colheight!=''))$output.=' HEIGHT="'.$cpg_colheight.'" ';
  304.                                                         if(($cpg_table!='') and ($cpg_colheight!=''))$output.=' WIDTH="'.$cpg_colwidth.'" ';
  305.                                                         if(($cpg_table!='') and ($cpg_bgcolor!=''))$output.=' BGCOLOR="'.$cpg_bgcolor.'" ';
  306.                                                         if($cpg_table!='')$output=$output .'>';
  307.  
  308.                                                         if(($cpg_individuallink=='') and ($cpg_albumlink==''))$output.='<a title="'.$cpg_tooltip.'" target="_parent" href="'.$cpg_url.'">';
  309.                                                         if($cpg_individuallink!='')$output.='<a title="'.$cpg_tooltip.'" target="_parent" href="'.$cpg_root.'displayimage.php?album='.$cpg_aid.'&cat=0&pos=-'.$cpg_pid.'">';
  310.                                                         if($cpg_albumlink!='')$output.='<a title="'.$cpg_tooltip.'" target="_parent" href="'.$cpg_root.'thumbnails.php?album='.$cpg_aid.'&cat=0">';
  311.                                                         if($cpg_x!=0)$output.= "<img src=\"".$cpg_root."/albums/".$faryMySQLResult['filepath']."thumb_".$faryMySQLResult['filename']."\" border=\"0\">";
  312.                                                         else $output.= "<img src=\"".$cpg_root."images/thumb_mpg.jpg\" border=\"0\">";
  313.                                                         if($cpg_showcaption!='')$output.='<BR><FONT SIZE="'.$cpg_captionsize.'" COLOR="'.$cpg_captioncolor.'">'.$cpg_caption.'</FONT>';
  314.                                                         $output.='</a>';
  315.                                                         if($cpg_table!='')$output.='</TD>';
  316.  
  317.                                                          }
  318.  
  319.  
  320.  
  321.                                                 if($cpg_table!='')$output.='</TR></TABLE>';
  322.  
  323.  
  324.                         }
  325.  
  326.                  return $output;
  327.  }

Installation [edit]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/Coppermine.php");

Configuration parameters [edit]

Inside of the Coppermine.php file, you need to edit only two variables:

                $cpg_prefix =                           'cpg_';
                # Database prefix used for your coppermine tables
                $cpg_root  =                            'http://www.yoursitehere/gallery/';
                # Root of your coppermine install, so we can link to