Exemplo n.º 1
0
function amr_generate_csv($ulist, $strip_endings, $strip_html = false, $suffix, $wrapper, $delimiter, $nextrow, $tofile = false)
{
    /* get the whole cached file - write to file? but security / privacy ? */
    /* how big */
    $c = new adb_cache();
    $rptid = $c->reportid($ulist);
    $total = $c->get_cache_totallines($rptid);
    $lines = $c->get_cache_report_lines($rptid, 1, $total + 1);
    /* we want the heading line (line1), but not the internal nameslines (line 0) , plus all the data lines, so neeed total + 1 */
    if (isset($lines) and is_array($lines)) {
        $t = count($lines);
    } else {
        $t = 0;
    }
    $csv = '';
    if ($t > 0) {
        if ($strip_endings) {
            foreach ($lines as $k => $line) {
                $csv .= apply_filters('amr_users_csv_line', $line['csvcontent']) . $nextrow;
            }
        } else {
            foreach ($lines as $k => $line) {
                $csv .= $line['csvcontent'] . $nextrow;
            }
        }
        $csv = str_replace('","', $wrapper . $delimiter . $wrapper, $csv);
        /* we already have in std csv - allow for other formats */
        $csv = str_replace($nextrow . '"', $nextrow . $wrapper, $csv);
        $csv = str_replace('"' . $nextrow, $wrapper . $nextrow, $csv);
        if ($csv[0] == '"') {
            $csv[0] = $wrapper;
        }
    }
    if (amr_debug()) {
        echo '<br />In Debug only: Csv setup: Report: ' . $ulist . ' ' . $c->reportname($ulist) . ' ' . sprintf(__('%s lines found, 1 heading line, the rest data.', 'amr-users'), $t);
        $bytes = mb_strlen($csv);
        echo ' Size = ' . amru_convert_mem($bytes) . '<br />';
    }
    if ($tofile) {
        $csvfile = amr_users_to_csv($ulist, $csv, $suffix);
        $csvurl = amr_users_get_csv_link($ulist);
        //return ($csvurl);
        $html = '<br />' . __('Public user list csv file: ', 'amr-users') . '<br />' . $csvurl;
    } else {
        echo '<p>' . sprintf(__('List %s, %s lines, plus heading line'), $ulist, $t) . '</p>';
        $html = amr_csv_form($csv, $suffix);
    }
    return $html;
}
Exemplo n.º 2
0
function amr_lines_to_csv($lines, $ulist, $strip_endings, $strip_html = false, $suffix, $wrapper, $delimiter, $nextrow, $tofile = false)
{
    if (isset($lines) and is_array($lines)) {
        $t = count($lines);
    } else {
        $t = 0;
    }
    $csv = '';
    if ($t > 0) {
        array_walk($lines, 'amr_undo_db_slashes');
        array_walk($lines, 'amr_remove_ID_from_front');
        // REMOVE technical ID
        if ($strip_endings) {
            foreach ($lines as $k => $line) {
                $csv .= apply_filters('amr_users_csv_line', $line['csvcontent']) . $nextrow;
            }
        } else {
            foreach ($lines as $k => $line) {
                $csv .= $line['csvcontent'] . $nextrow;
            }
        }
        $csv = str_replace('","', $wrapper . $delimiter . $wrapper, $csv);
        /* we already have in std csv - allow for other formats */
        $csv = str_replace($nextrow . '"', $nextrow . $wrapper, $csv);
        $csv = str_replace('"' . $nextrow, $wrapper . $nextrow, $csv);
        if ($csv[0] == '"') {
            $csv[0] = $wrapper;
        }
        // 20140722 }
        if (amr_debug()) {
            echo '<br />In Debug only: Csv setup: Report: ' . $ulist . ' ' . sprintf(__('%s lines found, 1 heading line, the rest data.', 'amr-users'), $t);
            $bytes = mb_strlen($csv);
            echo ' Size = ' . amru_convert_mem($bytes) . '<br />';
        }
        if ($tofile) {
            $csvfile = amr_users_to_csv($ulist, $csv, $suffix);
            $csvurl = amr_users_get_csv_link($ulist, $suffix);
            if ($suffix == 'txt') {
                $html = '<br />' . __('Public user list txt file: ', 'amr-users') . '<br />' . $csvurl;
            } else {
                $html = '<br />' . __('Public user list csv file: ', 'amr-users') . '<br />' . $csvurl;
            }
        } else {
            echo '<p>' . sprintf(__('List %s, %s lines, plus heading line', 'amr-users'), $ulist, $t) . '</p>';
            $html = amr_csv_form($csv, $suffix);
        }
    } else {
        // 20140722 added empty file check
        $csv = '';
        //20140722 empty so previous file will be deleted
        $csvurl = amr_users_get_csv_link($ulist, $suffix);
        $html = '<br />' . __('No lines found.', 'amr-users');
    }
    return $html;
}
 function amr_check_memory()
 {
     /* */
     if (!function_exists('memory_get_peak_usage')) {
         return false;
     }
     $mem_usage = memory_get_peak_usage(true);
     $html = amru_convert_mem($mem_usage);
     return $html;
 }