elabx

Members
  • Content count

    332
  • Joined

  • Last visited

  • Days Won

    3

elabx last won the day on December 29 2015

elabx had the most liked content!

Community Reputation

386 Excellent

About elabx

  • Rank
    Sr. Member
  • Birthday 04/12/1988

Profile Information

  • Gender
    Male
  • Location
    Mexico City

Recent Profile Visitors

4,677 profile views
  1. elabx

    Try to turn off output formatting before changing the value.
  2. elabx

    My thought is that you could use a hook to add the html into the rendering of the Inputfield, or maybe you could add a Markup field in FormBuilder so you can place this link, right bellow the checkbox.
  3. elabx

    Check this post: https://processwire.com/talk/topic/16932-adding-classes-to-repeater-items-for-custom-styling-in-admin/
  4. Hi everyone! I have a module that gets the top visited pages of a website, I have a problem that when the cache invalidates by time guest users doesn't seem to be able to use the module that actually get's the info. Heres the code on the template file: $mostPopular = $cache->get("mostpopular"); if(!$mostPopular){ $latest = $modules->get("GoogleAnalyticsAPI"); $latest = $latest->getMostPopular(); $pa = new PageArray(); foreach($latest as $popular){ $thePage = $pages->get($sanitizer->pagePathName($popular['path'])); if($thePage->id){ $pa->add($thePage); } } $pa = $pa->filter("template=articulo"); $mostPopular = $pa; $cache->save("mostpopular", $pa, 604800); } Here's the code for the Google Analytics module: <?php /** * GoogleAnalyticsAPI (0.0.1) * Google Analytics API Wrapper * * @author elabx * * ProcessWire 3.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class GoogleAnalyticsAPI extends WireData implements Module,ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Google Analytics API Wrapper', 'version' => 1, 'author' => 'Eduardo San Miguel', 'summary' => 'Description of what this module does and who made it.', 'href' => 'http://www.domain.com/info/about/this/module/', 'autoload' => true, // set to true if module should auto-load at boot 'requires' => array( 'PHP>=5.4.1', 'ProcessWire>=3.x' ), ); } public $configData = array(); public $analytics = null; public function init() { // $this->addStyle("custom.css"); // $this->addScript("custom.js"); // $this->addHookAfter("class::function", $this, "yourFunction"); } public function initClient(){ // Use the developers console and download your service account // credentials in JSON format. Place them in this directory or // change the key file location if necessary. $configData = wire('modules')->getModuleConfigData($this); $KEY_FILE_LOCATION = wire("config")->paths->assets . 'service.json'; $this->log->save("google-debug", $KEY_FILE_LOCATION); // Create and configure a new client object. $client = new Google_Client(); $client->setApplicationName("ProcessWire CMS Analytics Reporting"); $client->setAuthConfig($KEY_FILE_LOCATION); $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']); $analytics = new Google_Service_AnalyticsReporting($client); $this->analytics = $analytics; //return $analytics; } public function getMostPopular(){ $this->initClient(); $analytics = $this->analytics; $VIEW_ID = "123456789"; // Get unique pageviews and average time on page. // Create the DateRange object. $dateRange = new Google_Service_AnalyticsReporting_DateRange(); $dateRange->setStartDate("7daysAgo"); $dateRange->setEndDate("today"); // Create the Metrics object. $sessions = new Google_Service_AnalyticsReporting_Metric(); $sessions->setExpression("ga:sessions"); $sessions->setAlias("sessions"); $dimensions = new Google_Service_AnalyticsReporting_Dimension(); //$dimensions->setExpression("ga:sessions"); $dimensions->setName("ga:pagePath"); $orderby = new Google_Service_AnalyticsReporting_OrderBy(); //$orderby->setOrderType("HISTOGRAM_BUCKET"); $orderby->setFieldName("ga:sessions"); $orderby->setSortOrder("DESCENDING"); // Create the ReportRequest object. $request = new Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId($VIEW_ID); $request->setDateRanges($dateRange); $request->setMetrics(array($sessions)); $request->setDimensions(array($dimensions)); $request->setOrderBys(array($orderby)); $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests( array( $request) ); $response = $analytics->reports->batchGet( $body ); foreach($response->getReports() as $i => $report){ //d($reports->getData()->getRows()); //d($reports); //$report = $reports[0]; $header = $report->getColumnHeader(); $dimensionHeaders = $header->getDimensions(); //d($dimensionHeaders); $metricHeaders = $header->getMetricHeader()->getMetricHeaderEntries(); $rows = $report->getData()->getRows(); $sessionsPerPageData = array(); for ( $rowIndex = 0; $rowIndex < count($rows); $rowIndex++) { $row = $rows[ $rowIndex ]; $dimensions = $row->getDimensions(); $metrics = $row->getMetrics(); for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) { $sessionsPerPageData[$rowIndex]["path"] = $dimensions[$i]; //print_r($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n"); } for ($j = 0; $j < count($metrics); $j++) { $values = $metrics[$j]->getValues(); for ($k = 0; $k < count($values); $k++) { $entry = $metricHeaders[$k]; $sessionsPerPageData[$rowIndex]["sessions"] = $values[$k]; //print_r($entry->getName() . ": " . $values[$k] . "\n"); } } } $this->log->save("google-debug", print_r($sessionsPerPageData, true)); return $sessionsPerPageData; } } } Could anyone give me a hint on why guest users wouldn't be able to use this module? If I login as admin it all works fine again, every time the cache invalidates, the info gets retrieved again.
  5. I've done it getting the actual Inputfield module, not the Fieldtype, I'd be very curious to see if the getInputfield method works! Get back to us on what works @bernhard :D
  6. I guess that's because users are pages under admin, so If a user with "guest" role (which is the default for every request made to the site) runs that code, it won't normally have access to that data, unles specified with check_access selector.
  7. elabx

    I have done several integrations and I just basically grab this library through composer and use a private app credentials, the library also handles the API throttling which is extra nice when working with large amounts of data.
  8. elabx

    THIS has happened to me multiple times calling it in the wrong place.
  9. elabx

    Shouldn't output formatting be turned off in the $copy page, which is the one getting saved?
  10. elabx

    Try: $datetofind=strtotime($date); foreach($page->special_days->find("date_value={$datetofind}, time_from!='', time_to!=''") as $special_day) { $slot_txt.=$special_day->time_from." to ".$special_day->time_to."<br/>"; }
  11. elabx

    i also stumbled on this issue! Needed a drink too! Even asked a few days ago why this behaves like this! https://processwire.com/talk/topic/14638-no-input-data-when-post-form-with-ajax/?tab=comments#comment-163444
  12. elabx

    Can confirm it works on PW3 too, I had some issues with the included AWS SDK: So just for trying something out because I couldn't figure out anything from the error, I switched to installing the Amazon SDK through composer to get the latest version of the SDK and I basically just had to change how the S3 client is initialized. $this->client = new S3Client([ 'version' => 'latest', //Hardcoded value, think this has to do with the SDK version? 'region' => 'us-east-2', //Hard coded value for now, could be a config field 'credentials' => [ 'key' => $this->s3_key, 'secret' => $this->s3_secret, ], ]); Also removed the require_once for the included SDK.
  13. elabx

    Doesn't the previous output the link already for download?? You can use an if statement to check if there is an uploaded file: <?php if($publication->repeater_download):?> <p><?=$publication->repeater_description?></p> <a href="<?=$publication->repeater_download->url?>">Download</a> <?php endif ?> It uses naming convention, the following code will render the file content in site/template/fields/Repeater_publication.php : (EDIT: Edited some code on previous post, I was mixing Repeater Matrix field rendering with normal Repeaters) <?php //Render the repeater field in the current page $page->render("Repeater_publication"); And inside site/template/fields/Repeater_publication.php : <?php foreach($value as $publication):?> <p> <?=$publication->publication_year?></p> <?php endforeach?> Maybe you can save this for later if you already got the rendering almost done with a more common approach
  14. Try setting the output formatting for the $flexibleContentRepeater repeater matrix item (which is a page!) $flexibleContentRepeater->of(false); I also think you shouldn't be saving the page inside the hook:
  15. elabx

    I think you might have a mistake here: $publications = $subpage->publication_year(); If I understand your setup correctly that returns a year integer, so looping on that will have no relevant effect. I think the final code could look like this: <?php foreach($page->children() as $subpage): ?> <!-- $subpage are the "year" pages --> <h1>Publications on: <?php $subpage->title </h2> <!-- eg. Publications on 1997 --> <?php foreach($subpage->Repeater_publications as $publication): ?> <p><?=$publication->repeater_description?></p> <a href="<?=$publication->repeater_download->url?>">Download</a> <?php endforeach; ?> <?php endforeach; There is a way to render the repeater field as its own template (or any field for what matters) with a feature called field rendering, you would have to create a template file as: templates/fields/Repeater_publication.php that actually renders some markup when calling the render method on the repeater field reference. <?php foreach($page->children() as $subpage): ?> <!-- $subpage are the "year" pages --> <h1>Publications on: <?php $subpage->title </h2> <!-- eg. Publications on 1997 --> <?php echo $page->render("Repeater_publications"); ?> <?php endforeach; And inside site/template/fields/Repeater_publication.php : <?php foreach($value as $publication):?> <p> <?=$publication->publication_year?></p> <?php endforeach?> Check this blog post for more info on field rendering, to see which variables are available in the template file: https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/#processwire-3.0.5-introduces-field-rendering-with-template-files