function qa_upload_file_one($maxfilesize = null, $onlyimage = false, $imagemaxwidth = null, $imagemaxheight = null)
{
    $file = reset($_FILES);
    return qa_upload_file($file['tmp_name'], $file['name'], $maxfilesize, $onlyimage, $imagemaxwidth, $imagemaxheight);
}
Beispiel #2
0
 public function actionFillDb()
 {
     set_time_limit(0);
     ini_set('mysqli.reconnect', 'on');
     ini_set('mysql.connect_timeout', 400);
     // 		foreach (glob("C:/Users/fabio/git/qea/webapp/protected/vendors/qea/qa-include/*.php") as $filename)
     // 		{
     // 			inclde $filename;
     // 		}
     $tag = "";
     $criteria = new CDbCriteria();
     $criteria->condition = "post_type_l1 like '%useful%' AND post_type_l3 like '%si%' ";
     // 			$criteria->condition = "fbpid = 143370932459708";
     $posts = FbPost::model()->findAll($criteria);
     foreach ($posts as $p) {
         $blob_id = null;
         if ($this->addFakeName($p->author_id)) {
             $qa_user_id = $this->addAuthor($p->author_id);
         }
         if (is_array($qa_user_id)) {
             $qa_user_id = $qa_user_id[0];
         }
         // 				$tag =  str_replace("_baseline", "",$p->post_type_l2);
         // 				$tag =  str_replace("_", "-",$p->post_type_l2);
         //categories
         if (isset($p->degree_group_id)) {
             $category_id = $this->setSecondLevelCategory($p->degree_group_id, 1);
         } else {
             if (isset($p->exam_group_id)) {
                 $exam_group = ExamGroup::model()->findByPk($p->exam_group_id);
                 $course = Courses::model()->findByPk($exam_group->courses_id);
                 $parent = $this->setSecondLevelCategory($course->degree_id, 0);
                 $category_id = $this->setThirdLevelCategory($course->name, $parent);
                 // 				 	$exam_group = ExamGroup::model()->findByPk($p->exam_group_id);
                 // 				 	$course = Courses::model()->findByPk($exam_group->courses_id);
                 $tag = $course->name;
                 $tag = str_replace(" ", "-", $tag);
                 // 				 	$tag = $tag.",";
             }
         }
         $photo = PhotoFbPost::model()->findByAttributes(array('element_id' => $p->fbpid));
         if (isset($photo)) {
             $photo->medium = str_replace("/" . $photo->fid . "jpeg", "", $photo->medium);
             $blob_id = qa_upload_file($photo->medium, $photo->fid . 'jpeg');
         }
         $tag_hold = "";
         $substrmessage = substr($p->message, 0, 50);
         if (is_int(strpos($substrmessage, "["))) {
             for ($i = strpos($substrmessage, "[") + 1; $i < strlen($p->message); $i++) {
                 if ($p->message[$i] == "]") {
                     break;
                 }
                 $tag_hold = $tag_hold . $p->message[$i];
             }
             if ($tag == "") {
                 $tag = str_replace(" ", "-", $tag_hold);
             } else {
                 $tag = $tag . "," . str_replace(" ", "-", $tag_hold);
             }
         }
         $title = substr($p->message, 0, 100);
         $title = $title . "...";
         //posts
         if (qa_post_check_by_fb_id($p->fbpid) == null) {
             if ($blob_id != null) {
                 $p->message = '<p><img alt="" src="http://www.universitree.com/?qa=blob&amp;qa_blobid=' . $blob_id['blobid'] . '" style="height:250px;"><br>' . $p->message . '</p>';
                 //RIVEDI
                 $question_id = qa_post_create_with_data("Q", null, $title, $p->message, 'html', $p->created_time, $category_id, $tag, $qa_user_id);
                 qa_post_set_hidden($question_id, true);
             } else {
                 $question_id = qa_post_create_with_data("Q", null, $title, $p->message, '', $p->created_time, $category_id, $tag, $qa_user_id);
             }
             qa_post_create_fb_mapping($question_id, $p->fbpid);
             $this->addLikes($p->fbpid, $question_id);
             $this->addAnswer($p->fbpid, $question_id);
             //	$this->deletePost($p->fbpid);
         }
         // 				$comments = FbPostComment::model()->findAllByAttributes(array("ref_entity_id" => $p->fbpid));
         // 				foreach ($comments as $c){
         // 					if($this->addFakeName($c->author_id))
         // 					if(!$this->addAuthor($c->author_id))
         // 						echo "problemi di inconsistenza nei commenti";
         // 				}
         //inserire qui gli unset
         unset($blob_id);
         unset($qa_user_id);
         unset($category_id);
         unset($exam_group);
         unset($course);
         unset($photo);
         $p->post_type_l1 = "ut_base";
         $p->save();
     }
     //$this->deleteUselessPost();
 }