コード例 #1
0
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = (string) parent::doClean($value);
     $clean = aTools::strtolower($clean);
     $slugified = aTools::slugify($clean, $this->getOption('allow_slashes'));
     if ($this->getOption('strict')) {
         if ($slugified !== $clean) {
             throw new sfValidatorError($this, 'invalid', array('value' => $value));
         }
     } else {
         $clean = $slugified;
     }
     return $clean;
 }
コード例 #2
0
 public function addCategory($name, $blog_id, $type = 'posts')
 {
     $category = current($this->sql->query("SELECT * FROM a_category where name = :name", array('name' => $name)));
     if ($category) {
         $category_id = $category['id'];
     } else {
         $s = "INSERT INTO a_category (name, created_at, updated_at, slug) ";
         $s .= "VALUES (:name, :created_at, :updated_at, :slug)";
         $params = array('name' => $name, 'created_at' => aDate::mysql(), 'updated_at' => aDate::mysql(), 'slug' => aTools::slugify($name));
         $this->sql->query($s, $params);
         $category_id = $this->sql->lastInsertId();
     }
     $s = 'INSERT INTO a_blog_item_to_category (blog_item_id, category_id) VALUES(:blog_item_id, :category_id) ON DUPLICATE KEY UPDATE blog_item_id=blog_item_id';
     $parms = array('blog_item_id' => $blog_id, 'category_id' => $category_id);
     $this->sql->query($s, $parms);
     return $category_id;
 }
