示例#1
0
文件: move.php 项目: nemein/openpsa
 private function _move_object($target)
 {
     $move_to_topic = new midcom_db_topic();
     $move_to_topic->get_by_id($target);
     if (!$move_to_topic->guid) {
         throw new midcom_error('Failed to move the topic. Could not get the target topic');
     }
     $move_to_topic->require_do('midgard:create');
     if (is_a($this->_object, 'midcom_db_topic')) {
         $name = $this->_object->name;
         $this->_object->name = '';
         // Prevents problematic location to break the site, we set this back below...
         $up = $this->_object->up;
         $this->_object->up = $move_to_topic->id;
         if (!$this->_object->update()) {
             throw new midcom_error('Failed to move the topic, reason ' . midcom_connection::get_error_string());
         }
         if (!midcom_admin_folder_management::is_child_listing_finite($this->_object)) {
             $this->_object->up = $up;
             $this->_object->name = $name;
             $this->_object->update();
             throw new midcom_error("Refusing to move this folder because the move would have created an " . "infinite loop situation caused by the symlinks on this site. The " . "whole site would have been completely and irrevocably broken if this " . "move would have been allowed to take place. Infinite loops can not " . "be allowed. Sorry, but this was for your own good.");
         }
         // It was ok, so set name back now
         $this->_object->name = $name;
         $this->_object->update();
     } else {
         $this->_object->topic = $move_to_topic->id;
         if (!$this->_object->update()) {
             throw new midcom_error('Failed to move the article, reason ' . midcom_connection::get_error_string());
         }
     }
 }
示例#2
0
文件: email.php 项目: nemein/openpsa
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 private function _create_article($title)
 {
     $this->_article = new midcom_db_article();
     $author = $this->_find_email_person($this->_request_data['from']);
     if (!$author) {
         debug_add("Author '{$this->_request_data['from']}' not found", MIDCOM_LOG_WARN);
         if ($this->_config->get('api_email_abort_authornotfound') !== false) {
             throw new midcom_error("Author '{$this->_request_data['from']}' not found");
         }
         $this->_article->author = midcom_connection::get_user();
     } else {
         // TODO: This code needs a bit of rethinking
         $author_user = midcom::get('auth')->get_user($author->guid);
         if (!$this->_content_topic->can_do('midgard:create', $author_user)) {
             throw new midcom_error('Author doesn\'t have posting privileges');
         }
         $this->_article->author = $author->id;
     }
     //Default to first user in DB if author is not set
     if (!$this->_article->author) {
         $qb = midcom_db_person::new_query_builder();
         $qb->add_constraint('username', '<>', '');
         $qb->set_limit(1);
         $results = $qb->execute();
         unset($qb);
         if (empty($results)) {
             //No users found
             throw new midcom_error('Cannot set any author for the article');
         }
         $this->_article->author = $results[0]->id;
     }
     $resolver = new midcom_helper_reflector_nameresolver($this->_article);
     $this->_article->topic = $this->_content_topic->id;
     $this->_article->title = $title;
     $this->_article->allow_name_catenate = true;
     $this->_article->name = $resolver->generate_unique_name('title');
     if (empty($this->_article->name)) {
         debug_add('Could not generate unique name for the new article from title, using timestamp', MIDCOM_LOG_INFO);
         $this->_article->name = time();
         $resolver = new midcom_helper_reflector_nameresolver($this->_article);
         if (!$resolver->name_is_unique()) {
             throw new midcom_error('Failed to create unique name for the new article, aborting.');
         }
     }
     if (!$this->_article->create()) {
         debug_print_r('Failed to create article:', $this->_article);
         throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     $this->_article->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_email_schema'));
     return true;
 }
示例#3
0
 public function _on_updated()
 {
     // Invalidate topic in cache to refresh all views
     // TODO: Do this only on status changes
     $topic = midcom_db_topic::get_cached($this->topic);
     if ($topic->guid) {
         $_MIDCOM->cache->invalidate($topic->guid);
     }
     if (isset($GLOBALS['disable_activitystream'])) {
         return true;
     }
     if ($_MIDCOM->auth->request_sudo('midcom')) {
         $actor = midcom_db_person::get_cached($_MIDGARD['user']);
         $activity = new midcom_helper_activitystream_activity_dba();
         $activity->target = $this->guid;
         $activity->application = 'fi.kilonkipinat.account';
         $activity->actor = $actor->id;
         $activity->verb = 'http://activitystrea.ms/schema/1.0/post';
         if ($this->id == $actor->id) {
             $activity->summary = sprintf('%s muokkasi omaa tunnustaan', $actor->name);
         } else {
             $tmp_name = $this->firstname . ' ' . $this->lastname;
             $activity->summary = sprintf('%s muokkasi %s:n tunnusta', $actor->name, $tmp_name);
         }
         $activity->create();
         $_MIDCOM->auth->drop_sudo();
     }
     return true;
 }
示例#4
0
 public function test_get_objects()
 {
     $mc = midcom_db_topic::new_collector('id', self::$_topic->id);
     $objects = $mc->get_objects();
     $this->assertEquals(1, sizeof($objects));
     $this->assertEquals(self::$_topic->guid, $objects[0]->guid);
 }
示例#5
0
文件: create.php 项目: nemein/openpsa
 /**
  * Displays an article edit view.
  *
  * Note, that the article for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation article
  *
  * @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_create($handler_id, array $args, array &$data)
 {
     $this->_content_topic->require_do('midgard:create');
     $this->_schema = $args[0];
     if ($handler_id == 'createindex') {
         $this->_indexmode = true;
     }
     $data['controller'] = $this->get_controller('create');
     switch ($data['controller']->process_form()) {
         case 'save':
             /**
              * http://trac.midgard-project.org/ticket/809 should have taken care of this.
              * BUT: to be extra careful, let's do this sanity-check anyway.
              */
             if (strlen($this->_article->name) == 0) {
                 // Generate something to avoid empty "/" links in case of failures
                 $this->_article->name = time();
                 $this->_article->update();
             }
             // Index the article
             $indexer = midcom::get('indexer');
             net_nehmer_static_viewer::index($data['controller']->datamanager, $indexer, $this->_content_topic);
             if ($this->_article->name === 'index') {
                 return new midcom_response_relocate('');
             }
             return new midcom_response_relocate("{$this->_article->name}/");
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $this->_prepare_request_data();
     $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}");
     $this->add_breadcrumb("create/{$this->_schema}/", sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description));
 }
