Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->adClient)) {
         $this->adClient = Setting::getValue('adsense');
     }
 }
Exemplo n.º 2
0
 public static function register()
 {
     $js = Setting::getValue('headJs');
     if (!empty($js)) {
         $view = Yii::$app->getView();
         $view->registerJs($js, View::POS_HEAD);
     }
 }
Exemplo n.º 3
0
 public static function register()
 {
     if (!Core::isInMemberAreaPage() && Yii::$app->id != 'app-backend') {
         if ($id = Setting::getValue('addthis')) {
             Yii::$app->view->registerJsFile('//s7.addthis.com/js/300/addthis_widget.js#pubid=' . $id);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $shortname = Setting::getValue('disqus');
     if (!empty($shortname)) {
         $js = $this->registerVariables($shortname);
         Yii::$app->view->registerJs($js, \yii\web\View::POS_END);
         echo Html::tag('div', '', ['id' => 'disqus_thread']);
     }
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $tracking = Setting::getValue('amzTracking');
     $searchAds = Setting::getValue('amzSearchAds');
     if (!empty($tracking) && !empty($searchAds)) {
         return $this->render('amzSearchAds', ['tracking' => $tracking, 'searchAds' => $searchAds]);
     }
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     /* facebook */
     if (empty($this->fb['appId'])) {
         $this->fb['appId'] = Setting::getValue('fbAppId');
     }
     if (empty($this->fb['language'])) {
         $this->fb['language'] = str_ireplace('-', '_', Yii::$app->language);
     }
 }
 /**
  * set new email
  * @return bool
  */
 public function changeEmail()
 {
     $user = Yii::$app->user->identity;
     if (!Account::isTokenValid($user->change_email_token)) {
         $user->generateChangeEmailToken();
     }
     $user->new_email = $this->newEmail;
     if ($user->save()) {
         Yii::$app->language = $user->language;
         $subject = Yii::t('app', '[{APP_NAME}] Please verify your email address', ['APP_NAME' => Yii::$app->name]);
         return Yii::$app->mailer->compose(['html' => 'change-email-html', 'text' => 'change-email-text'], ['title' => $subject, 'user' => $user])->setFrom([Setting::getValue('outgoingMail')])->setTo($user->new_email)->setSubject($subject)->send();
     }
     return false;
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     $user = Account::findOne(['status' => Account::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!Account::isTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             $email = Yii::$app->mailer->compose(['html' => 'password-reset-token-html', 'text' => 'password-reset-token-text'], ['user' => $user])->setFrom([Setting::getValue('outgoingMail') => \Yii::$app->name])->setTo($this->email)->setSubject(Yii::t('app', 'Password reset for {APP_NAME}', ['APP_NAME' => \Yii::$app->name]));
             return $email->send();
         }
     }
     return false;
 }
Exemplo n.º 9
0
    /**
     * @inheritdoc
     */
    public function run()
    {
        $baseUrl = Yii::$app->request->baseUrl;
        $themeColor = Setting::getValue('androidThemeColor');
        $data = <<<EOB
<link rel="apple-touch-icon" sizes="180x180" href="{$baseUrl}/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" href="{$baseUrl}/favicon/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="{$baseUrl}/favicon/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="{$baseUrl}/favicon/manifest.json">
<link rel="mask-icon" href="{$baseUrl}/favicon/safari-pinned-tab.svg" color="{$themeColor}">
<meta name="msapplication-config" content="{$baseUrl}/favicon/browserconfig.xml">
<meta name="theme-color" content="{$themeColor}">
EOB;
        return $data;
    }
Exemplo n.º 10
0
    public static function register()
    {
        $id = Setting::getValue('googleAnalytics');
        if (!empty($id)) {
            $js = <<<EOB
(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,"script","https://www.google-analytics.com/analytics.js","ga");
ga("create", "{$id}", "auto");
ga("send", "pageview");
EOB;
            $view = Yii::$app->getView();
            $view->registerJs($js, View::POS_HEAD);
        }
    }
Exemplo n.º 11
0
 /**
  * for user account settings
  * @param $e [] exception
  * @return array
  */
 public static function getLocaleList($e = [])
 {
     /* current translation languages */
     $l = (new Query())->select(['language'])->distinct()->from('{{%core_message}}')->column();
     $l[] = Yii::$app->sourceLanguage;
     /* site default language */
     $default = Setting::getValue('language');
     if (!in_array($default, $l)) {
         $l[] = $default;
     }
     $list = Core::getLocaleList($l);
     /* exception */
     if (is_array($e)) {
         foreach ($e as $key) {
             unset($list[$key]);
         }
     }
     return $list;
 }
Exemplo n.º 12
0
<?php

/* @var $this yii\web\View */
use common\models\Setting;
$this->title = Yii::$app->name;
$keywords = Setting::getValue('keywords');
$description = Setting::getValue('description');
$this->registerMetaTag(['name' => 'keywords', 'content' => Yii::t('app', $keywords)]);
$this->registerMetaTag(['name' => 'description', 'content' => Yii::t('app', $description)]);
//$this->registerMetaTag(['name' => 'robots', 'content' => 'noindex, nofollow, nosnippet, noodp, noarchive, noimageindex']);
/* Facebook */
//$this->registerMetaTag(['property' => 'og:title', 'content' => $this->title]);
//$this->registerMetaTag(['property' => 'og:description', 'content' => $description]);
//$this->registerMetaTag(['property' => 'og:type', 'content' => '']);
//$this->registerMetaTag(['property' => 'og:image', 'content' => '']);
//$this->registerMetaTag(['property' => 'og:url', 'content' => '']);
//$this->registerMetaTag(['property' => 'fb:app_id', 'content' => '']);
//$this->registerMetaTag(['property' => 'fb:admins', 'content' => '']);
/* Twitter */
//$this->registerMetaTag(['name'=>'twitter:title', 'content'=>$this->title]);
//$this->registerMetaTag(['name'=>'twitter:description', 'content'=>$description]);
//$this->registerMetaTag(['name'=>'twitter:card', 'content'=>'summary']);
//$this->registerMetaTag(['name'=>'twitter:site', 'content'=>'']);
//$this->registerMetaTag(['name'=>'twitter:image', 'content'=>'']);
//$this->registerMetaTag(['name'=>'twitter:data1', 'content'=>'']);
//$this->registerMetaTag(['name'=>'twitter:label1', 'content'=>'']);
//$this->registerMetaTag(['name'=>'twitter:data2', 'content'=>'']);
//$this->registerMetaTag(['name'=>'twitter:label2', 'content'=>'']);
/* breadcrumbs */
//$this->params['breadcrumbs'][] = ['label' => 'label', 'url' => '#'];
?>
Exemplo n.º 13
0
    /**
     * This is page where google search result displayed
     * @param null $q
     * @return string|Response
     */
    public function actionSearch($q = null)
    {
        if (empty($q)) {
            return $this->redirect(Yii::$app->request->referrer);
        }
        $data['title'] = Yii::t('app', 'Search Result');
        $keywords = Yii::t('app', 'search result, search');
        $description = Yii::t('app', 'Search our website');
        $metaTags[] = ['name' => 'keywords', 'content' => $keywords];
        $metaTags[] = ['name' => 'description', 'content' => $description];
        $metaTags[] = ['name' => 'robots', 'content' => 'noindex, nofollow, nosnippet, noodp, noarchive, noimageindex'];
        $data['metaTags'] = $metaTags;
        $this->registerMetaTagJsonLD($data);
        /* js */
        $cx = Setting::getValue('googleCustomSearch');
        if (empty($cx)) {
            return $this->redirect(Yii::$app->homeUrl);
        }
        $js = <<<EOB
(function() {
    var cx = "{$cx}";
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
})();
EOB;
        $this->view->registerJs($js, View::POS_HEAD);
        return $this->render('search');
    }
Exemplo n.º 14
0
"/>
                </a>
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#navbar-collapse">
                    <?php 
echo Icon::widget(['icon' => 'bars']);
?>
                </button>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse pull-left" id="navbar-collapse">
                <?php 
echo Nav::widget(['options' => ['class' => 'navbar-nav'], 'items' => $items]);
?>
                <?php 
if (!empty(Setting::getValue('googleCustomSearch'))) {
    ?>
                    <form class="navbar-form navbar-left" role="search" action="<?php 
    echo Yii::$app->urlManager->createUrl(['/site/search']);
    ?>
">
                        <div class="input-group input-group-sm">
                            <input name="q" value="<?php 
    echo Yii::$app->request->get('q');
    ?>
" type="text" class="form-control" placeholder="<?php 
    echo Yii::t('app', 'Search');
    ?>
">
                            <span class="input-group-btn">
                      <button type="submit" class="btn btn-default btn-flat">
Exemplo n.º 15
0
 /**
  * Finds out if change email token is valid
  *
  * @param string $token change email token
  * @return boolean
  */
 public static function isTokenValid($token)
 {
     if (empty($token)) {
         return false;
     }
     $expire = Setting::getValue('tokenExpiryTime');
     $parts = explode('_', $token);
     $timestamp = (int) end($parts);
     return $timestamp + $expire >= time();
 }
Exemplo n.º 16
0
 /**
  * check if reCaptcha enabled
  * @return bool
  */
 public static function isReCaptchaEnabled()
 {
     $rcKey = Setting::getValue('reCaptchaKey');
     $rcSecret = Setting::getValue('reCaptchaSecret');
     if (!empty($rcKey) && !empty($rcSecret)) {
         return true;
     }
     return false;
 }
Exemplo n.º 17
0
 /**
  * handle
  */
 public function handle()
 {
     $attributes = $this->client->getUserAttributes();
     // common
     $continue = false;
     $id = ArrayHelper::getValue($attributes, 'id');
     $fullname = '';
     $email = '';
     // google
     if ($this->client->getName() == 'google') {
         $fullname = ArrayHelper::getValue($attributes, 'displayName');
         $emails = ArrayHelper::getValue($attributes, 'emails');
         $email = $emails[0]['value'];
         $continue = true;
     }
     // facebook
     if ($this->client->getName() == 'facebook') {
         $fullname = ArrayHelper::getValue($attributes, 'name');
         $email = ArrayHelper::getValue($attributes, 'email');
         $continue = true;
     }
     if (!$continue) {
         //            Yii::$app->getSession()->setFlash('info', [
         //                Yii::t('app', 'Flickr'),
         //            ]);
         //Yii::$app->user->setReturnUrl(Yii::$app->request->referrer);
         return;
     }
     /* @var Auth $auth */
     $auth = Auth::find()->where(['source' => $this->client->getId(), 'source_id' => $id])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             // login
             /* @var Account $user */
             $user = $auth->user;
             $this->updateUserInfo($user);
             Yii::$app->user->login($user, Setting::getValue('rememberMeDuration'));
         } else {
             // signup
             if ($email !== null && Account::find()->where(['email' => $email])->exists()) {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $this->client->getTitle()])]);
             } else {
                 $password = Yii::$app->security->generateRandomString(6);
                 $user = new Account(['fullname' => $fullname, 'email' => $email, 'password' => $password]);
                 $user->generateAuthKey();
                 $user->generatePasswordResetToken();
                 $transaction = Account::getDb()->beginTransaction();
                 //file_put_contents('D:\log', json_encode($transaction));
                 if ($user->save()) {
                     $auth = new Auth(['user_id' => $user->id, 'source' => $this->client->getId(), 'source_id' => (string) $id]);
                     if ($auth->save()) {
                         $transaction->commit();
                         Yii::$app->user->login($user, Setting::getValue('rememberMeDuration'));
                     } else {
                         $transaction->rollBack();
                         Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to save {client} account: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($auth->getErrors())])]);
                     }
                 } else {
                     $transaction->rollBack();
                     Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to save user: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($user->getErrors())])]);
                 }
             }
         }
     } else {
         // user already logged in
         Yii::$app->user->setReturnUrl(Yii::$app->request->referrer);
         if (!$auth) {
             // add auth provider
             $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $this->client->getId(), 'source_id' => (string) $attributes['id']]);
             if ($auth->save()) {
                 /** @var Account $user */
                 $user = $auth->user;
                 $this->updateUserInfo($user);
                 Yii::$app->getSession()->setFlash('success', [Yii::t('app', 'Linked {client} account.', ['client' => $this->client->getTitle()])]);
             } else {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to link {client} account: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($auth->getErrors())])]);
             }
         } else {
             // there's existing auth
             Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to link {client} account. There is another user using it.', ['client' => $this->client->getTitle()])]);
         }
     }
 }
