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.
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.