Phalcon Framework 3.4.1

Error: Call to a member function insertBefore() on null

/srv/www/2tin.net/app/modules/highnews/controllers/ArticleController.php (110)
#0Cms\Modules\Highnews\Controllers\ArticleController->addMobifosAds(<p>doanh thu. D&ugrave; kh&ocirc;ng &#273;&#7841;t &#273;i&#7875;m s&#7889; cao b&#7857;ng ph&#7847;n m&#7897;t (97%), Incredibles 2 v&#7851;n &#273;&#432;&#7907;c 94% &#273;&aacute;nh gi&aacute; t&iacute;ch c&#7921;c t&#7915; gi&#7899;i chuy&ecirc;n m&ocirc;n tr&ecirc;n Rotten Tomatoes. Nh&#7919;ng c&acirc;u chuy&#7879;n v&#7873; &#273;&#7901;i s&#7889;ng gi&#7919;a v&#7907; v&agrave; ch&#7891;ng, cha m&#7865; v&agrave; con c&aacute;i l&agrave; y&#7871;u t&#7889; khi&#7871;n ng&#432;&#7901;i l&#7899;n c&#361;ng ph&#7843;i ng&#7843; nghi&ecirc;ng v&igrave; b&#7897; phim. Ch&#432;a h&#7871;t, v&#7899;i v&#7883; th&#7871; c&#7911;a d&ograve;ng phim si&ecirc;u anh h&ugrave;ng hi&#7879;n nay, Incredibles 2 c&#361;ng kh&ocirc;ng h&#7873; k&eacute;m c&#7841;nh v&#7873; &#273;&#7897; &#273;&#7865;p m&#7855;t trong nh&#7919;ng pha h&agrave;nh &#273;&#7897;ng.</p> \n<table class="picture" align="center"><tbody><tr><td class="pic"><img title="Nh&#7919;ng b&#7897; phim ho&#7841;t h&igrave;nh khi&#7871;n ng&#432;&#7901;i l&#7899;n c&#361;ng thao th&#7913;c h&igrave;nh &#7843;nh 1" src="http://img.2tin.net/uploads/images/2018/10/06/b0cd6477ac2c9ad0cf87e6af0dda39f9_8b96a2675576471f9c4358e09349084f/b0cd6477ac2c9ad0cf87e6af0dda39f9.jpg" alt="Nhung bo phim hoat hinh khien nguoi lon cung thao thuc hinh anh 1" width="1140" height="640" class=" img-responsive"></td> \n</tr><tr><td class="pCaption caption"><strong><em>Incredibles 2 </em></strong>(2018): Sau 14 n&#259;m, Brad Bird b&#7845;t ng&#7901; t&aacute;i xu&#7845;t v&#7899;i ph&#7847;n hai c&#7911;a <em>Gia &#273;&igrave;nh si&ecirc;u nh&acirc;n</em> khi&#7871;n kh&ocirc;ng ch&#7881; nh&#7919;ng &#273;&#7913;a tr&#7867; t&ograve; m&ograve; m&agrave; c&#7843; nh&#7919;ng ng&#432;&#7901;i tr&#432;&#7903;ng th&agrave;nh c&#361;ng x&#7889;n xang. M&#7897;t m&#7843;nh k&iacute; &#7913;c tu&#7893;i th&#417; tr&agrave;n v&#7873;, l&ocirc;i k&eacute;o ng&#432;&#7901;i ng&#432;&#7901;i ra r&#7841;p v&agrave; thu v&#7873; h&#417;n 1,2 t&#7927; USD</td> \n</tr></tbody></table>)
/srv/www/2tin.net/app/modules/highnews/controllers/ArticleController.php (46)
<?php
 
namespace Cms\Modules\Highnews\Controllers;
 
use Cms\Helper;
use Cms\IAHelper;
use Cms\Models\Admins;
use Cms\Models\Articles;
use Cms\Models\ArticlesTags;
use Cms\Models\Categories;
use Cms\Models\Tags;
use Cms\Tag;
use Facebook\InstantArticles\Parser\Parser;
use Phalcon\Mvc\View;
 
