Since: 1.0
Author: Kartik Visweswaran (kartikv2@gmail.com)
Inheritance: extends yii\base\Widget
Ejemplo n.º 1
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     static $initDone = false;
     $this->validPlugins = [self::COMMENTS, self::POST, self::COMMUNITY, self::LIKE, self::RECO, self::POLL, self::AUTH, self::SHARE, self::SUBSCRIBE];
     parent::init();
     $this->setConfig('vk');
     $initRequired = !in_array($this->type, [self::POST, self::COMMUNITY, self::SHARE, self::SUBSCRIBE]);
     $this->_initVk = $initRequired && !$initDone;
     if ($this->_initVk) {
         $initDone = true;
     }
     if (empty($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if (empty($this->type)) {
         throw new InvalidConfigException("The plugin 'type' must be set.");
     }
     if (empty($this->apiId) && $this->_initVk) {
         throw new InvalidConfigException("The VKontakte 'apiId' has not been set.");
     }
     if (!isset($this->noscript)) {
         $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript on your browser to view the VKontakte {pluginName} plugin correctly on this site.', ['pluginName' => Yii::t('kvsocial', str_replace('vk_', '', $this->type))]);
     }
     $this->_options = $this->options;
     $this->options = ['id' => $this->options['id'], 'class' => $this->type];
     unset($this->_options['id']);
     $this->registerAssets();
     echo $this->renderPlugin();
 }
Ejemplo n.º 2
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->setConfig('github');
     $this->settings['type'] = $this->type;
     if (empty($this->settings['repo'])) {
         throw new InvalidConfigException("The GitHub 'repository' has not been set.");
     }
     if (empty($this->settings['user'])) {
         throw new InvalidConfigException("The GitHub 'user' must be set.");
     }
     if (empty($this->settings['type'])) {
         throw new InvalidConfigException("The GitHub button 'type' has not been set.");
     }
     if (!isset($this->noscript)) {
         $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript on your browser to view the Facebook {pluginName} plugin correctly on this site.', ['pluginName' => Yii::t('kvsocial', str_replace('fb-', '', $this->type))]);
     }
     if (!empty($this->settings['count']) && ($this->settings['count'] || $this->settings['count'] == 'true')) {
         $this->settings['count'] = 'true';
     } else {
         unset($this->settings['count']);
     }
     $this->settings['v'] = 2;
     $large = !empty($this->settings['size']) && $this->settings['size'] == 'large';
     $defaultOptions = ['allowtransparency' => "true", 'frameborder' => 0, 'scrolling' => 0] + ($large ? ['width' => 170, 'height' => 30] : ['width' => 110, 'height' => 20]);
     $this->options = array_replace($defaultOptions, $this->options);
     $this->options['src'] = ltrim(Url::to([self::API] + $this->settings), Url::to(['/']));
     echo Html::tag('iframe', '', $this->options);
 }
Ejemplo n.º 3
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     $this->validPlugins = false;
     parent::init();
     $config = $this->setConfig('disqus');
     if ($this->credits === null) {
         $this->credits = Html::a(Yii::t('kvsocial', 'comments powered by Disqus'), 'http://disqus.com/?ref_noscript');
     }
     $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript to view the {pluginLink}.', ['pluginLink' => $this->credits]);
     if (empty($this->settings['shortname'])) {
         throw new InvalidConfigException("Disqus 'shortname' has not been set in settings.");
     }
     $variables = "";
     foreach ($this->settings as $key => $value) {
         $variables .= $key == 'disable_mobile' ? "var disqus_{$key} = {$value};\n" : "var disqus_{$key} = '{$value}';\n";
     }
     $params = ['variables' => $variables, 'credits' => $this->showCredits ? $this->credits : '', 'noscript' => $this->renderNoScript()];
     $view = $this->showCount ? 'disqus-count' : 'disqus-comments';
     echo $this->render($view, $params);
 }
