Exemplo n.º 1
0
    /**
     * Creates a new tag
     *
     * @throws SwatException if no database connection is set on this tag
     *                        entry control.
     */
    protected function insertTag($title, $index)
    {
        if ($this->app === null) {
            throw new SwatException('An application must be set on the tag entry control during ' . 'the widget init phase.');
        }
        // check to see if the tag already exists
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select * from
			BlorgTag where lower(title) = lower(%s) and instance %s %s', $this->app->db->quote($title, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $tags = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgTagWrapper'));
        // only insert if no tag already exists (prevents creating two tags on
        // reloading)
        if (count($tags) > 0) {
            $tag = $tags->getFirst();
        } else {
            $tag = new BlorgTag();
            $tag->setDatabase($this->app->db);
            $tag->instance = $instance_id;
            $tag->title = $title;
            $tag->save();
            if (isset($this->app->memcache)) {
                $this->app->memcache->flushNs('tags');
            }
            $message = new SwatMessage(sprintf(Blorg::_('The tag “%s” has been added.'), $tag->title));
            $this->app->messages->add($message);
        }
        $this->tag_array[$tag->shortname] = $tag->title;
        $this->selected_tag_array[$tag->shortname] = $tag->title;
    }
Exemplo n.º 2
0
    /**
     * Creates a new tag
     *
     * @throws SwatException if no database connection is set on this tag
     *                        entry control.
     */
    protected function insertTag($title, $index)
    {
        if ($this->app === null) {
            throw new SwatException('An application must be set on the tag entry control during ' . 'the widget init phase.');
        }
        // check to see if the tag already exists
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select * from
			PinholeTag where lower(title) = lower(%s)
				and instance %s %s', $this->app->db->quote($title, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $tags = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('PinholeTagDataObjectWrapper'));
        // only insert if no tag already exists (prevents creating two tags on
        // reloading)
        if (count($tags) > 0) {
            $tag_obj = $tags->getFirst();
        } else {
            $tag_obj = new PinholeTagDataObject();
            $tag_obj->setDatabase($this->app->db);
            $tag_obj->instance = $instance_id;
            $tag_obj->title = $title;
            $tag_obj->save();
            $message = new SwatMessage(sprintf(Pinhole::_('“%s” tag has been added'), SwatString::minimizeEntities($tag_obj->title)));
            $message->content_type = 'text/xml';
            $message->secondary_content = sprintf(Pinhole::_('You can <a href="Tag/Edit?id=%d">edit this tag</a> ' . 'to customize it.'), $tag_obj->id);
            $this->app->messages->add($message);
        }
        $this->tag_array[$tag_obj->name] = $tag_obj->title;
        $this->selected_tag_array[$tag_obj->name] = $tag_obj->title;
    }
Exemplo n.º 3
0
    protected function getPhotos()
    {
        // load the photos uploaded in the last day
        $date = new SwatDate();
        $date->subtractDays(1);
        $date->toUTC();
        $instance_id = $this->app->getInstance() === null ? null : $this->app->getInstanceId();
        $sql = sprintf('select PinholePhoto.* from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			where ImageSet.instance %s %s and PinholePhoto.dav_upload = %s
				and PinholePhoto.upload_date > %s
			order by original_filename asc', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean'), $this->app->db->quote($date->getDate(), 'date'));
        $photos = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('PinholeSimplePhotoWrapper'));
        return $photos;
    }
Exemplo n.º 4
0
 /**
  * Configures modules of this application before they are initialized
  *
  * @param SiteConfigModule $config the config module of this application to
  *                                  use for configuration other modules.
  */
 protected function configure(SiteConfigModule $config)
 {
     parent::configure($config);
     if (isset($config->exceptions->log_location)) {
         SwatException::setLogger(new SiteExceptionLogger($config->exceptions->log_location, $config->exceptions->base_uri, $config->email->logging_address));
     }
     if (isset($config->errors->log_location)) {
         SwatError::setLogger(new SiteErrorLogger($config->errors->log_location, $config->errors->base_uri, $config->email->logging_address));
     }
     SwatForm::$default_salt = $config->swat->form_salt;
     $this->database->dsn = $config->database->dsn;
     $this->setBaseUri($config->uri->base);
     $this->setSecureBaseUri($config->uri->secure_base);
     $this->default_time_zone = new Date_TimeZone($config->date->time_zone);
     $this->analytics->setGoogleAccount($config->analytics->google_account);
 }
Exemplo n.º 5
0
 /**
  * Configures modules of this application before they are initialized
  *
  * @param SiteConfigModule $config the config module of this application to
  *                                  use for configuration other modules.
  */
 protected function configure(SiteConfigModule $config)
 {
     parent::configure($config);
     SwatForm::$default_salt = $config->swat->form_salt;
     $this->database->dsn = $config->database->dsn;
     $this->setBaseUri($config->uri->base);
     $this->setSecureBaseUri($config->uri->secure_base);
     $this->default_time_zone = new HotDateTimeZone($config->date->time_zone);
     setlocale(LC_ALL, $config->i18n->locale);
     if (isset($this->memcache)) {
         $this->memcache->server = $config->memcache->server;
         $this->memcache->app_ns = $config->memcache->app_ns;
     }
 }
Exemplo n.º 6
0
 public static function getPhotoCountPerDay(SiteWebApplication $app, SwatDate $date)
 {
     if (isset($app->memcache)) {
         $cache_key = sprintf('PinholeCalendarGadget.count.%s.%s', $date->formatLikeIntl('yyyy-MM'), $app->session->isLoggedIn() ? 'private' : 'public');
         $count = $app->memcache->getNs('photos', $cache_key);
         if ($count !== false) {
             return $count;
         }
     }
     $sql = "select count(PinholePhoto.id) as photo_count,\n\t\t\t\tdate_part('day', max(convertTZ(PinholePhoto.photo_date,\n\t\t\t\t\tPinholePhoto.photo_time_zone))) as photo_day\n\t\t\tfrom PinholePhoto\n\t\t\tinner join ImageSet on PinholePhoto.image_set = ImageSet.id\n\t\t\twhere ImageSet.instance %s %s and PinholePhoto.status = %s\n\t\t\t\tand PinholePhoto.photo_date is not null\n\t\t\t\tand convertTZ(PinholePhoto.photo_date,\n\t\t\t\t\tPinholePhoto.photo_time_zone) >= %s\n\t\t\t\tand convertTZ(PinholePhoto.photo_date,\n\t\t\t\t\tPinholePhoto.photo_time_zone) < %s\n\t\t\t\t%s\n\t\t\tgroup by date_part('day', convertTZ(PinholePhoto.photo_date,\n\t\t\t\tPinholePhoto.photo_time_zone))";
     $end_date = clone $date;
     $end_date->addMonths(1);
     if (!$app->session->isLoggedIn()) {
         $private_where_clause = sprintf('and PinholePhoto.private = %s', $app->db->quote(false, 'boolean'));
     } else {
         $private_where_clause = '';
     }
     $sql = sprintf($sql, SwatDB::equalityOperator($app->getInstanceId()), $app->db->quote($app->getInstanceId(), 'integer'), $app->db->quote(PinholePhoto::STATUS_PUBLISHED), $app->db->quote($date->getDate(), 'date'), $app->db->quote($end_date->getDate(), 'date'), $private_where_clause);
     $days = SwatDB::query($app->db, $sql);
     $day_count = array();
     foreach ($days as $day) {
         $day_count[$day->photo_day] = $day->photo_count;
     }
     if (isset($app->memcache)) {
         $app->memcache->setNs('photos', $cache_key, $day_count);
     }
     return $day_count;
 }