Ejemplo n.º 1
0
 /**
  * Standard function to create the standardised category tree
  *
  * @param  ID_TEXT		Notification code
  * @param  ?ID_TEXT		The ID of where we're looking under (NULL: N/A)
  * @return array 			Tree structure
  */
 function create_category_tree($notification_code, $id)
 {
     require_code('downloads');
     if (is_null($id)) {
         $total = $GLOBALS['SITE_DB']->query_value_null_ok('download_categories', 'COUNT(*)');
         if ($total > 300) {
             return parent::create_category_tree($notification_code, $id);
         }
         // Too many, so just allow removing UI
     }
     $pagelinks = get_downloads_tree(NULL, is_null($id) ? NULL : intval($id), NULL, NULL, NULL, is_null($id) ? 0 : 1);
     $filtered = array();
     foreach ($pagelinks as $p) {
         if (strval($p['id']) !== $id) {
             $filtered[] = $p;
         }
     }
     return $filtered;
 }
Ejemplo n.º 2
0
/**
 * Get a list of maps containing all the downloads, and path information, under the specified category - and those beneath it, recursively.
 *
 * @param  ?MEMBER		Only show images/videos submitted by this member (NULL: no filter)
 * @param  ?AUTO_LINK	The category being at the root of our recursion (NULL: true root)
 * @param  ?string		The tree up to this point in the recursion (NULL: blank, as we are starting the recursion)
 * @param  ?ID_TEXT		The name of the $category_id we are currently going through (NULL: look it up). This is here for efficiency reasons, as finding children IDs to recurse to also reveals the childs title
 * @param  ?integer		The number of recursive levels to search (NULL: all)
 * @param  ?AUTO_LINK	Download we do not want to show (NULL: none to not show)
 * @param  boolean		Whether to get a list of child categories (not just direct ones, recursively), instead of just IDs
 * @param  boolean		Whether to only show for what may be edited by the current member
 * @param  boolean		Whether to only show entries that are tar files (addons)
 * @return array			A list of maps for all categories. Each map entry containins the fields 'id' (category ID) and 'tree' (tree path to the category, including the categories own title), and more. Or if $use_compound_list, the tree structure built with pairs containing the compound list in addition to the child branches
 */
