예제 #1
0
function insert($callnumber, $essay)
{
    $words = array();
    $MAX_LENGTH = 4;
    while (mb_strlen($essay, 'utf-8') > 1) {
        $len = $MAX_LENGTH;
        if (mb_strlen($essay, 'utf-8') < $len) {
            $len = mb_strlen($essay, 'utf-8');
        }
        //取指定的最大长度的文本去词典里面匹配
        $matchword = mb_substr($essay, mb_strlen($essay, 'utf-8') - $len, mb_strlen($essay, 'utf-8') - 1, 'utf-8');
        while (!contain($matchword)) {
            //如果长度为一且在词典中未找到匹配,则按长度为一切分
            if (mb_strlen($matchword, 'utf-8') == 1) {
                break;
            }
            //如果匹配不到,则长度减一继续匹配
            $matchword = mb_substr($matchword, 1, mb_strlen($matchword, 'utf-8') - 1, 'utf-8');
        }
        array_push($words, $matchword);
        //从待分词文本中去除已经分词的文本
        //echo $matchword;
        //echo mb_strlen($matchword,'utf-8');
        $essay = mb_substr($essay, 0, mb_strlen($essay, 'utf-8') - mb_strlen($matchword, 'utf-8'), 'utf-8');
        //echo $essay;
    }
    //echo $words;
    $con = ConnectDatabase("library");
    for ($i = 0; $i < count($words); $i++) {
        //把切词结果和索书号一起存进索引里
        $sql = "INSERT INTO `index`(`callnumber`, `word`) VALUES ('{$callnumber}','{$words[$i]}');";
        mysqli_query($con, $sql);
        //if(mysqli_query($con,$sql)){echo "New record inserted successfully ";}
    }
    CloseDatabase($con);
}
예제 #2
0
파일: Duproprio.php 프로젝트: schpill/thin
 private function tag($start, $end, $segment)
 {
     if (contain($start, $segment) && contain($end, $segment)) {
         return Utils::cut($start, $end, $segment);
     }
     return null;
 }
