Пример #1
0
 /**
  * Helper to generate a random WKT string
  *
  * Try to keeps values sane, no shape is more than 100km across
  */
 function wkt_generate()
 {
     $types = array('point', 'linestring', 'polygon', 'multipoint', 'multilinestring', 'multipolygon');
     // don't always generate the same type
     shuffle($types);
     $type = $types[0];
     $func = 'wkt_generate_' . $type;
     if (method_exists($this, $func)) {
         $wkt = $this->{$func}();
         return drupal_strtoupper($type) . ' (' . $wkt . ')';
     }
     return 'POINT (0 0)';
 }
/**
 * Factory method for creating questions from an XML DOMEelement.
 *
 * @param DOMElement $xmlNode
 *   representing the question.
 * @param CqUserAnswerInterface $userAnswer
 *   to use for storing the user's answer
 * @param Object $node
 *   Drupal node object that this comes from.
 *
 * @return CqQuestion
 *   The question.
 */
function cq_question_from_dom_element($xml_node, &$user_answer, &$node)
{
    $type = $xml_node->getAttribute('type');
    $question = FALSE;
    switch (drupal_strtoupper($type)) {
        case 'BALANCE':
            $question = new CqQuestionBalance($user_answer, $node);
            break;
        case 'CHECK':
            $question = new CqQuestionCheck($user_answer, $node);
            break;
        case 'DRAGDROP':
            $question = new CqQuestionDragDrop($user_answer, $node);
            break;
        case 'FILLBLANKS':
            $question = new CqQuestionFillblanks($user_answer, $node);
            break;
        case 'FLASH':
            $question = new CqQuestionFlash($user_answer, $node);
            break;
        case 'HOTSPOT':
            $question = new CqQuestionHotspot($user_answer, $node);
            break;
        case 'OPTION':
            $question = new CqQuestionOption($user_answer, $node);
            break;
        case 'SELECTORDER':
        case 'PATTERN':
            $question = new CqQuestionSelectOrder($user_answer, $node);
            break;
        case 'SEQUENCE':
            $question = new CqQuestionSequence($user_answer, $node);
            break;
        case 'VALUE':
            $question = new CqQuestionValue($user_answer, $node);
            break;
        default:
            drupal_set_message(t('Unknown question type: %type', array('%type' => $type)), 'error');
            break;
    }
    return $question;
}
Пример #3
0
/**
 * Factory method for creating hotspot classes from XML DOMElements
 *
 * @param DOMElement $node
 *   The XML element representing the hotspot.
 * @param CqQuestionInterface $context
 *   The question or other object that the mapping can query for things like the
 *   current answer, draggables and hotspots.
 *
 * @return CqHotspot
 *   The correct hotspot object.
 */
function cq_Hotspot_from_xml($node, $context)
{
    $type = '';
    if ($node) {
        $type = $node->getAttribute('shape');
        $identifier = $node->getAttribute('identifier');
        if (empty($identifier)) {
            $identifier = $node->getAttribute('id');
        }
        $coords = $node->getAttribute('coords');
        $description = cq_get_text_content($node, $context);
        $hotspot = FALSE;
        switch (drupal_strtoupper($type)) {
            case 'RECT':
                $numbers = explode(',', $coords);
                $x1 = (int) $numbers[0];
                $y1 = (int) $numbers[1];
                $x2 = (int) $numbers[2];
                $y2 = (int) $numbers[3];
                $hotspot = new CqHotspotRect($identifier, $x1, $y1, $x2, $y2);
                $hotspot->setDescription($description);
                break;
            case 'CIRCLE':
                $numbers = explode(',', $coords);
                $x1 = (int) $numbers[0];
                $y1 = (int) $numbers[1];
                $radius = (int) $numbers[2];
                $hotspot = new CqHotspotCircle($identifier, $x1, $y1, $radius);
                $hotspot->setDescription($description);
                break;
            case 'POLY':
                $numbers = explode(',', $coords);
                $hotspot = new CqHotspotPoly($identifier, $numbers);
                $hotspot->setDescription($description);
                break;
            default:
                drupal_set_message(t('Unknown hotspot type: %type', array('%type' => $type)));
                break;
        }
    }
    return $hotspot;
}
Пример #4
0
/**
 * Convert an RGB triplet to a hex color.
 */
