/**
* Lite Publisher
* Copyright (C) 2010 - 2015 Vladimir Yushko http://litepublisher.ru/ http://litepublisher.com/
* Dual licensed under the MIT (mit.txt)
* and GPL (gpl.txt) licenses.
**/
function tkeywordspluginInstall($self)
{
    @mkdir(litepublisher::$paths->data . 'keywords', 0777);
    @chmod(litepublisher::$paths->data . 'keywords', 0777);
    $item = litepublisher::$classes->items[get_class($self)];
    litepublisher::$classes->add('tkeywordswidget', 'keywords.widget.php', $item[1]);
    $widget = tkeywordswidget::i();
    $widgets = twidgets::i();
    $widgets->lock();
    $id = $widgets->add($widget);
    $sidebars = tsidebars::i();
    $sidebars->insert($id, false, 1, -1);
    $widgets->unlock();
    $urlmap = turlmap::i();
    $urlmap->lock();
    $urlmap->afterrequest = $self->parseref;
    $urlmap->deleted = $self->urldeleted;
    $urlmap->unlock();
}
 public function processform()
 {
     $datadir = litepublisher::$paths->data . 'keywords' . DIRECTORY_SEPARATOR;
     if (isset($_POST['optionsform'])) {
         extract($_POST, EXTR_SKIP);
         $plugin = tkeywordsplugin::i();
         $widget = tkeywordswidget::i();
         $widgets = twidgets::i();
         $idwidget = $widgets->find($widget);
         $widget->lock();
         $widget->settitle($idwidget, $title);
         $widget->count = (int) $count;
         $widget->notify = isset($notify);
         $trace = isset($trace);
         if ($widget->trace != $trace) {
             if ($trace) {
                 litepublisher::$urlmap->afterrequest = $plugin->parseref;
             } else {
                 litepublisher::$urlmap->delete_event_class('afterrequest', get_class($plugin));
             }
         }
         $widget->trace = $trace;
         $widget->unlock();
         $plugin->blackwords = array();
         $words = strtoarray($blackwords);
         if (litepublisher::$options->language != 'en') {
             tlocal::usefile('translit');
             foreach ($words as $word) {
                 $word = strtr($word, tlocal::$self->ini['translit']);
                 $word = trim($word);
                 if (empty($word)) {
                     continue;
                 }
                 $plugin->blackwords[] = strtolower($word);
             }
         }
         $plugin->save();
         return;
     }
     if (isset($_GET['filename'])) {
         $filename = str_replace('_', '.', $_GET['filename']);
         $content = trim($_POST['content']);
         if ($content == '') {
             @unlink($datadir . $filename);
         } else {
             file_put_contents($datadir . $filename, $content);
         }
         return;
     }
     foreach ($_POST as $filename => $value) {
         $filename = str_replace('_', '.', $filename);
         if (preg_match('/^\\d+?\\.\\d+?\\.php$/', $filename)) {
             unlink($datadir . $filename);
         }
     }
 }
Exemplo n.º 3
0
 public function parseref($url)
 {
     if (strbegin($url, '/admin/') || strbegin($url, '/croncron.php')) {
         return;
     }
     $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     if (empty($ref)) {
         return;
     }
     $urlarray = parse_url($ref);
     if ($urlarray['scheme'] !== 'http') {
         return;
     }
     $host = $urlarray['host'];
     if ($host == 'search.msn.com' || is_int(strpos($host, '.google.'))) {
         parse_str($urlarray['query']);
         $keywords = $q;
         if (isset($ie) && $ie == 'windows-1251') {
             $keywords = @iconv("windows-1251", "utf-8", $keywords);
         }
     } elseif ($host == 'www.rambler.ru') {
         parse_str($urlarray['query']);
         $keywords = @iconv("windows-1251", "utf-8", $words);
     } elseif ($host == 'www.yandex.ru' || $host == 'yandex.ru') {
         parse_str($urlarray['query']);
         $keywords = $text;
     } else {
         return;
     }
     $keywords = trim($keywords);
     if (empty($keywords)) {
         return;
     }
     $c = substr_count($keywords, chr(208));
     if ($c < 3 && $this->hasru($keywords)) {
         $keywords = @iconv('windows-1251', 'utf-8', $keywords);
     }
     $keywords = trim($keywords);
     if (empty($keywords)) {
         return;
     }
     if (strlen($keywords) <= 5) {
         return;
     }
     foreach (array('site:', 'inurl:', 'link:', '%', '@', '<', '>', 'intext:', 'http:', 'ftp:', '\\') as $k) {
         if (false !== strpos($keywords, $k)) {
             return;
         }
     }
     if ($this->inblack($keywords)) {
         return;
     }
     $keywords = htmlspecialchars($keywords, ENT_QUOTES);
     //$link =" <a href=\"http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]\">$keywords</a>";
     $widget = tkeywordswidget::i();
     //if (in_array($link, $widget->links)) return;
     foreach ($widget->links as $item) {
         if ($keywords == $item['text']) {
             return;
         }
     }
     $widget->links[] = array('url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'text' => $keywords);
     $widget->save();
 }