当前位置: 首页>>代码示例>>PHP>>正文


PHP Slugify\Slugify类代码示例

本文整理汇总了PHP中Cocur\Slugify\Slugify的典型用法代码示例。如果您正苦于以下问题:PHP Slugify类的具体用法?PHP Slugify怎么用?PHP Slugify使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Slugify类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bundlePost

 function bundlePost($request)
 {
     $data = $request->except(['subdoot']);
     $slugify = new Slugify();
     $data['slug'] = $slugify->slugify($request->get('title'), '_');
     if (strlen($data['slug']) > 46) {
         $data['slug'] = substr($data['slug'], 0, 46);
     }
     //6 character string for a permalink
     $permalink = $this->generateRandomString();
     //Make sure the permalink is unique
     while (Post::wherePermalink($permalink)->exists()) {
         $permalink = $this->generateRandomString();
     }
     $data['permalink'] = $permalink;
     //Insert the post into the db
     $post = new Post($data);
     //Attach the post to the user who created it
     //$post->user()->associate(\App\User::find(Auth::user()->id));
     // $user = \App\User::find(Auth::user()->id);
     // $subdoot = Subdoot::find($request->get('subdoot'));
     // $user->posts()->save($post);
     // $subdoot->posts()->save($post);
     $post->user()->associate(\App\User::find(Auth::user()->id));
     $post->save();
     $post->subdoot()->associate(Subdoot::find($request->get('subdoot')));
     $post->save();
     //Attach the post to the subdoot it was submitted in
     //$post->subdoot()->associate(Subdoot::find($request->get('subdoot')));
     return $post;
 }
开发者ID:nehero,项目名称:updoot,代码行数:31,代码来源:SubdootController.php

示例2: postSave

 /**
  * @param Picture $picture
  * @param array $data
  */
 protected function postSave(Picture $picture, array $data)
 {
     if (isset($data['meta']) && isset($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $slugifier = new Slugify();
         $filename = sprintf('%s-%u.%s', $slugifier->slugify($picture->getAthlete()), $picture->getId(), $file->getExtension());
         $filepath = $module->getPicturesPath($picture->getSkill())->append($filename);
         $file->move($filepath);
         // create thumb folder
         $thumbspath = $module->getPicturesPath($picture->getSkill())->append('thumbs');
         $dir = new Directory($thumbspath);
         if (!$dir->exists()) {
             $dir->make();
         }
         // create thumb
         $imagine = new Imagine();
         $image = $imagine->open($filepath->toString());
         $max = max($image->getSize()->getWidth(), $image->getSize()->getHeight());
         $width = $image->getSize()->getWidth() / $max * self::THUMB_MAX_SIZE;
         $height = $image->getSize()->getHeight() / $max * self::THUMB_MAX_SIZE;
         $size = new Box($width, $height);
         $thumbpath = $thumbspath->append($filename);
         $image->thumbnail($size)->save($thumbpath->toString());
         // save to picture
         $picture->setUrl($module->getPicturesUrl($picture->getSkill()) . '/' . $filename);
         $picture->setThumbUrl($module->getPicturesUrl($picture->getSkill()) . '/thumbs/' . $filename);
         $picture->save();
     }
     // activity
     $user = $this->getServiceContainer()->getAuthManager()->getUser();
     $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $picture, 'target' => $picture->getSkill()));
 }
开发者ID:gossi,项目名称:trixionary,代码行数:37,代码来源:PictureDomain.php

