function midgard_admin_asgard_trash_type_show($object, $indent = 0, $prefix = '', $enable_undelete = true)
{
    static $persons = array();
    static $shown = array();
    static $url_prefix = '';
    if (!$url_prefix) {
        $url_prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
    }
    if (isset($shown[$object->guid])) {
        return;
    }
    if (!isset($persons[$object->metadata->revisor])) {
        $persons[$object->metadata->revisor] = midcom::get('auth')->get_user($object->metadata->revisor);
    }
    $reflector = midcom_helper_reflector_tree::get($object);
    $icon = $reflector->get_object_icon($object);
    echo "{$prefix}<tr>\n";
    $disabled = '';
    if (!$enable_undelete) {
        $disabled = ' disabled="disabled"';
    }
    $object_label = $reflector->get_object_label($object);
    if (empty($object_label)) {
        $object_label = $object->guid;
    }
    echo "{$prefix}    <td class=\"checkbox\"><input type=\"checkbox\" name=\"undelete[]\"{$disabled} value=\"{$object->guid}\" id=\"guid_{$object->guid}\" /></td>\n";
    echo "{$prefix}    <td class=\"label\" style=\"padding-left: {$indent}px\"><label for=\"guid_{$object->guid}\">{$icon}" . $object_label . "</label></td>\n";
    echo "{$prefix}    <td class=\"nowrap\">" . strftime('%x %X', strtotime($object->metadata->revised)) . "</td>\n";
    if (isset($persons[$object->metadata->revisor]->guid)) {
        echo "{$prefix}    <td><a href=\"{$url_prefix}__mfa/asgard/object/view/{$persons[$object->metadata->revisor]->guid}/\">{$persons[$object->metadata->revisor]->name}</a></td>\n";
    } else {
        echo "{$prefix}    <td>&nbsp;</td>\n";
    }
    echo "{$prefix}    <td>" . midcom_helper_misc::filesize_to_string($object->metadata->size) . "</td>\n";
    echo "{$prefix}</tr>\n";
    $child_types = midcom_helper_reflector_tree::get_child_objects($object, true);
    if (is_array($child_types) && count($child_types) > 0) {
        $child_indent = $indent + 20;
        echo "{$prefix}<tbody class=\"children\">\n";
        foreach ($child_types as $type => $children) {
            if (count($children) < 10 || isset($_GET['show_children'][$object->guid][$type])) {
                foreach ($children as $child) {
                    midgard_admin_asgard_trash_type_show($child, $child_indent, "{$prefix}    ", false);
                }
            } else {
                echo "{$prefix}    <tr>\n";
                echo "{$prefix}        <td class=\"label\" style=\"padding-left: {$child_indent}px\" colspan=\"5\"><a href=\"?show_children[{$object->guid}][{$type}]=1\">" . sprintf(midcom::get('i18n')->get_string('show %s %s children', 'midgard.admin.asgard'), count($children), midgard_admin_asgard_plugin::get_type_label($type)) . "</a></td>\n";
                echo "{$prefix}    </tr>\n";
            }
        }
        echo "{$prefix}</tbody>\n";
    }
    $shown[$object->guid] = true;
}
示例#2
0
文件: test.php 项目: nemein/openpsa
<?php