예제 #3
0
     $sql = "SELECT  count(*) FROM `book-information` WHERE firstauthor like '%{$author}%' or otherauthor like '%{$author}%';";
 } else {
     if ($title != null and $title != "题目检索") {
         $sql = "SELECT  count(*) FROM `book-information` WHERE name like '%{$title}%';";
     } else {
         $MAX_LENGTH = 4;
         //echo $pages;
         while (mb_strlen($pages, 'utf-8') > 1) {
             $len = $MAX_LENGTH;
             if (mb_strlen($pages, 'utf-8') < $len) {
                 $len = mb_strlen($pages, 'utf-8');
             }
             //取指定的最大长度的文本去词典里面匹配
             $matchword = mb_substr($pages, mb_strlen($pages, 'utf-8') - $len, mb_strlen($pages, 'utf-8'), 'utf-8');
             //echo $matchword;
             while (!contain($matchword, $con)) {
                 //如果长度为一且在词典中未找到匹配,则按长度为一切分
                 if (mb_strlen($matchword, 'utf-8') == 1) {
                     break;
                 }
                 //如果匹配不到,则长度减一继续匹配
                 $matchword = mb_substr($matchword, 1, mb_strlen($matchword, 'utf-8') - 1, 'utf-8');
             }
             array_push($words, $matchword);
             //从待分词文本中去除已经分词的文本
             $pages = mb_substr($pages, 0, mb_strlen($pages, 'utf-8') - mb_strlen($matchword, 'utf-8'), 'utf-8');
         }
         $sql = "select count(*) from `book-information` where callnumber in (";
         for ($x = 0; $x < count($words) - 1; $x++) {
             $sql = $sql . "select callnumber from `index` where word='{$words[$x]}' and callnumber in(";
         }
예제 #4
0
파일: Helper.php 프로젝트: noikiy/inovi
 function parseLanguage($file)
 {
     $tab = array();
     $cnt = fgc($file);
     $sentences = explode('@@@', $cnt);
     $key = null;
     if (count($sentences)) {
         foreach ($sentences as $sentence) {
             $sentence = trim($sentence);
             $rows = explode("\n", $sentence);
             if (count($rows)) {
                 foreach ($rows as $row) {
                     $row = trim($row);
                     if (!contain('[:', $row)) {
                         $key = $row;
                     } else {
                         $lng = Utils::cut('[:', ':]', $row);
                         $translation = str_replace("[:{$lng}:]", '', $row);
                         if (!Arrays::exists(Inflector::lower($lng), $tab)) {
                             $tab[Inflector::lower($lng)] = array();
                         }
                         $tab[Inflector::lower($lng)][sha1($key)] = $translation;
                     }
                 }
             }
         }
     }
     foreach ($tab as $lng => $sentences) {
         $setter = setter($lng);
         languages()->{$setter}($sentences);
     }
 }
예제 #5
0
 public function row(array $data, $recursive = true, $extends = array())
 {
     if (Arrays::isAssoc($data)) {
         $obj = o(sha1(serialize($data)));
         $obj->db_instance = $this;
         if (count($extends)) {
             foreach ($extends as $name => $instance) {
                 $closure = function ($object) use($name, $instance) {
                     $idx = $object->is_thin_object;
                     $objects = Utils::get('thinObjects');
                     return $instance->{$name}($objects[$idx]);
                 };
                 $obj->_closures[$name] = $closure;
             }
         }
         $fields = $this->fields();
         foreach ($fields as $field) {
             $hasFk = $this->hasFk($field);
             if (false === $hasFk) {
                 $obj->{$field} = $data[$field];
             } else {
                 extract($hasFk);
                 $ar = ar($foreignEntity, $foreignTable);
                 $one = contain('toone', Inflector::lower($type));
                 if ($one && $recursive) {
                     $foreignObj = $ar->findBy($foreignKey, $data[$field], $one);
                     $obj->{$relationKey} = $foreignObj;
                 }
             }
         }
         $hasFk = ake('relationships', $this->_settings);
         if (true === $hasFk && $recursive) {
             $rs = $this->_settings['relationships'];
             if (count($rs)) {
                 foreach ($rs as $field => $infos) {
                     extract($infos);
                     $ar = ar($foreignEntity, $foreignTable);
                     if (!Arrays::in($field, $fields)) {
                         $pk = $this->pk();
                         $obj->{$field} = $ar->findBy($foreignKey, $obj->{$pk}, false, false);
                     }
                 }
             }
         }
         return $obj;
     }
     return null;
 }
예제 #6
0
파일: Paypal.php 프로젝트: schpill/thin
 public static function execPayment(array $args)
 {
     extract($args);
     // $token = static::getToken(array('environment' => 'development', 'clientId' => 'AR1gYxBYuhVXGHInUsHgSXTZ_OBWj9AsGNPg--92OPZqLsD089GsFfeb8CHB', 'clientSecret' => 'EDh0XRCYD34dDH-n3ad6n-AzYOm3Ko_6AlcwUhMGrJG_5r9lMoKXqBR5hl-7'));
     // $token = static::getToken($args);
     $data = '{ "payer_id" : "' . $PayerID . '" }';
     $curl = curl_init($execute);
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . static::getToken($clientId, $clientSecret, $environment), 'Accept: application/json', 'Content-Type: application/json'));
     $page = curl_exec($curl);
     return contain('approved', $page) || contain('pending', $page) ? true : false;
 }
예제 #7
0
파일: Cms.php 프로젝트: schpill/thin
 public static function fixtures()
 {
     $adminTables = Data::getAll('admintable');
     $adminUsers = Data::getAll('adminuser');
     $adminactions = Data::getAll('adminaction');
     $adminRights = Data::getAll('adminright');
     $adminTaskStatus = Data::getAll('admintaskstatus');
     $adminTaskType = Data::getAll('admintasktype');
     $adminTaskTypes = Data::getAll('admintasktype');
     $adminCountries = Data::getAll('admincountry');
     $options = Data::getAll('option');
     $bools = Data::getAll('bool');
     $formTypes = Data::getAll('adminformfieldtype');
     if (!count($bools)) {
         $bool1 = array('name' => 'Oui', 'value' => 'true');
         $bool2 = array('name' => 'Non', 'value' => 'false');
         Data::add('bool', $bool1);
         Data::getAll('bool');
         Data::add('bool', $bool2);
         Data::getAll('bool');
     }
     if (!count($formTypes)) {
         $typesToAdd = array();
         $typesToAdd[] = array('name' => 'Classique', 'value' => 'text');
         $typesToAdd[] = array('name' => 'Texte', 'value' => 'textarea');
         $typesToAdd[] = array('name' => 'Date', 'value' => 'date');
         $typesToAdd[] = array('name' => 'Courriel', 'value' => 'email');
         $typesToAdd[] = array('name' => 'Sélection', 'value' => 'select');
         $typesToAdd[] = array('name' => 'Téléphone', 'value' => 'telephone');
         $typesToAdd[] = array('name' => 'Caché', 'value' => 'hidden');
         $typesToAdd[] = array('name' => 'Url', 'value' => 'url');
         foreach ($typesToAdd as $typeToAdd) {
             Data::add('adminformfieldtype', $typeToAdd);
             Data::getAll('adminformfieldtype');
         }
     }
     if (!count($adminCountries)) {
         $list = fgc("http://web.gpweb.co/u/45880241/cdn/pays.csv");
         $rows = explode("\n", $list);
         foreach ($rows as $row) {
             $row = repl('"', '', trim($row));
             if (contain(';', $row)) {
                 list($id, $name, $upp, $low, $code) = explode(';', $row, 5);
                 $country = array('name' => $name, 'code' => $code);
                 Data::add('admincountry', $country);
                 Data::getAll('admincountry');
             }
         }
     }
     if (!count($adminTaskTypes)) {
         $types = array('Bogue', 'Snippet', 'SEO', 'Traduction', 'Graphisme', 'Contenu', 'Html', 'Css', 'Javascript');
         foreach ($types as $type) {
             $taskType = array('name' => $type);
             Data::add('admintasktype', $taskType);
             Data::getAll('admintasktype');
         }
     }
     if (!count($adminTaskStatus)) {
         $allStatus = array(1 => 'Attribuée', 4 => 'Terminée', 2 => 'En cours', 7 => 'En suspens', 6 => 'En attente d\'information', 3 => 'En test', 5 => 'Réattribuée', 8 => 'Annulée');
         foreach ($allStatus as $priority => $status) {
             $taskStatus = array('name' => $status, 'priority' => $priority);
             Data::add('admintaskstatus', $taskStatus);
             Data::getAll('admintaskstatus');
         }
     }
     if (!count($adminTables)) {
         $entities = container()->getEntities();
         if (count($entities)) {
             foreach ($entities as $entity) {
                 $table = array('name' => $entity);
                 Data::add('admintable', $table);
                 Data::getAll('admintable');
             }
         }
     }
     if (!count($adminactions)) {
         $actions = array('list', 'add', 'duplicate', 'view', 'delete', 'edit', 'import', 'export', 'search', 'empty_cache');
         foreach ($actions as $action) {
             $newAction = array('name' => $action);
             Data::add('adminaction', $newAction);
             Data::getAll('adminaction');
         }
     }
     if (!count($adminUsers)) {
         $user = array('name' => 'Admin', 'firstname' => 'Dear', 'login' => 'admin', 'password' => 'admin', 'email' => '*****@*****.**');
         Data::add('adminuser', $user);
         Data::getAll('adminuser');
     }
     if (!count($adminRights)) {
         $sql = dm('adminuser');
         $res = $sql->where('email = admin@admin.com')->get();
         $user = $sql->first($res);
         $tables = Data::getAll('admintable');
         $actions = Data::getAll('adminaction');
         if (count($tables)) {
             foreach ($tables as $table) {
                 $table = Data::getIt('admintable', $table);
                 foreach ($actions as $action) {
                     $action = Data::getIt('adminaction', $action);
                     $right = array('adminuser' => $user->getId(), 'admintable' => $table->getId(), 'adminaction' => $action->getId());
                     Data::add('adminright', $right);
                     Data::getAll('adminright');
                 }
             }
         }
     }
     if (!count($options)) {
         $optionsToAdd = array();
         $optionsToAdd[] = array('name' => 'default_language', 'value' => 'fr');
         $optionsToAdd[] = array('name' => 'lng_fr_display', 'value' => 'flag');
         $optionsToAdd[] = array('name' => 'page_languages', 'value' => 'fr');
         $optionsToAdd[] = array('name' => 'theme', 'value' => SITE_NAME);
         $optionsToAdd[] = array('name' => 'menu_fixed', 'value' => 'true');
         $optionsToAdd[] = array('name' => 'show_menu', 'value' => 'true');
         $optionsToAdd[] = array('name' => 'logo_max_width', 'value' => 400);
         $optionsToAdd[] = array('name' => 'menu_background_color', 'value' => '#eee');
         $optionsToAdd[] = array('name' => 'menu_link_background_color', 'value' => '#444');
         $optionsToAdd[] = array('name' => 'menu_link_color', 'value' => '#fff');
         $optionsToAdd[] = array('name' => 'page_background', 'value' => '#e2e2e2');
         $optionsToAdd[] = array('name' => 'page_color', 'value' => '#333');
         $optionsToAdd[] = array('name' => 'show_logo', 'value' => 'true');
         $optionsToAdd[] = array('name' => 'site_font_family', 'value' => 'Oswald');
         $optionsToAdd[] = array('name' => 'site_font_size', 'value' => '14px');
         $optionsToAdd[] = array('name' => 'slideshow_background', 'value' => '#222');
         $optionsToAdd[] = array('name' => 'slideshow_height', 'value' => '500px');
         $optionsToAdd[] = array('name' => 'slideshow_text_color', 'value' => '#fff');
         $optionsToAdd[] = array('name' => 'title_font_family', 'value' => 'Passion One');
         $optionsToAdd[] = array('name' => 'company_name', 'value' => 'My website');
         $optionsToAdd[] = array('name' => 'google_fonts', 'value' => 'Ubuntu,Oswald,Passion One');
         $optionsToAdd[] = array('name' => 'map_marker_name', 'value' => 'My website');
         $optionsToAdd[] = array('name' => 'map_text', 'value' => 'Bienvenue!');
         $optionsToAdd[] = array('name' => 'custom_css', 'value' => ' ');
         $optionsToAdd[] = array('name' => 'latitude', 'value' => 48);
         $optionsToAdd[] = array('name' => 'longitude', 'value' => -71);
         $optionsToAdd[] = array('name' => 'contact_email', 'value' => '*****@*****.**');
         $optionsToAdd[] = array('name' => 'form_email', 'value' => '*****@*****.**');
         foreach ($optionsToAdd as $optionToAdd) {
             Data::add('option', $optionToAdd);
             Data::getAll('option');
         }
         $status1 = array('name' => 'online');
         $status2 = array('name' => 'offline');
         $status3 = array('name' => 'maintenance');
         Data::add('statuspage', $status1);
         Data::getAll('statuspage');
         Data::add('statuspage', $status2);
         Data::getAll('statuspage');
         Data::add('statuspage', $status3);
         Data::getAll('statuspage');
         $sql = dm('statuspage');
         $res = $sql->where('name = online')->get();
         $status = $sql->first($res);
         $page = array('name' => 'Accueil', 'url' => array('fr' => 'home'), 'template' => 'home', 'parent' => null, 'statuspage' => $status->getId(), 'date_out' => null, 'hierarchy' => 1, 'is_home' => getBool('true')->getId());
         Data::add('page', $page);
         Data::getAll('page');
     }
 }
예제 #8
0
/**
 * @param $item
 * @return \Closure
 */
function notContain($item)
{
    return negate(contain($item));
}
예제 #9
0
파일: Data.php 프로젝트: schpill/thin
 public static function analyze($comp, $op, $value)
 {
     if (isset($comp)) {
         $comp = Inflector::lower($comp);
         $value = Inflector::lower($value);
         switch ($op) {
             case '=':
                 return $comp == $value;
             case '>=':
                 return $comp >= $value;
             case '>':
                 return $comp > $value;
             case '<':
                 return $comp < $value;
             case '<=':
                 return $comp <= $value;
             case '<>':
             case '!=':
                 return $comp != $value;
             case 'LIKE':
                 $value = repl("'", '', $value);
                 $value = repl('%', '', $value);
                 return contain($value, $comp);
             case 'NOTLIKE':
                 $value = repl("'", '', $value);
                 $value = repl('%', '', $value);
                 return !contain($value, $comp);
             case 'LIKESTART':
                 $value = repl("'", '', $value);
                 $value = repl('%', '', $value);
                 return substr($comp, 0, strlen($value)) === $value;
             case 'LIKEEND':
                 $value = repl("'", '', $value);
                 $value = repl('%', '', $value);
                 if (!strlen($comp)) {
                     return true;
                 }
                 return substr($comp, -strlen($value)) === $value;
             case 'IN':
                 $value = repl('(', '', $value);
                 $value = repl(')', '', $value);
                 $tabValues = explode(',', $value);
                 return Arrays::in($comp, $tabValues);
             case 'NOTIN':
                 $value = repl('(', '', $value);
                 $value = repl(')', '', $value);
                 $tabValues = explode(',', $value);
                 return !Arrays::in($comp, $tabValues);
         }
     }
     return false;
 }