Example #1
1
 public function generate_cookie()
 {
     $characters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0';
     $characters_array = explode(',', $characters);
     shuffle($characters_array);
     return implode('', $characters_array);
 }
 public function executeNormalView()
 {
     $this->setup();
     $this->options['constraints'] = $this->getOption('constraints', array());
     // Behave well if it's not set yet!
     if (strlen($this->slot->value)) {
         $items = $this->slot->MediaItems;
         $data = $this->slot->getArrayValue();
         $order = $data['order'];
         $itemsById = aArray::listToHashById($items);
         $this->items = array();
         foreach ($order as $id) {
             if (isset($itemsById[$id])) {
                 $this->items[] = $itemsById[$id];
             }
         }
         $this->itemIds = aArray::getIds($this->items);
         foreach ($this->items as $item) {
             $this->itemIds[] = $item->id;
         }
         if ($this->getOption('random', false)) {
             shuffle($this->items);
         }
     } else {
         $this->items = array();
         $this->itemIds = array();
     }
 }
Example #3
0
  function Render()
  {
    global $currentUser;
    if (!$currentUser)
      return;

    if (!$currentUser->CanSubmitItems())
      return;

    echo "\n\n";
    echo "<div class='pouettbl' id='".$this->uniqueID."'>\n";

    echo "  <h2>".$this->title."</h2>\n";
    echo "  <div class='content'>\n";

    $width = 15;

    $g = glob(POUET_CONTENT_LOCAL."avatars/*.gif");
    shuffle($g);
    $g = array_slice($g,0,$width * $width);

    echo "<ul id='avatargallery'>\n";
    foreach($g as $v)
      printf("  <li><img src='".POUET_CONTENT_URL."avatars/%s' alt='%s' title='%s'/></li>\n",basename($v),basename($v),basename($v));
    echo "</ul>\n";

    echo "  </div>\n";
    echo "</div>\n";
  }
Example #4
0
 protected function getBanners()
 {
     // images at {theme_path}/bnr
     $base_url = Yii::app()->theme->baseUrl;
     // 150x40
     $banners[] = array('link' => 'http://www.adyra.com', 'image' => $base_url . '/bnr/adyra.png');
     //$banners[] = array('link' => 'http://www.grupomoyvesa.com', 'image' => $base_url.'/bnr/moyvesa.png');
     //$banners[] = array('link' => 'http://www.melicar.com', 'image' => $base_url.'/bnr/melicar.png');
     //$banners[] = array('link' => 'http://www.fiateira.com', 'image' => $base_url.'/bnr/fiateira.png');
     $banners[] = array('link' => 'http://www.llantaslandin.com', 'image' => $base_url . '/bnr/landin.png');
     $banners[] = array('link' => 'http://www.grupotrigocar.com', 'image' => $base_url . '/bnr/trigocar.png');
     $banners[] = array('link' => 'http://www.imgautosubastas.com', 'image' => $base_url . '/bnr/imgautosubastas.png');
     $banners[] = array('link' => 'http://www.autosrema.com', 'image' => $base_url . '/bnr/rema.png');
     $banners[] = array('link' => 'http://www.automovilesmlosada.com', 'image' => $base_url . '/bnr/losada.png');
     $banners[] = array('link' => 'http://www.carballeiraautomocion.com', 'image' => $base_url . '/bnr/carballeira.png');
     $banners[] = array('link' => '#', 'image' => $base_url . '/bnr/monterey.png');
     $banners[] = array('link' => '#', 'image' => $base_url . '/bnr/mediodia.png');
     $banners[] = array('link' => 'http://www.donsilencioso.com', 'image' => $base_url . '/bnr/donsilencioso.png');
     $banners[] = array('link' => 'http://www.hangar.es', 'image' => $base_url . '/bnr/hangar.png');
     $banners[] = array('link' => 'http://rysservicios.com/', 'image' => $base_url . '/bnr/rys.png');
     // talleresmonterrey
     // talleresmediodia
     // donsilencioso
     shuffle($banners);
     return $banners;
 }
