Advertisement
Guest User

accessit class

a guest
Jan 9th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. class Accessit {
  2.    
  3.     private static $_instance;
  4.     private static $DIV_NAMES = array();
  5.  
  6.     private function __construct($xoopsDB)
  7.     {
  8.         $this->xoopsDB          = $xoopsDB;
  9.     }
  10.    
  11.     private function __clone () {}
  12.    
  13.     public static function getInstance($xoopsDB)
  14.     {
  15.         if (!(self::$_instance instanceof self)) self::$_instance = new self($xoopsDB);
  16.         return self::$_instance;
  17.     }
  18.    
  19.     public function retDivNames()
  20.     {
  21.         $this->DIV_NAMES    = array();
  22.         $TMP            = array();
  23.        
  24.         $table = $this->xoopsDB->prefix('tplsource');
  25.         $sql = "SELECT tpl_source FROM " . $table . ";";
  26.        
  27.         $result = $this->xoopsDB->queryF($sql);
  28.        
  29.         while($row = $this->xoopsDB->fetchArray($result))
  30.         {
  31.             foreach($row as $value)
  32.             {
  33.                 $TMP[] = $value;
  34.             }
  35.         }
  36.        
  37.         foreach($TMP as $var)
  38.         {
  39.             $html = str_get_html(($var));
  40.             foreach($html->find('div') as $element)
  41.                 if(is_string($element->id))
  42.                     if(stripos($element->id, "<"))
  43.                     {
  44.                         $this->DIV_NAMES[] = substr($element->id, 0, stripos($element->id, "<"));
  45.                     }else
  46.                     {
  47.                         $this->DIV_NAMES[] = $element->id;
  48.                     }
  49.         }
  50.        
  51.         $this->DIV_NAMES = array_unique($this->DIV_NAMES);
  52.         sort($this->DIV_NAMES);
  53.        
  54.         // insertion of the div names in the accessit table
  55.         $table = $this->xoopsDB->prefix('accessit');
  56.        
  57.        
  58.         foreach($this->DIV_NAMES as $value)
  59.         {
  60.             $sql = 'SELECT id FROM ' . $table . ' WHERE div_name=\'' . $value . '\';';
  61.             $result = $this->xoopsDB->queryF($sql);
  62.  
  63.             if(!$this->xoopsDB->fetchArray($result))
  64.             {
  65.                 $sql = 'INSERT INTO ' . $table . ' (div_name) VALUES (\'' . $value . '\');';
  66.                 $this->xoopsDB->queryF($sql);
  67.             }
  68.         }
  69.        
  70.         return $this->DIV_NAMES;
  71.     }
  72.    
  73.  
  74.     public function getDivNamesFromDb()
  75.     {
  76.         $table = $this->xoopsDB->prefix('accessit');
  77.         $sql = 'SELECT div_name, role FROM ' . $table . ';';
  78.  
  79.         $result = $this->xoopsDB->queryF($sql);
  80.  
  81.         while($row = $this->xoopsDB->fetchArray($result))
  82.         {
  83.             $this->DIV_NAMES[$row['div_name']] = $row['role'];
  84.         }
  85.        
  86.  
  87.         return $this->DIV_NAMES;
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement