示例#1
0
 function read_node($node)
 {
     $node_array = array();
     $node_array['name'] = $node->name;
     $node_array['title'] = $node->extra;
     $node_array['component'] = $node->component;
     $node_array['style'] = $node->style;
     $node_array['style_inherit'] = $node->styleInherit;
     // Per-component specialties
     switch ($node->component) {
         case 'net.nehmer.static':
             $node_array['create_index'] = true;
     }
     // Get parameters
     $node_array['parameters'] = $node->list_parameters();
     // TODO: Implement ACL exporting
     $node_array['acl'] = array();
     // Recurse subnodes
     $node_array['nodes'] = array();
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('up', '=', $node->id);
     $children = $qb->execute();
     foreach ($children as $child) {
         $node_array['nodes'][$child->name] = $this->read_node($child);
     }
     return $node_array;
 }
示例#2
0
文件: index.php 项目: nemein/openpsa
 /**
  * Handler method for listing users
  *
  * @param string $handler_id Name of the used handler
  * @param mixed $args Array containing the variable arguments passed to the handler
  * @param mixed &$data Data passed to the show method
  */
 public function _handler_subfolders($handler_id, array $args, array &$data)
 {
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('component', '=', $this->_component);
     $qb->add_constraint('up', '=', $this->_topic->id);
     $qb->add_order('metadata.score', 'ASC');
     $data['subfolders'] = $qb->execute();
     $data['thumbnails'] = $this->_get_folder_thumbnails($data['subfolders']);
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "edit/", MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('edit %s'), $this->_l10n->get('slideshow')), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/configuration.png'));
 }
示例#3
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_navigation($handler_id, array $args, array &$data)
 {
     $current_topic = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_CONTENTTOPIC);
     $current_component = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_CONTENTTOPIC)->component;
     $root_topic = $current_topic;
     while ($root_topic->get_parent()->component == $current_component) {
         $root_topic = $root_topic->get_parent();
     }
     $this->_request_data['root_topic'] = $root_topic;
     $this->_request_data['current_topic'] = $current_topic;
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint("component", "=", $current_component);
     $qb->add_constraint("up", "INTREE", $root_topic->id);
     $document_topics = $qb->execute();
     $this->_request_data['topic_array'] = $document_topics;
     //This handler is supposed to be used with dynamic_load or AJAX, so skip page style
     midcom::get()->skip_page_style = true;
 }
function midcom_admin_folder_list_folders($up = 0, $tree_disabled = false)
{
    $data =& midcom_core_context::get()->get_custom_key('request_data');
    if (is_a($data['object'], 'midcom_db_topic') && $up == $data['object']->id) {
        $tree_disabled = true;
    }
    $qb = midcom_db_topic::new_query_builder();
    $qb->add_constraint('up', '=', $up);
    $qb->add_constraint('component', '<>', '');
    $folders = $qb->execute();
    if (count($folders) > 0) {
        echo "<ul>\n";
        foreach ($folders as $folder) {
            $class = '';
            $selected = '';
            $disabled = '';
            if ($folder->guid == $data['current_folder']->guid) {
                $class = 'current';
                $selected = ' checked="checked"';
            }
            if (!is_a($data['object'], 'midcom_db_topic') && $folder->component !== $data['current_folder']->component) {
                // Non-topic objects may only be moved under folders of same component
                $class = 'wrong_component';
                $disabled = ' disabled="disabled"';
            }
            if ($tree_disabled) {
                $class = 'child';
                $disabled = ' disabled="disabled"';
            }
            if ($folder->guid == $data['object']->guid) {
                $class = 'self';
                $disabled = ' disabled="disabled"';
            }
            echo "<li class=\"{$class}\"><label><input{$selected}{$disabled} type=\"radio\" name=\"move_to\" value=\"{$folder->id}\" /> {$folder->extra}</label>\n";
            midcom_admin_folder_list_folders($folder->id, $tree_disabled);
            echo "</li>\n";
        }
        echo "</ul>\n";
    }
}
示例#5
0
 public static function get_component_node($component)
 {
     $siteconfig = org_openpsa_core_siteconfig::get_instance();
     midcom::get('auth')->request_sudo($component);
     if ($topic_guid = $siteconfig->get_node_guid($component)) {
         $topic = new midcom_db_topic($topic_guid);
     } else {
         $qb = midcom_db_topic::new_query_builder();
         $qb->add_constraint('component', '=', $component);
         $qb->set_limit(1);
         $qb->add_order('id');
         $result = $qb->execute();
         if (sizeof($result) == 1) {
             midcom::get('auth')->drop_sudo();
             return $result[0];
         }
         $root_topic = midcom_db_topic::get_cached($GLOBALS['midcom_config']['root_topic']);
         $topic_attributes = array('up' => $root_topic->id, 'component' => $component, 'name' => 'handler_test_' . time());
         $topic = self::create_class_object('midcom_db_topic', $topic_attributes);
     }
     midcom::get('auth')->drop_sudo();
     return $topic;
 }
示例#6
0
 /**
  * Main MidCOM initialization.
  *
  * Initialize the Application class. Sets all private variables to a predefined
  * state. $node should be set to the midcom root-node GUID.
  * $prefix can be a prefix, which is appended to midcom_connection::get_url('self') (i.e. the
  * Midgard Page URL). This may be needed when MidCOM is run by wrapper.
  */
 public function initialize()
 {
     $this->_status = MIDCOM_STATUS_PREPARE;
     // Start-up some of the services
     midcom::get('dbclassloader')->load_classes('midcom', 'legacy_classes.inc', null, true);
     midcom::get('dbclassloader')->load_classes('midcom', 'core_classes.inc', null, true);
     midcom::get('componentloader')->load_all_manifests();
     // Initialize Context Storage
     $context = new midcom_core_context(0);
     $context->set_current();
     // Initialize Root Topic
     try {
         $root_node = midcom_db_topic::get_cached($GLOBALS['midcom_config']['midcom_root_topic_guid']);
     } catch (midcom_error $e) {
         if ($e instanceof midcom_error_forbidden) {
             throw new midcom_error_forbidden(midcom::get('i18n')->get_string('access denied', 'midcom'));
         } else {
             // Fall back to another topic so that admin has a chance to fix this
             midcom::get('auth')->require_admin_user("Root folder is misconfigured. Please log in as administrator and fix this in settings.");
             $qb = midcom_db_topic::new_query_builder();
             $qb->add_constraint('up', '=', 0);
             $qb->add_constraint('component', '<>', '');
             $topics = $qb->execute();
             if (count($topics) == 0) {
                 throw new midcom_error("Fatal error: Unable to load website root folder with GUID '{$GLOBALS['midcom_config']['midcom_root_topic_guid']}'.<br />" . 'Last Midgard Error was: ' . midcom_connection::get_error_string());
             }
             $root_node = $topics[0];
         }
     }
     $context->set_key(MIDCOM_CONTEXT_ROOTTOPIC, $root_node);
     $context->set_key(MIDCOM_CONTEXT_ROOTTOPICID, $root_node->id);
     // Check the midcom_config site prefix for absolute local urls
     if ($GLOBALS['midcom_config']['midcom_site_url'][0] == '/') {
         $GLOBALS['midcom_config']['midcom_site_url'] = $this->get_page_prefix() . substr($GLOBALS['midcom_config']['midcom_site_url'], 1);
     }
 }
示例#7
0
 /**
  * Get list of topics using a particular style
  *
  * @param string $style Style path
  * @return array List of folders
  */
 function get_nodes_using_style($style)
 {
     $style_nodes = array();
     // Get topics directly using the style
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('style', '=', $style);
     $nodes = $qb->execute();
     foreach ($nodes as $node) {
         $style_nodes[] = $node;
         if ($node->styleInherit) {
             $child_nodes = $this->_get_nodes_inheriting_style($node);
             $style_nodes = array_merge($style_nodes, $child_nodes);
         }
     }
     return $style_nodes;
 }
示例#8
0
 /**
  * This function resolves any GUID into a fully qualified URL which can be relocated
  * to. It operates in multiple phases:
  *
  * 1. Check, whether the GUID is already known by NAP. In case we have the corresponding
  *    node/leaf loaded, use its linking information directly.
  * 2. Look if we have a topic, in that case, we get the corresponding NAP node and use
  *    it to resolve the permalink. If that object is not retrievable, the lookup
  *    fails.
  * 3. We check whether the object in question has a topic as one of its ancestors. If yes,
  *    that topic and its corresponding component is used to lookup the GUID, which might
  *    fail.
  * 4. As a last resort we have to iterate over all NAP topics to do the resolving.
  *
  * @param string $guid The GUID to resolve.
  * @return string The full HTTP relocation'able URL to the GUID.
  */
 function resolve_permalink($guid)
 {
     // resolves a guid into a fully qualified url, uses some heuristics for that, mainly replaces
     // the nap permalink resolver, with the difference that it will be based on the
     // components permalink interface code.
     $nav = new midcom_helper_nav();
     // Step 1: Maybe NAP already knows the topic.
     $napobj = $nav->resolve_guid($guid);
     if ($napobj) {
         return $napobj[MIDCOM_NAV_FULLURL];
     }
     try {
         $object = midcom::get('dbfactory')->get_object_by_guid($guid);
     } catch (midcom_error $e) {
         debug_add("Failed to resolve the GUID {$guid}, this is most probably an access denied error.", MIDCOM_LOG_ERROR);
         debug_add('Last MidCOM error string: ' . $e->getMessage());
         return null;
     }
     $metadata = midcom_helper_metadata::retrieve($object);
     if (!$metadata->is_object_visible_onsite()) {
         return null;
     }
     if (is_a($object, 'midcom_db_topic')) {
         $napobj = $nav->get_node($object->id);
         if (!$napobj) {
             debug_add("Failed to retrieve the NAP object for topic {$object->id}.", MIDCOM_LOG_INFO);
             return null;
         }
         return $napobj[MIDCOM_NAV_FULLURL];
     }
     if (is_a($object, 'midcom_db_attachment')) {
         // Faster linking to attachments
         $parent = $object->get_parent();
         if (is_a($parent, 'midcom_db_topic') && $nav->is_node_in_tree($parent->id, $nav->get_root_node())) {
             $napobj = $nav->get_node($parent->id);
             return $napobj[MIDCOM_NAV_FULLURL] . $object->name;
         } else {
             return "{$GLOBALS['midcom_config']['midcom_site_url']}midcom-serveattachmentguid-{$object->guid}/{$object->name}";
         }
     }
     // Ok, unfortunately, this is not an immediate topic. We try to traverse
     // upwards in the object chain to find a topic.
     $topic = null;
     $parent = $object->get_parent();
     while ($parent) {
         if (is_a($parent, 'midcom_db_topic')) {
             // Verify that this topic is within the current sites tree, if it is not,
             // we ignore it. This might happen on symlink topics with static & co
             // which point to the outside f.x.
             if ($nav->is_node_in_tree($parent->id, $nav->get_root_node())) {
                 $topic = $parent;
                 break;
             }
         }
         $parent = $parent->get_parent();
     }
     if ($topic !== null) {
         $return_value = $this->_resolve_permalink_in_topic($topic, $guid);
         if ($return_value != null) {
             return $return_value;
         }
     }
     // Bad, this means a full scan,
     // We need to try every topic for the GUID.
     $topic_qb = midcom_db_topic::new_query_builder();
     $topic_qb->add_constraint('name', '<>', '');
     $topic_qb->add_constraint('up', 'INTREE', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPIC)->id);
     $topics = $topic_qb->execute();
     foreach ($topics as $topic) {
         $result = $this->_resolve_permalink_in_topic($topic, $guid);
         if ($result !== null) {
             return $result;
         }
     }
     // We were unable to find the GUID
     return null;
 }
示例#9
0
function render_breadcrumb(&$crumbs)
{
    while (current($crumbs) !== false) {
        $crumb = current($crumbs);
        if (next($crumbs) === false) {
            // last item
            echo "<a href='{$crumb['napobject'][MIDCOM_NAV_FULLURL]}'>{$crumb[MIDCOM_NAV_NAME]}</a>";
        } else {
            echo "{$crumb[MIDCOM_NAV_NAME]} &gt; ";
        }
    }
}
$site_root = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPIC);
$host_prefix = midcom::get()->get_host_prefix();
$nap = new midcom_helper_nav();
$qb = midcom_db_topic::new_query_builder();
$qb->add_constraint('up', 'INTREE', $site_root->id);
$qb->begin_group('OR');
$qb->add_constraint('metadata.hidden', '=', 1);
$qb->add_constraint('metadata.navnoentry', '=', 1);
$qb->end_group();
$qb->add_order('name');
$topics = $qb->execute();
unset($qb);
echo "<h2>Topics</h2>\n";
foreach ($topics as $topic) {
    $node =& $nap->get_node($topic->id);
    $crumbs =& $nap->get_breadcrumb_data($node[MIDCOM_NAV_ID]);
    $n_crumbs = count($crumbs);
    $i = 0;
    render_breadcrumb($crumbs);
示例#10
0
 function _on_execute()
 {
     debug_push_class(__CLASS__, __FUNCTION__);
     if (!$_MIDCOM->auth->request_sudo('fi.kilonkipinat.emailmappings')) {
         $msg = "Could not get sudo, aborting operation, see error log for details";
         $this->print_error($msg);
         debug_add($msg, MIDCOM_LOG_ERROR);
         debug_pop();
         return;
     }
     $email_group_guid = $this->_config->get('group_for_emails');
     if ($email_group_guid == null) {
         // Email group not set in global config, we try to search for topic
         //            $nap_topic = midcom_helper_find_node_by_component('fi.kilonkipinat.emailmappings');
         //            $topic = new midcom_db_topic($nap_topic[MIDCOM_NAV_GUID]);
         $qb = midcom_db_topic::new_query_builder();
         $qb->add_constraint('component', '=', 'fi.kilonkipinat.emailmappings');
         $qb->add_constraint('name', '<>', '');
         $qb->set_limit(1);
         $topics = $qb->execute();
         $topic = False;
         if (count($topics) > 0) {
             $topic = $topics[0];
         }
         if ($topic && $topic->guid && $topic->guid != '') {
             $real_config = new midcom_helper_configuration($topic, 'fi.kilonkipinat.emailmappings');
             $email_group_guid = $real_config->get('group_for_emails');
         } else {
             $msg = "Could not find topic for config, aborting operation, see error log for details";
             $this->print_error($msg);
             debug_add($msg, MIDCOM_LOG_ERROR);
             debug_pop();
             return;
         }
     }
     $emails = array();
     $usernames = array();
     $file_content = '';
     if ($email_group_guid != null) {
         $email_group = new midcom_db_group($email_group_guid);
         if ($email_group && $email_group->guid && $email_group->guid != '' && $email_group->guid == $email_group_guid) {
             $mc_members = midcom_db_member::new_collector('gid', $email_group->id);
             $mc_members->add_value_property('uid');
             $mc_members->execute();
             $member_keys = $mc_members->list_keys();
             $person_ids = array();
             foreach ($member_keys as $guid => $content) {
                 $person_id = $mc_members->get_subkey($guid, 'uid');
                 $person_ids[] = $person_id;
                 unset($person_id);
             }
             $mc_persons = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']);
             if (count($person_ids) > 0) {
                 $mc_persons->add_constraint('id', 'IN', $person_ids);
             }
             $mc_persons->add_constraint('username', '<>', '');
             $mc_persons->add_constraint('email', '<>', '');
             $mc_persons->add_constraint('email', 'LIKE', '%@%');
             $mc_persons->add_value_property('username');
             $mc_persons->add_value_property('email');
             $mc_persons->execute();
             $person_keys = $mc_persons->list_keys();
             foreach ($person_keys as $guid => $content) {
                 $person_username = $mc_persons->get_subkey($guid, 'username');
                 $person_email = $mc_persons->get_subkey($guid, 'email');
                 if (strstr($person_email, '@kilonkipinat.fi') || strstr($person_email, '@lists.kilonkipinat.fi')) {
                     debug_add('illegal content in email-address for person guid ' . $guid . ', continuing to next person', MIDCOM_LOG_ERROR);
                     continue;
                 }
                 if (isset($emails[$person_email]) || isset($usernames[$person_username])) {
                     continue;
                 }
                 $emails[$person_email] = $person_email;
                 $usernames[$person_username] = $person_username;
                 $file_content .= "\n" . $person_username . ': ' . $person_email;
             }
         } else {
             $msg = "Could not instantiate group for emailmapping, aborting operation, see error log for details";
             $this->print_error($msg);
             debug_add($msg, MIDCOM_LOG_ERROR);
             debug_pop();
             return;
         }
     } else {
         $msg = "Could not find group for emailmapping, aborting operation, see error log for details";
         $this->print_error($msg);
         debug_add($msg, MIDCOM_LOG_ERROR);
         debug_pop();
         return;
     }
     if ($file_content != '') {
         $file_content .= "\n\n";
         $filename = '/root/mailaliases/aliases_automatic';
         if (is_writable($filename)) {
             if (!file_put_contents($filename, $file_content)) {
                 $msg = "Tried to write aliases file, aborting operation, see error log for details";
                 $this->print_error($msg);
                 debug_add($msg, MIDCOM_LOG_ERROR);
                 debug_pop();
                 return;
             }
         } else {
             $msg = "Couldn't write to aliases file, aborting operation, see error log for details";
             $this->print_error($msg);
             debug_add($msg, MIDCOM_LOG_ERROR);
             debug_pop();
             return;
         }
     }
     $file2_content = '';
     $mc_mappings = fi_kilonkipinat_emailmappings_emailmapping_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']);
     $mc_mappings->add_value_property('name');
     $mc_mappings->add_value_property('persons');
     if (count($usernames) != 0) {
         $mc_mappings->add_constraint('name', 'NOT IN', $usernames);
     }
     $mc_mappings->execute();
     $mapping_keys = $mc_mappings->list_keys();
     foreach ($mapping_keys as $guid => $content) {
         $key = $mc_mappings->get_subkey($guid, 'name');
         $person_guids = $mc_mappings->get_subkey($guid, 'persons');
         $tmp_guids = explode('|', $person_guids);
         $guids = array();
         foreach ($tmp_guids as $guid2) {
             $guids[] = trim(str_replace('|', '', $guid2));
         }
         $persons_mc = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']);
         $persons_mc->add_value_property('email');
         if (count($guids) > 0) {
             $persons_mc->add_constraint('guid', 'IN', $guids);
         }
         $persons_mc->add_constraint('email', '<>', '');
         $persons_mc->execute();
         $persons_tmp = $persons_mc->list_keys();
         $emails = '';
         foreach ($persons_tmp as $guid3 => $content2) {
             $email = $persons_mc->get_subkey($guid3, 'email');
             if ($emails != '') {
                 $emails .= ', ';
             }
             $emails .= $email;
         }
         if (strlen($emails) > 3 && strstr($emails, "@")) {
             $file2_content .= "\n" . $key . ': ' . $emails;
         }
     }
     if ($file2_content != '') {
         $file2_content .= "\n\n";
         $filename2 = '/root/mailaliases/aliases_mappings';
         if (is_writable($filename2)) {
             if (!file_put_contents($filename2, $file2_content)) {
                 $msg = "Tried to write aliases file 2, aborting operation, see error log for details";
                 $this->print_error($msg);
                 debug_add($msg, MIDCOM_LOG_ERROR);
                 debug_pop();
                 return;
             }
         } else {
             $msg = "Couldn't write to aliases file 2, aborting operation, see error log for details";
             $this->print_error($msg);
             debug_add($msg, MIDCOM_LOG_ERROR);
             debug_pop();
             return;
         }
     }
     $_MIDCOM->auth->drop_sudo();
     debug_pop();
 }
示例#11
0
文件: view.php 项目: nemein/openpsa
 /**
  * Helper function to get directories for passed topic of the passed component
  *
  * @param root_topic - the topic to search the directories for
  * @param current_component - component of the topic/directories
  */
 private function _prepare_directories(&$root_topic, &$current_component)
 {
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint("component", "=", $current_component);
     $qb->add_constraint("up", "=", $root_topic->id);
     $this->_directories = $qb->execute();
 }
示例#12
0
文件: edit.php 项目: nemein/openpsa
 private function _update_topic($prefix, $old_name)
 {
     if (!empty($this->_topic->symlink) && !empty($this->_topic->component)) {
         $this->_topic->symlink = null;
         $this->_topic->update();
     }
     if ($_REQUEST['style'] === '__create') {
         $this->_topic->style = $this->_create_style($this->_topic->name);
         // Failed to create the new style template
         if ($this->_topic->style === '') {
             return false;
         }
         midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('new style created'));
         if (!$this->_topic->update()) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.folder'), sprintf($this->_l10n->get('could not save folder: %s'), midcom_connection::get_error_string()));
             return false;
         }
     }
     midcom::get('auth')->request_sudo('midcom.admin.folder');
     // Because edit from a symlink edits its target, it is best to keep name properties in sync to get the expected behavior
     $qb_topic = midcom_db_topic::new_query_builder();
     $qb_topic->add_constraint('symlink', '=', $this->_topic->id);
     foreach ($qb_topic->execute() as $symlink_topic) {
         if (empty($symlink_topic->symlink)) {
             debug_add("Symlink topic is not a symlink. Query must have failed. " . "Constraint was: #{$this->_topic->id}", MIDCOM_LOG_ERROR);
         } else {
             if ($symlink_topic->name !== $this->_topic->name) {
                 $symlink_topic->name = $this->_topic->name;
                 // This might fail if the URL name is already taken,
                 // but in such case we can just ignore it silently which keeps the original value
                 $symlink_topic->update();
             }
         }
     }
     midcom::get('auth')->drop_sudo();
     midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder saved'));
     // Get the relocation url
     $url = preg_replace("/{$old_name}\\/\$/", "{$this->_topic->name}/", $prefix);
     return $url;
 }
