当前位置: 首页>>代码示例>>PHP>>正文


PHP Toolbox::getRandomString方法代码示例

本文整理汇总了PHP中Toolbox::getRandomString方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::getRandomString方法的具体用法?PHP Toolbox::getRandomString怎么用?PHP Toolbox::getRandomString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Toolbox的用法示例。


在下文中一共展示了Toolbox::getRandomString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testGetRandomString

 /**
  * @covers Toolbox::getRandomString
  */
 public function testGetRandomString()
 {
     for ($len = 20; $len < 50; $len += 5) {
         // Low strength
         $str = Toolbox::getRandomString($len);
         $this->assertEquals($len, strlen($str));
         $this->assertTrue(ctype_alnum($str));
         // High strength
         $str = Toolbox::getRandomString($len, true);
         $this->assertEquals($len, strlen($str));
         $this->assertTrue(ctype_alnum($str));
     }
 }
开发者ID:glpi-project,项目名称:glpi,代码行数:16,代码来源:ToolboxTest.php

示例2: getUniquePersonalToken

 /**
  * Get personal token checking that it is unique
  *
  * @return string personal token
  **/
 static function getUniquePersonalToken()
 {
     global $DB;
     $ok = false;
     do {
         $key = Toolbox::getRandomString(40);
         $query = "SELECT COUNT(*)\n                    FROM `glpi_users`\n                    WHERE `personal_token` = '{$key}'";
         $result = $DB->query($query);
         if ($DB->result($result, 0, 0) == 0) {
             return $key;
         }
     } while (!$ok);
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:18,代码来源:user.class.php

示例3: redirectToLogin

 /**
  * Redirection to Login page
  *
  * @param $params       param to add to URL (default '')
  * @since version 0.85
  *
  * @return nothing
  **/
 static function redirectToLogin($params = '')
 {
     global $CFG_GLPI;
     $dest = $CFG_GLPI["root_doc"] . "/index.php";
     $url_dest = str_replace($CFG_GLPI["root_doc"], '', $_SERVER['REQUEST_URI']);
     $dest .= "?redirect=" . rawurlencode($url_dest);
     if (!empty($params)) {
         $dest .= '&' . $params;
     }
     $toadd = '';
     if (!strpos($dest, "?")) {
         $toadd = '&tokonq=' . Toolbox::getRandomString(5);
     }
     echo "<script language=javascript>\n            NomNav = navigator.appName;\n            if (NomNav=='Konqueror') {\n               window.location='" . $dest . $toadd . "';\n            } else {\n               window.location='" . $dest . "';\n            }\n         </script>";
     exit;
 }
开发者ID:OlivierLM,项目名称:glpi,代码行数:24,代码来源:html.class.php

示例4: getUniqueAppToken

 /**
  * Get app token checking that it is unique
  *
  * @return string app token
  **/
 static function getUniqueAppToken()
 {
     global $DB;
     $ok = false;
     do {
         $key = Toolbox::getRandomString(40);
         if (countElementsInTable(self::getTable(), ['app_token' => $key]) == 0) {
             return $key;
         }
     } while (!$ok);
 }
开发者ID:btry,项目名称:glpi,代码行数:16,代码来源:apiclient.class.php

示例5: replace

 /**
  * @param $type
  * @param $model_id
  * @param $tab_ids
  * @param $location
  **/
 static function replace($type, $model_id, $tab_ids, $location)
 {
     global $DB, $CFG_GLPI, $PLUGIN_HOOKS;
     $model = new PluginUninstallModel();
     $model->getConfig($model_id);
     $overwrite = $model->fields["overwrite"];
     echo "<div class='center'>";
     echo "<table class='tab_cadre_fixe'><tr><th>" . __('Replacement', 'uninstall') . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>";
     $count = 0;
     $tot = count($tab_ids);
     Html::createProgressBar(__('Please wait, replacement is running...', 'uninstall'));
     foreach ($tab_ids as $olditem_id => $newitem_id) {
         $count++;
         $olditem = new $type();
         $olditem->getFromDB($olditem_id);
         $newitem = new $type();
         $newitem->getFromDB($newitem_id);
         //Hook to perform actions before item is being replaced
         $olditem->fields['_newid'] = $newitem_id;
         $olditem->fields['_uninstall_event'] = $model_id;
         $olditem->fields['_action'] = 'replace';
         Plugin::doHook("plugin_uninstall_replace_before", $olditem);
         // Retrieve informations
         //States
         if ($model->fields['states_id'] != 0) {
             $olditem->update(array('id' => $olditem_id, 'states_id' => $model->fields['states_id']), false);
         }
         // METHOD REPLACEMENT 1 : Archive
         if ($model->fields['replace_method'] == self::METHOD_PURGE) {
             $name_out = str_shuffle(Toolbox::getRandomString(5) . time());
             $plugin = new Plugin();
             if ($plugin->isActivated('PDF')) {
                 // USE PDF EXPORT
                 $plugin->load('pdf', true);
                 include_once GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php";
                 //Get all item's tabs
                 $tab = array_keys($olditem->defineTabs());
                 //Tell PDF to also export item's main tab, and in first position
                 array_unshift($tab, "_main_");
                 $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($olditem);
                 $out = $itempdf->generatePDF(array($olditem_id), $tab, 1, false);
                 $name_out .= ".pdf";
             } else {
                 //TODO Which datas ? Add Defaults...
                 $out = __('Replacement', 'uninstall') . "\r\n";
                 $datas = $olditem->fields;
                 unset($datas['comment']);
                 foreach ($datas as $k => $v) {
                     $out .= $k . ";";
                 }
                 $out .= "\r\n";
                 foreach ($datas as $k => $v) {
                     $out .= $v . ";";
                 }
                 // USE CSV EXPORT
                 $name_out .= ".csv";
             }
             // Write document
             $out_file = GLPI_DOC_DIR . "/_uploads/" . $name_out;
             $open_file = fopen($out_file, 'a');
             fwrite($open_file, $out);
             fclose($open_file);
             // Compute comment text
             $comment = __('This document is the archive of this replaced item', 'uninstall') . " " . self::getCommentsForReplacement($olditem, false, false);
             // Create & Attach new document to current item
             $doc = new Document();
             $input = array('name' => addslashes(__('Archive of old material', 'uninstall')), 'upload_file' => $name_out, 'comment' => addslashes($comment), 'add' => __('Add'), 'entities_id' => $newitem->getEntityID(), 'is_recursive' => $newitem->isRecursive(), 'link' => "", 'documentcategories_id' => 0, 'items_id' => $olditem_id, 'itemtype' => $type);
             //Attached the document to the old item, to generate an accurate name
             $document_added = $doc->add($input);
             //Attach the document to the new item, once the document's name is correct
             $docItem = new Document_Item();
             $docItemId = $docItem->add(array('documents_id' => $document_added, 'itemtype' => $type, 'items_id' => (int) $newitem_id));
         }
         // General Informations - NAME
         if ($model->fields["replace_name"]) {
             if ($overwrite || empty($newitem->fields['name'])) {
                 $newitem->update(array('id' => $newitem_id, 'name' => $olditem->getField('name')), false);
             }
         }
         $data['id'] = $newitem->getID();
         // General Informations - SERIAL
         if ($model->fields["replace_serial"]) {
             if ($overwrite || empty($newitem->fields['serial'])) {
                 $newitem->update(array('id' => $newitem_id, 'serial' => $olditem->getField('serial')), false);
             }
         }
         // General Informations - OTHERSERIAL
         if ($model->fields["replace_otherserial"]) {
             if ($overwrite || empty($newitem->fields['otherserial'])) {
                 $newitem->update(array('id' => $newitem_id, 'otherserial' => $olditem->getField('otherserial')), false);
             }
         }
         // Documents
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:uninstall,代码行数:101,代码来源:replace.class.php

示例6: generate_entity


//.........这里部分代码省略.........
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1)));
   }
   $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes");


   $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1;
   $nb_items                   = mt_rand(0,$MAX['solutiontemplates']);
   $st                         = new SolutionTemplate();
   for ($i=0 ; $i<$nb_items ; $i++) {
      $st-> add(toolbox::addslashes_deep(
                array('entities_id'        => $ID_entity,
                      'is_recursive'       => 1,
                      'name'               => "solution' $i-$ID_entity",
                      'content'            => "content solution' $i-$ID_entity",
                      'solutiontypes_id'   => mt_rand(0,$MAX['solutiontypes']),
                      'comment'            => "comment solution' $i-$ID_entity")));
   }

   $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates");

   // Add Specific questions
   $k                = 0;
   $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1;
   $ki               = new KnowbaseItem();
   $eki              = new Entity_KnowbaseItem();
   for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) {
      $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT);
      for ($j=0 ; $j<$nb ; $j++) {
         $k++;
         $newID = $ki->add(toolbox::addslashes_deep(
                           array('knowbaseitemcategories_id'   => $i,
                                 'name'      => "Entity' $ID_entity Question $k",
                                 'answer'    => "Answer' $k".Toolbox::getRandomString(50),
                                 'is_faq'    => mt_rand(0,1),
                                 'users_id'  => mt_rand($FIRST['users_sadmin'],
                                                        $LAST['users_admin']))));

         $eki->add(array('entities_id'       => $ID_entity,
                        'knowbaseitems_id'   => $newID,
                        'is_recursive'       => 0));
      }
   }


   // Add global questions
   for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) {
      $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT);
      for ($j=0 ; $j<$nb ; $j++) {
         $k++;
         $newID = $ki->add(toolbox::addslashes_deep(
                           array('knowbaseitemcategories_id'   => $i,
                                 'name'      => "Entity' $ID_entity Recursive Question $k",
                                 'answer'    => "Answer' $k".Toolbox::getRandomString(50),
                                 'is_faq'    => mt_rand(0,1),
                                 'users_id'  => mt_rand($FIRST['users_sadmin'],
                                                        $LAST['users_admin']))));

         $eki->add(array('entities_id'       => $ID_entity,
                        'knowbaseitems_id'   => $newID,
                        'is_recursive'       => 1));
      }
   }

   $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems");
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:66,代码来源:generate_bigdump.function.php