function _abessive_color_pack($rgb, $normalize = FALSE)
{
    $out = 0;
    foreach ($rgb as $k => $v) {
        $out |= $v * ($normalize ? 255 : 1) << 16 - $k * 8;
    }
    return '#' . str_pad(drupal_strtoupper(dechex($out)), 6, 0, STR_PAD_LEFT);
}
 /**
  * Add the active facet filters to the parameters.
  */
 protected function addFacetFilters($params)
 {
     // Add the date range facet.
     if (isset($params['date_range'])) {
         $dates = explode('-', $params['date_range']);
         $startDate = DateTime::createFromFormat('d/m/Y', trim($dates[0]));
         if ($startDate) {
             $endDate = clone $startDate;
             if (isset($dates[1])) {
                 $endDateTime = DateTime::createFromFormat('d/m/Y', trim($dates[1]));
                 if ($endDateTime) {
                     $endDate = $endDateTime;
                 }
             }
             // Set start date time on beginning of the day.
             $startDate->setTime(0, 0, 0);
             // Set end date time to end of the day day, to it searches on full day.
             $endDate->setTime(23, 59, 59);
             $this->parameters[] = new Parameter\DateRangeFilterQuery('startdate', $startDate->getTimestamp(), $endDate->getTimestamp());
         }
     }
     // Add search on coordinates.
     if (isset($params['coordinates'])) {
         $coordinates = explode(',', $params['coordinates']);
         if (isset($params['distance'])) {
             $this->parameters[] = new Parameter\Spatial\Distance($params['distance']);
         } else {
             $this->parameters[] = new Parameter\Spatial\Distance(CULTUREFEED_SEARCH_DEFAULT_PROXIMITY_RANGE);
         }
         if (isset($params['sort']) && $params['sort'] == 'geodist') {
             $this->parameters[] = new Parameter\Sort('geodist()', 'asc');
             $this->parameters[] = new Parameter\FilterQuery('{!geofilt}');
         }
         $this->parameters[] = new Parameter\Spatial\Point($coordinates[0], $coordinates[1]);
         $this->parameters[] = new Parameter\Spatial\SpatialField('physical_gis');
     }
     if (empty($params['facet']['category_flandersregion_id'][0]) && !empty($params['location'])) {
         $flanders_region = culturefeed_search_get_category_by_slug($params['location'], 'flandersregion');
         if (!empty($flanders_region)) {
             $flanders_region = $flanders_region->tid;
         }
         // Backwards compatiblity for sites without clean urls: make sure location is mapped to flandersregion.
         if (empty($flanders_region)) {
             $flanders_region = key(culturefeed_search_get_categories_by_domain('flandersregion', array('name_like' => $params['location'])));
         }
         // Check if a valid flanders region was found. If not, show a message and force empty result.
         if (empty($flanders_region)) {
             drupal_set_message(t('You are searching on an invalid location.'), 'warning', FALSE);
             $params['facet']['category_flandersregion_id'][0] = $params['location'];
         } else {
             $params['facet']['category_flandersregion_id'][0] = $flanders_region;
         }
     }
     // Add the location facet. Only use the location if a distance is set.
     // all other cases will search for a category Id of the type flandersregion
     // or workingregion.
     if (!empty($params['facet']['category_flandersregion_id'][0])) {
         if (!isset($params['distance'])) {
             $regFilter = array();
             if (!empty($params['wregIds'])) {
                 $regFilter[] = array_shift($params['wregIds']);
                 $wregFilters = array();
                 foreach ($params['wregIds'] as $wregId) {
                     $wregFilters[] = $wregId;
                 }
             }
             if (empty($_GET['only-wregs'])) {
                 $regFilter = array_merge($regFilter, $params['facet']['category_flandersregion_id']);
             }
             $regFilterQuery = '(';
             $regFilterQuery .= 'category_id:(' . implode(' OR ', $regFilter) . ')';
             if (!empty($wregFilters)) {
                 $regFilterQuery .= ' OR exact_category_id:(' . implode(' OR ', $wregFilters) . ')';
             }
             $regFilterQuery .= ')';
             $this->parameters[] = new Parameter\FilterQuery($regFilterQuery);
         } else {
             $location = culturefeed_search_get_term_by_id($params['facet']['category_flandersregion_id'][0]);
             // Check if postal was present.
             if ($location) {
                 $city_parts = explode(' ', $location->name);
                 if (is_numeric($city_parts[0]) && empty($params['wregIds'])) {
                     $distance = isset($params['distance']) ? $params['distance'] : FALSE;
                     // If category_actortype_id we assume that we search on pages (on day we have to fix)
                     if (isset($params['facet']['category_actortype_id'])) {
                         $this->parameters[] = new Parameter\FilterQuery('zipcode' . ':' . $city_parts[0]);
                     } else {
                         $this->parameters[] = new Parameter\Spatial\Zipcode($city_parts[0], $distance);
                     }
                 }
             }
         }
         unset($params['facet']['category_flandersregion_id']);
     }
     // Calculate actor if available.
     if (isset($params['actor']) && !empty($params['actor'])) {
         $this->parameters[] = new Parameter\FilterQuery('"' . $params['actor'] . '"');
     }
     foreach ($params['facet'] as $facetFieldName => $facetFilter) {
         // Filter out empty facets.
         $facetFilter = array_filter($facetFilter);
         if (!empty($facetFilter)) {
             // Datetype is not a real facet, but a search field.
             if ($facetFieldName == 'datetype') {
                 $facetFilterQuery = new Parameter\DateTypeQuery(implode(' OR ', $facetFilter));
             } elseif ($facetFieldName == 'location_category_facility_id') {
                 $operator = drupal_strtoupper(variable_get('culturefeed_multiple_categories_operator', 'and'));
                 $facetFilterQuery = new Parameter\FilterQuery('location_category_facility_id:(' . implode(' ' . $operator . ' ', $facetFilter) . ')');
             } else {
                 // If wreg we need to add reg (same id's, example 3000 Leuven wreg.638 reg.638)
                 foreach ($facetFilter as $facetFilterItem) {
                     if (substr($facetFilterItem, 0, 4) == 'wreg') {
                         $facetFilter[] = substr($facetFilterItem, 1);
                     }
                 }
                 array_walk($facetFilter, function (&$item) {
                     $item = '"' . str_replace('"', '\\"', $item) . '"';
                 });
                 $operator = drupal_strtoupper(variable_get('culturefeed_multiple_categories_operator', 'and'));
                 // @todo clean up this code. This is still buggy.
                 if (!empty($facetFilter)) {
                     $facetFilterQuery = new Parameter\FilterQuery('category_id:(' . implode(' ' . $operator . ' ', $facetFilter) . ')');
                 }
             }
             $this->parameters[] = $facetFilterQuery;
         }
     }
 }
