function contents_csv() { global $xoopsDB, $status_sel; $rec = split(',', 'mid,title,ctime,mtime,poster,hits,status'); $res = $xoopsDB->query("SELECT name,label,type,weight FROM " . FIELDS . " ORDER BY weight"); $labels = array('mid' => 'ID', 'hits' => _AM_HITS, 'status' => _AM_STATUS); while (list($name, $label, $type, $w) = $xoopsDB->fetchRow($res)) { $labels[$name] = $w ? $label : "[{$label}]"; if ($type == 'link') { continue; } if (!in_array($name, $rec)) { $rec[] = $name; } } $head = array(); foreach ($rec as $n) { $head[] = $labels[$n]; } $buf = join(',', array_map('quote_csv', $head)) . "\n"; $file = 'medialinks-' . formatTimestamp(time(), 'Ymd') . '.csv'; $res = $xoopsDB->query("SELECT * FROM " . MAIN . " ORDER BY status,mid"); while ($data = $xoopsDB->fetchArray($res)) { $row = array(); foreach ($rec as $n) { $keys = keys_expand($data['mid']); if (preg_match('/\\[(\\d+)\\]$/', $n, $d)) { $v = isset($keys[$d[1]]) ? $keys[$d[1]] : ''; } else { $v = $data[$n]; } switch ($n) { case 'mtime': case 'ctime': $row[] = formatTimestamp($v); break; case 'poster': $row[] = XoopsUser::getUnameFromId($v); break; case 'status': if (isset($status_sel[$v])) { $v = $status_sel[$v]; } default: $row[] = $v; } } $buf .= join(',', array_map('quote_csv', $row)) . "\n"; } export_out($file, $buf); }
function ml_index_view($order, $trim, $keyid = 0, $verb = 0, $max = 0, $start = 0, $fmt = 's') { global $xoopsDB, $xoopsUser, $keywords; $myts =& MyTextSanitizer::getInstance(); $modpath = dirname(__FILE__); $dirname = basename($modpath); $modurl = XOOPS_URL . "/modules/{$dirname}"; $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname($dirname); $isadmin = $uid && $xoopsUser->isAdmin($module->getVar('mid')); $cond = "status='N'"; if ($keyid) { $kcond = 'keyref IN (' . join(',', array_map('intval', explode(',', $keyid))) . ')'; $res = $xoopsDB->query("SELECT midref FROM " . RELAY . " WHERE " . $kcond); $mids = array(); while (list($mid) = $xoopsDB->fetchRow($res)) { $mids[] = $mid; } $mids = array_unique($mids); if (count($mids)) { $cond .= " AND mid IN (" . join(',', $mids) . ")"; } else { return array(); } } $acl = ""; if (!$isadmin) { // check access control $acl = " LEFT JOIN " . $xoopsDB->prefix('medialinks_access') . " ON amid=mid AND auid={$uid}"; $cond .= " AND (nacl=0 OR auid>0)"; } $sql = " FROM " . $xoopsDB->prefix('medialinks') . " {$acl} WHERE {$cond}"; $result = $xoopsDB->query("SELECT count(mid) {$sql}"); list($n) = $xoopsDB->fetchRow($result); $result = $xoopsDB->query("SELECT mid, title, description, ctime, mtime, poster, hits {$sql} ORDER BY {$order}", $max, $start); if (!$result || $xoopsDB->getRowsNum($result) == 0) { return null; } $len = $verb == 0 ? $trim : 0; // only trim short style if ($verb == 2) { require_once $modpath . "/screenshot.php"; } $dirname = basename(dirname(__FILE__)); $modurl = XOOPS_URL . "/modules/{$dirname}"; $media = array('order' => preg_replace('/[\\s,].*$/', '', $order), 'count' => $n, 'verbose' => $verb, 'dirname' => $dirname, 'module_url' => $modurl); $contents = array(); while ($myrow = $xoopsDB->fetchArray($result)) { $myrow['title'] = ml_mysubstr($myrow['title'], $len); $desc = $myts->displayTarea($myrow["description"]); $myrow['description'] = $desc; $myrow['shortdesc'] = ml_mysubstr(strip_tags($desc), 50); $myrow['cdate'] = formatTimestamp($myrow['ctime'], $fmt); $myrow['mdate'] = formatTimestamp($myrow['mtime'], $fmt); $myrow['uname'] = XoopsUser::getUnameFromId($myrow['poster']); if ($verb == 2) { $myrow['image'] = ml_screenshot($myrow['mid']); } // keywords expand $myrow['keywords'] = keys_expand($myrow['mid']); $contents[] = $myrow; } $media['contents'] = $contents; return $media; }