Osclass Support Forums

Osclass plugin support => Blog and News Plugin => Topic started by: David Beaudoin on April 06, 2021, 04:30:48 PM

Title: adsense and blog ?
Post by: David Beaudoin on April 06, 2021, 04:30:48 PM
hello, i am trying to embed adsense javascript code in php but it doesn't work.

Someone to direct me please?


Quote
​<?php
  $blog_id = Params::getParam('blogId');
  $blog = ModelBLG::newInstance()->getBlogDetail($blog_id);
  $author = ModelBLG::newInstance()->getAuthor($blog['fk_i_user_id']);
  $comments = ModelBLG::newInstance()->getComments($blog_id, 1);
  ModelBLG::newInstance()->updateBlogViews($blog_id);
?>


<script data-ad-client="ca-pub-5046117062556130" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<?php


<div id="blg-body" class="blg-theme-<?php echo osc_current_web_theme(); ?>">
  <div id="blg-main" class="blg-content">
    <h1><?php echo blg_get_title($blog); ?></h1>

    <?php if(blg_get_subtitle($blog) <> '') { ?>
      <h2><?php echo blg_get_subtitle($blog); ?></h2>
    <?php } ?>

    <div class="blg-details">
      <?php if($blog['i_category'] > 0) { ?>
        <?php $blog_cat = ModelBLG::newInstance()->getCategoryDetail($blog['i_category']); ?>
        <div class="blg-detail-entry blg-detail-cat" <?php if($blog_cat['s_color'] <> '') { ?>style="background:<?php echo $blog_cat['s_color']; ?>;"<?php } ?>><?php echo blg_get_cat_name($blog_cat); ?></div>
      <?php } else { ?>
        <div class="blg-detail-entry blg-detail-cat"><?php _e('Uncategorized', 'blog'); ?></div>
      <?php } ?>

      <div class="blg-detail-entry"><?php echo date('j. M Y', strtotime($blog['dt_pub_date'])); ?></div>
      <div class="blg-detail-entry"><?php echo sprintf(__('%d views', 'blog'), $blog['i_view']); ?></div>
    </div>
 
 

    <div class="blg-content-text">
      <div class="blg-primary-img">
          <img src="<?php echo blg_img_link($blog['s_image']); ?>" alt="<?php echo osc_esc_html(blg_get_title($blog)); ?>" data-src="<?php echo blg_img_link($blog['s_image']); ?>"/>
      </div>

      <div class="blg-raw-text">
        <?php
          if(!blg_is_premium($blog)) {
            echo blg_get_description($blog);
          } else {
            echo osc_highlight(blg_get_description($blog), 800);
          }
        ?>
      </div>

      <?php if(blg_is_premium($blog)) { ?>
        <div class="blg-premium-cover"></div>
      <?php } ?>
    </div>

    <?php require 'premium.php'; ?>


    <?php if(blg_param('comment_enabled') == 1) { ?>
      <div class="blg-comments">
        <h2><?php _e('Comments', 'blog'); ?></h2>

        <?php if(count($comments) > 0) { ?>
          <?php $j = 0; ?>
          <?php foreach($comments as $c) { ?>
            <?php
              $j++;
              $cuser = User::newInstance()->findByPrimaryKey($c['fk_i_os_user_id']);
              $cauthor = ModelBLG::newInstance()->getUserByOsclassId($c['fk_i_os_user_id']);

              if(!$cauthor) {
                $is_author = false;
              } else {
                $is_author = true;
              }
            ?>


            <div class="blg-row<?php if($j == 1) { ?> blg-comment-first<?php } ?>">
              <div class="blg-comment-img">
                <?php
                  $cimg = '';

                  if($is_author) {
                    $cname = $cauthor['s_name'];
                    $cimg = blg_user_img($cauthor['s_image']);
                  } else {
                    $cname = (@$cuser['s_name'] <> '' ? $cuser['s_name'] : __('Anonymous', 'blog'));

                    if(function_exists('profile_picture_show')) {
                      if($c['fk_i_os_user_id'] > 0) {
                        $cimg = profile_picture_show(null, 'item', 200, null, $c['fk_i_os_user_id']);
                      }
                    }
                  }

                  if($cimg == '') {
                    $cimg = osc_base_url() . 'oc-content/plugins/blog/img/user/user-default.png';
                  }
                ?>

                <img src="<?php echo $cimg; ?>" alt="<?php echo osc_esc_html($cname); ?>" />
              </div>

              <div class="blg-comment-text">
                <div class="blg-comment-top">
                  <span class="blg-comment-user">
                    <?php if($is_author && @$cauthor['pk_i_id'] > 0) { ?>
                      <a href="<?php echo osc_route_url('blg-author', array('authorSlug' => osc_sanitizeString(blg_slug($cauthor['s_name'])), 'authorId' => $cauthor['pk_i_id'])); ?>" class="blg-comment-author-link"><?php echo $cname; ?></a>
                    <?php } else { ?>
                      <?php echo $cname; ?>
                    <?php } ?>
                  </span>

                  <span class="blg-comment-del"><?php _e('on', 'blog'); ?></span>
                  <span class="blg-comment-date"><?php echo date('j. M Y', strtotime($c['dt_pub_date'])); ?></span>
                </div>

                <div class="blg-comment-bot"><?php echo strip_tags($c['s_comment'], '<br>'); ?></div>
              </div>
            </div>
          <?php } ?>
        <?php } else { ?>
          <div class="blg-row blg-empty"><?php _e('No comments has been added on this post', 'blog'); ?></div>
        <?php } ?>
      </div>

      <div class="blg-new-comment">
        <h3><?php _e('Add new comment', 'blog'); ?></h3>

        <?php if(!osc_is_web_user_logged_in()) { ?>
          <div class="blg-row blg-not-logged"><?php _e('You must be logged in to add new comment', 'blog'); ?>. <a href="<?php echo osc_user_login_url(); ?>"><?php _e('Log in', 'blog'); ?></a></div>

        <?php } else { ?>
          <form class="nocsrf" method="POST" name="blg_new_comment" action="<?php echo osc_route_url('blg-action', array('blgPage' => 'comment')); ?>">
            <input type="hidden" name="fk_i_blog_id" value="<?php echo $blog_id; ?>" />

            <div class="blg-row">
              <label for="s_name"><?php _e('Your name', 'blog'); ?></label>
              <input type="text" name="s_name" id="s_name" value="<?php echo osc_esc_html(osc_logged_user_name()); ?>" readonly required/>
            </div>

            <div class="blg-row">
              <label for="s_comment"><?php _e('Comment', 'blog'); ?></label>
              <textarea name="s_comment" id="s_comment" required></textarea>
            </div>

            <button class="blg-btn blg-btn-primary" type="submit" title="<?php echo osc_esc_html(__('Submit', 'blog')); ?>"><i class="fa fa-check"></i> <?php echo osc_esc_html(__('Submit', 'blog')); ?></button>
          </form>
        <?php } ?>
      </div>
    <?php } ?>
  </div>

  <?php require_once 'sidebar.php'; ?>
</div>

Regards,

David
Title: Re: adsense and blog ?
Post by: MB Themes on April 06, 2021, 04:45:10 PM
@David
I would put adsense into blg-body div content or deeper
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 06, 2021, 04:59:56 PM
It's true but that doesn't change the problem...

It was to do a test integration of the code but obviously it does not work...
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 06, 2021, 05:02:14 PM
@David
I would put adsense into blg-body div content or deeper

I don't even know where is what you told me
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 06, 2021, 05:12:03 PM
I integrated it into blg-body and here is the result...
Title: Re: adsense and blog ?
Post by: MB Themes on April 06, 2021, 05:22:03 PM
You did something wrong, as you see results
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 06, 2021, 05:32:06 PM
I integrated the code the same way I showed you in my first post and it always gives me that no matter where I put it.

this is the way to implement the code which is not good and i would like to know how to implement it correctly
Title: Re: adsense and blog ?
Post by: MB Themes on April 06, 2021, 05:49:15 PM
That should be written on google docs
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 06, 2021, 05:55:12 PM
No he only talks about HTML not PHP and for the rest when he is in CMS he refers to the author of the CMS yes, that's what I do ...
Title: Re: adsense and blog ?
Post by: MB Themes on April 06, 2021, 07:17:13 PM
Php is enclosed in php tags, rest is html.
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 09:12:43 AM
Until then it doesn't work, it always gives what I have on the screenshot. However, I inserted my code normally as in my 1st message ...
Title: Re: adsense and blog ?
Post by: MB Themes on April 07, 2021, 09:18:53 AM
@David
Well basically your screenshot looks like it generates error and stops execution at start.
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 09:37:21 AM
But don't you have any idea what could be wrong with my code insertion?
Title: Re: adsense and blog ?
Post by: MB Themes on April 07, 2021, 09:39:34 AM
@David
Well, probably because of that <?php tag after adsense code
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 09:41:16 AM
But I have to reopen PHP, right?
Title: Re: adsense and blog ?
Post by: MB Themes on April 07, 2021, 09:53:40 AM
@David
I think you should read at least very very basics about PHP. You've reopened PHP tag for HTML code.
Enable PHP error logging on your hosting and you will see errors instead of blank page.
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 09:55:19 AM
Without the PHP tag at the end it doesn't work and without any tags at all, I don't have the ad
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 09:56:08 AM
Anyway, thank you for taking the time for me
Title: Re: adsense and blog ?
Post by: MB Themes on April 07, 2021, 09:56:14 AM
https://www.ntchosting.com/encyclopedia/scripting-and-programming/php/php-in/#:~:text=PHP%20is%20an%20HTML%2Dembedded,write%20dynamically%20generated%20pages%20quickly.
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 10:09:35 AM
Yes I have already seen tutorials like that but it's always for writing... the cries, there is no problem I manage to do it it is to integrate my damn script that I cannot do it
Title: Re: adsense and blog ?
Post by: cartagena68 on April 07, 2021, 03:12:07 PM
<?php
  $blog_id = Params::getParam('blogId');
  $blog = ModelBLG::newInstance()->getBlogDetail($blog_id);
  $author = ModelBLG::newInstance()->getAuthor($blog['fk_i_user_id']);
  $comments = ModelBLG::newInstance()->getComments($blog_id, 1);
  ModelBLG::newInstance()->updateBlogViews($blog_id);