Example #5
0
function generarPalabras(&$palabraelegida, &$coincidencias, $palabras)
{
    global $VOCALES, $NUM_PALABRAS;
    shuffle($palabras);
    $palabrasrestantes = $palabras;
    $palabraelegida = [$palabras[0]];
    unset($palabrasrestantes[0]);
    $palabraconsonantes = str_replace($VOCALES, "", $palabraelegida[0]);
    $coincidencias = [];
    while (count($palabraelegida) < $NUM_PALABRAS) {
        $found = false;
        for ($i = 0; $i < strlen($palabraconsonantes) && !$found; $i++) {
            $c = $palabraconsonantes[$i];
            foreach ($palabrasrestantes as $key => $value) {
                if (strpos($value, $c) !== false) {
                    array_push($palabraelegida, $value);
                    $palabraconsonantes = str_replace($c, "", str_replace($VOCALES, "", $value));
                    array_push($coincidencias, $c);
                    unset($palabrasrestantes[$key]);
                    $found = true;
                    break;
                }
            }
        }
        //si no encuentra $found==false volver a empezar
        if ($found == false) {
            shuffle($palabras);
            $palabrasrestantes = $palabras;
            $palabraelegida = [$palabras[0]];
            unset($palabrasrestantes[0]);
            $palabraconsonantes = str_replace($VOCALES, "", $palabraelegida[0]);
            $coincidencias = [];
        }
    }
}
Example #6
0
function compo_cloud()
{
    global $wpdb;
    $topurl = get_bloginfo("url");
    $start = 10;
    $total = 24;
    $query = "SELECT {$wpdb->terms}.term_id, {$wpdb->terms}.name, {$wpdb->term_taxonomy}.count, {$wpdb->terms}.slug FROM (({$wpdb->term_relationships} INNER JOIN {$wpdb->posts} ON {$wpdb->term_relationships}.object_id = {$wpdb->posts}.ID) INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) INNER JOIN {$wpdb->terms} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id WHERE ((({$wpdb->term_taxonomy}.taxonomy)='post_tag') AND (({$wpdb->posts}.post_status)='publish')) GROUP BY {$wpdb->terms}.name ORDER BY count DESC, {$wpdb->terms}.name";
    # LIMIT $start,$total";
    $terms = $wpdb->get_results($query);
    shuffle($terms);
    $data = array();
    foreach ($terms as $e) {
        if ($e->count < 2) {
            continue;
        }
        $data[] = "{$e->count}|{$e->name}|{$e->slug}";
        if (count($data) >= $total) {
            break;
        }
    }
    natcasesort($data);
    $out = array();
    $n = 0;
    foreach ($data as $v) {
        $z = intval(8 + $n * 0.5);
        list($x, $name, $slug) = explode("|", $v);
        //         $name = htmlentities($name);
        $out[] = "<a href='{$topurl}/tag/{$slug}' style='font-size:{$z}px'>{$name}</a>";
        $n += 1;
    }
    shuffle($out);
    echo implode(" ", $out);
}
 protected function make_answer_form($attempt = null)
 {
     global $USER, $CFG;
     // don't shuffle answers (could be an option??)
     $getanswers = array_slice($this->get_answers(), 2);
     $answers = array();
     foreach ($getanswers as $getanswer) {
         $answers[$getanswer->id] = $getanswer;
     }
     $responses = array();
     foreach ($answers as $answer) {
         // get all the response
         if ($answer->response != null) {
             $responses[] = trim($answer->response);
         }
     }
     $responseoptions = array('' => get_string('choosedots'));
     if (!empty($responses)) {
         shuffle($responses);
         foreach ($responses as $response) {
             $responseoptions[htmlspecialchars($response)] = $response;
         }
     }
     if (isset($USER->modattempts[$this->lesson->id]) && !empty($attempt->useranswer)) {
         $useranswers = explode(',', $attempt->useranswer);
         $t = 0;
     } else {
         $useranswers = array();
     }
     $action = $CFG->wwwroot . '/mod/lesson/continue.php';
     $params = array('answers' => $answers, 'useranswers' => $useranswers, 'responseoptions' => $responseoptions, 'lessonid' => $this->lesson->id, 'contents' => $this->get_contents());
     $mform = new lesson_display_answer_form_matching($action, $params);
     return $mform;
 }