示例#13
0
文件: view.php 项目: nemein/openpsa
 private function _load_page($wikiword)
 {
     $qb = net_nemein_wiki_wikipage::new_query_builder();
     $qb->add_constraint('topic', '=', $this->_topic->id);
     $qb->add_constraint('name', '=', $wikiword);
     $result = $qb->execute();
     if (count($result) > 0) {
         $this->_page = $result[0];
         return true;
     }
     if ($wikiword == 'index') {
         // Autoinitialize
         $this->_topic->require_do('midgard:create');
         $this->_page = net_nemein_wiki_viewer::initialize_index_article($this->_topic);
         if ($this->_page) {
             return true;
         }
     }
     $topic_qb = midcom_db_topic::new_query_builder();
     $topic_qb->add_constraint('up', '=', $this->_topic->id);
     $topic_qb->add_constraint('name', '=', $wikiword);
     $topics = $topic_qb->execute();
     if (count($topics) > 0) {
         // There is a topic by this URL name underneath, go there
         return false;
     }
     // We need to get the node from NAP for safe redirect
     $nap = new midcom_helper_nav();
     $node = $nap->get_node($this->_topic->id);
     $urlized_wikiword = midcom_helper_misc::generate_urlname_from_string($wikiword);
     if ($urlized_wikiword != $wikiword) {
         // Lets see if the page for the wikiword exists
         $qb = net_nemein_wiki_wikipage::new_query_builder();
         $qb->add_constraint('topic', '=', $this->_topic->id);
         $qb->add_constraint('title', '=', $wikiword);
         $result = $qb->execute();
         if (count($result) > 0) {
             // This wiki page actually exists, so go there as "Permanent Redirect"
             midcom::get()->relocate("{$node[MIDCOM_NAV_ABSOLUTEURL]}{$result[0]->name}/", 301);
         }
     }
     midcom::get()->relocate("{$node[MIDCOM_NAV_ABSOLUTEURL]}notfound/" . rawurlencode($wikiword) . '/');
     // This will exit
 }
示例#14
0
文件: misc.php 项目: nemein/openpsa
 /**
  * This helper function returns the first instance of a given component on
  * the MidCOM site.
  *
  * @return array NAP array of the first component instance found
  */
 public static function find_node_by_component($component, $node_id = null, $nap = null)
 {
     static $cache = array();
     $cache_node = $node_id;
     if (is_null($cache_node)) {
         $cache_node = 0;
     }
     if (!isset($cache[$cache_node])) {
         $cache[$cache_node] = array();
     }
     if (array_key_exists($component, $cache[$cache_node])) {
         return $cache[$cache_node][$component];
     }
     if (is_null($nap)) {
         $nap = new midcom_helper_nav();
     }
     if (is_null($node_id)) {
         $node_id = $nap->get_root_node();
         $root_node = $nap->get_node($node_id);
         if ($root_node[MIDCOM_NAV_COMPONENT] == $component) {
             $cache[$cache_node][$component] = $root_node;
             return $root_node;
         }
     }
     // Otherwise, go with QB
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('component', '=', $component);
     $qb->add_constraint('name', '<>', '');
     $qb->add_constraint('up', 'INTREE', $node_id);
     $qb->set_limit(1);
     $topics = $qb->execute();
     if (count($topics) == 0) {
         $cache[$cache_node][$component] = null;
         return null;
     }
     $node = $nap->get_node($topics[0]->id);
     $cache[$cache_node][$component] = $node;
     return $node;
 }