示例#6
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;
 }
示例#7
0
文件: link.php 项目: nemein/openpsa
 /**
  * Displays an article edit view.
  *
  * Note, that the article for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation article
  *
  * @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_create($handler_id, array $args, array &$data)
 {
     $this->_content_topic->require_do('midgard:create');
     if (!$this->_config->get('enable_article_links')) {
         throw new midcom_error_notfound('Article linking disabled');
     }
     $data['controller'] = $this->get_controller('create');
     switch ($data['controller']->process_form()) {
         case 'save':
             $this->_article = new midcom_db_article($this->_link->article);
             return new midcom_response_relocate("{$this->_article->name}/");
         case 'cancel':
             if (isset($_GET['article'])) {
                 if ($this->_config->get('view_in_url')) {
                     $prefix = 'view/';
                 } else {
                     $prefix = '';
                 }
                 try {
                     $article = new midcom_db_article($_GET['article']);
                     return new midcom_response_relocate("{$prefix}{$article->name}/");
                 } catch (midcom_error $e) {
                     $e->log();
                 }
             }
             return new midcom_response_relocate('');
     }
     $this->_prepare_request_data();
     $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link'));
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}");
     $this->_update_breadcrumb_line($handler_id);
 }
示例#8
0
 function newMediaObject($message)
 {
     $args = $this->_params_to_args($message);
     if (count($args) != 4) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Invalid arguments.');
     }
     if ($args[0] != $this->_content_topic->guid) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Blog ID does not match this folder.');
     }
     if (!midcom::get('auth')->login($args[1], $args[2])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Authentication failed.');
     }
     midcom::get('auth')->initialize();
     if (count($args) < 3) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Invalid file data.');
     }
     if (!$args[3]['name']) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'No filename given.');
     }
     // Clean up possible path information
     $attachment_name = basename($args[3]['name']);
     $attachment = $this->_content_topic->get_attachment($attachment_name);
     if (!$attachment) {
         // Create new attachment
         $attachment = $this->_content_topic->create_attachment($attachment_name, $args[3]['name'], $args[3]['type']);
         if (!$attachment) {
             return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to create attachment: ' . midgard_connection::get_error_string());
         }
     }
     if (!$attachment->copy_from_memory($args[3]['bits'])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to store contents to attachment: ' . midgard_connection::get_error_string());
     }
     $attachment_array = array('url' => new XML_RPC_Value("{$GLOBALS['midcom_config']['midcom_site_url']}midcom-serveattachmentguid-{$attachment->guid}/{$attachment->name}", 'string'), 'guid' => new XML_RPC_Value($attachment->guid, 'string'));
     return new XML_RPC_Response(new XML_RPC_Value($attachment_array, 'struct'));
 }
 function scan_subgalleries($node)
 {
     $mc = org_routamc_gallery_photolink_dba::new_collector('node', $node);
     $mc->add_value_property('photo');
     $mc->add_constraint('censored', '=', 0);
     $mc->add_order('photo.taken', 'DESC');
     $mc->set_limit(1);
     $mc->execute();
     $photolinks = $mc->list_keys();
     foreach ($photolinks as $guid => $array) {
         $id = $mc->get_subkey($guid, 'photo');
         $photo = new org_routamc_photostream_photo_dba($id);
         return $photo;
     }
     $mc = midcom_db_topic::new_collector('up', $node);
     $mc->add_value_property('id');
     $mc->add_constraint('up', '=', $node);
     $mc->add_constraint('component', '=', 'org.routamc.gallery');
     $mc->add_constraint('metadata.navnoentry', '=', 0);
     $mc->add_order('score');
     $mc->execute();
     $nodes = $mc->list_keys();
     foreach ($nodes as $guid => $array) {
         $id = $mc->get_subkey($guid, 'id');
         $link = $this->_scan_subgalleries($id);
         if ($link) {
             return $link;
         }
     }
     return false;
 }
示例#10
0
文件: create.php 项目: nemein/openpsa
 /**
  * Displays an article edit view.
  *
  * Note, that the article for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation article
  *
  * @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_create($handler_id, array $args, array &$data)
 {
     $this->_content_topic->require_do('midgard:create');
     $this->_schema = $args[0];
     if ($handler_id == 'createindex') {
         $this->_indexmode = true;
     }
     $data['controller'] = $this->get_controller('create');
     switch ($data['controller']->process_form()) {
         case 'save':
             // #809 should have taken care of this, but see same place in n.n.static
             if (strlen($this->_article->name) == 0) {
                 // Generate something to avoid empty "/" links in case of failures
                 $this->_article->name = time();
                 $this->_article->update();
             }
             // Index the article
             $indexer = midcom::get('indexer');
             net_nehmer_blog_viewer::index($data['controller']->datamanager, $indexer, $this->_content_topic);
             // *** FALL THROUGH ***
         // *** FALL THROUGH ***
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $this->_prepare_request_data();
     $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}");
     $this->add_breadcrumb("create/{$this->_schema}/", sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description));
 }
示例#11
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'));
 }
示例#12
0
 /**
  * Locates the root event
  */
 public static function find_root_event()
 {
     if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
         midcom::get('componentloader')->load_graceful('org.openpsa.calendar');
         //Doublecheck
         if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
             return false;
         }
     }
     $data = midcom_baseclasses_components_configuration::get('org.openpsa.calendar');
     //Check if we have already initialized
     if (isset($data['calendar_root_event']) && is_object($data['calendar_root_event'])) {
         return $data['calendar_root_event'];
     }
     $root_event = false;
     $root_guid = $data['config']->get('calendar_root_event');
     if (mgd_is_guid($root_guid)) {
         $root_event = org_openpsa_calendar_event_dba::get_cached($root_guid);
     } else {
         // Check for calendar event tree.
         $qb = org_openpsa_calendar_event_dba::new_query_builder();
         $qb->add_constraint('title', '=', '__org_openpsa_calendar');
         $qb->add_constraint('up', '=', '0');
         $ret = $qb->execute();
         if (is_array($ret) && count($ret) > 0) {
             $root_event = $ret[0];
             $siteconfig = org_openpsa_core_siteconfig::get_instance();
             $topic_guid = $siteconfig->get_node_guid('org.openpsa.calendar');
             if ($topic_guid) {
                 $topic = new midcom_db_topic($topic_guid);
                 $topic->set_parameter('org.openpsa.calendar', 'calendar_root_event', $root_event->guid);
             }
         } else {
             debug_add("OpenPSA Calendar root event could not be found", MIDCOM_LOG_ERROR);
             //Attempt to auto-initialize
             $root_event = self::create_root_event();
         }
     }
     $data['calendar_root_event'] = $root_event;
     return $root_event;
 }
