本文整理汇总了PHP中Link::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Link::save方法的具体用法?PHP Link::save怎么用?PHP Link::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Link
的用法示例。
在下文中一共展示了Link::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postShorten
/**
* Shorten a new URL
*
* @return Response
*/
public function postShorten()
{
// No big url
if (!\Input::has('bigurl')) {
return \Response::json(array('error' => array('code' => 'MISSING-PARAMETERS', 'http_code' => '400', 'message' => 'Bad Request')), 400);
}
$bigURL = \Input::get('bigurl');
$user = $this->apiKey->user;
// No user linked to API key - SHOULD NEVER HAPPEN
if (!isset($user)) {
return \Response::json(array('error' => array('code' => 'NOT-AUTH', 'http_code' => '403', 'message' => 'Forbidden: SHOULD NEVER HAPPEN!')), 403);
}
// User has gone over quota so cant shorten
if ($user->quota_max != 0 && $user->quota_used + 1 > $user->quota_max) {
return \Response::json(array('error' => array('code' => 'QUOTA-USED', 'http_code' => '400', 'message' => 'Bad Request')), 403);
}
if (filter_var($bigURL, FILTER_VALIDATE_URL) === false) {
return \Response::json(array('error' => array('code' => 'URL-INVALID', 'http_code' => '400', 'message' => 'Bad Request')), 400);
}
$dbLink = \Link::where('destination', '=', $bigURL)->first();
if (!isset($dbLink)) {
$dbLink = new \Link();
$dbLink->user_id = $user->id;
$dbLink->code = $dbLink->generateCode();
$dbLink->destination = $bigURL;
$dbLink->clicks = "0";
$dbLink->save();
$user->quota_used += 1;
$user->save();
}
$linkCode = $dbLink->code;
$linkURL = \Request::root() . '/' . $linkCode;
return \Response::json(array('ok' => array('code' => 'LINK-SHORTENED', 'http_code' => '200', 'message' => 'OK', 'data' => array('url' => $linkURL, 'url_code' => $linkCode))), 200);
}
示例2: storeHref
public function storeHref($href)
{
$model = Link::model()->find('href = ?', $href);
$needToFetch = false;
if ($model == null) {
if ($model == null) {
$model = new Link();
$needToFetch = true;
}
} else {
$content = $model->getHTMLContent();
if (empty($content)) {
$needToFetch = true;
}
}
if ($needToFetch) {
$content = file_get_contents($href);
$model->href = $href;
$model->provider = $this->_providerName;
$model->type = $this->getType();
$canonicalUrl = $this->getCanonicalUrl($content);
if (!empty($canonicalUrl)) {
$model->href = $canonicalUrl;
}
if ($model->validate()) {
echo 'store URL : ' . $href . PHP_EOL;
$model->save();
$model->saveHTMLContent($content);
return $model;
}
}
}
示例3: postShorten
/**
* Shorten a new URL
*
* @return Response
*/
public function postShorten()
{
if (!\Auth::check()) {
return \Response::json(array('error' => array('code' => 'NOT-AUTH', 'http_code' => '403', 'message' => 'Forbidden')), 403);
}
$shortenValidator = \Validator::make(\Input::all(), array('url' => 'required|url'));
if ($shortenValidator->fails()) {
return \Response::json(array('error' => array('code' => 'SHORTEN-VALIDATOR-FAILED', 'http_code' => '400', 'message' => 'Bad Request', 'data' => array('validator_messages' => $shortenValidator->messages()))), 400);
}
$bigURL = \Input::get('url');
// User has gone over quota so cant shorten
if (\Auth::user()->quota_max != 0 && \Auth::user()->quota_used + 1 > \Auth::user()->quota_max) {
return \Response::json(array('error' => array('code' => 'QUOTA-USED', 'http_code' => '400', 'message' => 'Bad Request')), 403);
}
$dbLink = \Link::where('destination', '=', $bigURL)->first();
if (!isset($dbLink)) {
$dbLink = new \Link();
$dbLink->user_id = \Auth::user()->id;
$dbLink->code = $dbLink->generateCode();
$dbLink->destination = $bigURL;
$dbLink->clicks = "0";
$dbLink->save();
\Auth::user()->quota_used += 1;
\Auth::user()->save();
}
$linkCode = $dbLink->code;
$linkURL = \Request::root() . '/' . $linkCode;
return \Response::json(array('ok' => array('code' => 'LINK-SHORTENED', 'http_code' => '200', 'message' => 'OK', 'data' => array('url' => $linkURL, 'url_code' => $linkCode))), 200);
}
示例4: addLink
public function addLink($url, $user = null)
{
/** @var myModel $this */
$link = new Link();
$user = $user ?: \Phalcon\Di::getDefault()->get('auth');
$link->save(['url' => $url, 'user_id' => $user->id, 'linkable_type' => get_class($this), 'linkable_id' => $this->id]);
if (property_exists($this, 'linkCount')) {
$this->increaseCount('linkCount');
}
return $this;
}
示例5: run
public function run()
{
$model = new Link();
if (isset($_POST['Link'])) {
$model->attributes = $_POST['Link'];
$model->logo = isset($_POST['logo']) ? $_POST['logo'] : '';
if ($model->save()) {
$this->controller->message('success', Yii::t('admin', 'Add Success'), $this->controller->createUrl('index'));
}
}
$this->controller->render('create', array('model' => $model));
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Link();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Link'])) {
$model->attributes = $_POST['Link'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例7: actionCreate
/**
* 录入
*
*/
public function actionCreate()
{
parent::_acl('link_create');
$model = new Link();
if (isset($_POST['Link'])) {
$model->attributes = $_POST['Link'];
if ($model->save()) {
AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入友情链接,ID:' . $model->id));
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model));
}
示例8: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
if ($this->menu_use[12]) {
$model = new Link();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Link'])) {
$_POST['Link']['user_id'] = Yii::app()->user->id;
$model->attributes = $_POST['Link'];
if ($model->save()) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model));
} else {
$this->redirect(array('site/index'));
}
}
示例9: actionLinkCreate
/**
* 链接录入
*
*/
public function actionLinkCreate()
{
parent::_acl('link_create');
$model = new Link();
if (isset($_POST['Link'])) {
$model->attributes = $_POST['Link'];
$file = XUpload::upload($_FILES['attach']);
if (is_array($file)) {
$model->attach_file = $file['pathname'];
$model->link_type = 'image';
}
if ($model->save()) {
XXcache::refresh('_link');
AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入友情链接,ID:' . $model->id));
$this->redirect(array('link'));
}
}
$this->render('link_create', array('model' => $model));
}
示例10: actionCreate
/**
* 添加新链接
*
*/
public function actionCreate()
{
$model = new Link();
if (isset($_POST['Link'])) {
$model->attributes = $_POST['Link'];
if ($_FILES['logo']['error'] == UPLOAD_ERR_OK) {
$upload = new Uploader();
$upload->uploadFile($_FILES['logo']);
if ($upload->_error) {
$this->message('error', Yii::t('admin', $upload->_error));
return;
}
$model->logo = $upload->_file_name;
}
if ($model->save()) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model));
}
示例11: fill_db_course
/**
* Fills the course database with some required content and example content.
* @param int Course (int) ID
* @param string Course directory name (e.g. 'ABC')
* @param string Language used for content (e.g. 'spanish')
* @param bool Whether to fill the course with example content
* @return bool False on error, true otherwise
* @version 1.2
* @assert (null, '', '', null) === false
* @assert (1, 'ABC', null, null) === false
* @assert (1, 'TEST', 'spanish', true) === true
*/
public static function fill_db_course($course_id, $course_repository, $language, $fill_with_exemplary_content = null)
{
if (is_null($fill_with_exemplary_content)) {
$fill_with_exemplary_content = api_get_setting('course.example_material_course_creation') != 'false';
}
$course_id = intval($course_id);
if (empty($course_id)) {
return false;
}
$entityManager = Database::getManager();
$course = $entityManager->getRepository('ChamiloCoreBundle:Course')->find($course_id);
$tools = array();
$settingsManager = CourseManager::getCourseSettingsManager();
$settingsManager->setCourse($course);
$toolList = CourseManager::getToolList();
$toolList = $toolList->getTools();
/** @var Chamilo\CourseBundle\Tool\BaseTool $tool */
foreach ($toolList as $tool) {
$visibility = self::string2binary(api_get_setting_in_list('course.active_tools_on_create', $tool->getName()));
$toolObject = new CTool();
$toolObject->setName($tool->getName())->setCategory($tool->getCategory())->setLink($tool->getLink())->setImage($tool->getImage())->setVisibility($visibility)->setAdmin(0)->setTarget($tool->getTarget());
$tools[] = $toolObject;
$settings = $settingsManager->loadSettings($tool->getName());
$settingsManager->saveSettings($tool->getName(), $settings);
}
$course->setTools($tools);
$entityManager->persist($course);
$entityManager->flush($course);
$courseInfo = api_get_course_info_by_id($course_id);
$now = api_get_utc_datetime(time());
$tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST);
$TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO);
$TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY);
$TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA);
$TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT);
$TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
$TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
$TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING);
$TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY);
$TABLEFORUMS = Database::get_course_table(TABLE_FORUM);
$TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD);
$TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST);
$TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$visible_for_all = 1;
$visible_for_course_admin = 0;
$visible_for_platform_admin = 2;
/* Course tools */
$alert = api_get_setting('exercise.email_alert_manager_on_new_quiz');
if ($alert === 'true') {
$defaultEmailExerciseAlert = 1;
} else {
$defaultEmailExerciseAlert = 0;
}
/* course_setting table (courseinfo tool) */
$settings = ['email_alert_manager_on_new_doc' => ['default' => 0, 'category' => 'work'], 'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'], 'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'], 'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'], 'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'], 'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'], 'course_theme' => ['default' => '', 'category' => 'theme'], 'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'], 'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'], 'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' => 'registration'], 'allow_user_view_user_list' => ['default' => 1, 'category' => 'user'], 'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'], 'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'], 'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'], 'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'], 'allow_public_certificates' => ['default' => api_get_setting('course.allow_public_certificates') === 'true' ? 1 : '', 'category' => 'certificates'], 'documents_default_visibility' => ['default' => 'visible', 'category' => 'document']];
/*$counter = 1;
foreach ($settings as $variable => $setting) {
Database::query(
"INSERT INTO $TABLESETTING (id, c_id, variable, value, category)
VALUES ($counter, $course_id, '".$variable."', '".$setting['default']."', '".$setting['category']."')"
);
$counter++;
}*/
/* Course homepage tools for platform admin only */
/* Group tool */
Database::query("INSERT INTO {$TABLEGROUPCATEGORIES} (c_id, id, title , description, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)\n VALUES ({$course_id}, '2', '" . self::lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');");
/* Example Material */
$language_interface = !empty($language_interface) ? $language_interface : api_get_setting('language.platform_language');
// Example material should be in the same language as the course is.
$language_interface_original = $language_interface;
$now = api_get_utc_datetime();
$files = [['path' => '/shared_folder', 'title' => get_lang('UserFolders'), 'filetype' => 'folder', 'size' => 0], ['path' => '/chat_files', 'title' => get_lang('ChatFiles'), 'filetype' => 'folder', 'size' => 0]];
$counter = 1;
foreach ($files as $file) {
self::insertDocument($course_id, $counter, $file);
$counter++;
}
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$chat_path = $sys_course_path . $course_repository . '/document/chat_files';
//.........这里部分代码省略.........
示例12: ID
<?php
require '../../../lib/link.php';
require '../../../lib/id.php';
require '../../../lib/vote.php';
Link::set_db('sqlite:../../../heer.db');
Vote::set_db('sqlite:../../../heer.db');
ID::set_seed(file_get_contents('../../../seed'));
$url = $_GET['u'];
$title = $_GET['t'];
$bookmarklet = new ID($_GET['i']);
$vote = new Vote($url, $bookmarklet);
if ($_GET['n']) {
$vote->note = $_GET['n'];
}
$link = new Link($url, $title);
if ($bookmarklet->isAuthentic() && $vote->save()) {
$link->save();
}
header("Location: {$url}");
示例13: save_link
function save_link($type, $size, $url, $nick, $saved_file)
{
global $fetch_log;
$title = $url;
if (stristr($type, 'text/html') !== false && $size < FIVE_MEGS) {
if (preg_match('!<title>(?<title>.*?)</title>!sim', file_get_contents($saved_file), $match)) {
$title = html_entity_decode($match['title']);
}
}
unlink($saved_file);
if (ORM::all('link', array('url' => $url))->count() === 0) {
$link = new Link(array('nick' => $nick, 'title' => $title, 'url' => $url, 'ctime' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME'])));
$link->save();
} else {
file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\tduplicate link\t{$url}\n", FILE_APPEND);
}
}
示例14: postCreateLink
public function postCreateLink()
{
if (Input::get('form') == 'form_main') {
//var_dump(Input::all());
$rules = array('name' => 'required|unique:links,name', 'img' => 'image|mimes:jpg,jpeg,png,gif', 'link' => 'required', 'descript' => 'required', 'middlecategories' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/admin/link/create')->withErrors($validator)->withInput(Input::all());
} else {
$check = true;
if (Input::hasFile('file')) {
$file = Input::file('img');
//$fileName = $file->getClientOriginalName();
$archivo = value(function () use($file) {
$filename = str_random(34) . '.' . $file->getClientOriginalExtension();
return strtolower($filename);
});
//var_dump($archivo);
$destinationPath = 'uploads/';
// Move file to generated folder
$check = $file->move($destinationPath, $archivo);
}
if ($check) {
$link = new Link();
$link->name = Input::get('name');
$link->link = Input::get('link');
$link->descript = Input::get('descript');
$link->img = NULL;
if (Input::hasFile('file')) {
$link->img = $archivo;
}
if (Input::get('gov')) {
$link->gov_id = Input::get('gov_id');
}
if (Input::get('middlecategories')) {
$link->middle_categories_id = Input::get('middlecategories');
} else {
$link->middle_categories_id = 3;
}
$link->frequency = 0;
$link->save();
/* @var \Elasticquent\ElasticquentTrait $link */
$link->addToIndex();
Session::flash('message', "สร้าง " . Input::get('name') . " สำเร็จ!!");
return Redirect::to('/admin/link/create');
} else {
$messages = $validator->errors();
$messages->add('img', 'มีข้อผิดพลาดระหว่างการอัพโหลดรูป กรุณาลองอีกครั้ง');
return Redirect::to('/admin/link/create')->withErrors($messages)->withInput(Input::all());
}
}
} else {
if (Request::ajax() && Input::get('form') == 'form_uc') {
$data = new UserCategories();
$data->name = Input::get('name');
$data->save();
} else {
if (Request::ajax() && Input::get('form') == 'form_mjc') {
$data = new MajorCategories();
$data->name = Input::get('name');
$data->user_categories_id = 6;
$data->save();
} else {
if (Request::ajax() && Input::get('form') == 'form_mdc') {
$data = new MiddleCategories();
$data->name = Input::get('name');
$data->major_categories_id = 6;
$data->save();
}
}
}
}
}
示例15: actionAddLink
public function actionAddLink()
{
if (isset($_POST['dataset_id']) && isset($_POST['database']) && isset($_POST['acc_num'])) {
// if(!is_numeric($_POST['acc_num'])) {
// Util::returnJSON(array("success"=>false,"message"=>Yii::t("app", "Please enter a number.")));
// }
$linkVal = $_POST['database'] . ":" . $_POST['acc_num'];
$link = Link::model()->findByAttributes(array('dataset_id' => $_POST['dataset_id'], 'link' => $linkVal));
if ($link) {
Util::returnJSON(array("success" => false, "message" => Yii::t("app", "This link has been added already.")));
}
$link = new Link();
$link->dataset_id = $_POST['dataset_id'];
$link->is_primary = true;
$link->link = $linkVal;
if ($link->save()) {
Util::returnJSON(array("success" => true));
}
Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Save Error.")));
}
}