<?php

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


class ToolTwitter extends ToolBase
{
  public function __construct()
  {
    parent::__construct();
    $this->toolTitle = 'Twitter-Nachrichten';
  }

  
  public function init($pPageId)
  {
    switch ($pPageId) {
      default:
      case 269:
        $page = new PageTwitter($this);
        break;
    }
    if ($page == null) {
      throw new Exception('ungültige PageId');
    }
    $this->currentPage = $page;
  }

  public function getToolId()
  {
    return \ToolsAPI::TOOL_TWITTER;
  }
}

class PageTwitter extends PageBaseWT
{
  public function __construct($pTool)
  {
    parent::__construct('Twitter', 269, $pTool);
  }

  
  public function getContentHeader()
  {
    return 'Twitter-Nachrichten';
  }

  
  public function getContent()
  {
    $sicht = '<div class="twittercontent">';
    $sicht .= $this->_getTwitterProfileWidget();
    $sicht .= '</div>';

    return $sicht;
  }

  public function getSpecialJS()
  {
    return array();
  }

  
  private function _getTwitterProfileWidget()
  {
    if (trim($this->toolSettings->widget) == '') {
      return HTMLOperations::getInfoBox('Das Twitter-Tool muss erst konfiguriert werden.', 'Hinweis');
    } else {
      $widget = $this->toolSettings->widget;
      $widget .= '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';

      return $widget;
    }
  }
}