本文整理汇总了PHP中Utils::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::getExtension方法的具体用法?PHP Utils::getExtension怎么用?PHP Utils::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils
的用法示例。
在下文中一共展示了Utils::getExtension方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute($pair)
{
global $conf;
global $localUri;
global $uri;
global $acceptContentType;
global $endpoints;
global $lodspk;
global $results;
global $firstResults;
list($res, $page, $format) = $pair;
//If resource is not the page, send a 303 to the document
if ($res == $localUri) {
HTTPStatus::send303($page, $acceptContentType);
}
$uri = $res;
if ($conf['mirror_external_uris'] != false) {
$localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $res);
}
$extension = Utils::getExtension($format);
/*Redefine Content type based on the
* dcterms:format for this page
*/
$acceptContentType = $format;
//Check if files for model and view exist
$t = Queries::getClass($uri, $endpoints['local']);
$obj = $this->getModelandView($t, $extension);
$modelFile = $obj['modelFile'];
$lodspk['model'] = $conf['model']['directory'];
$viewFile = $obj['viewFile'];
$lodspk['view'] = $obj['view']['directory'];
if ($viewFile == null) {
$lodspk['transform_select_query'] = true;
}
$lodspk['type'] = $modelFile;
$lodspk['home'] = $conf['basedir'];
$lodspk['baseUrl'] = $conf['basedir'];
$lodspk['module'] = 'type';
$lodspk['root'] = $conf['root'];
$lodspk['contentType'] = $acceptContentType;
$lodspk['ns'] = $conf['ns'];
$lodspk['endpoint'] = $conf['endpoint'];
$lodspk['view'] = $conf['view']['directory'];
$lodspk['add_mirrored_uris'] = true;
$lodspk['this']['value'] = $uri;
$lodspk['this']['curie'] = Utils::uri2curie($uri);
$lodspk['local']['value'] = $localUri;
$lodspk['local']['curie'] = Utils::uri2curie($localUri);
$lodspk['this']['extension'] = $extension;
//chdir($conf['home'].$conf['model']['directory']);
Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
if (!$lodspk['resultRdf']) {
$results = Utils::internalize($results);
$firstAux = Utils::getfirstResults($results);
//chdir($conf['home']);
if (is_array($results)) {
$resultsObj = Convert::array_to_object($results);
$results = $resultsObj;
} else {
$resultsObj = $results;
}
$lodspk['firstResults'] = Convert::array_to_object($firstAux);
} else {
$resultsObj = $results;
}
//chdir($conf['home'].$conf['model']['directory']);
Utils::processDocument($viewFile, $lodspk, $resultsObj);
}
示例2: updateThemes
private function updateThemes()
{
$themeManager = $this->director->themeManager;
$settings = array('active' => 1);
$settings['content_path'] = $this->getContentPath(true);
$tempPath = realpath($this->director->getImportPath());
$logging = array();
$dh = dir($tempPath);
while (FALSE !== ($entry = $dh->read())) {
$file = $tempPath . '/' . $entry;
if (Utils::getExtension($file) != 'gz') {
continue;
}
try {
$themeManager->extractTheme($tempPath, $file);
$logging = array_merge($logging, $themeManager->installTheme($tempPath, $settings, NULL));
} catch (Exception $err) {
$logging[] = $err->getMessage();
}
}
$dh->close();
// try to link plugins that are uploaded but not in the database
$tempPath = $this->getThemePath();
$dh = dir($tempPath);
while (FALSE !== ($entry = $dh->read())) {
$themeDir = $tempPath . '/' . $entry . '/script';
if (!$themeManager->isTheme($themeDir)) {
continue;
}
try {
$logging = array_merge($logging, $themeManager->installTheme($themeDir, $settings, NULL, ThemeManager::ACTION_UPDATE));
} catch (Exception $err) {
$logging[] = $err->getMessage();
}
}
$dh->close();
return $logging;
}
示例3: import
private function import($tree_id, $tag, $nl_id, $stdout = true)
{
// enable processing of local files in insertimage
$this->importing = true;
$debug = array();
$importPath = $this->director->getImportPath() . "/";
$values = array('tree_id' => $tree_id, 'tag' => $tag, 'nl_id' => $nl_id, 'active' => 1);
if (!is_dir($importPath)) {
throw new Exception("Import path {$importPath} does not exist. Create it and fill it with attachments first\n");
}
$debug[] = "Starting import at " . date('d-m-Y H:i:s');
$debug[] = "Path: {$importPath}";
$debug[] = "Tree: {$tree_id}";
$debug[] = "Tag: {$tag}";
$debug[] = "----------------------------------\n";
if ($stdout) {
echo join("\n", $debug);
}
$files = array();
$dh = dir($importPath);
while (FALSE !== ($entry = $dh->read())) {
$file = $importPath . $entry;
if (!is_file($file)) {
continue;
}
$files[] = $file;
}
// sort alphabetical
sort($files);
foreach ($files as $file) {
$name = basename($file, "." . Utils::getExtension($file));
$values['name'] = $name;
$values['weight'] = $this->getNextWeight($tree_id, $tag);
$values['file'] = array('tmp_name' => $file, 'name' => $name);
$debug[] = "Processing {$name}";
$id = $this->insert($values);
if ($stdout) {
echo join("\n", $debug);
}
}
$debug[] = "----------------------------------";
$debug[] = "Import finished at " . date('d-m-Y H:i:s');
if ($stdout) {
echo join("\n", $debug);
}
return $debug;
}
示例4: save
public function save($file = NULL)
{
// check fil file is set
if (!$this->getFileName()) {
return;
}
$filename = isset($file) ? $file : $this->getFileName();
switch (Utils::getExtension($filename)) {
case 'jpg':
case 'jpeg':
imagejpeg($this->getImage(), $filename, 95);
break;
case 'gif':
imagegif($this->getImage(), $filename);
break;
default:
imagepng($this->getImage(), $filename, 9);
break;
}
chmod($filename, 0644);
}
示例5: processDocument
public static function processDocument($viewFile, $lodspk, $data)
{
global $conf;
global $lodspk;
$contentType = $lodspk['contentType'];
$extension = Utils::getExtension($contentType);
header('Content-Type: ' . $contentType);
if (isset($lodspk['resultRdf']) && $lodspk['resultRdf'] == true) {
$rdfData = Utils::serializeRdf($data, $extension);
if ($rdfData["serialized"]) {
echo $rdfData["content"];
} else {
$data['rdf'] = new stdClass();
$subjectCounter = 0;
$sIndex = array();
$sCounter = array();
$spCounter = array();
foreach ($rdfData["content"] as $t) {
//SUBJECT
if ($t['s_type'] == 'uri') {
$subject = $t['s'];
$subjectCurie = Utils::uri2curie($subject);
$subjectMethod = str_replace(":", "__", $subjectCurie);
} else {
if (isset($sIndex[$t['s']])) {
$subject = $sIndex[$t['s']];
$subjectCurie = $sIndex[$t['s']];
$subjectMethod = $sIndex[$t['s']];
} else {
$subject = "_bnode" . $subjectCounter;
$subjectCurie = "_bnode" . $subjectCounter;
$subjectMethod = "_bnode" . $subjectCounter;
$sIndex[$t['s']] = "_bnode" . $subjectCounter++;
}
}
if (!isset($data['rdf']->subjects)) {
$data['rdf']->subjects = new stdClass();
}
if (!isset($data['rdf']->{$subjectMethod})) {
$data['rdf']->{$subjectMethod} = new stdClass();
$data['rdf']->{$subjectMethod}->predicates = new stdClass();
}
$data['rdf']->{$subjectMethod}->mirroredUri = $subject;
$data['rdf']->{$subjectMethod}->mirroredCurie = $subjectCurie;
$data['rdf']->{$subjectMethod}->value = Utils::getUnMirroredUri($subject);
$data['rdf']->{$subjectMethod}->curie = Utils::uri2curie($data['rdf']->{$subjectMethod}->value);
if (!isset($data['rdf']->subjects->{$subjectMethod})) {
$data['rdf']->subjects->{$subjectMethod} = $data['rdf']->{$subjectMethod};
}
//PREDICATE
$predicate = $t['p'];
$predicateCurie = Utils::uri2curie($predicate);
$predicateMethod = str_replace(":", "__", $predicateCurie);
if (!isset($data['rdf']->{$subjectMethod}->{$predicateMethod})) {
$data['rdf']->{$subjectMethod}->{$predicateMethod} = new stdClass();
}
$data['rdf']->{$subjectMethod}->{$predicateMethod}->mirroredUri = $predicate;
$data['rdf']->{$subjectMethod}->{$predicateMethod}->mirroredCurie = $predicateCurie;
$data['rdf']->{$subjectMethod}->{$predicateMethod}->value = Utils::getUnMirroredUri($predicate);
$data['rdf']->{$subjectMethod}->{$predicateMethod}->curie = Utils::uri2curie($data['rdf']->{$subjectMethod}->{$predicateMethod}->value);
if (!isset($data['rdf']->{$subjectMethod}->predicates)) {
$data['rdf']->{$subjectMethod}->predicates = new stdClass();
}
if (!isset($sCounter[$subjectMethod])) {
$sCounter[$subjectMethod] = 0;
}
$sCount = $sCounter[$subjectMethod]++;
$data['rdf']->{$subjectMethod}->predicates->{$sCount} = $data['rdf']->{$subjectMethod}->{$predicateMethod};
//OBJECT
if ($t['o_type'] == 'uri') {
$object = $t['o'];
$objectCurie = Utils::uri2curie($object);
} elseif ($t['o_type'] == 'literal') {
$object = $t['o'];
$objectCurie = $object;
} else {
if (isset($sIndex[$t['o']])) {
$object = $sIndex[$t['o']];
$objectCurie = $sIndex[$t['o']];
} else {
$object = "_bnode" . $objectCounter;
$objectCurie = "_bnode" . $objectCounter;
$sIndex[$t['s']] = "_bnode" . $objectCounter++;
}
}
$obj = new stdClass();
$obj->mirroredUri = $object;
$obj->mirroredCurie = $objectCurie;
$obj->value = Utils::getUnMirroredUri($object);
$obj->curie = Utils::uri2curie($obj->value);
if (!isset($spCounter[$subjectMethod . " " . $predicateMethod])) {
$spCounter[$subjectMethod . " " . $predicateMethod] = 0;
}
$sCount = $spCounter[$subjectMethod . " " . $predicateMethod]++;
$data['rdf']->{$subjectMethod}->{$predicateMethod}->objects->{$sCount} = $obj;
}
Utils::showView($lodspk, $data, $viewFile);
}
} else {
Utils::showView($lodspk, $data, $viewFile);
//.........这里部分代码省略.........
示例6: execute
public function execute($service)
{
global $conf;
global $localUri;
global $uri;
global $acceptContentType;
global $endpoints;
global $lodspk;
global $firstResults;
global $results;
$context = array();
$context['contentType'] = $acceptContentType;
$context['endpoints'] = $endpoints;
//$f = $this->getFunction($localUri);
$params = array();
$params = $this->getParams($localUri);
//$params[] = $context;
//$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
$extension = Utils::getExtension($acceptContentType);
$args = array();
list($modelFile, $viewFile) = $service;
try {
$prefixHeader = array();
for ($i = 0; $i < sizeof($params); $i++) {
if ($conf['mirror_external_uris'] != false) {
$altUri = Utils::curie2uri($params[$i]);
$altUri = preg_replace("|^" . $conf['basedir'] . "|", $conf['ns']['local'], $altUri);
$params[$i] = Utils::uri2curie($altUri);
}
}
$segmentConnector = "";
for ($i = 0; $i < sizeof($params); $i++) {
Utils::curie2uri($params[$i]);
//echo $params[$i]." ".Utils::curie2uri($params[$i]);exit(0);
$auxPrefix = Utils::getPrefix($params[$i]);
if ($auxPrefix['ns'] != NULL) {
$prefixHeader[] = $auxPrefix;
}
$args["arg" . $i] = $params[$i];
$args["all"] .= $segmentConnector . $params[$i];
if ($segmentConnector == "") {
$segmentConnector = "/";
}
}
$results['params'] = $params;
$lodspk['home'] = $conf['basedir'];
$lodspk['baseUrl'] = $conf['basedir'];
$lodspk['module'] = 'service';
$lodspk['root'] = $conf['root'];
$lodspk['contentType'] = $acceptContentType;
$lodspk['ns'] = $conf['ns'];
$lodspk['this']['value'] = $uri;
$lodspk['this']['curie'] = Utils::uri2curie($uri);
$lodspk['local']['value'] = $localUri;
$lodspk['local']['curie'] = Utils::uri2curie($localUri);
$lodspk['contentType'] = $acceptContentType;
$lodspk['endpoint'] = $conf['endpoint'];
$lodspk['type'] = $modelFile;
$lodspk['header'] = $prefixHeader;
$lodspk['args'] = $args;
$lodspk['add_mirrored_uris'] = false;
$lodspk['baseUrl'] = $conf['basedir'];
$lodspk['this']['value'] = $uri;
if ($viewFile == null) {
$lodspk['transform_select_query'] = true;
}
// chdir($lodspk['model']);
Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
if (!$lodspk['resultRdf']) {
$results = Utils::internalize($results);
$firstAux = Utils::getfirstResults($results);
// chdir($conf['home']);
if (is_array($results)) {
$resultsObj = Convert::array_to_object($results);
$results = $resultsObj;
} else {
$resultsObj = $results;
}
$lodspk['firstResults'] = Convert::array_to_object($firstAux);
} else {
$resultsObj = $results;
}
//Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly
//$viewFile = $extension.".template";
//chdir($conf['home']);
Utils::processDocument($viewFile, $lodspk, $results);
} catch (Exception $ex) {
echo $ex->getMessage();
if ($conf['debug']) {
Logging::log($ex->getMessage(), E_ERROR);
}
HTTPStatus::send500($uri);
}
}
示例7: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new ImportUserFileModel();
$content_type = Yii::app()->request->getParam('content_type', 'subscribe');
Yii::app()->session['content_type'] = $content_type;
if (Yii::app()->request->isPostRequest) {
$content_type = Yii::app()->session['content_type'];
$package_id = Yii::app()->request->getParam('package_id', null);
if (!isset($package_id)) {
$model->addError("name", "Chưa chọn gói cước!");
}
if (!$_FILES['file']['error']) {
$ext = Utils::getExtension($_FILES['file']['name']);
$type = $_FILES['file']['type'];
if ($ext == 'xls' && ($type == 'application/xls' || $type == 'application/vnd.ms-excel')) {
$storage = Yii::app()->params['storage']['baseStorage'] . "uploads" . DS . "user" . DS;
Utils::makeDir($storage);
$fileName = $_FILES['file']['name'];
if (move_uploaded_file($_FILES['file']['tmp_name'], $storage . DS . $fileName)) {
$transaction = Yii::app()->db->beginTransaction();
try {
$file_path = $storage . DS . $fileName;
$model->file_name = $fileName;
$model->created_by = $this->userId;
$model->file_path = $file_path;
$model->package_id = $package_id;
$model->created_time = new CDbExpression("NOW()");
$model->content_type = $content_type;
if ($model->save(false)) {
$data = new ExcelReader($file_path);
$start_row = 2;
$limit_row = $data->rowcount();
$cell_name = "A";
$arrayVal = array();
for ($i = $start_row; $i <= $limit_row; $i++) {
if ($data->val($i, $cell_name) == "") {
continue;
}
$name = $model->my_encoding($data->val($i, $cell_name));
$arrayVal[] = "('{$name}','{$model->id}','{$package_id}')";
}
/**
* Start insert here: split 200 line per command
*/
$arrs = array_chunk($arrayVal, 200);
foreach ($arrs as $arr) {
$vals = implode(",", $arr);
$sql = "INSERT INTO import_user_content (`msisdn`,`file_id`,`package_id`) VALUES {$vals}";
$command = Yii::app()->db->createCommand($sql);
$command->execute();
}
$transaction->commit();
$this->redirect(array('view', 'id' => $model->id, 'content_type' => $content_type));
} else {
$transaction->rollback();
}
} catch (Exception $e) {
$transaction->rollback();
$model->addError("exception", $e->getMessage());
}
} else {
$model->addError("name", "Không upload được file vào thư mục:" . $storage . DS . $fileName);
}
} else {
$model->addError("name", "Chỉ upload file xls");
}
} else {
$model->addError("name", "Chưa upload file");
// $model->content_type = $content_type;
}
}
$this->render('create', array('model' => $model, 'content_type' => $content_type));
}
示例8: insertImage
protected function insertImage($id, $values)
{
$request = Request::getInstance();
// get settings
$calSettings = $this->plugin->getObject(Calendar::TYPE_SETTINGS);
$globalSettings = $this->plugin->getSettings();
$settings = array_merge($globalSettings, $calSettings->getSettings($values['tree_id'], $values['tag']));
$destWidth = $settings['image_width'];
$destHeight = $settings['image_height'];
$maxWidth = $settings['image_max_width'];
// user global if tree values are not set
if (!$destWidth) {
$destWidth = $globalSettings['image_width'];
}
if (!$destHeight) {
$destHeight = $globalSettings['image_height'];
}
if (!$maxWidth) {
$maxWidth = $globalSettings['image_max_width'];
}
$imgX = $values['img_x'];
$imgY = $values['img_y'];
$path = $this->plugin->getContentPath(true);
$filename = strtolower($this->getClassName()) . "_" . $id['id'];
// check if image is uploaded
$img = $values['image'];
$upload = is_array($img) && $img['tmp_name'];
if ($upload) {
// image is new uploaded image
$image = new Image($img);
$imgWidth = $image->getWidth();
$imgHeight = $image->getHeight();
$ext = Utils::getExtension($img['name']);
$originalFile = "{$filename}.{$ext}";
$croppedFile = $filename . "_thumb.{$ext}";
// delete current image if filename new filename is different
$detail = $this->getDetail($id);
if ($detail['image'] && $detail['image'] != $originalFile) {
$this->deleteImage($detail);
}
// resize original image. (increase size if necessary)
if ($maxWidth > 0 && $imgWidth > $maxWidth) {
$image->resize($maxWidth);
} elseif ($imgWidth < $destWidth || $imgHeight < $destHeight) {
if ($image->getWidth() < $destWidth) {
$image->resize($destWidth, 0, true);
}
if ($image->getHeight() < $destHeight) {
$image->resize(0, $destHeight, true);
}
}
$image->save($path . $originalFile);
} else {
// no image provided. check if one exists
$detail = $this->getDetail($id);
if (!$detail['image']) {
return;
}
// get original image
$image = new Image($detail['image'], $this->plugin->getContentPath(true));
$ext = Utils::getExtension($detail['image']);
$originalFile = "{$filename}.{$ext}";
$croppedFile = $filename . "_thumb.{$ext}";
}
// only crop if both width and height settings are set and image is big enough, else do a resize
if ($destWidth && $destHeight) {
// crop image
if ($upload) {
// calculate area of crop field
// first assume width is smalles side
$newWidth = $image->getWidth();
$newHeight = $newWidth / $destWidth * $destHeight;
if ($newHeight > $image->getHeight()) {
// width was larger than height, so use height as smallest side
$newHeight = $image->getHeight();
$newWidth = $newHeight / $destHeight * $destWidth;
}
// center crop area
$imgX = intval($image->getWidth() / 2 - $newWidth / 2);
$imgY = intval($image->getHeight() / 2 - $newHeight / 2);
} else {
$newWidth = $values['img_width'];
$newHeight = $values['img_height'];
}
// crop image
$image->crop($imgX, $imgY, $newWidth, $newHeight, $destWidth, $destHeight);
// save cropped and overlayed image
$image->save($path . $croppedFile);
} else {
// resize image
$image->resize($destWidth, $destHeight);
$newWidth = $image->getWidth();
$newHeight = $image->getHeight();
$image->save($path . $croppedFile);
}
$db = $this->getDb();
$query = sprintf("update calendar set cal_image= '%s', cal_thumbnail = '%s', cal_img_x = %d, cal_img_y = %d, cal_img_width = %d, cal_img_height = %d where cal_id = %d", addslashes($originalFile), addslashes($croppedFile), $imgX, $imgY, $newWidth, $newHeight, $id['id']);
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
//.........这里部分代码省略.........
示例9: error_reporting
//error_reporting(E_ALL);
}
} else {
error_reporting(E_ERROR);
}
include_once 'classes/HTTPStatus.php';
include_once 'classes/Utils.php';
include_once 'classes/Queries.php';
include_once 'classes/Endpoint.php';
include_once 'classes/Convert.php';
$results = array();
$firstResults = array();
$endpoints = array();
$endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']);
$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
$extension = Utils::getExtension($acceptContentType);
//Check content type is supported by LODSPeaKr
if ($acceptContentType == NULL) {
HTTPStatus::send406($uri);
}
//Export
if ($conf['export'] && $_GET['q'] == 'export') {
include_once 'settings.inc.php';
include_once 'classes/Exporter.php';
$exp = new Exporter();
header('Content-Type: text/plain');
$exp->run();
exit(0);
}
//Redirect to root URL if necessary
$uri = $conf['basedir'] . $_GET['q'];
示例10: execute
public function execute($p)
{
global $conf;
global $localUri;
global $uri;
global $acceptContentType;
global $endpoints;
global $lodspk;
global $results;
global $firstResults;
$res = $p['res'];
$page = $p['page'];
$format = $p['format'];
$modelFile = $p['modelFile'];
$viewFile = $p['viewFile'];
$uri = $res;
$curie = Utils::uri2curie($res);
//If resource is not the page, send a 303 to the document
if ($res == $localUri) {
HTTPStatus::send303($page, $acceptContentType);
}
$uri = $res;
if ($conf['mirror_external_uris'] != false) {
$localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $res);
}
$extension = Utils::getExtension($format);
/*Redefine Content type based on the
* dcterms:format for this page
*/
$acceptContentType = $format;
$curie = Utils::uri2curie($uri);
if ($modelFile == NULL) {
return;
}
//$lodspk = $conf['view']['standard'];
$lodspk['type'] = $modelFile;
$lodspk['home'] = $conf['basedir'];
$lodspk['module'] = 'uri';
$lodspk['add_mirrored_uris'] = true;
$lodspk['this']['value'] = $uri;
$lodspk['this']['curie'] = Utils::uri2curie($uri);
$lodspk['local']['value'] = $localUri;
$lodspk['local']['curie'] = Utils::uri2curie($localUri);
$lodspk['contentType'] = $acceptContentType;
$lodspk['model'] = $conf['model']['directory'];
$lodspk['view'] = $conf['view']['directory'];
$lodspk['ns'] = $conf['ns'];
//chdir($conf['home'].$conf['model']['directory']);
Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
if (!$lodspk['resultRdf']) {
$results = Utils::internalize($results);
$firstAux = Utils::getfirstResults($results);
chdir($conf['home']);
if (is_array($results)) {
$resultsObj = Convert::array_to_object($results);
$results = $resultsObj;
} else {
$resultsObj = $results;
}
$lodspk['firstResults'] = Convert::array_to_object($firstAux);
} else {
$resultsObj = $results;
}
//chdir($conf['home']);
if ($conf['debug']) {
Logging::log("Using template " . $viewFile);
}
Utils::processDocument($viewFile, $lodspk, $resultsObj);
}
示例11: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new CopyrightInputFileModel();
if (Yii::app()->request->isPostRequest) {
$content_type = Yii::app()->request->getParam('content_type', null);
if (!isset($content_type)) {
$model->addError("name", "Chưa chọn loại nội dung content_type!");
} else {
if (!$_FILES['file']['error']) {
$ext = Utils::getExtension($_FILES['file']['name']);
$type = $_FILES['file']['type'];
if ($ext == 'xls' && ($type == 'application/xls' || $type == 'application/vnd.ms-excel')) {
$storage = Yii::app()->params['storage']['baseStorage'] . "uploads" . DS . "copyright";
Utils::makeDir($storage);
$fileName = $_FILES['file']['name'];
if (move_uploaded_file($_FILES['file']['tmp_name'], $storage . DS . $fileName)) {
$transaction = Yii::app()->db->beginTransaction();
try {
$model->file_name = $fileName;
$model->content_type = $content_type;
$model->created_by = $this->userId;
$model->created_time = new CDbExpression("NOW()");
if ($model->save()) {
$file_path = $storage . DS . $fileName;
$data = new ExcelReader($file_path);
$start_row = 2;
$limit_row = $data->rowcount();
$cell_content_id = "A";
$cell_name = "B";
$cell_artist = "C";
$cell_copyright_code = "F";
$copyright_id = "J";
$arrayVal = array();
for ($i = $start_row; $i < $limit_row; $i++) {
if ($data->val($i, $cell_name) == "" || $data->val($i, $cell_artist) == "" || $data->val($i, $copyright_id) == "") {
continue;
}
$contentId = $model->my_encoding($data->val($i, $cell_content_id));
$name = $model->my_encoding($data->val($i, $cell_name));
$name = '"' . $name . '"';
$artist = $model->my_encoding($data->val($i, $cell_artist));
$ccode = $model->my_encoding($data->val($i, $cell_copyright_code));
$ccid = $model->my_encoding($data->val($i, $copyright_id));
$arrayVal[] = "('" . $contentId . " ', " . $name . " ,'" . $artist . " ','" . $ccode . " '," . $ccid . " ,'{$model->id}')";
}
/**
* Start insert here: split 200 line per command
*/
$arrs = array_chunk($arrayVal, 200);
foreach ($arrs as $arr) {
$vals = implode(",", $arr);
$sql = "INSERT INTO copyright_input_content (`content_id`,`name`,`artist`,`copyright_code`,`copyright_id`,`input_file`) VALUES {$vals}";
$command = Yii::app()->db->createCommand($sql);
$command->execute();
}
$transaction->commit();
$this->redirect(array('view', 'id' => $model->id));
} else {
$transaction->rollback();
}
} catch (Exception $e) {
$transaction->rollback();
$model->addError("exception", $e->getMessage());
}
} else {
$model->addError("name", "Không upload được file vào thư mục:" . $storage . DS . $fileName);
}
} else {
$model->addError("name", "Chỉ upload file xls");
}
} else {
$model->addError("name", "Chưa upload file");
$model->content_type = $content_type;
}
}
}
$this->render('create', array('model' => $model));
}
示例12: installExtensions
private function installExtensions()
{
$extensionManager = $this->director->extensionManager;
$settings = array('active' => 1);
$setupPath = DIF_SYSTEM_ROOT . $this->director->getConfig()->file_path . "/" . strtolower($this->getClassName()) . '/extension/';
$tempPath = realpath($this->director->getTempPath());
$logging = array();
if (is_dir($setupPath)) {
$dh = dir($setupPath);
while (FALSE !== ($entry = $dh->read())) {
$file = $setupPath . $entry;
$tempFile = "{$tempPath}/{$entry}";
if (Utils::getExtension($file) != 'gz') {
continue;
}
try {
copy($file, $tempFile);
$extensionManager->extractExtension($tempPath, $tempFile);
$logging = array_merge($logging, $extensionManager->installExtension($tempPath, $settings, NULL));
} catch (Exception $err) {
$this->log->error($err->getMessage());
$logging[] = $err->getMessage();
}
}
$dh->close();
} else {
$this->log->error("{$setupPath} is missing.");
}
// try to link plugins that are uploaded but not in the database
$tempPath = $extensionManager->getExtensionPath();
$dh = dir($tempPath);
while (FALSE !== ($entry = $dh->read())) {
if ($entry == "." || $entry == "..") {
continue;
}
$extensionDir = $tempPath . '/' . $entry . '/script';
if (!$extensionManager->isExtension($extensionDir)) {
continue;
}
try {
$logging = array_merge($logging, $extensionManager->installExtension($extensionDir, $settings, NULL, ExtensionManager::ACTION_UPDATE));
} catch (Exception $err) {
$logging[] = $err->getMessage();
}
}
$dh->close();
return $logging;
}
示例13: insertImage
protected function insertImage($id, $values)
{
$request = Request::getInstance();
$img = $values['image'];
if (!is_array($img) || !$img['tmp_name']) {
return;
}
// get settings
$searchcriteria = array('tree_id' => $values['tree_id'], 'tag' => $values['tag']);
$destWidth = $values['image_width'];
$destHeight = $values['image_height'];
$image = new Image($img);
$ext = Utils::getExtension(is_array($img) ? $img['name'] : $img);
$path = $this->getContentPath(true);
$filename = strtolower($this->getClassName()) . "_layer_" . $id['tree_id'] . "." . $ext;
// delete current image if filename new filename is different
$detail = $this->getDetail($id);
if ($detail['image'] && $detail['image'] != $filename) {
$this->deleteImage($detail);
}
// resize image
$image->resize($destWidth, $destHeight);
$image->save($path . $filename);
$db = $this->getDb();
$query = sprintf("update banner_settings set bnr_image= '%s' where bnr_tree_id = %d and bnr_tag = '%s'", addslashes($filename), $values['tree_id'], $values['tag']);
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
}