Ejemplo n.º 4
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     $this->validPlugins = [self::LIKE, self::SHARE, self::SEND, self::POST, self::VIDEO, self::FOLLOW, self::COMMENT, self::PAGE];
     parent::init();
     $this->setConfig('facebook');
     if (empty($this->type)) {
         throw new InvalidConfigException("The plugin 'type' must be set.");
     }
     if (empty($this->appId)) {
         throw new InvalidConfigException("The Facebook 'appId' has not been set.");
     }
     if (!isset($this->noscript)) {
         $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript on your browser to view the Facebook {pluginName} plugin correctly on this site.', ['pluginName' => Yii::t('kvsocial', str_replace('fb-', '', $this->type))]);
     }
     $this->registerAssets();
     if ($this->type === self::COMMENT && empty($this->settings['data-href'])) {
         $this->settings['data-href'] = Yii::$app->request->getAbsoluteUrl();
     }
     $this->setPluginOptions();
     echo "<div id='fb-root'></div>\n" . $this->renderPlugin();
 }
Ejemplo n.º 5
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     $this->validPlugins = [self::SHARE, self::FOLLOW, self::HASHTAG, self::MENTION, self::TWEET, self::TIMELINE];
     parent::init();
     $this->tag = $this->type === self::TWEET ? 'blockquote' : 'a';
     $this->setConfig('twitter');
     $this->settings['lang'] = $this->language;
     if ($this->type === self::HASHTAG && empty($this->hashTag) && empty($this->options['data-href'])) {
         throw new InvalidConfigException("The Twitter 'hashTag' must be set for displaying the 'hashtag' button.");
     }
     if ($this->type !== self::SHARE && $this->type !== self::TWEET && empty($this->screenName)) {
         throw new InvalidConfigException("The Twitter 'screenName' must be set for displaying the " . str_replace('-', ' ', $this->type) . ".");
     }
     if ($this->type === self::TWEET && empty($this->content)) {
         throw new InvalidConfigException("The Twitter 'content' must be set for displaying 'embedded tweets'.");
     }
     if ($this->type === self::TIMELINE) {
         if (empty($this->settings['widget-id'])) {
             throw new InvalidConfigException("The Twitter \"settings['widget-id']\" must be set for displaying the twitter timeline.");
         }
     }
     if (!isset($this->noscript)) {
         $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript on your browser to view the Twitter {pluginName} plugin correctly on this site.', ['pluginName' => Yii::t('kvsocial', str_replace('twitter-', '', $this->type))]);
     }
     $this->registerAssets();
     $this->setPluginOptions();
     $screenName = Html::encode($this->screenName);
     switch ($this->type) {
         case self::FOLLOW:
             $this->options['href'] = "https://twitter.com/{$screenName}";
             break;
         case self::HASHTAG:
             $this->options['href'] = 'https://twitter.com/intent/tweet?button_hashtag=' . Html::encode($this->hashTag);
             $this->options['data-related'] = empty($this->options['data-related']) ? $screenName : $screenName . ',' . $this->options['data-related'];
             break;
         case self::MENTION:
             $this->options['href'] = "https://twitter.com/intent?screen_name={$screenName}";
             break;
         case self::TIMELINE:
             $this->options['href'] = "https://twitter.com/{$screenName}";
             $content = 'Tweets by @' . $this->screenName;
             if (isset($this->timelineConfig['listSlug'])) {
                 $slug = Html::encode($this->timelineConfig['listSlug']);
                 $this->options['href'] .= "/lists/{$slug}";
                 $this->options['data-list-slug'] = $slug;
                 if (!empty($this->options['data-list-owner-screen-name'])) {
                     $screenName = Html::encode($this->options['data-list-owner-screen-name']);
                 }
                 $this->options['data-list-owner-screen-name'] = $screenName;
                 $content = "Tweets from " . $this->options['href'];
             } elseif (isset($this->timelineConfig['search'])) {
                 $search = $this->timelineConfig['search'];
                 $isHash = substr($search, 0, 1) === '#';
                 if ($isHash) {
                     $search = substr($search, 1);
                 }
                 $search = Html::encode($search);
                 $this->options['href'] = $isHash ? "https://twitter.com/hashtag/{$search}" : "https://twitter.com/search?q={$search}";
                 $content = $this->timelineConfig['search'] . ' Tweets';
             } elseif (isset($this->timelineConfig['collectionId'])) {
                 $id = Html::encode($this->timelineConfig['collectionId']);
                 $this->options['href'] .= "/timelines/{$id}";
                 if (empty($this->options['data-custom-timeline-id'])) {
                     $this->options['data-custom-timeline-id'] = $id;
                 }
                 $content = ArrayHelper::getValue($this->timelineConfig, 'collectionName', '');
             } else {
                 $this->options['data-screen-name'] = $screenName;
             }
             if (empty($this->content)) {
                 $this->content = $content;
             }
             break;
     }
     echo $this->renderPlugin();
 }
