/** * Convert any passed string to a url friendly string. Converts 'My first blog post' to 'my-first-blog-post' * * @param string $text Text to urlize * @return string $text Urlized text */ public static function doctrine_urlize($text) { // Transliteration $text = self::transliterate($text); // Urlize return Doctrine_Inflector::urlize($text); }
public function executeAddDocument(sfWebRequest $request) { $this->forward404Unless($request->isMethod(sfRequest::PUT)); $document = $request->getParameter('document'); $this->transaction = TransactionTable::getInstance()->find($document['transaction_id']); $asso = AssoTable::getInstance()->find($document['asso_id']); $this->checkAuthorisation($asso); $form = new DocumentForm(); $files = $request->getFiles($form->getName()); $form->bind($request->getParameter($form->getName()), $files); $infos = new finfo(FILEINFO_MIME_TYPE); if ($form->isValid() and $infos->file($files['fichier']['tmp_name']) == 'application/pdf') { $fichier = $this->transaction->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($files['fichier']['name']); if (substr($fichier, -4) == '-pdf') { $fichier = substr($fichier, 0, -4); } $fichier .= '.pdf'; $form->setValue('fichier', $fichier); $form->setValue('auteur', $this->getUser()->getGuardUser()->getPrimaryKey()); $doc = $form->save(); $path = $doc->getPath(); $dir = substr($path, 0, -strlen($fichier)); if (!is_dir($dir)) { mkdir($dir); } move_uploaded_file($files['fichier']['tmp_name'], $path); $this->redirect('transaction_show', $this->transaction); } else { $this->form = $form; $this->setTemplate('show', $this->transaction); $this->getResponse()->setSlot('current_asso', $asso); } }
public static function sortString($a, $b) { if ($a[0] == $b[0]) { return 0; } return Doctrine_Inflector::urlize($a[0]) < Doctrine_Inflector::urlize($b[0]) ? -1 : 1; }
public function postUp() { $records = Projects_Model_ProjectTable::getInstance()->findAll(); foreach ($records as $record) { if (empty($record->name_slug)) { $record->name_slug = Doctrine_Inflector::urlize($record->name); $record->save(); } } }
public function testGermanCharactersAreConvertedCorrectly() { $this->assertEqual(Doctrine_Inflector::urlize('Ästhetik'), 'aesthetik'); $this->assertEqual(Doctrine_Inflector::urlize('ästhetisch'), 'aesthetisch'); $this->assertEqual(Doctrine_Inflector::urlize('Übung'), 'uebung'); $this->assertEqual(Doctrine_Inflector::urlize('über'), 'ueber'); $this->assertEqual(Doctrine_Inflector::urlize('Öl'), 'oel'); $this->assertEqual(Doctrine_Inflector::urlize('ölig'), 'oelig'); $this->assertEqual(Doctrine_Inflector::urlize('Fuß'), 'fuss'); }
public function postUp() { $table = Doctrine::getTable('News_Model_News'); $records = $table->findAll(); foreach ($records as $record) { if (empty($record->title_slug)) { $record->title_slug = Doctrine_Inflector::urlize($record->title); $record->save(); } } }
/** * Generates a non-random-filename * * @return string A non-random name to represent the current file */ public function generateFilename() { $filename = $this->getOriginalName(); $ext = filter_var($this->getExtension($this->getOriginalExtension()), FILTER_SANITIZE_URL); $name = substr($this->getOriginalName(), 0, -strlen($ext)); $i = 1; while (file_exists($this->getPath() . '/' . $filename)) { $filename = Doctrine_Inflector::urlize($name) . '-' . $i . $ext; $i++; } return $filename; }
protected function buildSlug($record) { if (empty($this->_options['fields'])) { $value = (string) $record; } else { $value = ''; foreach ($this->_options['fields'] as $field) { $value = $record->{$field} . ' '; } } return Doctrine_Inflector::urlize($value); }
public function executeExport(sfWebRequest $request) { $budget = $this->getRoute()->getObject(); $asso = $budget->getAsso(); $this->checkAuthorisation($budget->getAsso()); $categories = $budget->getCategoriesWithEntry()->execute(); $nom = $budget->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($budget->getNom()); $html = $this->getPartial('budget/pdf', compact(array('categories', 'asso', 'budget', 'transactions'))); $doc = new Document(); $doc->setNom('Export du budget prévisionnel'); $doc->setAsso($asso); $doc->setUser($this->getUser()->getGuardUser()); $doc->setTypeFromSlug('budgets'); $path = $doc->generatePDF('Budget Prévisionnel', $nom, $html); header('Content-type: application/pdf'); readfile($path); return sfView::NONE; }
public function beforeSave($event) { if (true !== $this->update && $this->owner->slug) { return parent::beforeSave($event); } if (!is_array($this->columns)) { throw new CException('Columns have to be in array format.'); } $availableColumns = array_keys($this->owner->tableSchema->columns); // Try to guess the right columns if (0 === count($this->columns)) { $this->columns = array_intersect($this->_defaultColumnsToCheck, $availableColumns); } else { // Unknown columns on board? foreach ($this->columns as $col) { if (!in_array($col, $availableColumns)) { throw new CException('Unable to build slug, column ' . $col . ' not found.'); } } } // No columns to build a slug? if (0 === count($this->columns)) { throw new CException('You must define "columns" to your sluggable behavior.'); } // Fetch values $values = array(); foreach ($this->columns as $col) { $values[] = $this->owner->{$col}; } // First version of slug $slug = $checkslug = Doctrine_Inflector::urlize(implode('-', $values)); // Check if slug has to be unique if (false === $this->unique) { $this->owner->slug = $slug; } else { $counter = 0; while ($this->owner->findByAttributes(array('slug' => $checkslug))) { $checkslug = sprintf('%s-%d', $slug, ++$counter); } $this->owner->slug = $counter > 0 ? $checkslug : $slug; } return parent::beforeSave($event); }
private function _deleteRelatedData() { if (!$this->_contentTypeName) { return; } $this->logSection('sympal', sprintf('...deleting data related to Sympal plugin ContentType "%s"', $this->_contentTypeName), null, 'COMMENT'); $lowerName = str_replace('-', '_', Doctrine_Inflector::urlize($this->_contentTypeName)); $slug = 'sample-' . $lowerName; $contentType = Doctrine_Core::getTable('sfSympalContentType')->findOneByName($this->_contentTypeName); // Find content lists related to this conten type $q = Doctrine_Core::getTable('sfSympalContentList')->createQuery('c')->select('c.id, c.content_id')->from('sfSympalContentList c INDEXBY c.content_id')->where('c.content_type_id = ?', $contentType['id']); $contentTypes = $q->fetchArray(); $contentIds = array_keys($contentTypes); // Delete content records related to this content type Doctrine_Core::getTable('sfSympalContent')->createQuery('c')->delete()->where('c.content_type_id = ?', $contentType['id'])->orWhereIn('c.id', $contentIds)->execute(); // Delete menu items related to this content type Doctrine_Core::getTable('sfSympalMenuItem')->createQuery('m')->delete()->where('m.name = ?', array($this->_contentTypeName))->execute(); // Delete the content type record Doctrine_Core::getTable('sfSympalContentType')->createQuery('t')->delete()->where('t.id = ?', $contentType['id'])->execute(); }
public function executeJustificatif(sfWebRequest $request) { $note_de_frais = $this->getRoute()->getObject(); $user = $this->getUser(); $asso = $note_de_frais->getAsso(); $this->checkAuthorisation($asso); $html = $this->getPartial('noteDeFrais/pdf', compact(array('note_de_frais', 'asso', 'user'))); $nom = $note_de_frais->getPrimaryKey() . '-' . date('Y-m-d-H-i-s') . '-' . Doctrine_Inflector::urlize($note_de_frais->getNom()); $doc = new Document(); $doc->setNom('Attestation à signer'); $doc->setAsso($asso); $doc->setUser($this->getUser()->getGuardUser()); $doc->transaction_id = $note_de_frais->transaction_id; $doc->setTypeFromSlug('note_de_frais'); $path = $doc->generatePDF('Note de frais', $nom, $html); $doc->save(); header('Content-type: application/pdf'); readfile($path); return sfView::NONE; }
protected function _createDefaultContentTypeRecords(&$installVars) { $this->logSection('sympal', '...creating default Sympal ContentType records', null, 'COMMENT'); $lowerName = str_replace('-', '_', Doctrine_Inflector::urlize(str_replace('sfSympal', null, $this->_contentTypeName))); $slug = 'sample_' . $lowerName; $properties = array(); $contentType = $this->newContentType($this->_contentTypeName, $properties); $installVars['contentType'] = $contentType; $properties = array('slug' => $slug); $content = $this->newContent($contentType, $properties); $installVars['content'] = $content; $properties = array('slug' => $lowerName, 'ContentType' => Doctrine_Core::getTable('sfSympalContentType')->findOneByName('ContentList')); $contentList = $this->newContent('sfSympalContentList', $properties); $contentList->trySettingTitleProperty('Sample ' . $contentType['label'] . ' List'); $contentList->getRecord()->setContentType($contentType); $installVars['contentList'] = $contentList; $properties = array('date_published' => new Doctrine_Expression('NOW()'), 'label' => str_replace('sfSympal', null, $this->_contentTypeName), 'RelatedContent' => $contentList); $menuItem = $this->newMenuItem($this->_contentTypeName, $properties); $installVars['menuItem'] = $menuItem; $properties = array('body' => '<?php echo get_sympal_breadcrumbs($menuItem, $content) ?><h2><?php echo get_sympal_content_slot($content, \'title\') ?></h2><p><strong>Posted by <?php echo $content->CreatedBy->username ?> on <?php echo get_sympal_content_slot($content, \'date_published\') ?></strong></p><p><?php echo get_sympal_content_slot($content, \'body\') ?></p>'); }
/** * Clean for usage in URLs * * @param $string * @return string */ private function urlize($string) { return Doctrine_Inflector::urlize($string); }
/** * beforeSave * * @param CModelEvent $event * * @throws CException * @access public */ public function beforeSave($event) { // Slug already created and no updated needed if (true !== $this->update && !empty($this->getOwner()->{$this->slugColumn})) { Yii::trace('Slug found - no update needed.', __CLASS__ . '::' . __FUNCTION__); return parent::beforeSave($event); } $availableColumns = array_keys($this->getOwner()->tableSchema->columns); // Try to guess the right columns if (0 === count($this->columns)) { $this->columns = array_intersect($this->_defaultColumnsToCheck, $availableColumns); } else { // Unknown columns on board? foreach ($this->columns as $col) { if (!in_array($col, $availableColumns)) { if (false !== strpos($col, '.')) { Yii::trace('Dependencies to related models found', __CLASS__); list($model, $attribute) = explode('.', $col); $externalColumns = array_keys($this->getOwner()->{$model}->tableSchema->columns); if (!in_array($attribute, $externalColumns)) { throw new CException("Model {$model} does not haz {$attribute}"); } } else { throw new CException('Unable to build slug, column ' . $col . ' not found.'); } } } } // No columns to build a slug? if (0 === count($this->columns)) { throw new CException('You must define "columns" to your sluggable behavior.'); } // Fetch values $values = array(); foreach ($this->columns as $col) { if (false === strpos($col, '.')) { $values[] = $this->getOwner()->{$col}; } else { list($model, $attribute) = explode('.', $col); $values[] = $this->getOwner()->{$model}->{$attribute}; } } // First version of slug if (true === $this->useInflector) { $slug = $checkslug = Doctrine_Inflector::urlize(implode('-', $values)); } else { $slug = $checkslug = $this->simpleSlug(implode('-', $values)); } // Check if slug has to be unique if (false === $this->unique || !$this->getOwner()->getIsNewRecord() && $slug === $this->getOwner()->{$this->slugColumn}) { Yii::trace('Non unique slug or slug already set', __CLASS__); $this->getOwner()->{$this->slugColumn} = $slug; } else { $counter = 0; while ($this->getOwner()->resetScope()->exists($this->slugColumn . '=:sluggable', array(':sluggable' => $checkslug))) { Yii::trace("{$checkslug} found, iterating", __CLASS__); $checkslug = sprintf('%s-%d', $slug, ++$counter); } $this->getOwner()->{$this->slugColumn} = $counter > 0 ? $checkslug : $slug; } return parent::beforeSave($event); }
/** * Convert any passed string to a url friendly string. Converts 'My first blog post' to 'my-first-blog-post' * * @param string $text Text to urlize * @return string $text Urlized text */ public static function urlize($text) { return Doctrine_Inflector::urlize(self::slugify($text)); }
public function newContentType($name, $properties = array()) { $contentType = new sfSympalContentType(); $contentType->name = $name; $contentType->label = sfInflector::humanize(sfInflector::tableize(str_replace('sfSympal', null, $name))); $contentType->slug = Doctrine_Inflector::urlize($contentType->label); $contentType->default_path = '/' . $contentType->slug . '/:slug'; $this->_setDoctrineProperties($contentType, $properties); $this->logSection('sympal', sprintf('...instantiating new content type "%s"', $contentType), null, 'COMMENT'); return $contentType; }
public static function slugBuilder($text) { if (strpos($text, '.') !== false) { $e = explode('.', $text); unset($e[count($e) - 1]); $slug = implode('.', $e); } else { $slug = $text; } return Doctrine_Inflector::urlize($slug); }
public static function slugBuilder($text, $content) { if ($record = $content->getRecord()) { try { return $record->slugBuilder($text); } catch (Doctrine_Record_UnknownPropertyException $e) { return Doctrine_Inflector::urlize($text); } } else { return Doctrine_Inflector::urlize($text); } }
public function postValidator($validator, $values) { $values['name'] = Doctrine_Inflector::urlize($values['name']); return $values; }
public function addDataUriCallback($matches) { list($full, $prefix, $image, $suffix) = $matches; $image = substr($image, 0, strpos($image, '?')); $mime_types = array('png' => 'image/png', 'jpg' => 'image/jpg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif'); $location = Doctrine_Inflector::urlize($image); $path = sfConfig::get('sf_web_dir') . $image; $info = pathinfo($path); $mime_type = $mime_types[strtolower($info['extension'])]; $contents = base64_encode(file_get_contents($path)); $this->storeDataUriContent($location, $contents); return sprintf('background:%surl("data:%s;base64,%s")%s;' . '*background:%surl(mhtml:__FILE__!%s)%s;', $prefix, $mime_type, $contents, $suffix, $prefix, $location, $suffix); }
/** * @return string: the prepared slug for 'this->owner' model object * @throws CException */ public function generateUniqueSlug() { if ($this->slugIdPrefix) { // check that the defined 'id attribute' exists for 'this' model. explode if not. if (!$this->owner->hasAttribute($this->sourceIdAttr)) { throw new CException("requested to prepare a slug for " . get_class($this->owner) . " (id=" . $this->owner->getPrimaryKey() . ") but this model doesn't have an attribute named " . $this->sourceIdAttr); } } else { // inflector can not be used when id prefix is not used if ($this->slugInflector) { throw new CException("requested inlector to prepare a slug for " . get_class($this->owner) . " (id=" . $this->owner->getPrimaryKey() . ") but inflector can not be used when id prefix is not used"); } } if (!$this->owner->hasAttribute($this->sourceStringAttr)) { throw new CException("requested to prepare a slug for " . get_class($this->owner) . " (id=" . $this->owner->getPrimaryKey() . ") but this model doesn't have an attribute named " . $this->sourceStringAttr); } // create the base slug out of this attribute: if ($this->slugInflector) { $this->_slug = Doctrine_Inflector::urlize($this->owner->{$this->sourceStringAttr}); } else { $this->_slug = $this->createSimpleSlug($this->owner->{$this->sourceStringAttr}); } // prepend everything with the id of the model followed by a dash if ($this->slugIdPrefix) { $id_attr = $this->sourceIdAttr; $this->_slug = $this->owner->{$id_attr} . "-" . $this->_slug; } // trim if necessary: if (mb_strlen($this->_slug) > $this->maxChars) { $this->_slug = mb_substr($this->_slug, 0, $this->maxChars); } // done return $this->_slug; }
<?php /* * Important set of helper variables for usage in the layout template. * * */ use_helper('rtTemplate'); $routes = $sf_context->getRouting()->getRoutes(); $module = $sf_request->getParameter('module'); $action = $sf_request->getParameter('action'); $area_class = Doctrine_Inflector::urlize(sfInflector::tableize($module)); $area_class .= ' ' . $area_class . '-' . Doctrine_Inflector::urlize(sfInflector::tableize($action)); $snippet_area = Doctrine_Inflector::urlize(sfInflector::tableize($module) . '-' . sfInflector::tableize($action));
public function save($flag = false) { $this->preSave(); if (isset($this->_fields['slug'])) { $field = isset($this->_fields['slug']['field']) ? $this->_fields['slug']['field'] : 'title'; $this->slug = Doctrine_Inflector::urlize($this->{$field}); } if (isset($this->_fields[$this->_updatedAtField])) { $format = isset($this->_fields[$this->_updatedAtField]['format']) ? $this->_fields[$this->_updatedAtField]['format'] : 'Y-m-d H:i:s'; $updatedField = $this->_updatedAtField; $this->{$updatedField} = date($format); } if ($this->isNew()) { $this->_typeofWork = 'INSERT'; if (isset($this->_fields[$this->_createdAtField])) { $format = isset($this->_fields[$this->_createdAtField]['format']) ? $this->_fields[$this->_createdAtField]['format'] : 'Y-m-d H:i:s'; $createdField = $this->_createdAtField; $this->{$createdField} = date($format); } $pk = $this->getPrimaryKeyName(); $this->{$pk} = null; $return = $this->getConnection()->insertRecord($this); } else { $this->_typeofWork = 'UPDATE'; /* if($flag){ $this->getConnection(); }*/ $return = $this->getConnection()->updateRecord($this); } $this->postSave(); return $return; }
/** * getUniqueSlug * * Creates a unique slug for a given Doctrine_Record. This function enforces the uniqueness by incrementing * the values with a postfix if the slug is not unique * * @param Doctrine_Record $record * @return string $slug */ public function getUniqueSlug($record) { $name = $this->_options['name']; $slugFromFields = ''; foreach ($this->_options['fields'] as $field) { $slugFromFields .= $record->{$field} . ' '; } $proposal = $record->{$name} ? $record->{$name} : $slugFromFields; $proposal = Doctrine_Inflector::urlize($proposal); $slug = $proposal; $whereString = 'r.' . $name . ' LIKE ?'; $whereParams = array($proposal . '%'); if ($record->exists()) { $identifier = $record->identifier(); $whereString .= ' AND r.' . implode(' != ? AND r.', $record->getTable()->getIdentifierColumnNames()) . ' != ?'; $whereParams = array_merge($whereParams, array_values($identifier)); } foreach ($this->_options['uniqueBy'] as $uniqueBy) { if (is_null($record->{$uniqueBy})) { $whereString .= ' AND r.' . $uniqueBy . ' IS NULL'; } else { $whereString .= ' AND r.' . $uniqueBy . ' = ?'; $whereParams[] = $record->{$uniqueBy}; } } $query = Doctrine_Query::create()->select('r.' . $name)->from(get_class($record) . ' r')->where($whereString, $whereParams)->setHydrationMode(Doctrine::HYDRATE_ARRAY); $similarSlugResult = $query->execute(); $similarSlugs = array(); foreach ($similarSlugResult as $key => $value) { $similarSlugs[$key] = $value[$name]; } $i = 1; while (in_array($slug, $similarSlugs)) { $slug = $proposal . '-' . $i; $i++; } return $slug; }
public function executeEdit_asset(sfWebRequest $request) { $this->asset = $this->getRoute()->getObject(); if ($request->isMethod('post')) { $this->form = new sfSympalAssetEditForm(); $this->form->setAsset($this->asset); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $postFile = $this->form->getValue('file'); if ($postFile) { $fileName = $postFile->getOriginalName(); $name = Doctrine_Inflector::urlize(sfSympalAssetToolkit::getNameFromFile($fileName)); $extension = pathinfo($fileName, PATHINFO_EXTENSION); $fullName = $extension ? $name . '.' . $extension : $name; $newPath = $this->asset->getPathDirectory() . '/' . $fullName; $this->asset->move($newPath); $postFile->save($newPath); $this->asset->save(); $this->asset->copyOriginal(); } else { if ($this->asset->isImage()) { $this->asset->resize($this->form->getValue('width'), $this->form->getValue('height')); } $this->asset->rename($this->form->getValue('new_name')); } $this->asset->save(); if ($this->isAjax) { $this->redirect('@sympal_assets_select?is_ajax=1&dir=' . $this->asset->getRelativePathDirectory()); } else { $this->redirect($this->generateUrl('sympal_assets_edit_asset', $this->asset)); } } } else { $values = array('new_name' => $this->asset->getName(), 'current_name' => $this->asset->getName(), 'directory' => $this->asset->getRelativePathDirectory()); if ($this->asset->isImage()) { $values['width'] = $this->asset->getWidth(); $values['height'] = $this->asset->getHeight(); } $this->form = new sfSympalAssetEditForm($values); $this->form->setAsset($this->asset); } }
/** * generateMigrationClass * * @return void */ public function generateMigrationClass($className, $options = array(), $up = null, $down = null, $return = false) { $className = Doctrine_Inflector::urlize($className); $className = str_replace('-', '_', $className); $className = Doctrine_Inflector::classify($className); if ($return || !$this->getMigrationsPath()) { return $this->buildMigrationClass($className, null, $options, $up, $down); } else { if (!$this->getMigrationsPath()) { throw new Doctrine_Migration_Exception('You must specify the path to your migrations.'); } $next = (string) $this->migration->getNextVersion(); $fileName = str_repeat('0', 3 - strlen($next)) . $next . '_' . Doctrine_Inflector::tableize($className) . $this->suffix; $class = $this->buildMigrationClass($className, $fileName, $options, $up, $down); $path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName; if (class_exists($className) || file_exists($path)) { return false; } file_put_contents($path, $class); return true; } }
public function renderChild() { if ($this->checkUserAccess()) { $class = array(); if ($this->isCurrent() || $this->isCurrentAncestor()) { $class[] = 'current'; } if ($this->isFirst()) { $class[] = 'first'; } if ($this->isLast()) { $class[] = 'last'; } if ($this->_liClass) { $class[] = $this->_liClass; } $id = Doctrine_Inflector::urlize($this->getRoot()->getName() . '-' . $this->getName()); $html = '<li id="' . $id . '"' . (!empty($class) ? ' class="' . implode(' ', $class) . '"' : null) . '>'; $html .= $this->renderChildBody(); if ($this->hasChildren() && $this->showChildren()) { $html .= $this->render(); } $html .= '</li>'; return $html; } }
/** * Return the email addresses of the managers in an array, where the keys are the e-mail addresses, * the values are the matching names. * * @return array */ public function getEntitlementPrefix() { $vo_prefix = 'urn:geant:niif.hu:sztaki:'; $unaccentname = Doctrine_Inflector::urlize($this->getName()); return $vo_prefix . $unaccentname; }
?> F*****g fantastic. <?php } ?> <ul> <li><a href="<?php echo "http://www.imdb.com/title/" . $result['imdb_id'] . "/reviews?filter=hate"; ?> ">Why this stinks</a></li> <li><a href="<?php echo "http://www.imdb.com/title/" . $result['imdb_id'] . "/reviews?filter=love"; ?> ">What stupid fans say</a></li> <li><a href="<?php echo "/show/search?type=related&query=" . Doctrine_Inflector::urlize($result['title']); ?> ">More things like this please.</a></li> </ul> </li> </ul> </div> <div style="float:right;width:1051px;display:inline;margin-left: auto; margin-right: 30px"> <?php echo image_tag($result['images']['banner']); ?> </div> </div> <?php } }