Exemple #1
0
 public function addLinkBy(Users $byUser, $url)
 {
     $data = array('url' => $url, 'linkable_id' => $this->id, 'linkable_type' => get_class($this), 'site_id' => Sites::findByUrl($url)->id, 'user_id' => $byUser->id);
     $link = new Links();
     $link->save($data);
     return $this;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Links();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Links'])) {
         $model->attributes = $_POST['Links'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->cod_link));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Links::$rules);
     if ($validator->passes()) {
         $link = new Links();
         $link->message = Input::get('message');
         $link->recipient_id = Input::get('recipient_id');
         $link->sender_id = Auth::user()->id;
         $link->save();
         return Redirect::back()->with('message', 'Your link was sent successfully!');
     } else {
         return Redirect::back()->with('message', 'Sorry! The following errors occured')->withErrors($validator)->withInput();
     }
 }
 /**
  * 创建友情链接
  *
  */
 function actionCreate()
 {
     //创建表单
     $form = Form_Admin_Links::createForm('links', url('links/create'));
     //是否是post提交 及通过验证
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         try {
             //用表单的数据创建模型
             $links = new Links($form->values());
             $links->save();
             return $this->_redirectMessage('创建友情链接成功', '如果你不做出选择系统将自动跳转', url('links/index'), 3);
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['form'] = $form;
     $this->_viewname = 'edit';
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Links();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Links'])) {
         $model->attributes = $_POST['Links'];
         $model->id_creator = Yii::app()->user->id;
         if ($model->save()) {
             $linkTranslation = new LinksTranslation();
             $linkTranslation->id_language = 1;
             $linkTranslation->name = $model->name;
             $linkTranslation->link_to = $model->link_to;
             $linkTranslation->id_links = $model->id_links;
             $linkTranslation->save();
             $this->redirect(array('view', 'id' => $model->id_links));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemple #6
0
 private function doTb($tid, $cid = 0)
 {
     if ($tid == 2610) {
         //彩票部分
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://www.114la.com/icai.json';
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         $fcurl = substr($fcurl, 17, -1);
         $data_arr = json_decode($fcurl, TRUE);
         if (!empty($data_arr)) {
             //对应关系
             $dy = array('ssq' => array(220, 221, 222), 'dlt' => array(223, 224, 225), 'fc3d' => array(226, 227, 228), 'jx_11x5' => array(229, 230, 231));
             foreach ($data_arr as $tp => $v) {
                 $va = $v[0];
                 $fdata[$dy[$tp][0]] = array(0 => array('title' => '上期开奖号码', 'link' => $va['url'][0], 'opt_a' => implode(',', $va['result']), 'opt_b' => $va['phase'], 'opt_c' => $va['date']));
                 $fdata[$dy[$tp][1]] = array(0 => array('title' => '立即投注', 'link' => $va['url'][1]), 1 => array('title' => $va['chain'][0], 'link' => $va['chain'][1]));
                 foreach ($va['link'] as $vl => $tu) {
                     $tu['link'] = $tu['url'];
                     unset($tu['url']);
                     $va['link'][$vl] = $tu;
                 }
                 $fdata[$dy[$tp][2]] = $va['link'];
             }
         }
         if (!empty($fdata)) {
             foreach ($fdata as $cid => $cinfo) {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
                 foreach ($cinfo as $info) {
                     try {
                         $model = new Links();
                         $info['catalog_id'] = $cid;
                         $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                         $info['link'] = empty($info['link']) || $info['link'] == '#' ? 'http://www.114la.com/' : $info['link'];
                         $info['mix'] = empty($info['mix']) ? null : base64_decode($info['mix']);
                         $info = array_filter($info);
                         $model->attributes = $this->_form($info);
                         //                        ppr($model->attributes);
                         $model->save();
                     } catch (Exception $exc) {
                         return 'error1caipiao';
                     }
                 }
             }
         }
         return 'ok';
         //            ppr($fdata,1);
     } elseif ($tid == 1114) {
         //实时热点部分
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://api4.114la.com/1114_2.json';
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         $fcurl = substr($fcurl, 20, -1);
         //            ppr($fcurl,1);
         if (!empty($fcurl) && ($fcurl = json_decode($fcurl, 1))) {
             //先将对应的旧数据处理
             $old = reqPost('old');
             if (empty($old)) {
                 Links::model()->updateAll(array('status_is' => 'N'), "`catalog_id`='{$cid}'");
             } else {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
             }
             //                ppr(Links::model()->findAll("`catalog_id`='$cid'"));
             foreach ($fcurl as $info) {
                 try {
                     $model = new Links();
                     $info['catalog_id'] = $cid;
                     $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                     $info['link'] = empty($info['url']) || $info['url'] == '#' ? 'http://www.114la.com/' : $info['url'];
                     unset($info['url']);
                     $info = array_filter($info);
                     $model->attributes = $this->_form($info);
                     //                        ppr($model->attributes);
                     $model->save();
                 } catch (Exception $exc) {
                     return 'error1';
                 }
             }
             $cacheId = '_catalogAllNum';
             $catalogAllNum = XXcache::refresh($cacheId);
             return empty($catalogAllNum[$cid]) ? 0 : $catalogAllNum[$cid] . ' ok';
         } else {
             return 'error2';
         }
         ppr($data_arr, 1);
     } elseif ($tid > 1000 && $tid < 10000) {
         $tid = (int) $tid;
         $data = $re = 0;
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://www.114la.com/api/ky.php?id=' . $tid . '&' . time();
             //                $url = 'http://www.114la.com/api/ky.php?id='.$tid;
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         if (!empty($fcurl) && ($fcurl = json_decode($fcurl, 1))) {
             //先将对应的旧数据处理
             $old = reqPost('old');
             if (empty($old)) {
                 Links::model()->updateAll(array('status_is' => 'N'), "`catalog_id`='{$cid}'");
             } else {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
             }
             //                ppr(Links::model()->findAll("`catalog_id`='$cid'"));
             foreach ($fcurl as $info) {
                 try {
                     $model = new Links();
                     $info['catalog_id'] = $cid;
                     $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                     $info['link'] = empty($info['link']) || $info['link'] == '#' ? 'http://www.114la.com/' : $info['link'];
                     $info['mix'] = empty($info['mix']) ? null : base64_decode($info['mix']);
                     $info = array_filter($info);
                     $model->attributes = $this->_form($info);
                     //                        ppr($model->attributes);
                     $model->save();
                 } catch (Exception $exc) {
                     return 'error1';
                 }
             }
             $cacheId = '_catalogAllNum';
             $catalogAllNum = XXcache::refresh($cacheId);
             return empty($catalogAllNum[$cid]) ? 0 : $catalogAllNum[$cid] . ' ok';
         } else {
             return 'error2';
         }
     } else {
         return 'error3';
     }
 }
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "index", "action" => "index"));
     }
     $check = Links::findFirst('longurl="' . $this->request->getPost("longurl") . '"');
     if ($check) {
         $this->flash->success("links was already created");
         $this->view->token = $check->token;
         return $this->dispatcher->forward(array("controller" => "index", "action" => "index"));
     } else {
         $hash = md5($this->request->getPost("longurl") . microtime());
         $token = substr($hash, -7);
         $links = new Links();
         $links->token = $token;
         $links->longurl = trim($this->request->getPost("longurl"));
         $links->visitor_count = 0;
         if (!$links->save()) {
             foreach ($links->getMessages() as $message) {
                 echo $message . "<br />";
                 $this->flash->error((string) $message);
             }
             die;
             return $this->dispatcher->forward(array("controller" => "index", "action" => "index"));
         } else {
             $this->flash->success("links was created successfully");
             $this->view->token = $token;
             return $this->dispatcher->forward(array("controller" => "index", "action" => "index"));
         }
     }
 }
 public function actionSave_link()
 {
     if (isset($_POST['cancel'])) {
         $this->redirect($this->createAbsoluteUrl('default/list_links', $_GET));
     }
     if (isset($_POST['delete'])) {
         $this->actionDelete_link();
         $this->redirect($this->createAbsoluteUrl('default/list_links', $_GET));
     }
     if (isset($_GET['link_id'])) {
         $model = Links::model()->findByPk($_GET['link_id']);
     } else {
         $model = new Links();
     }
     if (isset($_POST['Links'])) {
         $model->attributes = $_POST['Links'];
         if ($model->validate()) {
             $model->save();
             $this->redirect($this->createAbsoluteUrl('default/list_links', $_GET));
         }
     }
     $this->render('links/save_link', array('model' => $model));
 }