Jump to content

Frank Vèssia

Members
  • Posts

    585
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Frank Vèssia

  1. I created a custom role which can: view, edit and delete pages but when i login with a user with that role i can only view pages... i miss something? I'm using the latest commit.
  2. I created (or trying to) an inpufieldselect that shows me all files stored in a server folder and save the value as text. It works good but i have two problems. First: I need to execute a function called "sendVideo" after the page is saved based on my select value. I tried to add an hookafter save but the code is executed everytime a page is saved and not only the current page. public function init() { $this->pages->addHookAfter('save', $this, 'sendVideo'); } Second: I need to execute my code only if i change the value of my select and do nothing if not . This is my entire code <?php class FieldtypeSelect extends Fieldtype { public static $defaultOptionValues = array (); public static function getModuleInfo() { return array( 'title' => 'Select temporary videos', 'version' => 100, 'summary' => 'This Fieldtype get files stored in /toencode/ folder', 'singular' => true, 'autoload' => true, ); } public function init() { $this->pages->addHookAfter('save', $this, 'sendVideo'); } public function sendVideo($event) { $page = $event->arguments[0]; $vfile = "http://".$_SERVER['HTTP_HOST']."/videodaconvertire/".$page->videotoconvert; $filename = $page->id; function sendRequestv($xml) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://manage.encoding.com/"); curl_setopt($ch, CURLOPT_POSTFIELDS, "xml=" . urlencode($xml)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); return curl_exec($ch); } // Begin processing User's POST if(!empty($vfile)) { // Preparing XML request // Main fields $req = new SimpleXMLElement('<?xml version="1.0"?><query></query>'); $req->addChild('userid', 'xxxxxx'); $req->addChild('userkey', 'xxxxxxxxxxxxxxxxxxxx'); $req->addChild('action', 'AddMedia'); $req->addChild('source', $vfile); $req->addChild('notify', 'http://www.librolo.com/addmedia/'); $formatNode = $req->addChild('format'); $formatNode->addChild('output', 'flv'); $formatNode->addChild('size', '650x366'); $formatNode->addChild('bitrate', '512k'); $formatNode->addChild('destination','ftp://xxx:xxx@librolo.com/public_html/video/'.$filename.'.flv'); $logoNode = $formatNode->addChild('logo'); $logoNode->addChild('logo_source', 'http://www.librolo.com/watermark.png'); $logoNode->addChild('logo_x', '4'); $logoNode->addChild('logo_y', '4'); $logoNode->addChild('logo_mode', '1'); $formatNode = $req->addChild('format'); $formatNode->addChild('output', 'thumbnail'); $formatNode->addChild('time', '10%'); $formatNode->addChild('width', '650'); $formatNode->addChild('destination', 'ftp://xxx:xxx@librolo.com/public_html/thumbs/'.$filename.'_1.jpg'); $formatNode = $req->addChild('format'); $formatNode->addChild('output', 'thumbnail'); $formatNode->addChild('time', '30%'); $formatNode->addChild('width', '650'); $formatNode->addChild('destination', 'ftp://xxx:xxx@librolo.com/public_html/thumbs/'.$filename.'_2.jpg'); $formatNode = $req->addChild('format'); $formatNode->addChild('output', 'thumbnail'); $formatNode->addChild('time', '50%'); $formatNode->addChild('width', '650'); $formatNode->addChild('destination', 'ftp://xxx:xxx@librolo.com/public_html/thumbs/'.$filename.'_3.jpg'); $formatNode = $req->addChild('format'); $formatNode->addChild('output', 'thumbnail'); $formatNode->addChild('time', '70%'); $formatNode->addChild('width', '650'); $formatNode->addChild('destination', 'ftp://xxx:xxx@librolo.com/public_html/thumbs/'.$filename.'_4.jpg'); $formatNode = $req->addChild('format'); $formatNode->addChild('output', 'thumbnail'); $formatNode->addChild('time', '90%'); $formatNode->addChild('width', '650'); $formatNode->addChild('destination', 'ftp://xxx:xxx@librolo.com/public_html/thumbs/'.$filename.'_5.jpg'); // Sending API request $res = sendRequestv($req->asXML()); try { // Creating new object from response XML $response = new SimpleXMLElement($res); // If there are any errors, set error message if(isset($response->errors[0]->error[0])) { $error = $response->errors[0]->error[0] . ''; } else if ($response->message[0]) { // If message received, set OK message $message =$response->message[0]; } } catch(Exception $e) { // If wrong XML response received $error = $e->getMessage(); } // Displaying error if any if (!empty($error)) { $this->message(htmlspecialchars($error)); } // Displaying message if (!empty($message)) { //$this->message($message); } } } public function getInputfield(Page $page, Field $field) { function read_folder_directory($dir = "root_dir/dir") { $listDir = array(); if($handler = opendir($dir)) { while (($sub = readdir($handler)) !== FALSE) { if ($sub != "." && $sub != ".." && $sub != "Thumb.db" && $sub != "Thumbs.db") { if(is_file($dir."/".$sub)) { $listDir[] = $sub; }elseif(is_dir($dir."/".$sub)){ $listDir[$sub] = ReadFolderDirectory($dir."/".$sub); } } } closedir($handler); } return $listDir; } $inputfield = $this->modules->get('InputfieldSelect'); $inputfield->addOption(''); // blank or unselected option $files = read_folder_directory ($_SERVER["DOCUMENT_ROOT"]."/videodaconvertire/"); if ($files) { foreach ($files as $file) { $inputfield->addOption($file,$file); } } return $inputfield; } public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data'] = 'text NOT NULL'; $schema['keys']['data_exact'] = 'KEY `data_exact` (`data`(255))'; $schema['keys']['data'] = 'FULLTEXT KEY `data` (`data`)'; return $schema; } public function sanitizeValue(Page $page, Field $field, $value) { return $value; } public function ___getConfigInputfields(Field $field) { $inputfields = NULL; return $inputfields; } } This is made for adding a video to a page using encoding.com apis. Basically i upload some videos in a folder, than i create a page and choose a video for encoding, after the page is saved i use encoding.com apis to send request to their server via xml and after the video is encoded and thumbnails created with a callback function that call an hidden pw page i editing the page, add the thumbnails and save it again.
  3. I tried, i can delete images from api..but not from admin...
  4. Ok, i've added the php validation and imageSizer correctly. Regarding the error in the admin i'm using PW 2.1 latest commit, cannot say more. I'm adding images to user profile in a multi-image field, that's all. It happens for every users, i can see the images both in front end and in the admin but i cannot delete them from the admin, now i will try to delete from api...i will let you know.
  5. Your point is correct but i have to say that all my forms have action="" and js call external php pages for making all so nobody can access them...however adding 2 more lines of php for validation code don't cost anything... ;D
  6. come on...my website will be not so huge to entering in the target of some hacker or similar, however without js you cannot enter in the website, just the homepage. Try to "use" Facebook without js... I want to deliver the best experience to my users and i decided to use a lot of javascript and css with special features, i also will not support IE6. I don't think the 1% of users with js disabled will affect my activities...i want to focus on a particular target of people.
  7. If someone don't have javascript they cannot view the website... and i show up an alert message. I have too many js controls and javascript is essential
  8. This is what i've done till now. I'm using jquery validation for image type and size so my php now is more clean. I still need to implement the ImageSizer class because i have some problems with your code but i will explain later. Now i have another problem. $("#profilephotoform").validate({ debug: false, rules: { imageUpload: { required: true, accept: true, filesize: 524288 } }, messages: { imageUpload: "Solo immagini JPG, GIF o PNG di massimo 500 Kb", } }); <? function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } require_once('../index.php'); $input = wire('input'); $sanitizer = wire('sanitizer'); $users = wire('users'); $user = wire('user'); if($_FILES['imageUpload']['name']) { $filename = stripslashes($_FILES['imageUpload']['name']); $extension = getExtension($filename); $image_name=time().$user->id.'.'.$extension; $newname="../site/tmpfiles/profiles/".$image_name; $copied = move_uploaded_file($_FILES['imageUpload']['tmp_name'], $newname); if ($copied) { $user->setOutputFormatting(false); $user->profilephoto->add($config->paths->root."site/tmpfiles/profiles/".$image_name); $user->save(); //delete copied image $tmpfile = $config->paths->root."/site/tmpfiles/profiles/".$image_name; if (file_exists($tmpfile)) { unlink ($tmpfile); } }else{ print "Errore nel salvataggio del file"; exit; } print $user->profilephoto->last()->size(250,0)->url; } ?> The code works good now, i can add images but when i try to delete one of these images from the admin i get this error; Notice: Trying to get property of non-object in /home/librolo/public_html/wire/core/Pagefiles.php on line 207 Fatal error: Call to a member function path() on a non-object in /home/librolo/public_html/wire/core/Pagefiles.php on line 207 P.S.: How can i delete images using api?? Getting back to ImageSizer i tried to implement it but in your code you wrote: $u->profilephoto->add($filename); $filename is the path of the image saved in tmp folder, so i changed to $image that is the new image object created from imageSizer class, but $image return an object and it doesn't work. I printed the $image array and i found $image->filename but also this is not good because is protected, like all properties of $image...
  9. Very nice, i will try. Suggestion: could be really nice if this module can save every login as pw page (choosing the parent page as option)...so an admin can control anytime all logins in his website.
  10. that's my code, i didn't use the ImageSizer class cause of my bad php knowledge but it works... thanks. <? define ("MAX_SIZE","100"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } require_once('../index.php'); $input = wire('input'); $sanitizer = wire('sanitizer'); $users = wire('users') if($input->post->userid) { $filename = stripslashes($_FILES['imageUpload']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { print "File non valido"; exit; }else{ $size=filesize($_FILES['imageUpload']['tmp_name']); if ($size > MAX_SIZE*1024){ print 'File troppo grosso'; exit; } //copy the image in secure folder $image_name=time().'.'.$extension; $newname="../site/tmpfiles/profiles/".$image_name; $copied = copy($_FILES['imageUpload']['tmp_name'], $newname); if ($copied) { $userid = $sanitizer->text($input->post->userid); $u = $users->get($userid); $u->setOutputFormatting(false); $u->profilephoto->add("http://".$_SERVER['HTTP_HOST']."/site/tmpfiles/profiles/".$image_name); $u->save(); //delete copied image $tmpfile = $_SERVER["DOCUMENT_ROOT"]."/site/tmpfiles/profiles/".$image_name; if (file_exists($tmpfile)) { unlink ($tmpfile); } }else{ print "Errore nel salvataggio del file."; exit; } } print $u->profilephoto->eq(1)->url; } ?> what is thew commando for remove an image? ->remove maybe?
  11. I'm resuming this post cause now pw 2.1 is out with new user system ;D. So is there now a way to add image from disk from my external form using api?
  12. Thanks Apeisa, i run 2.1 lc but didn't notice that post...
  13. I always "fight" with wire method, this time i need to create a new user outside PW root folder. $name = wire('sanitizer')->username(wire('input')->post->login_name); $pass = wire('input')->post->login_pass; $email = wire('sanitizer')->email(wire('input')->post->email); $u = new User(); $u->name = $name; $u->pass = $pass; $u->addRole("guest"); $u->save(); i get error on addRole(), i need to add wire at some point but i don't know where.
  14. thanks Ryan, the second example works good. 8) I cannot use limit because i need to know the total of pages in my archive. P.S: now I count 14k pages.
  15. for using $page->count i need first make a query with get o find method...
  16. Ops... I moved the template folder but i get the same notice
  17. Great template. Installed right now. I get this notice: Notice: Trying to get property of non-object in /home/librolo/public_html/wire/templates-admin/default.php on line 71 and before main menu i can see the link "admin>" There are also some css issues.
×
×
  • Create New...