コード例 #1
0
function yahoo_mecab($data, $hinshi, $url)
{
    $apikey = 'dj0zaiZpPUpZVzNaZ3oxeExXMSZzPWNvbnN1bWVyc2VjcmV0Jng9Yjc-';
    //yahooAPIキー
    //$query = "冬の京都も美しい。";
    $query = urlencode($data);
    //urlの標準コード(utf8)に変換
    $res = "surface,reading,pos,feature";
    //レスポンスで返信される形態素情報
    $q_url = 'http://jlp.yahooapis.jp/MAService/V1/parse?appid=' . $apikey . '&response=' . $res . '&sentence=' . $query;
    //レスポンスで返信される形態素情報を指定したurl:「?」以下は、リクエストパラメータ
    $rss = file_get_contents($q_url);
    //リクエスト送信&レスポンス取得
    $xml = simplexml_load_string($rss);
    //取得したXMLを解析
    $a = $hinshi;
    foreach ($xml->ma_result->word_list->word as $item) {
        if (ereg($a, $item->feature) == 1) {
            //名詞なら、情報を出力
            $contents = $item->surface;
            insert_sql('list', $url, $contents);
            //echo $item->surface."|".$item->feature;
            //echo "<br>";
            $tango[] = "{$contents}";
            //単語を単語リストに格納
        }
    }
    return $tango;
    //単語リストを返す
}
コード例 #2
0
ファイル: db.fn.php プロジェクト: boxcore/xspider
/**
 * 快捷插入数据
 * @param $table
 * @param $data
 */
function insert($table, $data, $db = NULL)
{
    is_null($db) && ($db = db());
    run_sql(insert_sql($table, $data, $db), $db);
    return mysql_insert_id($db);
}
コード例 #3
0
ファイル: FSLog.php プロジェクト: jleexp/Code_Snippets
function fslSaveFile($HMd5,$fl){
  global $conn,$FslBodyFolder,$MIRROR;
  if (!isset($MIRROR[this]) )
    $MIRROR[this]=0;
  $rv=false;
  if ( fslIsFileExists($HMd5)===false ) {
    $dt=date("Y-m-d");
    if ( fslIsRepository($dt)===false ) {
      fslNewRepository($dt);
    }
    $dir=fslDateToPath($dt);
    $full_dir=$FslBodyFolder.$dir.substr($HMd5,0,1)."/";
    unset($dir);
    if ( !is_dir($full_dir) ) {
      @mkdir($full_dir);
	  @chown($full_dir,"www");
      @chgrp($full_dir,"www");
    }
    $fn=$HMd5;
    $full_path=$full_dir.$fn;
    @rename($fl,$full_path);
    if ( is_file($full_path) ) {
      @chown($full_path,"www");
      @chgrp($full_path,"www");
      $fds=array("PT","HMd5","MirrorIdx","FileSize","FilePath");
      $val=array(substr($HMd5,0,1),$HMd5,$MIRROR[this],filesize($full_path),$full_path);
      insert_sql("FileBody",$fds,$val);
      $rv=$full_path;
    }
  }
  return $rv;
}
コード例 #4
0
 public function syncToDatabase()
 {
     $salt = getNewSalt();
     $encryptedPassword = encryptWithSalt($this->data['password'], $salt);
     $guid = $this->user->guid;
     insert_sql("DELETE FROM ra_mail WHERE url = ?", 's', array($this->data['code']));
     $input = insert_sql("UPDATE user SET password=?, salt=? WHERE guid=? ", 'sss', array($encryptedPassword, $salt, $guid));
     if ($input) {
         $this->state = STATE_SUCCESS;
         $this->message = "Wachtwoord met succes veranderd.";
     } else {
         $this->message = "Kon het wachtwoord niet opslaan.";
     }
 }
コード例 #5
0
/**
 * Generate a unique guid
 * 
 * @param int $length length of guid
 * @return string generated guid
 */
function getGUID($length = 8)
{
    $str = generateRandomString($length);
    $r = select_sql('SELECT * FROM allguids WHERE guid = ?', 's', $str);
    if ($r == array()) {
        insert_sql("INSERT INTO allguids(guid) VALUES(?)", 's', array($str));
        return $str;
    } else {
        return getGUID($length);
    }
}
コード例 #6
0
ファイル: xml_import.php プロジェクト: agundran/addige
function process_state( $ps_state )
////////////////////////////////////////////
//
// A basic state machine.
//
// Given the $ps_state value passed, perform
// the action dictated by that state.
//
////////////////////////////////////////////
{
GLOBAL $argv;
GLOBAL $msg_log;
GLOBAL $db_host, $db_user, $db_pwd, $db_name;
GLOBAL $DEBUG;

	$done = FALSE;

// $cont_key is an integer 1 .. N of the contract number 
// we'll display.  It indexes the arrays $headers and $details

	$cont_key  = isset( $_SESSION[ 'cont_key'  ] ) ? $_SESSION[ 'cont_key'  ] : NULL;
	$campaigns = isset( $_SESSION[ 'campaigns' ] ) ? $_SESSION[ 'campaigns' ] : NULL;
	$headers   = isset( $_SESSION[ 'headers'   ] ) ? $_SESSION[ 'headers'   ] : NULL;
	$details   = isset( $_SESSION[ 'details'   ] ) ? $_SESSION[ 'details'   ] : NULL;

// loop until we reach a state where the user (web client)
// must perform an action to determine what the next state
// will be.

	output_style_header();
	do {

		message_log_reset( $msg_log );
		if ($DEBUG)
		{
			message_log_append( $msg_log, "database name is $db_name\n" );
		}
		if ($DEBUG)
		{
			message_log_append( $msg_log, "state is $ps_state\n" );
		}
		switch (TRUE) 
		{
/////////////////////////////////
//
//  Initial state is BEGIN
//
/////////////////////////////////
			case ($ps_state == 'BEGIN'):
//  Clear all keys in array $_SESSION
				foreach (array_keys( $_SESSION ) as $sess_key) 
				{
					unset( $_SESSION[ $sess_key ] );
				} // foreach
//  Proceed to a prompting state
				next_state( 'PROMPT_FOR_XML_INPUT' );
				break;
/////////////////////////////////
//
//  Prompt the user to provide an
//  XML file.
//
/////////////////////////////////
			case ($ps_state == 'PROMPT_FOR_XML_INPUT'):
// We are ready to prompt for an input file
				if (CLI) 
				{
					;
// In CLI mode, the input file name will be on the command line.
				} 
				else 
				{
					prompt_for_xml_input();
				}
//  The next step is to check the XML file for basic sanity checks
				next_state( 'CHECK_XML_FILENAME' );
//  But first we have to wait for the web client to upload the file
				$done = TRUE;
				if (CLI) 
				{
					$done = FALSE;
				}
				break;
/////////////////////////////////
//
//  Do some basic checking on the
//  XML file the user provided.
//
/////////////////////////////////
			case ($ps_state == 'CHECK_XML_FILENAME'):
				$input_nam = 'xmlfile'; // per the POST form
				$filnam = isset( $_FILES[ $input_nam ] ) ? 
						 $_FILES[ $input_nam ][ 'name' ] : NULL;
// The full path to where the file was uploaded on the server
				$filtmp = isset( $_FILES[ $input_nam ] ) ? 
						 $_FILES[ $input_nam ][ 'tmp_name' ] : NULL;
				if (is_null( $filnam ) || is_null( $filtmp ) ||
						(strlen( $filnam ) == 0) ||
						(strlen( $filtmp ) == 0)) 
				{
					next_state( 'BEGIN' );
				} 
				else 
				{
					next_state( 'CHECK_XML_UPLOAD' );
				}
				break;
			case ($ps_state == 'CHECK_XML_UPLOAD'):
				if (CLI) 
				{
					$filtmp = $argv[1];
					echo "input file is $filtmp\n";
				}
// The size of the file in bytes
				$filsiz = $_FILES[ $input_nam ][ 'size' ];
// The error code of the upload process
				$filerr = $_FILES[ $input_nam ][ 'error' ];
				if (CLI || $filerr == UPLOAD_ERR_OK) 
				{
					next_state( 'PARSE_XML_UPLOAD' );
				} 
				else 
				{
					message_log_append( $msg_log, "Upload error $filerr", MSG_LOG_ERROR );
					$done = TRUE;
					next_state( 'BEGIN' );	// start over
				}
				break;
/////////////////////////////////
//
//  Do a full parsing of the
//  XML file the user provided.
//
/////////////////////////////////

			case ($ps_state == 'PARSE_XML_UPLOAD'):
				open_mysql();
//  What is the path portion of the $filtmp filename?
				$_SESSION[ 'xmlfile' ] = $filtmp;
				if ($DEBUG) 
				{
					echo "calling parse_xml<br>\n";
					echo "parsing file: $filtmp<br>\n";
				}
//  Set state to start over, in case we fail before parse_xml
// returns.
				next_state( 'BEGIN' );
// parse the XML file, returning an array of contract headers,
// and an array of arrays of detail lines.  First-order indices of 
// headers and details arrays will be integers starting from 1.
				if (parse_xml( $filtmp, $campaigns, $headers, $details )) 
				{
					next_state( 'VERIFY_CAMPAIGN' );
				} 
				else 
				{
					message_log_append( $msg_log, "XML order parsing failed", MSG_LOG_ERROR );
					unset( $_SESSION[ 'campaigns' ] );
					unset( $_SESSION[ 'headers'   ] );
					unset( $_SESSION[ 'details'   ] );
					next_state( 'TRY_AGAIN' );
				}
				break;
/////////////////////////////////
//
//  Verify some basic integrity
//  checks on the data, and create
//  human-readable log messages for
//  problems that are identified.
//
/////////////////////////////////
			case ($ps_state == 'RE-VERIFY_CAMPAIGN'):
// unset all header row MSG_LOG values
				foreach (array_keys( $headers ) as $key)
				{
				    unset( $headers[ $key ][ 'MSG_LOG' ] );
				}
// unset all detail line MSG_LOG values
				foreach (array_keys( $details ) as $dkey)
				{
				    foreach (array_keys( $details[ $dkey ] ) as $ln)
					{
						unset( $details[ $dkey ][ $ln ][ 'MSG_LOG' ] );
					}
				}
// and fall through to VERIFY_CAMPAIGN:
			case ($ps_state == 'VERIFY_CAMPAIGN'):
				verify_campaign( $campaigns, $headers, $details );
				next_state( 'BEGIN' );	// as precaution
//echo "calling verify_all_contracts<br>";
				if (verify_all_contracts( $campaigns, $headers, $details )) 
				{
//echo "vac succeeded<br>";
				} 
				else 
				{
//echo "vac failed<br>";
				}
				next_state( ($ps_state == 'VERIFY_CAMPAIGN')
					? 'DISPLAY_CAMPAIGN'
					: 'DISPLAY_CONTRACT' );
				break;
			case ($ps_state == 'DISPLAY_CAMPAIGN'):
				unset( $cont_key );	// contract array key
				next_state( 'DISPLAY_CONTRACT' );
				break;
			case ($ps_state == 'DISPLAY_CONTRACT'):
//echo "$ps_state<br>";
				if (is_null( $campaigns ) ||
				    is_null( $headers   ) || is_null( $details   )) 
				{
				    next_state( 'BEGIN' );
				} 
				else 
				{
				    if (!isset( $cont_key ) || is_null( $cont_key )) 
					{
						$keys = array_keys( $headers );
						$cont_key = $keys[0];
				    } // if
				    if (is_null( $cont_key )) 
					{
						next_state( 'BEGIN' );
				    } 
					else 
					{
						echo html_campaign( $campaigns );
						echo nav_buttons( array_keys( $headers ), 
							  TRUE,
							  $headers,
							  $cont_key );
						echo html_order( $headers[$cont_key], $cont_key );
						echo html_detail( $details[$cont_key], $cont_key );
// set a safe next state.  form_handler ought to override, unless error.
						next_state( 'BEGIN' );
						$done = TRUE;
				    } //if
				} // if
				break;
			case ($ps_state == 'DISPLAY_NEXT'):
				$keys = array_keys( $headers );
				$cont_key = next_cont_key( $cont_key, $keys );
// we might someday use a better state than BEGIN here.  A NULL
// return from next_cont_key would mean that no contracts remain.
				next_state( is_null( $cont_key ) ? 'BEGIN' : 'DISPLAY_CONTRACT' );
				break;
			case ($ps_state == 'DISPLAY_PREV'):
				$keys = array_keys( $headers );
				$cont_key = prev_cont_key( $cont_key, $keys );
				next_state( is_null( $cont_key ) ? 'BEGIN' : 'DISPLAY_CONTRACT' );
				break;
/////////////////////////////////
//
//  Push SQL file out to
//  the web client for download.
//
/////////////////////////////////
			case ($ps_state == 'PUSH_SQL_FILE'):
				next_state( 'BEGIN' );
				if (CLI) 
				{
					echo "SQL output is in file $sql_file\n";
				} 
				else 
				{
					header( 'Content-type: application/force-download' );
    				header( 'Content-Transfer-Encoding: Binary' );
    				header( 'Content-length: ' . filesize( $sql_file ) );
    				header( 'Content-disposition: attachment; filename="' . basename( $sql_file ) . '"' );
    				readfile( $sql_file );
					unlink( $sql_file );   // delete
				}
				$done = TRUE;
				break;
/////////////////////////////////
//
//  Connect to the SQL server and
//  move the data into the database.
//
/////////////////////////////////
			case ($ps_state == 'IMPORT'):
				next_state( 'BEGIN' );
				open_mysql();
				insert_sql( $campaigns, $headers, $details );
				echo message_log_format( $msg_log );
				message_log_reset( $msg_log );
				break;
/////////////////////////////////
//
//  Delete a LineID from a contract
//
/////////////////////////////////
			case ($ps_state == 'DELETE_LINE'):
				$lineID	   = $_SESSION[ 'LineID'    ];  // XML LineID number
//message_log_append( $msg_log, 'You requested to delete LineID ' . $lineID . ' from contract key ' . $cont_key );

// Deleting detail lines will change the header spot and value totals.
// delete_detail_lineid is responsible for telling us how many spots
// were deleted, and what their total value was.
				$spots = 0;
				$value = 0;
				$details[ $cont_key ] = delete_detail_lineid( 
					$details[ $cont_key ], $lineID, $spots, $value );

// subtract deleted spots and value from header 'detail_*' totals
				$headers[ $cont_key ][ 'detail_spots' ] -= $spots;
				$v = $headers[ $cont_key ][ 'detail_cost' ];
				$v = bcsub( $v, $value, 2 );
				$headers[ $cont_key ][ 'detail_cost' ] = $v;

// subtract deleted spots and value from header 'total_*' totals
				$headers[ $cont_key ][ 'total_spots' ] -= $spots;
				$v = $headers[ $cont_key ][ 'total_cost' ];
				$v = bcsub( $v, $value, 2 );
				$headers[ $cont_key ][ 'total_cost' ] = $v;

// subtract deleted spots and value from campaign 'detail_*' totals
				$campaigns[0][ 'detail_spots' ] -= $spots;
				$v = $campaigns[0][ 'detail_cost' ];
				$v = bcsub( $v, $value, 2 );
				$campaigns[0][ 'detail_cost' ] = $v;

// subtract deleted spots and value from campaign 'total_*' totals
				$campaigns[0][ 'total_spots' ] -= $spots;
				$v = $campaigns[0][ 'total_cost' ];
				$v = bcsub( $v, $value, 2 );
				$campaigns[0][ 'total_cost' ] = $v;

// Now re-validate everything, and re-display this
// specific contract.
				next_state( 'RE-VERIFY_CAMPAIGN' );
				break;
/////////////////////////////////
//
//  Delete a Network from a contract
//
/////////////////////////////////
			case ($ps_state == 'DELETE_NETWORK'):
next_state( 'BEGIN' );
				$lineID	   = $_SESSION[ 'LineID'    ];  // XML LineID number
				$network   = NULL;
				foreach ($details[ $cont_key ] as $det) 
				{
					if ($det[ 'LineID' ] === $lineID) 
					{
						$network = $det[ 'Network' ];
//echo "<pre>"; var_dump( $det ); echo "</pre>";
						break;
					}
				}

				next_state( 'RE-VERIFY_CAMPAIGN' );
				if (is_null( $network)) 
				{
message_log_append( $msg_log, 'Invalid LineID: ' . $lineID . ' not found in contract key ' . $cont_key );
					break;
				}

// Deleting detail lines will change the header spot and value totals.
// delete_detail_network is responsible for telling us how many spots
// were deleted, and what their total value was.
				$spots = 0;
				$value = 0;
				$details[ $cont_key ] = delete_detail_network( 
					$details[ $cont_key ], $network, $spots, $value );

// subtract deleted spots and value from header 'detail_*' totals
				$headers[ $cont_key ][ 'detail_spots' ] -= $spots;
				$v = $headers[ $cont_key ][ 'detail_cost' ];
				$v = bcsub( $v, $value, 2 );
				$headers[ $cont_key ][ 'detail_cost' ] = $v;

// subtract deleted spots and value from header 'total_*' totals
				$headers[ $cont_key ][ 'total_spots' ] -= $spots;
				$v = $headers[ $cont_key ][ 'total_cost' ];
				$v = bcsub( $v, $value, 2 );
				$headers[ $cont_key ][ 'total_cost' ] = $v;

// subtract deleted spots and value from campaign 'detail_*' totals
				$campaigns[0][ 'detail_spots' ] -= $spots;
				$v = $campaigns[0][ 'detail_cost' ];
				$v = bcsub( $v, $value, 2 );
				$campaigns[0][ 'detail_cost' ] = $v;

// subtract deleted spots and value from campaign 'total_*' totals
				$campaigns[0][ 'total_spots' ] -= $spots;
				$v = $campaigns[0][ 'total_cost' ];
				$v = bcsub( $v, $value, 2 );
				$campaigns[0][ 'total_cost' ] = $v;

				message_log_append( $msg_log, 
					'Network ' . $network . 
					' deleted from contract ' . $cont_key );

// Now re-validate everything, and re-display this
// specific contract.
				next_state( 'RE-VERIFY_CAMPAIGN' );
				break;
/////////////////////////////////
//
//  Delete an entire contract
//
/////////////////////////////////
			case ($ps_state == 'DELETE_CONTRACT'):
//message_log_append( $msg_log, 'You requested to delete contract ' . $cont_key );

// Unset the individual detail lines for this contract.
				$dkeys = array_keys( $details[ $cont_key ] );
				foreach ($dkeys as $key) 
				{
					unset( $details[ $cont_key ][ $key ] );
				}
// subtract contract spots and value from campaign 'detail_*' totals
				$spots = $headers[ $cont_key ][ 'detail_spots' ];
				$value = $headers[ $cont_key ][ 'detail_cost'  ];
				$campaigns[0][ 'detail_spots' ] -= $spots;
				$v = $campaigns[0][ 'detail_cost' ];
				$v = bcsub( $v, $value, 2 );
				$campaigns[0][ 'detail_cost' ] = $v;

// subtract contract spots and value from campaign 'total_*' totals
				$spots = $headers[ $cont_key ][ 'total_spots' ];
				$value = $headers[ $cont_key ][ 'total_cost'  ];
				$campaigns[0][ 'total_spots' ] -= $spots;
				$v = $campaigns[0][ 'total_cost' ];
				$v = bcsub( $v, $value, 2 );
				$campaigns[0][ 'total_cost' ] = $v;

// Set the contract header to show 0 spots, 0 value.
				$spots = 0;
				$value = 0;
				$headers[ $cont_key ][ 'detail_spots' ] = $spots;
				$headers[ $cont_key ][ 'detail_cost'  ] = $value;
				$headers[ $cont_key ][ 'total_spots'  ] = $spots;
				$headers[ $cont_key ][ 'total_cost'   ] = $value;

// Unset the 'versionN' fields of deleted contracts so that version
// problems don't prevent the remaining contracts from being imported.
				$j = 0;
				$done = FALSE;
				while (!$done) 
				{
					$fld = 'version' . (++$j);
					$done = !isset( $headers[ $cont_key ][ $fld ] );
					unset( $headers[ $cont_key ][ $fld ] );
				} // while
// auto-advance to next contract
				$done = FALSE;
				$keys = array_keys( $headers );
				$cont_key = next_cont_key( $cont_key, $keys );
// we might someday use a better state than BEGIN here.  A NULL
// return from next_cont_key would mean that no contracts remain.
				next_state( is_null( $cont_key ) ? 'BEGIN' : 'RE-VERIFY_CAMPAIGN' );
				break;
/////////////////////////////////
//
//  Dummy stub.
//
/////////////////////////////////
			case ($ps_state == 'DEAD_END'):
			case ($ps_state == 'STOP'):
				echo $ps_state;
				next_state( 'BEGIN' );
				$done = TRUE;
				break;
/////////////////////////////////
//
//  Screen has error messages.
//  Force user to go back and retry.
//
/////////////////////////////////
			case ($ps_state == 'TRY_AGAIN'):
				next_state( 'BEGIN' );
				echo nav_buttons( NULL, FALSE );	// Cancel only
				$done = TRUE;
				break;
/////////////////////////////////
//
//  State is unknown or invalid.
//  Go back to BEGIN state.
//
/////////////////////////////////
			default:
				message_log_append( $msg_log, 'Invalid state label: ' . $ps_state, MSG_LOG_ERROR );
				next_state( 'BEGIN' );
				$done = TRUE;

		} // switch
		$ps_state = current_state();
//		echo message_log_format( $msg_log );
		echo message_log_table( $msg_log );
	} while (!$done);
	$_SESSION[ 'campaigns' ] = $campaigns;
	$_SESSION[ 'headers'   ] = $headers;
	$_SESSION[ 'details'   ] = $details;
	$_SESSION[ 'cont_key'  ] = $cont_key;
} // process_state
コード例 #7
0
<?php

require_once 'php/db.php';
insert_sql("INSERT INTO category(guid, name, description) VALUES(?,?,?)", 'sss', array(getGUID(8), $_GET['name'], $_GET['desc']));
コード例 #8
0
include_once 'php/db.php';
get_header();
$message = "";
$title = "Ongeldige Url!";
if (!isset($_GET['url'][0])) {
    $message = '<h4>Geen geldige url!</h4>';
} else {
    $db = select_sql("SELECT user_guid, action FROM ra_mail WHERE url = ?", 's', $_GET['url'][0]);
    if (empty($db)) {
        $message = '<h4>Geen geldige url!</h4>';
    } else {
        $db = $db[0];
        switch ($db['action']) {
            case ACTIONACTIVATE:
                insert_sql("UPDATE user SET isactive = 1 WHERE guid = ?", 's', array($db['user_guid']));
                insert_sql("DELETE FROM ra_mail WHERE url = ?", 's', array($_GET['url'][0]));
                $message = '<h4>Uw account is geactiveerd!</h4>' . '<h4><a href="/login">Ga naar de loginpagina</a></h4>';
                $title = "Activeren";
                break;
            case ACTIONRESETPASSWORD:
                $message = ACTIONRESETPASSWORD;
                $title = "Wachtwoord Resetten";
                break;
            default:
                $message = '<h4>Geen geldige url!</h4>';
        }
    }
}
?>
<!-- Page Content -->
<div class="container">
コード例 #9
0
 public function doDraw()
 {
     if (strtotime($this->allot_date) < strtotime("now") && !$this->isgone) {
         $users = $this->getUsers();
         if (count($users) > 0) {
             $amount_of_users = count($users);
             $amount_of_users--;
             $winner_number = round(rand(0, $amount_of_users));
             $winner = $users[$winner_number];
             $insert = insert_sql("UPDATE product SET winner_guid = ?, isgone = 1 WHERE guid = ?", 'ss', array($winner->guid, $this->guid));
             if ($insert) {
                 foreach ($users as $user) {
                     svMail($user->email, $this->name . " is zojuist verloot!", array('product_name' => $this->name, 'product_url' => 'http://' . BASEURL . $this->getURL() . '/c'), 'on_allot');
                 }
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }