示例#1
0
 protected function _export($start)
 {
     // do we have a valid filename
     $this->_filename = Sh404sefHelperFiles::createFileName($this->_filename, 'sh404sef_export_' . $this->_context);
     // put some data in the file
     $end = $start + self::MAX_PAGEIDS_PER_STEP + 1;
     $end = $end > $this->_total ? $this->_total : $end;
     // fetch shURLs record from model
     $model =& JModel::getInstance('urls', 'Sh404sefModel');
     $model->setContext('urls.view404');
     $options = (object) array('layout' => 'view404');
     $records = $model->getList($options, $returnZeroElement = false, $start, $forcedLimit = self::MAX_PAGEIDS_PER_STEP);
     // do we need a header written to the file, for first record
     $header = $start == 0 ? Sh404sefHelperGeneral::getExportHeaders($this->_context) . "\n" : '';
     // format them for text file output
     $data = '';
     $counter = $start;
     $glue = Sh404sefHelperFiles::$stringDelimiter . Sh404sefHelperFiles::$fieldDelimiter . Sh404sefHelperFiles::$stringDelimiter;
     if (!empty($records)) {
         foreach ($records as $record) {
             $counter++;
             $textRecord = $record->oldurl . $glue . $record->newurl . $glue . $record->cpt . $glue . $record->rank . $glue . $record->dateadd . $glue . '' . $glue . '' . $glue . '' . $glue . '' . $glue . '' . Sh404sefHelperFiles::$stringDelimiter;
             $line = Sh404sefHelperFiles::$stringDelimiter . $counter . $glue . $textRecord;
             $data .= $line . "\n";
         }
     }
     // prepare data for storage
     if (!empty($header)) {
         // first record written to file, prepend header
         $data = $header . $data;
     }
     // store in file
     $status = Sh404sefHelperFiles::appendToFile($this->_filename, $data);
     // return any error
     return $status;
 }
示例#2
0
 protected function _export($start)
 {
     // do we have a valid filename
     $this->_filename = Sh404sefHelperFiles::createFileName($this->_filename, 'sh404sef_export_' . $this->_context);
     // put some data in the file
     $end = $start + self::MAX_PAGEIDS_PER_STEP + 1;
     $end = $end > $this->_total ? $this->_total : $end;
     // fetch pageIds record from model
     $model = ShlMvcModel_Base::getInstance('aliases', 'Sh404sefModel');
     $model->setContext('aliases.default');
     $options = (object) array('layout' => 'default', 'includeHomeData' => true);
     $records = $model->getList($options, $returnZeroElement = false, $start, $forcedLimit = self::MAX_PAGEIDS_PER_STEP);
     // do we need a header written to the file, for first record
     $header = $start == 0 ? Sh404sefHelperGeneral::getExportHeaders($this->_context) . "\n" : '';
     // format them for text file output
     $data = '';
     $counter = $start;
     $glue = Sh404sefHelperFiles::$stringDelimiter . Sh404sefHelperFiles::$fieldDelimiter . Sh404sefHelperFiles::$stringDelimiter;
     if (!empty($records)) {
         foreach ($records as $record) {
             $counter++;
             if ($record->newurl == sh404SEF_HOMEPAGE_CODE) {
                 $record->newurl = '__ Homepage __';
             }
             $textRecord = $record->alias . $glue . $record->oldurl . $glue . $record->newurl . $glue . $record->type . $glue . $record->hits . Sh404sefHelperFiles::$stringDelimiter;
             $line = Sh404sefHelperFiles::$stringDelimiter . $counter . $glue . $textRecord;
             $data .= $line . "\n";
         }
     }
     // prepare data for storage
     if (!empty($header)) {
         // first record written to file, prepend header
         $data = $header . $data;
     }
     // store in file
     $status = Sh404sefHelperFiles::appendToFile($this->_filename, $data);
     // return any error
     return $status;
 }
 protected function _createSourcesGraph()
 {
     // load pChart graphic library
     $this->_loadLibs();
     // définition des données à afficher
     $dataSet = new pData();
     // need config, to know which data user wants to display : visits, unique visitors, pageviews
     $sefConfig = Sh404sefFactory::getConfig();
     // Google does not allow combining dimension=ga:medium with metric = unique visitors
     $dataType = $sefConfig->analyticsDashboardDataType == 'ga:visitors' ? 'ga:visits' : $sefConfig->analyticsDashboardDataType;
     $dataTypeString = str_replace('ga:', '', $dataType);
     // sort data for proper display
     usort($this->_rawData['sources'], array($this, '_sortSourcesDataCompareFunction'));
     // we walk the array, pulling out alternatively
     // the first and last items
     // making the new array having the largest item
     // followed by the smallest, then second largest
     // then second smallest, ...
     // which makes drawing labels much easier
     $tmpArray = array();
     $even = false;
     $max = count($this->_rawData['sources']);
     for ($i = 0; $i < $max; $i++) {
         if ($even) {
             // pull last item in sorted array
             $tmpArray[] = array_pop($this->_rawData['sources']);
         } else {
             // pull array first item
             $tmpArray[] = array_shift($this->_rawData['sources']);
         }
         // flag inversion
         $even = !$even;
     }
     // get data from response
     $data = array();
     $types = array();
     foreach ($tmpArray as $entry) {
         $value = $entry->{$dataTypeString};
         // do not add empty values, as pChart would choke on that and display a warning
         if (!empty($value)) {
             $data[] = $value;
             $types[] = Sh404sefHelperAnalytics::getReferralLabel($entry->dimension['medium']);
         }
     }
     $dataSet->AddPoint($data, "visits");
     $dataSet->AddPoint($types, "types");
     $dataSet->addSerie('visits');
     $dataSet->SetAbsciseLabelSerie("types");
     $label = JText::_('COM_SH404SEF_ANALYTICS_REPORT_SOURCES') . JText::_('COM_SH404SEF_ANALYTICS_REPORT_BY_LABEL') . Sh404sefHelperAnalytics::getDataTypeTitle();
     $dataSet->SetSerieName($label, "visits");
     // Initialise the graph
     $w = intval(0.45 * $this->_options['cpWidth']);
     $w = empty($w) ? 160 : $w;
     $radius = intval($w * 0.22);
     $margin = 5;
     $h = intval($w * 0.8);
     $centreX = intval(0.5 * $w);
     $centreY = intval(0.5 * $h);
     $chart = new pChart($w, $h);
     $fontSize = 8;
     // prepare graph
     $chart->setFontProperties($this->_baseChartPath . DS . 'Fonts/arial.ttf', $fontSize);
     $chart->loadColorPalette($this->_baseChartPath . DS . 'palettes' . DS . 'tones-2-green-soft.php');
     $chart->setGraphArea($margin, $margin, $w - $margin, $h - $margin);
     // This will draw a shadow under the pie chart
     $chart->drawFilledCircle($centreX + 4, $centreY + 4, $radius, 200, 200, 200);
     // Draw the pie chart
     $d = $dataSet->GetData();
     if (!empty($d)) {
         $chart->drawBasicPieGraph($d, $dataSet->GetDataDescription(), $centreX, $centreY, $radius, PIE_PERCENTAGE_LABEL_VALUE, 255, 255, 218);
     }
     // create a temporary file for
     $user =& JFactory::getUser();
     // make sure the root tmp dir exists
     $rootDir = 'tmp' . DS . 'sh404sef_analytics';
     Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $rootDir);
     // file name is variable to avoid browser cache
     $basePath = $rootDir . DS . md5('useless_' . $user->id . '_hashing') . DS;
     // create path and make sure there's an index.html file in it
     Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $basePath);
     $imageFileName = Sh404sefHelperAnalytics::createTempFile($basePath, $this->_options['report'] . '.' . $this->_options['accountId'] . '.sources.' . $dataTypeString);
     $chart->Render(JPATH_ROOT . DS . $imageFileName);
     // need cleaning up, so let's remove all report files for that user older than an hour or so
     Sh404sefHelperAnalytics::cleanReportsImageFiles(JPATH_ROOT . DS . $basePath, $age = 4000);
     return JURI::root() . $imageFileName;
 }