Exemplo n.º 18
0
 public function init()
 {
     parent::init();
     // TODO: Change the autogenerated stub
     if (in_array($this->perms, ['read', 'write', 'delete'])) {
         $this->authUrl .= '?perms=' . $this->perms;
     }
     if (empty($this->consumerKey) or empty($this->consumerSecret)) {
         $this->consumerKey = Setting::getValue('flickrClientKey');
         $this->consumerSecret = Setting::getValue('flickrClientSecret');
     }
 }
Exemplo n.º 19
0
 /**
  * Displays a single Blog model.
  * @param string $name
  * @return mixed
  */
 public function actionView($name)
 {
     $this->layout = 'main';
     $model = $this->findBySlug($name);
     //        $new=new Blog();
     //        $new->attributes=$model->attributes;
     //        $new->slug=$new->slug.'-'.rand(1000,9999);
     //        $new->id=null;
     //        if(!$new->save()){
     //            var_dump($new->errors);
     //        }
     /* views ++ */
     $model->updateViews();
     /* metaData */
     $title = $model->title;
     $keywords = $model->tags;
     $description = $model->desc;
     $metaTags[] = ['name' => 'keywords', 'content' => $keywords];
     $metaTags[] = ['name' => 'description', 'content' => $description];
     /* Facebook */
     $metaTags[] = ['property' => 'og:title', 'content' => $title];
     $metaTags[] = ['property' => 'og:description', 'content' => $description];
     $metaTags[] = ['property' => 'og:type', 'content' => 'article'];
     // article, product, profile etc
     $metaTags[] = ['property' => 'og:image', 'content' => $model->thumbnail];
     //best 1200 x 630
     $metaTags[] = ['property' => 'og:url', 'content' => $model->getViewUrl(true)];
     if ($appId = Setting::getValue('fbAppId')) {
         $metaTags[] = ['property' => 'fb:app_id', 'content' => $appId];
     }
     //$metaTags[]=['property' => 'fb:app_id', 'content' => ''];
     //$metaTags[]=['property' => 'fb:admins', 'content' => ''];
     /* Twitter */
     $metaTags[] = ['name' => 'twitter:card', 'content' => 'summary_large_image'];
     $metaTags[] = ['name' => 'twitter:site', 'content' => Setting::getValue('twitterSite')];
     //        $metaTags[]=['name'=>'twitter:title', 'content'=>$title];
     //        $metaTags[]=['name'=>'twitter:description', 'content'=>$description];
     //        $metaTags[]=['name'=>'twitter:card', 'content'=>'summary'];
     //        $metaTags[]=['name'=>'twitter:site', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:image', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:data1', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:label1', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:data2', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:label2', 'content'=>''];
     /* jsonld */
     $imageObject = $model->getImageObject();
     $jsonLd = (object) ['@type' => 'Article', 'http://schema.org/name' => $model->title, 'http://schema.org/headline' => $model->desc, 'http://schema.org/articleBody' => $model->content, 'http://schema.org/dateCreated' => Yii::$app->formatter->asDate($model->created_at, 'php:c'), 'http://schema.org/dateModified' => Yii::$app->formatter->asDate($model->updated_at, 'php:c'), 'http://schema.org/datePublished' => Yii::$app->formatter->asDate($model->published_at, 'php:c'), 'http://schema.org/url' => $model->getViewUrl(true), 'http://schema.org/image' => (object) ['@type' => 'ImageObject', 'http://schema.org/url' => $imageObject['url'], 'http://schema.org/width' => $imageObject['width'], 'http://schema.org/height' => $imageObject['height']], 'http://schema.org/author' => (object) ['@type' => 'Person', 'http://schema.org/name' => $model->author->fullname], 'http://schema.org/publisher' => (object) ['@type' => 'Organization', 'http://schema.org/name' => Yii::$app->name, 'http://schema.org/logo' => (object) ['@type' => 'ImageObject', 'http://schema.org/url' => Yii::$app->urlManager->createAbsoluteUrl(Yii::$app->homeUrl . '/images/logo.png')]], 'http://schema.org/mainEntityOfPage' => (object) ['@type' => 'WebPage', '@id' => Yii::$app->urlManager->createAbsoluteUrl($model->viewUrl)]];
     /* OK */
     $data['title'] = $title;
     $data['metaTags'] = $metaTags;
     $data['jsonLd'] = $jsonLd;
     $this->registerMetaTagJsonLD($data);
     return $this->render('view', ['model' => $model]);
 }