/**
 * @package midcom.helper.reflector
 * @author The Midgard Project, http://www.midgard-project.org
 * @copyright The Midgard Project, http://www.midgard-project.org
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 */
if (!isset($_GET['guid']) || empty($_GET['guid'])) {
    throw new midcom_error_notfound('Specify $guid via GET for info');
}
$object = midcom::get('dbfactory')->get_object_by_guid($_GET['guid']);
$reflector =& midcom_helper_reflector::get($object);
echo "Got " . $reflector->get_class_label() . ' "' . $reflector->get_object_label($object) . "\", dump<pre>\n";
var_dump($object);
echo "</pre>\n";
if (midcom_helper_reflector_tree::has_children($object)) {
    echo "Object has children<br/>\n";
    echo "Child counts <pre>\n";
    $counts = midcom_helper_reflector_tree::count_child_objects($object);
    print_r($counts);
    echo "</pre>\n";
    echo "Child objects dump<pre>\n";
    $children = midcom_helper_reflector_tree::get_child_objects($object);
    var_dump($children);
    echo "</pre>\n";
}
示例#3
0
文件: copy.php 项目: nemein/openpsa
 /**
  * Copy an object tree. Both source and parent may be liberally filled. Source can be either
  * MgdSchema or MidCOM db object or GUID of the object and parent can be
  *
  * - MgdSchema object
  * - MidCOM db object
  * - predefined target array (@see get_target_properties())
  * - ID or GUID of the object
  * - left empty to copy as a parentless object
  *
  * This method is self-aware and will refuse to perform any infinite loops (e.g. to copy
  * itself to its descendant, copying itself again and again and again).
  *
  * Eventually this method will return the first root object that was created, i.e. the root
  * of the new tree.
  *
  * @param mixed $source        GUID or MgdSchema object that will be copied
  * @param mixed $parent        MgdSchema or MidCOM db object, predefined array or ID of the parent object
  * @return mixed               False on failure, newly created MgdSchema root object on success
  */
 public function copy_tree(&$source, &$parent)
 {
     // Copy the root object
     $root = $this->copy_object($source, $parent);
     if (!$root || !$root->guid) {
         $this->errors[] = sprintf($this->_l10n->get('failed to copy object %s'), $source->guid);
         return false;
     }
     // Add the newly copied object to the exclusion list to prevent infinite loops
     $this->exclude[] = $this->source->guid;
     // Get the children
     $children = midcom_helper_reflector_tree::get_child_objects($source);
     if (!$children || count($children) === 0) {
         return $root;
     }
     // Loop through the children and copy them to their corresponding parents
     foreach ($children as $subchildren) {
         // Get the children of each type
         foreach ($subchildren as $child) {
             // Skip the excluded child
             if (in_array($child->guid, $this->exclude)) {
                 continue;
             }
             $this->copy_tree($child, $root);
         }
     }
     // Return the newly created root object
     return $root;
 }
示例#4
0
 /**
  * Helper method for purging objects
  *
  * @param Array $guids
  * @param string $type
  * @return boolean Indicating success
  */
 public static function purge($guids, $type)
 {
     $purged_size = 0;
     foreach ($guids as $guid) {
         $object = midcom_helper_reflector::get_object($guid, $type);
         if (is_null($object)) {
             debug_add("Failed to get object {$type} {$guid}", MIDCOM_LOG_ERROR);
             // Something wrong
             continue;
         }
         // first kill your children
         $children_types = midcom_helper_reflector_tree::get_child_objects($object, true);
         if (is_array($children_types)) {
             foreach ($children_types as $child_type => $children) {
                 $child_guids = array();
                 foreach ($children as $child) {
                     if (!$child->metadata->deleted) {
                         $child->delete();
                     }
                     $child_guids[] = $child->guid;
                 }
                 self::purge($child_guids, $child_type);
             }
         }
         // then shoot your dogs
         $purged_size += self::purge_parameters($guid);
         $purged_size += self::purge_attachments($guid);
         // now shoot yourself
         if (!$object->purge()) {
             debug_add("Failed to purge object " . get_class($object) . " {$object->guid}", MIDCOM_LOG_INFO);
         } else {
             $purged_size += $object->metadata->size;
         }
     }
     return $purged_size;
 }