Example #8
0
 public static function runOften()
 {
     $feeds = XenForo_Model::create('DigitalPointSocialBar_Model_SocialBar')->getSlugsFromOptions();
     shuffle($feeds);
     // randomize order in case someone has absurd number of lists attached to forums (would need to be more than 180 unique) to work around Twitter API limits
     $cacheObject = XenForo_Application::getCache();
     $twitter = DigitalPointSocialBar_Helper_Twitter::getService(XenForo_Application::getOptions()->dpTwitterAccessToken, XenForo_Application::getOptions()->dpTwitterAccessTokenSecret, XenForo_Application::getOptions()->dpTwitterUsername);
     // forum specific feeds
     if ($feeds) {
         foreach ($feeds as $slug) {
             $tweets_array = array();
             $results = $twitter->listsStatuses(array('slug' => $slug, 'owner_screen_name' => XenForo_Application::getOptions()->dpTwitterUsername, 'count' => 250, 'include_rts' => 1, 'include_entities' => 1));
             if (count($results)) {
                 try {
                     for ($i = 0; $i < count($results); $i++) {
                         $tweet = $results[$i];
                         if (is_object($tweet->user)) {
                             $screen_name = $tweet->user->screen_name;
                             if (!@isset($tweets_array[$screen_name])) {
                                 $tweets_array[$screen_name] = DigitalPointSocialBar_Helper_Twitter::parseTweet($tweet);
                             }
                         }
                     }
                     $cacheObject->save(json_encode(array_values($tweets_array)), 'social_bar_' . str_replace('-', '_', $slug), array(), 604800);
                     // 7 day cache
                 } catch (Exception $e) {
                 }
             }
         }
     }
 }
Example #9
0
 static function getImagesFromFolder(&$params)
 {
     if (!is_numeric($max = $params->get('max_images'))) {
         $max = 20;
     }
     $folder = $params->get('image_folder');
     if (!($dir = @opendir($folder))) {
         return null;
     }
     while (false !== ($file = readdir($dir))) {
         if (preg_match('/.+\\.(jpg|jpeg|gif|png)$/i', $file)) {
             // check with getimagesize() which attempts to return the image mime-type
             if (getimagesize(JPATH_ROOT . DS . $folder . DS . $file) !== FALSE) {
                 $files[] = $file;
             }
         }
     }
     closedir($dir);
     if ($params->get('sort_by')) {
         natcasesort($files);
     } else {
         shuffle($files);
     }
     $images = array_slice($files, 0, $max);
     $target = modDJImageSliderHelper::getSlideTarget($params->get('link'));
     foreach ($images as $image) {
         $slides[] = (object) array('title' => '', 'description' => '', 'image' => $folder . '/' . $image, 'link' => $params->get('link'), 'alt' => $image, 'target' => $target);
     }
     return $slides;
 }
 public function tanya()
 {
     header("Content-type: text/javascript");
     $teks = $this->input->get('txt');
     if ($teks == "'" or $teks == '"') {
         $teks = "Aku maho";
     } elseif ($teks == 1) {
         $teks = "Satu";
     } elseif ($teks == 2) {
         $teks = "Duaa";
     } elseif ($teks == 3) {
         $teks = "Tiga";
     } elseif ($teks == 0) {
         $teks = "Bantuan Urang!";
     } else {
         $teks = "Ferdhika ganteng";
     }
     $teks = strtolower($teks);
     if ($teks) {
         $hasil = $this->db->query("SELECT * FROM tb_about WHERE MATCH(no) AGAINST('" . $teks . "' IN BOOLEAN MODE);");
         if ($hasil->num_rows() > 0) {
             $cius = $hasil->result_array();
             shuffle($cius);
             $arr = array('no' => $teks, 'response' => $cius[0]['jawaban']);
         } else {
             $cius = array("Jangan masukin kata lain selain angka yang ada di list", "Salah euy!");
             shuffle($cius);
             $arr = array('no' => $teks, 'response' => $cius[0]);
         }
     } else {
         $arr = array('response' => 'masukin dek textnya');
     }
     echo json_encode($arr);
 }
 public static function generate($length = 7)
 {
     $chars = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M');
     shuffle($chars);
     $password = substr(implode('', $chars), 0, $length);
     return $password;
 }