Пример #6
0
function ardent_facet_items_alter(&$build, &$settings)
{
    if ($settings->facet == "YOUR_FACET_NAME") {
        foreach ($build as $key => $item) {
            $build[$key]["#markup"] = drupal_strtoupper($item["#markup"]);
        }
    }
}
Пример #7
0
/**
 * Return the first letter in current path page.
 *
 * @return null|string
 *   The first letter.
 */
function obiba_bootstrap_letters_badge_title()
{
    $current_item = explode('/', current_path());
    if (!empty($current_item[0]) && $current_item[0] != 'mica') {
        return NULL;
    }
    if (!empty($current_item[1])) {
        if (!empty($current_item[2]) && strstr($current_item[2], 'study-') || strstr($current_item[1], 'study-')) {
            return 'D';
        }
        if (!empty($current_item[2]) && strstr($current_item[2], 'harmonization-') || strstr($current_item[1], 'harmonization-')) {
            return 'D-h';
        }
        if (strstr($current_item[1], 'datasets')) {
            return 'D';
        }
        if (strstr($current_item[1], 'coverage')) {
            return 'taxonomy';
        } elseif (strstr($current_item[1], 'search')) {
            return 'search-icon';
        } else {
            return drupal_strtoupper(drupal_substr($current_item[1], 0, 1));
        }
    } else {
        return NULL;
    }
}
Пример #8
0
function _os_poker_process_message_unsafe()
{
    static $poker_server_events = array('NONE', 'HAND', 'TOURNEY', 'BUY_IN', 'REFILL', 'PRIZE', 'REGISTER', 'UNREGISTER', 'LEAVE', 'SEAT', 'TOURNEY_START');
    $current_user = CUserManager::instance()->CurrentUser();
    $resp = array("errorMsg" => NULL, "error" => FALSE, "messages" => array());
    $message_type = trim(isset($_GET["type"]) ? trim($_GET["type"]) : "noop");
    if ($message_type == "os_poker_reward") {
        /* Reward message is a special message which comes without a current user context 
        		   args[0] = reward number
        		   args[1] = player serial
        		   args[2] = time_stamp
        		*/
        $all_rewards = CPoker::GetRewards();
        $params = json_decode($_GET['args'], TRUE);
        CPoker::ShowReward("reward" . $params[0], $params[1], $all_rewards);
        $resp["messages"][] = array("type" => "noop", "body" => NULL);
    }
    if ($current_user && $current_user->uid != 0) {
        switch ($message_type) {
            case "os_poker_sit_down":
                CPoker::CheckRewards("sit", $current_user->uid, json_decode($_GET["players"], TRUE));
                $resp["messages"][] = array("type" => "noop", "body" => NULL);
                break;
            case "os_poker_daily_gift":
                if ($current_user->DailyGift()) {
                    $resp["messages"][] = array('type' => 'os_poker_gift_sent', 'body' => array('text' => t('You have sent !amount free chips to !count buddies', array('!count' => count($current_user->Buddies()), '!amount' => 100))));
                } else {
                    $resp["messages"][] = array("type" => "noop", "body" => NULL);
                }
                break;
            case "os_poker_load_messagebox":
                CScheduler::instance()->Trigger("inbox");
                $mbox = CScheduler::instance()->GetUnreadTasks("inbox");
                $mboxsize = count($mbox);
                if ($_GET["msgcount"] != $mboxsize) {
                    $resp["messages"][] = array("type" => "os_poker_messagebox", "body" => array("inbox" => $mboxsize, "picture" => $base_path . drupal_get_path('module', 'os_poker') . "/images/mailbox.png"));
                } else {
                    $resp["messages"][] = array("type" => "noop", "body" => NULL);
                }
                break;
            case "os_poker_challenge_user":
                //TODO: limit challenge to 1 per sender/receiver
                if (isset($_GET["challengetarget"])) {
                    $target_user = CUserManager::instance()->User($_GET["challengetarget"]);
                    if ($target_user && $target_user->uid != 0 && $current_user->uid != $target_user->uid) {
                        //Wait for symbol, text, link
                        $args["symbol"] = 'chips';
                        $args["text"] = t("You just receive a headsup challenge from !user", array("!user" => $current_user->profile_nickname));
                        $args["links"] = "<a class='noreplace' href='javascript:void(0);' onclick='javascript:parent.os_poker_start_challenge(" . $current_user->uid . ", " . $target_user->uid . ");'>" . t("Accept") . "</a>/<a href='javascript:void(0);' >" . t("Refuse") . "</a>";
                        CMessageSpool::instance()->SendMessage($target_user->uid, $args);
                        $notification = array('text' => t("You just challenged !user", array("!user" => $target_user->profile_nickname ? $target_user->profile_nickname : variable_get('anonymous', t('Anonymous')))), 'title' => t('Challenge'));
                        CMessageSpool::instance()->SendInstantMessage($notification);
                        $resp["messages"][] = array("type" => "os_poker_notify", "body" => $notification);
                    }
                }
                break;
            case "os_poker_activate_item":
                if (isset($_GET["id_item"]) && is_numeric($_GET["id_item"])) {
                    $current_user->ActivateItem($_GET["id_item"]);
                } else {
                    trigger_error(t('Invalid item ID: %item_id', array('%item_id' => isset($_GET["id_item"]) ? $_GET["id_item"] : 'undefined')), E_USER_ERROR);
                }
                break;
            case "os_poker_invite_user":
                if (isset($_GET["target"])) {
                    $target_user = CUserManager::instance()->User($_GET["target"]);
                    if ($target_user && $target_user->uid != 0 && $current_user->uid != $target_user->uid) {
                        $tables = $current_user->Tables();
                        if (count($tables) > 0) {
                            $args["symbol"] = 'chips';
                            $args["text"] = t("!user is playing at table !table come and join", array("!user" => $current_user->profile_nickname, "!table" => $tables[0]->name));
                            //TODO : Check $_GET["online"] to send mail
                            CMessageSpool::instance()->SendMessage($target_user->uid, $args);
                            $notification = array('text' => t("You just invited !user to play", array("!user" => $target_user->profile_nickname ? $target_user->profile_nickname : variable_get('anonymous', t('Anonymous')))), 'title' => t('Invitation'));
                            CMessageSpool::instance()->SendInstantMessage($notification);
                            $resp["messages"][] = array("type" => "os_poker_notify", "body" => $notification);
                        }
                    }
                }
                break;
            case 'os_poker_trigger_error':
                trigger_error("Message triggered error.", E_USER_ERROR);
                break;
            case 'os_poker_trigger_exception':
                throw new Exception('Message triggered exception.');
                break;
            default:
                $resp["messages"][] = array("type" => "noop", "body" => NULL);
                break;
        }
    }
    if (in_array(drupal_strtoupper($message_type), $poker_server_events)) {
        if (preg_match('/\\[([^,]+),([^,]+),([^,]+)\\]/', $_GET['args'], $args)) {
            array_shift($args);
        }
        //Event setn from the poker server
        //TODO Authenticate the request... how ?
        switch ($message_type) {
            case 'BUY_IN':
                list($uid, $game_id, $amount) = $args;
                if (user_load($uid)) {
                    CScheduler::instance()->RegisterTask(new CUpdateUserChipsCount(), $uid, array('live'));
                    $resp["messages"][] = array("type" => "debug", "body" => t('Recevied BUY_IN for user !uid', array('!uid' => $uid)));
                } else {
                    trigger_error(t('Invalid user ID: %uid', array('%uid' => $uid)), E_USER_ERROR);
                }
                break;
            case 'TOURNEY_START':
                list($tourney_serial, $dummy1, $dummy2) = $args;
                $tourney_users = CPoker::TourneyRegisteredUsers($tourney_serial);
                foreach ($tourney_users as $tourney_user) {
                    if (user_load($tourney_user->user_serial)) {
                        CScheduler::instance()->RegisterTask(new CTourneyNotificationMessage(), $tourney_user->user_serial, array('live'), "-1 day", array($tourney_serial, $tourney_user->description_short, $tourney_user->table_serial));
                        $resp["messages"][] = array("type" => "debug", "body" => t('Recevied tourney start notification for user !uid', array('!uid' => $tourney_user->user_serial)));
                    }
                }
                break;
            case 'HAND':
            case 'TOURNEY':
            case 'REFILL':
            case 'PRIZE':
            case 'REGISTER':
            case 'UNREGISTER':
            case 'LEAVE':
            case 'SEAT':
            case 'NONE':
                $resp["messages"][] = array("type" => "noop", "body" => NULL);
                break;
        }
    } else {
        if (!$resp["messages"]) {
            $resp["messages"][] = array("type" => "noop", "body" => NULL);
        }
    }
    _os_poker_process_message_set_header();
    print json_encode($resp);
}
Пример #9
0
 /**
  * Return full license name.
  */
 function get_name($style = 'full')
 {
     if ($this->is_valid()) {
         // CCO
         $prefix = $this->type && $this->type != 'zero' ? t('Creative Commons') . ' ' : '';
         switch ($style) {
             case 'full':
                 $name = $prefix . $this->name;
                 break;
             case 'generic':
                 $name = creativecommons_generic_license_name($prefix . $this->name);
                 break;
             case 'short':
                 //TODO: t() ?
                 switch ($this->type) {
                     case 'zero':
                         $name = t('CC0');
                         break;
                     case 'publicdomain':
                         $name = 'PD';
                         break;
                     default:
                         $name = 'CC ' . drupal_strtoupper($this->type);
                 }
                 break;
         }
         return $name;
     } else {
         return '"' . $this->uri . '"';
     }
 }
