コード例 #1
0
ファイル: Learn.php プロジェクト: nystudio107/seomatic
 public function save(AbstractFormat $output)
 {
     if (empty($this->samples)) {
         throw new \Exception("You need to provide samples");
     }
     $sort = $this->config->getSortObject();
     $max = $this->config->maxNGram();
     $parser = $this->config->getParser();
     $callback = $this->callback;
     foreach ($this->samples as $lang => $texts) {
         if (!empty($this->output[$lang])) {
             continue;
         }
         if ($callback) {
             $callback($lang, 'start');
         }
         $text = implode("\n", $texts);
         $pos = 0;
         $data = array();
         $sorted = $sort->sort($parser->get($text));
         foreach (array_splice($sorted, 0, $max) as $ngram => $score) {
             $data[$ngram] = array('pos' => $pos++, 'score' => $score);
         }
         $this->output[$lang] = $data;
         if ($callback) {
             $callback($lang, 'end');
         }
     }
     $output->dump(array('config' => $this->config, 'data' => $this->output));
 }
コード例 #2
0
ファイル: Rss.php プロジェクト: akinyeleolubodun/PhireCMS2
 /**
  * Method to create an RSS feed object
  *
  * @param  mixed  $options
  * @param  int    $limit
  * @throws Exception
  * @return \Pop\Feed\Format\Rss
  */
 public function __construct($options, $limit = 0)
 {
     parent::__construct($options, $limit);
     // Create the SimpleXMLElement
     if (null === $this->obj) {
         if (!($this->obj = simplexml_load_string($this->source, 'SimpleXMLElement', LIBXML_NOWARNING))) {
             throw new Exception('That feed URL cannot be read at this time. Please try again later.');
         }
     }
     // Check for the date
     if (isset($this->obj->channel->lastBuildDate)) {
         $date = (string) $this->obj->channel->lastBuildDate;
     } else {
         if (isset($this->obj->channel->pubDate)) {
             $date = (string) $this->obj->channel->pubDate;
         } else {
             $date = null;
         }
     }
     // Get the main header info of the feed
     $feed = array();
     $feed['title'] = isset($this->obj->channel->title) ? (string) $this->obj->channel->title : null;
     $feed['url'] = isset($this->obj->channel->link) ? (string) (string) $this->obj->channel->link : null;
     $feed['description'] = isset($this->obj->channel->description) ? (string) $this->obj->channel->description : null;
     $feed['date'] = $date;
     $feed['generator'] = isset($this->obj->channel->generator) ? (string) $this->obj->channel->generator : null;
     $feed['author'] = isset($this->obj->channel->managingEditor) ? (string) $this->obj->channel->managingEditor : null;
     $feed['items'] = array();
     $this->feed = new \ArrayObject($feed, \ArrayObject::ARRAY_AS_PROPS);
 }
コード例 #3
0
ファイル: Php.php プロジェクト: akinyeleolubodun/PhireCMS2
 /**
  * Method to create a PHP feed object
  *
  * @param  mixed  $options
  * @param  int    $limit
  * @throws Exception
  * @return \Pop\Feed\Format\Php
  */
 public function __construct($options, $limit = 0)
 {
     parent::__construct($options, $limit);
     // Create the PHP data object from the serialized PHP string source
     if (null === $this->obj) {
         if (!($this->obj = unserialize($this->source))) {
             throw new Exception('That feed URL cannot be read at this time. Please try again later.');
         }
     }
 }
コード例 #4
0
 public static function initByPath($datafile)
 {
     $format = AbstractFormat::initFormatByPath($datafile);
     $data = $format->load($datafile);
     foreach (array('config', 'data') as $type) {
         if (empty($data[$type])) {
             throw new \Exception("Invalid data file, missing {$type}");
         }
     }
     return new self($data['config'], $data['data']);
 }