Example #12
0
 /**
  * @brief ้šๆœบ็”Ÿๆˆๅญ—็ฌฆไธฒๅ‡ฝๆ•ฐ
  * @param int $len ่ฆ็”Ÿๆˆ็š„้•ฟๅบฆ
  * @param string $type ็”Ÿๆˆๅญ—็ฌฆไธฒ็š„็ฑปๅž‹
  * @return String ้šๆœบ็”Ÿๆˆๅญ—็ฌฆ
  */
 public static function random($len = 6, $type = 'mix')
 {
     $len = intval($len);
     if ($len > 32) {
         $len = 32;
     }
     $str = '';
     $attr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'g', 'm', 'p', 't', 'z', 'c');
     shuffle($attr);
     $int_attr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '5', '9');
     shuffle($int_attr);
     $attr = implode($attr);
     $int_attr = implode($int_attr);
     switch ($type) {
         case 'int':
             $str = $int_attr;
             break;
         case 'char':
             $str = $attr;
             break;
         default:
             $str = md5(uniqid(mt_rand(), true));
             break;
     }
     return substr($str, 0, $len);
 }
Example #13
0
 public function __construct()
 {
     // Some logic to create the deck of cards
     $this->createDeck();
     // Shuffle the deck
     shuffle($this->cards);
 }
Example #14
0
 /**
  * Runs the tests
  *
  * @return array $results
  *  Returns array of results. A result consists of 
  */
 function run()
 {
     $results = array();
     $this->saveState();
     $class = get_class($this);
     $class_methods = get_class_methods($class);
     shuffle($class_methods);
     // execute tests in random order!
     foreach ($class_methods as $cm) {
         if (substr($cm, -4) == 'Test') {
             // Run the test
             if (is_callable(array($this, 'setUp'))) {
                 $this->setUp();
             }
             //echo "running $class::$cm...\n";
             try {
                 $ret = call_user_func(array($this, $cm));
                 // $ret is not used for now.
                 $results[$class][$cm] = array(self::TEST_SUCCEEDED, 'succeeded');
             } catch (Pie_Exception_TestCase $e) {
                 // one of the predefined testcase outcomes occurred
                 $results[$class][$cm] = array($e->getCode(), $e->getMessage());
             } catch (Exception $e) {
                 $results[$class][$cm] = array(self::TEST_EXCEPTION, 'exception', $e);
             }
             if (is_callable(array($this, 'tearDown'))) {
                 $this->tearDown();
             }
             $this->restoreState();
         }
     }
     $this->hasToRun = false;
     return $results;
 }
 private function generateTagCloud($tags, $resize = true, $min_font_size = 9, $max_font_size = 25, $font_weight)
 {
     if ($resize == true) {
         arsort($tags);
         $max_qty = max(array_values($tags));
         $min_qty = min(array_values($tags));
         $spread = $max_qty - $min_qty;
         if ($spread == 0) {
             $spread = 1;
         }
         $step = ((int) $max_font_size - (int) $min_font_size) / $spread;
         $cloud = array();
         foreach ($tags as $key => $value) {
             $size = rand((int) $min_font_size, (int) $max_font_size);
             $cloud[] = '<a href="' . $this->url->link('product/search', 'tag=' . $value) . '" style="text-decoration:none;font-size:' . $size . 'px;font-weight:' . $font_weight . ';" title="">' . $value . '</a> ';
         }
     } else {
         foreach ($tags as $key => $value) {
             $cloud[] = '<a href="' . $this->url->link('product/search', 'tag=' . $value) . '" style="text-decoration:none;" title="">' . $value . '</a> ';
         }
     }
     $tagcloud = '';
     shuffle($cloud);
     for ($x = 0; $x < count($cloud); $x++) {
         $tagcloud .= $cloud[$x];
     }
     return $tagcloud;
 }