Пример #10
0
function _user_import_create_username($order, $data, $abbreviate, $username_space)
{
    if (is_array($order)) {
        asort($order);
        reset($order);
        $username = '';
        while (list($file_column, $sequence) = each($order)) {
            if (!empty($username) && !empty($username_space)) {
                $username .= ' ';
            }
            $username .= $abbreviate[$file_column] == 1 ? trim(drupal_strtoupper(chr(ord($data[$file_column])))) : trim($data[$file_column]);
        }
    }
    if (empty($username)) {
        $username = _user_import_random_username();
    }
    $username = _user_import_sanitise_username($username);
    $username = _user_import_unique_username($username, TRUE);
    return $username;
}
Пример #11
0
 /**
  * Files cleaner handler.
  *
  * @param string $type
  *   Type: CSS or JS.
  */
 private static function cleanerFilesClear($type)
 {
     // Check if CSS/JS aggregation enabled.
     if (variable_get('preprocess_' . $type)) {
         $dir = drupal_realpath('public://' . $type);
         foreach (scandir($dir) as $file) {
             if (strpos($file, $type) !== FALSE) {
                 $uri = 'public://' . $type . '/' . $file;
                 if (REQUEST_TIME - filemtime($uri) > 3600) {
                     file_unmanaged_delete($uri);
                 }
             }
         }
         // Write a log about successful files clearing into the watchdog.
         self::cleanerLog('Cleared old temporary @type files by Cleaner', array('@type' => drupal_strtoupper($type)));
     } else {
         // Write a log about thing that CSS/JS aggregation isn't enabled.
         self::cleanerLog('Aggregation for @type files isn\'t enabled', array('@type' => drupal_strtoupper($type)));
     }
 }
/**
 * Apply advanced options to a generated member id string.
 */
function _membership_entity_token_clean_string($string, $settings)
{
    // Remove all HTML tags from the string.
    $return = strip_tags(decode_entities($string));
    // Get rid of words that are on the ignore list
    $ignore_words = $settings['ignore_words'];
    $ignore_words_regex = preg_replace(array('/^[,\\s]+|[,\\s]+$/', '/[,\\s]+/'), array('', '\\b|\\b'), $ignore_words);
    if ($ignore_words_regex) {
        $ignore_words_regex = '/\\b' . $ignore_words_regex . '\\b/i';
        $words_removed = preg_replace($ignore_words_regex, '', $return);
        if (drupal_strlen(trim($words_removed)) > 0) {
            $return = $words_removed;
        }
    }
    // Replace whitespace with the separator.
    $return = _membership_entity_token_clean_separator($return, $settings['separator']);
    // Convert to lower or upper case.
    if ($settings['case'] == 'lower') {
        $return = drupal_strtolower($return);
    } else {
        if ($settings['case'] == 'upper') {
            $return = drupal_strtoupper($return);
        }
    }
    // Shorten to maxlength.
    if (!empty($settings['maxlength'])) {
        $return = truncate_utf8($return, $settings['maxlength']);
    }
    return $return;
}
 /**
  * Test that text separated by block-level tags in HTML get separated by
  * (at least) a newline in the plaintext version.
  */
 public function testDrupalHtmlToTextBlockTagToNewline()
 {
     $input = '[text]' . '<blockquote>[blockquote]</blockquote>' . '<br />[br]' . '<dl><dt>[dl-dt]</dt>' . '<dt>[dt]</dt>' . '<dd>[dd]</dd>' . '<dd>[dd-dl]</dd></dl>' . '<h1>[h1]</h1>' . '<h2>[h2]</h2>' . '<h3>[h3]</h3>' . '<h4>[h4]</h4>' . '<h5>[h5]</h5>' . '<h6>[h6]</h6>' . '<hr />[hr]' . '<ol><li>[ol-li]</li>' . '<li>[li]</li>' . '<li>[li-ol]</li></ol>' . '<p>[p]</p>' . '<ul><li>[ul-li]</li>' . '<li>[li-ul]</li></ul>' . '[text]';
     $output = drupal_html_to_text($input);
     $pass = $this->assertFalse(preg_match('/\\][^\\n]*\\[/s', $output), 'Block-level HTML tags should force newlines');
     if (!$pass) {
         $this->verbose($this->stringToHtml($output));
     }
     $output_upper = drupal_strtoupper($output);
     $upper_input = drupal_strtoupper($input);
     $upper_output = drupal_html_to_text($upper_input);
     $pass = $this->assertEqual($upper_output, $output_upper, 'Tag recognition should be case-insensitive');
     if (!$pass) {
         $this->verbose($upper_output . '<br />should  be equal to <br />' . $output_upper);
     }
 }