示例#13
0
文件: viewer.php 项目: nemein/openpsa
 /**
  * Populates the node toolbar depending on the user's rights.
  */
 private function _populate_node_toolbar()
 {
     if ($this->_content_topic->can_do('midgard:create')) {
         foreach (array_keys($this->_request_data['schemadb']) as $name) {
             $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "create/{$name}/", MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get($this->_request_data['schemadb'][$name]->description)), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/new-text.png', MIDCOM_TOOLBAR_ACCESSKEY => 'n'));
         }
     }
     if ($this->_config->get('enable_article_links') && $this->_content_topic->can_do('midgard:create')) {
         $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link')), MIDCOM_TOOLBAR_URL => "create/link/", MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png'));
     }
     if ($this->_topic->can_do('midgard:update') && $this->_topic->can_do('midcom:component_config')) {
         $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'config/', MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png'));
     }
 }
示例#14
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;
 }
示例#15
0
 /**
  * Get topic guid statically
  *
  * used by get_parent_guid_uncached_static
  *
  * @param int $parent_id id of topic to get the guid for
  */
 private static function _get_parent_guid_uncached_static_topic($parent_id)
 {
     if (empty($parent_id)) {
         return null;
     }
     $mc_parent = midcom_db_topic::new_collector('id', $parent_id);
     if (!$mc_parent->execute()) {
         // Error
         return null;
     }
     $mc_parent_keys = $mc_parent->list_keys();
     $parent_guid = key($mc_parent_keys);
     if ($parent_guid === false) {
         // Error
         return null;
     }
     return $parent_guid;
 }
示例#16
0
文件: link.php 项目: nemein/openpsa
 /**
  * Displays an article edit view.
  *
  * Note, that the article for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation article
  *
  * @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_create($handler_id, array $args, array &$data)
 {
     $this->_content_topic->require_do('midgard:create');
     if (!$this->_config->get('enable_article_links')) {
         throw new midcom_error_notfound('Article linking disabled');
     }
     $data['controller'] = $this->get_controller('create');
     switch ($data['controller']->process_form()) {
         case 'save':
             $this->_article = new midcom_db_article($this->_link->article);
             return new midcom_response_relocate("{$this->_article->name}/");
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $this->_prepare_request_data();
     $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link'));
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}");
     $this->add_breadcrumb("create/link/", sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link')));
 }
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";
    }
}
示例#18
0
 public function _on_updated()
 {
     // Invalidate topic in cache to refresh all views
     // TODO: Do this only on status changes
     $topic = midcom_db_topic::get_cached($this->topic);
     if ($topic->guid) {
         $_MIDCOM->cache->invalidate($topic->guid);
     }
     if (isset($GLOBALS['disable_activitystream'])) {
         return true;
     }
     if ($_MIDCOM->auth->request_sudo('midcom')) {
         // This is here because creating an object calls create and update..... and we don't want duplicate entry's
         $qb = midcom_helper_activitystream_activity_dba::new_query_builder();
         $qb->set_limit(1);
         $qb->add_constraint('application', '=', 'fi.kilonkipinat.account');
         $qb->add_constraint('target', '=', $this->guid);
         $groups = $qb->execute();
         if ($groups && is_array($groups) && count($groups) > 0) {
             $new_object = false;
         } else {
             $new_object = true;
         }
         $actor = midcom_db_person::get_cached($_MIDGARD['user']);
         $activity = new midcom_helper_activitystream_activity_dba();
         $activity->target = $this->guid;
         $activity->application = 'fi.kilonkipinat.account';
         $activity->actor = $actor->id;
         $activity->verb = 'http://activitystrea.ms/schema/1.0/post';
         if ($new_object) {
             $activity->summary = sprintf('%s loi pestiryhmän %s', $actor->name, $this->title);
         } else {
             $activity->summary = sprintf('%s muokkasi pestiryhmää %s', $actor->name, $this->title);
         }
         $activity->create();
         $_MIDCOM->auth->drop_sudo();
     }
     return true;
 }
示例#19
0
文件: view.php 项目: nemein/openpsa
 /**
  * Handle actual article display
  *
  * @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_view($handler_id, array $args, array &$data)
 {
     if ($handler_id == 'view-raw') {
         midcom::get()->skip_page_style = true;
     }
     $this->_load_datamanager();
     if ($this->_config->get('enable_ajax_editing')) {
         $this->_request_data['controller'] = midcom_helper_datamanager2_controller::create('ajax');
         $this->_request_data['controller']->schemadb =& $this->_request_data['schemadb'];
         $this->_request_data['controller']->set_storage($this->_article);
         $this->_request_data['controller']->process_ajax();
     }
     if ($this->_config->get('comments_enable')) {
         $comments_node = $this->_seek_comments();
         if ($comments_node) {
             $this->_request_data['comments_url'] = $comments_node[MIDCOM_NAV_RELATIVEURL] . "comment/{$this->_article->guid}";
             if ($this->_topic->can_do('midgard:update') && $this->_topic->can_do('net.nehmer.comments:moderation')) {
                 net_nehmer_comments_viewer::add_head_elements();
             }
         }
         // TODO: Should we tell admin to create a net.nehmer.comments folder?
     }
     $tmp = array();
     $arg = $this->_article->name ? $this->_article->name : $this->_article->guid;
     if ($this->_config->get('view_in_url')) {
         $view_url = "view/{$arg}/";
     } else {
         $view_url = "{$arg}/";
     }
     $this->add_breadcrumb($view_url, $this->_article->title);
     $this->_prepare_request_data();
     if ($this->_config->get('enable_article_links') && $this->_content_topic->can_do('midgard:create')) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link')), MIDCOM_TOOLBAR_URL => "create/link/?article={$this->_article->id}", MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png'));
     }
     $this->bind_view_to_object($this->_article, $this->_datamanager->schema->name);
     midcom::get('metadata')->set_request_metadata($this->_article->metadata->revised, $this->_article->guid);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$this->_article->title}");
 }
示例#20
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;
 }
示例#21
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);
     }
 }
示例#22
0
文件: view.php 项目: nemein/openpsa
 private function _load_index_article()
 {
     $qb = midcom_db_article::new_query_builder();
     $qb->add_constraint('name', '=', 'index');
     $qb->set_limit(1);
     // Include the article links to the indexes if enabled
     if ($this->_config->get('enable_article_links')) {
         $mc = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id);
         $mc->add_constraint('topic', '=', $this->_content_topic->id);
         $links = $mc->get_values('article');
         $qb->begin_group('OR');
         if (count($links) > 0) {
             $qb->add_constraint('id', 'IN', $links);
         }
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
         $qb->end_group();
     } else {
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
     }
     $result = $qb->execute();
     if (empty($result)) {
         if ($this->_content_topic->can_do('midgard:create')) {
             // Check via non-ACLd QB that the topic really doesn't have index article before relocating
             $index_qb = midcom_db_article::new_query_builder();
             $index_qb->add_constraint('topic', '=', $this->_content_topic->id);
             $index_qb->add_constraint('name', '=', 'index');
             if ($index_qb->count_unchecked() == 0) {
                 $schemas = array_keys($this->_request_data['schemadb']);
                 midcom::get()->relocate("createindex/{$schemas[0]}/");
                 // This will exit.
             }
         }
         throw new midcom_error_forbidden('Directory index forbidden');
     }
     $this->_article = $result[0];
 }
示例#23
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;
 }
示例#24
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;
 }
示例#25
0
 /**
  * Prepare event listing query builder that takes all configured filters into account
  *
  * @access static
  */
 static function prepare_event_qb(&$data, &$config)
 {
     // Load filters
     $filters = fi_kilonkipinat_events_viewer::prepare_filters($config);
     $qb = fi_kilonkipinat_events_event_dba::new_query_builder();
     if (!$_MIDGARD['user']) {
         $qb->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC);
     }
     // Add node or root event constraints
     if ($config->get('list_from_master')) {
         // List under an event tree by up field
         $qb->add_constraint('up', 'INTREE', $data['master_event']);
     } else {
         $list_from_folders = $config->get('list_from_folders');
         if ($list_from_folders) {
             // We have specific folders to list from, therefore list from them and current node
             $guids = explode('|', $config->get('list_from_folders'));
             $guids_array = array();
             $guids_array[] = $data['content_topic']->guid;
             foreach ($guids as $guid) {
                 if (!$guid || !mgd_is_guid($guid)) {
                     // Skip empty and broken guids
                     continue;
                 }
                 $guids_array[] = $guid;
             }
             /**
              * Ref #1776, expands GUIDs before adding them as constraints, should save query time
              */
             $topic_ids = array();
             $topic_ids[] = $data['content_topic']->id;
             if (!empty($guids_array)) {
                 $mc = midcom_db_topic::new_collector('sitegroup', $_MIDGARD['sitegroup']);
                 $mc->add_constraint('guid', 'IN', $guids_array);
                 $mc->add_value_property('id');
                 $mc->execute();
                 $keys = $mc->list_keys();
                 foreach ($keys as $guid => $dummy) {
                     $topic_ids[] = $mc->get_subkey($guid, 'id');
                 }
                 unset($mc, $keys, $guid, $dummy);
             }
             $qb->add_constraint('topic', 'IN', $topic_ids);
         } else {
             // List from current node only
             $qb->add_constraint('topic', '=', $data['content_topic']->id);
         }
     }
     // Add filtering constraint
     if (isset($filters['type_filter'])) {
         $qb->add_constraint('type', '=', (int) $filters['type_filter']);
     }
     if (isset($filters['other'])) {
         // Handle other direct field mapping constraints
         foreach ($filters['other'] as $field => $filter) {
             $qb->add_constraint($field, '=', $filter);
         }
     }
     // Handle category filter
     if (isset($filters['category_filter'])) {
         $qb->add_constraint('category', 'LIKE', "%|{$filters['category_filter']}|%");
     }
     return $qb;
 }
示例#26
0
文件: viewer.php 项目: nemein/openpsa
 private function _get_available_generators()
 {
     if (is_array($this->_available_generators)) {
         return $this->_available_generators;
     }
     $this->_available_generators = array();
     $components = array('org.openpsa.projects' => midcom::get('i18n')->get_string('org.openpsa.projects', 'org.openpsa.projects'), 'org.openpsa.sales' => midcom::get('i18n')->get_string('org.openpsa.sales', 'org.openpsa.sales'), 'org.openpsa.invoices' => midcom::get('i18n')->get_string('org.openpsa.invoices', 'org.openpsa.invoices'));
     $siteconfig = org_openpsa_core_siteconfig::get_instance();
     foreach ($components as $component => $loc) {
         $node_guid = $siteconfig->get_node_guid($component);
         try {
             $topic = midcom_db_topic::get_cached($node_guid);
             $this->_available_generators[$component] = $loc;
         } catch (midcom_error $e) {
             debug_add("topic for component '{$component}' not found or accessible");
         }
     }
     $this->_available_generators = $components;
     return $this->_available_generators;
 }
示例#27
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;
 }
示例#28
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);
示例#29
0
<?php

// Available request keys: article, datamanager, edit_url, delete_url, create_urls
$view = $data['view_article'];
?>

<h1>&(view['title']:h);</h1>

&(view['content']:h);

<br />
<?php 
$topic = new midcom_db_topic();
$topic->get_by_path('/kkp_root/extranet/tiedotteet/lippukuntapostit');
$mc = midcom_db_topic::new_collector('up', $topic->id);
$mc->add_constraint('component', '=', 'net.nehmer.blog');
$mc->add_value_property('name');
$mc->execute();
$keys = $mc->list_keys();
$counter = 0;
foreach ($keys as $guid => $blog_topic) {
    $counter++;
    $topic_name = $mc->get_subkey($guid, 'name');
    $dl_path = '/midcom-substyle-dl_frontpage/extranet/tiedotteet/lippukuntapostit/' . $topic_name . '/latest/4';
    if ($counter % 2 != 0) {
        ?>
            <div class="content_fp_lift_container_left">
        <?php 
    } else {
        ?>
            <div class="content_fp_lift_container_right">
示例#30
0
<?php

$document = $data['document'];
$score = round($document->score * 100);
try {
    $topic = midcom_db_topic::get_cached($document->topic_guid);
} catch (midcom_error $e) {
    $e->log();
}
?>
<div class="midcom_helper_search_result">
  <h3><a href='&(document.document_url);'>&(document.title);</a></h3>
  <div class="midcom_helper_search_result_abstract">
      &(document.abstract:h);
  </div>
  <div class="midcom_helper_search_result_metadata">
    <?php 
if (isset($topic)) {
    ?>
        <span class="midcom_helper_search_result_topic"><?php 
    echo $data['l10n_midcom']->get('topic');
    ?>
: &(topic.extra);</span>,
    <?php 
}
?>
    <span class="midcom_helper_search_result_score"><?php 
echo $data['l10n']->get('score');
?>
: &(score); %</span>
  </div>