Example #1
0
 /**
  * Internal helper, computes an MD5 string which is used as an attachment location.
  * It should be random enough, even if the algorithm used does not match the one
  * Midgard uses. If the location already exists, it will iterate until an unused
  * location is found.
  *
  * @return string An unused attachment location.
  */
 private function _create_attachment_location()
 {
     $location_in_use = true;
     $location = '';
     while ($location_in_use) {
         $base = get_class($this);
         $base .= microtime();
         if (isset($this->id)) {
             $base .= $this->id;
         } else {
             if (isset($this->guid)) {
                 $base .= $this->guid;
             }
         }
         $base .= $_SERVER['SERVER_NAME'];
         $base .= $_SERVER['REMOTE_ADDR'];
         $base .= $_SERVER['REMOTE_PORT'];
         $name = strtolower(md5($base));
         $location = strtoupper(substr($name, 0, 1) . '/' . substr($name, 1, 1) . '/') . $name;
         // Check uniqueness
         $qb = midcom_db_attachment::new_query_builder();
         $qb->add_constraint('location', '=', $location);
         if (isset($this->id) && !empty($this->id)) {
             // Add this one if and only if we are persistent already.
             $qb->add_constraint('id', '<>', $this->id);
         } elseif (isset($this->guid) && !empty($this->guid)) {
             // Add this one if and only if we are persistent already.
             $qb->add_constraint('guid', '<>', $this->guid);
         }
         $result = $qb->count_unchecked();
         if ($result == 0) {
             $location_in_use = false;
         } else {
             debug_add("Location {$location} is in use, retrying");
         }
     }
     debug_add("Created this location: {$location}");
     return $location;
 }
Example #2
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];
 }
Example #3
0
 private function _list_files()
 {
     $qb = midcom_db_attachment::new_query_builder();
     $qb->add_constraint('parentguid', '=', $this->_object->guid);
     $qb->add_order('mimetype');
     $qb->add_order('metadata.score', 'DESC');
     $qb->add_order('name');
     $this->_files = $qb->execute();
 }
Example #4
0
 private function _run_search(&$data)
 {
     $qb = midcom_db_attachment::new_query_builder();
     $query = str_replace('*', '%', $data['query']);
     $qb->begin_group('OR');
     $qb->add_constraint('name', 'LIKE', $query);
     $qb->add_constraint('title', 'LIKE', $query);
     $qb->add_constraint('mimetype', 'LIKE', $query);
     $qb->end_group();
     $this->_search_results = $qb->execute();
     midcom::get('head')->add_jsonload("jQuery('.midcom_helper_imagepopup_search_result_item').dm2ImagePopupConvert();");
 }
Example #5
0
<?php

midcom::get('auth')->require_admin_user();
midcom::get()->disable_limits();
$qb = midcom_db_attachment::new_query_builder();
$qb->add_order('metadata.created', 'DESC');
echo "<p>STARTING...</p>\n";
$atts = $qb->execute_unchecked();
echo "<p>" . count($atts) . " attachments to process...</p>\n";
foreach ($atts as $att) {
    $att->file_to_cache();
}
echo "<p>DONE</p>\n";