Пример #14
0
 /**
  * just uppercases the http method
  */
 public function get_normalized_http_method()
 {
     return drupal_strtoupper($this->http_method);
 }
 /**
  * Returns an array of parts as file objects
  *
  * @param
  * @param $structure
  *   A message structure, usually used to recurse into specific parts
  * @param $max_depth
  *   Maximum Depth to recurse into parts.
  * @param $depth
  *   The current recursion depth.
  * @param $part_number
  *   A message part number to track position in a message during recursion.
  * @return
  *   An array of file objects.
  */
 function get_parts($stream, $msg_number, $max_depth = 10, $depth = 0, $structure = FALSE, $part_number = 1)
 {
     $parts = array();
     // Load Structure.
     if (!$structure && !($structure = imap_fetchstructure($stream, $msg_number))) {
         watchdog('mailhandler', 'Could not fetch structure for message number %msg_number', array('%msg_number' => $msg_number), WATCHDOG_NOTICE);
         return $parts;
     }
     // Recurse into multipart messages.
     if ($structure->type == TYPEMULTIPART) {
         // Restrict recursion depth.
         if ($depth >= $max_depth) {
             watchdog('mailhandler', 'Maximum recursion depths met in mailhander_get_structure_part for message number %msg_number.', array('%msg_number' => $msg_number), WATCHDOG_NOTICE);
             return $parts;
         }
         $prefix = '';
         foreach ($structure->parts as $index => $sub_structure) {
             // If a part number was passed in and we are a multitype message, prefix the
             // the part number for the recursive call to match the imap4 dot seperated part indexing.
             if ($part_number) {
                 $prefix = $part_number . '.';
             }
             $sub_parts = $this->get_parts($stream, $msg_number, $max_depth, $depth + 1, $sub_structure, $prefix . ($index + 1));
             $parts = array_merge($parts, $sub_parts);
         }
         return $parts;
     }
     // Per Part Parsing.
     // Initalize file object like part structure.
     $part = new stdClass();
     $part->attributes = array();
     $part->filename = 'unnamed_attachment';
     if (!($part->filemime = $this->get_mime_type($structure))) {
         watchdog('mailhandler', 'Could not fetch mime type for message part. Defaulting to application/octet-stream.', array(), WATCHDOG_NOTICE);
         $part->filemime = 'application/octet-stream';
     }
     if ($structure->ifparameters) {
         foreach ($structure->parameters as $parameter) {
             switch (drupal_strtoupper($parameter->attribute)) {
                 case 'NAME':
                 case 'FILENAME':
                     $part->filename = $parameter->value;
                     break;
                 default:
                     // put every thing else in the attributes array;
                     $part->attributes[$parameter->attribute] = $parameter->value;
             }
         }
     }
     // Handle Content-Disposition parameters for non-text types.
     if ($structure->type != TYPETEXT && $structure->ifdparameters) {
         foreach ($structure->dparameters as $parameter) {
             switch (drupal_strtoupper($parameter->attribute)) {
                 case 'NAME':
                 case 'FILENAME':
                     $part->filename = $parameter->value;
                     break;
                     // put every thing else in the attributes array;
                 // put every thing else in the attributes array;
                 default:
                     $part->attributes[$parameter->attribute] = $parameter->value;
             }
         }
     }
     // Store part id for reference.
     if (!empty($structure->id)) {
         $part->id = $structure->id;
     }
     // Retrieve part and convert MIME encoding to UTF-8
     if (!($part->data = imap_fetchbody($stream, $msg_number, $part_number, FT_PEEK))) {
         watchdog('mailhandler', 'No Data!!', array(), WATCHDOG_ERROR);
         return $parts;
     }
     // Decode as necessary.
     if ($structure->encoding == ENCBASE64) {
         $part->data = imap_base64($part->data);
     } elseif ($structure->encoding == ENCQUOTEDPRINTABLE) {
         $part->data = quoted_printable_decode($part->data);
     } elseif ($structure->type == TYPETEXT) {
         $part->data = imap_utf8($part->data);
     }
     // Always return an array to satisfy array_merge in recursion catch, and
     // array return value.
     $parts[] = $part;
     return $parts;
 }