?>


<script data-ad-client="ca-pub-5046117062556130" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<?php  <-- THIS MUST GO


<div id="blg-body" class="blg-theme-<?php echo osc_current_web_theme(); ?>">
  <div id="blg-main" class="blg-content">
    <h1><?php echo blg_get_title($blog); ?></h1>

    <?php if(blg_get_subtitle($blog) <> '') { ?>
      <h2><?php echo blg_get_subtitle($blog); ?></h2>
    <?php } ?>

    <div class="blg-details">
      <?php if($blog['i_category'] > 0) { ?>
        <?php $blog_cat = ModelBLG::newInstance()->getCategoryDetail($blog['i_category']); ?>
        <div class="blg-detail-entry blg-detail-cat" <?php if($blog_cat['s_color'] <> '') { ?>style="background:<?php echo $blog_cat['s_color']; ?>;"<?php } ?>><?php echo blg_get_cat_name($blog_cat); ?></div>
      <?php } else { ?>
        <div class="blg-detail-entry blg-detail-cat"><?php _e('Uncategorized', 'blog'); ?></div>
      <?php } ?>

      <div class="blg-detail-entry"><?php echo date('j. M Y', strtotime($blog['dt_pub_date'])); ?></div>
      <div class="blg-detail-entry"><?php echo sprintf(__('%d views', 'blog'), $blog['i_view']); ?></div>
    </div>
 
 

    <div class="blg-content-text">
      <div class="blg-primary-img">
          <img src="<?php echo blg_img_link($blog['s_image']); ?>" alt="<?php echo osc_esc_html(blg_get_title($blog)); ?>" data-src="<?php echo blg_img_link($blog['s_image']); ?>"/>
      </div>

      <div class="blg-raw-text">
        <?php
          if(!blg_is_premium($blog)) {
            echo blg_get_description($blog);
          } else {
            echo osc_highlight(blg_get_description($blog), 800);
          }
        ?>
      </div>

      <?php if(blg_is_premium($blog)) { ?>
        <div class="blg-premium-cover"></div>
      <?php } ?>
    </div>

    <?php require 'premium.php'; ?>


    <?php if(blg_param('comment_enabled') == 1) { ?>
      <div class="blg-comments">
        <h2><?php _e('Comments', 'blog'); ?></h2>

        <?php if(count($comments) > 0) { ?>
          <?php $j = 0; ?>
          <?php foreach($comments as $c) { ?>
            <?php
              $j++;
              $cuser = User::newInstance()->findByPrimaryKey($c['fk_i_os_user_id']);
              $cauthor = ModelBLG::newInstance()->getUserByOsclassId($c['fk_i_os_user_id']);

              if(!$cauthor) {
                $is_author = false;
              } else {
                $is_author = true;
              }
            ?>


            <div class="blg-row<?php if($j == 1) { ?> blg-comment-first<?php } ?>">
              <div class="blg-comment-img">
                <?php
                  $cimg = '';

                  if($is_author) {
                    $cname = $cauthor['s_name'];
                    $cimg = blg_user_img($cauthor['s_image']);
                  } else {
                    $cname = (@$cuser['s_name'] <> '' ? $cuser['s_name'] : __('Anonymous', 'blog'));

                    if(function_exists('profile_picture_show')) {
                      if($c['fk_i_os_user_id'] > 0) {
                        $cimg = profile_picture_show(null, 'item', 200, null, $c['fk_i_os_user_id']);
                      }
                    }
                  }

                  if($cimg == '') {
                    $cimg = osc_base_url() . 'oc-content/plugins/blog/img/user/user-default.png';
                  }
                ?>

                <img src="<?php echo $cimg; ?>" alt="<?php echo osc_esc_html($cname); ?>" />
              </div>

              <div class="blg-comment-text">
                <div class="blg-comment-top">
                  <span class="blg-comment-user">
                    <?php if($is_author && @$cauthor['pk_i_id'] > 0) { ?>
                      <a href="<?php echo osc_route_url('blg-author', array('authorSlug' => osc_sanitizeString(blg_slug($cauthor['s_name'])), 'authorId' => $cauthor['pk_i_id'])); ?>" class="blg-comment-author-link"><?php echo $cname; ?></a>
                    <?php } else { ?>
                      <?php echo $cname; ?>
                    <?php } ?>
                  </span>

                  <span class="blg-comment-del"><?php _e('on', 'blog'); ?></span>
                  <span class="blg-comment-date"><?php echo date('j. M Y', strtotime($c['dt_pub_date'])); ?></span>
                </div>

                <div class="blg-comment-bot"><?php echo strip_tags($c['s_comment'], '<br>'); ?></div>
              </div>
            </div>
          <?php } ?>
        <?php } else { ?>
          <div class="blg-row blg-empty"><?php _e('No comments has been added on this post', 'blog'); ?></div>
        <?php } ?>
      </div>

      <div class="blg-new-comment">
        <h3><?php _e('Add new comment', 'blog'); ?></h3>

        <?php if(!osc_is_web_user_logged_in()) { ?>
          <div class="blg-row blg-not-logged"><?php _e('You must be logged in to add new comment', 'blog'); ?>. <a href="<?php echo osc_user_login_url(); ?>"><?php _e('Log in', 'blog'); ?></a></div>

        <?php } else { ?>
          <form class="nocsrf" method="POST" name="blg_new_comment" action="<?php echo osc_route_url('blg-action', array('blgPage' => 'comment')); ?>">
            <input type="hidden" name="fk_i_blog_id" value="<?php echo $blog_id; ?>" />

            <div class="blg-row">
              <label for="s_name"><?php _e('Your name', 'blog'); ?></label>
              <input type="text" name="s_name" id="s_name" value="<?php echo osc_esc_html(osc_logged_user_name()); ?>" readonly required/>
            </div>

            <div class="blg-row">
              <label for="s_comment"><?php _e('Comment', 'blog'); ?></label>
              <textarea name="s_comment" id="s_comment" required></textarea>
            </div>

            <button class="blg-btn blg-btn-primary" type="submit" title="<?php echo osc_esc_html(__('Submit', 'blog')); ?>"><i class="fa fa-check"></i> <?php echo osc_esc_html(__('Submit', 'blog')); ?></button>
          </form>
        <?php } ?>
      </div>
    <?php } ?>
  </div>

  <?php require_once 'sidebar.php'; ?>
</div>
Title: Re: adsense and blog ?
Post by: David Beaudoin on April 07, 2021, 03:24:54 PM
thanks but i have already tried. It does not work. Here I am saving my site so Filezilla is busy but I will try again afterwards!