Exemplo n.º 20
0
 /**
  * debug mode
  */
 protected function configDebugMode()
 {
     if (Setting::getValue('debug') && !is_a(Yii::$app, 'yii\\console\\Application') && Yii::$app->user->can('admin')) {
         $module = Yii::$app->getModule('debug');
         $module->allowedIPs = [Yii::$app->request->userIP];
     }
 }
 /**
  * send new password to user
  * @param $id
  * @return bool|\yii\web\Response
  */
 public function actionNewPassword($id)
 {
     $model = $this->findModel($id);
     if ($model->status != Account::STATUS_SUSPENDED) {
         $model->setPassword();
         if ($model->save()) {
             /* send mail */
             $subject = Yii::t('app', '[{APP_NAME}] Password changed', ['APP_NAME' => Yii::$app->name]);
             $mailSent = Yii::$app->mailer->compose(['html' => 'password-changed-html', 'text' => 'password-changed-text'], ['user' => $model])->setFrom([Setting::getValue('outgoingMail') => Yii::$app->name])->setTo($model->email)->setSubject($subject)->send();
             if ($mailSent) {
                 Yii::$app->session->setFlash('success', Yii::t('app', 'New password has been sent.'));
             } else {
                 Yii::$app->session->setFlash('warning', Yii::t('app', 'New password set successfully ({PASS}). Error while sending email to user.', ['PASS' => $model->passwordText]));
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Sorry, something went wrong. Please try again later.'));
         }
     } else {
         Yii::$app->session->setFlash('error', Yii::t('app', 'Before you can send the password, restore the suspended account.'));
     }
     return $this->redirect(['view', 'id' => $model->id]);
 }
Exemplo n.º 22
0
/* @var $searchModel common\models\BlogSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* breadcrumbs */
$this->params['breadcrumbs'][] = $this->title;
/* misc */
$this->registerJs('$(document).on("pjax:send", function(){ $(".grid-view-overlay").removeClass("hidden");});$(document).on("pjax:complete", function(){ $(".grid-view-overlay").addClass("hidden");})');
//$js=file_get_contents(__DIR__.'/index.min.js');
//$this->registerJs($js);
//$css=file_get_contents(__DIR__.'/index.css');
//$this->registerCss($css);
?>
<div class="blog-index">
    <div class="box box-info">
        <div class="box-body">
            <?php 
echo \common\models\Setting::getValue('blogDesc');
?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-8">
            <?php 
echo ListView::widget(['layout' => '<div class="row">{items}</div>{summary}{pager}<div><br /></div>', 'dataProvider' => $dataProvider, 'itemOptions' => ['class' => 'item'], 'itemView' => function ($model, $key, $index, $widget) {
    return $this->render('_grid', ['model' => $model, 'index' => $index]);
}]);
?>
        </div>
        <div class="col-md-4">
            <div class="hidden-xs hidden-sm"><?php 
echo \frontend\widgets\BlogPost::widget(['type' => 'mostViewed']);