Пример #16
0
 /**
  * Get the active trail to show.
  */
 public function getActiveTrail()
 {
     $active_trail = array();
     $active_trail[] = array('title' => t('Home'), 'href' => '<front>', 'link_path' => '', 'localized_options' => array(), 'type' => 0);
     $active_trail[] = array('title' => t('Agenda'), 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array(), 'type' => 0);
     // Show event type and theme in breadcrumb.
     $query = drupal_get_query_parameters(NULL, array('page', 'q'));
     $facet = array();
     if (isset($query['facet']['category_eventtype_id']) || isset($query['facet']['category_theme_id'])) {
         if (isset($query['facet']['category_eventtype_id'])) {
             $facet['category_eventtype_id'] = $query['facet']['category_eventtype_id'];
             $title = array();
             foreach ($facet['category_eventtype_id'] as $eventtype_id) {
                 if (strpos($eventtype_id, '!') === 0) {
                     $title[] = t('NOT ') . culturefeed_search_get_term_translation(substr($eventtype_id, 1));
                 } else {
                     $title[] = culturefeed_search_get_term_translation($eventtype_id);
                 }
             }
             $operator = drupal_strtoupper(variable_get('culturefeed_multiple_categories_operator', 'and'));
             $active_trail[] = array('title' => implode(' ' . $operator . ' ', $title), 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array('query' => array('facet' => $facet)), 'type' => 0);
         }
         if (isset($query['facet']['category_theme_id'])) {
             $facet['category_theme_id'] = $query['facet']['category_theme_id'];
             $active_trail[] = array('title' => culturefeed_search_get_term_translation($query['facet']['category_theme_id'][0]), 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array('query' => array('facet' => $facet)), 'type' => 0);
         }
     }
     // Show entity type in breadcrumb for actors.
     if (isset($query['facet']['type'])) {
         if ($query['facet']['type'][0] == 'actor') {
             $facet['type'] = $query['facet']['type'];
             $active_trail[] = array('title' => t('Places & organisers'), 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array('query' => array('facet' => $facet)), 'type' => 0);
         }
     }
     // Show actor type in breadcrumb.
     if (isset($query['facet']['category_actortype_id'])) {
         $facet['category_actortype_id'] = $query['facet']['category_actortype_id'];
         $active_trail[] = array('title' => culturefeed_search_get_term_translation($query['facet']['category_actortype_id'][0]), 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array('query' => array('facet' => $facet)), 'type' => 0);
     }
     // Show flandersregion in breadcrumb.
     if (isset($query['facet']['category_flandersregion_id'])) {
         $facet['category_flandersregion_id'] = $query['facet']['category_flandersregion_id'];
         $active_trail[] = array('title' => culturefeed_search_get_term_translation($query['facet']['category_flandersregion_id'][0]), 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array('query' => array('facet' => $facet)), 'type' => 0);
     }
     if (isset($query['location'])) {
         $active_trail[] = array('title' => $query['location'], 'href' => 'agenda/search', 'link_path' => '', 'localized_options' => array('query' => array('location' => $query['location'], 'facet' => $facet)), 'type' => 0);
     }
     $active_trail[] = array('title' => $this->getPageTitle(), 'href' => $_GET['q'], 'link_path' => '', 'localized_options' => array(), 'type' => 0);
     return $active_trail;
 }