class ArticleController extends ControllerBase
{
 
    public function indexAction($article_slug = '', $id = null)
    {
        $page = $this->request->get('page', 'int', 1);
        $per_page = 5;
        $offset = (($page - 1) * $per_page) + 4;
 
        $article = $this->__is_bot() ? Articles::findById($id) : Articles::findByIdCache($id);
        if (empty($article) || ($this->admin === null && $article->status != 1)) {
            $this->dispatcher->forward(['controller' => 'error', 'action' => 'show404']);
            return;
        }
 
        // redirect right url
        $uri = $this->tag->article_url($article);
        if (strpos($this->router->getRewriteUri(), $uri) === false) {
            $this->response->redirect($uri);
            return;
        }
 
        if ($page === 1) {
            // add tạm view counter
            Articles::update_view($article->aid);
        }
 
 
        $article->content = $this->addClassToImg($article->content, 'img-responsive');// add class img-responsive to img tag
        $article->content = $this->transforYoutubeIframe($article->content);
        $article->content = $this->addMobifosAds($article->content); //Add fucking ads
        //$article->content = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $article->content); // remove custom style
        $article->source_link = parse_url($article->source_link);
        $article->source_link = isset($article->source_link['host']) ? sprintf('http://%s/', $article->source_link['host']) : '';
 
 
        $category = Categories::getCategoryByArticleId($article->aid, false);
        $categories = Categories::getCategoryByArticleId($article->aid, true);
        $tags = Tags::findByArticleId($article->aid);
 
        $this->tag->setTitle(html_entity_decode($article->title));
 
        $this->view->setVar('admin', Admins::findByIdCache($article->create_by));
        $this->view->setVar('article', $article);
        $this->view->setVar('related_articles', $this->widget_related_top_news_block($article->aid, $category['cid'], 3, 0));
        $this->view->setVar('related_articles_2', $this->widget_most_related_news_block($article->aid, $category['cid'], 1, 3));
        $this->view->setVar('related_articles_3', $this->widget_related_news_block($article->aid, $category['cid'], $per_page, $offset));
        $this->view->setVar('day_transform', ['Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm', 'Thứ sáu', 'Thứ bảy']);
        $this->view->setVar('category', $category);
        $this->view->setVar('categories', $categories);
        $this->view->setVar('tags', $tags);
        $this->view->setVar('hot_block_1', $this->widget_hot(15, 'hot_block_1'));
 
        $this->view->setVar('publisher', 'https://www.facebook.com/blog2tin/');
        $this->view->setVar('published_time', $article->publish_time);
        $this->view->setVar('modified_time', $article->modify_time);
        $this->view->setVar('og_type', 'article');
        $this->view->setVar('og_image', $article->thumbnail);
        $this->view->setVar('description', $article->introduce);
        $this->view->setVar('rss', ['title' => $article->title, 'link' => $this->url->get('rss/article/' . $article->aid)]);
    }
 
    private function addClassToImg($content, $new_class = '')
    {
        $dom = new \DOMDocument();
        @$dom->loadHTML(mb_convert_encoding('<?xml encoding="utf-8" ?>' . $content, 'HTML-ENTITIES', 'UTF-8'));
        $dom->preserveWhiteSpace = false;
 
        $images = $dom->getElementsByTagName('img');
 
        foreach ($images as $image) {
 
            // the existing classes already on the images
            $existing_classes = $image->getAttribute('class');
 
            if (strpos($existing_classes, $new_class) === false) {
                $new_class = $existing_classes . ' ' . $new_class;
                $image->setAttribute('class', $new_class);
            }
        }
        $body = $dom->saveHTML();
        preg_match("/<body[^>]*>(.*?)<\/body>/is", $body, $match);
        return !empty($match) ? end($match) : '';
    }
 