コード例 #3
0
 public static function migrate()
 {
     $migrate = new aMigrate(Doctrine_Manager::connection()->getDbh());
     $blogIsNew = false;
     echo "Migrating apostropheBlogPlugin...\n";
     if (!$migrate->tableExists('a_blog_item')) {
         $migrate->sql(array("        CREATE TABLE a_blog_editor (blog_item_id BIGINT, user_id BIGINT, PRIMARY KEY(blog_item_id, user_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "CREATE TABLE a_blog_item (id BIGINT AUTO_INCREMENT, author_id BIGINT, page_id BIGINT, title VARCHAR(255) NOT NULL, slug_saved TINYINT(1) DEFAULT '0', excerpt TEXT, status VARCHAR(255) DEFAULT 'draft' NOT NULL, allow_comments TINYINT(1) DEFAULT '0' NOT NULL, template VARCHAR(255) DEFAULT 'singleColumnTemplate', published_at DATETIME, type VARCHAR(255), start_date DATE, start_time TIME, end_date DATE, end_time TIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, slug VARCHAR(255), INDEX a_blog_item_type_idx (type), UNIQUE INDEX a_blog_item_sluggable_idx (slug), INDEX author_id_idx (author_id), INDEX page_id_idx (page_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "        ALTER TABLE a_blog_editor ADD CONSTRAINT a_blog_editor_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id);", "        ALTER TABLE a_blog_editor ADD CONSTRAINT a_blog_editor_blog_item_id_a_blog_item_id FOREIGN KEY (blog_item_id) REFERENCES a_blog_item(id);", "        ALTER TABLE a_blog_item ADD CONSTRAINT a_blog_item_page_id_a_page_id FOREIGN KEY (page_id) REFERENCES a_page(id) ON DELETE CASCADE;", "        ALTER TABLE a_blog_item ADD CONSTRAINT a_blog_item_author_id_sf_guard_user_id FOREIGN KEY (author_id) REFERENCES sf_guard_user(id) ON DELETE SET NULL;"));
     }
     if (!$migrate->columnExists('a_blog_item', 'location')) {
         $migrate->sql(array('ALTER TABLE a_blog_item ADD COLUMN location varchar(300)'));
     }
     if (!$migrate->columnExists('a_blog_item', 'start_time')) {
         $migrate->sql(array('ALTER TABLE a_blog_item ADD COLUMN start_time TIME', 'ALTER TABLE a_blog_item ADD COLUMN end_time TIME'));
     }
     if (!$migrate->tableExists('a_page_to_category')) {
         $migrate->sql(array("CREATE TABLE a_page_to_category (page_id BIGINT, category_id BIGINT, PRIMARY KEY(page_id, category_id)) ENGINE = INNODB;"));
     }
     if (!$migrate->tableExists('a_blog_item_to_category')) {
         $migrate->sql(array("CREATE TABLE a_blog_item_to_category (blog_item_id BIGINT, category_id BIGINT, PRIMARY KEY(blog_item_id, category_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "ALTER TABLE a_blog_item_to_category ADD CONSTRAINT a_blog_item_to_category_category_id_a_category_id FOREIGN KEY (category_id) REFERENCES a_category(id) ON DELETE CASCADE;", "ALTER TABLE a_blog_item_to_category ADD CONSTRAINT a_blog_item_to_category_blog_item_id_a_blog_item_id FOREIGN KEY (blog_item_id) REFERENCES a_blog_item(id) ON DELETE CASCADE;"));
         echo "Migrating blog categories to Apostrophe categories...\n";
         $oldCategories = array();
         if ($migrate->tableExists('a_blog_category')) {
             $oldCategories = $migrate->query('SELECT * FROM a_blog_category');
         }
         $newCategories = $migrate->query('SELECT * FROM a_category');
         $nc = array();
         foreach ($newCategories as $newCategory) {
             $nc[$newCategory['name']] = $newCategory;
         }
         $oldIdToNewId = array();
         foreach ($oldCategories as $category) {
             if (isset($nc[$category['name']])) {
                 $oldIdToNewId[$category['id']] = $nc[$category['name']]['id'];
             } else {
                 // Blog categories didn't have slugs
                 $category['slug'] = aTools::slugify($category['name']);
                 $migrate->query('INSERT INTO a_category (name, description, slug) VALUES (:name, :description, :slug)', $category);
                 $oldIdToNewId[$category['id']] = $migrate->lastInsertId();
             }
         }
         echo "Migrating from aBlogItemCategory to aBlogItemToCategory...\n";
         if ($migrate->tableExists('a_blog_item_category')) {
             $oldMappings = $migrate->query('SELECT * FROM a_blog_item_category');
             foreach ($oldMappings as $info) {
                 $info['category_id'] = $oldIdToNewId[$info['blog_category_id']];
                 $migrate->query('INSERT INTO a_blog_item_to_category (blog_item_id, category_id) VALUES (:blog_item_id, :category_id)', $info);
             }
         }
     }
     // Older updates may not have categories on the virtual page
     $blogPagesById = array();
     $blogPageIdInfos = $migrate->query("SELECT id, page_id FROM a_blog_item");
     foreach ($blogPageIdInfos as $info) {
         $blogPagesById[$info['id']] = $info['page_id'];
     }
     $blogToCategories = $migrate->query("SELECT * FROM a_blog_item_to_category");
     foreach ($blogToCategories as $toCategory) {
         $migrate->query("INSERT INTO a_page_to_category (category_id, page_id) VALUES (:category_id, :page_id) ON DUPLICATE KEY UPDATE category_id = category_id", array('category_id' => $toCategory['category_id'], 'page_id' => $blogPagesById[$toCategory['blog_item_id']]));
     }
     // Older versions did not have taggings on the virtual page
     $blogTaggings = $migrate->query("SELECT * FROM tagging WHERE taggable_model IN ('aBlogPost', 'aEvent')");
     $blogTagsById = array();
     foreach ($blogTaggings as $tagging) {
         $blogTagsById[$tagging['taggable_id']][$tagging['tag_id']] = true;
     }
     $pageTaggings = $migrate->query("SELECT * FROM tagging WHERE taggable_model IN ('aPage')");
     $pageTagsById = array();
     foreach ($pageTaggings as $tagging) {
         $pageTagsById[$tagging['taggable_id']][$tagging['tag_id']] = true;
     }
     foreach ($blogTagsById as $blogId => $tags) {
         if (!isset($blogPagesById[$blogId])) {
             // No virtual page - just a stale tagging
             continue;
         }
         foreach ($tags as $tagId => $dummy) {
             if (!isset($pageTagsById[$blogPagesById[$blogId]][$tagId])) {
                 $migrate->query('INSERT INTO tagging (taggable_model, taggable_id, tag_id) VALUES ("aPage", :taggable_id, :tag_id)', array('taggable_id' => $blogPagesById[$blogId], 'tag_id' => $tagId));
             }
         }
     }
     $migrate->query('UPDATE a_page SET engine = "aBlog" WHERE slug LIKE "@a_blog_search_redirect%"');
     $migrate->query('UPDATE a_page SET engine = "aEvent" WHERE slug LIKE "@a_event_search_redirect%"');
     // Older blog post virtual pages won't have published_at
     $migrate->query('update a_page p inner join a_blog_item bi on bi.page_id = p.id set p.published_at = bi.published_at');
     // Really old events may have full timestamps in start_date and end_date, break them out
     $migrate->query('UPDATE a_blog_item SET start_time = substr(start_date, 12), start_date = substr(start_date, 1, 10) WHERE (length(start_date) > 10) AND start_time IS NULL');
     $migrate->query('ALTER TABLE a_blog_item modify column start_date date;');
     $migrate->query('UPDATE a_blog_item SET end_time = substr(end_date, 12), end_date = substr(end_date, 1, 10) WHERE (length(end_date) > 10) AND end_time IS NULL');
     $migrate->query('ALTER TABLE a_blog_item modify column end_date date;');
     // Migrate old full day events from before we started defining this as a null start and end time
     $migrate->query('UPDATE a_blog_item SET start_time = null, end_time = null WHERE start_time = "00:00:00" AND end_time = "00:00:00"');
     if ($migrate->tableExists('a_blog_category_user')) {
         $oldCategoryUsers = $migrate->query('SELECT * FROM a_blog_category_user');
         $oldCategories = $migrate->query('SELECT * from a_blog_category');
         $newCategories = $migrate->query('SELECT * from a_category');
         $oldByName = array();
         foreach ($oldCategories as $oldCategory) {
             $oldByName[$oldCategory['name']] = $oldCategory['id'];
         }
         $newByName = array();
         foreach ($newCategories as $newCategory) {
             $newByName[$newCategory['name']] = $newCategory['id'];
         }
         $oldToNew = array();
         foreach ($oldByName as $name => $id) {
             $oldToNew[$id] = $newByName[$name];
         }
         foreach ($oldCategoryUsers as $oldCategoryUser) {
             $migrate->query('INSERT INTO a_category_user (category_id, user_id) VALUES (:category_id, :user_id) ON DUPLICATE KEY UPDATE category_id = category_id', array('category_id' => $oldToNew[$oldCategoryUser['blog_category_id']], 'user_id' => $oldCategoryUser['user_id']));
         }
     }
     if ($migrate->tableExists('a_blog_category_group')) {
         $oldCategoryGroups = $migrate->query('SELECT * FROM a_blog_category_group');
         $oldCategories = $migrate->query('SELECT * from a_blog_category');
         $newCategories = $migrate->query('SELECT * from a_category');
         $oldByName = array();
         foreach ($oldCategories as $oldCategory) {
             $oldByName[$oldCategory['name']] = $oldCategory['id'];
         }
         $newByName = array();
         foreach ($newCategories as $newCategory) {
             $newByName[$newCategory['name']] = $newCategory['id'];
         }
         $oldToNew = array();
         foreach ($oldByName as $name => $id) {
             $oldToNew[$id] = $newByName[$name];
         }
         foreach ($oldCategoryGroups as $oldCategoryGroup) {
             if (!isset($oldToNew[$oldCategoryGroup['blog_category_id']])) {
                 echo "WARNING: there is no a_blog_category with the id " . $oldCategoryGroup['blog_category_id'] . "\n";
                 continue;
             }
             $migrate->query('INSERT INTO a_category_group (category_id, group_id) VALUES (:category_id, :group_id) ON DUPLICATE KEY UPDATE category_id = category_id', array('category_id' => $oldToNew[$oldCategoryGroup['blog_category_id']], 'group_id' => $oldCategoryGroup['group_id']));
         }
     }
     // Blog item tags must also be on the virtual page, ditto for categories
     if (!$migrate->getCommandsRun()) {
         echo "Your database is already up to date.\n\n";
     } else {
         echo $migrate->getCommandsRun() . " SQL commands were run.\n\n";
     }
     echo "Done!\n";
 }
コード例 #4
0
ファイル: error404Success.php プロジェクト: hashir/UoA
?>
	
<?php 
$page ? $slots = $page->getArea('body') : ($slots = array());
?>

<?php 
// If there are no slots, show some default text
if (!count($slots)) {
    ?>
	<h2><?php 
    echo a_('Error 404 &mdash; The page you are looking for could not be found.');
    ?>
</h2>
	<?php 
    $search = trim(aTools::slugify(str_replace($sf_request->getUriPrefix(), '', $sf_request->getUri()), false, false, ' '));
    ?>
	<h3><?php 
    echo link_to(a_('Try searching for %SEARCH%.', array('%SEARCH%' => $search)), 'a/search?' . http_build_query(array('q' => $search)));
    ?>
</h3>
	<h3><a href="/"><?php 
    echo a_('Go Home.');
    ?>
</a></h3>
<?php 
}
?>

<?php 
// Display some help information to admins so they know they can customize the Error404 page
コード例 #5
0
ファイル: PluginaPage.class.php プロジェクト: hashir/UoA
 /**
  * DOCUMENT ME
  * @param mixed $title
  * @return mixed
  */
 public function updateLastSlugComponent($title)
 {
     if ($this->slug === '/') {
         // We never update the home page slug
         return;
     }
     if ($this->getCulture() !== sfConfig::get('sf_default_culture')) {
         // Retitling a page in a culture other than the default does not
         // change the page slug
         return;
     }
     $component = aTools::slugify($title, false);
     $path = $this->slug;
     if (function_exists('mb_strrpos')) {
         $slash = mb_strrpos($path, '/');
         $newPath = mb_substr($path, 0, $slash + 1) . $component;
     } else {
         $slash = strrpos($path, '/');
         $newPath = substr($path, 0, $slash + 1) . $component;
     }
     if ($path === $newPath) {
         return;
     }
     $this->slug = $newPath;
     $this->save();
     Doctrine::getTable('aRedirect')->update($path, $this);
     $children = $this->getChildren();
     foreach ($children as $child) {
         $child->updateParentSlug($path, $newPath);
     }
 }
コード例 #6
0
ファイル: aImporter.class.php プロジェクト: hashir/UoA
 /**
  * Finds or adds a video without the overhead of a proper Doctrine save.
  * @param array $info
  * @return mixed
  */
 protected function findOrAddVideo($info)
 {
     $mediaId = null;
     $slug = null;
     if (!isset($info['title'])) {
         $info['title'] = 'Imported video';
     }
     $slug = aTools::slugify(!empty($info['title']) ? $info['title'] : (!empty($info['service_url']) ? $info['service_url'] : md5($info['embed'])));
     $result = $this->sql->query('SELECT id FROM a_media_item WHERE slug = :slug', array('slug' => $slug));
     if (isset($result[0]['id'])) {
         $mediaId = $result[0]['id'];
     } else {
         $mediaItem = new aMediaItem();
         foreach ($info as $key => $value) {
             if ($key !== 'tags') {
                 $mediaItem[$key] = $value;
             }
         }
         if (empty($mediaItem['title'])) {
             $mediaItem->setTitle($slug);
         } else {
             $mediaItem->setTitle($info['title']);
         }
         $mediaItem->setSlug($slug);
         $mediaItem->setType('video');
         if ($mediaItem->service_url) {
             $service = aMediaTools::getEmbedService($mediaItem->service_url);
             $id = $service->getIdFromUrl($mediaItem->service_url);
             if ($service->supports('thumbnail')) {
                 $filename = $service->getThumbnail($id);
                 if ($filename) {
                     // saveFile can't handle a nonlocal file directly, so
                     // copy to a temporary file first
                     $bad = isset($this->failedMedia[$filename]);
                     if (!$bad) {
                         $tmpFile = aFiles::getTemporaryFilename();
                         try {
                             if (!copy($filename, $tmpFile)) {
                                 throw new sfException(sprintf('Could not copy file: %s', $src));
                             }
                             if (!$mediaItem->saveFile($tmpFile)) {
                                 throw new sfException(sprintf('Could not save file: %s', $src));
                             }
                         } catch (Exception $e) {
                             $this->failedMedia[$filename] = true;
                         }
                         unlink($tmpFile);
                     }
                 }
             }
         }
         $this->sql->fastSaveMediaItem($mediaItem);
         if (count($info['tags'])) {
             $this->sql->fastSaveTags('aMediaItem', $mediaItem->id, $info['tags']);
         }
         $mediaId = $mediaItem->id;
         $mediaItem->free(true);
     }
     return $mediaId;
 }
コード例 #7
0
ファイル: BaseaActions.class.php プロジェクト: hashir/UoA
 /**
  * A REST API to aTools::slugify(), used when suggesting page slugs for new pages.
  * "Can't you just reimplement it in JavaScript?" No.
  * some of the major browsers (*cough* IE) can't manipulate Unicode in regular expressions.
  * Also two implementations mean our code will drift apart and introduce bugs
  * Returns a suitable slug for a new page component (i.e. based on a title).
  * The browser appends this to the slug of the parent page to create its suggestion
  * @param sfWebRequest $request
  */
 public function executeSlugify(sfWebRequest $request)
 {
     $slug = $request->getParameter('slug');
     $this->slug = aTools::slugify($slug, false);
     $this->setLayout(false);
 }
コード例 #8
0
 public function executeCreate()
 {
     $this->flunkUnless($this->getRequest()->getMethod() == sfRequest::POST);
     $parent = $this->retrievePageForEditingBySlugParameter('parent', 'manage');
     $title = trim($this->getRequestParameter('title'));
     $this->flunkUnless(strlen($title));
     $pathComponent = aTools::slugify($title, false);
     $base = $parent->getSlug();
     if ($base === '/') {
         $base = '';
     }
     $slug = "{$base}/{$pathComponent}";
     $page = new aPage();
     $page->setArchived(!sfConfig::get('app_a_default_on', true));
     $page->setSlug($slug);
     $existingPage = aPageTable::retrieveBySlug($slug);
     if ($existingPage) {
         // TODO: an error in addition to displaying the existing page?
         return $this->redirect($existingPage->getUrl());
     } else {
         $page->getNode()->insertAsFirstChildOf($parent);
         // Figure out what template this new page should use based on
         // the template rules.
         //
         // The default rule assigns default to everything.
         $rule = aRules::select(sfConfig::get('app_a_template_rules', array(array('rule' => '*', 'template' => 'default'))), $slug);
         if (!$rule) {
             $template = 'default';
         } else {
             $template = $rule['template'];
         }
         $page->template = $template;
         // Must save the page BEFORE we call setTitle, which has the side effect of
         // refreshing the page object
         $page->save();
         $page->setTitle(htmlspecialchars($title));
         return $this->redirect($page->getUrl());
     }
 }
コード例 #9
0
 protected function uniqueSlugFromTitle($title)
 {
     return $this->uniqueifySlug(aTools::slugify(html_entity_decode($title, ENT_COMPAT, 'UTF-8')));
 }
コード例 #10
0
 /**
  * preUpdate function used to do some slugification.
  * @param <type> $event
  */
 public function preUpdate($event)
 {
     if ($this->update) {
         // If the slug was altered by the user we no longer want to attempt to sluggify
         // the title to create the slug
         if (array_key_exists('slug', $this->getModified())) {
             $this['slug_saved'] = true;
         }
         if ($this['slug_saved'] == false && array_key_exists('title', $this->getModified())) {
             // If the slug hasn't been altered slugify the title to create the slug
             $this['slug'] = aTools::slugify($this->_get('title'));
         } else {
             // Otherwise slugify the user entered value.
             $this['slug'] = aTools::slugify($this['slug']);
         }
     }
     $this->Page['view_is_secure'] = $this['status'] == 'published' ? false : true;
     // Check if a blog post or event already has this slug
     $i = 1;
     $slug = $this['slug'];
     while ($this->findConflictingItem()) {
         $this['slug'] = $slug . '-' . $i;
         $i++;
     }
 }
コード例 #11
0
ファイル: aBlogImporter.class.php プロジェクト: hashir/UoA
 /**
  * Generate a unique, safe slug
  */
 public function slugify($slug)
 {
     $slug = aTools::slugify($slug);
     while (count($this->sql->query('select id from a_blog_item where slug = :slug', array('slug' => $slug)))) {
         if (preg_match('/^(.*)-(\\d+)$/', $slug, $matches)) {
             $rest = $matches[1];
             $ordinal = $matches[2];
             $ordinal++;
             $slug = $rest . "-" . $ordinal;
         } else {
             $slug .= "-1";
         }
     }
     return $slug;
 }
コード例 #12
0
ファイル: aMediaImporter.class.php プロジェクト: hashir/UoA
 /**
  * DOCUMENT ME
  */
 public function go()
 {
     $dir_iterator = new RecursiveDirectoryIterator($this->dir);
     $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
     $count = 0;
     $mimeTypes = aMediaTools::getOption('mime_types');
     // It comes back as a mapping of extensions to types, get the types
     $extensions = array_keys($mimeTypes);
     $mimeTypes = array_values($mimeTypes);
     foreach ($iterator as $sfile) {
         if ($sfile->isFile()) {
             $file = $sfile->getPathname();
             if (preg_match('/(^|\\/)\\./', $file)) {
                 # Silently ignore all dot folders to avoid trouble with svn and friends
                 $this->giveFeedback("info", "Ignoring dotfile", $file);
                 continue;
             }
             $pathinfo = pathinfo($file);
             // basename and filename seem backwards to me, but that's how it is in the PHP docs and
             // sure enough that's how it behaves
             if ($pathinfo['basename'] === 'Thumbs.db') {
                 continue;
             }
             $vfp = new aValidatorFilePersistent(array('mime_types' => $mimeTypes, 'validated_file_class' => 'aValidatedFile', 'required' => false), array('mime_types' => 'The following file types are accepted: ' . implode(', ', $extensions)));
             $guid = aGuid::generate();
             try {
                 $vf = $vfp->clean(array('newfile' => array('tmp_name' => $file, 'name' => $pathinfo['basename']), 'persistid' => $guid));
             } catch (Exception $e) {
                 $this->giveFeedback("warning", "Not supported or corrupt", $file);
                 continue;
             }
             $item = new aMediaItem();
             // Split it up to make tags out of the portion of the path that isn't dir (i.e. the folder structure they used)
             $dir = $this->dir;
             $dir = preg_replace('/\\/$/', '', $dir) . '/';
             $relevant = preg_replace('/^' . preg_quote($dir, '/') . '/', '', $file);
             // TODO: not Microsoft-friendly, might matter in some setting
             $components = preg_split('/\\//', $relevant);
             $tags = array_slice($components, 0, count($components) - 1);
             foreach ($tags as &$tag) {
                 // We don't strictly need to be this harsh, but it's safe and definitely
                 // takes care of some things we definitely can't allow, like periods
                 // (which cause mod_rewrite problems with pretty Symfony URLs).
                 // TODO: clean it up in a nicer way without being UTF8-clueless
                 // (aTools::slugify is UTF8-safe)
                 $tag = aTools::slugify($tag);
             }
             $item->title = aMediaTools::filenameToTitle($pathinfo['basename']);
             $item->setTags($tags);
             if (!strlen($item->title)) {
                 $this->giveFeedback("error", "Files must have a basename", $file);
                 continue;
             }
             // The preSaveImage / save / saveImage dance is necessary because
             // the sluggable behavior doesn't kick in until save and the image file
             // needs a slug based filename.
             if (!$item->preSaveFile($vf)) {
                 $this->giveFeedback("error", "Save failed", $file);
                 continue;
             }
             $item->save();
             if (!$item->saveFile($vf)) {
                 $this->giveFeedback("error", "Save failed", $file);
                 $item->delete();
                 continue;
             }
             unlink($file);
             $count++;
             $this->giveFeedback("completed", $count, $file);
         }
     }
     $this->giveFeedback("total", $count);
 }
コード例 #13
0
 public static function slugify($s, $item)
 {
     return aTools::slugify($s);
 }
コード例 #14
0
<?php

// Compatible with sf_escaping_strategy: true
$a_event = isset($a_event) ? $sf_data->getRaw('a_event') : null;
?>

<?php 
use_helper("a");
?>

<?php 
$catClass = "";
foreach ($a_event->getCategories() as $category) {
    $catClass .= " category-" . aTools::slugify($category);
}
?>

<div class="a-blog-item event <?php 
echo $a_event->getTemplate();
echo $catClass != '' ? $catClass : '';
?>
">
  <?php 
if ($a_event->userHasPrivilege('edit')) {
    ?>
	  <ul class="a-ui a-controls a-blog-post-controls">
			<li>
			<?php 
    echo a_button(a_('Edit'), url_for('a_event_admin_edit', $a_event), array('a-btn', 'icon', 'a-edit', 'lite', 'alt', 'no-label'));
    ?>
			</li>
コード例 #15
0
 /**
  * DOCUMENT ME
  * @param mixed $values
  */
 public function updateObject($values = null)
 {
     if (is_null($values)) {
         $values = $this->getValues();
     }
     $oldSlug = $this->getObject()->slug;
     if (!isset($values['slug']) && isset($values['realtitle']) && $oldSlug !== '/') {
         // If they can manually edit the title but not the slug, we need to autogenerate and
         // autoupdate the slug so they have reasonable options to avoid collisions
         $oldSlug = $this->getObject()->slug;
         if (!strlen($oldSlug)) {
             // New page, provide a starter slug to replace
             $oldSlug = $this->parent->slug . '/';
         }
         $newSlug = preg_replace('|/[^/]*$|', '/' . aTools::slugify($values['realtitle'], false, false), $oldSlug);
         $suffix = '';
         $n = 0;
         while (true) {
             $values['slug'] = $newSlug . $suffix;
             if ($values['slug'] === $oldSlug) {
                 break;
             }
             $existing = Doctrine::getTable('aPage')->findOneBySlug($values['slug']);
             if (!$existing) {
                 break;
             }
             $suffix = '-' . $n;
             $n++;
         }
         $this->getObject()->slug = $values['slug'];
     }
     // Slashes break routes in most server configs. Do NOT force case of tags.
     $values['tags'] = str_replace('/', '-', isset($values['tags']) ? $values['tags'] : '');
     $object = parent::updateObject($values);
     // Check for cascading operations
     if ($this->getValue('cascade_archived')) {
         $q = Doctrine::getTable('aPage')->createQuery()->update()->where('lft > ? and rgt < ?', array($object->getLft(), $object->getRgt()));
         if ($this->getValue('cascade_archived')) {
             $q->set('archived', '?', $object->getArchived());
         }
         $q->execute();
     }
     if (isset($values['joinedtemplate'])) {
         $template = $values['joinedtemplate'];
         // $templates = aTools::getTemplates();
         list($engine, $etemplate) = preg_split('/:/', $template);
         if ($engine === 'a') {
             $object->engine = null;
         } else {
             $object->engine = $engine;
         }
         $object->template = $etemplate;
     }
     // On manual change of slug, set up a redirect from the old slug,
     // and notify child pages so they can update their slugs if they are
     // not already deliberately different
     if ($object->slug !== $oldSlug) {
         Doctrine::getTable('aRedirect')->update($oldSlug, $object);
         $children = $object->getChildren();
         foreach ($children as $child) {
             $child->updateParentSlug($oldSlug, $object->slug);
         }
     }
     if (isset($object->engine) && !strlen($object->engine)) {
         // Store it as null for plain ol' executeShow page templating
         $object->engine = null;
     }
     // A new page must be added as a child of its parent
     if ($this->parent) {
         $this->getObject()->getNode()->insertAsFirstChildOf($this->parent);
     }
     $jvalues = json_decode($this->getValue('view_groups'), true);
     // Most custom permissions are saved in separate methods called from save()
     // after the object exists. However the "Editors + Guests" group is a special
     // case which really maps to everyone who has the 'view_locked' permission, so
     // we have to scan for it in the list of groups
     foreach ($jvalues as $value) {
         if ($value['id'] === 'editors_and_guests') {
             // Editors + Guests special case
             $object->view_guest = $value['selected'] && $value['selected'] !== 'remove';
         }
     }
     // Check for cascading operations
     if ($this->getValue('cascade_archived')) {
         $q = Doctrine::getTable('aPage')->createQuery()->update()->where('lft > ? and rgt < ?', array($object->getLft(), $object->getRgt()));
         $q->set('archived', '?', $object->getArchived());
         $q->execute();
     }
     if ($values['view_options'] === 'public') {
         $object->view_admin_lock = false;
         $object->view_is_secure = false;
     } elseif ($values['view_options'] === 'login') {
         $object->view_admin_lock = false;
         $object->view_is_secure = true;
     } elseif ($values['view_options'] === 'admin') {
         $object->view_admin_lock = true;
         $object->view_is_secure = true;
     }
     if ($this->getValue('view_options_apply_to_subpages')) {
         $q = Doctrine::getTable('aPage')->createQuery()->update()->where('lft > ? and rgt < ?', array($object->getLft(), $object->getRgt()));
         $q->set('view_admin_lock', '?', $object->view_admin_lock);
         $q->set('view_is_secure', '?', $object->view_is_secure);
         $q->set('view_guest', '?', $object->view_guest);
         $q->execute();
     }
     // We have no UI for scheduling publication yet, so make sure
     // we set the publication date when we save with archived false
     if (!$values['archived']) {
         $object->setPublishedAt(aDate::mysql());
     }
     // Has to be done on shutdown so it comes after the in-memory cache of
     // sfFileCache copies itself back to disk, which otherwise overwrites
     // our attempt to invalidate the routing cache [groan]
     register_shutdown_function(array($this, 'invalidateRoutingCache'));
 }
コード例 #16
0
 public function go()
 {
     $dir_iterator = new RecursiveDirectoryIterator($this->dir);
     $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
     $count = 0;
     foreach ($iterator as $sfile) {
         if ($sfile->isFile()) {
             $file = $sfile->getPathname();
             if (preg_match('/(^|\\/)\\./', $file)) {
                 # Silently ignore all dot folders to avoid trouble with svn and friends
                 $this->giveFeedback("info", "Ignoring dotfile", $file);
                 continue;
             }
             $pathinfo = pathinfo($file);
             if ($pathinfo['filename'] === 'Thumbs.db') {
                 continue;
             }
             $info = aImageConverter::getInfo($file);
             if ($info === false) {
                 $this->giveFeedback("warning", "Not supported or corrupt", $file);
                 continue;
             }
             $item = new aMediaItem();
             if ($info['format'] === 'pdf') {
                 $item->type = 'pdf';
             } else {
                 $item->type = 'image';
             }
             // Split it up to make tags out of the portion of the path that isn't dir (i.e. the folder structure they used)
             $dir = $this->dir;
             $dir = preg_replace('/\\/$/', '', $dir) . '/';
             $relevant = preg_replace('/^' . preg_quote($dir, '/') . '/', '', $file);
             // TODO: not Microsoft-friendly, might matter in some setting
             $components = preg_split('/\\//', $relevant);
             $tags = array_slice($components, 0, count($components) - 1);
             foreach ($tags as &$tag) {
                 // We don't strictly need to be this harsh, but it's safe and definitely
                 // takes care of some things we definitely can't allow, like periods
                 // (which cause mod_rewrite problems with pretty Symfony URLs).
                 // TODO: clean it up in a nicer way without being UTF8-clueless
                 // (aTools::slugify is UTF8-safe)
                 $tag = aTools::slugify($tag);
             }
             $item->title = aTools::slugify($pathinfo['filename']);
             $item->setTags($tags);
             if (!strlen($item->title)) {
                 $this->giveFeedback("error", "Files must have a basename", $file);
                 continue;
             }
             // The preSaveImage / save / saveImage dance is necessary because
             // the sluggable behavior doesn't kick in until save and the image file
             // needs a slug based filename.
             if (!$item->preSaveImage($file)) {
                 $this->giveFeedback("error", "Save failed", $file);
                 continue;
             }
             $item->save();
             if (!$item->saveImage($file)) {
                 $this->giveFeedback("error", "Save failed", $file);
                 $item->delete();
                 continue;
             }
             unlink($file);
             $count++;
             $this->giveFeedback("completed", $count, $file);
         }
     }
     $this->giveFeedback("total", $count);
 }
コード例 #17
0
ファイル: BaseaAssets.class.php プロジェクト: hashir/UoA
 /**
  * @param string $file The name of the file
  * Basename seems wrong, but it's consistent with pathinfo() (http://us2.php.net/pathinfo), which uses filename to refer
  * to the basename without the extension.
  * @return string A unique name for the compiled version of $file
  */
 public static function getLessBasename($file)
 {
     $name = md5($file) . '.less.css';
     if (!sfConfig::get('app_a_minify', false)) {
         // In dev environments let the developer figure out what the original filename was
         $slug = aTools::slugify($file);
         $name = $slug . '-' . $name;
     }
     return $name;
 }
コード例 #18
0
ファイル: _normalView.php プロジェクト: hashir/UoA
$areaOptions = isset($areaOptions) ? $sf_data->getRaw('areaOptions') : null;
$page = isset($page) ? $sf_data->getRaw('page') : null;
$pageid = isset($pageid) ? $sf_data->getRaw('pageid') : null;
$permid = isset($permid) ? $sf_data->getRaw('permid') : null;
$slot = isset($slot) ? $sf_data->getRaw('slot') : null;
$slug = isset($slug) ? $sf_data->getRaw('slug') : null;
use_helper('a');
?>

<?php 
if ($editable) {
    ?>
  <?php 
    slot("a-slot-controls-{$pageid}-{$name}-{$permid}");
    ?>
		<?php 
    include_partial('a/simpleEditWithVariants', array('pageid' => $pageid, 'name' => $name, 'permid' => $permid, 'slot' => $slot, 'page' => $page, 'controlsSlot' => false, 'label' => a_get_option($options, 'editLabel', a_('Edit'))));
    ?>
  <?php 
    end_slot();
}
?>

<div class="a-inset-area-slot <?php 
echo aTools::slugify($options['insetTemplate']);
?>
">
<?php 
include_partial('aInsetAreaSlot/' . $options['insetTemplate'] . 'Template', array('editable' => $editable, 'name' => $name, 'options' => $options, 'areaOptions' => $areaOptions, 'page' => $page, 'pageid' => $pageid, 'permid' => $permid, 'slot' => $slot, 'slug' => $slug));
?>
</div>
コード例 #19
0
 public static function getItem(sfActions $actions)
 {
     if ($actions->hasRequestParameter('slug')) {
         // Not sure why we're tolerant about this, but let's stay compatible with that
         $slug = aTools::slugify($actions->getRequestParameter('slug'));
         $item = Doctrine_Query::create()->from('aMediaItem')->where('slug = ?', array($slug))->fetchOne();
     } else {
         $id = $actions->getRequestParameter('id');
         $item = Doctrine::getTable('aMediaItem')->find($id);
     }
     $actions->forward404Unless($item);
     return $item;
 }
コード例 #20
0
  <?php 
    if (isset($filterFieldConfig[$name])) {
        ?>
    <?php 
        //This field needs dropdown filters to be applied
        ?>
    <ul class="a-multi-title">
      <li><a href="#" class="a-btn a-sort-label">[?php echo __('<?php 
        echo $field->getConfig('label');
        ?>
', array(), '<?php 
        echo $this->getI18nCatalogue();
        ?>
') ?]</a>
        <div class="filternav <?php 
        echo aTools::slugify($name);
        ?>
">
          <hr/>
    <?php 
        if ($filterFieldConfig[$name]->isComponent()) {
            ?>
      [?php include_component('<?php 
            echo $this->getModuleName();
            ?>
', 'list_th_<?php 
            echo $name;
            ?>
_dropdown', array('filters' => $filters, 'name' => '<?php 
            echo $name;
            ?>
コード例 #21
0
ファイル: BaseaMediaTools.class.php プロジェクト: hashir/UoA
 /**
  * DOCUMENT ME
  * @param mixed $filename
  * @return mixed
  */
 public static function filenameToTitle($filename)
 {
     $title = preg_replace('/\\.\\w+$/', '', $filename);
     // *Not* aMediaTools::slugify, which is specifically for the slug of the media item
     return aTools::slugify($title, false, false, ' ');
 }