示例#4
0
 protected function _lineToArray($line, $glue = null)
 {
     $glue = is_null($glue) ? Sh404sefHelperFiles::$stringDelimiter . Sh404sefHelperFiles::$fieldDelimiter . Sh404sefHelperFiles::$stringDelimiter : $glue;
     // remove opening and closing quotes - can't use trim or ltrim, as this would remove several occurences
     if (substr($line, 0, 1) == Sh404sefHelperFiles::$stringDelimiter) {
         $line = substr($line, 1);
     }
     if (substr($line, -1, 1) == Sh404sefHelperFiles::$stringDelimiter) {
         $line = substr($line, 0, -1);
     }
     // break up the line
     $records = explode($glue, $line);
     if (empty($records)) {
         return $records;
     }
     // now clean up a bit
     foreach ($records as $i => $value) {
         // remove double quotes, and store back in array
         $records[$i] = Sh404sefHelperFiles::csvUnquote($value);
     }
     return $records;
 }
 /**
  * Creates an export file line, based on db record
  *
  * @param $record the data coming from DB
  * @param $counter, running counter
  * @param $glue , glue string between elements of records
  */
 protected function _createLine($record, $counter, $glue)
 {
     $textRecord = $record->oldurl . $glue . $record->newurl . $glue . (empty($record->cpt) ? 0 : $record->cpt) . $glue . (empty($record->rank) ? 0 : $record->rank) . $glue . (!isset($record->dateadd) ? '0000-00-00' : $record->dateadd) . $glue . Sh404sefHelperFiles::csvQuote($record->metatitle) . $glue . Sh404sefHelperFiles::csvQuote($record->metadesc) . $glue . Sh404sefHelperFiles::csvQuote($record->metakey) . $glue . Sh404sefHelperFiles::csvQuote($record->metalang) . $glue . Sh404sefHelperFiles::csvQuote($record->metarobots) . Sh404sefHelperFiles::$stringDelimiter;
     $line = Sh404sefHelperFiles::$stringDelimiter . $counter . $glue . $textRecord . "\n";
     return $line;
 }