示例3: removeGroupAction

 /**
  * @Route("/remove/{id}", name="civix_front_superuser_group_remove")
  * @Method({"POST"})
  */
 public function removeGroupAction(Group $group)
 {
     $entityManager = $this->getDoctrine()->getManager();
     /** @var $csrfProvider \Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider */
     $csrfProvider = $this->get('form.csrf_provider');
     if ($csrfProvider->isCsrfTokenValid('remove_group_' . $group->getId(), $this->getRequest()->get('_token'))) {
         $slugify = new Slugify();
         $groupName = $slugify->slugify($group->getOfficialName(), '');
         $mailgun = $this->get('civix_core.mailgun')->listremoveAction($groupName);
         if ($mailgun['http_response_code'] != 200) {
             $this->get('session')->getFlashBag()->add('error', 'Something went wrong removing the group from mailgun');
             return $this->redirect($this->generateUrl('civix_front_superuser_manage_groups'));
         }
         try {
             $this->get('civix_core.customer_manager')->removeCustomer($group);
         } catch (\Exception $e) {
             $this->get('session')->getFlashBag()->add('error', $e->getMessage());
             return $this->redirect($this->generateUrl('civix_front_superuser_manage_groups'));
         }
         $entityManager->getRepository('CivixCoreBundle:Group')->removeGroup($group);
         $this->get('session')->getFlashBag()->add('notice', 'Group was removed');
     } else {
         $this->get('session')->getFlashBag()->add('error', 'Something went wrong');
     }
     return $this->redirect($this->generateUrl('civix_front_superuser_manage_groups'));
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:30,代码来源:GroupController.php

示例4: postSavePage

 /**
  * Saved edited page; called via ajax
  * @return string
  */
 public function postSavePage()
 {
     $okay = true;
     $page_id = $_REQUEST['page_id'];
     $page_content = $_REQUEST['thedata'];
     if ($page_id > 0) {
         $page = Page::find($page_id);
     } else {
         $page = new Page();
         $slugify = new Slugify();
         $browser_title = $_REQUEST['browser_title'];
         $page->browser_title = $browser_title;
         $page->slug = $slugify->slugify($browser_title);
         // verify that the slug is not already in the db
         $results = Page::where('slug', '=', $slugify->slugify($browser_title))->get();
         foreach ($results as $result) {
             $okay = false;
         }
     }
     $page->page_content = $page_content;
     if ($okay) {
         $page->save();
         echo "OK";
     } else {
         echo "Browser Title already in use";
     }
 }
开发者ID:pagchen,项目名称:acme,代码行数:31,代码来源:AdminController.php

示例5: postSavePage

 /**
  * Saved edited page; called via ajax
  * @return string
  */
 public function postSavePage()
 {
     $okay = true;
     $page_id = $this->request->input('page_id');
     $page_content = $this->request->input('thedata');
     if ($page_id > 0) {
         $page = Page::find($page_id);
     } else {
         $page = new Page();
         $slugify = new Slugify();
         $browser_title = $this->request->input('broswer_title');
         $page->browser_title = $browser_title;
         $page->slug = $slugify->slugify($browser_title);
         $results = Page::where('slug', '=', $slugify->slugify($browser_title))->first();
         if ($results) {
             $okay = false;
         }
     }
     $page->page_content = $page_content;
     if ($okay) {
         $page->save();
         echo "OK";
     } else {
         echo "Browser title is already in use!";
     }
 }
开发者ID:tsawler,项目名称:phpunit-testing,代码行数:30,代码来源:AdminController.php

示例6: run

 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $file = $request->files->get('file');
     try {
         // validate: upload progress
         if (!$file->isValid()) {
             throw new FileException($file->getErrorMessage());
         }
         // validate: mime type
         $mimeTypes = ['image/png', 'image/jpeg', 'image/jpg', 'video/mp4', 'video/quicktime'];
         if (!in_array($file->getClientMimeType(), $mimeTypes)) {
             throw new FileException('No matching mime type');
         }
         // validate: extension
         $exts = ['png', 'jpg', 'jpeg', 'mp4', 'mov'];
         if (!in_array($file->getClientOriginalExtension(), $exts)) {
             throw new FileException('No matching extension');
         }
         // move uploaded file
         $slugifier = new Slugify();
         $fileName = $file->getClientOriginalName();
         $fileName = str_replace('.' . $file->getClientOriginalExtension(), '', $fileName);
         $fileName = $slugifier->slugify($fileName) . '.' . $file->getClientOriginalExtension();
         $file->move($this->getModule()->getUploadPath()->toString(), $fileName);
         $payload = new Success(['filename' => $fileName, 'url' => $this->getModule()->getUploadUrl() . '/' . urlencode($fileName)]);
     } catch (FileException $e) {
         $payload = new Failed(['error' => $e->getMessage()]);
     }
     return $this->responder->run($request, $payload);
 }
开发者ID:gossi,项目名称:trixionary,代码行数:36,代码来源:UploadAction.php

示例7: saveInvites

 public function saveInvites(array $emails, Group $group)
 {
     $emails = array_diff($emails, $this->entityManager->getRepository('CivixCoreBundle:DeferredInvites')->getEmails($group, $emails));
     $users = $this->entityManager->getRepository('CivixCoreBundle:User')->getUsersByEmails($emails);
     $usersEmails = array();
     $invites = array();
     $slugify = new Slugify();
     $groupName = $slugify->slugify($group->getOfficialName(), '');
     /** @var $user \Civix\CoreBundle\Entity\User */
     foreach ($users as $user) {
         if (!$group->getInvites()->contains($user) && !$group->getUsers()->contains($user)) {
             $this->mailgun->listaddmemberAction($groupName, $user->getEmail(), $user->getUsername());
             $user->addInvite($group);
             $invites[] = $user;
             $usersEmails[] = $user->getEmail();
         }
     }
     foreach (array_diff($emails, $usersEmails) as $email) {
         $deferredInvite = $this->createDeferredInvites($email, $group);
         $this->entityManager->persist($deferredInvite);
         $invites[] = $deferredInvite;
     }
     $this->entityManager->flush();
     return $invites;
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:25,代码来源:InviteSender.php

示例8: prePersist

 /**
  * @param \Acme\BasicCmsBundle\Document\Page $document
  * @return void
  */
 public function prePersist($document)
 {
     $slugify = new Slugify();
     $document->setSlug($slugify->slugify($document->getTitle()));
     $parent = $this->getModelManager()->find(null, '/cms/pages');
     $document->setParentDocument($parent);
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:11,代码来源:PageAdmin.php

示例9: preSave

 protected function preSave(Object $object)
 {
     // set slug
     if (Text::create($object->getSlug())->isEmpty()) {
         $slugifier = new Slugify();
         $object->setSlug($slugifier->slugify($object->getTitle()));
     }
 }
开发者ID:gossi,项目名称:trixionary,代码行数:8,代码来源:ObjectDomain.php

示例10: preCreate

 /**
  * @param Group $model
  */
 protected function preCreate(Group $model)
 {
     if (Text::create($model->getSlug())->isEmpty()) {
         $title = $model->getTitle();
         $slugifier = new Slugify();
         $model->setSlug($slugifier->slugify($title));
     }
 }
开发者ID:gossi,项目名称:trixionary,代码行数:11,代码来源:GroupDomain.php

示例11: isUnique

 private function isUnique($data)
 {
     $rooms = $this->service->get('rooms');
     $name = htmlentities($data['name']);
     $slugify = new Slugify();
     $slug = $slugify->slugify($name);
     return !RoomFinder::set($rooms)->findOneBySlug($slug);
 }
开发者ID:nirgendswo,项目名称:justText,代码行数:8,代码来源:Room.php

示例12: invoke

 /**
  * @test
  * @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelper::__invoke()
  */
 public function invoke()
 {
     $actual = 'Hällo Wörld';
     $expected = call_user_func($this->viewHelper, $actual);
     $this->assertEquals($expected, $this->slugify->slugify($actual));
     $expected = call_user_func($this->viewHelper, $actual, '_');
     $this->assertEquals($expected, $this->slugify->slugify($actual, '_'));
 }
开发者ID:ferch01991,项目名称:BlogLaravel,代码行数:12,代码来源:SlugifyViewHelperTest.php

示例13: getFilename

 /**
  * Return the filename which is passed or get from file
  * Filename is slug.
  *
  * @param UploadedFile $image
  * @param $filename
  * @return string
  */
 protected function getFilename(UploadedFile $image, $filename)
 {
     if (empty($filename)) {
         // use filename from uploaded file
         $filename = str_replace('.' . $image->getClientOriginalExtension(), '', $image->getClientOriginalName());
     }
     $slugify = new Slugify();
     return $slugify->slugify($filename);
 }
开发者ID:alcodo,项目名称:powerimage,代码行数:17,代码来源:CreateImage.php

示例14: titleToTags

 public function titleToTags($title)
 {
     $slugify = new Slugify();
     $stopwords = array('with', 'your', 'and', 'for', 'the', 'com', 'iii', 'fuer', 'mit', 'der', 'die', 'das', 'org', 'und', 'you', 'net', 'from');
     $tags = array_slice(array_unique(array_filter(explode(' ', $slugify->slugify($title, ' ')), function ($tag) use($stopwords) {
         return strlen($tag) >= 3 && !in_array($tag, $stopwords);
     })), 0, 10);
     return count($tags) == 0 ? 'untagged' : implode(',', $tags);
 }
开发者ID:emilyemorehouse,项目名称:readlater,代码行数:9,代码来源:TagTransformer.php

示例15: preSave

 /**
  * @param Skill $skill
  * @param mixed $data
  */
 protected function preSave(Skill $skill)
 {
     // set slug
     if (Text::create($skill->getSlug())->isEmpty()) {
         $name = str_replace('°', '', $skill->getName());
         $slugifier = new Slugify();
         $skill->setSlug($slugifier->slugify($name));
     }
     $this->isNew = $skill->isNew();
 }
开发者ID:gossi,项目名称:trixionary,代码行数:14,代码来源:SkillDomain.php


注:本文中的Cocur\Slugify\Slugify类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。