public function install() { $models = Shared\Markup::models(); foreach ($models as $key => $value) { $this->sync($value); } }
/** * Searchs for data and returns result from db * @param type $model the data model * @param type $property the property of modal * @param type $val the value of property * @before _secure, changeLayout, _admin */ public function search($model = NULL, $property = NULL, $val = 0, $page = 1, $limit = 10) { $this->seo(array("title" => "Search", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView())); $view = $this->getActionView(); $model = RequestMethods::get("model", $model); $property = RequestMethods::get("key", $property); $val = RequestMethods::get("value", $val); $page = RequestMethods::get("page", $page); $limit = RequestMethods::get("limit", $limit); $sign = RequestMethods::get("sign", "equal"); $view->set("items", array()); $view->set("values", array()); $view->set("models", Shared\Markup::models()); $view->set("page", $page); $view->set("limit", $limit); $view->set("property", $property); $view->set("val", $val); $view->set("sign", $sign); if ($model) { if ($sign == "like") { $where = array("{$property} LIKE ?" => "%{$val}%"); } else { $where = array("{$property} = ?" => $val); } $objects = $model::all($where, array("*"), "created", "desc", $limit, $page); $count = $model::count($where); $i = 0; if ($objects) { foreach ($objects as $object) { $properties = $object->getJsonData(); foreach ($properties as $key => $property) { $key = substr($key, 1); $items[$i][$key] = $property; $values[$i][] = $key; } $i++; } $view->set("items", $items); $view->set("values", $values[0]); $view->set("count", $count); //echo '<pre>', print_r($values[0]), '</pre>'; $view->set("success", "Total Results : {$count}"); } else { $view->set("success", "No Results Found"); } } }
/** * @before _secure, memberLayout */ public function create() { $this->seo(array("title" => "Ping | Create", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (RequestMethods::post('title')) { $ping = Registry::get('MongoDB')->ping; $time = strtotime(date('d-m-Y H:i:s')); $mongo_date = new MongoDate($time); $url = RequestMethods::post('url', ''); $regex = Shared\Markup::websiteRegex(); if (!preg_match("/^{$regex}\$/", $url)) { $view->set("success", "Invalid Url"); return; } $record = $ping->findOne(array('user_id' => (int) $this->user->id, 'url' => $url)); if ($record) { $view->set("success", "Ping already created! Go to <a href='/ping/edit/" . $record['url'] . "'>Edit</a>"); return; } $ping->insert(array("user_id" => (int) $this->user->id, "title" => RequestMethods::post('title'), "url" => $url, "interval" => RequestMethods::post('interval'), "live" => 1, "created" => $mongo_date)); $view->set('success', 'Ping Created Successfully'); } }
protected function _upload($name, $opts = array()) { $type = isset($opts["type"]) ? $opts["type"] : "images"; /*** Create Directory if not present ***/ $path = APP_PATH . "/public/assets/uploads/{$type}"; exec("mkdir -p {$path}"); $path .= "/"; $filename = Shared\Markup::uniqueString(); // For normal file upload via browser if (isset($_FILES[$name])) { $file = $_FILES[$name]; $extension = pathinfo($file["name"], PATHINFO_EXTENSION); if (empty($extension)) { return false; } $filename .= ".{$extension}"; /*** Check mime type before moving ***/ if (isset($opts["mimes"])) { if (!preg_match("/^{$opts['mimes']}\$/", $extension)) { return false; } } if (move_uploaded_file($file["tmp_name"], $path . $filename)) { return $filename; } else { return FALSE; } // for app upload } elseif ($f = RequestMethods::post($name)) { if (file_put_contents($filename, base64_decode($f))) { return $filename; } } else { return false; } }
/** * @return string|array Array on DB validation errors, else string messages */ private function _saveSerp($keyword, $link) { $keyword = RequestMethods::post("keyword"); $link = RequestMethods::post("link"); $regex = Shared\Markup::websiteRegex(); if (!preg_match("/^{$regex}\$/", $link)) { return "Invalid URL"; } $serp = Keyword::first(array("link = ?" => $link, "user_id = ?" => $this->user->id, "keyword = ?" => $keyword, "serp = ?" => true)); if ($serp) { return "SERP Already Registered"; } $serp = new Keyword(array("link" => $link, "user_id" => $this->user->id, "keyword" => $keyword, "serp" => true)); if ($serp->validate()) { $serp->save(); return "Serp Action saved succesfully!!"; } else { $errors = $keyword->errors; return $errors; } }
/** * @before _secure, _admin */ public function manageGroups() { $this->seo(array("title" => "Manage Group Members", "view" => $this->getLayoutView())); $view = $this->getActionView(); $page = Shared\Markup::page(array("model" => "Group", "where" => array())); $groups = Group::all(); $view->set("groups", $groups)->set($page); }
/** * @return string */ private function _saveSocial() { $regex = Shared\Markup::websiteRegex(); $link = RequestMethods::post("link"); if (!preg_match("/^{$regex}\$/", $link)) { return "Invalid URL"; } $tracker = Keyword::first(array("link = ?" => $link, "user_id = ?" => $this->user->id, "serp = ?" => false)); if ($tracker) { return "Already added"; } $tracker = new Keyword(array("keyword" => "social", "link" => $link, "user_id" => $this->user->id, "serp" => false)); $tracker->save(); return "Social Tracker Added"; }
/** * @before _secure, changeLayout, _admin */ public function dataAnalysis() { $this->seo(array("title" => "Data Analysis", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (RequestMethods::get("action") == "dataAnalysis") { $startdate = RequestMethods::get("startdate"); $enddate = RequestMethods::get("enddate"); $model = ucfirst(RequestMethods::get("model")); $diff = date_diff(date_create($startdate), date_create($enddate)); for ($i = 0; $i < $diff->format("%a"); $i++) { $date = date('Y-m-d', strtotime($startdate . " +{$i} day")); $count = $model::count(array("created LIKE ?" => "%{$date}%")); $obj[] = array('y' => $date, 'a' => $count); } $view->set("data", \Framework\ArrayMethods::toObject($obj)); } $view->set("models", Shared\Markup::models()); }
/** * @before _secure, _admin */ public function all() { $this->seo(array("title" => "Websites added", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView())); $view = $this->getActionView(); $page = Shared\Markup::page(array("model" => "Website", "where" => array())); $websites = \Website::all(array(), array("title", "url", "id", "created"), "created", "desc", $page["limit"], $page["page"]); $view->set("websites", $websites)->set($page); }
protected function _shuffleprocess($game, $campaign, $play_again = true) { $participant = Participant::first(array("user_id = ?" => $this->user->id, "campaign_id = ?" => $campaign->id)); if ($participant && !$play_again) { return $participant->image; } $items = ShuffleItem::all(array("shuffle_id = ?" => $game->id, "meta_key = ?" => "gender", "meta_value = ?" => strtolower($this->user->gender))); $key = rand(0, count($items) - 1); $item = $items[$key]; $vars = array(); $user = $this->user; $path = APP_PATH . '/public/assets/uploads/images/'; $user_img = "{$path}user-" . $user->fbid . ".jpg"; if (!file_exists($user_img)) { if (!copy('http://graph.facebook.com/' . $user->fbid . '/picture?width=' . $item->usr_w . '&height=' . $item->usr_h, $user_img)) { die('Could not copy image'); } } $src_file = $path . $item->base_im; $extension = pathinfo($src_file, PATHINFO_EXTENSION); if ($participant) { $filename = $participant->image; } else { $filename = Shared\Markup::uniqueString() . ".{$extension}"; } $final_img = $path . $filename; copy($src_file, $final_img); $dest = Shared\Image::resource($final_img); $vars['file'] = $final_img; $vars['filename'] = $filename; $img = Shared\Image::resize($user_img, $item->usr_w, $item->usr_h); $vars['usr'] = Shared\Image::resource($img); imagecopymerge($dest, $vars['usr'], $item->usr_x, $item->usr_y, 0, 0, $item->usr_w, $item->usr_h, 100); // add text $tt_color = $this->_makeColor($dest, $item->txt_color); $font = APP_PATH . '/public/assets/fonts/monaco.ttf'; imagettftext($dest, $item->txt_size, 0, $item->txt_x, $item->txt_y, $tt_color, $font, $user->name); Shared\Image::create($dest, $vars['file']); $this->_saveParticipant($participant, $campaign, $vars); return $participant->image; }
/** * @before _secure * @after _cleanUp */ public function devices() { $view = $this->getActionView(); $devices = Shared\Markup::devices(); $view->set('data', ['devices' => array_keys($devices)]); }