    private function addMobifosAds($content)
    {
        $dom = new \DOMDocument();
        @$dom->loadHTML(mb_convert_encoding('<?xml encoding="utf-8" ?>' . $content, 'HTML-ENTITIES', 'UTF-8'));
        $dom->preserveWhiteSpace = false;
        $ptags = $dom->getElementsByTagName('p');
        $stop = (int)round($ptags->length/2);
        $p = $ptags->item($stop);
        $ads = $dom->createElement("div","FUCKINGADS");
        $p->parentNode->insertBefore($ads, $p);
        $html = $dom->saveHTML();
        $content = str_replace("FUCKINGADS",'<script src="https://player.cliphub.io/js/clh.js?v=1.3.0"></script><div id="clh_hot_news"></div><script>CLH.hotNews("clh_hot_news", {  cat : "phim,giai-tri",  mobile: true});</script>',$html);
       // return str_replace("ABC",'<script src="https://player.cliphub.io/js/clh.js?v=1.3.0"></script><div id="clh_hot_news"></div><script>CLH.hotNews("clh_hot_news", {  cat : "phim,giai-tri",  mobile: true});</script>',$html);
        return $content;
    }
 
    private function transforYoutubeIframe($content)
    {
        preg_match_all("/<iframe[^>]*src=\"[^\"]*youtu[.]?be.*<\\/iframe>/mi", $content, $matches);
        if (!empty($matches)) {
            foreach ($matches as $match) {
                if (!empty($match[0])) {
                    $new_iframe = $match[0];
                    $dom = new \DOMDocument();
                    @$dom->loadHTML(mb_convert_encoding($match[0], 'HTML-ENTITIES', 'UTF-8'));
                    $dom->preserveWhiteSpace = false;
                    $iframes = $dom->getElementsByTagName('iframe');
                    foreach ($iframes as $iframe) {
                        $existing_classes = $iframe->getAttribute('class');
                        if (!empty($existing_classes)) {
                            $new_class = $existing_classes . ' embed-responsive-item';
                            $iframe->setAttribute('class', $new_class);
                        } else {
                            $iframe->setAttribute('class', 'embed-responsive-item');
                        }
 
                        $body = $dom->saveHTML();
                        $new_iframe = $body;
                    }
                    $content = str_replace($match[0], '<div class="embed-responsive-16by9">' . $new_iframe . '</div>', $content);
                }
            }
        }
        return $content;
    }
 
}
#1Cms\Modules\Highnews\Controllers\ArticleController->indexAction(nhung-bo-phim-hoat-hinh-khien-nguoi-lon-cung-thao-thuc, 13190)
#2Phalcon\Dispatcher->callActionMethod(Object(Cms\Modules\Highnews\Controllers\ArticleController), indexAction, Array([article_slug] => nhung-bo-phim-hoat-hinh-khien-nguoi-lon-cung-thao-thuc, [id] => 13190))
#3Phalcon\Dispatcher->dispatch()
#4Phalcon\Mvc\Application->handle()
/srv/www/2tin.net/app/bootstrap_highnews.php (63)
<?php
 
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Application;
 
error_reporting(E_ALL);
 
define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');
define('APP_MODULE', 'highnews');
 
/**
 * friendly error
 */
$debug = new \Phalcon\Debug();
$debug->listen();
 
/**
 * The FactoryDefault Dependency Injector automatically registers the services that
 * provide a full stack framework. These default services can be overidden with custom ones.
 */
$di = new FactoryDefault();
 
/**
 * Include general services
 */
require APP_PATH . '/config/services.php';
 
/**
 * Include web environment specific services
 */
require APP_PATH . '/config/services_highnews.php';
 
/**
 * Add debug
 */
if ($di->has('profiler')) {
    $di->getShared('profiler')->addAggregator(new \Fabfuel\Prophiler\Aggregator\Database\QueryAggregator());
    $di->getShared('profiler')->addAggregator(new \Fabfuel\Prophiler\Aggregator\Cache\CacheAggregator());
    $pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($di->getShared('profiler'));
    $pluginManager->register();
}
 
/**
 * Include Autoloader
 */
include APP_PATH . '/config/loader.php';
/**
 * Handle the request
 */
$application = new Application($di);
 
/**
 * Register application modules
 */
$application->registerModules(['highnews' => ['className' => 'Cms\Modules\Highnews\Module']]);
 
/**
 * Include routes
 */