示例#15
0
文件: main.php 项目: nemein/openpsa
 /**
  * Checks if the given node is within the tree of another node.
  *
  * @param int    $node_id    The node in question.
  * @param int    $root_node    The root node to use.
  * @return boolean                True, if the node is a subnode of the root node, false otherwise.
  */
 function is_node_in_tree($node_id, $root_id)
 {
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('id', '=', $node_id);
     $qb->add_constraint('up', 'INTREE', $root_id);
     if ($qb->count() > 0) {
         return true;
     }
     return false;
 }
示例#16
0
 function import_folder($folder, $parent_id)
 {
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('up', '=', (int) $parent_id);
     $qb->add_constraint('name', '=', $folder->name);
     $existing = $qb->execute();
     if (count($existing) > 0 && $existing[0]->up == $parent_id) {
         $topic = $existing[0];
         echo "Using existing topic {$topic->name} (#{$topic->id}) from #{$topic->up}\n";
     } else {
         $topic = new midcom_db_topic();
         $topic->up = $parent_id;
         $topic->name = $folder->name;
         if (!$topic->create()) {
             echo "Failed to create folder {$folder->name}: " . midcom_connection::get_error_string() . "\n";
             return false;
         }
         echo "Created folder {$topic->name} (#{$topic->id}) under #{$topic->up}\n";
     }
     $topic->extra = $folder->title;
     $topic->update();
     $topic->parameter('midcom', 'component', $folder->component);
     if ($folder->component == 'net.nehmer.static') {
         if (!$folder->has_index) {
             $topic->parameter('net.nehmer.static', 'autoindex', 1);
         } else {
             $topic->parameter('net.nehmer.static', 'autoindex', '');
         }
     }
     foreach ($folder->files as $file) {
         $this->import_file($file, $topic->id);
     }
     foreach ($folder->folders as $subfolder) {
         $this->import_folder($subfolder, $topic->id);
     }
     return true;
 }
示例#17
0
文件: delete.php 项目: nemein/openpsa
 /**
  * List topic contents
  *
  * @param int $id Topic ID
  */
 public static function list_children($id)
 {
     try {
         $topic = new midcom_db_topic($id);
         $children = self::_get_child_objects($topic);
         if ($children === false) {
             $children = array();
         }
     } catch (midcom_error $e) {
         $children = array();
     }
     $qb_topic = midcom_db_topic::new_query_builder();
     $qb_topic->add_constraint('up', '=', $id);
     $qb_article = midcom_db_article::new_query_builder();
     $qb_article->add_constraint('topic', '=', $id);
     if ($qb_topic->count() === 0 && $qb_article->count() === 0 && !$children) {
         return false;
     }
     echo "<ul class=\"folder_list\">\n";
     foreach ($qb_topic->execute_unchecked() as $topic) {
         $topic_title = $topic->extra;
         if (!$topic_title) {
             $topic_title = $topic->name;
         }
         echo "    <li class=\"node\">\n";
         echo "        <img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/stock_folder.png\" alt=\"\" /> {$topic_title}\n";
         self::list_children($topic->id);
         echo "    </li>\n";
     }
     foreach ($qb_article->execute_unchecked() as $article) {
         echo "    <li class=\"leaf article\">\n";
         echo "        <img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/document.png\" alt=\"\" /> {$article->title}\n";
         // Check for the reply articles
         $qb = midcom_db_article::new_query_builder();
         $qb->add_constraint('up', '=', $article->id);
         if ($qb->count() > 0) {
             $reply_ul = false;
             foreach ($qb->execute_unchecked() as $reply) {
                 if (!$reply_ul) {
                     echo "        <ul>\n";
                     $reply_ul = true;
                 }
                 echo "            <li class=\"leaf_child reply_article\">{$reply->title}\n";
                 self::_list_leaf_children($reply);
                 echo "            </li>\n";
             }
             if ($reply_ul) {
                 echo "        </ul>\n";
             }
         }
         self::_list_leaf_children($article, array('midgard_article'));
         echo "    </li>\n";
     }
     foreach ($children as $class => $objects) {
         if ($class == 'midgard_topic' || $class == 'midgard_article') {
             continue;
         }
         $style = "";
         if ($class == 'net_nemein_tag_link') {
             $style = "style=\"display: none;\"";
         }
         foreach ($objects as $object) {
             $title = midcom_helper_reflector::get($class)->get_object_label($object);
             echo "    <li class=\"leaf {$class}\"{$style}>\n";
             echo "        <img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/document.png\" alt=\"\" /> {$title}\n";
             self::_list_leaf_children($object);
             echo "    </li>\n";
         }
     }
     echo "</ul>\n";
 }
示例#18
0
 /**
  * Return next object in URL path
  */
 public function get_object()
 {
     if ($this->argc == 0) {
         // No arguments left
         return false;
     }
     if (empty($this->url)) {
         $object_url = "{$this->argv[0]}/";
     } else {
         $object_url = "{$this->url}/{$this->argv[0]}/";
     }
     if (array_key_exists($object_url, $this->objects)) {
         // Remove this component from path
         $this->argc -= 1;
         array_shift($this->argv);
         // Set as current object
         $this->url = $object_url;
         $this->current_object = $this->objects[$object_url];
         return $this->objects[$object_url];
     }
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('name', '=', $this->argv[0]);
     $qb->add_constraint('up', '=', $this->current_object->id);
     if ($qb->count() == 0) {
         //last load returned ACCESS DENIED, no sense to dig deeper
         if ($qb->denied > 0) {
             midcom_connection::set_error(MGD_ERR_ACCESS_DENIED);
             return false;
         }
         // No topics matching path, check for attachments
         $att_qb = midcom_db_attachment::new_query_builder();
         $att_qb->add_constraint('name', '=', $this->argv[0]);
         $att_qb->add_constraint('parentguid', '=', $this->current_object->guid);
         if ($att_qb->count() == 0) {
             // allow for handler switches to work
             return false;
         }
         $atts = $att_qb->execute();
         // Remove this component from path
         $this->argc -= 1;
         array_shift($this->argv);
         // Set as current object
         $this->url = $object_url;
         $this->current_object = $atts[0];
         $this->objects[$object_url] = $this->current_object;
         return $this->objects[$object_url];
     }
     $topics = $qb->execute();
     // Set to current topic
     $this->current_object = $topics[0];
     $this->objects[$object_url] = $this->current_object;
     if ($GLOBALS['midcom_config']['symlinks'] && !empty($this->current_object->symlink)) {
         try {
             $topic = midcom_db_topic::get_cached($this->current_object->symlink);
             $this->current_object = $topic;
         } catch (midcom_error $e) {
             debug_add("Could not get target for symlinked topic #{$this->current_object->id}: " . $e->getMessage(), MIDCOM_LOG_ERROR);
         }
     }
     // TODO: Remove
     $this->check_style_inheritance($this->current_object);
     // Remove this component from path
     $this->argc -= 1;
     array_shift($this->argv);
     $this->url .= $this->objects[$object_url]->name . '/';
     return $this->objects[$object_url];
 }
示例#19
0
 /**
  * Checks if the folder has finite (healthy) tree below it.
  *
  * @param object $topic The folder to be checked.
  * @return boolean Indicating success
  */
 public function is_child_listing_finite($topic, $stop = array())
 {
     if (!empty($topic->symlink)) {
         midcom::get('auth')->request_sudo('midcom.admin.folder');
         try {
             $topic = new midcom_db_topic($topic->symlink);
         } catch (midcom_error $e) {
             debug_add("Could not get target for symlinked topic #{$topic->id}: " . $e->getMessage(), MIDCOM_LOG_ERROR);
         }
         midcom::get('auth')->drop_sudo();
     }
     if (in_array($topic->id, $stop)) {
         return false;
     }
     $stop[] = $topic->id;
     midcom::get('auth')->request_sudo('midcom.admin.folder');
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('up', '=', $topic->id);
     $results = $qb->execute();
     midcom::get('auth')->drop_sudo();
     foreach ($results as $topic) {
         if (!self::is_child_listing_finite($topic, $stop)) {
             return false;
         }
     }
     return true;
 }
示例#20
0
 private function delete_missing_folders($foldernames, $topic_id)
 {
     if (!$this->delete_missing) {
         return;
     }
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('up', '=', $topic_id);
     if (!empty($foldernames)) {
         $qb->add_constraint('name', 'NOT IN', $foldernames);
     }
     $folders = $qb->execute();
     foreach ($folders as $folder) {
         $folder->delete();
     }
 }