- 26 września 2009
- 0 Comments
Strona główna
$db = &JFactory::getDBO();
$document = &JFactory::getDocument();
$path = PhocaGalleryPath::getPath();
$menu = &JSite::getMenu();
$document->addScript( JURI::base(true) . '/plugins/content/phocagalleryslideshow.js’);
// PARAMS – direct from Phoca Gallery Global configuration
$component = 'com_phocagallery’;
$table =& JTable::getInstance(’component’);
$table->loadByOption( $component );
$paramsC = new JParameter( $table->params );
// Start Plugin
$regex_one = '/({pgslideshow\s*)(.*?)(})/si’;
$regex_all = '/{pgslideshow\s*.*?}/si’;
$matches = array();
$count_matches = preg_match_all($regex_all,$article->text,$matches,PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER);
$customCSS = ”;
$customCSS2 = ”;
for($j = 0; $j < $count_matches; $j++) {
// Plugin variables
$id = 0;
$width = 200;
$height = 150;
$delay = 3000;
$image = 'M’;
$tmpl[’pgslink’] = 0;
$tmpl[’imageordering’] = $paramsC->get( 'image_ordering’, 9);
// Get plugin parameters
$phocagallery = $matches[0][$j][0];
preg_match($regex_one,$phocagallery,$phocagallery_parts);
$parts = explode(„|”, $phocagallery_parts[2]);
$values_replace = array („/^’/”, „/’$/”, „/^'/”, „/'$/”, „/<br \/>/”);
foreach($parts as $key => $value) {
$values = explode(„=”, $value, 2);
foreach ($values_replace as $key2 => $values2) {
$values = preg_replace($values2, ”, $values);
}
// Get plugin parameters from article
if($values[0]==’id’) {$id = $values[1];}
else if($values[0]==’height’) {$height = $values[1];}
else if($values[0]==’width’) {$width = $values[1];}
else if($values[0]==’delay’) {$delay = $values[1];}
else if($values[0]==’image’) {$image = $values[1];}
else if($values[0]==’pgslink’) {$tmpl[’pgslink’] = $values[1];}
else if($values[0]==’imageordering’) {$tmpl[’imageordering’] = $values[1];}
}
if ($id > 0) {
if ($tmpl[’imageordering’] == 9) {
$imageOrdering = ’ ORDER BY RAND()’;
} else {
$imageOrdering = ’ ORDER BY a.’.PhocaGalleryOrdering::getOrderingString($tmpl[’imageordering’]);
}
$c = time() * rand(0,10);
$query = ’ SELECT a.filename, cc.id,’
. ’ CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\’:\’, cc.id, cc.alias) ELSE cc.id END as catslug’
. ’ FROM #__phocagallery_categories AS cc’
. ’ LEFT JOIN #__phocagallery AS a ON a.catid = cc.id’
. ’ WHERE cc.published = 1 AND a.published = 1 AND a.catid = ’ . (int)$id
. $imageOrdering;
$db->setQuery($query);
$images = $db->loadObjectList();
$script = '<script type=”text/javascript”>’ . „\n”;
$script .= 'fadeimages’.$c.’ = new Array();’ . „\n”;
$n = count( $images );
for ($i = 0; $i < $n; $i++) {
switch ($image) {
case 'S’:
$imageName = PhocaGalleryFileThumbnail::getThumbnailName($images[$i]->filename, 'small’);
break;
case 'M’:
$imageName = PhocaGalleryFileThumbnail::getThumbnailName($images[$i]->filename, 'medium’);
break;
case 'O’:
$imageName->rel = PhocaGalleryFile::getFileOriginal($images[$i]->filename , 1);
break;
case 'L’:
$imageName = PhocaGalleryFileThumbnail::getThumbnailName($images[$i]->filename, 'large’);
default:
break;
}
$script .= 'fadeimages’.$c.'[’.$i.’] = [\” . JURI::base(true).’/’.$imageName->rel . '\’, \’\’, \’\’];’. „\n”;
}
$siteLink = ”;
if (isset($images[0]->id)) {
// ——————————————————————– SEF PROBLEM
// Is there an Itemid for category
$items = $menu->getItems(’link’, 'index.php?option=com_phocagallery&view=category&id=’.$images[0]->id);
$itemscat= $menu->getItems(’link’, 'index.php?option=com_phocagallery&view=categories’);
if(isset($itemscat[0])) {
$itemid = $itemscat[0]->id;
$itemIdOutput = '&Itemid=’.$itemid;
} else if(isset($items[0])) {
$itemid = $items[0]->id;
$itemIdOutput = '&Itemid=’.$itemid;
} else {
$itemid = 0;
$itemIdOutput = ”;
}
// ———————————————————————————
// Different Link – to all categories
if ((int)$tmpl[’pgslink’] == 2) {
$siteLink = 'index.php?option=com_phocagallery&view=categories&Itemid=’.$itemid;
}
// Different Link – to all category
else if ((int)$tmpl[’pgslink’] == 1) {
$siteLink = 'index.php?option=com_phocagallery&view=category&id=’.$images[0]->catslug.’&Itemid=’.$itemIdOutput;
}
}
//$script .= 'new fadeshow(fadeimages’.$c.’, ’.$width.’, ’.$height.’, 0, ’.$delay.’, 1, \’R\’)’ . „\n”;
// Added by Ingo
$script .= „function fadeshowladen”.$c.”() {\n”;
$script .= 'new fadeshow(fadeimages’.$c.’, ’.$width.’, ’.$height.’, 0, ’.$delay.’, 1, \’R\’, \’phocagallerycontent’.$c.’\’);’ . „\n”;
$script .= „}\n”;
$script .= „if(window.onload) {\n”;
$script .= „var temp = window.onload;\n”;
$script .= „window.onload=function(e) {\n”;
$script .= „temp(e);\n”;
$script .= „fadeshowladen”.$c.”();\n”;
$script .= „};\n}\n else{\n window.onload=function(e) {\n”;
$script .= „fadeshowladen”.$c.”();\n”;
$script .= „};\n}”;
/* $script .= 'new fadeshow(fadeimages’.$c.’, ’.$width.’, ’.$height.’, 0, ’.$delay.’, 1, \’R\’)’ . „\n”;*/
$script .= '</script>’. „\n”;
$output = ”;
$output .= '<div class=”phocagalleryslideshow” style=”text-align:center;”>’ . „\n”;
if ($siteLink != ”) {
$output .= '<a href=”’.$siteLink.'” ><span id=”phocagallerycontent’.$c.'”></span></a>’. „\n”;
} else {
$output .= '<div id=”phocagallerycontent’.$c.'”></div>’;
}
$output .=$script;
$output .='</div>’;
$c++;
$article->text = preg_replace($regex_all, $output, $article->text, 1);
}
}
return true;
}