require APP_PATH . '/config/routes.php';
 
$html = $application->handle()->getContent();
 
/**
 * render debug html
 */
if ($di->has('profiler')) {
    $toolbar = new \Fabfuel\Prophiler\Toolbar($di->getShared('profiler'));
    $toolbar->addDataCollector(new \Fabfuel\Prophiler\DataCollector\Request());
    $html = str_replace('</head>', $toolbar->render() . '</head>', $html);
}
 
/**
 * compress html
 */
if (isset($config->compress) && $config->compress) {
    $html = str_replace(["\n", "\r", "\t"], null, $html);
}
 
echo $html;
#5require(/srv/www/2tin.net/app/bootstrap_highnews.php)
/srv/www/2tin.net/public/highnews/index.php (2)
<?php
require '../../app/bootstrap_highnews.php';
KeyValue
_url/nhung-bo-phim-hoat-hinh-khien-nguoi-lon-cung-thao-thuc-13190.html
KeyValue
USERnginx
HOME/var/lib/nginx
HTTP_CONNECTIONclose
HTTP_X_FORWARDED_FOR54.164.198.240
HTTP_ACCEPT_ENCODINGgzip
HTTP_HOST2tin.net
HTTP_IF_MODIFIED_SINCEThu, 18 Oct 2018 19:56:57 MSK
HTTP_ACCEPTtext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_USER_AGENTCCBot/2.0 (https://commoncrawl.org/faq/)
REDIRECT_STATUS200
SERVER_NAME2tin.net
SERVER_PORT80
SERVER_ADDR172.31.16.150
REMOTE_PORT60672
REMOTE_ADDR172.31.16.103
SERVER_SOFTWAREnginx/1.10.2
GATEWAY_INTERFACECGI/1.1
REQUEST_SCHEMEhttp
SERVER_PROTOCOLHTTP/1.1
DOCUMENT_ROOT/srv/www/2tin.net/public/highnews
DOCUMENT_URI/index.php
REQUEST_URI/nhung-bo-phim-hoat-hinh-khien-nguoi-lon-cung-thao-thuc-13190.html
SCRIPT_NAME/index.php
CONTENT_LENGTH
CONTENT_TYPE
REQUEST_METHODGET
QUERY_STRING_url=/nhung-bo-phim-hoat-hinh-khien-nguoi-lon-cung-thao-thuc-13190.html&
SCRIPT_FILENAME/srv/www/2tin.net/public/highnews/index.php
APP_ENVproduction
FCGI_ROLERESPONDER
PHP_SELF/index.php
REQUEST_TIME_FLOAT1544619073.5807
REQUEST_TIME1544619073
#Path
0/srv/www/2tin.net/public/highnews/index.php
1/srv/www/2tin.net/app/bootstrap_highnews.php
2/srv/www/2tin.net/app/config/services.php
3/srv/www/2tin.net/vendor/autoload.php
4/srv/www/2tin.net/vendor/composer/autoload_real.php
5/srv/www/2tin.net/vendor/composer/ClassLoader.php
6/srv/www/2tin.net/vendor/composer/autoload_static.php
7/srv/www/2tin.net/vendor/guzzlehttp/psr7/src/functions_include.php
8/srv/www/2tin.net/vendor/guzzlehttp/psr7/src/functions.php
9/srv/www/2tin.net/vendor/guzzlehttp/promises/src/functions_include.php
10/srv/www/2tin.net/vendor/guzzlehttp/promises/src/functions.php
11/srv/www/2tin.net/vendor/guzzlehttp/guzzle/src/functions_include.php
12/srv/www/2tin.net/vendor/guzzlehttp/guzzle/src/functions.php
13/srv/www/2tin.net/vendor/react/promise/src/functions_include.php
14/srv/www/2tin.net/vendor/react/promise/src/functions.php
15/srv/www/2tin.net/vendor/swiftmailer/swiftmailer/lib/swift_required.php
16/srv/www/2tin.net/vendor/swiftmailer/swiftmailer/lib/classes/Swift.php
17/srv/www/2tin.net/vendor/facebook/graph-sdk/src/Facebook/polyfills.php
18/srv/www/2tin.net/vendor/ezyang/htmlpurifier/library/HTMLPurifier.composer.php
19/srv/www/2tin.net/app/config/config.php
20/srv/www/2tin.net/app/config/production/config.php
21/srv/www/2tin.net/app/config/production/config-highnews.php
22/srv/www/2tin.net/app/config/services_highnews.php
23/srv/www/2tin.net/app/config/services_web.php
24/srv/www/2tin.net/app/config/loader.php
25/srv/www/2tin.net/app/config/routes.php
26/srv/www/2tin.net/app/config/routes/highnews.php
27/srv/www/2tin.net/app/modules/highnews/Module.php
28/srv/www/2tin.net/app/modules/highnews/controllers/ArticleController.php
29/srv/www/2tin.net/app/modules/highnews/controllers/ControllerBase.php
30/srv/www/2tin.net/app/common/library/Browser.php
31/srv/www/2tin.net/app/common/library/Tag.php
32/srv/www/2tin.net/app/common/models/Articles.php
33/srv/www/2tin.net/app/common/models/base/Articles.php
34/srv/www/2tin.net/app/common/models/base/Model.php
35/srv/www/2tin.net/app/common/library/Blameable.php
36/srv/www/2tin.net/app/common/library/RedisDB.php
37/srv/www/2tin.net/app/common/library/ProfilerHelper.php
38/srv/www/2tin.net/vendor/predis/predis/src/Client.php
39/srv/www/2tin.net/vendor/predis/predis/src/ClientInterface.php
40/srv/www/2tin.net/vendor/predis/predis/src/Configuration/Options.php
41/srv/www/2tin.net/vendor/predis/predis/src/Configuration/OptionsInterface.php
42/srv/www/2tin.net/vendor/predis/predis/src/Configuration/ConnectionFactoryOption.php
43/srv/www/2tin.net/vendor/predis/predis/src/Configuration/OptionInterface.php
44/srv/www/2tin.net/vendor/predis/predis/src/Connection/Factory.php
45/srv/www/2tin.net/vendor/predis/predis/src/Connection/FactoryInterface.php
46/srv/www/2tin.net/vendor/predis/predis/src/Connection/Parameters.php
47/srv/www/2tin.net/vendor/predis/predis/src/Connection/ParametersInterface.php
48/srv/www/2tin.net/vendor/predis/predis/src/Connection/StreamConnection.php
49/srv/www/2tin.net/vendor/predis/predis/src/Connection/AbstractConnection.php
50/srv/www/2tin.net/vendor/predis/predis/src/Connection/NodeConnectionInterface.php
51/srv/www/2tin.net/vendor/predis/predis/src/Connection/ConnectionInterface.php
52/srv/www/2tin.net/vendor/predis/predis/src/Command/RawCommand.php
53/srv/www/2tin.net/vendor/predis/predis/src/Command/CommandInterface.php
54/srv/www/2tin.net/vendor/predis/predis/src/Configuration/ProfileOption.php
55/srv/www/2tin.net/vendor/predis/predis/src/Profile/Factory.php
56/srv/www/2tin.net/vendor/predis/predis/src/Profile/RedisVersion320.php
57/srv/www/2tin.net/vendor/predis/predis/src/Profile/RedisProfile.php
58/srv/www/2tin.net/vendor/predis/predis/src/Profile/ProfileInterface.php
59/srv/www/2tin.net/vendor/predis/predis/src/Command/StringGet.php
60/srv/www/2tin.net/vendor/predis/predis/src/Command/Command.php
61/srv/www/2tin.net/vendor/predis/predis/src/Response/Status.php
62/srv/www/2tin.net/vendor/predis/predis/src/Response/ResponseInterface.php
63/srv/www/2tin.net/cache/metadata/meta-cms_models_articles-articles.php
64/srv/www/2tin.net/cache/metadata/map-cms_models_articles.php
65/srv/www/2tin.net/vendor/predis/predis/src/Command/StringSet.php
66/srv/www/2tin.net/vendor/predis/predis/src/Command/KeyExpire.php
Memory
Usage2097152