Example #16
0
 /**
  * Shuffles the cards, takes in a multiplier 
  * which can be used to seed the number of times
  * the deck is shuffled
  * Return $this for possible chaining
  *
  * @param integer $multiplier number of times the deck should be shuffled, defaults to 100
  * @return Deck
  */
 public function shuffle($multiplier = 100)
 {
     for ($x = 0; $x < $multiplier; $x++) {
         shuffle($this->_cards);
     }
     return $this;
 }
 /**
  * @brief ์œ„์ ฏ์˜ ์‹คํ–‰ ๋ถ€๋ถ„
  *
  * ./widgets/์œ„์ ฏ/conf/info.xml ์— ์„ ์–ธํ•œ extra_vars๋ฅผ args๋กœ ๋ฐ›๋Š”๋‹ค
  * ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ ํ›„ print๊ฐ€ ์•„๋‹ˆ๋ผ return ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค
  **/
 function proc($args)
 {
     $banners = array();
     for ($i = 1; $i <= 10; $i++) {
         $array = array();
         foreach (array('url', 'img', 'target') as $type) {
             $key = $type . "_" . $i;
             $array[$type] = $args->{$key};
         }
         if ($array['img']) {
             array_push($banners, $array);
         }
     }
     shuffle($banners);
     $rand_keys = array_rand($banners, 2);
     $widget_info->url_1 = $banners[$rand_keys[0]]['url'];
     $widget_info->img_1 = $banners[$rand_keys[0]]['img'];
     $widget_info->target_1 = $banners[$rand_keys[0]]['target'];
     $widget_info->url_2 = $banners[$rand_keys[1]]['url'];
     $widget_info->img_2 = $banners[$rand_keys[1]]['img'];
     $widget_info->target_2 = $banners[$rand_keys[1]]['target'];
     Context::set('widget_info', $widget_info);
     $tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin);
     Context::set('colorset', $args->colorset);
     $tpl_file = 'skin';
     // ์œ„์ ฏ ์Šคํ‚จ์˜ ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ๋ช…์„ ์ง€์นญํ•จ. ํ•ด๋‹น ์œ„์ ฏ์˜ ์Šคํ‚จ ํŒŒ์ผ์€ ์ด ์ด๋ฆ„์„ ์จ์•ผ ๋™์ž‘ํ•จ.
     $oTemplate =& TemplateHandler::getInstance();
     return $oTemplate->compile($tpl_path, $tpl_file);
 }
 private function getRandomDescription()
 {
     $phrases = array('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Pellentesque vitae velit ex.', 'Mauris dapibus, risus quis suscipit vulputate, eros diam egestas libero, eu vulputate eros eros eu risus.', 'In hac habitasse platea dictumst.', 'Morbi tempus commodo mattis.', 'Donec vel elit dui.', 'Ut suscipit posuere justo at vulputate.', 'Phasellus id porta orci.', 'Ut eleifend mauris et risus ultrices egestas.', 'Aliquam sodales, odio id eleifend tristique, urna nisl sollicitudin urna, id varius orci quam id turpis.', 'Nulla porta lobortis ligula vel egestas.', 'Curabitur aliquam euismod dolor non ornare.', 'Nunc et feugiat lectus.', 'Nam porta porta augue.', 'Sed varius a risus eget aliquam.', 'Nunc viverra elit ac laoreet suscipit.', 'Pellentesque et sapien pulvinar, consectetur eros ac, vehicula odio.');
     $numPhrases = rand(5, 10);
     shuffle($phrases);
     return implode(' ', array_slice($phrases, 0, $numPhrases - 1));
 }
Example #19
0
 /**
  * @inheritdoc
  */
 public function shuffle()
 {
     if (!$this->hasCards()) {
         $this->reset();
     }
     shuffle($this->deck);
 }
 protected function generateNew()
 {
     $numbers = range(1, 49);
     shuffle($numbers);
     $numbers = array_slice($numbers, 0, 3);
     return ['a' => $numbers[0], 'b' => $numbers[1], 'c' => $numbers[2]];
 }