示例#5
0
文件: delete.php 项目: nemein/openpsa
 private static function _get_child_objects($object)
 {
     $children = midcom_helper_reflector_tree::get_child_objects($object);
     if ($children === false) {
         debug_add('Failed to query the children of object {$object->guid}: ' . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
     }
     return $children;
 }
示例#6
0
 /**
  * List the child elements
  *
  * @param mixed $object     MgdSchema object
  * @param string $prefix     Indent for the output
  * @param int $level         Level of depth
  */
 public function _list_child_elements($object, $prefix = '    ', $level = 0)
 {
     if ($level > 25) {
         debug_add('Recursion level 25 exceeded, aborting', MIDCOM_LOG_ERROR);
         return;
     }
     $siblings = midcom_helper_reflector_tree::get_child_objects($object);
     if (is_array($siblings) && count($siblings) > 0) {
         echo "{$prefix}<ul>\n";
         foreach ($siblings as $type => $children) {
             foreach ($children as $child) {
                 if (isset($this->shown_objects[$child->guid])) {
                     continue;
                 }
                 $ref =& $this->_get_reflector($child);
                 $span_class = '';
                 $css_class = $type;
                 $this->_common_css_classes($child, $ref, $css_class);
                 $this->shown_objects[$child->guid] = true;
                 echo "{$prefix}    <li class=\"{$css_class}\">\n";
                 $label = htmlspecialchars($ref->get_object_label($child));
                 $icon = $ref->get_object_icon($child);
                 if (empty($label)) {
                     $label = "#{$child->id}";
                 }
                 if ($this->copy_tree) {
                     $checked = ' checked="checked"';
                 } else {
                     $checked = '';
                 }
                 if ($this->inputs) {
                     // This value is used for compiling the exclusion list: if the object is found from this list, but not from the selection list,
                     // it means that the selection did not include the object GUID
                     echo "{$prefix}        <input type=\"hidden\" name=\"all_objects[]\" value=\"{$child->guid}\" />\n";
                     echo "{$prefix}        <label for=\"item_{$child->guid}\">\n";
                     echo "{$prefix}        <input id=\"item_{$child->guid}\" type=\"{$this->input_type}\" name=\"{$this->input_name}\" value=\"{$child->guid}\"{$checked} />\n";
                 }
                 echo "{$prefix}            <span class=\"title{$span_class}\">{$icon}{$label}</span>\n";
                 // Show the link to the object
                 if ($this->view_link) {
                     echo "{$prefix}            <a href=\"{$this->page_prefix}__mfa/asgard/object/view/{$child->guid}/\" class=\"thickbox\" target=\"_blank\" title=\"" . sprintf(midcom::get('i18n')->get_string('%s (%s)', 'midgard.admin.asgard'), $label, $ref->get_class_label()) . "\">\n";
                     echo "{$prefix}                <img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/view.png\" alt=\"" . midcom::get('i18n')->get_string('view object', 'midgard.admin.asgard') . "\" />\n";
                     echo "{$prefix}            </a>\n";
                 }
                 // Show the link to the object
                 if ($this->edit_link) {
                     echo "{$prefix}            <a href=\"{$this->page_prefix}__mfa/asgard/object/edit/{$child->guid}/\" class='target_blank' title=\"" . sprintf(midcom::get('i18n')->get_string('%s (%s)', 'midgard.admin.asgard'), $label, $ref->get_class_label()) . "\">\n";
                     echo "{$prefix}                <img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/edit.png\" alt=\"" . midcom::get('i18n')->get_string('edit object', 'midgard.admin.asgard') . "\" />\n";
                     echo "{$prefix}            </a>\n";
                 }
                 if ($this->inputs) {
                     echo "{$prefix}        </label>\n";
                 }
                 // List the child elements
                 $this->_list_child_elements($child, "{$prefix}        ", $level + 1);
                 echo "{$prefix}    </li>\n";
             }
         }
         echo "{$prefix}</ul>\n";
     }
 }
示例#7
0
 private function _list_child_elements($object, $prefix = '    ', $level = 0)
 {
     if ($level > 25) {
         debug_add('Recursion level 25 exceeded, aborting', MIDCOM_LOG_ERROR);
         return;
     }
     $siblings = midcom_helper_reflector_tree::get_child_objects($object);
     if (is_array($siblings) && count($siblings) > 0) {
         echo "{$prefix}<ul>\n";
         foreach ($siblings as $type => $children) {
             $label_mapping = array();
             $i = 0;
             foreach ($children as $child) {
                 if (isset($this->shown_objects[$child->guid])) {
                     continue;
                 }
                 $ref =& $this->_get_reflector($child);
                 $label_mapping[$i] = htmlspecialchars($ref->get_object_label($child));
                 $i++;
             }
             asort($label_mapping);
             foreach ($label_mapping as $index => $label) {
                 $child =& $children[$index];
                 $ref =& $this->_get_reflector($child);
                 $selected = $this->_is_selected($child);
                 $css_class = $type;
                 $this->_common_css_classes($child, $ref, $css_class);
                 $mode = $this->_request_data['default_mode'];
                 if (strpos($css_class, 'readonly')) {
                     $mode = 'view';
                 }
                 $this->shown_objects[$child->guid] = true;
                 echo "{$prefix}    <li class=\"{$css_class}\">";
                 $icon = $ref->get_object_icon($child);
                 if (empty($label)) {
                     $label = "#{$child->id}";
                 }
                 echo "<a href=\"" . midcom_connection::get_url('self') . "__mfa/asgard/object/{$mode}/{$child->guid}/\" title=\"GUID: {$child->guid}, ID: {$child->id}\">{$icon}{$label}</a>\n";
                 if ($selected) {
                     $this->_list_child_elements($child, "{$prefix}        ", $level + 1);
                 }
                 echo "{$prefix}    </li>\n";
             }
         }
         echo "{$prefix}</ul>\n";
     }
 }
示例#8
0
 /**
  * Populate the object toolbar
  *
  * @param mixed $object        MgdSchema object for which the toolbar will be created
  * @param String $handler_id   Initialized handler id
  * @param array $data          Local request data
  */
 public function bind_to_object($object, $handler_id, $data)
 {
     // Show view toolbar button, if the user hasn't configured to use straight the edit mode
     if ($data['default_mode'] === 'view') {
         $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('view', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('view', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/view.png', MIDCOM_TOOLBAR_ACCESSKEY => 'v'));
     }
     if (!is_a($object, 'midcom_db_style') && !is_a($object, 'midcom_db_element') && !is_a($object, 'midcom_db_snippetdir') && !is_a($object, 'midcom_db_snippet') && !is_a($object, 'midcom_db_page') && !is_a($object, 'midcom_db_pageelement') && !is_a($object, 'midcom_db_parameter') && substr($object->__mgdschema_class_name__, 0, 23) != 'org_routamc_positioning' && substr($object->__mgdschema_class_name__, 0, 14) != 'net_nemein_tag') {
         $link = midcom::get('permalinks')->resolve_permalink($object->guid);
         if ($link) {
             $this->add_item(array(MIDCOM_TOOLBAR_URL => $link, MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('view on site', 'midgard.admin.asgard'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_internet.png'));
         }
     }
     if ($object->can_do('midgard:update')) {
         $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('edit', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('edit', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ACCESSKEY => 'e'));
     }
     if ($object->can_do('midgard:create')) {
         if (midcom_helper_reflector_tree::get_child_objects($object)) {
             $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('copy/tree', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('copy', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/editcopy.png'));
         } else {
             $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('copy', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('copy', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/editcopy.png'));
         }
     }
     if ($object->can_do('midgard:update')) {
         $this->_add_toolbar_update_items($object);
     }
     if ($object->can_do('midgard:create')) {
         // Find out what types of children the object can have and show create buttons for them
         $child_types = $data['tree_reflector']->get_child_classes();
         if (!is_array($child_types)) {
             debug_add("\$data['tree_reflector']->get_child_classes() failed critically, recasting \$child_types as array", MIDCOM_LOG_WARN);
             $child_types = array();
         }
         foreach ($child_types as $type) {
             $display_button = true;
             if (is_a($object, 'midcom_db_topic')) {
                 // With topics we should check for component before populating create buttons as so many types can be children of topics
                 switch ($type) {
                     case 'midgard_topic':
                     case 'midgard_article':
                         // Articles and topics can always be created
                         break;
                     default:
                         $midcom_dba_classname = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($type);
                         if (!$midcom_dba_classname) {
                             $display_button = false;
                             break;
                         }
                         $component = midcom::get('dbclassloader')->get_component_for_class($type);
                         if ($component != $object->component) {
                             $display_button = false;
                         }
                         break;
                 }
             } elseif (is_a($object, 'midcom_db_article') && $object->topic) {
                 $topic = new midcom_db_topic($object->topic);
                 // With articles we should check for topic component before populating create buttons as so many types can be children of topics
                 switch ($type) {
                     case 'midgard_article':
                         // Articles can always be created
                         break;
                     default:
                         $component = midcom::get('dbclassloader')->get_component_for_class($type);
                         if ($component != $topic->component) {
                             $display_button = false;
                         }
                         break;
                 }
             }
             if (!$display_button) {
                 // Skip this type
                 continue;
             }
             $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('create/' . $type, $object), MIDCOM_TOOLBAR_LABEL => sprintf(midcom::get('i18n')->get_string('create %s', 'midcom'), midgard_admin_asgard_plugin::get_type_label($type)), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/' . $data['tree_reflector']->get_create_icon($type)));
         }
     }
     if ($object->can_do('midgard:delete')) {
         $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('delete', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('delete', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ACCESSKEY => 'd'));
     }
     if ($GLOBALS['midcom_config']['midcom_services_rcs_enable'] && $object->can_do('midgard:update') && $object->_use_rcs) {
         $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('rcs', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('show history', 'midgard.admin.asgard'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/history.png', MIDCOM_TOOLBAR_ENABLED => substr($handler_id, 0, 25) === '____mfa-asgard-object_rcs' ? false : true, MIDCOM_TOOLBAR_ACCESSKEY => 'h'));
     }
     $this->_disable_active_item($handler_id, $object, $data);
 }