コード例 #1
0
ファイル: choose_image.php プロジェクト: erico-deh/ocPortal
 /**
  * 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('galleries');
     $only_owned = array_key_exists('only_owned', $options) ? is_null($options['only_owned']) ? NULL : intval($options['only_owned']) : NULL;
     $editable_filter = array_key_exists('editable_filter', $options) ? $options['editable_filter'] : false;
     $tree = get_gallery_content_tree('images', $only_owned, $id, NULL, NULL, is_null($id) ? 0 : 1, false, $editable_filter);
     if (!has_actual_page_access(NULL, 'galleries')) {
         $tree = array();
     }
     $out = '';
     foreach ($tree as $t) {
         $_id = $t['id'];
         if ($id === $_id) {
             foreach ($t['entries'] as $eid => $etitle) {
                 if (is_object($etitle)) {
                     $etitle = @html_entity_decode(strip_tags($etitle->evaluate()), ENT_QUOTES, get_charset());
                 }
                 $out .= '<entry id="' . xmlentities(strval($eid)) . '" 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($_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('images', 'cat', array('id' => intval($default)));
         while (!is_null($cat) && $cat != '') {
             $out .= '<expand>' . $cat . '</expand>';
             $cat = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'parent_id', array('name' => $cat));
         }
     }
     return '<result>' . $out . '</result>';
 }
コード例 #2
0
ファイル: galleries.php プロジェクト: erico-deh/ocPortal
/**
 * Get a list of maps containing all the gallery entries, and path information, under the specified gallery - and those beneath it, recursively.
 *
 * @param  ID_TEXT		The table we are working with
 * @set    images videos
 * @param  ?AUTO_LINK	Only show images/videos submitted by this member (NULL: no filter)
 * @param  ?ID_TEXT		The gallery 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 $gallery 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  boolean		Whether to get a list of child galleries (not just direct ones, recursively), instead of just IDs
 * @param  boolean		Whether to only show for what may be edited by the current member
 * @return array			A list of maps for all galleries. Each map entry containins the fields 'id' (gallery 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_gallery_content_tree($table, $submitter = NULL, $gallery = NULL, $tree = NULL, $title = NULL, $levels = NULL, $use_compound_list = false, $editable_filter = false)
{
    if (is_null($gallery)) {
        $gallery = 'root';
    }
    if (!has_category_access(get_member(), 'galleries', $gallery)) {
        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('galleries', 'fullname', array('name' => $gallery)));
    }
    $tree .= $title;
    // We'll be putting all children in this entire tree into a single list
    $children = array();
    $children[0] = array();
    $children[0]['id'] = $gallery;
    $children[0]['title'] = $title;
    $children[0]['tree'] = $tree;
    $compound_list = $gallery . ',';
    // Children of this category
    $rows = $GLOBALS['SITE_DB']->query_select('galleries', array('name', 'fullname'), array('parent_id' => $gallery), 'ORDER BY add_date DESC', 300);
    $where = array('cat' => $gallery);
    if (!is_null($submitter)) {
        $where['submitter'] = $submitter;
    }
    $erows = $GLOBALS['SITE_DB']->query_select($table, array('id', 'url', 'submitter', 'title'), $where, 'ORDER BY add_date DESC', 300);
    $children[0]['entries'] = array();
    foreach ($erows as $row) {
        if ($editable_filter && !has_edit_permission('mid', get_member(), $row['submitter'], 'cms_galleries', array('galleries', $gallery))) {
            continue;
        }
        $e_title = get_translated_text($row['title']);
        if ($e_title == '') {
            $e_title = basename($row['url']);
        }
        $children[0]['entries'][$row['id']] = $e_title;
    }
    $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) {
        foreach ($rows as $child) {
            $child_id = $child['name'];
            $child_title = get_translated_text($child['fullname']);
            $child_tree = $tree;
            $child_children = get_gallery_content_tree($table, $submitter, $child_id, $child_tree, $child_title, is_null($levels) ? NULL : $levels - 1, $use_compound_list, $editable_filter);
            if ($use_compound_list) {
                list($child_children, $_compound_list) = $child_children;
                $compound_list .= $_compound_list;
            }
            $children = array_merge($children, $child_children);
        }
    }
    $children[0]['compound_list'] = $compound_list;
    return $use_compound_list ? array($children, $compound_list) : $children;
}