function get_downloads_tree($submitter = NULL, $category_id = NULL, $tree = NULL, $title = NULL, $shun = NULL, $levels = NULL, $use_compound_list = false, $editable_filter = false, $tar_filter = false)
{
    if (is_null($category_id)) {
        $category_id = db_get_first_id();
    }
    if (!has_category_access(get_member(), 'downloads', strval($category_id))) {
        return array();
    }
    if (is_null($tree)) {
        $tree = '';
    }
    // Put our title onto our tree
    if (is_null($title)) {
        $title = get_translated_text($GLOBALS['SITE_DB']->query_value('download_categories', 'category', array('id' => $category_id)));
    }
    $tree .= $title;
    $compound_list = strval($category_id) . ',';
    // We'll be putting all children in this entire tree into a single list
    $children = array();
    $children[0] = array();
    $children[0]['id'] = $category_id;
    $children[0]['title'] = $title;
    $children[0]['tree'] = $tree;
    // Children of this category
    $rows = $GLOBALS['SITE_DB']->query_select('download_categories c LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=c.category AND ' . db_string_equal_to('language', user_lang()), array('c.id', 'c.category'), array('parent_id' => $category_id), 'ORDER BY text_original', 300);
    if (count($rows) == 300) {
        $rows = array();
    }
    $where = array('category_id' => $category_id);
    if (!is_null($submitter)) {
        $where['submitter'] = $submitter;
    }
    $erows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('id', 'name', 'submitter', 'original_filename'), $where, 'ORDER BY add_date DESC', 300);
    $children[0]['entries'] = array();
    foreach ($erows as $row) {
        if ($tar_filter && substr(strtolower($row['original_filename']), -4) != '.tar') {
            continue;
        }
        if ($editable_filter && !has_edit_permission('mid', get_member(), $row['submitter'], 'cms_downloads', array('download_downloads', $category_id))) {
            continue;
        }
        if (!is_null($shun) && $shun == $row['id']) {
            continue;
        }
        $children[0]['entries'][$row['id']] = get_translated_text($row['name']);
    }
    $children[0]['child_entry_count'] = count($children[0]['entries']);
    if ($levels === 0) {
        $children[0]['entries'] = array();
    }
    $children[0]['child_count'] = count($rows);
    $tree .= ' > ';
    if ($levels !== 0 || $use_compound_list) {
        foreach ($rows as $child) {
            $child_id = $child['id'];
            $child_title = get_translated_text($child['category']);
            $child_tree = $tree;
            $child_children = get_downloads_tree($submitter, $child_id, $child_tree, $child_title, $shun, is_null($levels) ? NULL : max(0, $levels - 1), $use_compound_list, $editable_filter, $tar_filter);
            if ($use_compound_list) {
                list($child_children, $_compound_list) = $child_children;
                $compound_list .= $_compound_list;
            }
            if ($levels !== 0) {
                $children = array_merge($children, $child_children);
            }
        }
    }
    $children[0]['compound_list'] = $compound_list;
    return $use_compound_list ? array($children, $compound_list) : $children;
}
Ejemplo n.º 3
0
 /**
  * Standard modular run function for ajax-tree hooks. Generates XML for a tree list, which is interpreted by Javascript and expanded on-demand (via new calls).
  *
  * @param  ?ID_TEXT		The ID to do under (NULL: root)
  * @param  array			Options being passed through
  * @param  ?ID_TEXT		The ID to select by default (NULL: none)
  * @return string			XML in the special category,entry format
  */
 function run($id, $options, $default = NULL)
 {
     require_code('downloads');
     if (!is_numeric($id) && $id != '') {
         if (substr($id, 0, 8) == 'Version ') {
             $id_float = floatval(substr($id, 8));
             do {
                 $str = 'Version ' . float_to_raw_string($id_float, 1);
                 $_id = $GLOBALS['SITE_DB']->query_value_null_ok('download_categories c LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON t.id=c.category', 'c.id', array('parent_id' => 3, 'text_original' => $str));
                 if (is_null($_id)) {
                     $id_float -= 0.1;
                 }
             } while (is_null($_id) && $id_float != 0.0);
         } else {
             $_id = $GLOBALS['SITE_DB']->query_value_null_ok('download_categories c LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON t.id=c.category', 'c.id', array('text_original' => $id));
         }
         if (is_null($_id)) {
             warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
         }
         $id = strval($_id);
     }
     $only_owned = array_key_exists('only_owned', $options) ? is_null($options['only_owned']) ? NULL : intval($options['only_owned']) : NULL;
     $shun = array_key_exists('shun', $options) ? $options['shun'] : NULL;
     $editable_filter = array_key_exists('editable_filter', $options) ? $options['editable_filter'] : false;
     $tar_filter = array_key_exists('tar_filter', $options) ? $options['original_filename'] : false;
     $tree = get_downloads_tree($only_owned, is_null($id) ? NULL : intval($id), NULL, NULL, $shun, is_null($id) ? 0 : 1, false, $editable_filter, $tar_filter);
     if (!has_actual_page_access(NULL, 'downloads')) {
         $tree = array();
     }
     $file_type = get_param('file_type', '');
     $out = '';
     foreach ($tree as $t) {
         $_id = $t['id'];
         if ($id === strval($_id)) {
             asort($t['entries']);
             foreach ($t['entries'] as $eid => $etitle) {
                 $row = $GLOBALS['SITE_DB']->query_select('download_downloads', array('description', 'original_filename'), array('id' => $eid), '', 1);
                 if ($file_type != '') {
                     if (substr($row[0]['original_filename'], -strlen($file_type) - 1) != '.' . $file_type) {
                         continue;
                     }
                 }
                 $lang_id = $row[0]['description'];
                 $description = get_translated_text($lang_id);
                 $description_html = get_translated_tempcode($lang_id);
                 $images_details = new ocp_tempcode();
                 if (addon_installed('galleries')) {
                     // Images
                     $_out = new ocp_tempcode();
                     require_lang('galleries');
                     $cat = 'download_' . strval($eid);
                     $map = array('cat' => $cat);
                     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
                         $map['validated'] = 1;
                     }
                     $rows = $GLOBALS['SITE_DB']->query_select('images', array('*'), $map, 'ORDER BY id', 200);
                     $counter = 0;
                     $div = 2;
                     $_out = new ocp_tempcode();
                     $_row = new ocp_tempcode();
                     require_code('images');
                     while (array_key_exists($counter, $rows)) {
                         $row = $rows[$counter];
                         //		$view_url=build_url(array('page'=>'galleries','type'=>'image','wide'=>1,'id'=>$row['id']),get_module_zone('galleries'));
                         $view_url = $row['url'];
                         if (url_is_local($view_url)) {
                             $view_url = get_custom_base_url() . '/' . $view_url;
                         }
                         $thumb_url = ensure_thumbnail($row['url'], $row['thumb_url'], 'galleries', 'images', $row['id']);
                         $comment = get_translated_tempcode($row['comments']);
                         $thumb = do_image_thumb($thumb_url, '');
                         $iedit_url = new ocp_tempcode();
                         $_content = do_template('DOWNLOAD_SCREEN_IMAGE', array('_GUID' => 'fba0e309aa0ae04891e32c65a625b177', 'ID' => strval($row['id']), 'VIEW_URL' => $view_url, 'EDIT_URL' => $iedit_url, 'THUMB' => $thumb, 'COMMENT' => $comment));
                         $_row->attach(do_template('DOWNLOAD_GALLERY_IMAGE_CELL', array('_GUID' => '8400a832dbed64bb63f264eb3a038895', 'CONTENT' => $_content)));
                         if ($counter % $div == 1 && $counter != 0) {
                             $_out->attach(do_template('DOWNLOAD_GALLERY_ROW', array('_GUID' => '205c4f5387e98c534d5be1bdfcccdd7d', 'CELLS' => $_row)));
                             $_row = new ocp_tempcode();
                         }
                         $counter++;
                     }
                     if (!$_row->is_empty()) {
                         $_out->attach(do_template('DOWNLOAD_GALLERY_ROW', array('_GUID' => 'e9667ca2545ac72f85a873f236cbbd6f', 'CELLS' => $_row)));
                     }
                     $images_details = put_in_standard_box($_out);
                 }
                 $description_html->attach($images_details);
                 $out .= '<entry id="' . xmlentities(strval($eid)) . '" description="' . xmlentities(strip_comcode($description)) . '" description_html="' . xmlentities($description_html->evaluate()) . '" title="' . xmlentities($etitle) . '" selectable="true"></entry>';
             }
             continue;
         }
         $title = $t['title'];
         $has_children = $t['child_count'] != 0 || $t['child_entry_count'] != 0;
         $out .= '<category id="' . xmlentities(strval($_id)) . '" title="' . xmlentities($title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="false"></category>';
     }
     // Mark parent cats for pre-expansion
     if (!is_null($default) && $default != '') {
         $cat = $GLOBALS['SITE_DB']->query_value_null_ok('download_downloads', 'category_id', array('id' => intval($default)));
         while (!is_null($cat)) {
             $out .= '<expand>' . strval($cat) . '</expand>';
             $cat = $GLOBALS['SITE_DB']->query_value_null_ok('download_categories', 'parent_id', array('id' => $cat));
         }
     }
     return '<result>' . $out . '</result>';
 }