Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/video/helpers/category.php
Строк: 27
<?php
class VHelper_video_category
{
    public static function 
categories()
    {
        
$cache VF::factory('cache');
        if (!
$categories $cache->get('categories'86400)) {
            
$db VF::factory('database');
            
$db->query("SELECT cat_id, parent_id, name, slug, total_videos
                        FROM #__video_categories
                        ORDER BY slug, parent_id ASC"
);
            if (
$db->affected_rows()) {
                
$categories $db->fetch_rows();
                if (
VCfg::get('video.subcategories')) {
                    
$categories VArray::tree($categories);
                }

                
$cache->store('categories'$categories86400);
            }
        }
        
        return 
$categories;
    }
    
    public static function 
categorize($video_id$title$description$current$tags$categories)
    {
          
$matched        = array();
          
$current        explode(','$current);
          
$tags           explode(','$tags);

          foreach (
$categories as $category) {
              
$cat_id     = (int) $category['cat_id'];
              
$keywords   explode(','$category['auto_term']);

              foreach (
$keywords as $keyword) {
                  
$keyword    trim($keyword);

                  if (
stripos($title$keyword) !== false) {
                      if (!
in_array($cat_id$matched)) {
                          
$matched[] = $cat_id;
                      }
                  }
     
                  if (
$description != '') {
                      if (
stripos($description$keyword) !== false) {
                          if (!
in_array($cat_id$matched)) {
                              
$matched[] = $cat_id;
                          }
                      }
                  }

                  if (
$tags) {
                      foreach (
$tags as $tag) {
                          if (
stripos(trim($tag), $keyword) !== false) {
                              if (!
in_array($cat_id$matched)) {
                                  
$matched[] = $cat_id;
                              }
                          }
                      }
                  }
              }
          }

          
$matched    array_flip($matched);
          
$current    array_flip($current);

          foreach (
$matched as $cat_id => $value) {
              if (isset(
$current[$cat_id])) {
                  unset(
$matched[$cat_id]);
                  unset(
$current[$cat_id]);
              }
          }
    
          
$db VF::factory('database');

          if (
$matched) {
              foreach (
$matched as $cat_id => $value) {
                  
$db->query("
                      INSERT INTO #__video_category
                      SET cat_id = "
.$cat_id.",
                          video_id = "
.$video_id
                  
);

                  
$db->query("
                      UPDATE #__video_categories
                      SET total_videos = total_videos+1
                      WHERE cat_id = "
.$cat_id."
                      LIMIT 1
                  "
);
              }
        }
    
          if (
$current) {
              foreach (
$current as $cat_id => $value) {
                  
$db->query("
                      DELETE FROM #__video_category
                      WHERE cat_id = "
.$cat_id."
                      AND video_id = "
.$video_id."
                      LIMIT 1"
                  
);

                  
$db->query("
                      UPDATE #__video_categories
                      SET total_videos = total_videos-1
                      WHERE cat_id = "
.$cat_id."
                      LIMIT 1
                  "
);
              }
          }
      }
}
Онлайн: 0
Реклама