Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. /* ---------------- getTags ---------------- */
  2. if (!function_exists('getTags')) {
  3.     function getTags($cIDs, $tvTags, $days) {
  4.        
  5.         global $modx, $parent;
  6.        
  7.         $docTags = array ();
  8.  
  9.         $baspath= $modx->config["base_path"] . "manager/includes";
  10.         include_once $baspath . "/tmplvars.format.inc.php";
  11.         include_once $baspath . "/tmplvars.commands.inc.php";
  12.        
  13.         if ($days > 0) {
  14.             $pub_date = mktime() - $days*24*60*60;
  15.         } else {
  16.             $pub_date = 0;
  17.         }
  18.  
  19.         list($region, $countries) = explode(",", $tvTags);
  20.  
  21.      $tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
  22.      $tb2 = $modx->getFullTableName("site_tmplvars");
  23.      $tb_content = $modx->getFullTableName("site_content");
  24.      $query = "SELECT stv.name,stc.tmplvarid,stc.contentid,stv.type,stv.display,stv.display_params,stc.value";
  25.      $query .= " FROM ".$tb1." stc LEFT JOIN ".$tb2." stv ON stv.id=stc.tmplvarid ";
  26.      $query .= " LEFT JOIN $tb_content tb_content ON stc.contentid=tb_content.id ";
  27.          $query .= " WHERE (stv.name='region' AND stc.contentid IN  (".implode($cIDs,",").") OR ";
  28.          $query .= " stv.name='countries' AND stc.contentid IN  (".implode($cIDs,",").")) ";
  29.          $query .= " AND tb_content.pub_date >= '$pub_date' ";
  30.      $query .= " AND tb_content.published = 1 ";
  31.      $query .= " ORDER BY stc.contentid ASC;";
  32.    
  33.         $rs = $modx->db->query($query);
  34.         $tot = $modx->db->getRecordCount($rs);
  35.         $resourceArray = array();
  36.         for($i=0;$i<$tot;$i++)  {
  37.             $row = @$modx->fetchRow($rs);
  38.             $docTags[$row['contentid']]['tags'] = getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);  
  39.         }
  40.             if ($tot != count($cIDs)) {
  41.             $query = "SELECT name,type,display,display_params,default_text";
  42.             $query .= " FROM $tb2";
  43.             $query .= " WHERE name='".$region."' OR name= '".$countries."'  ";
  44.             $rs = $modx->db->query($query);
  45.             $row = @$modx->fetchRow($rs);
  46.             $defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
  47.             foreach ($cIDs as $id) {
  48.                 if (!isset($docTags[$id]['tags'])) {
  49.                     $docTags[$id]['tags'] = $defaultOutput;
  50.                 }
  51.             }
  52.         }
  53.        
  54.             return $docTags;
  55.     }
  56.    
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement