Author: Florian Eckerstorfer (florian@eckerstorfer.co)
Author: Ivo Bathke (ivo.bathke@gmail.com)
Author: Marchenko Alexandr
Inheritance: implements Cocur\Slugify\SlugifyInterface
Exemplo n.º 1
0
 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;
 }
 public function search($tags)
 {
     $searchUrl = self::CPASBIEN_BASE_URL . '/recherche/' . $this->slugifier->slugify($tags) . '.html';
     $dom = HtmlDomParser::file_get_html($searchUrl);
     $lignes0 = $dom->find('div[class=ligne0]');
     $lignes1 = $dom->find('div[class=ligne1]');
     $torrentsLigne0 = array();
     foreach ($lignes0 as $torrentLigne0) {
         array_push($torrentsLigne0, $this->parseHtmlToTorrent($torrentLigne0));
     }
     $torrentsLigne1 = array();
     foreach ($lignes1 as $torrentLigne1) {
         array_push($torrentsLigne1, $this->parseHtmlToTorrent($torrentLigne1));
     }
     //merge array to respect website order result
     $result = array();
     $index0 = $index1 = 0;
     for ($i = 0; $i < count($torrentsLigne0) + count($torrentsLigne1); $i++) {
         if ($i % 2 == 0) {
             array_push($result, $torrentsLigne0[$index0]);
             $index0++;
         } else {
             array_push($result, $torrentsLigne1[$index1]);
             $index1++;
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * @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()));
 }
 /**
  * @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'));
 }
Exemplo n.º 5
0
 /**
  * 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";
     }
 }
Exemplo n.º 6
0
 /**
  * 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!";
     }
 }
Exemplo n.º 7
0
 /**
  * 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);
 }
 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;
 }
Exemplo n.º 9
0
 /**
  * @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);
 }
Exemplo n.º 10
0
 protected function preSave(Object $object)
 {
     // set slug
     if (Text::create($object->getSlug())->isEmpty()) {
         $slugifier = new Slugify();
         $object->setSlug($slugifier->slugify($object->getTitle()));
     }
 }
Exemplo n.º 11
0
 /**
  * @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));
     }
 }
Exemplo n.º 12
0
 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);
 }
 /**
  * @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, '_'));
 }
Exemplo n.º 14
0
 /**
  * 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);
 }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 /**
  * @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();
 }
Exemplo n.º 17
0
 public function fill(array $attributes)
 {
     parent::fill($attributes);
     if (array_key_exists('slug', $attributes) === false && array_key_exists('title', $attributes)) {
         // create slug
         $slugify = new Slugify();
         $this->slug = $slugify->slugify($attributes['title']);
     }
     return $this;
 }
Exemplo n.º 18
0
 /**
  * Updates the specified Article.
  *
  * @param $id string
  * @param $title string
  * @param $content string
  * @return void
  */
 public static function UpdateArticle($id, $title, $content)
 {
     $slugify = new Slugify();
     $article = Article::find($id);
     $article->title = $title;
     $article->title_slug = $slugify->slugify($title);
     $article->content_markdown = $content;
     $article->content = Parsedown::instance()->setMarkupEscaped(true)->text($content);
     $article->save();
 }
 public function __construct($name = null)
 {
     parent::__construct();
     // Load Twig templates
     $loader = new \Twig_Loader_Filesystem(getcwd() . '/src/templates');
     $this->twig = new \Twig_Environment($loader, array('debug' => false));
     $this->twig->addExtension(new \Twig_Extension_Debug());
     // Custom filter for parsing the endpoint URI
     $this->twig->addFilter(new \Twig_SimpleFilter('parseUri', function ($baseUrl, $uriTemplate, $action) {
         // Check if the URI Template has parameters
         if (strpos($uriTemplate, '{?') !== false) {
             $resultString = preg_match('/{(.*?)}/', $uriTemplate, $matches);
             $resultString = $matches[1];
             if (strpos($resultString, '?') !== false) {
                 $resultString = str_replace(',', '&', substr($resultString, 1));
                 $urlParameters = explode('&', $resultString);
             }
             foreach ($urlParameters as $key => $urlParameter) {
                 $urlParameters[$key] = $urlParameter . '=' . $action['parameters'][$key]['example'];
             }
             $start = strpos($uriTemplate, '{');
             $convertedUrl = substr_replace($uriTemplate, '', $start);
             foreach ($urlParameters as $key => $urlParameter) {
                 $convertedUrl .= ($key === 0 ? '?' : '&') . $urlParameter;
             }
         } else {
             if (strpos($uriTemplate, '{') !== false) {
                 foreach ($action['parameters'] as $parameter) {
                     $convertedUrl = str_replace('{' . $parameter['name'] . '}', $parameter['example'], $uriTemplate);
                 }
             } else {
                 $convertedUrl = $uriTemplate;
             }
         }
         return $baseUrl . $convertedUrl;
     }));
     // Custom filter for parsing Markdown
     $this->twig->addFilter(new \Twig_SimpleFilter('markdown', function ($string) {
         return Markdown::defaultTransform($string);
     }));
     // Custom filter for creating a slug with an optional prefix/suffix
     $this->twig->addFilter(new \Twig_SimpleFilter('slugify', function ($string, $prefix = null, $suffix = null) {
         $slugify = new Slugify();
         return $slugify->slugify($prefix . $string . $suffix);
     }));
     // Custom filter for extracting keys from a multidimensional array
     $this->twig->addFilter(new \Twig_SimpleFilter('arrayFromKey', function ($array, $key) {
         $result = array();
         foreach ($array as $value) {
             $result[] = $value[$key];
         }
         return $result;
     }));
 }
Exemplo n.º 20
0
 /**
  * @param array $value
  * @param string $prefix
  * @param string $separator
  * @return string
  */
 public function render(array $value = null, $prefix = '', $separator = ' ')
 {
     $slugify = new Slugify();
     if ($value === null) {
         $value = $this->renderChildren();
     }
     $value = array_map(function ($item) use($prefix, $slugify) {
         return mb_strtolower($prefix . $slugify->slugify($item));
     }, $value);
     return implode($separator, $value);
 }
Exemplo n.º 21
0
 public function setFile($file)
 {
     $slugify = new Slugify();
     $upload_directory = $this->getUploadDirectory();
     $filename_without_extension = str_replace("." . $file->getClientOriginalExtension(), "", $file->getClientOriginalName());
     $filename = $slugify->slugify($filename_without_extension) . "." . $file->getClientOriginalExtension();
     $filepath = $upload_directory . "/" . $filename;
     $file = $file->move($upload_directory, $filename);
     $this->setFilename($filename);
     $this->setFilepath($filepath);
     return $this;
 }
Exemplo n.º 22
0
 /**
  * Slugify
  *
  * @param string $text
  * @return string
  */
 public function slugify($text)
 {
     $slugged = $this->slugify->slugify($text);
     $count = 1;
     $orig = $slugged;
     while (in_array($slugged, $this->used)) {
         $slugged = $orig . '-' . $count;
         $count++;
     }
     $this->used[] = $slugged;
     return $slugged;
 }
Exemplo n.º 23
0
 /**
  * @param $string
  * @return string
  */
 public static function genSlug($string)
 {
     //		return $string;
     //$accepted = implode(self::$MY_RULE);
     //$replace_char = "/([^a-zA-Z0-9" . $accepted . "]|-)+/u";
     //echo $replace_char;
     $slug_engine = new Slugify();
     //new Slugify($replace_char);
     $slug_engine->addRules(self::$MY_RULE);
     $slug_engine->addRule('#', '-sharp-');
     $slug_engine->addRule('+', '-plus-');
     return $slug_engine->slugify($string);
 }
Exemplo n.º 24
0
 /**
  * Show available jobs
  */
 public function indexAction()
 {
     $jobs = $this->jobConfigurationRepository->findAll();
     $tags = [];
     foreach ($jobs as $job) {
         $tags = array_merge($tags, $job->getTags());
     }
     $slugify = new Slugify();
     $tags = array_map(function ($tag) use($slugify) {
         return $slugify->slugify(mb_strtolower($tag));
     }, array_unique($tags));
     $this->view->assignMultiple(['jobs' => $jobs, 'tags' => $tags]);
 }
Exemplo n.º 25
0
 public function setNameAttribute($value)
 {
     // censor name
     $censor = new CensorWords();
     $badwords = $censor->setDictionary(array('es', 'en-us', 'en-uk'));
     $cname = $censor->censorString($value);
     $name = $cname['clean'];
     $this->attributes['name'] = $name;
     // generates uri slug
     $slugify = new Slugify();
     $this->attributes['slug'] = $slugify->slugify($name);
     // TODO - generates short url of this place
     // $this->attributes['googl'] = '';
 }
Exemplo n.º 26
0
 /**
  * Returns a link for a file
  *
  * @param  File   $file
  * @return string Link
  */
 protected function getBaseLink(File $file)
 {
     $folder = $this->folderRepository->find($file->getFolderId());
     $beautifurl = explode('/', $folder->getUrl());
     $beautifurl = array_filter($beautifurl, function ($beautifurl) {
         return (bool) $beautifurl;
     });
     $beautifurl = array_map(function ($fragment) {
         return $this->slugifier->slugify($fragment);
     }, $beautifurl);
     $beautifurl[] = $file->getName();
     $beautifurl = implode(DIRECTORY_SEPARATOR, $beautifurl);
     return $beautifurl;
 }
Exemplo n.º 27
0
 /**
  * Operate the transformation
  *
  * @param string $input
  * @param array  $arguments
  *
  * @throws Inet\Transformation\Exception\TransformationException
  *
  * @return string
  */
 public function transform($input, $arguments)
 {
     // I should have two arguments: old format / new format
     if (count($arguments) !== 0) {
         throw new TransformationException('Rule Slugify Expects no parameter');
     }
     try {
         $slugify = new CocurSlugify();
         $output = $slugify->slugify($input);
     } catch (\Exception $e) {
         throw new TransformationException("Input ({$input}) seems not valid");
     }
     return $output;
 }
Exemplo n.º 28
0
 /**
  * Set name
  *
  * @param string $name
  *
  * @return RecruitmentStatus
  */
 public function setName($name)
 {
     $slugify = new Slugify();
     $this->name = $name;
     $this->setSlug($slugify->slugify($this->name));
     return $this;
 }
Exemplo n.º 29
0
 /**
  * Adds the WP-specific filters and functions to the twig environment
  * @param \Twig_Environment $twig_Environment
  */
 private static function extendTwig(\Twig_Environment $twig_Environment)
 {
     $twig_Environment->addFilter(new \Twig_SimpleFilter('__', function ($text, $domain = 'default') {
         return __($text, $domain);
     }));
     $twig_Environment->addExtension(new SlugifyExtension(Slugify::create()));
 }
 /**
  * @Route("/registration", name="civix_front_group_registration")
  * @Method({"GET", "POST"})
  */
 public function registrationAction()
 {
     $form = $this->createForm(new Registration(), new Group());
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         if ($form->isValid()) {
             /** @var $group Group */
             $group = $form->getData();
             $password = $group->getPassword();
             $encoder = $this->get('security.encoder_factory')->getEncoder($group);
             $encodedPassword = $encoder->encodePassword($password, $group->getSalt());
             $group->setPassword($encodedPassword);
             $slugify = new Slugify();
             $groupName = $slugify->slugify($group->getOfficialName(), '');
             /*
                             $mailgun = $this->get('civix_core.mailgun')->listcreateAction($groupName,$group->getOfficialDescription(),$group->getManagerEmail(),$group->getManagerFirstName().' '.$group->getManagerLastName());
             
                             if($mailgun['http_response_code'] != 200){
             
                                 return $this->render('CivixFrontBundle:Group:error.html.twig');
                             }*/
             /** @var $entityManager \Doctrine\ORM\EntityManager */
             $entityManager = $this->getDoctrine()->getManager();
             $entityManager->persist($group);
             $entityManager->flush();
             //send notification
             $this->get('civix_core.email_sender')->sendRegistrationSuccessGroup($group, $password);
             return $this->render('CivixFrontBundle:Group:thanks.html.twig');
         }
     }
     return $this->render('CivixFrontBundle:Group:registration.html.twig', array('form' => $form->createView()));
 }