Пример #17
0
 /**
  * Set database-engine specific properties for a field.
  *
  * @param $field
  *   A field description array, as specified in the schema documentation.
  */
 protected function processField($field)
 {
     if (!isset($field['size'])) {
         $field['size'] = 'normal';
     }
     // Set the correct database-engine specific datatype.
     // In case one is already provided, force it to uppercase.
     if (isset($field['sqlite_type'])) {
         $field['sqlite_type'] = drupal_strtoupper($field['sqlite_type']);
     } else {
         $map = $this->getFieldTypeMap();
         $field['sqlite_type'] = $map[$field['type'] . ':' . $field['size']];
     }
     if (isset($field['type']) && $field['type'] == 'serial') {
         $field['auto_increment'] = TRUE;
     }
     return $field;
 }
    ?>
><?php 
    print $label;
    ?>
:&nbsp;</div>
  <?php 
}
?>
  <div class="field-items"<?php 
print $content_attributes;
?>
><?php 
if (substr($element['#field_name'], 0, 17) === 'field_logo_files_' || substr($element['#field_name'], 0, 13) === 'field_medium_') {
    foreach ($variables['element']['#items'] as $delta => $item) {
        echo '<div class="field-item ' . ($delta % 2 ? 'odd' : 'even') . '"' . $item_attributes[$delta] . '>' . '<span class="full-url element-invisible">' . file_create_url($item['uri']) . '</span>';
        if (user_access('access zipcart downloads')) {
            echo theme('zipcart_download', array('text' => drupal_strtoupper(pathinfo($item['uri'], PATHINFO_EXTENSION)) . (!empty($item['description']) ? ' (' . $item['description'] . ')' : ''), 'path' => variable_get('file_public_path', conf_path() . '/files' . str_replace('public://', '/', $item['uri']))));
        } else {
            echo l(drupal_strtoupper(pathinfo($item['uri'], PATHINFO_EXTENSION)) . (!empty($item['description']) ? ' (' . $item['description'] . ')' : ''), file_create_url($item['uri']), array('attributes' => array('class' => 'zipcart')));
        }
        echo '</div>';
    }
} else {
    foreach ($items as $delta => $item) {
        echo '<div class="field-item ' . ($delta % 2 ? 'odd' : 'even') . '"' . $item_attributes[$delta] . '>' . render($item) . '</div>';
    }
}
?>
</div>
</div>
 *
 * Available variables:
 * - $lexicon_section: section object.
 *    - $lexicon_section->letter: The letter the section is for.
 *    - $lexicon_section->id: The id to be used as the anchor of the section.
 * - $lexicon_overview_items: Lexicon overview items as rendered by
 *   lexicon-overview-item.tpl.php
 */
if (isset($lexicon_section)) {
    ?>
  <a id="<?php 
    print $lexicon_section->id;
    ?>
"></a>
  <h2 class="lexicon-letter"><?php 
    print drupal_strtoupper($lexicon_section->letter);
    ?>
</h2>
<?php 
}
if (!empty($lexicon_overview_items)) {
    ?>
  <dl>
    <?php 
    print $lexicon_overview_items;
    ?>
  </dl>
<?php 
} else {
    ?>
  <p>
Пример #20
0
 /**
  * Retrieve a copy of the given directory item in the repository.
  *
  * (You won't get the original because repositories can often be
  * remote.)
  *
  * The caller should make sure to delete the directory when it's not
  * needed anymore.
  *
  * This function is optional for VCS backends to implement, be sure to
  * check return to NULL.
  *
  * @param $destination_dirpath
  *   The path of the directory that will receive the contents of the
  *   exported repository item. If that directory already exists, it
  *   will be replaced. If that directory doesn't yet exist, it will be
  *   created by the backend. (This directory will directly correspond
  *   to the @p $directory_item - there are no artificial
  *   subdirectories, even if the @p $destination_dirpath has a
  *   different basename than the original path of the @p
  *   $directory_item.)
  *
  * @return
  *   TRUE if successful, or FALSE if not.
  *   FALSE can be returned if the given item is not under version
  *   control, or was not under version control at the time of the given
  *   revision, or simply cannot be exported to the destination
  *   directory for any reason.
  */
 public function exportDirectory($destination_dirpath)
 {
     if (!$item->isDirectory()) {
         return FALSE;
     }
     // Unless file.inc provides a nice function for recursively deleting
     // directories, let's just go for the straightforward portable method.
     $rm = drupal_strtoupper(drupal_substr(PHP_OS, 0, 3)) == 'WIN' ? 'rd /s' : 'rm -rf';
     exec("{$rm} {$destination_dirpath}");
     if ($this instanceof VersioncontrolItemExportDirectory) {
         $success = $this->_exportDirectory($destination_dirpath);
     } else {
         return FALSE;
     }
     if (!$success) {
         exec("{$rm} {$destination_dirpath}");
         return FALSE;
     }
     return TRUE;
 }