Ejemplo n.º 6
0
 /**
  * Sets the options for the Google plugin
  */
 protected function setPluginOptions($convertLowerCase = true)
 {
     parent::setPluginOptions();
     if ($this->type === self::SIGNIN && empty($this->options["data-clientid"])) {
         $this->options["data-clientid"] = $this->clientId;
     } elseif ($this->type === self::SHARE && empty($this->options["data-action"])) {
         $this->options["data-action"] = 'share';
     } elseif ($this->type === self::BADGE_PERSON && empty($this->options["data-href"])) {
         $this->options["data-href"] = "https://plus.google.com/{$this->profileId}";
     } elseif ($this->type === self::BADGE_COMMUNITY && empty($this->options["data-href"])) {
         $this->options["data-href"] = "https://plus.google.com/communities/{$this->communityId}";
     } elseif (($this->type === self::FOLLOW || $this->type === self::BADGE_PAGE) && empty($this->options["data-href"])) {
         $this->options["data-href"] = "https://plus.google.com/{$this->pageId}";
     } elseif ($this->type === self::HANGOUT && empty($this->options["data-render"])) {
         $this->options["data-render"] = 'createhangout';
     }
 }
Ejemplo n.º 7
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     $this->validPlugins = false;
     parent::init();
     $this->setConfig('googleAnalytics');
     if (empty($this->id)) {
         throw new InvalidConfigException("Google analytics tracking 'id' has not been set.");
     }
     if (empty($this->domain)) {
         throw new InvalidConfigException("Google analytics tracking 'domain' has not been set.");
     }
     if ($this->anonymizeIp === self::HIT_ALL) {
         $this->jsBeforeSend .= "{$this->objectName}('set', 'anonymizeIp', true);\n";
     } elseif ($this->anonymizeIp === self::HIT_EACH && !is_string($this->sendConfig)) {
         $this->sendConfig['anonymizeIp'] = true;
     }
     if ($this->testMode === true && !is_string($this->trackerConfig)) {
         $this->trackerConfig['cookieDomain'] = 'none';
     }
     $trackerConfig = empty($this->trackerConfig) ? '' : ', ' . (is_array($this->trackerConfig) ? Json::encode($this->trackerConfig) : $this->trackerConfig);
     $sendConfig = empty($this->sendConfig) ? '' : ', ' . (is_array($this->sendConfig) ? Json::encode($this->sendConfig) : $this->sendConfig);
     $params = ['id' => $this->id, 'domain' => $this->domain, 'anonIp' => $this->anonymizeIp, 'obj' => $this->objectName, 'trackerConfig' => $trackerConfig, 'sendConfig' => $sendConfig, 'jsBeforeSend' => $this->jsBeforeSend, 'jsAfterSend' => $this->jsAfterSend, 'noscript' => $this->renderNoScript()];
     echo $this->render('google-analytics', $params);
 }
Ejemplo n.º 8
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->setConfig('githubX');
     if (empty($this->user)) {
         throw new InvalidConfigException("The GitHub 'user' must be set.");
     }
     if (empty($this->repo) && $this->type !== self::FOLLOW) {
         throw new InvalidConfigException("The GitHub 'repository' has not been set.");
     }
     if (empty($this->type)) {
         throw new InvalidConfigException("The GitHub button 'type' has not been set.");
     }
     if (!isset($this->noscript)) {
         $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript on your browser to view the Facebook {pluginName} plugin correctly on this site.', ['pluginName' => Yii::t('kvsocial', str_replace('fb-', '', $this->type))]);
     }
 }