Example #21
0
 /**
  * Gets the featured members according to Phpfox::getParam('user.how_many_featured_members').
  * Uses cache to save a query (stores a cache if none found)
  * @return array( array of users, int total featured users )
  */
 public function get()
 {
     if ($sPlugin = Phpfox_Plugin::get('user.service_featured_get_1')) {
         eval($sPlugin);
         if (isset($mPluginReturn)) {
             return $mPluginReturn;
         }
     }
     $iTotal = Phpfox::getParam('user.how_many_featured_members');
     // the random will be done with php logic
     $sCacheId = $this->cache()->set('featured_users');
     if (!($aUsers = $this->cache()->get($sCacheId))) {
         $aUsers = $this->database()->select(Phpfox::getUserField() . ', uf.ordering')->from(Phpfox::getT('user'), 'u')->join($this->_sTable, 'uf', 'uf.user_id = u.user_id')->order('ordering DESC')->execute('getSlaveRows');
         if (Phpfox::getParam('user.cache_featured_users')) {
             $this->cache()->save($sCacheId, $aUsers);
         }
     }
     if (!is_array($aUsers)) {
         return array(array(), 0);
     }
     $aOut = array();
     if (Phpfox::getParam('user.randomize_featured_members')) {
         shuffle($aUsers);
     }
     $iCount = count($aUsers);
     // using count instead of $this->database()->limit to measure the real value
     for ($i = 0; $i <= $iTotal; $i++) {
         if (!isset($aUsers[$iCount - $i])) {
             continue;
         }
         // availability check
         $aOut[] = $aUsers[$iCount - $i];
     }
     return array($aOut, count($aUsers));
 }
Example #22
0
function spp_random_terms_func($atts)
{
    extract(shortcode_atts(array('count' => 10), $atts));
    global $spp_settings;
    global $wpdb;
    // SELECT * FROM myTable WHERE RAND()<(SELECT ((30/COUNT(*))*10) FROM myTable) ORDER BY RAND() LIMIT 30;
    $sql = "SELECT `term` FROM `" . $wpdb->prefix . "spp` WHERE RAND()<(SELECT ((" . $count . "/COUNT(`term`))*10) FROM `" . $wpdb->prefix . "spp`) ORDER BY RAND() LIMIT " . $count . ";";
    $searchterms = $wpdb->get_results($sql);
    if (!empty($searchterms) && count($searchterms) > 100) {
        $terms = array();
        foreach ($searchterms as $term) {
            $terms[] = $term->term;
        }
    } else {
        $file = @file_get_contents(SPP_PATH . '/keywords.txt');
        if ($file) {
            $terms = explode("\n", $file);
            shuffle($terms);
            $terms = array_slice($terms, 0, $count);
        } else {
            $terms = array();
        }
    }
    $result = new h2o(SPP_PATH . "/templates/widget.html");
    return $result->render(array('terms' => $terms, 'settings' => $spp_settings));
}
Example #23
0
 public function getSearch()
 {
     if ($this->_search === null) {
         $conns = array();
         if (!isset($this->_config['server.search'])) {
             $conns[] = 8384;
         } else {
             foreach (explode(';', $this->_config['server.search']) as $conn) {
                 $conn = trim($conn);
                 if ($conn !== '') {
                     $conns[] = $conn;
                 }
             }
         }
         if (count($conns) > 1) {
             shuffle($conns);
         }
         for ($i = 0; $i < count($conns); $i++) {
             try {
                 $this->_search = new XsSearch($conns[$i], $this);
                 $this->_search->setCharset($this->getDefaultCharset());
                 return $this->_search;
             } catch (XSException $e) {
                 if ($i + 1 === count($conns)) {
                     throw $e;
                 }
             }
         }
     }
     return $this->_search;
 }
Example #24
0
 /**
  * Spawns another worker, based on which need more.
  * @return void
  */
 private function _spawnWorker(&$children)
 {
     $count = array_count_values($children);
     $parent = getmypid();
     $candidates = array();
     // find a list of candidate workers
     foreach ($this->_workers as $id => $worker) {
         if (!isset($count[$id]) || $count[$id] < $worker->_spawn_config['processes']) {
             $candidates[] = $worker;
         }
     }
     // shuffle the candidates, take the first
     shuffle($candidates);
     $worker = array_pop($candidates);
     // fork the process
     if ($pid = $this->fork()) {
         //$this->_logger->debug(sprintf("spawned child #%d for worker %d",$pid,$worker->_spawn_id));
         $children[$pid] = $worker->_spawn_id;
         return;
     } else {
         $this->_worker = $worker;
         $this->_parent = $parent;
         $this->onFork(getmypid());
         $code = $this->_executeWorker($worker);
         $this->onTerminate($code);
         exit($code);
     }
 }
