Exemple #1
0
void template_preprocess_aggregator_item( map <string, string> &variables ) 
{
	map <string, string> item = variables;

	variables["feed_url"] = check_url( item["link"] );
	variables["feed_title"] = check_plain( item["title"] );
	variables["content"] = aggregator_filter_xss( item["description"] );

	variables["source_url"] = "";
	variables["source_title"] = "";
	if ( isset(item["ftitle"]) && isset(item["fid"]) ) 
	{
		variables["source_url"] = url("aggregator/sources/"+item["fid"]);
		variables["source_title"] = check_plain(item["ftitle"]);
	}
	if ( date("Ymd", item["timestamp"]) == date("Ymd") ) 
	{
		variables["source_date"] = format_interval(time() - intval(item["timestamp"]) ) + " ago";
	}
	else 
	{
		variables["source_date"] = format_date( item["timestamp"] );
	}
}
Exemple #2
0
string aggregator_page_source()
{
	map <string, string> feed;

	aggregator_feed_load( feed, arg(2) );

	set_page_title( check_plain( feed["title"] ) );

	template_preprocess_aggregator_feed_source( feed );

	string feed_source = theme("aggregator_feed_source", feed);

	vector <map <string, string> > items;

	aggregator_feed_items_load( items, intval(feed["fid"]), 20 );

	return _aggregator_page_list( items, "", feed_source);
}
Exemple #3
0
void aggregator_refresh(map <string, string> &feed)
{
	// Generate conditional GET headers.
	map <string, string> headers;
  
	if ( isset(feed["etag"]) ) 
	{
		headers["If-None-Match"] = feed["etag"];
	}
	if ( isset(feed["modified"]) ) 
	{
		headers["If-Modified-Since"] = gmdate("D, d M Y H:i:s", feed["modified"]) + " GMT";
	}
	
	map <string, string> result;
  
	// Request feed.
	http_request( result, feed["url"], headers );

	// Process HTTP response code.
	switch ( intval( result["response_code"] ) ) 
	{
		case 304:
			if(DB_TYPE==1)
				redis_command("HSET aggregator_feed:%d checked %d", intval(feed["fid"]), time() );
			if(DB_TYPE==2)
				db_querya("UPDATE aggregator_feed SET checked = %d WHERE fid = %d", str( time() ).c_str(), feed["fid"].c_str() );

			set_page_message( "There is no new syndicated content from " + feed["title"] );
			break;
		case 301:
			feed["url"] = result["redirect_url"];
		case 200:
		case 302:
		case 307:
			// Filter the input data:
			if ( aggregator_parse_feed( result["data"], feed ) ) 
			{
				string modified = !isset2(result,"Last-Modified") ? "0" : strtotime( result["Last-Modified"] );

				// Prepare the channel data.
				for( map <string, string>::iterator curr = channel.begin(), end = channel.end();  curr != end;  curr++ )
				{
					trim( curr->second );
					channel[curr->first] = curr->second;
				}

				// Prepare the image data (if any).
				for( map <string, string>::iterator curr = image.begin(), end = image.end();  curr != end;  curr++ )
				{
					trim( curr->second );
					image[curr->first] = curr->second;
				}

				string str_image;
				if (isset(image["LINK"]) && isset(image["URL"]) && isset(image["TITLE"]) ) 
				{
					// Note, we should really use theme_image() here but that only works with local images it won't work with images fetched with a URL unless PHP version > 5
					str_image = "<a href=\""+ check_url(image["LINK"]) +"\" class=\"feed-image\"><img src=\"" + check_url(image["URL"]) + "\" alt=\"" + check_plain(image["TITLE"]) +"\" /></a>";
				}
				else {
					str_image = "";
				}

				string etag = !isset(result["ETag"]) ? "" : result["ETag"];
				// Update the feed data.

				if(DB_TYPE==1)
				{
					redis_command_fields(redis_arg("HMSET aggregator_feed:%d", intval(feed["fid"]) ), "", 
						"url,checked,link,description,image,etag,modified", "%s,%d,%s,%s,%s,%s,%d", 
						feed["url"].c_str(), 
						time(), 
						channel["LINK"].c_str(), 
						channel["DESCRIPTION"].c_str(), 
						str_image.c_str(), 
						etag.c_str(), 
						intval( modified ) );
				}
				if(DB_TYPE==2)
				{
					db_querya("UPDATE aggregator_feed SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', etag = '%s', modified = %d WHERE fid = %d", 
						feed["url"].c_str(), 
						str(time()).c_str(), 
						channel["LINK"].c_str(), 
						channel["DESCRIPTION"].c_str(), 
						str_image.c_str(), 
						etag.c_str(), 
						modified.c_str(), 
						feed["fid"].c_str() );
				}

				set_page_message( "There is new syndicated content from " + feed["title"] );
				break;
			}
			result["error"] = "feed not parseable";
		default:
			set_page_message( "The feed from "+feed["title"]+" seems to be broken, because of error \""+result["response_code"]+"\". "+ result["error"] );
	}
}
void
check_f (void)
{
  static const struct {
    const char  *fmt;
    const char  *f;
    const char  *want;

  } data[] = {

    { "%Ff",    "0",    "0.000000" },
    { "%Ff",  "123",  "123.000000" },
    { "%Ff", "-123", "-123.000000" },

    { "%+Ff",    "0",   "+0.000000" },
    { "%+Ff",  "123", "+123.000000" },
    { "%+Ff", "-123", "-123.000000" },

    { "%.0Ff",    "0",    "0" },
    { "%.0Ff",  "123",  "123" },
    { "%.0Ff", "-123", "-123" },

    { "%8.0Ff",    "0", "       0" },
    { "%8.0Ff",  "123", "     123" },
    { "%8.0Ff", "-123", "    -123" },

    { "%08.0Ff",    "0", "00000000" },
    { "%08.0Ff",  "123", "00000123" },
    { "%08.0Ff", "-123", "-0000123" },

    { "%10.2Ff",       "0", "      0.00" },
    { "%10.2Ff",    "0.25", "      0.25" },
    { "%10.2Ff",  "123.25", "    123.25" },
    { "%10.2Ff", "-123.25", "   -123.25" },

    { "%-10.2Ff",       "0", "0.00      " },
    { "%-10.2Ff",    "0.25", "0.25      " },
    { "%-10.2Ff",  "123.25", "123.25    " },
    { "%-10.2Ff", "-123.25", "-123.25   " },

    { "%.2Ff", "0.00000000000001", "0.00" },
    { "%.2Ff", "0.002",            "0.00" },
    { "%.2Ff", "0.008",            "0.01" },

    { "%.0Ff", "123.00000000000001", "123" },
    { "%.0Ff", "123.2",              "123" },
    { "%.0Ff", "123.8",              "124" },

    { "%.0Ff",  "999999.9", "1000000" },
    { "%.0Ff", "3999999.9", "4000000" },

    { "%Fe",    "0",  "0.000000e+00" },
    { "%Fe",    "1",  "1.000000e+00" },
    { "%Fe",  "123",  "1.230000e+02" },

    { "%FE",    "0",  "0.000000E+00" },
    { "%FE",    "1",  "1.000000E+00" },
    { "%FE",  "123",  "1.230000E+02" },

    { "%Fe",    "0",  "0.000000e+00" },
    { "%Fe",    "1",  "1.000000e+00" },

    { "%.0Fe",     "10000000000",    "1e+10" },
    { "%.0Fe",    "-10000000000",   "-1e+10" },

    { "%.2Fe",     "10000000000",  "1.00e+10" },
    { "%.2Fe",    "-10000000000", "-1.00e+10" },

    { "%8.0Fe",    "10000000000", "   1e+10" },
    { "%8.0Fe",   "-10000000000", "  -1e+10" },

    { "%-8.0Fe",   "10000000000", "1e+10   " },
    { "%-8.0Fe",  "-10000000000", "-1e+10  " },

    { "%12.2Fe",   "10000000000", "    1.00e+10" },
    { "%12.2Fe",  "-10000000000", "   -1.00e+10" },

    { "%012.2Fe",  "10000000000", "00001.00e+10" },
    { "%012.2Fe", "-10000000000", "-0001.00e+10" },

    { "%Fg",   "0", "0" },
    { "%Fg",   "1", "1" },
    { "%Fg",   "-1", "-1" },

    { "%.0Fg", "0", "0" },
    { "%.0Fg", "1", "1" },
    { "%.0Fg", "-1", "-1" },

    { "%.1Fg", "100", "1e+02" },
    { "%.2Fg", "100", "1e+02" },
    { "%.3Fg", "100", "100" },
    { "%.4Fg", "100", "100" },

    { "%Fg", "0.001",    "0.001" },
    { "%Fg", "0.0001",   "0.0001" },
    { "%Fg", "0.00001",  "1e-05" },
    { "%Fg", "0.000001", "1e-06" },

    { "%.4Fg", "1.00000000000001", "1" },
    { "%.4Fg", "100000000000001",  "1e+14" },

    { "%.4Fg", "12345678", "1.235e+07" },

    { "%Fa", "0","0x0p+0" },
    { "%FA", "0","0X0P+0" },

    { "%Fa", "1","0x1p+0" },
    { "%Fa", "65535","0xf.fffp+12" },
    { "%Fa", "65536","0x1p+16" },
    { "%F.10a", "65536","0x1.0000000000p+16" },
    { "%F.1a", "65535","0x1.0p+16" },
    { "%F.0a", "65535","0x1p+16" },

    { "%.2Ff", "0.99609375", "1.00" },
    { "%.Ff",  "0.99609375", "0.99609375" },
    { "%.Fe",  "0.99609375", "9.9609375e-01" },
    { "%.Fg",  "0.99609375", "0.99609375" },
    { "%.20Fg",  "1000000", "1000000" },
    { "%.Fg",  "1000000", "1000000" },

    { "%#.0Ff", "1", "1." },
    { "%#.0Fe", "1", "1.e+00" },
    { "%#.0Fg", "1", "1." },

    { "%#.1Ff", "1", "1.0" },
    { "%#.1Fe", "1", "1.0e+00" },
    { "%#.1Fg", "1", "1." },

    { "%#.4Ff", "1234", "1234.0000" },
    { "%#.4Fe", "1234", "1.2340e+03" },
    { "%#.4Fg", "1234", "1234." },

    { "%#.8Ff", "1234", "1234.00000000" },
    { "%#.8Fe", "1234", "1.23400000e+03" },
    { "%#.8Fg", "1234", "1234.0000" },

  };

  int     i;
  mpf_t   f;
  double  d;

  mpf_init2 (f, 256L);

  for (i = 0; i < numberof (data); i++)
    {
      if (data[i].f[0] == '0' && data[i].f[1] == 'x')
	mpf_set_str_or_abort (f, data[i].f, 16);
      else
	mpf_set_str_or_abort (f, data[i].f, 10);

      /* if mpf->double doesn't truncate, then expect same result */
      d = mpf_get_d (f);
      if (mpf_cmp_d (f, d) == 0)
	check_plain (data[i].want, data[i].fmt, d);

      check_one (data[i].want, data[i].fmt, f);
    }

  mpf_clear (f);
}
void
check_z (void)
{
  static const struct {
    const char  *fmt;
    const char  *z;
    const char  *want;
  } data[] = {
    { "%Zd", "0",    "0" },
    { "%Zd", "1",    "1" },
    { "%Zd", "123",  "123" },
    { "%Zd", "-1",   "-1" },
    { "%Zd", "-123", "-123" },

    { "%+Zd", "0",      "+0" },
    { "%+Zd", "123",  "+123" },
    { "%+Zd", "-123", "-123" },

    { "%Zx",  "123",   "7b" },
    { "%ZX",  "123",   "7B" },
    { "%Zx", "-123",  "-7b" },
    { "%ZX", "-123",  "-7B" },
    { "%Zo",  "123",  "173" },
    { "%Zo", "-123", "-173" },

    { "%#Zx",    "0",     "0" },
    { "%#ZX",    "0",     "0" },
    { "%#Zx",  "123",  "0x7b" },
    { "%#ZX",  "123",  "0X7B" },
    { "%#Zx", "-123", "-0x7b" },
    { "%#ZX", "-123", "-0X7B" },

    { "%#Zo",    "0",     "0" },
    { "%#Zo",  "123",  "0173" },
    { "%#Zo", "-123", "-0173" },

    { "%10Zd",      "0", "         0" },
    { "%10Zd",    "123", "       123" },
    { "%10Zd",   "-123", "      -123" },

    { "%-10Zd",     "0", "0         " },
    { "%-10Zd",   "123", "123       " },
    { "%-10Zd",  "-123", "-123      " },

    { "%+10Zd",   "123", "      +123" },
    { "%+-10Zd",  "123", "+123      " },
    { "%+10Zd",  "-123", "      -123" },
    { "%+-10Zd", "-123", "-123      " },

    { "%08Zd",    "0", "00000000" },
    { "%08Zd",  "123", "00000123" },
    { "%08Zd", "-123", "-0000123" },

    { "%+08Zd",    "0", "+0000000" },
    { "%+08Zd",  "123", "+0000123" },
    { "%+08Zd", "-123", "-0000123" },

    { "%#08Zx",    "0", "00000000" },
    { "%#08Zx",  "123", "0x00007b" },
    { "%#08Zx", "-123", "-0x0007b" },

    { "%+#08Zx",    "0", "+0000000" },
    { "%+#08Zx",  "123", "+0x0007b" },
    { "%+#08Zx", "-123", "-0x0007b" },

    { "%.0Zd", "0", "" },
    { "%.1Zd", "0", "0" },
    { "%.2Zd", "0", "00" },
    { "%.3Zd", "0", "000" },
  };

  int        i, j;
  mpz_t      z;
  char       *nfmt;
  mp_size_t  nsize, zeros;

  mpz_init (z);

  for (i = 0; i < numberof (data); i++)
    {
      mpz_set_str_or_abort (z, data[i].z, 0);

      /* don't try negatives or forced sign in hex or octal */
      if (mpz_fits_slong_p (z)
	  && ! (hex_or_octal_p (data[i].fmt)
		&& (strchr (data[i].fmt, '+') != NULL || mpz_sgn(z) < 0)))
	{
	  check_plain (data[i].want, data[i].fmt, mpz_get_si (z));
	}

      check_one (data[i].want, data[i].fmt, z);

      /* Same again, with %N and possibly some high zero limbs */
      nfmt = __gmp_allocate_strdup (data[i].fmt);
      for (j = 0; nfmt[j] != '\0'; j++)
	if (nfmt[j] == 'Z')
	  nfmt[j] = 'N';
      for (zeros = 0; zeros <= 3; zeros++)
	{
	  nsize = ABSIZ(z)+zeros;
	  MPZ_REALLOC (z, nsize);
	  nsize = (SIZ(z) >= 0 ? nsize : -nsize);
	  refmpn_zero (PTR(z)+ABSIZ(z), zeros);
	  check_one (data[i].want, nfmt, PTR(z), nsize);
	}
      __gmp_free_func (nfmt, strlen(nfmt)+1);
    }

  mpz_clear (z);
}