PDA

Zobacz pełną wersję : Jak mieścić plugin w tytule artykułu w K2



grzegorzd
24-05-2012, 13:01
Mam plugin do k2, który ładuje się w zajawce artykułu. Chciałbym, żeby pojawiał się w lini w której znajduje się tytuł. Bawiłem się już kilkanaście godzin ale niestety nie dałem rady.

Poniżej funkcję odpowiedzialne za wstawianie kodu w dane miejsce



class plgContentITPShare extends JPlugin {

private $locale = "en_US";
private $fbLocale = "en_US";
private $plusLocale = "en";
private $twitterLocale = "en";
private $currentView = "";
private $currentTask = "";
private $currentOption = "";

public function __construct($subject, $params){

parent::__construct($subject, $params);

$app =& JFactory::getApplication();
/* @var $app JApplication */

if($app->isAdmin()) {
return;
}

// Get locale code automatically
if($this->params->get("dynamicLocale", 0)) {
$lang = JFactory::getLanguage();
$locale = $lang->getTag();
$this->locale = str_replace("-","_",$locale);
}

$this->currentView = JRequest::getCmd("view");
$this->currentTask = JRequest::getCmd("task");
$this->currentOption = JRequest::getCmd("option");

}

public function onPrepareContent(&$article, &$params = null, $limitstart = null){

if (!$article OR !isset($this->params) ) { return; };

$app =& JFactory::getApplication();
/** @var $app JApplication **/

if($app->isAdmin()) {
return;
}

$doc = JFactory::getDocument();
/** @var $doc JDocumentHtml **/
$docType = $doc->getType();

// Check document type
if(strcmp("html", $docType) != 0){
return;
}

// Generate context value
$context = $this->item->featured.".".$this->currentView;

// Set the context if the component is MyBlog
if(is_a($article, "myblogBlogContent")) {
$context = "com_myblog";
}

/*** Check for restrictions ***/
if($this->isRestricted($article, $context)) {
return;
}

if($this->params->get("loadCss")) {
$doc->addStyleSheet(JURI::root() . "plugins/content/itpshare/style.css");
}

// Generate content
$content = $this->getContent($article, $context);
$position = $this->params->get('position');

switch($position){
case 1:
$article->text = $content . $article->text;
break;
case 2:
$article->text = $article->text . $content; // mam wybraną tą opcję
break;
default:
$article->text = $content . $article->text . $content;
break;
}

return;
}

private function isRestricted($article, $context) {

$result = false;

switch($this->currentOption) {
case "com_content":
// It's an implementation of "com_myblog"
// I don't know why but $option contains "com_content" for a value
// I hope it will be fixed in the future versions of "com_myblog"
if(!strcmp($context, "com_myblog") == 0) {
if($this->isContentRestricted($article, $context)) {
$result = true;
}
break;
}

case "com_myblog":

if($this->isMyBlogRestricted($article, $context)) {
$result = true;
}

break;

case "com_k2":
if($this->isK2Restricted($article, $context)) {
$result = true;
}
break;

case "com_virtuemart":
if($this->isVirtuemartRestricted($article, $context)) {
$result = true;
}
break;

case "com_jevents":
if($this->isJEventsRestricted($article, $context)) {
$result = true;
}
break;

case "com_easyblog":
if($this->isEasyBlogRestricted($article, $context)) {
$result = true;
}
break;

default:
$result = true;
break;
}

return $result;

}

/**
*
* Checks allowed articles, exluded categories/articles,... for component COM_CONTENT
* @param object $article
*/
private function isContentRestricted($article) {

// Check where we are able to show buttons?
$showInArticles = $this->params->get('showInArticles');
$showInCategories = $this->params->get('showInCategories');
$showInSections = $this->params->get('showInSections');
$showInFrontPage = $this->params->get('showInFrontPage');

/** Check for selected views, which will display the buttons. **/
/** If there is a specific set and do not match, return an empty string.**/
if(!$showInArticles AND (strcmp("article", $this->currentView) == 0)){
return true;
}

if(!$showInCategories AND (strcmp("category", $this->currentView) == 0)){
return true;
}

if(!$showInSections AND (strcmp("section", $this->currentView) == 0)){
return true;
}

if(!$showInFrontPage AND (strcmp("frontpage", $this->currentView) == 0)){
return true;
}

// Exclude categories
$excludedCats = $this->params->get('excludeCats');
if(!empty($excludedCats)){
$excludedCats = explode(',', $excludedCats);
}
settype($excludedCats, 'array');
JArrayHelper::toInteger($excludedCats);

// Exclude sections
$excludeSections = $this->params->get('excludeSections');
if(!empty($excludeSections)){
$excludeSections = explode(',', $excludeSections);
}
settype($excludeSections, 'array');
JArrayHelper::toInteger($excludeSections);

// Exclude articles
$excludeArticles = $this->params->get('excludeArticles');
if(!empty($excludeArticles)){
$excludeArticles = explode(',', $excludeArticles);
}
settype($excludeArticles, 'array');
JArrayHelper::toInteger($excludeArticles);

// Included Articles
$includedArticles = $this->params->get('includeArticles');
if(!empty($includedArticles)){
$includedArticles = explode(',', $includedArticles);
}
settype($includedArticles, 'array');
JArrayHelper::toInteger($includedArticles);

if(!in_array($article->id, $includedArticles)) {
// Check exluded places
if(in_array($article->catid, $excludedCats) OR in_array($article->sectionid, $excludeSections) OR in_array($article->id, $excludeArticles)){
return true;
}
}

return false;
}

private function isK2Restricted(&$article, $context) {

// Check for currect context
if(strpos($context, "com_k2") === false) {
return true;
}

$displayInArticles = $this->params->get('k2DisplayInArticles', 0);
if(!$displayInArticles AND (strcmp("item", $this->currentView) == 0)){
return true;
}

$displayInItemlist = $this->params->get('k2DisplayInItemlist', 0); /* miejse do wywoływania ikonek*/
if(!$displayInItemlist AND (strcmp("itemlist", $this->currentView) == 0)){
return true;
}

return false;

}
private function getContent(&$article, $context){

$url = $this->getUrl($article, $context);
$title= $this->getTitle($article, $context);

/*** Convert the url to short one ***/
if($this->params->get("sService")) {
$url = $this->getShortUrl($url);
}


// Start buttons box
$html = '
<div class="itp-share">';

$html .= $this->getTwitter($this->params, $url, $title);
$html .= $this->getDigg($this->params, $url, $title);
$html .= $this->getStumbpleUpon($this->params, $url, $title);
$html .= $this->getLinkedIn($this->params, $url, $title);
$html .= $this->getTumblr($this->params, $url, $title);
$html .= $this->getBuffer($this->params, $url, $title);
$html .= $this->getPinterest($this->params, $url, $title, $urlCat);
$html .= $this->getReddit($this->params, $url, $title);
$html .= $this->getReTweetMeMe($this->params, $url, $title);

$html .= $this->getFacebookLike($this->params, $url, $title, $urlCat);
$html .= $this->getGooglePlusOne($this->params, $url, $title);
$html .= $this->getGoogleShare($this->params, $url, $title);

// Gets extra buttons
$html .= $this->getExtraButtons($this->params, $url, $title);

// End buttons box
$html .= '
</div>
<div style="clear:both;"></div>
';

return $html;
}



Jest tam jeszcze wiele innych funkcji ale one tylko odpowiadają za wygląda social wtyczek.
Proszę o pomoc.

tomaszek83
24-05-2012, 14:43
bez adresu strony to tylko do wróżki.

grzegorzd
29-05-2012, 13:21
Dokładniej chodzi o social media plugin ipshare . Link : madeforwomen.pl/tajemnice/index.php

tomaszek83
29-05-2012, 13:35
Musiałbyś lekko zmodyfikować szablon K2

components/com_k2/templates/default/

i w zależności od tego czy jest to widok artykułu czy blogu z artykułami zmienić położenie tych wpisów:


<!-- Plugins: BeforeDisplayContent -->
<?php echo $this->item->event->BeforeDisplayContent; ?>

<!-- K2 Plugins: K2BeforeDisplayContent -->
<?php echo $this->item->event->K2BeforeDisplayContent; ?>

grzegorzd
29-05-2012, 13:43
możesz dokładniej przybliżyć o co chodzi bo nie do końca oriętuje się jak powinienem zmienić połoźenie tych wpisów.

Nawet jak usunąłe:




<!-- Plugins: AfterDisplayTitle -->
<?php echo $this->item->event->AfterDisplayTitle; ?>

<!-- K2 Plugins: K2AfterDisplayTitle -->
<?php echo $this->item->event->K2AfterDisplayTitle; ?>


<!-- Plugins: BeforeDisplayContent -->
<?php echo $this->item->event->BeforeDisplayContent; ?>

<!-- K2 Plugins: K2BeforeDisplayContent -->
<?php echo $this->item->event->K2BeforeDisplayContent; ?>


to pozycja pozostaje bez zmian.

tomaszek83
29-05-2012, 14:37
w katalogu components/com_k2/templates/nazwa_układu_k2_który_wykorzystujesz/ (domyślnie jest to default)

masz pliki:

category.php
category_item.php
category_item_links.php
item.php
item_comments_form.php
itemform.php
latest.php
latest_item.php
tag.php
user.php

są to widoki w zależności od tego czy wyświetlasz sam artykuł czy blog artykułów z danej kategorii.

To co przytoczyłeś w pierwszym poście to jest kod pluginu. A ty musisz zmienić jego położenie w szablonie K2. Nie wiem jaki wygląd masz przypisany. Napisałem Ci jak to wygląda w przypadku widoku domyślnego.

grzegorzd
29-05-2012, 14:57
Ja dokładnie wiem o co chodzi z tylko nie wiem jak to zmienić. Poniżej fragment kodu do którego następuje załadowanie pluginu.


<div class="catItemView group<?php echo ucfirst($this->item->itemGroup); ?><?php echo ($this->item->featured) ? ' catItemIsFeatured' : ''; ?><?php if($this->item->params->get('pageclass_sfx')) echo ' '.$this->item->params->get('pageclass_sfx'); ?>">

<!-- Plugins: BeforeDisplay -->
<?php echo $this->item->event->BeforeDisplay; ?>

<!-- K2 Plugins: K2BeforeDisplay -->
<?php echo $this->item->event->K2BeforeDisplay; ?>

<div class="catItemHeader<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">

<?php if($this->item->params->get('catItemTitle')): ?>
<!-- Item title -->
<h3 class="catItemTitle<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">
<?php if(isset($this->item->editLink)): ?>
<!-- Item edit link -->
<span class="catItemEditLink">
<a class="modal" rel="{handler:'iframe',size:{x:990,y:550}}" href="<?php echo $this->item->editLink; ?>">
<?php echo JText::_('K2_EDIT_ITEM'); ?>
</a>
</span>
<?php endif; ?>

<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>

<?php if($this->item->params->get('catItemFeaturedNotice') && $this->item->featured): ?>
<!-- Featured flag -->
<span>
<sup>
<?php echo JText::_('K2_FEATURED'); ?>
</sup>
</span>
<?php endif; ?>
</h3>
<?php endif; ?>
<?php if($this->item->params->get('catItemDateCreated')): ?>
<!-- Date created -->
<span class="catItemDateCreated<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">
<?php echo JHTML::_('date', $this->item->created , JText::_('K2_DATE_FORMAT_LC2')); ?>
</span>
<?php endif; ?>
<?php if($this->item->params->get('catItemAuthor')): ?>
<!-- Item Author -->
<span class="catItemAuthor<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">
<?php echo K2HelperUtilities::writtenBy($this->item->author->profile->gender); ?> <a rel="author" href="<?php echo $this->item->author->link; ?>"><?php echo $this->item->author->name; ?></a>
</span>
<?php endif; ?>
</div>

<!-- Plugins: AfterDisplayTitle -->
<?php echo $this->item->event->AfterDisplayTitle; ?>

<!-- K2 Plugins: K2AfterDisplayTitle -->
<?php echo $this->item->event->K2AfterDisplayTitle; ?>

<?php if($this->item->params->get('catItemRating')): ?>
<!-- Item Rating -->
<div class="catItemRatingBlock">
<span><?php echo JText::_('K2_RATE_THIS_ITEM'); ?></span>
<div class="itemRatingForm">
<ul class="itemRatingList">
<li class="itemCurrentRating" id="itemCurrentRating<?php echo $this->item->id; ?>" style="width:<?php echo $this->item->votingPercentage; ?>%;"></li>
<li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_1_STAR_OUT_OF_5'); ?>" class="one-star">1</a></li>
<li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_2_STARS_OUT_OF_5'); ?>" class="two-stars">2</a></li>
<li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_3_STARS_OUT_OF_5'); ?>" class="three-stars">3</a></li>
<li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_4_STARS_OUT_OF_5'); ?>" class="four-stars">4</a></li>
<li><a href="#" rel="<?php echo $this->item->id; ?>" title="<?php echo JText::_('K2_5_STARS_OUT_OF_5'); ?>" class="five-stars">5</a></li>
</ul>
<div id="itemRatingLog<?php echo $this->item->id; ?>" class="itemRatingLog"><?php echo $this->item->numOfvotes; ?></div>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
<?php endif; ?>

<div class="catItemBody<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">

<!-- Plugins: BeforeDisplayContent -->
<?php echo $this->item->event->BeforeDisplayContent; ?>

<!-- K2 Plugins: K2BeforeDisplayContent -->
<?php echo $this->item->event->K2BeforeDisplayContent; ?>
<?
$tajemnice = $this->params->get('pageclass_sfx');

if($tajemnice == "_tajemnice" || $tajemnice == "_konkurs" || $tajemnice == "_projektanci"): ?>

<?php if($this->item->params->get('catItemImage') && !empty($this->item->image)): ?>
<!-- Item Image -->
<div class="catItemImageBlock<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">
<span class="catItemImage<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">
<a href="<?php echo $this->item->link; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
</a>
</span>
<?php if($this->item->params->get('itemImageMainCaption') && !empty($this->item->image_caption)): ?>
<!-- Image caption -->
<span class="itemImageCaption<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>"><?php echo $this->item->image_caption; ?></span>
<?php endif; ?>

<?php if($this->item->params->get('itemImageMainCredits') && !empty($this->item->image_credits)): ?>
<!-- Image credits -->
<span class="itemImageCredits<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>"><?php echo $this->item->image_credits; ?></span>
<?php endif; ?>

<div class="clr"></div>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php endif; ?>
<?
$tajemnice = $this->params->get('pageclass_sfx');

if($tajemnice == "_mediaonas" || $tajemnice == "_wydarzenia"): ?>

<?php if($this->item->params->get('catItemImage') && !empty($this->item->image)): ?>
<!-- Item Image -->
<div class="catItemImageBlock<?php if($this->item->params->get('pageclass_sfx')) echo ''.$this->item->params->get('pageclass_sfx'); ?>">
<span class="catItemImage<?php if($this->item->params->get('pageclass_sfx')) echo ''.$this->item->params->get('pageclass_sfx'); ?>">
<a class="modal" rel="{handler: 'image'}" href="<?php echo $this->item->imageXLarge; ?>" title="<?php echo JText::_('K2_CLICK_TO_PREVIEW_IMAGE'); ?>">
<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
</a>
</span>
<?php if($this->item->params->get('itemImageMainCaption') && !empty($this->item->image_caption)): ?>
<!-- Image caption -->
<span class="itemImageCaption<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>"><?php echo $this->item->image_caption; ?></span>
<?php endif; ?>

<?php if($this->item->params->get('itemImageMainCredits') && !empty($this->item->image_credits)): ?>
<!-- Image credits -->
<span class="itemImageCredits<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>"><?php echo $this->item->image_credits; ?></span>
<?php endif; ?>

<div class="clr"></div>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText<?php if($this->params->get('pageclass_sfx')) echo ''.$this->params->get('pageclass_sfx'); ?>">
<?php echo $this->item->introtext; ?>
</div>
<?php endif; ?>

Jeżeli przekopiuje ten fragment:
<?php echo $this->item->introtext; ?> to cała "zajawka" wraz z pluginem zmieni położenie, a chciałbym tylko plugin.

tomaszek83
29-05-2012, 20:02
powiem szczerze że wymiękam. Musiałbym zainstalować sobie gdzieś ten plugin i przetestować co i jak. Ale widzę że już zmieniłeś jego położenie bo teraz jest pod datą, a nie pod obrazkiem.

grzegorzd
30-05-2012, 11:27
jest pod datą, ponieważ, nie ma w pierwszym artykule zajawki, wstępu. Jest możliwość, albo ustawienia w zajawcę, albo w tekście głównym. Niestety nie wiem jak zrobić, żeby umieścić go w innym miejscu, choćby przed zdjęciem w zajawce....masakra

grzegorzd
31-05-2012, 16:23
Rozwiązanie okazało się banalnie proste. Żal straconych godzin..., ale każdy uczy się na błędech.

Straciłem nadzieje, że uda mi się to zrobić, ale po kilku mailach do autora, przez przypadek natknąłem się na rozwiązanie na jego stronie ;-)

Wystarczyło zamiast zwykłego itpshare zainstalować ITPsharepoint który pozwala umieszcząć plugin w dowolnym miejscu, czy w artykule, czy kodzie strony...