📄 autogenprofile.php
字号:
<?php/** * class pluginTemplate * * A template to get you started building templates. Rename all pluginTemplate * with the name of your plugin * * * */include_once(MODOSDATE_DIR . 'modPlugin.php');class autogenprofile extends modPlugin { /** * Holds the language phrases * * @access private */ var $lang; /** * Table with generated users * * @access private */ var $lang_autogenprofile_table = "autogenprofile_autogenprofile"; /** * Table with generated forms * * @access private */ var $lang_autogenprofile_forms_table = "autogenprofile_forms"; /** * The name name of the plugin class. * * @access private */ var $plugin_class_name = "autogenprofile"; /** * The text that appears in the admin plugin list * * @access private */ var $display_name; /** * The link text that appears on the user's menu * * @access private */ var $user_menu_text; /** * Appear on users menu (true or false) * * @access private */ var $user_menu_appear = false; /** * The link text that appears on the admin's menu * * @access private */ var $admin_menu_text ; /** * Appear on admin's menu (true or false) * * @access private */ var $admin_menu_appear = true; /** * Constructor * * @return * @access public */ function autogenprofile( ) { $this->modPlugin(); $pluginDir = dirname(__FILE__).'/../'; $this->lang = $this->modLoadLang($pluginDir); $this->admin_menu_text=$this->lang['user_title']; $this->display_name=$this->lang['user_title']; } // end of member method pluginClass /** * Does the processing to display a user page. Called from plugin.php * * @return array * @access public */ function displayPluginPage() { } /** * WARNING: USER IS NOT VALIDATED HERE. BE CAREFUL * Does the processing to display 100% plugin content. Called from pluginraw.php * * @return array * @access public */ function displayPluginContent() { } /** * Returns the content that will appear in the left column of a page. Designed to be overridden by plugins * * @return array * @access public */ function displayLeftCol() { } /** * Returns the content that will appear in the main content area of the page. This content will appear after the existing main content. Designed to be overridden by plugins * * @return array * @access public */ function displayMain() { } function getUserName($firstname,$lastname) { $len=(strlen($firstname)+strlen($lastname)+mt_rand(0,9999))%10; if($len==1) return substr(trim($firstname).trim($lastname),0,24); if($len==2) return substr(trim($firstname)."_".trim($lastname),0,24); if($len==3) return $firstname[0].trim($lastname); if($len==4) return trim($firstname).$lastname[0]; if($len==5) return trim(substr($firstname,0,mt_rand(1,strlen($firstname)))).trim(substr($lastname,0,mt_rand(1,strlen($lastname)))); if($len==6) return trim(substr($firstname,0,mt_rand(1,strlen($firstname)))).trim(substr($lastname,0,mt_rand(1,strlen($lastname)))).mt_rand(1,999); if($len==7) return $firstname[0].trim($lastname).mt_rand(1,999); if($len==8) return trim($firstname).$lastname[0].mt_rand(1,999); if($len==9) return trim($firstname)."_".trim(substr($lastname,0,mt_rand(1,strlen($lastname)))); if($len==0) return trim($firstname).$lastname[0].mt_rand(1,999); } /** * Does the processing to display a admin page. Called from plugin.php * * @return array * @access public */ function displayPluginAdminPage() { $this->modSmartyAssign('lang',$this->modGetLang()); $this->modSmartyAssign('plugin_name',$this->plugin_class_name); $file_male="male_firstnames.txt"; $file_female="female_firstnames.txt"; $file_firstname="lastnames.txt"; $countries=$this->modGetAllCountries(); foreach ($countries as $item => $key) { if($key['code']=="AA") unset($countries[$item]);/* Vijay Nair - Want to take cities only for selected countries for generating profiles. else { $cities=$this->modGetAllCities($key['code']); if($cities) $city[$key['code']]=$cities; }*/ } $path=PLUGIN_DIR.$this->plugin_class_name."/temp/";// $pathimages=TEMP_DIR."profile_images/"; $pathimages=$path."profile_images/"; /* Generation process starts */ if(isset($_POST['generate'])) {// @ini_set('time_limit','0'); //set_time_limit(0); //getting data from form $opt1=$_POST['opt1']; //number of profiles; $opt2=$_POST['opt2']; //percentage of males $opt3=$_POST['opt3']; //percentage of females $opt4=$_POST['opt4']; //number of countries $opt6=$_POST['opt6']; //percentage of age ranges $opt8=$_POST['opt8']; //percentage of white ethnicity $opt9=$_POST['opt9']; //percentage of black ethnicity $opt10=$_POST['opt10']; //percentage of asian ethnicity $opt11=$_POST['opt11']; //percentage of other ethnicity if ($opt2 == '' && $opt3 != '') { $opt2 = 100 - $opt3; } else if ( $opt3 == '' && $opt2 != '') { $opt3 = 100 - $opt2; } else if ($opt2 == '' && $opt3 == '') { $opt2 = $opt3 = 50; } $nrmales=(int)($opt1*$opt2/100); $nrfemales=($opt1-$nrmales); $etn['w']="0"; $etns[0]="10020"; $etn['b']="1"; $etns[1]="10019"; $etn['a']="2"; $etns[2]="10018"; $etn['m']="3"; $etns[3]="10027"; $ethnicity[0]['number']=(int)($opt1*$opt8/100); $ethnicity[1]['number']=(int)($opt1*$opt9/100); $ethnicity[2]['number']=(int)($opt1*$opt10/100); $ethnicity[3]['number']=(int)($opt1*$opt11/100); $ethnicity[0]['ethnicity']="10020"; $ethnicity[1]['ethnicity']="10019"; $ethnicity[2]['ethnicity']="10018"; $ethnicity[3]['ethnicity']="10027"; $sum=0; for($i=0;$i<4;$i++) { if(!$ethnicity[$i]['number']) unset($ethnicity[$i]); $sum+=$ethnicity[$i]['number']; } if($sum<$opt1) $ethnicity[4]['number']=$opt1-$sum; $forms['ethnicity']=$ethnicity; if(file_exists($pathimages)) { $handle = opendir($pathimages);$file = readdir($handle);$file = readdir($handle); while (false !== ($file = readdir($handle))) { $itemx=explode(".",$file); $item=$itemx[0]; $item=explode("_",$item); $img['file']=$file; $img['age']=$item[1]; $img['ethnicity']=$item[2]; $img['ext']=strtolower($itemx[1]); $images[strtoupper($item[0])][]=$img; } unset($images['THUMBS']); }/* Countries start */ $sum=0; $nocount = 0; for($i=1;$i<=$opt4;$i++) { $field1="opt5_$i"; $field2="opt5_{$i}c"; if (!isset($_POST[$field2])) { /* If country is not selected, take random country */ $rx = mt_rand(0,count($countries)-1); $_POST[$field2] = $rx; } if ($_POST[$field1] != '') { $country[$i-1]['number']=(int)($opt1*$_POST[$field1]/100); } else { $country[$i-1]['number']=0; $nocount++; } $country[$i-1]['country']=$countries[$_POST[$field2]]['name']; $country[$i-1]['code']=$countries[$_POST[$field2]]['code']; $sum+=$country[$i-1]['number']; } if($sum<$opt1 && $nocount == 0) $country[0]['number']=$opt1-$sum; if ($nocount > 0) { /* There are countries records without any percentage allocated. Let us allocate balance numbers equally to these countries. */ $cnt = $opt1 - $sum; $cnt1 = 0; for ($i=0;$i<$opt4;$i++) { if ($country[$i]['number']==0) { $country[$i]['number'] = (int)($cnt / $nocount); $cnt1 += $country[$i]['number']; } } if ($cnt1 < $cnt) { $country[0]['number']+=$cnt-$cnt1; } } $forms['country']=$country;/* Countries end */ $sum=0; $nocount = 0; if ($opt6 == '') { $age[0]['min']=16; $age[0]['max']=90; $age[0]['number']=$opt1; } else { for($i=1;$i<=$opt6;$i++) { $field1="opt7_{$i}a"; $field2="opt7_{$i}b"; $field3="opt7_{$i}c"; if ($_POST[$field1] != '') { $age[$i-1]['number']=(int)($opt1*$_POST[$field1]/100); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -