if (@txpinterface == 'admin') { add_privs('upm_file_popper', '1,2,3,4,5'); register_callback('upm_file_popper', 'upm_file_popper'); add_privs('upm_file_popper_link', '1,2,3,4,5'); register_callback('upm_file_popper_link', 'article'); add_privs('upm_file_popper_js', '1,2,3,4,5'); register_callback('upm_file_popper_js', 'upm_file_popper_js', '', 1); add_privs('upm_file_popper_img', '1,2,3,4,5'); register_callback('upm_file_popper_img', 'upm_file_popper_img', '', 1); register_callback('upm_file_popper_menu', 'article_ui', 'extend_col_1'); } /** * Insert upm_file_popper link in column 1 on the write-tab * * @param string $event (article_ui) * @param string $step (extend_col_1) */ function upm_file_popper_menu($event, $step) { return '

'.upm_file_popper_gTxt('attach_file').'

'; } // ------------------------------------------------------------- function upm_file_popper() { global $step, $prefs; if ($step == 'upm_file_popper_change_pageby') { event_change_pageby('file'); $GLOBALS['prefs'] = get_prefs(); } upm_file_popper_list(); } // ------------------------------------------------------------- function upm_file_popper_list() { global $file_base_path, $prefs; pagetop(upm_file_popper_gTxt('file_selector')); echo << css; extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') $sort = get_pref('file_sort_column', 'filename'); if ($dir === '') $dir = get_pref('file_sort_dir', 'asc'); $dir = ($dir == 'desc') ? 'desc' : 'asc'; switch ($sort) { case 'id': $sort_sql = "id $dir, filename asc"; break; case 'filename': $sort_sql = "filename $dir"; break; case 'description': $sort_sql = 'description '.$dir.', filename desc'; break; case 'category': $sort_sql = "category $dir, filename asc"; break; case 'downloads': $sort_sql = "downloads $dir, filename asc"; break; default: $dir = 'desc'; $sort_sql = "filename $dir"; break; } $switch_dir = ($dir == 'desc') ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit) { $crit_escaped = doSlash($crit); $critsql = array( 'id' => "id = '$crit_escaped'", 'filename' => "filename like '%$crit_escaped%'", 'category' => "category like '%$crit_escaped%'", 'description' => "description like '%$crit_escaped%'" ); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $total = safe_count('txp_file', "$criteria"); if ($total < 1) { if ($criteria != 1) { echo n.upm_file_popper_search_form($crit, $search_method, $sort, $dir). n.graf(gTxt('no_results_found'), ' style="text-align: center;"'); } else { echo n.graf(gTxt('no_files_recorded'), ' style="text-align: center;"'); } return; } $limit = max($prefs['file_list_pageby'], 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo upm_file_popper_search_form($crit, $search_method, $sort, $dir); $rs = safe_rows_start('*', 'txp_file', "$criteria order by $sort_sql limit $offset, $limit"); if ($rs) { $sort_link = 'upm_file_popper'.a.'bm=true'; echo startTable('','','txp-list'), tr( column_head('ID', 'id', $sort_link, true, $switch_dir, $crit, $search_method). column_head('file_name', 'filename', $sort_link, true, $switch_dir, $crit, $search_method). column_head('description', 'description', $sort_link, true, $switch_dir, $crit, $search_method). column_head('file_category', 'category', $sort_link, true, $switch_dir, $crit, $search_method). hCell(). hCell(gTxt('tags')). hCell(gTxt('status')). column_head('downloads', 'downloads', $sort_link, true, $switch_dir, $crit, $search_method) ); while ($a = nextRow($rs)) { extract($a); // god I hate javascript in php $insert = ''.upm_file_popper_gTxt('attach_file').''; $tag_url = '?event=tag'.a.'tag_name=file_download_link'.a.'id='.$id.a.'description='.urlencode($description). a.'filename='.urlencode($filename); $file_exists = file_exists(build_file_path($file_base_path, $filename)); $status = ($file_exists) ? ''.gTxt('file_status_ok').'' : ''.gTxt('file_status_missing').''; if (!isset($downloads)) { safe_alter('txp_file', "ADD downloads INT DEFAULT '0' NOT NULL"); $downloads = 0; } elseif (empty($downloads)) { $downloads = '0'; } echo n.n.tr( n.td($id). td(''.$filename.'', 125). td($description, 150). td($category, 90). td($insert). td( n.'' , 75). td($status, 45). td( ($downloads == '0' ? gTxt('none') : $downloads) , 25) ); } echo endTable(). nav_form('upm_file_popper', $page, $numPages, $sort, $dir, $crit, $search_method). upm_file_popper_pageby_form(). n.tag( n.graf(upm_file_popper_gTxt('return')). n.graf(''.gTxt('yes').'.'. ' '.gTxt('no').'.') , 'div', ' id="return" style="display: none; width: 200px; height: 75px;"'). n.graf(upm_file_popper_gTxt('success'), ' id="success" style="display: none; width: 150px; height: 35px;"'). n.graf(upm_file_popper_gTxt('failed'), ' id="failed" style="display: none; width: 150px; height: 35px;"'); } } // ------------------------------------------------------------- function upm_file_popper_search_form($crit, $method, $sort, $dir) { $default_method = 'filename'; $method = ($method) ? $method : $default_method; $methods = array( 'id' => gTxt('id'), 'filename' => gTxt('file_name'), 'description' => gTxt('description'), 'category' => gTxt('file_category') ); return n.n.'
'. graf( ''.sp. selectInput('search_method', $methods, $method, '', '', 'upm-file-popper-search').sp. fInput('text', 'crit', $crit, 'edit', '', '', '15'). eInput('upm_file_popper'). hInput('bm','true'). fInput('submit', 'search', gTxt('go'), 'smallerbox') ). ($crit ? n.graf(''.upm_file_popper_gTxt('view_all').'') : ''). n.'
'; } // ------------------------------------------------------------- function upm_file_popper_pageby_form() { global $prefs; $vals = array( 15 => 15, 25 => 25, 50 => 50, 100 => 100 ); $select_page = selectInput('qty', $vals, $prefs['file_list_pageby'], '', 1); // proper localisation $page = str_replace('{page}', $select_page, gTxt('view_per_page')); return form( '
'. $page. eInput('upm_file_popper'). sInput('upm_file_popper_change_pageby'). hInput('bm', '1'). ''. '
' ); } // ------------------------------------------------------------- function upm_file_popper_link() { $view = gps('view'); if ($view == 'text' or empty($view)) { echo <<
form; } } // ------------------------------------------------------------- function upm_file_popper_js() { global $prefs; while (@ob_end_clean()); header("Content-type: text/javascript"); if (empty($prefs['upm_file_field'])) { $lang_forgot_field = upm_file_popper_gTxt('forgot_field'); echo << a:contains("$txt")'). before(link); }); js; exit(0); } elseif (gps('name') == 'pop') { $lang_check_leave = upm_file_popper_gTxt('check_leave'); echo << 'Attach', 'attach_file' => 'Attach File', 'check_leave' => 'You have made changes to the current post which you have not saved. Continue without saving?', 'description_for' => 'Description for', 'failed' => 'Insert failed.', 'file_selector' => 'File Selector', 'forgot_field' => 'You forgot to define the custom field for upm_file/upm_file_popper to use. Ensure that you have a custom field available, and that you have upm_file installed and activated, then visit Extensions > upm_file.', 'no_description' => 'No description has been defined for this file.', 'packet_custom_field' => 'Packet Custom Field', 'return' => 'Return to editing the post?', 'success' => 'Success.', 'view_all' => 'View All' ); return strtr($lang[$var], $atts); }