Example #25
0
 /**
  * AES encryption
  *
  * @param string $key
  * @param string $data		Content to be encrypted
  * @param bool $hex 	
  * @return string
  */
 static function salt()
 {
     $tmp = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
     shuffle($tmp);
     $salt = substr(implode('', $tmp), 0, 32);
     return $salt;
 }
 /**
  * @param string $gender
  */
 private function __generateNormalNameAction($gender = 'all')
 {
     $nation = empty($this->request->getPost("nation")) ? '' : $this->request->getPost("nation");
     // ๅง“ๅใƒ‡ใƒผใ‚ฟ็”Ÿๆˆ
     $model = new MasterNormalNames();
     $names = $model->findNormalNames(1, $nation, $gender);
     $this->view->setVar('normalNames', $names);
     // ๅ‡ฆ็†ใฎ้ƒฝๅˆไธŠใ“ใ“ใงๅ‡บ่‡ช(parent)ใฎใƒ‡ใƒผใ‚ฟ็”Ÿๆˆ
     $model2 = new MasterNations();
     $parent = array('father' => 'UNKNOWN', 'mother' => 'UNKNOWN');
     if ($nation != 'all') {
         $parentRecord = $model2->findFirst("nation_id = '{$nation}'");
         $parent = array('father' => $parentRecord->body_ja, 'mother' => $parentRecord->body_ja);
     } else {
         foreach ($names as $name) {
             // 0 or 1
             $hash = array(0, 1);
             $keys = array_rand($hash, 2);
             shuffle($keys);
             $fatherRecord = $model2->findFirst("nation_id = '" . $name['nation'][$keys[0]] . "'");
             $motherRecord = $model2->findFirst("nation_id = '" . $name['nation'][$keys[1]] . "'");
             $parent = array('father' => $fatherRecord->body_ja, 'mother' => $motherRecord->body_ja);
         }
     }
     $this->view->setVar('parent', $parent);
 }
 /**
  * Replace the default WordPress [gallery] shortcode with a slideshow
  *
  * @param array  $attrs
  * @param string $content
  */
 public function process_shortcode($params = array(), $content = null)
 {
     // Extract parameters and provide defaults for the missing ones
     extract(shortcode_atts(array('ids' => null, 'transition' => $this->plugin->get_option(BXSG_Settings::$OPTION_DEFAULT_TRANSITION), 'exclude_featured' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_EXCLUDE_FEATURED_IMAGE), 'hide_carousel' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_HIDE_CAROUSEL), 'adaptive_height' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_ADAPTIVE_HEIGHT), 'auto_start' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_AUTO_START), 'speed' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_SPEED), 'duration' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_DURATION), 'extra_options' => $this->plugin->get_option(BXSG_Settings::$OPTION_GS_EXTRA_OPTIONS), 'shuffle' => 0, 'size' => 'full', 'thumb_size' => 'thumbnail'), $params));
     // If no ids are provided, we will take every image attached to the current post.
     // Else, we'll simply fetch them from the DB
     $ids = $ids ? explode(',', $ids) : array();
     $attachments = $this->get_attached_medias($ids, $exclude_featured);
     if ($shuffle == 1) {
         shuffle($attachments);
     }
     // Compute an ID for this particular gallery
     $gallery_id = 'bx-gallery-' . $this->current_gallery_id;
     $this->current_gallery_id += 1;
     // Build the HTML output
     ob_start();
     include BXSG_INCLUDES_DIR . '/gallery-shortcode.view.php';
     $out = ob_get_contents();
     ob_end_clean();
     // We enqueue the script for inclusion in the WordPress footer
     ob_start();
     include BXSG_INCLUDES_DIR . '/gallery-shortcode.script.php';
     $this->scripts[] = ob_get_contents();
     ob_end_clean();
     return $out;
 }