コード例 #5
0
ファイル: Atom.php プロジェクト: Nnadozieomeonu/lacecart
 /**
  * Constructor method to create an Atom feed object
  *
  * @param  mixed  $options
  * @param  int    $limit
  * @throws Exception
  * @return Atom
  */
 public function __construct($options, $limit = 0)
 {
     parent::__construct($options, $limit);
     // Create the SimpleXMLElement
     if (null === $this->obj) {
         if (!($this->obj = simplexml_load_string($this->source, 'SimpleXMLElement', LIBXML_NOWARNING))) {
             throw new Exception('That feed URL cannot be read at this time. Please try again later.');
         }
     }
     // Get the main header info of the feed
     $feed = [];
     $feed['title'] = isset($this->obj->title) ? (string) $this->obj->title : null;
     $feed['url'] = isset($this->obj->link->attributes()->href) ? (string) $this->obj->link->attributes()->href : null;
     $feed['description'] = isset($this->obj->subtitle) ? (string) $this->obj->subtitle : null;
     $feed['date'] = isset($this->obj->updated) ? (string) $this->obj->updated : null;
     $feed['generator'] = isset($this->obj->generator) ? (string) $this->obj->generator : null;
     $feed['author'] = isset($this->obj->author->name) ? (string) $this->obj->author->name : null;
     $feed['items'] = [];
     $this->feed = new \ArrayObject($feed, \ArrayObject::ARRAY_AS_PROPS);
 }
コード例 #6
0
ファイル: Json.php プロジェクト: nicksagona/PopPHP
 /**
  * Method to create a JSON feed object
  *
  * @param  mixed $options
  * @param  int   $limit
  * @throws Exception
  * @return \Pop\Feed\Format\Json
  */
 public function __construct($options, $limit = 0)
 {
     parent::__construct($options, $limit);
     // Create the PHP data array from JSON
     if (null === $this->obj) {
         if (!($this->obj = json_decode($this->source, true))) {
             throw new Exception('That feed URL cannot be read at this time. Please try again later.');
         }
     }
     // Get the main header info of the feed
     $objs = isset($this->obj['feed']) ? $this->obj['feed'] : $this->obj;
     $feed = array();
     $feed['title'] = isset($objs['title']) ? $objs['title'] : null;
     $feed['url'] = isset($objs['link']) ? $objs['link'] : null;
     $feed['description'] = isset($objs['description']) ? $objs['description'] : null;
     $feed['date'] = isset($objs['updated']) ? $objs['updated'] : null;
     $feed['generator'] = isset($objs['generator']) ? $objs['generator'] : null;
     $feed['author'] = isset($objs['author']) ? $objs['author'] : null;
     $this->feed = new \ArrayObject($feed, \ArrayObject::ARRAY_AS_PROPS);
 }
コード例 #7
0
ファイル: bootstrap.php プロジェクト: phpcanvas/phpcanvas
spl_autoload_register(array('App', 'load'));
ini_set('unserialize_callback_func', 'spl_autoload_call');
File::defaultPath(App::conf('file.tmp'));
App::$sysroot = $ini['system_root'];
// For accurate date transactions.
date_default_timezone_set(App::conf('timezone'));
// Activates/Deactivates debug mode.
App::debug();
// Overwritting the error handler will the one in App Class.
set_error_handler(array('App', 'errorHandler'));
if (!RestRoute::parse(App::conf('route'))) {
    App::throwError('404');
}
// Everything is OK so far. start executing the method.
$params = RestRoute::$params;
$controller = new RestRoute::$class(RestRoute::$method, $params);
call_user_func_array(array($controller, RestRoute::$method), $params);
$layout = $controller->layout;
$viewData = $controller->getViewData();
$scriptTime = $controller->scriptTime;
unset($controller);
// Loading the View module
if (!empty($layout)) {
    // assumes that layout is an HTML format if it's not specified.
    AbstractFormat::factory($viewData, $layout, App::conf('view.compress'));
}
if ($scriptTime) {
    $ms = round((array_sum(explode(' ', microtime())) - $ms) * 1000, 4);
    // setting the end time.
    echo '<pre>script execution: ', $ms, 'ms</pre>';
}