PDA

Zobacz pełną wersję : AtomSMS i Atachments



skydeath
21-10-2009, 21:46
Witam.

czy ktoś mógłby rzucić okiem...

Używam Komponentu AtomSMS który zamiast artykułu wyświetla informacje o SMS, oraz komponentu atachments do obsługi załączników.

Problem w tym że załączniki wyświetlają się pod informacją o sms, a chciałbym aby były dopiero widoczne po opłaceniu razem z treścią artykułu.

atomsms-dostep.php:

<?php
/**
* @version $Id: atomsms-dostep.php 2009-01-12
* @package Joomla
* @copyright Copyright (C) Atom.SMS http://www.atomsms.pl/
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
$mainframe->registerEvent('onPrepareContent', 'plgContentAtomSmsDostep');

/**
* Mambot platnosci SMS za dostep do tresci
*/
function plgContentAtomSmsDostep( &$row, &$params, $page=0 ) {
if(($pos = strpos($row->text, '{sms-dostep')) === false)
return true;

$group = 1;
$zone = 'strefa1';
$err = '';
if($pos2 = strpos($row->text, '}', $pos+11)) {
$acc = substr($row->text, $pos+11, $pos2-$pos-11);
$accpars = explode(' ', strtolower($acc));
foreach($accpars as $accpar) {
if(!strlen($accpar)) continue;
switch($accpar[0]) {
case 'g':
if(strlen($accpar) == 2
&& in_array($accpar[1], array('1','2','3')))
$group = (int)$accpar[1];
else
$err .= "Nieprawidlowa grupa cenowa {sms-dostep}<br />\n";
break;
case 's':
$zone = substr($accpar, 1);
break;
}
}
}
else
$err = "Nieprawidlowy kwalifikator {sms-dostep}<br />\n";

// load atomsms-dostep info
$plugin = & JPluginHelper::getPlugin('content', 'atomsms-dostep');
$params = new JParameter( $plugin->params );

$GLOBALS['sms_dostep_prefix'] = $params->get('sms_dostep_prefix', 'MPLX3');
$GLOBALS['sms_dostep_klucz'] = $params->get('sms_dostep_klucz', '5fe8313c8c77419389e2332c87dd1eda');
$GLOBALS['sms_dostep_test'] = (int) $params->get('sms_dostep_test', 1);
$GLOBALS['sms_dostep_kodowanie'] = $params->get('sms_dostep_kodowanie', 'iso');
switch($params->get('sms_dostep_strefy', '1')) { // definicja stref
case 'S': $zone = "S{$row->sectionid}"; break;
case 'C': $zone = "C{$row->catid}"; break;
case 'A': $zone = "A{$row->id}"; break;
}
require_once( JPATH_SITE . '/plugins/content/atomsms/sms-dostep-j15.php' );

$times = array(1=>'M60', 2=>'H24', 3=>'D7');
$tars = array(1=>1, 2=>5, 3=>9);
$paid = false;
$strefa = "G{$group}_S{$zone}";
for($n = 1; $n <= 3; $n++) {
$time = $params->get("sms_dostep_czas_{$group}{$n}", $times[$n]);
if($time == '0') continue;
$tar = $params->get("sms_dostep_taryfa_{$group}{$n}", $tars[$n]);
if($paid = sms_dostep($tar, $time[0], (int)substr($time,1), $strefa, true)) break;
}
if($paid) { // oplacone
$row->text = preg_replace('/\{sms-dostep[^}]*\}/', '', $row->text);
}
else { // nie oplacone
$row->text = sms_dostep_pokaz($strefa, $row->title);
}

if($err) $row->text = $err . $row->text;
return true;
}
?>atachment.php

<?php
defined('_JEXEC') or die('Restricted access');
/**
* Attachments plugin
* @package Attachments
* @Copyright (C) 2007, 2008 Jonathan M. Cameron, All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @link http://joomlacode.org/gf/project/attachments/frs/
* @author Jonathan M. Cameron
**/

$mainframe->registerEvent('onAfterDispatch', 'addAttachmentsStyleSheet');
$mainframe->registerEvent('onPrepareContent', 'addAttachments');
// was: $mainframe->registerEvent('onAfterDisplayContent', 'addAttachments');


function addAttachmentsStyleSheet()
{
$document = & JFactory::getDocument();
$document->addStyleSheet( JURI::base() . 'plugins/content/attachments.css',
'text/css', null, array() );
}


function attachments_attachmentListHTML($article_id, $user_can_add, $Itemid, $from)
{
require_once(JPATH_SITE.DS.'components'.DS.'com_at tachments'.DS.'helper.php');

// Generate the HTML for the attachments for the specified article
$alist = "";
$db =& JFactory::getDBO();
$query = "SELECT count(*) FROM #__attachments WHERE article_id='" . $article_id . "' AND published='1'";
$db->setQuery($query);
$total = $db->loadResult();
if ( $total > 0 ) {

// Get the component parameters
jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams('com_attachments');

// Check the security status
$attach_dir = JPATH_SITE.DS.$params->get('upload_dir', 'attachments');
$secure = $params->get('secure', false);
$hta_filename = $attach_dir.DS.'.htaccess';
if ( ($secure && !file_exists($hta_filename)) ||
(!$secure && file_exists($hta_filename)) ) {
AttachmentsHelper::setup_upload_directory($attach_ dir, $secure);
}

$alist = AttachmentsHelper::attachmentsTableHTML($article_i d, false, true, true, $from);
}

return $alist;
}


function attachments_attachmentButtonsHTML($article_id, $Itemid, $from)
{
$document = & JFactory::getDocument();
$document->addScript( JURI::root(true).'/media/system/js/modal.js' );
JHTML::_('behavior.modal', 'a.modal-button');

// Generate the HTML for a button for the user to click to get to a form to add an attachment
$url = "index.php?option=com_attachments&task=upload&artid=$article_id&tmpl=component";
if ( $from ) {
// Add a var to give a hint of where to return to
// $url .= "&from=$from";
$url .= "&from=closeme";
}
$url = JRoute::_($url);
$icon_url = JURI::Base() . 'components/com_attachments/media/add_attachment.gif';

$add_attachment_txt = JText::_('ADD ATTACHMENT');
$ahead = '<a class="modal-button" type="button" href="' . $url . '" ';
$ahead .= "rel=\"{handler: 'iframe', size: {x: 900, y: 550}}\">";
$links = "$ahead<img src=\"$icon_url\" alt=\"$add_attachment_txt\" /></a>";
$links .= $ahead.$add_attachment_txt."</a>";
return "\n<div class=\"addattach\">$links</div>\n";

// The old way (save; may need for <noscript>)
// return "\n<div class=\"addattach\"><a href=\"$url\"><img src=\"$icon_url\" alt=\"\" /></a>&nbsp;<a href=\"$url\">" . JText::_('ADD ATTACHMENT') . "</a></div>\n";
}


function addAttachments( &$row, &$params, $page=0 )
{
// Only display attachments for content (articles)
global $option;
if ( $option != 'com_content' )
return;

// Apparently this is called before articles are displayed (ignore those calls)
if ( !isset($row->id) )
return;

// Get the component parameters
jimport('joomla.application.component.helper');
$attachParams = JComponentHelper::getParams('com_attachments');

// Get some of the options
$user =& JFactory::getUser();
$logged_in = $user->get('username') <> '';
$user_type = $user->get('usertype', false);

// Load the language files from the backend
$lang = & JFactory::getLanguage();
$lang->load('plg_frontend_attachments', JPATH_ADMINISTRATOR);

// See whether we can display the links to add attachments
require_once(JPATH_SITE.DS.'components'.DS.'com_at tachments'.DS.'permissions.php');
if ( AttachmentsPermissions::attachments_hidden_for_art icle($row->id, $attachParams) ) {
return;
}
$user_can_add = AttachmentsPermissions::user_may_add_attachment($u ser, $row->id);

// Determine where we are
global $option;
$from = JRequest::getVar( 'view', false);
$Itemid = JRequest::getVar( 'Itemid', false);
if ( is_numeric($Itemid) )
$Itemid = intval($Itemid);
else
$Itemid = 1;

// Show the attachment list (if appropriate)
$who_can_see = $attachParams->get('who_can_see', 'logged_in');

if ( ( $who_can_see == 'anyone' ) ||
( ($who_can_see == 'logged_in') && $logged_in ) ) {
$row->text .= attachments_attachmentListHtml($row->id, $user_can_add, $Itemid, $from);
}

if ( $user_can_add ) {
$row->text .= attachments_attachmentButtonsHTML($row->id, $Itemid, $from);
}
}

?>
Z góry dzięki za pomoc.

Jola
21-10-2009, 21:58
Witam,
można spróbować tak zmienić kolejność pluginów żeby atachments wykonywał się przed AtomSMS. Jeśli to nie zadziała, trzeba będzie dopisać w pluginie atachments warunek sprawdzający czy jest zapłacone.

skydeath
21-10-2009, 22:25
Kolejność pluginów zdała egzamin :-) Wielkie Dzięki!