Example #28
0
function dl_question_echo($question, $alternatives)
{
    $action = $_SERVER['PHP_SELF'] . '?action=' . $_GET['action'];
    $action .= isset($_GET['category']) ? '&category=' . $_GET['category'] : '';
    echo '<form action="' . $action . '" method="post" class="dl_answer_form" />' . "\n";
    if ($question['image'] == 1) {
        echo '<img src="http://images.hamsterpaj.net/drivers-license/question_illustrations/' . $question['id'] . '.jpg" class="image" />' . "\n";
    }
    echo '<p class="question">' . "\n";
    echo $question['question'] . "\n";
    echo '</p>' . "\n\n";
    echo '<ul class="alternatives">' . "\n";
    echo '<input type="hidden" name="question" value="' . $question['id'] . '" />' . "\n";
    shuffle($alternatives);
    foreach ($alternatives as $alternative) {
        echo '<li>' . "\n";
        echo '<input type="radio" name="answer" value="' . $alternative['id'] . '" id="dl_alt_' . $alternative['id'] . '" />' . "\n";
        echo '<label for="dl_alt_' . $alternative['id'] . '">' . $alternative['text'] . '</label>' . "\n";
        echo '</li>' . "\n\n";
    }
    echo '</ul>' . "\n\n";
    echo '<input type="submit" value="Skicka svar" />' . "\n";
    echo '</form>' . "\n";
    echo '<br style="clear: both;" />' . "\n";
}
 public function setAnswerOptions(array $options)
 {
     if ($this->shuffle) {
         shuffle($options);
     }
     $this->answerOptions = $options;
 }
Example #30
0
 /**
  * Method to output a tag-cloud formatted based on the weight of the tags
  *
  * @param array $tags Tag data array
  * @param array $options Display options. Valid keys are:
  * 	- shuffle: true to shuffle the tag list, false to display them in the same order than passed [default: true]
  *  - extract: Set::extract() compatible format string. Path to extract weight values from the $tags array [default: {n}.Tag.weight]
  *  - before: string to be displayed before each generated link. "%size%" will be replaced with tag size calculated from the weight [default: empty]
  *  - after: string to be displayed after each generated link. "%size%" will be replaced with tag size calculated from the weight [default: empty]
  *  - maxSize: size of the heaviest tag [default: 160]
  *  - minSize: size of the lightest tag [default: 80]
  *  - url: an array containing the default URL
  *  - named: the named parameter used to send the tag [default: by]
  *  - paramType: the type of URL parameters used (named or querystring) [default: named]
  * @return string
  */
 public function display($tags = null, $options = array())
 {
     if (empty($tags) || !is_array($tags)) {
         return '';
     }
     $defaults = array('tagModel' => 'Tag', 'shuffle' => true, 'extract' => '{n}.Tag.weight', 'before' => '', 'after' => '', 'maxSize' => 160, 'minSize' => 80, 'url' => array('controller' => 'search'), 'named' => 'by', 'paramType' => 'named');
     $options = array_merge($defaults, $options);
     $weights = Set::extract($tags, $options['extract']);
     $maxWeight = max($weights);
     $minWeight = min($weights);
     // find the range of values
     $spread = $maxWeight - $minWeight;
     if (0 == $spread) {
         $spread = 1;
     }
     if ($options['shuffle'] == true) {
         shuffle($tags);
     }
     $cloud = null;
     foreach ($tags as $tag) {
         $data = Set::extract(array($tag), $options['extract']);
         $tagWeight = array_pop($data);
         $size = $options['minSize'] + ($tagWeight - $minWeight) * (($options['maxSize'] - $options['minSize']) / $spread);
         $size = $tag[$options['tagModel']]['size'] = ceil($size);
         $cloud .= $this->_replace($options['before'], $size);
         $cloud .= $this->Html->link($tag[$options['tagModel']]['name'], $this->_tagUrl($tag, $options), array('id' => 'tag-' . $tag[$options['tagModel']]['id'])) . ' ';
         $cloud .= $this->_replace($options['after'], $size);
     }
     return $cloud;
 }