-
Posts
292 -
Joined
-
Last visited
Everything posted by Manol
-
Sorry, to much wine or to little sleep: $value->description
- 1 reply
-
- 4
-
-
Hello. I'm trying to get the title of a pdf file from a FieldtypeFile within a module, with print_r I can see basename, description.. but don't know how to get the value, any hint? $file = array(); $file = $pagina->get($field->name)->getArray(); foreach ($pagina->get($field->name) as $key => $value) { echo $key. " -> ". $value . "\n"; } Thank you.
-
Hi Soma. I've tried your way like you posted yesterday and today but I'm getting back the whole page maybe because my call is $http.post('http://ip/web-service/', {action: 'getPage', pageId: 1046 }) .success(function(data) { console.debug("page",data); }) As Jan pointed $this->addHook('ProcessPageView::pageNotFound', $this, 'webService'); is working for me, maybe is not the best way but it works as expected. Thank you
-
Fantastic Jan you're my star, it was a really good idea, now: PwAngular.module class PwAngular extends WireData implements Module, ConfigurableModule { ... public function init() { $this->addHook('ProcessPageView::pageNotFound', $this, 'webService'); ... public function webService($event) { // Check if asking for a web service $url = $event->arguments('url'); if ($url != '/web-service/') return; //Let pageNotFound() handle it header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK', true, 200); // Get post Data $request = file_get_contents('php://input'); $getPost = json_decode($request,true); $action = $getPost['action']; switch ($action) { case "getPage": $pageId = $getPost['pageId']; $event->return =$this->get_Page($pageId); break; } } protected function get_Page($pageId) { $pagina = wire('pages')->get($pageId); $array = array(); // fields to be avoided $avoid = array("FieldtypeFieldsetOpen", "FieldtypeFieldsetClose","FieldtypeFieldsetTabOpen","FieldtypeFieldsetTabClose"); $array['id'] = $pagina->id; foreach($pagina->fields as $field) { if (!in_array($field->type, $avoid)) { // si el campo no esta vacio if( htmlspecialchars($pagina->get($field->name)) ) if($field->type == "FieldtypePage"){ $buscar = htmlspecialchars($pagina->get($field->name)); $paginas = $pages->get($buscar); $array[$field->name] = $paginas->title; } else { // if textarea do not strip html tags if($field->type == "FieldtypeTextarea" || $field->type == "FieldtypeTextareaLanguage" ){$array[$field->name] = $pagina->get($field->name);} else {$array[$field->name] = htmlspecialchars($pagina->get($field->name));} } } } return json_encode($array); } my.js $http.post('http://ip/web-service/', {action: 'getPage', pageId: 1046 }) .success(function(data) { console.debug("success",data); }) and BUMP! working.
-
Just want to call a pw webservice from a mobile device and the service logic within a pw module.
-
Still not getting there. 1.- Javascript (angularjs) $http.post('http://mywebpage/user/', {name:'manol'}). success(function(data) { console.log(data); }). error(function(data) { console.log(data); }); 2.- and I wish to get json data back # PW MODULE $array = array(); $array['name'] = wire("user")->name; $array['language'] = wire("user")->language->title; $event->return = json_encode($array); 3.- Which hook or whatever should I use?, http://mywebpage/user/ doesn't correspond to any template.
-
Probably what I'm asking for is simpler than what I've exposed in the lines above. Just need to catch an ajax call from a pw module and return some data back. .The ajax call can come from a mobile device or other website located in a different server. Thank you
-
Hello. I would like to make an ajax call and get some data back. The way I use to do it is, make a call from javascript to a url that would be a pw page that uses the template that would return the data, like this: Define a page under /web-service/get-page that uses getpage.php template Javascript (angularjs) $http({url: '/web-service/get-page/', method: "POST", data: { pageId: pageId }} ) .success(function(response){ deferred.resolve(response); }); PHP template ( getpage.php ) <?php /** * datos enviados mediante JSON * @return [type] [description] */ function getPost(){ $request = file_get_contents('php://input'); return json_decode($request,true); } $getPost = getPost(); $pageId = $getPost['pageId']; $pagina = wire('pages')->get($pageId); $array = array(); // fields to be avoided $avoid = array("FieldtypeFieldsetOpen", "FieldtypeFieldsetClose","FieldtypeFieldsetTabOpen","FieldtypeFieldsetTabClose"); foreach($pagina->fields as $field) { if (!in_array($field->type, $avoid)) { // si el campo no esta vacio if( htmlentities($pagina->get($field->name)) ) $array[$field->name] = htmlentities($pagina->get($field->name)); } } echo json_encode($array); ?> My question is: How can I avoid creating a template and defining a page that uses it? I wish to intercept the ajax call from a module and return the data from that module without creating templates and pages. Is that possible? Thank you.
-
Hi Macrura. In the example below you´ll get a list of all children of the actual page. <script> app.controller('myCtrl', function ($scope) { $scope.children = []; $scope.children = <?=$page->getChildren()?>; }); </script> <div ng-controller="myCtrl"> <ul> <li ng-repeat="child in children">{{child.title}}</li> </ul> </div> The code is really clean and is not only that but you can make use of thousands of modules already available and a huge community. As mr-fan said you get lots of videos, docs, books.
-
A starting point module to use angularjs in our templates in an easy manner.
-
New methods: $page->getPage() $page->getPage(1015) $page->getChildren() $page->getChildren(2024) $page->getChildren('template=products')
-
Module updated 1.- Added methods $page->getChildren() $page->getPage() 2.- Now you can inject scripts trough module configuration
-
If you install this module you´ll be able to use angular and use it in your templates directly. Example of a list of all children of the actual page. <script> app.controller('myCtrl', function ($scope) { $scope.children = []; $scope.children = <?=$page->getChildren()?>; }); </script> <div ng-controller="myCtrl"> <ul> <li ng-repeat="child in children">{{child.title}}</li> </ul> </div>
- 6 replies
-
- 10
-
-
This is the way I use to integrate both worlds together. 1.- _header.php ( or whatever is called the file that contains your <body> tag ) <head> ... <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <script>var app = angular.module('myApp', [])</script> </head> <body ng-app="myApp"> ... 2.- yourTemplate.php <script> app.controller('myCtrl', function ($scope) { $scope.myvar = []; $scope.myvar = <?=getChildren("template=yourtemplatename")?>; console.debug("my Object form php",$scope.myvar); }); </script> <!-- now $scope.myvar is accesible --> <div ng-controller="myCtrl"> </div> 3.- getChildren is a function that I include in _func.php function getChildren($pageId) { $pagina = wire('pages')->get($pageId); // fields to be avoided $avoid = array("FieldtypeFieldsetOpen", "FieldtypeFieldsetClose","FieldtypeFieldsetTabOpen","FieldtypeFieldsetTabClose"); // fields that must be returned $wanted = $fields; // selector $paginas = $pagina->find($selector); $arr = array(); foreach ($paginas as $child) { $array = array(); foreach($child->fields as $field) { $array['id'] = $child->id; // if we dont' want all fields back if ( !in_array($field->type, $avoid) && in_array($field->name, $wanted) && (count($wanted)>0) ) { $array[$field->name] = htmlspecialchars($child->get($field->name)); } // we want all fields back if ( !in_array($field->type, $avoid) && (count($wanted)==0) ) { $array[$field->name] = htmlspecialchars($child->get($field->name)); } } array_push($arr, $array); } echo json_encode($arr); }
- 6 replies
-
- 11
-
-
Is it possible to serve files from S3 and delete them from the asses folder? Great module zyON.
-
Actually I'm using angularjs and trying to do an api to use Processwire as a backend service. https://github.com/manviny/ProcesswireToJson
-
Hi there. Any hint on how to login to pw with administrator credentials from javascript being it installed in a different server ( or locally ) than processwire? Thanks.
-
Can I use a regex in here? $products = $pages->get("/product/")->find("areas=$area");
-
Yes its a textfile, the problem is that using *= in the following case $area = 3 product = 31 -> areas = 2|13 product = 34 -> areas = 3 It would match 3 and 13
-
Hello guys. I'm trying to find a list of products that can belong to several areas, the areas consist in a number or numbers separated by "|" like the following example: 1.- Some products: product = 31 -> areas = 3|16 belongs to area 3 and 16 product = 32 -> areas = 2|14 product = 33 -> areas = 5 product = 34 -> areas = 3 2.- Area I'm looking for: $area = 3 3.- My selector $products = $pages->get("/product/")->find("areas=$area"); 4.- results I'm getting product 34 whereas I would like to get product 31 as well. Any ideas? Thank you.
-
Has anybody got publishing images and text from a pw page to facebook?
-
Hi Nico I deleted some bits of the code, but even that bit doesn't get the user id, it just gets a 0 <?php /** * ProcessWire 'Hello world' demonstration module * * Demonstrates the Module interface and how to add hooks. * * ProcessWire 2.x * Copyright (C) 2010 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class FaceMail extends WireData implements Module { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * * @return array * */ public static function getModuleInfo() { return array( // The module'ss title, typically a little more descriptive than the class name 'title' => 'Facebook Email Publish', // version: major, minor, revision, i.e. 100 = 1.0.0 'version' => 101, // summary is brief description of what this module is 'summary' => 'Publica noticias en Facebook y envia emails masivos', // Optional URL to more information about the module 'href' => 'http://www.processwire.com', // singular=true: indicates that only one instance of the module is allowed. // This is usually what you want for modules that attach hooks. 'singular' => true, // autoload=true: indicates the module should be started with ProcessWire. // This is necessary for any modules that attach runtime hooks, otherwise those // hooks won't get attached unless some other code calls the module on it's own. // Note that autoload modules are almost always also 'singular' (seen above). 'autoload' => true, ); } /** * Initialize the module * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. * */ public function init() { // add a hook after the $pages->save, to issue a notice every time a page is saved $this->pages->addHookAfter('save', $this, 'publicaEnvia'); } /** * Example1 hooks into the pages->save method and displays a notice every time a page is saved * */ public function publicaEnvia($event) { $page = $event->arguments[0]; /** * 1.- sino es la pagina de noticia -> salir */ if($page->template != 'noticia') return; /** * 2.- si esta check facebook -> publicalo * @var [type] */ if($page->facebook==1) { include_once 'fb/facebook.php'; $appId = '70373825635****'; $secret = 'd30530a5dcd4e5829e6c8bc8ba72****'; // $returnurl = 'http://indinet.es/facebook/post.php'; $returnurl = 'http://casergi.com'; $permissions = 'manage_pages, publish_stream'; $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret)); $fbuser = $fb->getUser(); $this->message("user " . $fbuser); } // facebook /** * 3.- se esta check enviar email a clientes -> envia correos * @var [type] */ if($page->enviar_a_Clientes==1) { $usuarios = wire(pages)->get("/acceso/access/users/"); $emails = $usuarios->children(); foreach ($emails as $email) { if($email->email) $this->message("enviado a: ". $email->email. ", "); mail($email->email, $page->title, $page->publicidad, "From: cassergi.com\nContent-Type: text/html"); } $this->message("enviado por correo a los clientes"); } } }
-
Hello. I wish to publish some processwire pages to facebook, including images. I got it working thanks to adrian and Martijn using ifttt, but I would like to use my own code and publish images or other stuff through the facebook php sdk. At the moment I've created a simple php page in my localhost that works, here is the code <?php include_once 'inc/facebook.php'; $appId = '703738********'; $secret = 'd30530a5dcd*************'; $returnurl = 'http://myweb.es/facebook/post.php'; $permissions = 'manage_pages, publish_stream'; $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret)); $fbuser = $fb->getUser(); if($fbuser){ try{ $message = array( 'message' => 'foo' ); $result = $fb->api('/me/feed/','POST',$message); if($result){ echo 'Published'; } }catch(FacebookApiException $e){ echo $e->getMessage(); } }else{ $fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions)); echo '<a href="'.$fbloginurl.'">Login with Facebook</a>'; } ?> but when I try it on a pw template or module it doesn't work $this->pages->addHookAfter('save', $this, 'fb'); ..... if($page->facebook==1) { include_once 'fb/facebook.php'; $appId = '70373825******'; $secret = 'd30530a5dcd4e5829e6c8b********'; // $returnurl = 'http://indinet.es/facebook/post.php'; $returnurl = 'http://pwpage.com'; $permissions = 'manage_pages, publish_stream'; $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret)); $fbuser = $fb->getUser(); $this->message("user " . $fbuser); } // facebook .... any ideas?
-
works changing time lo live.
-
Yes I changed to 1 minute but no results. My original idea was to publish some stuff to facebook wall after saving a page in the admin area, title, description and images. I got and external php that does exactly that and works: <?php include_once 'inc/facebook.php'; $appId = '703738********'; $secret = 'd30530a5dcd*************'; $returnurl = 'http://myweb.es/facebook/post.php'; $permissions = 'manage_pages, publish_stream'; $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret)); $fbuser = $fb->getUser(); if($fbuser){ try{ $message = array( 'message' => 'foo' ); $result = $fb->api('/me/feed/','POST',$message); if($result){ echo 'Published'; } }catch(FacebookApiException $e){ echo $e->getMessage(); } }else{ $fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions)); echo '<a href="'.$fbloginurl.'">Login with Facebook</a>'; } ?> I'm trying to implement that in a hook, there is a checkbox, if is on then publish to facebook $this->pages->addHookAfter('save', $this, 'fb'); ..... if($page->facebook==1) { include_once 'fb/facebook.php'; $appId = '70373825******'; $secret = 'd30530a5dcd4e5829e6c8b********'; // $returnurl = 'http://indinet.es/facebook/post.php'; $returnurl = 'http://pwpage.com'; $permissions = 'manage_pages, publish_stream'; $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret)); $fbuser = $fb->getUser(); $this->message("user " . $fbuser); } // facebook .... I'm trying first to check the user id, but the result is just 0, whereas in the original file outside pw I get the user id without problems. Any ideas, Why?