示例7: redirect

 /**
  * Redirection hack
  *
  * @param $dest string: Redirection destination
  *
  * @return nothing
  **/
 static function redirect($dest)
 {
     $toadd = '';
     if (!strpos($dest, "?")) {
         $toadd = '?tokonq=' . Toolbox::getRandomString(5);
     }
     echo "<script language=javascript>\n            NomNav = navigator.appName;\n            if (NomNav=='Konqueror') {\n               window.location='" . $dest . $toadd . "';\n            } else {\n               window.location='" . $dest . "';\n            }\n         </script>";
     exit;
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:16,代码来源:html.class.php

示例8: getUniqueAppToken

 /**
  * Get app token checking that it is unique
  *
  * @return string app token
  **/
 static function getUniqueAppToken()
 {
     global $DB;
     $ok = false;
     do {
         $key = Toolbox::getRandomString(40);
         $query = "SELECT COUNT(*)\n                    FROM `" . self::getTable() . "`\n                    WHERE `app_token` = '{$key}'";
         $result = $DB->query($query);
         if ($DB->result($result, 0, 0) == 0) {
             return $key;
         }
     } while (!$ok);
 }
开发者ID:stweil,项目名称:glpi,代码行数:18,代码来源:apiclient.class.php

示例9: testGetRandomString

 /**
  * @covers Toolbox::getRandomString
  */
 public function testGetRandomString()
 {
     for ($len = 20; $len < 50; $len += 5) {
         $this->assertEquals($len, strlen(Toolbox::getRandomString($len)));
     }
 }
开发者ID:btry,项目名称:glpi,代码行数:9,代码来源:ToolboxTest.php


注:本文中的Toolbox::getRandomString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。